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