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