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