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