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