Support video scaling for video 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_message.h>
36 #include <vconf.h>
37 #include <gst/video/video-format.h>
38 #include <ttrace.h>
39 #include <errno.h>
40 #include <restriction.h> /* device policy manager */
41 #include <dlog.h>
42
43 #include "mm_camcorder.h"
44
45 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
46 #include <mm_resource_manager.h>
47 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
48
49 /* camcorder sub module */
50 #include "mm_camcorder_attribute.h"
51 #include "mm_camcorder_platform.h"
52 #include "mm_camcorder_stillshot.h"
53 #include "mm_camcorder_videorec.h"
54 #include "mm_camcorder_audiorec.h"
55 #include "mm_camcorder_gstcommon.h"
56 #include "mm_camcorder_exifinfo.h"
57 #include "mm_camcorder_util.h"
58 #include "mm_camcorder_configure.h"
59 #include "mm_camcorder_sound.h"
60
61 #ifdef _MMCAMCORDER_RM_SUPPORT
62 /* rm (resource manager)*/
63 #include <rm_api.h>
64 #endif /* _MMCAMCORDER_RM_SUPPORT */
65
66 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
67 #include "camera_conf_mgr.h"
68 #endif /*_MMCAMCORDER_CAMERA_CONF_MGR_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 interruption */
399 #define _MMCAMCORDER_GET_INTERRUPT_LOCK(handle)           (_MMCAMCORDER_CAST_MTSAFE(handle).interrupt_lock)
400 #define _MMCAMCORDER_LOCK_INTERRUPT(handle)               _MMCAMCORDER_LOCK_FUNC(_MMCAMCORDER_GET_INTERRUPT_LOCK(handle))
401 #define _MMCAMCORDER_TRYLOCK_INTERRUPT(handle)            _MMCAMCORDER_TRYLOCK_FUNC(_MMCAMCORDER_GET_INTERRUPT_LOCK(handle))
402 #define _MMCAMCORDER_UNLOCK_INTERRUPT(handle)             _MMCAMCORDER_UNLOCK_FUNC(_MMCAMCORDER_GET_INTERRUPT_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 #define _MMCAMCORDER_GET_VEDECISION_CALLBACK_LOCK(handle)   (_MMCAMCORDER_CAST_MTSAFE(handle).vedecision_cb_lock)
448 #define _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(handle)       _MMCAMCORDER_LOCK_FUNC(_MMCAMCORDER_GET_VEDECISION_CALLBACK_LOCK(handle))
449 #define _MMCAMCORDER_TRYLOCK_VEDECISION_CALLBACK(handle)    _MMCAMCORDER_TRYLOCK_FUNC(_MMCAMCORDER_GET_VEDECISION_CALLBACK_LOCK(handle))
450 #define _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(handle)     _MMCAMCORDER_UNLOCK_FUNC(_MMCAMCORDER_GET_VEDECISION_CALLBACK_LOCK(handle))
451
452 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
453 /* for resource conflict */
454 #define _MMCAMCORDER_GET_RESOURCE_LOCK(handle)              (_MMCAMCORDER_CAST_MTSAFE(handle).resource_lock)
455 #define _MMCAMCORDER_LOCK_RESOURCE(handle)                  _MMCAMCORDER_LOCK_FUNC(_MMCAMCORDER_GET_RESOURCE_LOCK(handle))
456 #define _MMCAMCORDER_UNLOCK_RESOURCE(handle)                _MMCAMCORDER_UNLOCK_FUNC(_MMCAMCORDER_GET_RESOURCE_LOCK(handle))
457 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
458
459 /**
460  * Caster of main handle (camcorder)
461  */
462 #define MMF_CAMCORDER(h) (mmf_camcorder_t *)(h)
463
464 /**
465  * Caster of subcontext
466  */
467 #define MMF_CAMCORDER_SUBCONTEXT(h) (((mmf_camcorder_t *)(h))->sub_context)
468
469 /* LOCAL CONSTANT DEFINITIONS */
470 /**
471  * Total Numbers of Attribute values.
472  * If you increase any enum of attribute values, you also have to increase this.
473  */
474 #define MM_CAMCORDER_MODE_NUM                   3       /**< Number of mode type */
475 #define MM_CAMCORDER_COLOR_TONE_NUM             30      /**< Number of color-tone modes */
476 #define MM_CAMCORDER_WHITE_BALANCE_NUM          10      /**< Number of WhiteBalance modes*/
477 #define MM_CAMCORDER_SCENE_MODE_NUM             16      /**< Number of program-modes */
478 #define MM_CAMCORDER_FOCUS_MODE_NUM             6       /**< Number of focus mode*/
479 #define MM_CAMCORDER_AUTO_FOCUS_NUM             5       /**< Total count of auto focus type*/
480 #define MM_CAMCORDER_FOCUS_STATE_NUM            4       /**< Number of focus state */
481 #define MM_CAMCORDER_ISO_NUM                    10      /**< Number of ISO */
482 #define MM_CAMCORDER_AUTO_EXPOSURE_NUM          9       /**< Number of Auto exposure type */
483 #define MM_CAMCORDER_WDR_NUM                    3       /**< Number of wide dynamic range */
484 #define MM_CAMCORDER_FLIP_NUM                   4       /**< Number of Filp mode */
485 #define MM_CAMCORDER_ROTATION_NUM               4       /**< Number of Rotation mode */
486 #define MM_CAMCORDER_AHS_NUM                    4       /**< Number of anti-handshake */
487 #define MM_CAMCORDER_VIDEO_STABILIZATION_NUM    2       /**< Number of video stabilization */
488 #define MM_CAMCORDER_HDR_CAPTURE_NUM            3       /**< Number of HDR capture mode */
489 #define MM_CAMCORDER_GEOMETRY_METHOD_NUM        5       /**< Number of geometry method */
490 #define MM_CAMCORDER_TAG_ORT_NUM                8       /**< Number of tag orientation */
491 #define MM_CAMCORDER_STROBE_MODE_NUM            8       /**< Number of strobe mode type */
492 #define MM_CAMCORDER_STROBE_CONTROL_NUM         3       /**< Number of strobe control type */
493 #define MM_CAMCORDER_DETECT_MODE_NUM            2       /**< Number of detect mode type */
494
495 /*=======================================================================================
496 | ENUM DEFINITIONS                                                                      |
497 ========================================================================================*/
498 /**
499  * Command for Camcorder.
500  */
501 enum {
502         /* Command for Video/Audio recording */
503         _MMCamcorder_CMD_RECORD,
504         _MMCamcorder_CMD_PAUSE,
505         _MMCamcorder_CMD_CANCEL,
506         _MMCamcorder_CMD_COMMIT,
507
508         /* Command for Image capture */
509         _MMCamcorder_CMD_CAPTURE,
510
511         /* Command for Preview(Video/Image only effective) */
512         _MMCamcorder_CMD_PREVIEW_START,
513         _MMCamcorder_CMD_PREVIEW_STOP,
514 };
515
516 /**
517  * Still-shot type
518  */
519 enum {
520         _MMCamcorder_SINGLE_SHOT,
521         _MMCamcorder_MULTI_SHOT,
522 };
523
524 /**
525  * Enumerations for manual focus direction.
526  * If focusing mode is not "MM_CAMCORDER_AF_MODE_MANUAL", this value will be ignored.
527  */
528 enum MMCamcorderMfLensDir {
529         MM_CAMCORDER_MF_LENS_DIR_FORWARD = 1,   /**< Focus direction to forward */
530         MM_CAMCORDER_MF_LENS_DIR_BACKWARD,      /**< Focus direction to backward */
531         MM_CAMCORDER_MF_LENS_DIR_NUM,           /**< Total number of the directions */
532 };
533
534 /**
535  * Camcorder Pipeline's Element name.
536  * @note index of element.
537  */
538 typedef enum {
539         _MMCAMCORDER_NONE = (-1),
540
541         /* Main Pipeline Element */
542         _MMCAMCORDER_MAIN_PIPE = 0x00,
543
544         /* Pipeline element of Video input */
545         _MMCAMCORDER_VIDEOSRC_SRC,
546         _MMCAMCORDER_VIDEOSRC_FILT,
547         _MMCAMCORDER_VIDEOSRC_CLS_QUE,
548         _MMCAMCORDER_VIDEOSRC_CLS,
549         _MMCAMCORDER_VIDEOSRC_CLS_FILT,
550         _MMCAMCORDER_VIDEOSRC_QUE,
551         _MMCAMCORDER_VIDEOSRC_DECODE,
552
553         /* Pipeline element of Video output */
554         _MMCAMCORDER_VIDEOSINK_QUE,
555         _MMCAMCORDER_VIDEOSINK_CLS,
556         _MMCAMCORDER_VIDEOSINK_SINK,
557
558         _MMCAMCORDER_PIPELINE_ELEMENT_NUM,
559 } _MMCAMCORDER_PREVIEW_PIPELINE_ELELMENT;
560
561 /**
562  * Camcorder Pipeline's Element name.
563  * @note index of element.
564  */
565 typedef enum {
566         _MMCAMCORDER_ENCODE_NONE = (-1),
567
568         /* Main Pipeline Element */
569         _MMCAMCORDER_ENCODE_MAIN_PIPE = 0x00,
570
571         /* Pipeline element of Audio input */
572         _MMCAMCORDER_AUDIOSRC_BIN,
573         _MMCAMCORDER_AUDIOSRC_SRC,
574         _MMCAMCORDER_AUDIOSRC_FILT,
575         _MMCAMCORDER_AUDIOSRC_QUE,
576         _MMCAMCORDER_AUDIOSRC_CONV,
577         _MMCAMCORDER_AUDIOSRC_VOL,
578         _MMCAMCORDER_AUDIOSRC_RGA,      /* for replay gain analysis element */
579
580         /* Pipeline element of Encodebin */
581         _MMCAMCORDER_ENCSINK_BIN,
582         _MMCAMCORDER_ENCSINK_SRC,
583         _MMCAMCORDER_ENCSINK_FILT,
584         _MMCAMCORDER_ENCSINK_ENCBIN,
585         _MMCAMCORDER_ENCSINK_AQUE,
586         _MMCAMCORDER_ENCSINK_CONV,
587         _MMCAMCORDER_ENCSINK_AENC,
588         _MMCAMCORDER_ENCSINK_AENC_QUE,
589         _MMCAMCORDER_ENCSINK_VQUE,
590         _MMCAMCORDER_ENCSINK_VSCALE,
591         _MMCAMCORDER_ENCSINK_VSCALE_FILT,
592         _MMCAMCORDER_ENCSINK_VCONV,
593         _MMCAMCORDER_ENCSINK_VENC,
594         _MMCAMCORDER_ENCSINK_VENC_QUE,
595         _MMCAMCORDER_ENCSINK_ITOG,
596         _MMCAMCORDER_ENCSINK_ICROP,
597         _MMCAMCORDER_ENCSINK_ISCALE,
598         _MMCAMCORDER_ENCSINK_IFILT,
599         _MMCAMCORDER_ENCSINK_IQUE,
600         _MMCAMCORDER_ENCSINK_IENC,
601         _MMCAMCORDER_ENCSINK_MUX,
602         _MMCAMCORDER_ENCSINK_SINK,
603
604         _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM,
605 } _MMCAMCORDER_ENCODE_PIPELINE_ELELMENT;
606
607 typedef enum {
608         _MMCAMCORDER_TASK_THREAD_STATE_NONE,
609         _MMCAMCORDER_TASK_THREAD_STATE_SOUND_PLAY_START,
610         _MMCAMCORDER_TASK_THREAD_STATE_SOUND_SOLO_PLAY_START,
611         _MMCAMCORDER_TASK_THREAD_STATE_ENCODE_PIPE_CREATE,
612         _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING,
613         _MMCAMCORDER_TASK_THREAD_STATE_EXIT,
614 } _MMCamcorderTaskThreadState;
615
616 /**
617  * System state change cause
618  */
619 typedef enum {
620         _MMCAMCORDER_STATE_CHANGE_NORMAL = 0,
621         _MMCAMCORDER_STATE_CHANGE_BY_RM,
622         _MMCAMCORDER_STATE_CHANGE_BY_DPM,
623         _MMCAMCORDER_STATE_CHANGE_BY_STORAGE
624 } _MMCamcorderStateChange;
625
626
627 /*=======================================================================================
628 | STRUCTURE DEFINITIONS                                                                 |
629 ========================================================================================*/
630 /**
631  * MMCamcorder Gstreamer Element
632  */
633 typedef struct {
634         unsigned int id;                /**< Gstreamer piplinem element name */
635         GstElement *gst;                /**< Gstreamer element */
636 } _MMCamcorderGstElement;
637
638 /**
639  * MMCamcorder information for KPI measurement
640  */
641 typedef struct {
642         int current_fps;                /**< current fps of this second */
643         int average_fps;                /**< average fps  */
644         unsigned int video_framecount;  /**< total number of video frame */
645         unsigned int last_framecount;   /**< total number of video frame in last measurement */
646         struct timeval init_video_time; /**< time when start to measure */
647         struct timeval last_video_time; /**< last measurement time */
648 } _MMCamcorderKPIMeasure;
649
650 /**
651  * MMCamcorder information for Multi-Thread Safe
652  */
653 typedef struct {
654         GMutex lock;                    /**< Mutex (for general use) */
655         GCond cond;                     /**< Condition (for general use) */
656         GMutex cmd_lock;                /**< Mutex (for command) */
657         GCond cmd_cond;                 /**< Condition (for command) */
658         GMutex interrupt_lock;          /**< Mutex (for interruption) */
659         GMutex state_lock;              /**< Mutex (for state change) */
660         GMutex gst_state_lock;          /**< Mutex (for gst pipeline state change) */
661         GMutex gst_encode_state_lock;   /**< Mutex (for gst encode pipeline state change) */
662         GMutex message_cb_lock;         /**< Mutex (for message callback) */
663         GMutex vcapture_cb_lock;        /**< Mutex (for video capture callback) */
664         GMutex vstream_cb_lock;         /**< Mutex (for video stream callback) */
665         GMutex astream_cb_lock;         /**< Mutex (for audio stream callback) */
666         GMutex mstream_cb_lock;         /**< Mutex (for muxed stream callback) */
667         GMutex vedecision_cb_lock;      /**< Mutex (for video encode decision callback) */
668 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
669         GMutex resource_lock;           /**< Mutex (for resource check) */
670 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
671 } _MMCamcorderMTSafe;
672
673 /**
674  * MMCamcorder Replay gain value
675  */
676 typedef struct {
677         gdouble track_peak;
678         gdouble track_gain;
679         gdouble album_peak;
680         gdouble album_gain;
681 } _MMCamcorderReplayGain;
682
683 /**
684  * MMCamcorder Sub Context
685  */
686 typedef struct {
687         bool isMaxsizePausing;                  /**< Because of size limit, pipeline is paused. */
688         bool isMaxtimePausing;                  /**< Because of time limit, pipeline is paused. */
689         int element_num;                        /**< count of element */
690         int encode_element_num;                 /**< count of encode element */
691         int frame_stability_count;              /**< camsensor stability count. the count of frame will drop */
692         GstClockTime pipeline_time;             /**< current time of Gstreamer Pipeline */
693         GstClockTime pause_time;                /**< amount of time while pipeline is in PAUSE state.*/
694         GstClockTime stillshot_time;            /**< pipeline time of capturing moment*/
695         gboolean is_modified_rate;              /**< whether recording motion rate is modified or not */
696         gboolean ferror_send;                   /**< file write/seek error **/
697         guint ferror_count;                     /**< file write/seek error count **/
698         GstClockTime previous_slot_time;
699         int display_interval;                   /**< This value is set as 'GST_SECOND / display FPS' */
700         gboolean bget_eos;                      /**< Whether getting EOS */
701         gboolean bencbin_capture;               /**< Use Encodebin for capturing */
702         gboolean audio_disable;                 /**< whether audio is disabled or not when record */
703         int videosrc_rotate;                    /**< rotate of videosrc */
704         unsigned long long muxed_stream_offset; /**< current offset for muxed stream data */
705
706         /* For dropping video frame when start recording */
707         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. */
708         int pass_first_vframe;                  /**< When this value is bigger than zero, MSL won't drop video frame though "drop_vframe" is bigger then zero. */
709
710         /* Replay gain */
711         _MMCamcorderReplayGain replay_gain;     /**< Replay gain for audio recording */
712
713         /* INI information */
714         unsigned int fourcc;                    /**< Get fourcc value of camera INI file */
715         _MMCamcorderImageInfo *info_image;      /**< extra information for image capture */
716         _MMCamcorderVideoInfo *info_video;      /**< extra information for video recording */
717         _MMCamcorderAudioInfo *info_audio;      /**< extra information for audio recording */
718
719         _MMCamcorderGstElement *element;        /**< array of preview element */
720         _MMCamcorderGstElement *encode_element; /**< array of encode element */
721         _MMCamcorderKPIMeasure kpi;             /**< information related with performance measurement */
722
723         type_element *VideosinkElement;         /**< configure data of videosink element */
724         type_element *VideoconvertElement;      /**< configure data of videoconvert element */
725         type_element *VideodecoderElementH264;  /**< configure data of video decoder element for H.264 format */
726         gboolean SensorEncodedCapture;          /**< whether camera sensor support encoded image capture */
727         gboolean internal_encode;               /**< whether use internal encoding function */
728 } _MMCamcorderSubContext;
729
730 /**
731   * _MMCamcorderContext
732   */
733 typedef struct mmf_camcorder {
734         /* information */
735         int type;               /**< mmcamcorder_mode_type */
736         int device_type;        /**< device type */
737         int state;              /**< state of camcorder */
738         int old_state;          /**< old state of camcorder */
739
740         /* handles */
741         MMHandleType attributes;               /**< Attribute handle */
742         _MMCamcorderSubContext *sub_context;   /**< sub context */
743         mm_exif_info_t *exif_info;             /**< EXIF */
744         GList *buffer_probes;                  /**< a list of buffer probe handle */
745         GList *event_probes;                   /**< a list of event probe handle */
746         GList *signals;                        /**< a list of signal handle */
747 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
748         GList *msg_data;                       /**< a list of msg data */
749 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
750         camera_conf *conf_main;                /**< Camera configure Main structure */
751         camera_conf *conf_ctrl;                /**< Camera configure Control structure */
752 #ifdef _MMCAMCORDER_RM_SUPPORT
753         int rm_handle;                        /**< Resource manager handle */
754 #endif /* _MMCAMCORDER_RM_SUPPORT */
755         guint pipeline_cb_event_id;            /**< Event source ID of pipeline message callback */
756         guint encode_pipeline_cb_event_id;     /**< Event source ID of encode pipeline message callback */
757         guint setting_event_id;                /**< Event source ID of attributes setting to sensor */
758         SOUND_INFO snd_info;                   /**< Sound handle for multishot capture */
759
760         /* callback handlers */
761         MMMessageCallback msg_cb;                               /**< message callback */
762         void *msg_cb_param;                                     /**< message callback parameter */
763         mm_camcorder_video_stream_callback vstream_cb;          /**< Video stream callback */
764         void *vstream_cb_param;                                 /**< Video stream callback parameter */
765         mm_camcorder_audio_stream_callback astream_cb;          /**< Audio stream callback */
766         void *astream_cb_param;                                 /**< Audio stream callback parameter */
767         mm_camcorder_muxed_stream_callback mstream_cb;          /**< Muxed stream callback */
768         void *mstream_cb_param;                                 /**< Muxed stream callback parameter */
769         mm_camcorder_video_capture_callback vcapture_cb;        /**< Video capture callback */
770         void *vcapture_cb_param;                                /**< Video capture callback parameter */
771         mm_camcorder_video_encode_decision_callback vedecision_cb; /**< Video encode decision callback */
772         void *vedecision_cb_param;                                 /**< Video encode decision callback parameter */
773         int (*command)(MMHandleType, int);                      /**< camcorder's command */
774
775         /* etc */
776         mm_cam_attr_construct_info *cam_attrs_const_info;       /**< attribute info */
777         conf_info_table *conf_main_info_table[CONFIGURE_CATEGORY_MAIN_NUM]; /** configure info table - MAIN category */
778         conf_info_table *conf_ctrl_info_table[CONFIGURE_CATEGORY_CTRL_NUM]; /** configure info table - CONTROL category */
779         int conf_main_category_size[CONFIGURE_CATEGORY_MAIN_NUM]; /** configure info table size - MAIN category */
780         int conf_ctrl_category_size[CONFIGURE_CATEGORY_CTRL_NUM]; /** configure info table size - CONTROL category */
781         _MMCamcorderMTSafe mtsafe;                              /**< Thread safe */
782         int state_change_by_system;                             /**< MSL changes its state by itself because of system */
783         GMutex restart_preview_lock;                            /**< Capture sound mutex */
784         int use_zero_copy_format;                               /**< Whether use zero copy format for camera input */
785         int use_videoconvert;                                   /**< Whether use videoconvert element for display */
786         int support_media_packet_preview_cb;                    /**< Whether support zero copy format for camera input */
787         int support_user_buffer;                                /**< Whether support user allocated buffer for zero copy */
788         int shutter_sound_policy;                               /**< shutter sound policy */
789         int brightness_default;                                 /**< default value of brightness */
790         int brightness_step_denominator;                        /**< denominator of brightness bias step */
791         int support_zsl_capture;                                /**< support Zero Shutter Lag capture */
792         char *model_name;                                       /**< model name from system info */
793         char *software_version;                                 /**< software_version from system info */
794         int capture_sound_count;                                /**< count for capture sound */
795         char *root_directory;                                   /**< Root directory for device */
796         int resolution_changed;                                 /**< Flag for preview resolution change */
797         int interrupt_code;                                     /**< Interrupt code */
798         int recreate_decoder;                                   /**< Flag of decoder element recreation for encoded preview format */
799
800         _MMCamcorderInfoConverting caminfo_convert[CAMINFO_CONVERT_NUM];        /**< converting structure of camera info */
801         _MMCamcorderEnumConvert enum_conv[ENUM_CONVERT_NUM];                    /**< enum converting list that is modified by ini info */
802
803         gboolean capture_in_recording;                          /**< Flag for capture while recording */
804
805         gboolean error_occurs;                                  /**< flag for error */
806         int error_code;                                         /**< error code for internal gstreamer error */
807
808         /* task thread */
809         GThread *task_thread;                                   /**< thread for task */
810         GMutex task_thread_lock;                                /**< mutex for task thread */
811         GCond task_thread_cond;                                 /**< cond for task thread */
812         _MMCamcorderTaskThreadState task_thread_state;          /**< state of task thread */
813
814 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
815         /* resource manager for H/W resources */
816         mm_resource_manager_h resource_manager;
817         mm_resource_manager_res_h camera_resource;
818         mm_resource_manager_res_h video_overlay_resource;
819         mm_resource_manager_res_h video_encoder_resource;
820         gboolean is_release_cb_calling;
821 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
822
823         /* gdbus */
824         GDBusConnection *gdbus_conn;                            /**< gdbus connection */
825         _MMCamcorderGDbusCbInfo gdbus_info_sound;               /**< Informations for the gbus cb of sound play */
826         _MMCamcorderGDbusCbInfo gdbus_info_solo_sound;          /**< Informations for the gbus cb of solo sound play */
827
828         /* DPM(device policy manager) */
829         device_policy_manager_h dpm_handle;                     /**< DPM handle */
830         int dpm_camera_cb_id;                                   /**< DPM camera policy changed callback id */
831
832         /* Storage */
833         _MMCamcorderStorageInfo storage_info;                   /**< Storage information */
834
835 #ifdef _MMCAMCORDER_RM_SUPPORT
836         rm_category_request_s request_resources;
837         rm_device_return_s returned_devices;
838 #endif /* _MMCAMCORDER_RM_SUPPORT */
839 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
840         camera_conf_device_info_s conf_device_info;
841 #endif /*_MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT */
842         int reserved[4];                                        /**< reserved */
843 } mmf_camcorder_t;
844
845 /*=======================================================================================
846 | EXTERN GLOBAL VARIABLE                                                                |
847 ========================================================================================*/
848
849 /*=======================================================================================
850 | GLOBAL FUNCTION PROTOTYPES                                                            |
851 ========================================================================================*/
852 /**
853  *      This function creates camcorder for capturing still image and recording.
854  *
855  *      @param[out]     handle          Specifies the camcorder  handle
856  *      @param[in]      info            Preset information of camcorder
857  *      @return         This function returns zero on success, or negative value with error code.
858  *      @remarks        When this function calls successfully, camcorder  handle will be filled with a @n
859  *                      valid value and the state of  the camcorder  will become MM_CAMCORDER_STATE_NULL.@n
860  *                      Note that  it's not ready to working camcorder. @n
861  *                      You should call mmcamcorder_realize before starting camcorder.
862  *      @see            _mmcamcorder_create
863  */
864 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info);
865
866 /**
867  *      This function destroys instance of camcorder.
868  *
869  *      @param[in]      hcamcorder      Specifies the camcorder  handle
870  *      @return         This function returns zero on success, or negative value with error code.
871  *      @see            _mmcamcorder_create
872  */
873 int _mmcamcorder_destroy(MMHandleType hcamcorder);
874
875 /**
876  *      This function allocates memory for camcorder.
877  *
878  *      @param[in]      hcamcorder      Specifies the camcorder  handle
879  *      @return         This function returns zero on success, or negative value with error code.
880  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_NULL @n
881  *                      and  the state of the camcorder  will become MM_CAMCORDER_STATE_READY. @n
882  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
883  *      @see            _mmcamcorder_unrealize
884  *      @pre            MM_CAMCORDER_STATE_NULL
885  *      @post           MM_CAMCORDER_STATE_READY
886  */
887 int _mmcamcorder_realize(MMHandleType hcamcorder);
888
889 /**
890  *      This function free allocated memory for camcorder.
891  *
892  *      @param[in]      hcamcorder      Specifies the camcorder  handle
893  *      @return         This function returns zero on success, or negative value with error code.
894  *      @remarks        This function release all resources which are allocated for the camcorder engine.@n
895  *                      This function can  be called successfully when current state is MM_CAMCORDER_STATE_READY and  @n
896  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_NULL. @n
897  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
898  *      @see            _mmcamcorder_realize
899  *      @pre            MM_CAMCORDER_STATE_READY
900  *      @post           MM_CAMCORDER_STATE_NULL
901  */
902 int _mmcamcorder_unrealize(MMHandleType hcamcorder);
903
904 /**
905  *      This function is to start previewing.
906  *
907  *      @param[in]      hcamcorder      Specifies the camcorder  handle
908  *      @return         This function returns zero on success, or negative value with error code.
909  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_READY and  @n
910  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
911  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
912  *      @see            _mmcamcorder_stop
913  */
914 int _mmcamcorder_start(MMHandleType hcamcorder);
915
916 /**
917  *      This function is to stop previewing.
918  *
919  *      @param[in]      hcamcorder      Specifies the camcorder  handle
920  *      @return         This function returns zero on success, or negative value with error code.
921  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and  @n
922  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_READY.@n
923  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
924  *      @see            _mmcamcorder_start
925  */
926 int _mmcamcorder_stop(MMHandleType hcamcorder);
927
928 /**
929  *      This function to start capturing of still images.
930  *
931  *      @param[in]      hcamcorder      Specifies the camcorder  handle.
932  *      @return         This function returns zero on success, or negative value with error code.
933  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and @n
934  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_CAPTURING. @n
935  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
936  *      @see            _mmcamcorder_capture_stop
937  */
938 int _mmcamcorder_capture_start(MMHandleType hcamcorder);
939
940 /**
941  *      This function is to stop capturing still images.
942  *
943  *      @param[in]      hcamcorder      Specifies the camcorder  handle
944  *      @return         This function returns zero on success, or negative value with error code.
945  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_CAPTURING and @n
946  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
947  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
948  *      @see            _mmcamcorder_capture_start
949  */
950 int _mmcamcorder_capture_stop(MMHandleType hcamcorder);
951
952 /**
953  *      This function is to start  video and audio recording.
954  *
955  *      @param[in]      hcamcorder      Specifies the camcorder  handle
956  *      @return         This function returns zero on success, or negative value with error code.
957  *      @remarks        This function can  be called successfully when current state is @n
958  *                      MM_CAMCORDER_STATE_PREPARE or MM_CAMCORDER_STATE_PAUSED and  @n
959  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_RECORDING.@n
960  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
961  *      @see            _mmcamcorder_pause
962  */
963 int _mmcamcorder_record(MMHandleType hcamcorder);
964
965 /**
966  *      This function is to pause video and audio recording
967  *
968  *      @param[in]      hcamcorder      Specifies the camcorder  handle
969  *      @return         This function returns zero on success, or negative value with error code.
970  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_RECORDING and  @n
971  *                      the  state of the camcorder  will become MM_CAMCORDER_STATE_PAUSED.@n
972  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.@n
973  *      @see            _mmcamcorder_record
974  */
975 int _mmcamcorder_pause(MMHandleType hcamcorder);
976
977 /**
978  *      This function is to stop video and audio  recording and  save results.
979  *
980  *      @param[in]      hcamcorder      Specifies the camcorder  handle
981  *      @return         This function returns zero on success, or negative value with error code.
982  *      @remarks        This function can  be called successfully when current state is @n
983  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
984  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
985  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION
986  *      @see            _mmcamcorder_cancel
987  */
988 int _mmcamcorder_commit(MMHandleType hcamcorder);
989
990 /**
991  *      This function is to stop video and audio recording and do not save results.
992  *
993  *      @param[in]      hcamcorder      Specifies the camcorder  handle
994  *      @return         This function returns zero on success, or negative value with error code.
995  *      @remarks        This function can  be called successfully when current state is @n
996  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
997  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
998  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
999  *      @see            _mmcamcorder_commit
1000  */
1001 int _mmcamcorder_cancel(MMHandleType hcamcorder);
1002
1003 /**
1004  *      This function calls after commiting action finished asynchronously.
1005  *      In this function, remaining process , such as state change, happens.
1006  *
1007  *      @param[in]      hcamcorder      Specifies the camcorder  handle
1008  *      @return         This function returns zero on success, or negative value with error code.
1009  *      @remarks        This function can  be called successfully when current state is @n
1010  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
1011  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
1012  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
1013  *      @see            _mmcamcorder_commit
1014  */
1015 int _mmcamcorder_commit_async_end(MMHandleType hcamcorder);
1016
1017 /**
1018  *      This function is to set callback for receiving messages from camcorder.
1019  *
1020  *      @param[in]      hcamcorder      Specifies the camcorder  handle
1021  *      @param[in]      callback        Specifies the function pointer of callback function
1022  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1023  *
1024  *      @return         This function returns zero on success, or negative value with error code.
1025  *      @remarks        typedef bool (*mm_message_callback) (int msg, mm_messageType *param, void *user_param);@n
1026  *              @n
1027  *              typedef union                           @n
1028  *              {                                                       @n
1029  *                      int code;                               @n
1030  *                      struct                                  @n
1031  *                      {                                               @n
1032  *                              int total;                      @n
1033  *                              int elapsed;            @n
1034  *                      } time;                                 @n
1035  *                      struct                                  @n
1036  *                      {                                               @n
1037  *                              int previous;           @n
1038  *                              int current;                    @n
1039  *                      } state;                                        @n
1040  *              } mm_message_type;      @n
1041  *                                                                      @n
1042  *              If a  message value for mm_message_callback is MM_MESSAGE_STATE_CHANGED, @n
1043  *              state value in mm_message_type  will be a mmcamcorder_state_type enum value;@n
1044  *              @n
1045  *              If  a message value for mm_message_callback is MM_MESSAGE_ERROR,  @n
1046  *              the code value in mm_message_type will be a mmplayer_error_type enum value;
1047  *
1048  *      @see            mm_message_type,  mmcamcorder_state_type,  mmcamcorder_error_type
1049  */
1050 int _mmcamcorder_set_message_callback(MMHandleType hcamcorder,
1051                                       MMMessageCallback callback,
1052                                       void *user_data);
1053
1054 /**
1055  *      This function is to set callback for video stream.
1056  *
1057  *      @param[in]      hcamcorder      Specifies the camcorder  handle
1058  *      @param[in]      callback        Specifies the function pointer of callback function
1059  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1060  *
1061  *      @return         This function returns zero on success, or negative value with error code.
1062  *      @see            mmcamcorder_error_type
1063  */
1064 int _mmcamcorder_set_video_stream_callback(MMHandleType hcamcorder,
1065                                            mm_camcorder_video_stream_callback callback,
1066                                            void *user_data);
1067
1068 /**
1069  *      This function is to set callback for audio stream.
1070  *
1071  *      @param[in]      hcamcorder      Specifies the camcorder handle
1072  *      @param[in]      callback        Specifies the function pointer of callback function
1073  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1074  *
1075  *      @return         This function returns zero on success, or negative value with error code.
1076  *      @see            mmcamcorder_error_type
1077  */
1078 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle,
1079                                            mm_camcorder_audio_stream_callback callback,
1080                                            void *user_data);
1081
1082 /**
1083  *      This function is to set callback for muxed stream.
1084  *
1085  *      @param[in]      hcamcorder      Specifies the camcorder handle
1086  *      @param[in]      callback        Specifies the function pointer of callback function
1087  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1088  *
1089  *      @return         This function returns zero on success, or negative value with error code.
1090  *      @see            mmcamcorder_error_type
1091  */
1092 int _mmcamcorder_set_muxed_stream_callback(MMHandleType handle,
1093                                            mm_camcorder_muxed_stream_callback callback,
1094                                            void *user_data);
1095
1096 /**
1097  *      This function is to set callback for video capture.
1098  *
1099  *      @param[in]      hcamcorder      Specifies the camcorder  handle
1100  *      @param[in]      callback        Specifies the function pointer of callback function
1101  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1102  *
1103  *      @return         This function returns zero on success, or negative value with error code.
1104  *      @see            mmcamcorder_error_type
1105  */
1106 int _mmcamcorder_set_video_capture_callback(MMHandleType hcamcorder,
1107                                             mm_camcorder_video_capture_callback callback,
1108                                             void *user_data);
1109
1110 /**
1111  *      This function is to set callback for video encode decision.
1112  *
1113  *      @param[in]      hcamcorder      Specifies the camcorder  handle
1114  *      @param[in]      callback        Specifies the function pointer of callback function
1115  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1116  *
1117  *      @return         This function returns zero on success, or negative value with error code.
1118  */
1119 int _mmcamcorder_set_video_encode_decision_callback(MMHandleType hcamcorder,
1120                                             mm_camcorder_video_encode_decision_callback callback,
1121                                             void *user_data);
1122
1123 /**
1124  *      This function returns current state of camcorder, or negative value with error code.
1125  *
1126  *      @param[in]      hcamcorder      Specifies the camcorder  handle.
1127  *      @return         This function returns current state of camcorder, or negative value with error code.
1128  *      @see            mmcamcorder_state_type
1129  */
1130 int _mmcamcorder_get_current_state(MMHandleType hcamcorder);
1131
1132 int _mmcamcorder_init_focusing(MMHandleType handle);
1133 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction);
1134 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction);
1135 int _mmcamcorder_adjust_auto_focus(MMHandleType handle);
1136 int _mmcamcorder_stop_focusing(MMHandleType handle);
1137
1138 /**
1139  * This function gets current state of camcorder.
1140  *
1141  * @param       void
1142  * @return      This function returns state of current camcorder context
1143  * @remarks
1144  * @see         _mmcamcorder_set_state()
1145  *
1146  */
1147 int _mmcamcorder_streamer_init(void);
1148
1149 /**
1150  * This function gets current state of camcorder.
1151  *
1152  * @param       void
1153  * @return      This function returns state of current camcorder context
1154  * @remarks
1155  * @see         _mmcamcorder_set_state()
1156  *
1157  */
1158 int _mmcamcorder_display_init(void);
1159
1160 /**
1161  * This function gets current state of camcorder.
1162  *
1163  * @param[in]   handle          Handle of camcorder context.
1164  * @return      This function returns state of current camcorder context
1165  * @remarks
1166  * @see         _mmcamcorder_set_state()
1167  *
1168  */
1169 int _mmcamcorder_get_state(MMHandleType handle);
1170 int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state);
1171
1172 /**
1173  * This function sets new state of camcorder.
1174  *
1175  * @param[in]   handle          Handle of camcorder context.
1176  * @param[in]   state           setting state value of camcorder.
1177  * @return      void
1178  * @remarks
1179  * @see         _mmcamcorder_get_state()
1180  *
1181  */
1182 void _mmcamcorder_set_state(MMHandleType handle, int state);
1183
1184 /**
1185  * This function allocates structure of subsidiary attributes.
1186  *
1187  * @param[in]   type            Allocation type of camcorder context.
1188  * @return      This function returns structure pointer on success, NULL value on failure.
1189  * @remarks
1190  * @see         _mmcamcorder_dealloc_subcontext()
1191  *
1192  */
1193 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type);
1194
1195 /**
1196  * This function releases structure of subsidiary attributes.
1197  *
1198  * @param[in]   sc              Handle of camcorder subcontext.
1199  * @return      void
1200  * @remarks
1201  * @see         _mmcamcorder_alloc_subcontext()
1202  *
1203  */
1204 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc);
1205
1206 /**
1207  * This function sets command function according to the type.
1208  *
1209  * @param[in]   handle          Handle of camcorder context.
1210  * @param[in]   type            Allocation type of camcorder context.
1211  * @return      This function returns MM_ERROR_NONE on success, or other values with error code.
1212  * @remarks
1213  * @see         __mmcamcorder_video_command(), __mmcamcorder_audio_command(), __mmcamcorder_image_command()
1214  *
1215  */
1216 int _mmcamcorder_set_functions(MMHandleType handle, int type);
1217
1218 /**
1219  * This function is callback function of main pipeline.
1220  * Once this function is registered with certain pipeline using gst_bus_add_watch(),
1221  * this callback will be called every time when there is upcomming message from pipeline.
1222  * Basically, this function is used as error handling function, now.
1223  *
1224  * @param[in]   bus             pointer of buf that called this function.
1225  * @param[in]   message         callback message from pipeline.
1226  * @param[in]   data            user data.
1227  * @return      This function returns true on success, or false value with error
1228  * @remarks
1229  * @see         __mmcamcorder_create_preview_pipeline()
1230  *
1231  */
1232 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data);
1233
1234 /**
1235  * This function is callback function of main pipeline.
1236  * Once this function is registered with certain pipeline using gst_bus_set_sync_handler(),
1237  * this callback will be called every time when there is upcomming message from pipeline.
1238  * Basically, this function is used as sync error handling function, now.
1239  *
1240  * @param[in]   bus             pointer of buf that called this function.
1241  * @param[in]   message         callback message from pipeline.
1242  * @param[in]   data            user data.
1243  * @return      This function returns true on success, or false value with error
1244  * @remarks
1245  * @see         __mmcamcorder_create_preview_pipeline()
1246  *
1247  */
1248 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data);
1249
1250 /**
1251  * This function is callback function of encode pipeline.
1252  * Once this function is registered with certain pipeline using gst_bus_set_sync_handler(),
1253  * this callback will be called every time when there is upcomming message from pipeline.
1254  * Basically, this function is used for EOS and error handling now.
1255  *
1256  * @param[in]   bus             pointer of buf that called this function.
1257  * @param[in]   message         callback message from pipeline.
1258  * @param[in]   data            user data.
1259  * @return      This function returns true on success, or false value with error
1260  * @remarks
1261  * @see         __mmcamcorder_create_recorder_pipeline()
1262  * @see         __mmcamcorder_create_audiop_with_encodebin()
1263  *
1264  */
1265 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data);
1266
1267 /**
1268  * This function create main pipeline according to type.
1269  *
1270  * @param[in]   handle          Handle of camcorder context.
1271  * @param[in]   type            Allocation type of camcorder context.
1272  * @return      This function returns zero on success, or negative value with error code.
1273  * @remarks
1274  * @see         _mmcamcorder_destroy_pipeline()
1275  *
1276  */
1277 int _mmcamcorder_create_pipeline(MMHandleType handle, int type);
1278
1279 /**
1280  * This function release all element of main pipeline according to type.
1281  *
1282  * @param[in]   handle          Handle of camcorder context.
1283  * @param[in]   type            Allocation type of camcorder context.
1284  * @return      void
1285  * @remarks
1286  * @see         _mmcamcorder_create_pipeline()
1287  *
1288  */
1289 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type);
1290
1291 /**
1292  * This function sets gstreamer element status.
1293  * If the gstreamer fails to set status or returns asynchronous mode,
1294  * this function waits for state changed until timeout expired.
1295  *
1296  * @param[in]   pipeline        Pointer of pipeline
1297  * @param[in]   target_state    newly setting status
1298  * @return      This function returns zero on success, or negative value with error code.
1299  * @remarks
1300  * @see
1301  *
1302  */
1303 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state);
1304
1305
1306 /* For xvimagesink */
1307 GstBusSyncReply __mmcamcorder_sync_callback(GstBus *bus, GstMessage *message, gulong data);
1308
1309 /* For querying capabilities */
1310 int _mmcamcorder_read_vidsrc_info(int videodevidx, camera_conf **configure_info);
1311
1312 /* for performance check */
1313 void _mmcamcorder_video_current_framerate_init(MMHandleType handle);
1314 int _mmcamcorder_video_current_framerate(MMHandleType handle);
1315 int _mmcamcorder_video_average_framerate(MMHandleType handle);
1316
1317 /* for stopping forcedly */
1318 void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder, int state_change_by_system);
1319
1320 /* device policy manager */
1321 void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *value, void *user_data);
1322
1323 /* Emit dbus signal */
1324 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
1325         const char *interface_name, const char *signal_name, int value);
1326
1327 /* external storage state management */
1328 int _mmcamcorder_manage_external_storage_state(MMHandleType handle, int storage_state);
1329
1330 #ifdef __cplusplus
1331 }
1332 #endif
1333
1334 #endif /* __MM_CAMCORDER_INTERNAL_H__ */