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