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