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