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