4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef __MM_CAMCORDER_INTERNAL_H__
23 #define __MM_CAMCORDER_INTERNAL_H__
26 /*=======================================================================================
28 ========================================================================================*/
33 #include <semaphore.h>
37 #include <mm_attrs_private.h>
38 #include <mm_message.h>
42 #include "mm_camcorder.h"
45 /* camcorder sub module */
46 #include "mm_camcorder_attribute.h"
47 #include "mm_camcorder_platform.h"
48 #include "mm_camcorder_stillshot.h"
49 #include "mm_camcorder_videorec.h"
50 #include "mm_camcorder_audiorec.h"
51 #include "mm_camcorder_gstcommon.h"
52 #include "mm_camcorder_exifinfo.h"
53 #include "mm_camcorder_util.h"
54 #include "mm_camcorder_configure.h"
55 #include "mm_camcorder_sound.h"
61 /*=======================================================================================
63 ========================================================================================*/
64 #define _mmcam_dbg_verb(fmt, args...) mmf_debug(MMF_DEBUG_VERBOSE,"[%05d][%s]: " fmt "\n", __LINE__, __func__, ##args);
65 #define _mmcam_dbg_log(fmt, args...) mmf_debug(MMF_DEBUG_LOG,"[%05d][%s]: " fmt "\n", __LINE__, __func__, ##args);
66 #define _mmcam_dbg_warn(fmt, args...) mmf_debug(MMF_DEBUG_WARNING,"[%05d][%s]: " fmt "\n", __LINE__, __func__, ##args);
67 #define _mmcam_dbg_err(fmt, args...) mmf_debug(MMF_DEBUG_ERROR,"[%05d][%s]: " fmt "\n", __LINE__, __func__, ##args);
68 #define _mmcam_dbg_crit(fmt, args...) mmf_debug(MMF_DEBUG_CRITICAL,"[%05d][%s]: " fmt "\n", __LINE__, __func__, ##args);
71 * Macro for checking validity and debugging
73 #define mmf_return_if_fail( expr ) \
77 _mmcam_dbg_err( "failed [%s]", #expr); \
82 * Macro for checking validity and debugging
84 #define mmf_return_val_if_fail( expr, val ) \
88 _mmcam_dbg_err("failed [%s]", #expr); \
94 * Macro for getting array size
96 #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
99 /* gstreamer element creation macro */
100 #define _MMCAMCORDER_PIPELINE_MAKE(sub_context, eid, name /*char* */, err) \
101 if (sub_context->element[eid].gst != NULL) { \
102 _mmcam_dbg_err("The element(Pipeline) is existed. element_id=[%d], name=[%s]", eid, name); \
103 gst_object_unref(sub_context->element[eid].gst); \
105 sub_context->element[eid].id = eid; \
106 sub_context->element[eid].gst = gst_pipeline_new(name); \
107 if (sub_context->element[eid].gst == NULL) { \
108 _mmcam_dbg_err("Pipeline creation fail. element_id=[%d], name=[%s]", eid, name); \
109 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
110 goto pipeline_creation_error; \
112 g_object_weak_ref(G_OBJECT(sub_context->element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
115 #define _MMCAMCORDER_BIN_MAKE(sub_context, eid, name /*char* */, err) \
116 if (sub_context->element[eid].gst != NULL) { \
117 _mmcam_dbg_err("The element(Bin) is existed. element_id=[%d], name=[%s]", eid, name); \
118 gst_object_unref(sub_context->element[eid].gst); \
120 sub_context->element[eid].id = eid; \
121 sub_context->element[eid].gst = gst_bin_new(name); \
122 if (sub_context->element[eid].gst == NULL) { \
123 _mmcam_dbg_err("Bin creation fail. element_id=[%d], name=[%s]\n", eid, name); \
124 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
125 goto pipeline_creation_error; \
127 g_object_weak_ref(G_OBJECT(sub_context->element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
130 #define _MMCAMCORDER_ELEMENT_MAKE(sub_context, eid, name /*char* */, nickname /*char* */, elist, err) \
131 if (sub_context->element[eid].gst != NULL) { \
132 _mmcam_dbg_err("The element is existed. element_id=[%d], name=[%s]", eid, name); \
133 gst_object_unref(sub_context->element[eid].gst); \
135 sub_context->element[eid].id = eid; \
136 sub_context->element[eid].gst = gst_element_factory_make(name, nickname); \
137 if (sub_context->element[eid].gst == NULL) { \
138 _mmcam_dbg_err("Element creation fail. element_id=[%d], name=[%s]", eid, name); \
139 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
140 goto pipeline_creation_error; \
142 g_object_weak_ref(G_OBJECT(sub_context->element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
144 elist = g_list_append(elist, &(sub_context->element[eid]));
146 #define _MMCAMCORDER_ENCODEBIN_ELMGET(sub_context, eid, name /*char* */, err) \
147 if (sub_context->element[eid].gst != NULL) { \
148 _mmcam_dbg_err("The element is existed. element_id=[%d], name=[%s]", eid, name); \
149 gst_object_unref(sub_context->element[eid].gst); \
151 sub_context->element[eid].id = eid; \
152 g_object_get(G_OBJECT(sc->element[_MMCAMCORDER_ENCSINK_ENCBIN].gst), name, &(sc->element[eid].gst), NULL); \
153 if (sub_context->element[eid].gst == NULL) { \
154 _mmcam_dbg_err("Element get fail. element_id=[%d], name=[%s]", eid, name); \
155 err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; \
156 goto pipeline_creation_error; \
158 gst_object_unref(sub_context->element[eid].gst); \
159 g_object_weak_ref(G_OBJECT(sub_context->element[eid].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sub_context); \
162 /* GStreamer element remove macro */
163 #define _MMCAMCORDER_ELEMENT_REMOVE(sub_context, eid) \
164 if (sub_context->element[eid].gst != NULL) { \
165 gst_object_unref(sub_context->element[eid].gst); \
168 #define _MM_GST_ELEMENT_LINK_MANY gst_element_link_many
169 #define _MM_GST_ELEMENT_LINK gst_element_link
170 #define _MM_GST_PAD_LINK gst_pad_link
172 #define _MM_GST_PAD_LINK_UNREF( srcpad, sinkpad, err, if_fail_goto ) \
174 GstPadLinkReturn ret = _MM_GST_PAD_LINK( srcpad, sinkpad ); \
175 gst_object_unref( srcpad ); srcpad = NULL; \
176 gst_object_unref( sinkpad ); sinkpad = NULL; \
177 if (ret != GST_PAD_LINK_OK) { \
178 err = MM_ERROR_CAMCORDER_GST_LINK; \
183 #define _MM_GST_PAD_UNLINK_UNREF( srcpad, sinkpad) \
184 gst_pad_unlink( srcpad, sinkpad ); \
185 gst_object_unref( srcpad ); srcpad = NULL; \
186 gst_object_unref( sinkpad ); sinkpad = NULL;
188 #define _MMCAMCORDER_STATE_SET_COUNT 3 /* checking interval */
189 #define _MMCAMCORDER_STATE_CHECK_TOTALTIME 5000000L /* total wating time for state change */
190 #define _MMCAMCORDER_STATE_CHECK_INTERVAL 5000 /* checking interval */
193 * Total level count of manual focus */
194 #define _MMFCAMCORDER_FOCUS_TOTAL_LEVEL 8
197 * File name length limit
199 #define _MMCamcorder_FILENAME_LEN (512)
202 * Minimum integer value
204 #define _MMCAMCORDER_MIN_INT (-2147483648)
207 * Maximum integer value
209 #define _MMCAMCORDER_MAX_INT (2147483647)
212 * Audio timestamp margin (msec)
214 #define _MMCAMCORDER_AUDIO_TIME_MARGIN (300)
217 * Functions related with LOCK and WAIT
219 #define _MMCAMCORDER_CAST_MTSAFE(handle) (((mmf_camcorder_t*)handle)->mtsafe)
221 #define _MMCAMCORDER_GET_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).lock)
222 #define _MMCAMCORDER_LOCK(handle) g_mutex_lock(_MMCAMCORDER_GET_LOCK(handle))
223 #define _MMCAMCORDER_TRYLOCK(handle) g_mutex_trylock(_MMCAMCORDER_GET_LOCK(handle))
224 #define _MMCAMCORDER_UNLOCK(handle) g_mutex_unlock(_MMCAMCORDER_GET_LOCK(handle))
226 #define _MMCAMCORDER_GET_COND(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).cond)
227 #define _MMCAMCORDER_WAIT(handle) g_cond_wait (_MMCAMCORDER_GET_COND(handle), _MMCAMCORDER_GET_LOCK(handle))
228 #define _MMCAMCORDER_TIMED_WAIT(handle, timeval) g_cond_timed_wait (_MMCAMCORDER_GET_COND(handle), _MMCAMCORDER_GET_LOCK(handle),timeval)
230 #define _MMCAMCORDER_SIGNAL(handle) g_cond_signal (_MMCAMCORDER_GET_COND(handle));
231 #define _MMCAMCORDER_BROADCAST(handle) g_cond_broadcast (_MMCAMCORDER_GET_COND(handle));
234 #define _MMCAMCORDER_GET_CMD_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).cmd_lock)
235 #define _MMCAMCORDER_LOCK_CMD(handle) g_mutex_lock(_MMCAMCORDER_GET_CMD_LOCK(handle))
236 #define _MMCAMCORDER_TRYLOCK_CMD(handle) g_mutex_trylock(_MMCAMCORDER_GET_CMD_LOCK(handle))
237 #define _MMCAMCORDER_UNLOCK_CMD(handle) g_mutex_unlock(_MMCAMCORDER_GET_CMD_LOCK(handle))
239 /* for state change */
240 #define _MMCAMCORDER_GET_STATE_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).state_lock)
241 #define _MMCAMCORDER_LOCK_STATE(handle) g_mutex_lock(_MMCAMCORDER_GET_STATE_LOCK(handle))
242 #define _MMCAMCORDER_TRYLOCK_STATE(handle) g_mutex_trylock(_MMCAMCORDER_GET_STATE_LOCK(handle))
243 #define _MMCAMCORDER_UNLOCK_STATE(handle) g_mutex_unlock(_MMCAMCORDER_GET_STATE_LOCK(handle))
245 /* for gstreamer state change */
246 #define _MMCAMCORDER_GET_GST_STATE_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).gst_state_lock)
247 #define _MMCAMCORDER_LOCK_GST_STATE(handle) g_mutex_lock(_MMCAMCORDER_GET_GST_STATE_LOCK(handle))
248 #define _MMCAMCORDER_TRYLOCK_GST_STATE(handle) g_mutex_trylock(_MMCAMCORDER_GET_GST_STATE_LOCK(handle))
249 #define _MMCAMCORDER_UNLOCK_GST_STATE(handle) g_mutex_unlock(_MMCAMCORDER_GET_GST_STATE_LOCK(handle))
251 /* for setting/calling callback */
252 #define _MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).message_cb_lock)
253 #define _MMCAMCORDER_LOCK_MESSAGE_CALLBACK(handle) g_mutex_lock(_MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle))
254 #define _MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(handle) g_mutex_trylock(_MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle))
255 #define _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(handle) g_mutex_unlock(_MMCAMCORDER_GET_MESSAGE_CALLBACK_LOCK(handle))
257 #define _MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).vcapture_cb_lock)
258 #define _MMCAMCORDER_LOCK_VCAPTURE_CALLBACK(handle) g_mutex_lock(_MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle))
259 #define _MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(handle) g_mutex_trylock(_MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle))
260 #define _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(handle) g_mutex_unlock(_MMCAMCORDER_GET_VCAPTURE_CALLBACK_LOCK(handle))
262 #define _MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).vstream_cb_lock)
263 #define _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(handle) g_mutex_lock(_MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle))
264 #define _MMCAMCORDER_TRYLOCK_VSTREAM_CALLBACK(handle) g_mutex_trylock(_MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle))
265 #define _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(handle) g_mutex_unlock(_MMCAMCORDER_GET_VSTREAM_CALLBACK_LOCK(handle))
267 #define _MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle) (_MMCAMCORDER_CAST_MTSAFE(handle).astream_cb_lock)
268 #define _MMCAMCORDER_LOCK_ASTREAM_CALLBACK(handle) g_mutex_lock(_MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle))
269 #define _MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(handle) g_mutex_trylock(_MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle))
270 #define _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(handle) g_mutex_unlock(_MMCAMCORDER_GET_ASTREAM_CALLBACK_LOCK(handle))
273 * Caster of main handle (camcorder)
275 #define MMF_CAMCORDER(h) (mmf_camcorder_t *)(h)
278 * Caster of subcontext
280 #define MMF_CAMCORDER_SUBCONTEXT(h) (((mmf_camcorder_t *)(h))->sub_context)
282 /* LOCAL CONSTANT DEFINITIONS */
284 * Total Numbers of Attribute values.
285 * If you increase any enum of attribute values, you also have to increase this.
287 #define MM_CAMCORDER_MODE_NUM 3 /**< Number of mode type */
288 #define MM_CAMCORDER_COLOR_TONE_NUM 27 /**< Number of color-tone modes */
289 #define MM_CAMCORDER_WHITE_BALANCE_NUM 10 /**< Number of WhiteBalance modes*/
290 #define MM_CAMCORDER_SCENE_MODE_NUM 15 /**< Number of program-modes */
291 #define MM_CAMCORDER_FOCUS_MODE_NUM 6 /**< Number of focus mode*/
292 #define MM_CAMCORDER_AUTO_FOCUS_NUM 5 /**< Total count of auto focus type*/
293 #define MM_CAMCORDER_FOCUS_STATE_NUM 4 /**< Number of focus state */
294 #define MM_CAMCORDER_ISO_NUM 10 /**< Number of ISO */
295 #define MM_CAMCORDER_AUTO_EXPOSURE_NUM 9 /**< Number of Auto exposure type */
296 #define MM_CAMCORDER_WDR_NUM 3 /**< Number of wide dynamic range */
297 #define MM_CAMCORDER_AHS_NUM 4 /**< Number of anti-handshake */
298 #define MM_CAMCORDER_GEOMETRY_METHOD_NUM 4 /**< Number of geometry method */
299 #define MM_CAMCORDER_TAG_ORT_NUM 8 /**< Number of tag orientation */
300 #define MM_CAMCORDER_STROBE_MODE_NUM 8 /**< Number of strobe mode type */
301 #define MM_CAMCORDER_STROBE_CONTROL_NUM 3 /**< Number of strobe control type */
302 #define MM_CAMCORDER_DETECT_MODE_NUM 2 /**< Number of detect mode type */
305 /*=======================================================================================
307 ========================================================================================*/
309 * Command for Camcorder.
312 /* Command for Video/Audio recording */
313 _MMCamcorder_CMD_RECORD,
314 _MMCamcorder_CMD_PAUSE,
315 _MMCamcorder_CMD_CANCEL,
316 _MMCamcorder_CMD_COMMIT,
318 /* Command for Image capture */
319 _MMCamcorder_CMD_CAPTURE,
320 _MMCamcorder_CMD_CAPTURE_CANCEL,
322 /* Command for Preview(Video/Image only effective) */
323 _MMCamcorder_CMD_PREVIEW_START,
324 _MMCamcorder_CMD_PREVIEW_STOP,
331 _MMCamcorder_SINGLE_SHOT,
332 _MMCamcorder_MULTI_SHOT,
336 * Enumerations for manual focus direction.
337 * If focusing mode is not "MM_CAMCORDER_AF_MODE_MANUAL", this value will be ignored.
339 enum MMCamcorderMfLensDir {
340 MM_CAMCORDER_MF_LENS_DIR_FORWARD = 1, /**< Focus direction to forward */
341 MM_CAMCORDER_MF_LENS_DIR_BACKWARD, /**< Focus direction to backward */
342 MM_CAMCORDER_MF_LENS_DIR_NUM, /**< Total number of the directions */
346 * Camcorder Pipeline's Element name.
347 * @note index of element.
350 _MMCAMCORDER_NONE = (-1),
352 /* Main Pipeline Element */
353 _MMCAMCORDER_MAIN_PIPE = 0x00,
355 /* Pipeline element of Video input */
356 _MMCAMCORDER_VIDEOSRC_BIN,
357 _MMCAMCORDER_VIDEOSRC_SRC,
358 _MMCAMCORDER_VIDEOSRC_FILT,
359 _MMCAMCORDER_VIDEOSRC_CLS,
360 _MMCAMCORDER_VIDEOSRC_SCALE,
361 _MMCAMCORDER_VIDEOSRC_VSFLT,
362 _MMCAMCORDER_VIDEOSRC_TEE,
364 /* Pipeline element of Audio input */
365 _MMCAMCORDER_AUDIOSRC_BIN,
366 _MMCAMCORDER_AUDIOSRC_SRC,
367 _MMCAMCORDER_AUDIOSRC_FILT,
368 _MMCAMCORDER_AUDIOSRC_NS,
369 _MMCAMCORDER_AUDIOSRC_QUE,
370 _MMCAMCORDER_AUDIOSRC_CONV,
371 _MMCAMCORDER_AUDIOSRC_VOL,
372 _MMCAMCORDER_AUDIOSRC_ENC,
374 /* Pipeline element of Video output */
375 _MMCAMCORDER_VIDEOSINK_BIN,
376 _MMCAMCORDER_VIDEOSINK_QUE,
377 _MMCAMCORDER_VIDEOSINK_SCALE,
378 _MMCAMCORDER_VIDEOSINK_FILT,
379 _MMCAMCORDER_VIDEOSINK_OVERLAY,
380 _MMCAMCORDER_VIDEOSINK_CLS,
381 _MMCAMCORDER_VIDEOSINK_ROTATE,
382 _MMCAMCORDER_VIDEOSINK_SINK,
384 /* Pipeline element of Encodebin */
385 _MMCAMCORDER_ENCSINK_BIN,
386 _MMCAMCORDER_ENCSINK_ENCBIN,
387 _MMCAMCORDER_ENCSINK_AQUE,
388 _MMCAMCORDER_ENCSINK_CONV,
389 _MMCAMCORDER_ENCSINK_AENC,
390 _MMCAMCORDER_ENCSINK_AENC_QUE,
391 _MMCAMCORDER_ENCSINK_VQUE,
392 _MMCAMCORDER_ENCSINK_VENC,
393 _MMCAMCORDER_ENCSINK_VENC_QUE,
394 _MMCAMCORDER_ENCSINK_ITOG,
395 _MMCAMCORDER_ENCSINK_ICROP,
396 _MMCAMCORDER_ENCSINK_ISCALE,
397 _MMCAMCORDER_ENCSINK_IFILT,
398 _MMCAMCORDER_ENCSINK_IQUE,
399 _MMCAMCORDER_ENCSINK_IENC,
400 _MMCAMCORDER_ENCSINK_MUX,
401 _MMCAMCORDER_ENCSINK_SINK,
403 /* Pipeline element of Stillshot output */
404 _MMCAMCORDER_STILLSHOTSINK_BIN,
405 _MMCAMCORDER_STILLSHOTSINK_QUE,
406 _MMCAMCORDER_STILLSHOTSINK_TOGGLE,
407 _MMCAMCORDER_STILLSHOTSINK_CLS,
408 _MMCAMCORDER_STILLSHOTSINK_CROP,
409 _MMCAMCORDER_STILLSHOTSINK_FILT,
410 _MMCAMCORDER_STILLSHOTSINK_SCALE,
411 _MMCAMCORDER_STILLSHOTSINK_FILT2,
412 _MMCAMCORDER_STILLSHOTSINK_ENC,
413 _MMCAMCORDER_STILLSHOTSINK_SINK,
415 _MMCamcorder_PIPELINE_ELEMENT_NUM,
416 } _MMCAMCORDER_PIPELINE_ELELMENT;
419 * Command type for Camcorder.
422 _MMCAMCORDER_CMD_CREATE,
423 _MMCAMCORDER_CMD_DESTROY,
424 _MMCAMCORDER_CMD_REALIZE,
425 _MMCAMCORDER_CMD_UNREALIZE,
426 _MMCAMCORDER_CMD_START,
427 _MMCAMCORDER_CMD_STOP,
428 _MMCAMCORDER_CMD_CAPTURESTART,
429 _MMCAMCORDER_CMD_CAPTURESTOP,
430 _MMCAMCORDER_CMD_RECORD,
431 _MMCAMCORDER_CMD_PAUSE,
432 _MMCAMCORDER_CMD_COMMIT,
433 _MMCAMCORDER_CMD_CANCEL,
434 _MMCAMCORDER_CMD_QUIT,
435 } _MMCamcorderCommandType;
438 * System state change cause
441 _MMCAMCORDER_STATE_CHANGE_NORMAL = 0,
442 _MMCAMCORDER_STATE_CHANGE_BY_ASM,
443 } _MMCamcorderStateChange;
447 /*=======================================================================================
448 | STRUCTURE DEFINITIONS |
449 ========================================================================================*/
451 * MMCamcorder Gstreamer Element
454 unsigned int id; /**< Gstreamer piplinem element name */
455 GstElement *gst; /**< Gstreamer element */
456 } _MMCamcorderGstElement;
459 * MMCamcorder information for KPI measurement
462 int current_fps; /**< current fps of this second */
463 int average_fps; /**< average fps */
464 unsigned int video_framecount; /**< total number of video frame */
465 unsigned int last_framecount; /**< total number of video frame in last measurement */
466 struct timeval init_video_time; /**< time when start to measure */
467 struct timeval last_video_time; /**< last measurement time */
468 } _MMCamcorderKPIMeasure;
471 * MMCamcorder information for Multi-Thread Safe
474 GMutex *lock; /**< Mutex (for general use) */
475 GCond *cond; /**< Condition (for general use) */
476 GMutex *cmd_lock; /**< Mutex (for command) */
477 GMutex *state_lock; /**< Mutex (for state change) */
478 GMutex *gst_state_lock; /**< Mutex (for state change) */
479 GMutex *message_cb_lock; /**< Mutex (for message callback) */
480 GMutex *vcapture_cb_lock; /**< Mutex (for video capture callback) */
481 GMutex *vstream_cb_lock; /**< Mutex (for video stream callback) */
482 GMutex *astream_cb_lock; /**< Mutex (for audio stream callback) */
483 } _MMCamcorderMTSafe;
486 * MMCamcorder information for command loop
489 pthread_t pCommandThread; /**< Command loop handle */
490 GQueue *cmd_queue; /**< Queue for Command loop */
491 sem_t sema; /**< Semaphore for Command loop */
492 } _MMCamcorderCommand;
495 * MMCamcorder command information
498 MMHandleType handle; /**< camcorder handle */
499 _MMCamcorderCommandType type; /**< Type of command */
500 } __MMCamcorderCmdInfo;
503 * MMCamcorder Sub Context
506 bool isMaxsizePausing; /**< Because of size limit, pipeline is paused. */
507 bool isMaxtimePausing; /**< Because of time limit, pipeline is paused. */
508 int element_num; /**< count of element */
509 int cam_stability_count; /**< camsensor stability count. the count of frame will drop */
510 GstClockTime pipeline_time; /**< current time of Gstreamer Pipeline */
511 GstClockTime pause_time; /** amount of time while pipeline is in PAUSE state.*/
512 GstClockTime stillshot_time; /** pipeline time of capturing moment*/
514 gboolean error_occurs;
515 gboolean ferror_send; /** file write/seek error **/
516 guint ferror_count; /** file write/seek error count **/
517 GstClockTime previous_slot_time;
518 int display_interval; /** This value is set as 'GST_SECOND / display FPS' */
519 gboolean bget_eos; /** Whether getting EOS */
520 gboolean bencbin_capture; /** Use Encodebin for capturing */
521 gboolean now_continuous_af; /** whether continuous af starts */
523 /* For dropping video frame when start recording */
524 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. */
525 int pass_first_vframe; /**< When this value is bigger than zero, MSL won't drop video frame though "drop_vframe" is bigger then zero. */
527 /* INI information */
528 unsigned int fourcc; /**< Get fourcc value of camera INI file */
529 void *info; /**< extra information for camcorder */
531 _MMCamcorderGstElement *element; /**< array of Gstreamer element */
532 _MMCamcorderKPIMeasure kpi; /**< information related with performance measurement */
534 type_element *VideosinkElement; /**< configure data of videosink element */
535 gboolean SensorEncodedCapture; /**< whether camera sensor support encoded image capture */
536 gboolean internal_encode; /**< whether use internal encoding function */
537 } _MMCamcorderSubContext;
540 * _MMCamcorderContext
542 typedef struct mmf_camcorder {
544 int type; /**< mmcamcorder_mode_type */
545 int state; /**< state of camcorder */
546 int target_state; /**< Target state that want to set. This is a flag that
547 * stands for async state changing. If this value differ from state,
548 * it means state is changing now asychronously. */
551 MMHandleType attributes; /**< Attribute handle */
552 _MMCamcorderSubContext *sub_context; /**< sub context */
553 mm_exif_info_t *exif_info; /**< EXIF */
554 GList *buffer_probes; /**< a list of buffer probe handle */
555 GList *event_probes; /**< a list of event probe handle */
556 GList *data_probes; /**< a list of data probe handle */
557 GList *signals; /**< a list of signal handle */
558 GList *msg_data; /**< a list of msg data */
559 camera_conf *conf_main; /**< Camera configure Main structure */
560 camera_conf *conf_ctrl; /**< Camera configure Control structure */
561 int asm_handle; /**< Audio session manager handle */
562 guint pipeline_cb_event_id; /**< Event source ID of pipeline message callback */
563 guint setting_event_id; /**< Event source ID of attributes setting to sensor */
564 SOUND_INFO snd_info; /**< Sound handle for multishot capture */
566 /* callback handlers */
567 MMMessageCallback msg_cb; /**< message callback */
568 void *msg_cb_param; /**< message callback parameter */
569 mm_camcorder_video_stream_callback vstream_cb; /**< Video stream callback */
570 void *vstream_cb_param; /**< Video stream callback parameter */
571 mm_camcorder_audio_stream_callback astream_cb; /**< Audio stream callback */
572 void *astream_cb_param; /**< Audio stream callback parameter */
573 mm_camcorder_video_capture_callback vcapture_cb; /**< Video capture callback */
574 void *vcapture_cb_param; /**< Video capture callback parameter */
575 int (*command)(MMHandleType, int); /**< camcorder's command */
578 _MMCamcorderMTSafe mtsafe; /**< Thread safe */
579 _MMCamcorderCommand cmd; /**< information for command loop */
580 int sync_state_change; /**< Change framework state synchronously */
581 int quick_device_close;
582 int state_change_by_system; /**< MSL changes its state by itself because of system(ASM,MDM..) **/
583 int asm_event_code; /**< event code of audio session manager */
584 pthread_mutex_t sound_lock; /**< Capture sound mutex */
585 pthread_cond_t sound_cond; /**< Capture sound cond */
586 int use_zero_copy_format; /**< Whether use zero copy format for camera input */
588 int reserved[4]; /**< reserved */
591 /*=======================================================================================
592 | EXTERN GLOBAL VARIABLE |
593 ========================================================================================*/
595 /*=======================================================================================
596 | GLOBAL FUNCTION PROTOTYPES |
597 ========================================================================================*/
599 * This function creates camcorder for capturing still image and recording.
601 * @param[out] handle Specifies the camcorder handle
602 * @param[in] info Preset information of camcorder
603 * @return This function returns zero on success, or negative value with error code.
604 * @remarks When this function calls successfully, camcorder handle will be filled with a @n
605 * valid value and the state of the camcorder will become MM_CAMCORDER_STATE_NULL.@n
606 * Note that it's not ready to working camcorder. @n
607 * You should call mmcamcorder_realize before starting camcorder.
608 * @see _mmcamcorder_create
610 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info);
613 * This function destroys instance of camcorder.
615 * @param[in] hcamcorder Specifies the camcorder handle
616 * @return This function returns zero on success, or negative value with error code.
617 * @see _mmcamcorder_create
619 int _mmcamcorder_destroy(MMHandleType hcamcorder);
622 * This function allocates memory for camcorder.
624 * @param[in] hcamcorder Specifies the camcorder handle
625 * @return This function returns zero on success, or negative value with error code.
626 * @remarks This function can be called successfully when current state is MM_CAMCORDER_STATE_NULL @n
627 * and the state of the camcorder will become MM_CAMCORDER_STATE_READY. @n
628 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
629 * @see _mmcamcorder_unrealize
630 * @pre MM_CAMCORDER_STATE_NULL
631 * @post MM_CAMCORDER_STATE_READY
633 int _mmcamcorder_realize(MMHandleType hcamcorder);
636 * This function free allocated memory for camcorder.
638 * @param[in] hcamcorder Specifies the camcorder handle
639 * @return This function returns zero on success, or negative value with error code.
640 * @remarks This function release all resources which are allocated for the camcorder engine.@n
641 * This function can be called successfully when current state is MM_CAMCORDER_STATE_READY and @n
642 * the state of the camcorder will become MM_CAMCORDER_STATE_NULL. @n
643 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
644 * @see _mmcamcorder_realize
645 * @pre MM_CAMCORDER_STATE_READY
646 * @post MM_CAMCORDER_STATE_NULL
648 int _mmcamcorder_unrealize(MMHandleType hcamcorder);
651 * This function is to start previewing.
653 * @param[in] hcamcorder Specifies the camcorder handle
654 * @return This function returns zero on success, or negative value with error code.
655 * @remarks This function can be called successfully when current state is MM_CAMCORDER_STATE_READY and @n
656 * the state of the camcorder will become MM_CAMCORDER_STATE_PREPARE. @n
657 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
658 * @see _mmcamcorder_stop
660 int _mmcamcorder_start(MMHandleType hcamcorder);
663 * This function is to stop previewing.
665 * @param[in] hcamcorder Specifies the camcorder handle
666 * @return This function returns zero on success, or negative value with error code.
667 * @remarks This function can be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and @n
668 * the state of the camcorder will become MM_CAMCORDER_STATE_READY.@n
669 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
670 * @see _mmcamcorder_start
672 int _mmcamcorder_stop(MMHandleType hcamcorder);
675 * This function to start capturing of still images.
677 * @param[in] hcamcorder Specifies the camcorder handle.
678 * @return This function returns zero on success, or negative value with error code.
679 * @remarks This function can be called successfully when current state is MM_CAMCORDER_STATE_PREPARE and @n
680 * the state of the camcorder will become MM_CAMCORDER_STATE_CAPTURING. @n
681 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
682 * @see _mmcamcorder_capture_stop
684 int _mmcamcorder_capture_start(MMHandleType hcamcorder);
687 * This function is to stop capturing still images.
689 * @param[in] hcamcorder Specifies the camcorder handle
690 * @return This function returns zero on success, or negative value with error code.
691 * @remarks This function can be called successfully when current state is MM_CAMCORDER_STATE_CAPTURING and @n
692 * the state of the camcorder will become MM_CAMCORDER_STATE_PREPARE. @n
693 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
694 * @see _mmcamcorder_capture_start
696 int _mmcamcorder_capture_stop(MMHandleType hcamcorder);
699 * This function is to start video and audio recording.
701 * @param[in] hcamcorder Specifies the camcorder handle
702 * @return This function returns zero on success, or negative value with error code.
703 * @remarks This function can be called successfully when current state is @n
704 * MM_CAMCORDER_STATE_PREPARE or MM_CAMCORDER_STATE_PAUSED and @n
705 * the state of the camcorder will become MM_CAMCORDER_STATE_RECORDING.@n
706 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
707 * @see _mmcamcorder_pause
709 int _mmcamcorder_record(MMHandleType hcamcorder);
712 * This function is to pause video and audio recording
714 * @param[in] hcamcorder Specifies the camcorder handle
715 * @return This function returns zero on success, or negative value with error code.
716 * @remarks This function can be called successfully when current state is MM_CAMCORDER_STATE_RECORDING and @n
717 * the state of the camcorder will become MM_CAMCORDER_STATE_PAUSED.@n
718 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.@n
719 * @see _mmcamcorder_record
721 int _mmcamcorder_pause(MMHandleType hcamcorder);
724 * This function is to stop video and audio recording and save results.
726 * @param[in] hcamcorder Specifies the camcorder handle
727 * @return This function returns zero on success, or negative value with error code.
728 * @remarks This function can be called successfully when current state is @n
729 * MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and @n
730 * the state of the camcorder will become MM_CAMCORDER_STATE_PREPARE. @n
731 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION
732 * @see _mmcamcorder_cancel
734 int _mmcamcorder_commit(MMHandleType hcamcorder);
737 * This function is to stop video and audio recording and do not save results.
739 * @param[in] hcamcorder Specifies the camcorder handle
740 * @return This function returns zero on success, or negative value with error code.
741 * @remarks This function can be called successfully when current state is @n
742 * MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and @n
743 * the state of the camcorder will become MM_CAMCORDER_STATE_PREPARE. @n
744 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
745 * @see _mmcamcorder_commit
747 int _mmcamcorder_cancel(MMHandleType hcamcorder);
750 * This function calls after commiting action finished asynchronously.
751 * In this function, remaining process , such as state change, happens.
753 * @param[in] hcamcorder Specifies the camcorder handle
754 * @return This function returns zero on success, or negative value with error code.
755 * @remarks This function can be called successfully when current state is @n
756 * MM_CAMCORDER_STATE_PAUSED or MM_CAMCORDER_STATE_RECORDING and @n
757 * the state of the camcorder will become MM_CAMCORDER_STATE_PREPARE. @n
758 * Otherwise, this function will return MM_ERROR_CAMCORDER_INVALID_CONDITION.
759 * @see _mmcamcorder_commit
761 int _mmcamcorder_commit_async_end(MMHandleType hcamcorder);
764 * This function is to set callback for receiving messages from camcorder.
766 * @param[in] hcamcorder Specifies the camcorder handle
767 * @param[in] callback Specifies the function pointer of callback function
768 * @param[in] user_data Specifies the user poiner for passing to callback function
770 * @return This function returns zero on success, or negative value with error code.
771 * @remarks typedef bool (*mm_message_callback) (int msg, mm_messageType *param, void *user_param);@n
786 * } mm_message_type; @n
788 * If a message value for mm_message_callback is MM_MESSAGE_STATE_CHANGED, @n
789 * state value in mm_message_type will be a mmcamcorder_state_type enum value;@n
791 * If a message value for mm_message_callback is MM_MESSAGE_ERROR, @n
792 * the code value in mm_message_type will be a mmplayer_error_type enum value;
794 * @see mm_message_type, mmcamcorder_state_type, mmcamcorder_error_type
796 int _mmcamcorder_set_message_callback(MMHandleType hcamcorder,
797 MMMessageCallback callback,
801 * This function is to set callback for video stream.
803 * @param[in] hcamcorder Specifies the camcorder handle
804 * @param[in] callback Specifies the function pointer of callback function
805 * @param[in] user_data Specifies the user poiner for passing to callback function
807 * @return This function returns zero on success, or negative value with error code.
808 * @see mmcamcorder_error_type
810 int _mmcamcorder_set_video_stream_callback(MMHandleType hcamcorder,
811 mm_camcorder_video_stream_callback callback,
815 * This function is to set callback for audio stream.
817 * @param[in] hcamcorder Specifies the camcorder handle
818 * @param[in] callback Specifies the function pointer of callback function
819 * @param[in] user_data Specifies the user poiner for passing to callback function
821 * @return This function returns zero on success, or negative value with error code.
822 * @see mmcamcorder_error_type
824 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle,
825 mm_camcorder_audio_stream_callback callback,
829 * This function is to set callback for video capture.
831 * @param[in] hcamcorder Specifies the camcorder handle
832 * @param[in] callback Specifies the function pointer of callback function
833 * @param[in] user_data Specifies the user poiner for passing to callback function
835 * @return This function returns zero on success, or negative value with error code.
836 * @see mmcamcorder_error_type
838 int _mmcamcorder_set_video_capture_callback(MMHandleType hcamcorder,
839 mm_camcorder_video_capture_callback callback,
843 * This function returns current state of camcorder, or negative value with error code.
845 * @param[in] hcamcorder Specifies the camcorder handle.
846 * @return This function returns current state of camcorder, or negative value with error code.
847 * @see mmcamcorder_state_type
849 int _mmcamcorder_get_current_state(MMHandleType hcamcorder);
851 int _mmcamcorder_init_focusing(MMHandleType handle);
852 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction);
853 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction);
854 int _mmcamcorder_adjust_auto_focus(MMHandleType handle);
855 int _mmcamcorder_stop_focusing(MMHandleType handle);
858 * This function gets current state of camcorder.
861 * @return This function returns state of current camcorder context
863 * @see _mmcamcorder_set_state()
866 int _mmcamcorder_streamer_init(void);
869 * This function gets current state of camcorder.
872 * @return This function returns state of current camcorder context
874 * @see _mmcamcorder_set_state()
877 int _mmcamcorder_display_init(void);
880 * This function gets current state of camcorder.
882 * @param[in] handle Handle of camcorder context.
883 * @return This function returns state of current camcorder context
885 * @see _mmcamcorder_set_state()
888 int _mmcamcorder_get_state(MMHandleType handle);
891 * This function sets new state of camcorder.
893 * @param[in] handle Handle of camcorder context.
894 * @param[in] state setting state value of camcorder.
897 * @see _mmcamcorder_get_state()
900 void _mmcamcorder_set_state(MMHandleType handle, int state);
903 * This function gets asynchronous status of MSL Camcroder.
905 * @param[in] handle Handle of camcorder context.
906 * @param[in] target_state setting target_state value of camcorder.
907 * @return This function returns asynchrnous state.
909 * @see _mmcamcorder_set_async_state()
912 int _mmcamcorder_get_async_state(MMHandleType handle);
915 * This function sets new target state of camcorder.
917 * @param[in] handle Handle of camcorder context.
918 * @param[in] target_state setting target_state value of camcorder.
919 * @return This function returns zero on success, or negative value with error code.
921 * @see _mmcamcorder_get_async_state(), _mmcamcorder_set_async_cancel()
924 int _mmcamcorder_set_async_state(MMHandleType handle, int target_state);
927 * This function sets new target state of camcorder.
929 * @param[in] handle Handle of camcorder context.
932 * @see _mmcamcorder_set_async_cancel()
935 gboolean _mmcamcorder_set_async_cancel(MMHandleType handle);
938 * Check whether camcorder changes its state now.
940 * @param[in] handle Handle of camcorder context.
943 * @see _mmcamcorder_set_async_state(), _mmcamcorder_set_async_cancel()
946 gboolean _mmcamcorder_is_state_changing(MMHandleType handle);
949 * This function allocates structure of subsidiary attributes.
951 * @param[in] type Allocation type of camcorder context.
952 * @return This function returns structure pointer on success, NULL value on failure.
954 * @see _mmcamcorder_dealloc_subcontext()
957 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type);
960 * This function releases structure of subsidiary attributes.
962 * @param[in] sc Handle of camcorder subcontext.
965 * @see _mmcamcorder_alloc_subcontext()
968 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc);
971 * This function sets command function according to the type.
973 * @param[in] handle Handle of camcorder context.
974 * @param[in] type Allocation type of camcorder context.
975 * @return This function returns MM_ERROR_NONE on success, or other values with error code.
977 * @see __mmcamcorder_video_command(), __mmcamcorder_audio_command(), __mmcamcorder_image_command()
980 int _mmcamcorder_set_functions(MMHandleType handle, int type);
983 * This function is callback function of main pipeline.
984 * Once this function is registered with certain pipeline using gst_bus_add_watch(),
985 * this callback will be called every time when there is upcomming message from pipeline.
986 * Basically, this function is used as error handling function, now.
988 * @param[in] bus pointer of buf that called this function.
989 * @param[in] message callback message from pipeline.
990 * @param[in] data user data.
991 * @return This function returns true on success, or false value with error
993 * @see __mmcamcorder_create_preview_pipeline()
996 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data);
999 * This function create main pipeline according to type.
1001 * @param[in] handle Handle of camcorder context.
1002 * @param[in] type Allocation type of camcorder context.
1003 * @return This function returns zero on success, or negative value with error code.
1005 * @see _mmcamcorder_destroy_pipeline()
1008 int _mmcamcorder_create_pipeline(MMHandleType handle, int type);
1011 * This function release all element of main pipeline according to type.
1013 * @param[in] handle Handle of camcorder context.
1014 * @param[in] type Allocation type of camcorder context.
1017 * @see _mmcamcorder_create_pipeline()
1020 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type);
1023 * This function sets gstreamer element status.
1024 * If the gstreamer fails to set status or returns asynchronous mode,
1025 * this function waits for state changed until timeout expired.
1027 * @param[in] pipeline Pointer of pipeline
1028 * @param[in] target_state newly setting status
1029 * @return This function returns zero on success, or negative value with error code.
1034 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state);
1037 * This function sets gstreamer element status, asynchronously.
1038 * Regardless of processing, it returns immediately.
1040 * @param[in] pipeline Pointer of pipeline
1041 * @param[in] target_state newly setting status
1042 * @return This function returns zero on success, or negative value with error code.
1047 int _mmcamcorder_gst_set_state_async(MMHandleType handle, GstElement *pipeline, GstState target_state);
1049 /* For xvimagesink */
1050 GstBusSyncReply __mmcamcorder_sync_callback(GstBus *bus, GstMessage *message, gulong data);
1052 /* For querying capabilities */
1053 int _mmcamcorder_read_vidsrc_info(int videodevidx, camera_conf **configure_info);
1055 /* for performance check */
1056 void _mmcamcorder_video_current_framerate_init(MMHandleType handle);
1057 int _mmcamcorder_video_current_framerate(MMHandleType handle);
1058 int _mmcamcorder_video_average_framerate(MMHandleType handle);
1061 void _mmcamcorder_delete_command_info(__MMCamcorderCmdInfo *cmdinfo);
1062 int _mmcamcorder_create_command_loop(MMHandleType handle);
1063 int _mmcamcorder_destroy_command_loop(MMHandleType handle);
1064 int _mmcamcorder_append_command(MMHandleType handle, __MMCamcorderCmdInfo *info);
1065 int _mmcamcorder_append_simple_command(MMHandleType handle, _MMCamcorderCommandType type);
1066 void *_mmcamcorder_command_loop_thread(void *arg);
1072 #endif /* __MM_CAMCORDER_INTERNAL_H__ */