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