a656e35ad9246c4351e5483029d16fb61a58c2c4
[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
574         /* Pipeline element of Encodebin */
575         _MMCAMCORDER_ENCSINK_BIN,
576         _MMCAMCORDER_ENCSINK_SRC,
577         _MMCAMCORDER_ENCSINK_FILT,
578         _MMCAMCORDER_ENCSINK_ENCBIN,
579         _MMCAMCORDER_ENCSINK_AQUE,
580         _MMCAMCORDER_ENCSINK_CONV,
581         _MMCAMCORDER_ENCSINK_AENC,
582         _MMCAMCORDER_ENCSINK_AENC_QUE,
583         _MMCAMCORDER_ENCSINK_VQUE,
584         _MMCAMCORDER_ENCSINK_VCONV,
585         _MMCAMCORDER_ENCSINK_VENC,
586         _MMCAMCORDER_ENCSINK_VENC_QUE,
587         _MMCAMCORDER_ENCSINK_ITOG,
588         _MMCAMCORDER_ENCSINK_ICROP,
589         _MMCAMCORDER_ENCSINK_ISCALE,
590         _MMCAMCORDER_ENCSINK_IFILT,
591         _MMCAMCORDER_ENCSINK_IQUE,
592         _MMCAMCORDER_ENCSINK_IENC,
593         _MMCAMCORDER_ENCSINK_MUX,
594         _MMCAMCORDER_ENCSINK_SINK,
595
596         _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM,
597 } _MMCAMCORDER_ENCODE_PIPELINE_ELELMENT;
598
599 typedef enum {
600         _MMCAMCORDER_TASK_THREAD_STATE_NONE,
601         _MMCAMCORDER_TASK_THREAD_STATE_SOUND_PLAY_START,
602         _MMCAMCORDER_TASK_THREAD_STATE_SOUND_SOLO_PLAY_START,
603         _MMCAMCORDER_TASK_THREAD_STATE_ENCODE_PIPE_CREATE,
604         _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING,
605         _MMCAMCORDER_TASK_THREAD_STATE_EXIT,
606 } _MMCamcorderTaskThreadState;
607
608 /**
609  * System state change cause
610  */
611 typedef enum {
612         _MMCAMCORDER_STATE_CHANGE_NORMAL = 0,
613         _MMCAMCORDER_STATE_CHANGE_BY_FOCUS,
614         _MMCAMCORDER_STATE_CHANGE_BY_RM,
615         _MMCAMCORDER_STATE_CHANGE_BY_DPM,
616         _MMCAMCORDER_STATE_CHANGE_BY_STORAGE
617 } _MMCamcorderStateChange;
618
619
620 /*=======================================================================================
621 | STRUCTURE DEFINITIONS                                                                 |
622 ========================================================================================*/
623 /**
624  * MMCamcorder Gstreamer Element
625  */
626 typedef struct {
627         unsigned int id;                /**< Gstreamer piplinem element name */
628         GstElement *gst;                /**< Gstreamer element */
629 } _MMCamcorderGstElement;
630
631 /**
632  * MMCamcorder information for KPI measurement
633  */
634 typedef struct {
635         int current_fps;                /**< current fps of this second */
636         int average_fps;                /**< average fps  */
637         unsigned int video_framecount;  /**< total number of video frame */
638         unsigned int last_framecount;   /**< total number of video frame in last measurement */
639         struct timeval init_video_time; /**< time when start to measure */
640         struct timeval last_video_time; /**< last measurement time */
641 } _MMCamcorderKPIMeasure;
642
643 /**
644  * MMCamcorder information for Multi-Thread Safe
645  */
646 typedef struct {
647         GMutex lock;                    /**< Mutex (for general use) */
648         GCond cond;                     /**< Condition (for general use) */
649         GMutex cmd_lock;                /**< Mutex (for command) */
650         GCond cmd_cond;                 /**< Condition (for command) */
651         GMutex asm_lock;                /**< Mutex (for ASM) */
652         GMutex state_lock;              /**< Mutex (for state change) */
653         GMutex gst_state_lock;          /**< Mutex (for gst pipeline state change) */
654         GMutex gst_encode_state_lock;   /**< Mutex (for gst encode pipeline state change) */
655         GMutex message_cb_lock;         /**< Mutex (for message callback) */
656         GMutex vcapture_cb_lock;        /**< Mutex (for video capture callback) */
657         GMutex vstream_cb_lock;         /**< Mutex (for video stream callback) */
658         GMutex astream_cb_lock;         /**< Mutex (for audio stream callback) */
659         GMutex mstream_cb_lock;         /**< Mutex (for muxed stream callback) */
660 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
661         GMutex resource_lock;           /**< Mutex (for resource check) */
662 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
663 } _MMCamcorderMTSafe;
664
665 /**
666  * MMCamcorder Sub Context
667  */
668 typedef struct {
669         bool isMaxsizePausing;                  /**< Because of size limit, pipeline is paused. */
670         bool isMaxtimePausing;                  /**< Because of time limit, pipeline is paused. */
671         int element_num;                        /**< count of element */
672         int encode_element_num;                 /**< count of encode element */
673         int cam_stability_count;                /**< camsensor stability count. the count of frame will drop */
674         GstClockTime pipeline_time;             /**< current time of Gstreamer Pipeline */
675         GstClockTime pause_time;                /**< amount of time while pipeline is in PAUSE state.*/
676         GstClockTime stillshot_time;            /**< pipeline time of capturing moment*/
677         gboolean is_modified_rate;              /**< whether recording motion rate is modified or not */
678         gboolean ferror_send;                   /**< file write/seek error **/
679         guint ferror_count;                     /**< file write/seek error count **/
680         GstClockTime previous_slot_time;
681         int display_interval;                   /**< This value is set as 'GST_SECOND / display FPS' */
682         gboolean bget_eos;                      /**< Whether getting EOS */
683         gboolean bencbin_capture;               /**< Use Encodebin for capturing */
684         gboolean audio_disable;                 /**< whether audio is disabled or not when record */
685         int videosrc_rotate;                    /**< rotate of videosrc */
686         unsigned long long muxed_stream_offset; /**< current offset for muxed stream data */
687
688         /* For dropping video frame when start recording */
689         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. */
690         int pass_first_vframe;                  /**< When this value is bigger than zero, MSL won't drop video frame though "drop_vframe" is bigger then zero. */
691
692         /* INI information */
693         unsigned int fourcc;                    /**< Get fourcc value of camera INI file */
694         _MMCamcorderImageInfo *info_image;      /**< extra information for image capture */
695         _MMCamcorderVideoInfo *info_video;      /**< extra information for video recording */
696         _MMCamcorderAudioInfo *info_audio;      /**< extra information for audio recording */
697
698         _MMCamcorderGstElement *element;        /**< array of preview element */
699         _MMCamcorderGstElement *encode_element; /**< array of encode element */
700         _MMCamcorderKPIMeasure kpi;             /**< information related with performance measurement */
701
702         type_element *VideosinkElement;         /**< configure data of videosink element */
703         type_element *VideoconvertElement;      /**< configure data of videoconvert element */
704         type_element *VideodecoderElementH264;  /**< configure data of video decoder element for H.264 format */
705         gboolean SensorEncodedCapture;          /**< whether camera sensor support encoded image capture */
706         gboolean internal_encode;               /**< whether use internal encoding function */
707 } _MMCamcorderSubContext;
708
709 /**
710   * _MMCamcorderContext
711   */
712 typedef struct mmf_camcorder {
713         /* information */
714         int type;               /**< mmcamcorder_mode_type */
715         int device_type;        /**< device type */
716         int state;              /**< state of camcorder */
717         int old_state;          /**< old state of camcorder */
718
719         /* handles */
720         MMHandleType attributes;               /**< Attribute handle */
721         _MMCamcorderSubContext *sub_context;   /**< sub context */
722         mm_exif_info_t *exif_info;             /**< EXIF */
723         GList *buffer_probes;                  /**< a list of buffer probe handle */
724         GList *event_probes;                   /**< a list of event probe handle */
725         GList *signals;                        /**< a list of signal handle */
726 #ifdef _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK
727         GList *msg_data;                       /**< a list of msg data */
728 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
729         camera_conf *conf_main;                /**< Camera configure Main structure */
730         camera_conf *conf_ctrl;                /**< Camera configure Control structure */
731 #ifdef _MMCAMCORDER_RM_SUPPORT
732         int rm_handle;                        /**< Resource manager handle */
733 #endif /* _MMCAMCORDER_RM_SUPPORT */
734         guint pipeline_cb_event_id;            /**< Event source ID of pipeline message callback */
735         guint encode_pipeline_cb_event_id;     /**< Event source ID of encode pipeline message callback */
736         guint setting_event_id;                /**< Event source ID of attributes setting to sensor */
737         SOUND_INFO snd_info;                   /**< Sound handle for multishot capture */
738
739         /* callback handlers */
740         MMMessageCallback msg_cb;                               /**< message callback */
741         void *msg_cb_param;                                     /**< message callback parameter */
742         mm_camcorder_video_stream_callback vstream_cb;          /**< Video stream callback */
743         void *vstream_cb_param;                                 /**< Video stream callback parameter */
744         mm_camcorder_audio_stream_callback astream_cb;          /**< Audio stream callback */
745         void *astream_cb_param;                                 /**< Audio stream callback parameter */
746         mm_camcorder_muxed_stream_callback mstream_cb;          /**< Muxed stream callback */
747         void *mstream_cb_param;                                 /**< Muxed stream callback parameter */
748         mm_camcorder_video_capture_callback vcapture_cb;        /**< Video capture callback */
749         void *vcapture_cb_param;                                /**< Video capture callback parameter */
750         int (*command)(MMHandleType, int);                      /**< camcorder's command */
751
752         /* etc */
753         mm_cam_attr_construct_info *cam_attrs_const_info;       /**< attribute info */
754         conf_info_table *conf_main_info_table[CONFIGURE_CATEGORY_MAIN_NUM]; /** configure info table - MAIN category */
755         conf_info_table *conf_ctrl_info_table[CONFIGURE_CATEGORY_CTRL_NUM]; /** configure info table - CONTROL category */
756         int conf_main_category_size[CONFIGURE_CATEGORY_MAIN_NUM]; /** configure info table size - MAIN category */
757         int conf_ctrl_category_size[CONFIGURE_CATEGORY_CTRL_NUM]; /** configure info table size - CONTROL category */
758         _MMCamcorderMTSafe mtsafe;                              /**< Thread safe */
759         int state_change_by_system;                             /**< MSL changes its state by itself because of system */
760         GMutex restart_preview_lock;                            /**< Capture sound mutex */
761         int use_zero_copy_format;                               /**< Whether use zero copy format for camera input */
762         int use_videoconvert;                                   /**< Whether use videoconvert element for display */
763         int support_media_packet_preview_cb;                    /**< Whether support zero copy format for camera input */
764         int shutter_sound_policy;                               /**< shutter sound policy */
765         int brightness_default;                                 /**< default value of brightness */
766         int brightness_step_denominator;                        /**< denominator of brightness bias step */
767         int support_zsl_capture;                                /**< support Zero Shutter Lag capture */
768         char *model_name;                                       /**< model name from system info */
769         char *software_version;                                 /**< software_version from system info */
770         int capture_sound_count;                                /**< count for capture sound */
771         char *root_directory;                                   /**< Root directory for device */
772         int resolution_changed;                                 /**< Flag for preview resolution change */
773         int sound_focus_register;                               /**< Use sound focus internally */
774         int sound_focus_id;                                     /**< id for sound focus */
775         int sound_focus_watch_id;                               /**< id for sound focus watch */
776         unsigned int sound_focus_subscribe_id;                  /**< subscribe id for sound focus signal */
777         int interrupt_code;                                     /**< Interrupt code */
778         int acquired_focus;                                     /**< Current acquired focus */
779         int session_type;                                       /**< Session type */
780         int session_flags;                                      /**< Session flags */
781         int recreate_decoder;                                   /**< Flag of decoder element recreation for encoded preview format */
782
783         _MMCamcorderInfoConverting caminfo_convert[CAMINFO_CONVERT_NUM];        /**< converting structure of camera info */
784         _MMCamcorderEnumConvert enum_conv[ENUM_CONVERT_NUM];                    /**< enum converting list that is modified by ini info */
785
786         gboolean capture_in_recording;                          /**< Flag for capture while recording */
787
788         gboolean error_occurs;                                  /**< flag for error */
789         int error_code;                                         /**< error code for internal gstreamer error */
790
791         /* task thread */
792         GThread *task_thread;                                   /**< thread for task */
793         GMutex task_thread_lock;                                /**< mutex for task thread */
794         GCond task_thread_cond;                                 /**< cond for task thread */
795         _MMCamcorderTaskThreadState task_thread_state;          /**< state of task thread */
796
797 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
798         /* resource manager for H/W resources */
799         mm_resource_manager_h resource_manager;
800         mm_resource_manager_res_h camera_resource;
801         mm_resource_manager_res_h video_overlay_resource;
802         mm_resource_manager_res_h video_encoder_resource;
803         gboolean is_release_cb_calling;
804 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
805
806         /* gdbus */
807         GDBusConnection *gdbus_conn;                            /**< gdbus connection */
808         _MMCamcorderGDbusCbInfo gdbus_info_sound;               /**< Informations for the gbus cb of sound play */
809         _MMCamcorderGDbusCbInfo gdbus_info_solo_sound;          /**< Informations for the gbus cb of solo sound play */
810
811         /* DPM(device policy manager) */
812         device_policy_manager_h dpm_handle;                     /**< DPM handle */
813         int dpm_camera_cb_id;                                   /**< DPM camera policy changed callback id */
814
815         /* Storage */
816         _MMCamcorderStorageInfo storage_info;                   /**< Storage information */
817
818 #ifdef _MMCAMCORDER_RM_SUPPORT
819         rm_category_request_s request_resources;
820         rm_device_return_s returned_devices;
821 #endif /* _MMCAMCORDER_RM_SUPPORT */
822         int reserved[4];                                        /**< reserved */
823 } mmf_camcorder_t;
824
825 /*=======================================================================================
826 | EXTERN GLOBAL VARIABLE                                                                |
827 ========================================================================================*/
828
829 /*=======================================================================================
830 | GLOBAL FUNCTION PROTOTYPES                                                            |
831 ========================================================================================*/
832 /**
833  *      This function creates camcorder for capturing still image and recording.
834  *
835  *      @param[out]     handle          Specifies the camcorder  handle
836  *      @param[in]      info            Preset information of camcorder
837  *      @return         This function returns zero on success, or negative value with error code.
838  *      @remarks        When this function calls successfully, camcorder  handle will be filled with a @n
839  *                      valid value and the state of  the camcorder  will become MM_CAMCORDER_STATE_NULL.@n
840  *                      Note that  it's not ready to working camcorder. @n
841  *                      You should call mmcamcorder_realize before starting camcorder.
842  *      @see            _mmcamcorder_create
843  */
844 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info);
845
846 /**
847  *      This function destroys instance of camcorder.
848  *
849  *      @param[in]      hcamcorder      Specifies the camcorder  handle
850  *      @return         This function returns zero on success, or negative value with error code.
851  *      @see            _mmcamcorder_create
852  */
853 int _mmcamcorder_destroy(MMHandleType hcamcorder);
854
855 /**
856  *      This function allocates memory for camcorder.
857  *
858  *      @param[in]      hcamcorder      Specifies the camcorder  handle
859  *      @return         This function returns zero on success, or negative value with error code.
860  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_NULL @n
861  *                      and  the state of the camcorder  will become MM_CAMCORDER_STATE_READY. @n
862  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
863  *      @see            _mmcamcorder_unrealize
864  *      @pre            MM_CAMCORDER_STATE_NULL
865  *      @post           MM_CAMCORDER_STATE_READY
866  */
867 int _mmcamcorder_realize(MMHandleType hcamcorder);
868
869 /**
870  *      This function free allocated 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 release all resources which are allocated for the camcorder engine.@n
875  *                      This function can  be called successfully when current state is MM_CAMCORDER_STATE_READY and  @n
876  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_NULL. @n
877  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
878  *      @see            _mmcamcorder_realize
879  *      @pre            MM_CAMCORDER_STATE_READY
880  *      @post           MM_CAMCORDER_STATE_NULL
881  */
882 int _mmcamcorder_unrealize(MMHandleType hcamcorder);
883
884 /**
885  *      This function is to start previewing.
886  *
887  *      @param[in]      hcamcorder      Specifies the camcorder  handle
888  *      @return         This function returns zero on success, or negative value with error code.
889  *      @remarks        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_PREPARE. @n
891  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
892  *      @see            _mmcamcorder_stop
893  */
894 int _mmcamcorder_start(MMHandleType hcamcorder);
895
896 /**
897  *      This function is to stop previewing.
898  *
899  *      @param[in]      hcamcorder      Specifies the camcorder  handle
900  *      @return         This function returns zero on success, or negative value with error code.
901  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and  @n
902  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_READY.@n
903  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
904  *      @see            _mmcamcorder_start
905  */
906 int _mmcamcorder_stop(MMHandleType hcamcorder);
907
908 /**
909  *      This function to start capturing of still images.
910  *
911  *      @param[in]      hcamcorder      Specifies the camcorder  handle.
912  *      @return         This function returns zero on success, or negative value with error code.
913  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and @n
914  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_CAPTURING. @n
915  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
916  *      @see            _mmcamcorder_capture_stop
917  */
918 int _mmcamcorder_capture_start(MMHandleType hcamcorder);
919
920 /**
921  *      This function is to stop capturing still images.
922  *
923  *      @param[in]      hcamcorder      Specifies the camcorder  handle
924  *      @return         This function returns zero on success, or negative value with error code.
925  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_CAPTURING and @n
926  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
927  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
928  *      @see            _mmcamcorder_capture_start
929  */
930 int _mmcamcorder_capture_stop(MMHandleType hcamcorder);
931
932 /**
933  *      This function is to start  video and audio recording.
934  *
935  *      @param[in]      hcamcorder      Specifies the camcorder  handle
936  *      @return         This function returns zero on success, or negative value with error code.
937  *      @remarks        This function can  be called successfully when current state is @n
938  *                      MM_CAMCORDER_STATE_PREPARE or MM_CAMCORDER_STATE_PAUSED and  @n
939  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_RECORDING.@n
940  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
941  *      @see            _mmcamcorder_pause
942  */
943 int _mmcamcorder_record(MMHandleType hcamcorder);
944
945 /**
946  *      This function is to pause video and audio recording
947  *
948  *      @param[in]      hcamcorder      Specifies the camcorder  handle
949  *      @return         This function returns zero on success, or negative value with error code.
950  *      @remarks        This function can  be called successfully when current state is MM_CAMCORDER_STATE_RECORDING and  @n
951  *                      the  state of the camcorder  will become MM_CAMCORDER_STATE_PAUSED.@n
952  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.@n
953  *      @see            _mmcamcorder_record
954  */
955 int _mmcamcorder_pause(MMHandleType hcamcorder);
956
957 /**
958  *      This function is to stop video and audio  recording and  save results.
959  *
960  *      @param[in]      hcamcorder      Specifies the camcorder  handle
961  *      @return         This function returns zero on success, or negative value with error code.
962  *      @remarks        This function can  be called successfully when current state is @n
963  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
964  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
965  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION
966  *      @see            _mmcamcorder_cancel
967  */
968 int _mmcamcorder_commit(MMHandleType hcamcorder);
969
970 /**
971  *      This function is to stop video and audio recording and do not save results.
972  *
973  *      @param[in]      hcamcorder      Specifies the camcorder  handle
974  *      @return         This function returns zero on success, or negative value with error code.
975  *      @remarks        This function can  be called successfully when current state is @n
976  *                      MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and  @n
977  *                      the state of the camcorder  will become MM_CAMCORDER_STATE_PREPARE. @n
978  *                      Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
979  *      @see            _mmcamcorder_commit
980  */
981 int _mmcamcorder_cancel(MMHandleType hcamcorder);
982
983 /**
984  *      This function calls after commiting action finished asynchronously.
985  *      In this function, remaining process , such as state change, happens.
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_commit_async_end(MMHandleType hcamcorder);
996
997 /**
998  *      This function is to set callback for receiving messages from camcorder.
999  *
1000  *      @param[in]      hcamcorder      Specifies the camcorder  handle
1001  *      @param[in]      callback        Specifies the function pointer of callback function
1002  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1003  *
1004  *      @return         This function returns zero on success, or negative value with error code.
1005  *      @remarks        typedef bool (*mm_message_callback) (int msg, mm_messageType *param, void *user_param);@n
1006  *              @n
1007  *              typedef union                           @n
1008  *              {                                                       @n
1009  *                      int code;                               @n
1010  *                      struct                                  @n
1011  *                      {                                               @n
1012  *                              int total;                      @n
1013  *                              int elapsed;            @n
1014  *                      } time;                                 @n
1015  *                      struct                                  @n
1016  *                      {                                               @n
1017  *                              int previous;           @n
1018  *                              int current;                    @n
1019  *                      } state;                                        @n
1020  *              } mm_message_type;      @n
1021  *                                                                      @n
1022  *              If a  message value for mm_message_callback is MM_MESSAGE_STATE_CHANGED, @n
1023  *              state value in mm_message_type  will be a mmcamcorder_state_type enum value;@n
1024  *              @n
1025  *              If  a message value for mm_message_callback is MM_MESSAGE_ERROR,  @n
1026  *              the code value in mm_message_type will be a mmplayer_error_type enum value;
1027  *
1028  *      @see            mm_message_type,  mmcamcorder_state_type,  mmcamcorder_error_type
1029  */
1030 int _mmcamcorder_set_message_callback(MMHandleType hcamcorder,
1031                                       MMMessageCallback callback,
1032                                       void *user_data);
1033
1034 /**
1035  *      This function is to set callback for video stream.
1036  *
1037  *      @param[in]      hcamcorder      Specifies the camcorder  handle
1038  *      @param[in]      callback        Specifies the function pointer of callback function
1039  *      @param[in]      user_data       Specifies the user poiner for passing to callback function
1040  *
1041  *      @return         This function returns zero on success, or negative value with error code.
1042  *      @see            mmcamcorder_error_type
1043  */
1044 int _mmcamcorder_set_video_stream_callback(MMHandleType hcamcorder,
1045                                            mm_camcorder_video_stream_callback callback,
1046                                            void *user_data);
1047
1048 /**
1049  *      This function is to set callback for audio 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_audio_stream_callback(MMHandleType handle,
1059                                            mm_camcorder_audio_stream_callback callback,
1060                                            void *user_data);
1061
1062 /**
1063  *      This function is to set callback for muxed 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_muxed_stream_callback(MMHandleType handle,
1073                                            mm_camcorder_muxed_stream_callback callback,
1074                                            void *user_data);
1075
1076 /**
1077  *      This function is to set callback for video capture.
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_video_capture_callback(MMHandleType hcamcorder,
1087                                             mm_camcorder_video_capture_callback callback,
1088                                             void *user_data);
1089
1090 /**
1091  *      This function returns current state of camcorder, or negative value with error code.
1092  *
1093  *      @param[in]      hcamcorder      Specifies the camcorder  handle.
1094  *      @return         This function returns current state of camcorder, or negative value with error code.
1095  *      @see            mmcamcorder_state_type
1096  */
1097 int _mmcamcorder_get_current_state(MMHandleType hcamcorder);
1098
1099 int _mmcamcorder_init_focusing(MMHandleType handle);
1100 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction);
1101 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction);
1102 int _mmcamcorder_adjust_auto_focus(MMHandleType handle);
1103 int _mmcamcorder_stop_focusing(MMHandleType handle);
1104
1105 /**
1106  * This function gets current state of camcorder.
1107  *
1108  * @param       void
1109  * @return      This function returns state of current camcorder context
1110  * @remarks
1111  * @see         _mmcamcorder_set_state()
1112  *
1113  */
1114 int _mmcamcorder_streamer_init(void);
1115
1116 /**
1117  * This function gets current state of camcorder.
1118  *
1119  * @param       void
1120  * @return      This function returns state of current camcorder context
1121  * @remarks
1122  * @see         _mmcamcorder_set_state()
1123  *
1124  */
1125 int _mmcamcorder_display_init(void);
1126
1127 /**
1128  * This function gets current state of camcorder.
1129  *
1130  * @param[in]   handle          Handle of camcorder context.
1131  * @return      This function returns state of current camcorder context
1132  * @remarks
1133  * @see         _mmcamcorder_set_state()
1134  *
1135  */
1136 int _mmcamcorder_get_state(MMHandleType handle);
1137 int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state);
1138
1139 /**
1140  * This function sets new state of camcorder.
1141  *
1142  * @param[in]   handle          Handle of camcorder context.
1143  * @param[in]   state           setting state value of camcorder.
1144  * @return      void
1145  * @remarks
1146  * @see         _mmcamcorder_get_state()
1147  *
1148  */
1149 void _mmcamcorder_set_state(MMHandleType handle, int state);
1150
1151 /**
1152  * This function allocates structure of subsidiary attributes.
1153  *
1154  * @param[in]   type            Allocation type of camcorder context.
1155  * @return      This function returns structure pointer on success, NULL value on failure.
1156  * @remarks
1157  * @see         _mmcamcorder_dealloc_subcontext()
1158  *
1159  */
1160 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type);
1161
1162 /**
1163  * This function releases structure of subsidiary attributes.
1164  *
1165  * @param[in]   sc              Handle of camcorder subcontext.
1166  * @return      void
1167  * @remarks
1168  * @see         _mmcamcorder_alloc_subcontext()
1169  *
1170  */
1171 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc);
1172
1173 /**
1174  * This function sets command function according to the type.
1175  *
1176  * @param[in]   handle          Handle of camcorder context.
1177  * @param[in]   type            Allocation type of camcorder context.
1178  * @return      This function returns MM_ERROR_NONE on success, or other values with error code.
1179  * @remarks
1180  * @see         __mmcamcorder_video_command(), __mmcamcorder_audio_command(), __mmcamcorder_image_command()
1181  *
1182  */
1183 int _mmcamcorder_set_functions(MMHandleType handle, int type);
1184
1185 /**
1186  * This function is callback function of main pipeline.
1187  * Once this function is registered with certain pipeline using gst_bus_add_watch(),
1188  * this callback will be called every time when there is upcomming message from pipeline.
1189  * Basically, this function is used as error handling function, now.
1190  *
1191  * @param[in]   bus             pointer of buf that called this function.
1192  * @param[in]   message         callback message from pipeline.
1193  * @param[in]   data            user data.
1194  * @return      This function returns true on success, or false value with error
1195  * @remarks
1196  * @see         __mmcamcorder_create_preview_pipeline()
1197  *
1198  */
1199 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data);
1200
1201 /**
1202  * This function is callback function of main pipeline.
1203  * Once this function is registered with certain pipeline using gst_bus_set_sync_handler(),
1204  * this callback will be called every time when there is upcomming message from pipeline.
1205  * Basically, this function is used as sync error handling function, now.
1206  *
1207  * @param[in]   bus             pointer of buf that called this function.
1208  * @param[in]   message         callback message from pipeline.
1209  * @param[in]   data            user data.
1210  * @return      This function returns true on success, or false value with error
1211  * @remarks
1212  * @see         __mmcamcorder_create_preview_pipeline()
1213  *
1214  */
1215 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data);
1216
1217 /**
1218  * This function is callback function of encode pipeline.
1219  * Once this function is registered with certain pipeline using gst_bus_set_sync_handler(),
1220  * this callback will be called every time when there is upcomming message from pipeline.
1221  * Basically, this function is used for EOS and error handling now.
1222  *
1223  * @param[in]   bus             pointer of buf that called this function.
1224  * @param[in]   message         callback message from pipeline.
1225  * @param[in]   data            user data.
1226  * @return      This function returns true on success, or false value with error
1227  * @remarks
1228  * @see         __mmcamcorder_create_recorder_pipeline()
1229  * @see         __mmcamcorder_create_audiop_with_encodebin()
1230  *
1231  */
1232 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data);
1233
1234 /**
1235  * This function create main pipeline according to type.
1236  *
1237  * @param[in]   handle          Handle of camcorder context.
1238  * @param[in]   type            Allocation type of camcorder context.
1239  * @return      This function returns zero on success, or negative value with error code.
1240  * @remarks
1241  * @see         _mmcamcorder_destroy_pipeline()
1242  *
1243  */
1244 int _mmcamcorder_create_pipeline(MMHandleType handle, int type);
1245
1246 /**
1247  * This function release all element of main pipeline according to type.
1248  *
1249  * @param[in]   handle          Handle of camcorder context.
1250  * @param[in]   type            Allocation type of camcorder context.
1251  * @return      void
1252  * @remarks
1253  * @see         _mmcamcorder_create_pipeline()
1254  *
1255  */
1256 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type);
1257
1258 /**
1259  * This function sets gstreamer element status.
1260  * If the gstreamer fails to set status or returns asynchronous mode,
1261  * this function waits for state changed until timeout expired.
1262  *
1263  * @param[in]   pipeline        Pointer of pipeline
1264  * @param[in]   target_state    newly setting status
1265  * @return      This function returns zero on success, or negative value with error code.
1266  * @remarks
1267  * @see
1268  *
1269  */
1270 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state);
1271
1272
1273 /* For xvimagesink */
1274 GstBusSyncReply __mmcamcorder_sync_callback(GstBus *bus, GstMessage *message, gulong data);
1275
1276 /* For querying capabilities */
1277 int _mmcamcorder_read_vidsrc_info(int videodevidx, camera_conf **configure_info);
1278
1279 /* for performance check */
1280 void _mmcamcorder_video_current_framerate_init(MMHandleType handle);
1281 int _mmcamcorder_video_current_framerate(MMHandleType handle);
1282 int _mmcamcorder_video_average_framerate(MMHandleType handle);
1283
1284 /* sound focus related function */
1285 void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder, int state_change_by_system);
1286 void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
1287         mm_sound_focus_state_e focus_state, const char *reason_for_change,
1288         int option, const char *additional_info, void *user_data);
1289 void _mmcamcorder_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
1290         const char *reason_for_change, const char *additional_info, void *user_data);
1291 void _mmcamcorder_sound_signal_callback(mm_sound_signal_name_t signal, int value, void *user_data);
1292
1293 /* device policy manager */
1294 void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *value, void *user_data);
1295
1296 /* Emit dbus signal */
1297 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
1298         const char *interface_name, const char *signal_name, int value);
1299
1300 /* external storage state management */
1301 int _mmcamcorder_manage_external_storage_state(MMHandleType handle, int storage_state);
1302
1303 #ifdef __cplusplus
1304 }
1305 #endif
1306
1307 #endif /* __MM_CAMCORDER_INTERNAL_H__ */