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