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