84d14da7be029fe7642a3a1bc27d5f572ec1f5c3
[framework/multimedia/libmm-camcorder.git] / src / include / mm_camcorder_internal.h
1 /*
2  * libmm-camcorder
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jeongmo Yang <jm80.yang@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __MM_CAMCORDER_INTERNAL_H__
23 #define __MM_CAMCORDER_INTERNAL_H__
24
25 /*=======================================================================================
26 | INCLUDE FILES                                                                         |
27 ========================================================================================*/
28 #include <malloc.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <pthread.h>
32 #include <semaphore.h>
33
34 #include <mm_types.h>
35 #include <mm_attrs.h>
36 #include <mm_attrs_private.h>
37 #include <mm_message.h>
38 #include <sndfile.h>
39 #include <vconf.h>
40
41 #include "mm_camcorder.h"
42 #include "mm_debug.h"
43
44 /* camcorder sub module */
45 #include "mm_camcorder_attribute.h"
46 #include "mm_camcorder_platform.h"
47 #include "mm_camcorder_stillshot.h"
48 #include "mm_camcorder_videorec.h"
49 #include "mm_camcorder_audiorec.h"
50 #include "mm_camcorder_gstcommon.h"
51 #include "mm_camcorder_exifinfo.h"
52 #include "mm_camcorder_util.h"
53 #include "mm_camcorder_configure.h"
54 #include "mm_camcorder_sound.h"
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
60 /*=======================================================================================
61 | MACRO DEFINITIONS                                                                     |
62 ========================================================================================*/
63 #define _mmcam_dbg_verb(fmt, args...)  debug_verbose (" "fmt"\n", ##args);
64 #define _mmcam_dbg_log(fmt, args...)   debug_log (" "fmt"\n", ##args);
65 #define _mmcam_dbg_warn(fmt, args...)  debug_warning (" "fmt"\n", ##args);
66 #define _mmcam_dbg_err(fmt, args...)   debug_error (" "fmt"\n", ##args);
67 #define _mmcam_dbg_crit(fmt, args...)  debug_critical (" "fmt"\n", ##args);
68
69 /**
70  *      Macro for checking validity and debugging
71  */
72 #define mmf_return_if_fail( expr )      \
73         if( expr ){}                                    \
74         else                                            \
75         {                                                       \
76                 _mmcam_dbg_err( "failed [%s]", #expr);  \
77                 return;                                         \
78         };
79
80 /**
81  *      Macro for checking validity and debugging
82  */
83 #define mmf_return_val_if_fail( expr, val )     \
84         if( expr ){}                                    \
85         else                                            \
86         {                                                       \
87                 _mmcam_dbg_err("failed [%s]", #expr);   \
88                 return( val );                                          \
89         };
90
91 #ifndef ARRAY_SIZE
92 /**
93  *      Macro for getting array size
94  */
95 #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
96 #endif
97
98 /* gstreamer element creation macro */
99 #define _MMCAMCORDER_PIPELINE_MAKE(sub_context, element, eid, name /*char* */, err) \
100         if (element[eid].gst != NULL) { \
101                 _mmcam_dbg_err("The element(Pipeline) is existed. element_id=[%d], name=[%s]", eid, name); \
102                 gst_object_unref(element[eid].gst); \
103         } \
104         element[eid].id = eid; \
105         element[eid].gst = gst_pipeline_new(name); \
106         if (element[eid].gst == NULL) { \
107                 _mmcam_dbg_err("Pipeline creation fail. element_id=[%d], name=[%s]", eid, name); \
108                 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
109                 goto pipeline_creation_error; \
110         } else { \
111                 g_object_weak_ref(G_OBJECT(element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
112         }
113
114 #define _MMCAMCORDER_BIN_MAKE(sub_context, element, eid, name /*char* */, err) \
115         if (element[eid].gst != NULL) { \
116                 _mmcam_dbg_err("The element(Bin) is existed. element_id=[%d], name=[%s]", eid, name); \
117                 gst_object_unref(element[eid].gst); \
118         } \
119         element[eid].id = eid; \
120         element[eid].gst = gst_bin_new(name); \
121         if (element[eid].gst == NULL) { \
122                 _mmcam_dbg_err("Bin creation fail. element_id=[%d], name=[%s]\n", eid, name); \
123                 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
124                 goto pipeline_creation_error; \
125         } else { \
126                 g_object_weak_ref(G_OBJECT(element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
127         }
128
129 #define _MMCAMCORDER_ELEMENT_MAKE(sub_context, element, eid, name /*char* */, nickname /*char* */, elist, err) \
130         if (element[eid].gst != NULL) { \
131                 _mmcam_dbg_err("The element is existed. element_id=[%d], name=[%s]", eid, name); \
132                 gst_object_unref(element[eid].gst); \
133         } \
134         element[eid].gst = gst_element_factory_make(name, nickname); \
135         if (element[eid].gst == NULL) { \
136                 _mmcam_dbg_err("Element creation fail. element_id=[%d], name=[%s]", eid, name); \
137                 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
138                 goto pipeline_creation_error; \
139         } else { \
140                 _mmcam_dbg_log("Element creation done. element_id=[%d], name=[%s]", eid, name); \
141                 element[eid].id = eid; \
142                 g_object_weak_ref(G_OBJECT(element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
143                 err = MM_ERROR_NONE; \
144         } \
145         elist = g_list_append(elist, &(element[eid]));
146
147 #define _MMCAMCORDER_ELEMENT_MAKE2(sub_context, element, eid, name /*char* */, nickname /*char* */, err) \
148         if (element[eid].gst != NULL) { \
149                 _mmcam_dbg_err("The element is existed. element_id=[%d], name=[%s]", eid, name); \
150                 gst_object_unref(element[eid].gst); \
151         } \
152         element[eid].gst = gst_element_factory_make(name, nickname); \
153         if (element[eid].gst == NULL) { \
154                 _mmcam_dbg_err("Element creation fail. element_id=[%d], name=[%s]", eid, name); \
155                 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
156         } else { \
157                 _mmcam_dbg_log("Element creation done. element_id=[%d], name=[%s]", eid, name); \
158                 element[eid].id = eid; \
159                 g_object_weak_ref(G_OBJECT(element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
160                 err = MM_ERROR_NONE; \
161         } \
162
163 #define _MMCAMCORDER_ELEMENT_MAKE_IGNORE_ERROR(sub_context, element, eid, name /*char* */, nickname /*char* */, elist) \
164         if (element[eid].gst != NULL) { \
165                 _mmcam_dbg_err("The element is existed. element_id=[%d], name=[%s]", eid, name); \
166                 gst_object_unref(element[eid].gst); \
167         } \
168         element[eid].gst = gst_element_factory_make(name, nickname); \
169         if (element[eid].gst == NULL) { \
170                 _mmcam_dbg_err("Element creation fail. element_id=[%d], name=[%s], but keep going...", eid, name); \
171         } else { \
172                 _mmcam_dbg_log("Element creation done. element_id=[%d], name=[%s]", eid, name); \
173                 element[eid].id = eid; \
174                 g_object_weak_ref(G_OBJECT(element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
175                 elist = g_list_append(elist, &(element[eid])); \
176         }
177
178 #define _MMCAMCORDER_ENCODEBIN_ELMGET(sub_context, eid, name /*char* */, err) \
179         if (sub_context->encode_element[eid].gst != NULL) { \
180                 _mmcam_dbg_err("The element is existed. element_id=[%d], name=[%s]", eid, name); \
181                 gst_object_unref(sub_context->encode_element[eid].gst); \
182         } \
183         sub_context->encode_element[eid].id = eid; \
184         g_object_get(G_OBJECT(sub_context->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst), name, &(sub_context->encode_element[eid].gst), NULL); \
185         if (sub_context->encode_element[eid].gst == NULL) { \
186                 _mmcam_dbg_err("Encode Element get fail. element_id=[%d], name=[%s]", eid, name); \
187                 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
188                 goto pipeline_creation_error; \
189         } else{ \
190                 gst_object_unref(sub_context->encode_element[eid].gst); \
191                 g_object_weak_ref(G_OBJECT(sub_context->encode_element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
192         }
193
194 /* GStreamer element remove macro */
195 #define _MMCAMCORDER_ELEMENT_REMOVE(element, eid) \
196         if (element[eid].gst != NULL) { \
197                 gst_object_unref(element[eid].gst); \
198         }
199
200 #define _MM_GST_ELEMENT_LINK_MANY       gst_element_link_many
201 #define _MM_GST_ELEMENT_LINK            gst_element_link
202 #define _MM_GST_ELEMENT_UNLINK          gst_element_unlink
203 #define _MM_GST_PAD_LINK                gst_pad_link
204
205 #define _MM_GST_PAD_LINK_UNREF(srcpad, sinkpad, err, if_fail_goto)\
206 {\
207         GstPadLinkReturn ret = _MM_GST_PAD_LINK(srcpad, sinkpad);\
208         if (ret != GST_PAD_LINK_OK) {\
209                 GstObject *src_parent = gst_pad_get_parent(srcpad);\
210                 GstObject *sink_parent = gst_pad_get_parent(sinkpad);\
211                 char *src_name = NULL;\
212                 char *sink_name = NULL;\
213                 g_object_get((GObject *)src_parent, "name", &src_name, NULL);\
214                 g_object_get((GObject *)sink_parent, "name", &sink_name, NULL);\
215                 _mmcam_dbg_err("src[%s] - sink[%s] link failed", src_name, sink_name);\
216                 gst_object_unref(src_parent); src_parent = NULL;\
217                 gst_object_unref(sink_parent); sink_parent = NULL;\
218                 if (src_name) {\
219                         free(src_name); src_name = NULL;\
220                 }\
221                 if (sink_name) {\
222                         free(sink_name); sink_name = NULL;\
223                 }\
224                 gst_object_unref(srcpad); srcpad = NULL;\
225                 gst_object_unref(sinkpad); sinkpad = NULL;\
226                 err = MM_ERROR_CAMCORDER_GST_LINK;\
227                 goto if_fail_goto;\
228         }\
229         gst_object_unref(srcpad); srcpad = NULL;\
230         gst_object_unref(sinkpad); sinkpad = NULL;\
231 }
232
233 #define _MM_GST_PAD_UNLINK_UNREF( srcpad, sinkpad) \
234         if (srcpad && sinkpad) { \
235                 gst_pad_unlink(srcpad, sinkpad); \
236         } else { \
237                 _mmcam_dbg_warn("some pad(srcpad:%p,sinkpad:%p) is NULL", srcpad, sinkpad); \
238         } \
239         if (srcpad) { \
240                 gst_object_unref(srcpad); srcpad = NULL; \
241         } \
242         if (sinkpad) { \
243                 gst_object_unref(sinkpad); sinkpad = NULL; \
244         }
245
246 #define _MMCAMCORDER_STATE_SET_COUNT            3               /* checking interval */
247 #define _MMCAMCORDER_STATE_CHECK_TOTALTIME      5000000L        /* total wating time for state change */
248 #define _MMCAMCORDER_STATE_CHECK_INTERVAL       5000            /* checking interval */
249
250 /**
251  * Default videosink type
252  */
253 #define _MMCAMCORDER_DEFAULT_VIDEOSINK_TYPE     "VideosinkElementX"
254
255 /**
256  * Default recording motion rate
257  */
258 #define _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE   1.0
259
260 /**
261  * Total level count of manual focus */
262 #define _MMFCAMCORDER_FOCUS_TOTAL_LEVEL         8
263
264 /**
265  *      File name length limit
266  */
267 #define _MMCamcorder_FILENAME_LEN       (512)
268
269 /**
270  *      Minimum integer value
271  */
272 #define _MMCAMCORDER_MIN_INT    (INT_MIN)
273
274 /**
275  *      Maximum integer value
276  */
277 #define _MMCAMCORDER_MAX_INT    (INT_MAX)
278
279 /**
280  *      Minimum double value
281  */
282 #define _MMCAMCORDER_MIN_DOUBLE (DBL_MIN)
283
284 /**
285  *      Maximum integer value
286  */
287 #define _MMCAMCORDER_MAX_DOUBLE (DBL_MAX)
288
289 /**
290  *      Audio timestamp margin (msec)
291  */
292 #define _MMCAMCORDER_AUDIO_TIME_MARGIN (300)
293
294 /**
295  *      Functions related with LOCK and WAIT
296  */
297 #define _MMCAMCORDER_CAST_MTSAFE(handle)                                (((mmf_camcorder_t*)handle)->mtsafe)
298
299 #define _MMCAMCORDER_GET_LOCK(handle)                                   (_MMCAMCORDER_CAST_MTSAFE(handle).lock)
300 #define _MMCAMCORDER_LOCK(handle)                                               g_mutex_lock(_MMCAMCORDER_GET_LOCK(handle))
301 #define _MMCAMCORDER_TRYLOCK(handle)                                    g_mutex_trylock(_MMCAMCORDER_GET_LOCK(handle))
302 #define _MMCAMCORDER_UNLOCK(handle)                                             g_mutex_unlock(_MMCAMCORDER_GET_LOCK(handle))
303
304 #define _MMCAMCORDER_GET_COND(handle)                                   (_MMCAMCORDER_CAST_MTSAFE(handle).cond)
305 #define _MMCAMCORDER_WAIT(handle)                                               g_cond_wait (_MMCAMCORDER_GET_COND(handle), _MMCAMCORDER_GET_LOCK(handle))
306 #define _MMCAMCORDER_TIMED_WAIT(handle, timeval)                g_cond_timed_wait (_MMCAMCORDER_GET_COND(handle), _MMCAMCORDER_GET_LOCK(handle),timeval)
307
308 #define _MMCAMCORDER_SIGNAL(handle)                                             g_cond_signal (_MMCAMCORDER_GET_COND(handle));
309 #define _MMCAMCORDER_BROADCAST(handle)                                  g_cond_broadcast (_MMCAMCORDER_GET_COND(handle));
310
311 /* for command */
312 #define _MMCAMCORDER_GET_CMD_LOCK(handle)                                       (_MMCAMCORDER_CAST_MTSAFE(handle).cmd_lock)
313 #define _MMCAMCORDER_LOCK_CMD(handle)                                           g_mutex_lock(_MMCAMCORDER_GET_CMD_LOCK(handle))
314 #define _MMCAMCORDER_TRYLOCK_CMD(handle)                                        g_mutex_trylock(_MMCAMCORDER_GET_CMD_LOCK(handle))
315 #define _MMCAMCORDER_UNLOCK_CMD(handle)                                         g_mutex_unlock(_MMCAMCORDER_GET_CMD_LOCK(handle))
316
317 /* for ASM */
318 #define _MMCAMCORDER_GET_ASM_LOCK(handle)                                       (_MMCAMCORDER_CAST_MTSAFE(handle).asm_lock)
319 #define _MMCAMCORDER_LOCK_ASM(handle)                                           g_mutex_lock(_MMCAMCORDER_GET_ASM_LOCK(handle))
320 #define _MMCAMCORDER_TRYLOCK_ASM(handle)                                        g_mutex_trylock(_MMCAMCORDER_GET_ASM_LOCK(handle))
321 #define _MMCAMCORDER_UNLOCK_ASM(handle)                                         g_mutex_unlock(_MMCAMCORDER_GET_ASM_LOCK(handle))
322
323 /* for state change */
324 #define _MMCAMCORDER_GET_STATE_LOCK(handle)                                     (_MMCAMCORDER_CAST_MTSAFE(handle).state_lock)
325 #define _MMCAMCORDER_LOCK_STATE(handle)                                         g_mutex_lock(_MMCAMCORDER_GET_STATE_LOCK(handle))
326 #define _MMCAMCORDER_TRYLOCK_STATE(handle)                                      g_mutex_trylock(_MMCAMCORDER_GET_STATE_LOCK(handle))
327 #define _MMCAMCORDER_UNLOCK_STATE(handle)                                               g_mutex_unlock(_MMCAMCORDER_GET_STATE_LOCK(handle))
328
329 /* for gstreamer state change */
330 #define _MMCAMCORDER_GET_GST_STATE_LOCK(handle)                                 (_MMCAMCORDER_CAST_MTSAFE(handle).gst_state_lock)
331 #define _MMCAMCORDER_LOCK_GST_STATE(handle)                                     g_mutex_lock(_MMCAMCORDER_GET_GST_STATE_LOCK(handle))
332 #define _MMCAMCORDER_TRYLOCK_GST_STATE(handle)                                  g_mutex_trylock(_MMCAMCORDER_GET_GST_STATE_LOCK(handle))
333 #define _MMCAMCORDER_UNLOCK_GST_STATE(handle)                                   g_mutex_unlock(_MMCAMCORDER_GET_GST_STATE_LOCK(handle))
334
335 #define _MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle)                          (_MMCAMCORDER_CAST_MTSAFE(handle).gst_encode_state_lock)
336 #define _MMCAMCORDER_LOCK_GST_ENCODE_STATE(handle)                              g_mutex_lock(_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle))
337 #define _MMCAMCORDER_TRYLOCK_GST_ENCODE_STATE(handle)                           g_mutex_trylock(_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle))
338 #define _MMCAMCORDER_UNLOCK_GST_ENCODE_STATE(handle)                            g_mutex_unlock(_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle))
339
340 /* for setting/calling callback */
341 #define _MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle)      (_MMCAMCORDER_CAST_MTSAFE(handle).message_cb_lock)
342 #define _MMCAMCORDER_LOCK_MESSAGE_CALLBACK(handle)          g_mutex_lock(_MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle))
343 #define _MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(handle)       g_mutex_trylock(_MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle))
344 #define _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(handle)        g_mutex_unlock(_MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle))
345
346 #define _MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle)     (_MMCAMCORDER_CAST_MTSAFE(handle).vcapture_cb_lock)
347 #define _MMCAMCORDER_LOCK_VCAPTURE_CALLBACK(handle)         g_mutex_lock(_MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle))
348 #define _MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(handle)      g_mutex_trylock(_MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle))
349 #define _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(handle)       g_mutex_unlock(_MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle))
350
351 #define _MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle)      (_MMCAMCORDER_CAST_MTSAFE(handle).vstream_cb_lock)
352 #define _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(handle)          g_mutex_lock(_MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle))
353 #define _MMCAMCORDER_TRYLOCK_VSTREAM_CALLBACK(handle)       g_mutex_trylock(_MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle))
354 #define _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(handle)        g_mutex_unlock(_MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle))
355
356 #define _MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle)      (_MMCAMCORDER_CAST_MTSAFE(handle).astream_cb_lock)
357 #define _MMCAMCORDER_LOCK_ASTREAM_CALLBACK(handle)          g_mutex_lock(_MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle))
358 #define _MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(handle)       g_mutex_trylock(_MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle))
359 #define _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(handle)        g_mutex_unlock(_MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle))
360
361 /**
362  * Caster of main handle (camcorder)
363  */
364 #define MMF_CAMCORDER(h) (mmf_camcorder_t *)(h)
365
366 /**
367  * Caster of subcontext
368  */
369 #define MMF_CAMCORDER_SUBCONTEXT(h) (((mmf_camcorder_t *)(h))->sub_context)
370
371 /* LOCAL CONSTANT DEFINITIONS */
372 /**
373  * Total Numbers of Attribute values.
374  * If you increase any enum of attribute values, you also have to increase this.
375  */
376 #define MM_CAMCORDER_MODE_NUM                   3       /**< Number of mode type */
377 #define MM_CAMCORDER_COLOR_TONE_NUM             31      /**< Number of color-tone modes */
378 #define MM_CAMCORDER_WHITE_BALANCE_NUM          10      /**< Number of WhiteBalance modes*/
379 #define MM_CAMCORDER_SCENE_MODE_NUM             16      /**< Number of program-modes */
380 #define MM_CAMCORDER_FOCUS_MODE_NUM             6       /**< Number of focus mode*/
381 #define MM_CAMCORDER_AUTO_FOCUS_NUM             5       /**< Total count of auto focus type*/
382 #define MM_CAMCORDER_FOCUS_STATE_NUM            4       /**< Number of focus state */
383 #define MM_CAMCORDER_ISO_NUM                    10      /**< Number of ISO */
384 #define MM_CAMCORDER_AUTO_EXPOSURE_NUM          9       /**< Number of Auto exposure type */
385 #define MM_CAMCORDER_WDR_NUM                    3       /**< Number of wide dynamic range */
386 #define MM_CAMCORDER_FLIP_NUM                   4       /**< Number of Filp mode */
387 #define MM_CAMCORDER_ROTATION_NUM               4       /**< Number of Rotation mode */
388 #define MM_CAMCORDER_AHS_NUM                    4       /**< Number of anti-handshake */
389 #define MM_CAMCORDER_VIDEO_STABILIZATION_NUM    2       /**< Number of video stabilization */
390 #define MM_CAMCORDER_HDR_CAPTURE_NUM            3       /**< Number of HDR capture mode */
391 #define MM_CAMCORDER_GEOMETRY_METHOD_NUM        5       /**< Number of geometry method */
392 #define MM_CAMCORDER_TAG_ORT_NUM                8       /**< Number of tag orientation */
393 #define MM_CAMCORDER_STROBE_MODE_NUM            8       /**< Number of strobe mode type */
394 #define MM_CAMCORDER_STROBE_CONTROL_NUM         3       /**< Number of strobe control type */
395 #define MM_CAMCORDER_DETECT_MODE_NUM            2       /**< Number of detect mode type */
396
397
398 /*=======================================================================================
399 | ENUM DEFINITIONS                                                                      |
400 ========================================================================================*/
401 /**
402  * Command for Camcorder.
403  */
404 enum {
405         /* Command for Video/Audio recording */
406         _MMCamcorder_CMD_RECORD,
407         _MMCamcorder_CMD_PAUSE,
408         _MMCamcorder_CMD_CANCEL,
409         _MMCamcorder_CMD_COMMIT,
410
411         /* Command for Image capture */
412         _MMCamcorder_CMD_CAPTURE,
413
414         /* Command for Preview(Video/Image only effective) */
415         _MMCamcorder_CMD_PREVIEW_START,
416         _MMCamcorder_CMD_PREVIEW_STOP,
417 };
418
419 /**
420  * Still-shot type
421  */
422 enum {
423         _MMCamcorder_SINGLE_SHOT,
424         _MMCamcorder_MULTI_SHOT,
425 };
426
427 /**
428  * Audio session registered type
429  */
430 enum {
431         _MMCamcorder_ASM_NO_NEED_REGISTER,
432         _MMCamcorder_ASM_SESSION_REGISTERED_INTERNALLY,
433         _MMCamcorder_ASM_SESSION_REGISTERED_BY_OUTSIDE,
434 };
435
436 /** 
437  * Enumerations for manual focus direction. 
438  * If focusing mode is not "MM_CAMCORDER_AF_MODE_MANUAL", this value will be ignored. 
439  */
440 enum MMCamcorderMfLensDir {
441         MM_CAMCORDER_MF_LENS_DIR_FORWARD = 1,   /**< Focus direction to forward */
442         MM_CAMCORDER_MF_LENS_DIR_BACKWARD,      /**< Focus direction to backward */
443         MM_CAMCORDER_MF_LENS_DIR_NUM,           /**< Total number of the directions */
444 };
445
446 /**
447  * Camcorder Pipeline's Element name.
448  * @note index of element.
449  */
450 typedef enum {
451         _MMCAMCORDER_NONE = (-1),
452
453         /* Main Pipeline Element */
454         _MMCAMCORDER_MAIN_PIPE = 0x00,
455
456         /* Pipeline element of Video input */
457         _MMCAMCORDER_VIDEOSRC_SRC,
458         _MMCAMCORDER_VIDEOSRC_FILT,
459         _MMCAMCORDER_VIDEOSRC_CLS_QUE,
460         _MMCAMCORDER_VIDEOSRC_CLS,
461         _MMCAMCORDER_VIDEOSRC_CLS_FILT,
462         _MMCAMCORDER_VIDEOSRC_QUE,
463
464         /* Pipeline element of Video output */
465         _MMCAMCORDER_VIDEOSINK_QUE,
466         _MMCAMCORDER_VIDEOSINK_CLS,
467         _MMCAMCORDER_VIDEOSINK_SINK,
468
469         _MMCAMCORDER_PIPELINE_ELEMENT_NUM,
470 } _MMCAMCORDER_PREVIEW_PIPELINE_ELELMENT;
471
472 /**
473  * Camcorder Pipeline's Element name.
474  * @note index of element.
475  */
476 typedef enum {
477         _MMCAMCORDER_ENCODE_NONE = (-1),
478
479         /* Main Pipeline Element */
480         _MMCAMCORDER_ENCODE_MAIN_PIPE = 0x00,
481
482         /* Pipeline element of Audio input */
483         _MMCAMCORDER_AUDIOSRC_BIN,
484         _MMCAMCORDER_AUDIOSRC_SRC,
485         _MMCAMCORDER_AUDIOSRC_FILT,
486         _MMCAMCORDER_AUDIOSRC_QUE,
487         _MMCAMCORDER_AUDIOSRC_CONV,
488         _MMCAMCORDER_AUDIOSRC_VOL,
489
490         /* Pipeline element of Encodebin */
491         _MMCAMCORDER_ENCSINK_BIN,
492         _MMCAMCORDER_ENCSINK_SRC,
493         _MMCAMCORDER_ENCSINK_FILT,
494         _MMCAMCORDER_ENCSINK_ENCBIN,
495         _MMCAMCORDER_ENCSINK_AQUE,
496         _MMCAMCORDER_ENCSINK_CONV,
497         _MMCAMCORDER_ENCSINK_AENC,
498         _MMCAMCORDER_ENCSINK_AENC_QUE,
499         _MMCAMCORDER_ENCSINK_VQUE,
500         _MMCAMCORDER_ENCSINK_VCONV,
501         _MMCAMCORDER_ENCSINK_VENC,
502         _MMCAMCORDER_ENCSINK_VENC_QUE,
503         _MMCAMCORDER_ENCSINK_ITOG,
504         _MMCAMCORDER_ENCSINK_ICROP,
505         _MMCAMCORDER_ENCSINK_ISCALE,
506         _MMCAMCORDER_ENCSINK_IFILT,
507         _MMCAMCORDER_ENCSINK_IQUE,
508         _MMCAMCORDER_ENCSINK_IENC,
509         _MMCAMCORDER_ENCSINK_MUX,
510         _MMCAMCORDER_ENCSINK_SINK,
511
512         _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM,
513 } _MMCAMCORDER_ENCODE_PIPELINE_ELELMENT;
514
515 typedef enum {
516         _MMCAMCORDER_TASK_THREAD_STATE_NONE,
517         _MMCAMCORDER_TASK_THREAD_STATE_SOUND_PLAY_START,
518         _MMCAMCORDER_TASK_THREAD_STATE_ENCODE_PIPE_CREATE,
519         _MMCAMCORDER_TASK_THREAD_STATE_EXIT,
520 } _MMCamcorderTaskThreadState;
521
522 /**
523  * System state change cause
524  */
525 typedef enum {
526         _MMCAMCORDER_STATE_CHANGE_NORMAL = 0,
527         _MMCAMCORDER_STATE_CHANGE_BY_ASM,
528 } _MMCamcorderStateChange;
529
530
531 /*=======================================================================================
532 | STRUCTURE DEFINITIONS                                                                 |
533 ========================================================================================*/
534 /**
535  * MMCamcorder Gstreamer Element
536  */
537 typedef struct {
538         unsigned int id;                /**< Gstreamer piplinem element name */
539         GstElement *gst;                /**< Gstreamer element */
540 } _MMCamcorderGstElement;
541
542 /**
543  * MMCamcorder information for KPI measurement
544  */
545 typedef struct {
546         int current_fps;                /**< current fps of this second */
547         int average_fps;                /**< average fps  */
548         unsigned int video_framecount;  /**< total number of video frame */
549         unsigned int last_framecount;   /**< total number of video frame in last measurement */
550         struct timeval init_video_time; /**< time when start to measure */
551         struct timeval last_video_time; /**< last measurement time */
552 } _MMCamcorderKPIMeasure;
553
554 /**
555  * MMCamcorder information for Multi-Thread Safe
556  */
557 typedef struct {
558         GMutex *lock;                   /**< Mutex (for general use) */
559         GCond *cond;                    /**< Condition (for general use) */
560         GMutex *cmd_lock;               /**< Mutex (for command) */
561         GMutex *asm_lock;               /**< Mutex (for ASM) */
562         GMutex *state_lock;             /**< Mutex (for state change) */
563         GMutex *gst_state_lock;         /**< Mutex (for gst pipeline state change) */
564         GMutex *gst_encode_state_lock;  /**< Mutex (for gst encode pipeline state change) */
565         GMutex *message_cb_lock;        /**< Mutex (for message callback) */
566         GMutex *vcapture_cb_lock;       /**< Mutex (for video capture callback) */
567         GMutex *vstream_cb_lock;        /**< Mutex (for video stream callback) */
568         GMutex *astream_cb_lock;        /**< Mutex (for audio stream callback) */
569 } _MMCamcorderMTSafe;
570
571
572 /**
573  * MMCamcorder Sub Context
574  */
575 typedef struct {
576         bool isMaxsizePausing;                  /**< Because of size limit, pipeline is paused. */
577         bool isMaxtimePausing;                  /**< Because of time limit, pipeline is paused. */
578         int element_num;                        /**< count of element */
579         int encode_element_num;                 /**< count of encode element */
580         int cam_stability_count;                /**< camsensor stability count. the count of frame will drop */
581         GstClockTime pipeline_time;             /**< current time of Gstreamer Pipeline */
582         GstClockTime pause_time;                /**< amount of time while pipeline is in PAUSE state.*/
583         GstClockTime stillshot_time;            /**< pipeline time of capturing moment*/
584         gboolean is_modified_rate;              /**< whether recording motion rate is modified or not */
585         gboolean error_occurs;                  /**< flag for error */
586         int error_code;                         /**< error code for internal gstreamer error */
587         gboolean ferror_send;                   /**< file write/seek error **/
588         guint ferror_count;                     /**< file write/seek error count **/
589         GstClockTime previous_slot_time;
590         int display_interval;                   /**< This value is set as 'GST_SECOND / display FPS' */
591         gboolean bget_eos;                      /**< Whether getting EOS */
592         gboolean bencbin_capture;               /**< Use Encodebin for capturing */
593         gboolean audio_disable;                 /**< whether audio is disabled or not when record */
594         int videosrc_rotate;                    /**< rotate of videosrc */
595
596         /* For dropping video frame when start recording */
597         int drop_vframe;                        /**< When this value is bigger than zero and pass_first_vframe is zero, MSL will drop video frame though cam_stability count is bigger then zero. */
598         int pass_first_vframe;                  /**< When this value is bigger than zero, MSL won't drop video frame though "drop_vframe" is bigger then zero. */
599
600         /* INI information */
601         unsigned int fourcc;                    /**< Get fourcc value of camera INI file */
602         _MMCamcorderImageInfo *info_image;      /**< extra information for image capture */
603         _MMCamcorderVideoInfo *info_video;      /**< extra information for video recording */
604         _MMCamcorderAudioInfo *info_audio;      /**< extra information for audio recording */
605
606         _MMCamcorderGstElement *element;        /**< array of preview element */
607         _MMCamcorderGstElement *encode_element; /**< array of encode element */
608         _MMCamcorderKPIMeasure kpi;             /**< information related with performance measurement */
609
610         type_element *VideosinkElement;         /**< configure data of videosink element */
611         type_element *VideoconvertElement;      /**< configure data of videoconvert element */
612         gboolean SensorEncodedCapture;          /**< whether camera sensor support encoded image capture */
613         gboolean internal_encode;               /**< whether use internal encoding function */
614 } _MMCamcorderSubContext;
615
616 /**
617   * _MMCamcorderContext
618   */
619 typedef struct mmf_camcorder {
620         /* information */
621         int type;               /**< mmcamcorder_mode_type */
622         int device_type;        /**< device type */
623         int state;              /**< state of camcorder */
624         int target_state;       /**< Target state that want to set. This is a flag that
625                                    * stands for async state changing. If this value differ from state,
626                                    * it means state is changing now asychronously. */
627
628         /* handles */
629         MMHandleType attributes;               /**< Attribute handle */
630         _MMCamcorderSubContext *sub_context;   /**< sub context */
631         mm_exif_info_t *exif_info;             /**< EXIF */
632         GList *buffer_probes;                  /**< a list of buffer probe handle */
633         GList *event_probes;                   /**< a list of event probe handle */
634         GList *signals;                        /**< a list of signal handle */
635         GList *msg_data;                       /**< a list of msg data */
636         camera_conf *conf_main;                /**< Camera configure Main structure */
637         camera_conf *conf_ctrl;                /**< Camera configure Control structure */
638         int asm_handle;                        /**< Audio session manager handle */
639         guint pipeline_cb_event_id;            /**< Event source ID of pipeline message callback */
640         guint encode_pipeline_cb_event_id;     /**< Event source ID of encode pipeline message callback */
641         guint setting_event_id;                /**< Event source ID of attributes setting to sensor */
642         SOUND_INFO snd_info;                   /**< Sound handle for multishot capture */
643
644         /* callback handlers */
645         MMMessageCallback msg_cb;                               /**< message callback */
646         void *msg_cb_param;                                     /**< message callback parameter */
647         mm_camcorder_video_stream_callback vstream_cb;          /**< Video stream callback */
648         void *vstream_cb_param;                                 /**< Video stream callback parameter */
649         mm_camcorder_audio_stream_callback astream_cb;          /**< Audio stream callback */
650         void *astream_cb_param;                                 /**< Audio stream callback parameter */
651         mm_camcorder_video_capture_callback vcapture_cb;        /**< Video capture callback */
652         void *vcapture_cb_param;                                /**< Video capture callback parameter */
653         int (*command)(MMHandleType, int);                      /**< camcorder's command */
654         mm_camcorder_video_frame_render_error_callback render_error_cb; /* video frame render error callback */
655         void* render_error_cb_user_param;                               /* video frame render error callback user parameter */
656
657         /* etc */
658         _MMCamcorderMTSafe mtsafe;                              /**< Thread safe */
659         int state_change_by_system;                             /**< MSL changes its state by itself because of system */
660         int asm_event_code;                                     /**< event code of audio session manager */
661         pthread_mutex_t sound_lock;                             /**< Capture sound mutex */
662         pthread_cond_t sound_cond;                              /**< Capture sound cond */
663         pthread_mutex_t restart_preview_lock;                   /**< Capture sound mutex */
664         int use_zero_copy_format;                               /**< Whether use zero copy format for camera input */
665         int support_media_packet_preview_cb;                   /**< Whether support zero copy format for camera input */
666         int shutter_sound_policy;                               /**< shutter sound policy */
667         int brightness_default;                                 /**< default value of brightness */
668         int brightness_step_denominator;                        /**< denominator of brightness bias step */
669         int support_zsl_capture;                                /**< support Zero Shutter Lag capture */
670         char *model_name;                                       /**< model name from system info */
671         char *software_version;                                 /**< software_version from system info */
672         int capture_sound_count;                                /**< count for capture sound */
673         int asm_register;                                       /**< Use ASM internally */
674         int asm_event_type;                                     /**< Event type of ASM */
675         int asm_session_type;                                   /**< Session type of ASM */
676         int asm_session_options;                                /**< Session option of ASM */
677
678         _MMCamcorderInfoConverting caminfo_convert[CAMINFO_CONVERT_NUM];        /**< converting structure of camera info */
679         _MMCamcorderEnumConvert enum_conv[ENUM_CONVERT_NUM];                    /**< enum converting list that is modified by ini info */
680
681         gboolean capture_in_recording;                          /**< Flag for capture while recording */
682
683         guint64 system_memory;                                  /* system memory size, do not use this size for recording*/
684
685         /* task thread */
686         pthread_t task_thread;                                  /**< thread for task */
687         pthread_mutex_t task_thread_lock;                       /**< mutex for task thread */
688         pthread_cond_t task_thread_cond;                        /**< cond for task thread */
689         _MMCamcorderTaskThreadState task_thread_state;          /**< state of task thread */
690
691         int reserved[4];                                        /**< reserved */
692 } mmf_camcorder_t;
693
694 /*=======================================================================================
695 | EXTERN GLOBAL VARIABLE                                                                |
696 ========================================================================================*/
697
698 /*=======================================================================================
699 | GLOBAL FUNCTION PROTOTYPES                                                            |
700 ========================================================================================*/
701 /**
702  *      This function creates camcorder for capturing still image and recording.
703  *
704  *      @param[out]     handle          Specifies the camcorder  handle
705  *      @param[in]      info            Preset information of camcorder
706  *      @return         This function returns zero on success, or negative value with error code.
707  *      @remarks        When this function calls successfully, camcorder  handle will be filled with a @n
708  *                      valid value and the state of  the camcorder  will become MM_CAMCORDER_STATE_NULL.@n
709  *                      Note that  it's not ready to working camcorder. @n
710  *                      You should call mmcamcorder_realize before starting camcorder.
711  *      @see            _mmcamcorder_create
712  */
713 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info);
714
715 /**
716  *      This function destroys instance of camcorder. 
717  *
718  *      @param[in]      hcamcorder      Specifies the camcorder  handle
719  *      @return         This function returns zero on success, or negative value with error code.
720  *      @see            _mmcamcorder_create
721  */
722 int _mmcamcorder_destroy(MMHandleType hcamcorder);
723
724 /**
725  *      This function allocates memory for camcorder.
726  *
727  *      @param[in]      hcamcorder      Specifies the camcorder  handle
728  *      @return         This function returns zero on success, or negative value with error code.
729  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_NULL @n
730  *                      and  the state of the camcorder  will become MM_CAMCORDER_STATE_READY. @n
731  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
732  *      @see            _mmcamcorder_unrealize
733  *      @pre            MM_CAMCORDER_STATE_NULL
734  *      @post           MM_CAMCORDER_STATE_READY
735  */
736 int _mmcamcorder_realize(MMHandleType hcamcorder);
737
738 /**
739  *      This function free allocated memory for camcorder.
740  *
741  *      @param[in]      hcamcorder      Specifies the camcorder  handle
742  *      @return         This function returns zero on success, or negative value with error code.
743  *      @remarks        This function release all resources which are allocated for the camcorder engine.@n
744  *                      This function can  be called successfully when current state is MM_CAMCORDER_STATE_READY and  @n
745  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_NULL. @n
746  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
747  *      @see            _mmcamcorder_realize
748  *      @pre            MM_CAMCORDER_STATE_READY
749  *      @post           MM_CAMCORDER_STATE_NULL
750  */
751 int _mmcamcorder_unrealize(MMHandleType hcamcorder);
752
753 /**
754  *      This function is to start previewing.
755  *
756  *      @param[in]      hcamcorder      Specifies the camcorder  handle
757  *      @return         This function returns zero on success, or negative value with error code.
758  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_READY and  @n
759  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
760  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
761  *      @see            _mmcamcorder_stop
762  */
763 int _mmcamcorder_start(MMHandleType hcamcorder);
764
765 /**
766  *      This function is to stop previewing.
767  *
768  *      @param[in]      hcamcorder      Specifies the camcorder  handle
769  *      @return         This function returns zero on success, or negative value with error code.
770  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and  @n
771  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_READY.@n
772  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
773  *      @see            _mmcamcorder_start
774  */
775 int _mmcamcorder_stop(MMHandleType hcamcorder);
776
777 /**
778  *      This function to start capturing of still images.
779  *
780  *      @param[in]      hcamcorder      Specifies the camcorder  handle.
781  *      @return         This function returns zero on success, or negative value with error code.
782  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and @n
783  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_CAPTURING. @n
784  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
785  *      @see            _mmcamcorder_capture_stop
786  */
787 int _mmcamcorder_capture_start(MMHandleType hcamcorder);
788
789 /**
790  *      This function is to stop capturing still images.
791  *
792  *      @param[in]      hcamcorder      Specifies the camcorder  handle
793  *      @return         This function returns zero on success, or negative value with error code.
794  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_CAPTURING and @n
795  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
796  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
797  *      @see            _mmcamcorder_capture_start
798  */
799 int _mmcamcorder_capture_stop(MMHandleType hcamcorder);
800
801 /**
802  *      This function is to start  video and audio recording.
803  *
804  *      @param[in]      hcamcorder      Specifies the camcorder  handle
805  *      @return         This function returns zero on success, or negative value with error code.
806  *      @remarks        This function can  be called successfully when current state is @n
807  *                      MM_CAMCORDER_STATE_PREPARE or MM_CAMCORDER_STATE_PAUSED and  @n
808  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_RECORDING.@n
809  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
810  *      @see            _mmcamcorder_pause
811  */
812 int _mmcamcorder_record(MMHandleType hcamcorder);
813
814 /**
815  *      This function is to pause video and audio recording
816  *
817  *      @param[in]      hcamcorder      Specifies the camcorder  handle
818  *      @return         This function returns zero on success, or negative value with error code.
819  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_RECORDING and  @n
820  *                      the  state of the camcorder  will become MM_CAMCORDER_STATE_PAUSED.@n
821  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.@n
822  *      @see            _mmcamcorder_record
823  */
824 int _mmcamcorder_pause(MMHandleType hcamcorder);
825
826 /**
827  *      This function is to stop video and audio  recording and  save results.
828  *
829  *      @param[in]      hcamcorder      Specifies the camcorder  handle
830  *      @return         This function returns zero on success, or negative value with error code.
831  *      @remarks        This function can  be called successfully when current state is @n
832  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
833  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
834  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION
835  *      @see            _mmcamcorder_cancel
836  */
837 int _mmcamcorder_commit(MMHandleType hcamcorder);
838
839 /**
840  *      This function is to stop video and audio recording and do not save results.
841  *
842  *      @param[in]      hcamcorder      Specifies the camcorder  handle
843  *      @return         This function returns zero on success, or negative value with error code.
844  *      @remarks        This function can  be called successfully when current state is @n
845  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
846  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
847  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
848  *      @see            _mmcamcorder_commit
849  */
850 int _mmcamcorder_cancel(MMHandleType hcamcorder);
851
852 /**
853  *      This function calls after commiting action finished asynchronously. 
854  *      In this function, remaining process , such as state change, happens.
855  *
856  *      @param[in]      hcamcorder      Specifies the camcorder  handle
857  *      @return         This function returns zero on success, or negative value with error code.
858  *      @remarks        This function can  be called successfully when current state is @n
859  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
860  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
861  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
862  *      @see            _mmcamcorder_commit
863  */
864 int _mmcamcorder_commit_async_end(MMHandleType hcamcorder);
865
866 /**
867  *      This function is to set callback for receiving messages from camcorder.
868  *
869  *      @param[in]      hcamcorder      Specifies the camcorder  handle
870  *      @param[in]      callback        Specifies the function pointer of callback function
871  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
872  *
873  *      @return         This function returns zero on success, or negative value with error code.
874  *      @remarks        typedef bool (*mm_message_callback) (int msg, mm_messageType *param, void *user_param);@n
875  *              @n
876  *              typedef union                           @n
877  *              {                                                       @n
878  *                      int code;                               @n
879  *                      struct                                  @n
880  *                      {                                               @n
881  *                              int total;                      @n
882  *                              int elapsed;            @n
883  *                      } time;                                 @n
884  *                      struct                                  @n
885  *                      {                                               @n
886  *                              int previous;           @n
887  *                              int current;                    @n
888  *                      } state;                                        @n
889  *              } mm_message_type;      @n
890  *                                                                      @n
891  *              If a  message value for mm_message_callback is MM_MESSAGE_STATE_CHANGED, @n
892  *              state value in mm_message_type  will be a mmcamcorder_state_type enum value;@n
893  *              @n
894  *              If  a message value for mm_message_callback is MM_MESSAGE_ERROR,  @n
895  *              the code value in mm_message_type will be a mmplayer_error_type enum value;
896  *
897  *      @see            mm_message_type,  mmcamcorder_state_type,  mmcamcorder_error_type
898  */
899 int _mmcamcorder_set_message_callback(MMHandleType hcamcorder,
900                                       MMMessageCallback callback,
901                                       void *user_data);
902
903 /**
904  *      This function is to set callback for video stream.
905  *
906  *      @param[in]      hcamcorder      Specifies the camcorder  handle
907  *      @param[in]      callback        Specifies the function pointer of callback function
908  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
909  *
910  *      @return         This function returns zero on success, or negative value with error code.
911  *      @see            mmcamcorder_error_type
912  */
913 int _mmcamcorder_set_video_stream_callback(MMHandleType hcamcorder,
914                                            mm_camcorder_video_stream_callback callback,
915                                            void *user_data);
916
917
918 /**
919  *      This function is to set callback for video frame render error.
920  *
921  *      @param[in]      hcamcorder      Specifies the camcorder  handle
922  *      @param[in]      callback        Specifies the function pointer of callback function
923  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
924  *
925  *      @return         This function returns zero on success, or negative value with error code.
926  *      @see            mmcamcorder_error_type
927  */
928 int _mmcamcorder_set_video_frame_render_error_callback(MMHandleType handle,
929                                                        mm_camcorder_video_frame_render_error_callback callback,
930                                                        void *user_data);
931
932 /**
933  *      This function is to set callback for audio stream.
934  *
935  *      @param[in]      hcamcorder      Specifies the camcorder handle
936  *      @param[in]      callback        Specifies the function pointer of callback function
937  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
938  *
939  *      @return         This function returns zero on success, or negative value with error code.
940  *      @see            mmcamcorder_error_type
941  */
942 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle,
943                                            mm_camcorder_audio_stream_callback callback,
944                                            void *user_data);
945
946 /**
947  *      This function is to set callback for video capture.
948  *
949  *      @param[in]      hcamcorder      Specifies the camcorder  handle
950  *      @param[in]      callback        Specifies the function pointer of callback function
951  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
952  *
953  *      @return         This function returns zero on success, or negative value with error code.
954  *      @see            mmcamcorder_error_type
955  */
956 int _mmcamcorder_set_video_capture_callback(MMHandleType hcamcorder,
957                                             mm_camcorder_video_capture_callback callback,
958                                             void *user_data);
959
960 /**
961  *      This function returns current state of camcorder, or negative value with error code.
962  *
963  *      @param[in]      hcamcorder      Specifies the camcorder  handle.
964  *      @return         This function returns current state of camcorder, or negative value with error code.
965  *      @see            mmcamcorder_state_type
966  */
967 int _mmcamcorder_get_current_state(MMHandleType hcamcorder);
968
969 int _mmcamcorder_init_focusing(MMHandleType handle);
970 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction);
971 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction);
972 int _mmcamcorder_adjust_auto_focus(MMHandleType handle);
973 int _mmcamcorder_stop_focusing(MMHandleType handle);
974
975 /**
976  * This function gets current state of camcorder.
977  *
978  * @param       void
979  * @return      This function returns state of current camcorder context
980  * @remarks
981  * @see         _mmcamcorder_set_state()
982  *
983  */
984 int _mmcamcorder_streamer_init(void);
985
986 /**
987  * This function gets current state of camcorder.
988  *
989  * @param       void
990  * @return      This function returns state of current camcorder context
991  * @remarks
992  * @see         _mmcamcorder_set_state()
993  *
994  */
995 int _mmcamcorder_display_init(void);
996
997 /**
998  * This function gets current state of camcorder.
999  *
1000  * @param[in]   handle          Handle of camcorder context.
1001  * @return      This function returns state of current camcorder context
1002  * @remarks
1003  * @see         _mmcamcorder_set_state()
1004  *
1005  */
1006 int _mmcamcorder_get_state(MMHandleType handle);
1007
1008 /**
1009  * This function sets new state of camcorder.
1010  *
1011  * @param[in]   handle          Handle of camcorder context.
1012  * @param[in]   state           setting state value of camcorder.
1013  * @return      void
1014  * @remarks
1015  * @see         _mmcamcorder_get_state()
1016  *
1017  */
1018 void _mmcamcorder_set_state(MMHandleType handle, int state);
1019
1020 /**
1021  * This function gets asynchronous status of MSL Camcroder. 
1022  *
1023  * @param[in]   handle          Handle of camcorder context.
1024  * @param[in]   target_state    setting target_state value of camcorder.
1025  * @return      This function returns asynchrnous state.
1026  * @remarks
1027  * @see         _mmcamcorder_set_async_state()
1028  *
1029  */
1030 int _mmcamcorder_get_async_state(MMHandleType handle);
1031
1032 /**
1033  * This function allocates structure of subsidiary attributes.
1034  *
1035  * @param[in]   type            Allocation type of camcorder context.
1036  * @return      This function returns structure pointer on success, NULL value on failure.
1037  * @remarks
1038  * @see         _mmcamcorder_dealloc_subcontext()
1039  *
1040  */
1041 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type);
1042
1043 /**
1044  * This function releases structure of subsidiary attributes.
1045  *
1046  * @param[in]   sc              Handle of camcorder subcontext.
1047  * @return      void
1048  * @remarks
1049  * @see         _mmcamcorder_alloc_subcontext()
1050  *
1051  */
1052 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc);
1053
1054 /**
1055  * This function sets command function according to the type.
1056  *
1057  * @param[in]   handle          Handle of camcorder context.
1058  * @param[in]   type            Allocation type of camcorder context.
1059  * @return      This function returns MM_ERROR_NONE on success, or other values with error code.
1060  * @remarks
1061  * @see         __mmcamcorder_video_command(), __mmcamcorder_audio_command(), __mmcamcorder_image_command()
1062  *
1063  */
1064 int _mmcamcorder_set_functions(MMHandleType handle, int type);
1065
1066 /**
1067  * This function is callback function of main pipeline.
1068  * Once this function is registered with certain pipeline using gst_bus_add_watch(),
1069  * this callback will be called every time when there is upcomming message from pipeline.
1070  * Basically, this function is used as error handling function, now.
1071  *
1072  * @param[in]   bus             pointer of buf that called this function.
1073  * @param[in]   message         callback message from pipeline.
1074  * @param[in]   data            user data.
1075  * @return      This function returns true on success, or false value with error
1076  * @remarks
1077  * @see         __mmcamcorder_create_preview_pipeline()
1078  *
1079  */
1080 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data);
1081
1082 /**
1083  * This function is callback function of main pipeline.
1084  * Once this function is registered with certain pipeline using gst_bus_set_sync_handler(),
1085  * this callback will be called every time when there is upcomming message from pipeline.
1086  * Basically, this function is used as sync error handling function, now.
1087  *
1088  * @param[in]   bus             pointer of buf that called this function.
1089  * @param[in]   message         callback message from pipeline.
1090  * @param[in]   data            user data.
1091  * @return      This function returns true on success, or false value with error
1092  * @remarks
1093  * @see         __mmcamcorder_create_preview_pipeline()
1094  *
1095  */
1096 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data);
1097
1098 /**
1099  * This function is callback function of main pipeline.
1100  * Once this function is registered with certain pipeline using gst_bus_set_sync_handler(),
1101  * this callback will be called every time when there is upcomming message from pipeline.
1102  * Basically, this function is used as sync error handling function, now.
1103  *
1104  * @param[in]   bus             pointer of buf that called this function.
1105  * @param[in]   message         callback message from pipeline.
1106  * @param[in]   data            user data.
1107  * @return      This function returns true on success, or false value with error
1108  * @remarks
1109  * @see         __mmcamcorder_create_audiop_with_encodebin()
1110  *
1111  */
1112 GstBusSyncReply _mmcamcorder_audio_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data);
1113
1114
1115 /**
1116  * This function create main pipeline according to type.
1117  *
1118  * @param[in]   handle          Handle of camcorder context.
1119  * @param[in]   type            Allocation type of camcorder context.
1120  * @return      This function returns zero on success, or negative value with error code.
1121  * @remarks
1122  * @see         _mmcamcorder_destroy_pipeline()
1123  *
1124  */
1125 int _mmcamcorder_create_pipeline(MMHandleType handle, int type);
1126
1127 /**
1128  * This function release all element of main pipeline according to type.
1129  *
1130  * @param[in]   handle          Handle of camcorder context.
1131  * @param[in]   type            Allocation type of camcorder context.
1132  * @return      void
1133  * @remarks
1134  * @see         _mmcamcorder_create_pipeline()
1135  *
1136  */
1137 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type);
1138
1139 /**
1140  * This function sets gstreamer element status. 
1141  * If the gstreamer fails to set status or returns asynchronous mode,
1142  * this function waits for state changed until timeout expired.
1143  *
1144  * @param[in]   pipeline        Pointer of pipeline
1145  * @param[in]   target_state    newly setting status
1146  * @return      This function returns zero on success, or negative value with error code.
1147  * @remarks
1148  * @see
1149  *
1150  */
1151 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state);
1152
1153 /**
1154  * This function sets gstreamer element status, asynchronously. 
1155  * Regardless of processing, it returns immediately.
1156  *
1157  * @param[in]   pipeline        Pointer of pipeline
1158  * @param[in]   target_state    newly setting status
1159  * @return      This function returns zero on success, or negative value with error code.
1160  * @remarks
1161  * @see 
1162  *
1163  */
1164 int _mmcamcorder_gst_set_state_async(MMHandleType handle, GstElement *pipeline, GstState target_state);
1165
1166 /* For xvimagesink */
1167 GstBusSyncReply __mmcamcorder_sync_callback(GstBus *bus, GstMessage *message, gulong data);
1168
1169 /* For querying capabilities */
1170 int _mmcamcorder_read_vidsrc_info(int videodevidx, camera_conf **configure_info);
1171
1172 /* for performance check */
1173 void _mmcamcorder_video_current_framerate_init(MMHandleType handle);
1174 int _mmcamcorder_video_current_framerate(MMHandleType handle);
1175 int _mmcamcorder_video_average_framerate(MMHandleType handle);
1176
1177 #ifdef __cplusplus
1178 }
1179 #endif
1180
1181 #endif /* __MM_CAMCORDER_INTERNAL_H__ */