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