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