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 /*=======================================================================================
24 ========================================================================================*/
28 #include <gst/gstutils.h>
29 #include <gst/gstpad.h>
32 #include "mm_camcorder_internal.h"
35 #include <gst/video/colorbalance.h>
36 #include <gst/video/cameracontrol.h>
38 #include <system_info.h>
40 /*---------------------------------------------------------------------------------------
41 | GLOBAL VARIABLE DEFINITIONS for internal |
42 ---------------------------------------------------------------------------------------*/
44 /*---------------------------------------------------------------------------------------
45 | LOCAL VARIABLE DEFINITIONS for internal |
46 ---------------------------------------------------------------------------------------*/
47 #define __MMCAMCORDER_CMD_ITERATE_MAX 3
48 #define __MMCAMCORDER_SET_GST_STATE_TIMEOUT 3
49 #define __MMCAMCORDER_SOUND_WAIT_TIMEOUT 3
51 /*---------------------------------------------------------------------------------------
52 | LOCAL FUNCTION PROTOTYPES: |
53 ---------------------------------------------------------------------------------------*/
54 /* STATIC INTERNAL FUNCTION */
55 static gboolean __mmcamcorder_gstreamer_init(camera_conf * conf);
57 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error);
58 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message);
59 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message);
60 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message);
61 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message);
62 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error);
63 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error);
66 #ifdef _MMCAMCORDER_USE_SET_ATTR_CB
67 static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data);
68 #endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
70 /*=======================================================================================
71 | FUNCTION DEFINITIONS |
72 =======================================================================================*/
73 /*---------------------------------------------------------------------------------------
74 | GLOBAL FUNCTION DEFINITIONS: |
75 ---------------------------------------------------------------------------------------*/
77 /* Internal command functions {*/
78 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
80 int ret = MM_ERROR_NONE;
82 int rcmd_fmt_capture = MM_PIXEL_FORMAT_YUYV;
83 int rcmd_fmt_recording = MM_PIXEL_FORMAT_NV12;
84 int rcmd_dpy_rotation = MM_DISPLAY_ROTATION_270;
85 int play_capture_sound = TRUE;
86 int camera_device_count = MM_VIDEO_DEVICE_NUM;
87 int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
88 char *err_attr_name = NULL;
89 const char *ConfCtrlFile = NULL;
90 mmf_camcorder_t *hcamcorder = NULL;
91 type_element *EvasSurfaceElement = NULL;
93 _mmcam_dbg_log("Entered");
95 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
96 mmf_return_val_if_fail(info, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
98 /* Create mmf_camcorder_t handle and initialize every variable */
99 hcamcorder = (mmf_camcorder_t *)malloc(sizeof(mmf_camcorder_t));
100 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_LOW_MEMORY);
101 memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
104 hcamcorder->type = 0;
105 hcamcorder->state = MM_CAMCORDER_STATE_NONE;
106 hcamcorder->sub_context = NULL;
107 hcamcorder->target_state = MM_CAMCORDER_STATE_NULL;
108 hcamcorder->capture_in_recording = FALSE;
110 pthread_mutex_init(&((hcamcorder->mtsafe).lock), NULL);
111 pthread_cond_init(&((hcamcorder->mtsafe).cond), NULL);
113 pthread_mutex_init(&((hcamcorder->mtsafe).cmd_lock), NULL);
114 pthread_mutex_init(&((hcamcorder->mtsafe).asm_lock), NULL);
115 pthread_mutex_init(&((hcamcorder->mtsafe).state_lock), NULL);
116 pthread_mutex_init(&((hcamcorder->mtsafe).gst_state_lock), NULL);
117 pthread_mutex_init(&((hcamcorder->mtsafe).gst_encode_state_lock), NULL);
118 pthread_mutex_init(&((hcamcorder->mtsafe).message_cb_lock), NULL);
119 pthread_mutex_init(&((hcamcorder->mtsafe).vcapture_cb_lock), NULL);
120 pthread_mutex_init(&((hcamcorder->mtsafe).vstream_cb_lock), NULL);
121 pthread_mutex_init(&((hcamcorder->mtsafe).astream_cb_lock), NULL);
123 pthread_mutex_init(&(hcamcorder->sound_lock), NULL);
124 pthread_cond_init(&(hcamcorder->sound_cond), NULL);
125 pthread_mutex_init(&(hcamcorder->restart_preview_lock), NULL);
127 /* Sound mutex/cond init */
128 pthread_mutex_init(&(hcamcorder->snd_info.open_mutex), NULL);
129 pthread_cond_init(&(hcamcorder->snd_info.open_cond), NULL);
131 /* init for sound thread */
132 pthread_mutex_init(&(hcamcorder->task_thread_lock), NULL);
133 pthread_cond_init(&(hcamcorder->task_thread_cond), NULL);
134 hcamcorder->task_thread_state = _MMCAMCORDER_SOUND_STATE_NONE;
136 /* create task thread */
137 pthread_create(&(hcamcorder->task_thread), NULL, _mmcamcorder_util_task_thread_func, (void *)hcamcorder);
139 if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
140 info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
141 _mmcam_dbg_err("_mmcamcorder_create::video device type is out of range.");
142 ret = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
143 goto _ERR_DEFAULT_VALUE_INIT;
146 /* set device type */
147 hcamcorder->device_type = info->videodev_type;
148 _mmcam_dbg_warn("Device Type : %d", hcamcorder->device_type);
150 /* Get Camera Configure information from Camcorder INI file */
151 _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &hcamcorder->conf_main);
153 if (!(hcamcorder->conf_main)) {
154 _mmcam_dbg_err( "Failed to get configure(main) info." );
156 ret = MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
157 goto _ERR_AFTER_ASM_REGISTER;
160 hcamcorder->attributes = _mmcamcorder_alloc_attribute((MMHandleType)hcamcorder, info);
161 if (!(hcamcorder->attributes)) {
162 _mmcam_dbg_err("_mmcamcorder_create::alloc attribute error.");
164 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
165 goto _ERR_AFTER_ASM_REGISTER;
168 if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
169 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
170 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
171 "UseConfCtrl", &UseConfCtrl);
174 _mmcam_dbg_log( "Enable Configure Control system." );
176 switch (info->videodev_type) {
177 case MM_VIDEO_DEVICE_CAMERA0:
178 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
179 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
180 "ConfCtrlFile0", &ConfCtrlFile);
182 case MM_VIDEO_DEVICE_CAMERA1:
183 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
184 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
185 "ConfCtrlFile1", &ConfCtrlFile);
188 _mmcam_dbg_err( "Not supported camera type." );
189 ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
190 goto _ERR_AFTER_ASM_REGISTER;
193 _mmcam_dbg_log("videodev_type : [%d], ConfCtrlPath : [%s]", info->videodev_type, ConfCtrlFile);
195 _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_CTRL, ConfCtrlFile, &hcamcorder->conf_ctrl);
197 _mmcamcorder_conf_print_info(&hcamcorder->conf_main);
198 _mmcamcorder_conf_print_info(&hcamcorder->conf_ctrl);
200 if (!(hcamcorder->conf_ctrl)) {
201 _mmcam_dbg_err( "Failed to get configure(control) info." );
202 ret = MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
203 goto _ERR_AFTER_ASM_REGISTER;
206 ret = _mmcamcorder_init_convert_table((MMHandleType)hcamcorder);
207 if (ret != MM_ERROR_NONE) {
208 _mmcam_dbg_warn("converting table initialize error!!");
211 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder);
212 if (ret != MM_ERROR_NONE) {
213 _mmcam_dbg_warn("converting table initialize error!!");
216 /* Get device info, recommend preview fmt and display rotation from INI */
217 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
218 CONFIGURE_CATEGORY_CTRL_CAMERA,
219 "RecommendPreviewFormatCapture",
222 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
223 CONFIGURE_CATEGORY_CTRL_CAMERA,
224 "RecommendPreviewFormatRecord",
225 &rcmd_fmt_recording);
227 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
228 CONFIGURE_CATEGORY_CTRL_CAMERA,
229 "RecommendDisplayRotation",
232 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
233 CONFIGURE_CATEGORY_MAIN_CAPTURE,
235 &play_capture_sound);
237 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
238 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
240 &camera_device_count);
242 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
243 CONFIGURE_CATEGORY_CTRL_CAMERA,
245 &camera_facing_direction);
247 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
248 CONFIGURE_CATEGORY_CTRL_EFFECT,
249 "BrightnessStepDenominator",
250 &hcamcorder->brightness_step_denominator);
252 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
253 CONFIGURE_CATEGORY_CTRL_CAPTURE,
255 &hcamcorder->support_zsl_capture);
257 _mmcam_dbg_log("Recommend fmt[cap:%d,rec:%d], dpy rot %d, cap snd %d, dev cnt %d, cam facing dir %d, step denom %d, support zsl %d",
258 rcmd_fmt_capture, rcmd_fmt_recording, rcmd_dpy_rotation,
259 play_capture_sound, camera_device_count, camera_facing_direction,
260 hcamcorder->brightness_step_denominator, hcamcorder->support_zsl_capture);
262 /* Get UseZeroCopyFormat value from INI */
263 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
264 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
266 &(hcamcorder->use_zero_copy_format));
268 /* Get SupportMediaPacketPreviewCb value from INI */
269 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
270 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
271 "SupportMediaPacketPreviewCb",
272 &(hcamcorder->support_media_packet_preview_cb));
274 _mmcam_dbg_log("UseZeroCopyFormat : %d", hcamcorder->use_zero_copy_format);
275 _mmcam_dbg_log("SupportMediaPacketPreviewCb : %d", hcamcorder->support_media_packet_preview_cb);
277 mm_camcorder_set_attributes((MMHandleType)hcamcorder, &err_attr_name,
278 MMCAM_CAMERA_DEVICE_COUNT, camera_device_count,
279 MMCAM_CAMERA_FACING_DIRECTION, camera_facing_direction,
280 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, rcmd_fmt_capture,
281 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, rcmd_fmt_recording,
282 MMCAM_RECOMMEND_DISPLAY_ROTATION, rcmd_dpy_rotation,
283 MMCAM_SUPPORT_ZSL_CAPTURE, hcamcorder->support_zsl_capture,
284 MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
285 MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
286 "capture-sound-enable", play_capture_sound,
289 _mmcam_dbg_err("Set %s FAILED.", err_attr_name);
291 err_attr_name = NULL;
294 /* Get default value of brightness */
295 mm_camcorder_get_attributes((MMHandleType)hcamcorder, &err_attr_name,
296 MMCAM_FILTER_BRIGHTNESS, &hcamcorder->brightness_default,
299 _mmcam_dbg_err("Get brightness FAILED.");
301 err_attr_name = NULL;
303 _mmcam_dbg_log("Default brightness : %d", hcamcorder->brightness_default);
305 _mmcam_dbg_log( "Disable Configure Control system." );
306 hcamcorder->conf_ctrl = NULL;
310 ret = __mmcamcorder_gstreamer_init(hcamcorder->conf_main);
312 _mmcam_dbg_err( "Failed to initialize gstreamer!!" );
313 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
314 goto _ERR_AFTER_ASM_REGISTER;
317 /* Make some attributes as read-only type */
318 _mmcamcorder_lock_readonly_attributes((MMHandleType)hcamcorder);
320 /* Disable attributes in each model */
321 _mmcamcorder_set_disabled_attributes((MMHandleType)hcamcorder);
323 /* Get videosink name for evas surface */
324 _mmcamcorder_conf_get_element((MMHandleType)hcamcorder, hcamcorder->conf_main,
325 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
326 "VideosinkElementEvas",
327 &EvasSurfaceElement);
328 if (EvasSurfaceElement) {
330 const char *evassink_name = NULL;
331 mmf_attribute_t *item_evassink_name = NULL;
332 mmf_attrs_t *attrs = (mmf_attrs_t *)MMF_CAMCORDER_ATTRS(hcamcorder);
334 _mmcamcorder_conf_get_value_element_name(EvasSurfaceElement, &evassink_name);
335 mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_EVAS_SURFACE_SINK, &attr_index);
336 item_evassink_name = &attrs->items[attr_index];
337 mmf_attribute_set_string(item_evassink_name, evassink_name, strlen(evassink_name));
338 mmf_attribute_commit(item_evassink_name);
340 _mmcam_dbg_log("Evassink name : %s", evassink_name);
343 /* get shutter sound policy */
344 vconf_get_int(VCONFKEY_CAMERA_SHUTTER_SOUND_POLICY, &hcamcorder->shutter_sound_policy);
345 _mmcam_dbg_log("current shutter sound policy : %d", hcamcorder->shutter_sound_policy);
348 system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &hcamcorder->model_name);
350 /* get software version */
351 system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &hcamcorder->software_version);
353 /* Set initial state */
354 _mmcamcorder_set_state((MMHandleType)hcamcorder, MM_CAMCORDER_STATE_NULL);
356 _mmcam_dbg_log("created handle %p", hcamcorder);
358 *handle = (MMHandleType)hcamcorder;
360 return MM_ERROR_NONE;
362 _ERR_AFTER_ASM_REGISTER:
364 _ERR_DEFAULT_VALUE_INIT:
365 /* Release lock, cond */
366 pthread_mutex_destroy(&((hcamcorder->mtsafe).lock));
367 pthread_cond_destroy(&((hcamcorder->mtsafe).cond));
368 pthread_mutex_destroy(&((hcamcorder->mtsafe).cmd_lock));
369 pthread_mutex_destroy(&((hcamcorder->mtsafe).asm_lock));
370 pthread_mutex_destroy(&((hcamcorder->mtsafe).state_lock));
371 pthread_mutex_destroy(&((hcamcorder->mtsafe).gst_state_lock));
372 pthread_mutex_destroy(&((hcamcorder->mtsafe).gst_encode_state_lock));
373 pthread_mutex_destroy(&((hcamcorder->mtsafe).message_cb_lock));
374 pthread_mutex_destroy(&((hcamcorder->mtsafe).vcapture_cb_lock));
375 pthread_mutex_destroy(&((hcamcorder->mtsafe).vstream_cb_lock));
376 pthread_mutex_destroy(&((hcamcorder->mtsafe).astream_cb_lock));
378 pthread_mutex_destroy(&(hcamcorder->sound_lock));
379 pthread_cond_destroy(&(hcamcorder->sound_cond));
380 pthread_mutex_destroy(&(hcamcorder->snd_info.open_mutex));
381 pthread_cond_destroy(&(hcamcorder->snd_info.open_cond));
382 pthread_mutex_destroy(&(hcamcorder->restart_preview_lock));
384 if (hcamcorder->conf_ctrl) {
385 _mmcamcorder_conf_release_info(handle, &hcamcorder->conf_ctrl);
388 if (hcamcorder->conf_main) {
389 _mmcamcorder_conf_release_info(handle, &hcamcorder->conf_main);
392 if (hcamcorder->model_name) {
393 free(hcamcorder->model_name);
394 hcamcorder->model_name = NULL;
397 if (hcamcorder->software_version) {
398 free(hcamcorder->software_version);
399 hcamcorder->software_version = NULL;
403 memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
410 int _mmcamcorder_destroy(MMHandleType handle)
412 int ret = MM_ERROR_NONE;
413 int state = MM_CAMCORDER_STATE_NONE;
414 int state_FROM = MM_CAMCORDER_STATE_NULL;
416 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
421 _mmcam_dbg_err("Not initialized");
422 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
423 goto _ERR_CAMCORDER_CMD_PRECON;
426 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
427 _mmcam_dbg_err("Another command is running.");
428 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
429 goto _ERR_CAMCORDER_CMD_PRECON;
432 state = _mmcamcorder_get_state(handle);
433 if (state != state_FROM) {
434 _mmcam_dbg_err("Wrong state(%d)", state);
435 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
436 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
439 /* set exit state for sound thread */
440 pthread_mutex_lock(&(hcamcorder->task_thread_lock));
441 _mmcam_dbg_log("send signal for task thread exit");
442 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_EXIT;
443 pthread_cond_signal(&(hcamcorder->task_thread_cond));
444 pthread_mutex_unlock(&(hcamcorder->task_thread_lock));
446 pthread_mutex_lock(&(hcamcorder->sound_lock));
447 while (hcamcorder->capture_sound_count > 0) {
448 struct timespec timeout;
451 gettimeofday(&tv, NULL);
452 timeout.tv_sec = tv.tv_sec + __MMCAMCORDER_SOUND_WAIT_TIMEOUT;
453 timeout.tv_nsec = tv.tv_usec * 1000;
455 _mmcam_dbg_warn("capture_sound_count[%d] is not zero. wait signal...",
456 hcamcorder->capture_sound_count);
458 if (!pthread_cond_timedwait(&(hcamcorder->sound_cond), &(hcamcorder->sound_lock), &timeout)) {
459 _mmcam_dbg_warn("signal received. check again...");
461 hcamcorder->capture_sound_count = 0;
462 _mmcam_dbg_err("capture sound completion wait time out");
466 pthread_mutex_unlock(&(hcamcorder->sound_lock));
468 /* Release SubContext and pipeline */
469 if (hcamcorder->sub_context) {
470 if (hcamcorder->sub_context->element) {
471 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
474 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
475 hcamcorder->sub_context = NULL;
478 /* Remove idle function which is not called yet */
479 if (hcamcorder->setting_event_id) {
480 _mmcam_dbg_log("Remove remaining idle function");
481 g_source_remove(hcamcorder->setting_event_id);
482 hcamcorder->setting_event_id = 0;
485 /* Remove attributes */
486 if (hcamcorder->attributes) {
487 _mmcamcorder_dealloc_attribute(handle, hcamcorder->attributes);
488 hcamcorder->attributes = 0;
491 /* Remove exif info */
492 if (hcamcorder->exif_info) {
493 mm_exif_destory_exif_info(hcamcorder->exif_info);
494 hcamcorder->exif_info=NULL;
498 /* Release configure info */
499 if (hcamcorder->conf_ctrl) {
500 _mmcamcorder_conf_release_info(handle, &hcamcorder->conf_ctrl);
502 if (hcamcorder->conf_main) {
503 _mmcamcorder_conf_release_info(handle, &hcamcorder->conf_main);
506 /* Remove messages which are not called yet */
507 _mmcamcroder_remove_message_all(handle);
509 /* release model_name */
510 if (hcamcorder->model_name) {
511 free(hcamcorder->model_name);
512 hcamcorder->model_name = NULL;
515 if (hcamcorder->software_version) {
516 free(hcamcorder->software_version);
517 hcamcorder->software_version = NULL;
520 /* join task thread */
521 _mmcam_dbg_log("task thread join");
522 pthread_join(hcamcorder->task_thread, NULL);
524 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
526 /* Release lock, cond */
527 pthread_mutex_destroy(&((hcamcorder->mtsafe).lock));
528 pthread_cond_destroy(&((hcamcorder->mtsafe).cond));
529 pthread_mutex_destroy(&((hcamcorder->mtsafe).cmd_lock));
530 pthread_mutex_destroy(&((hcamcorder->mtsafe).asm_lock));
531 pthread_mutex_destroy(&((hcamcorder->mtsafe).state_lock));
532 pthread_mutex_destroy(&((hcamcorder->mtsafe).gst_state_lock));
533 pthread_mutex_destroy(&((hcamcorder->mtsafe).gst_encode_state_lock));
534 pthread_mutex_destroy(&((hcamcorder->mtsafe).message_cb_lock));
535 pthread_mutex_destroy(&((hcamcorder->mtsafe).vcapture_cb_lock));
536 pthread_mutex_destroy(&((hcamcorder->mtsafe).vstream_cb_lock));
537 pthread_mutex_destroy(&((hcamcorder->mtsafe).astream_cb_lock));
539 pthread_mutex_destroy(&(hcamcorder->sound_lock));
540 pthread_cond_destroy(&(hcamcorder->sound_cond));
541 pthread_mutex_destroy(&(hcamcorder->snd_info.open_mutex));
542 pthread_cond_destroy(&(hcamcorder->snd_info.open_cond));
543 pthread_mutex_destroy(&(hcamcorder->restart_preview_lock));
544 pthread_mutex_destroy(&(hcamcorder->task_thread_lock));
545 pthread_cond_destroy(&(hcamcorder->task_thread_cond));
548 memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
551 return MM_ERROR_NONE;
553 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
554 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
556 _ERR_CAMCORDER_CMD_PRECON:
558 _mmcam_dbg_err("Destroy fail (type %d, state %d)", hcamcorder->type, state);
561 _mmcam_dbg_err("Destroy fail (ret %x)", ret);
567 int _mmcamcorder_realize(MMHandleType handle)
569 int ret = MM_ERROR_NONE;
570 int state = MM_CAMCORDER_STATE_NONE;
571 int state_FROM = MM_CAMCORDER_STATE_NULL;
572 int state_TO = MM_CAMCORDER_STATE_READY;
573 int display_surface_type = MM_DISPLAY_SURFACE_X;
574 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
575 char *videosink_element_type = NULL;
576 const char *videosink_name = NULL;
578 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
583 _mmcam_dbg_err("Not initialized");
584 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
588 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
589 _mmcam_dbg_err("Another command is running.");
590 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
591 goto _ERR_CAMCORDER_CMD_PRECON;
594 state = _mmcamcorder_get_state(handle);
595 if (state != state_FROM) {
596 _mmcam_dbg_err("Wrong state(%d)", state);
597 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
598 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
601 mm_camcorder_get_attributes(handle, NULL,
602 MMCAM_MODE, &hcamcorder->type,
605 /* Get profile mode */
606 _mmcam_dbg_log("Profile mode [%d]", hcamcorder->type);
608 /* set camera state to vconf key */
609 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
610 int vconf_camera_state = 0;
612 /* get current camera state of vconf key */
613 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
614 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_OPEN);
616 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
617 vconf_camera_state, VCONFKEY_CAMERA_STATE_OPEN);
620 mm_camcorder_get_attributes(handle, NULL,
621 MMCAM_DISPLAY_SURFACE, &display_surface_type,
622 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
625 /* alloc sub context */
626 hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
627 if(!hcamcorder->sub_context) {
628 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
629 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
632 /* Set basic configure information */
633 if (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE) {
634 hcamcorder->sub_context->is_modified_rate = TRUE;
637 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
638 CONFIGURE_CATEGORY_MAIN_CAPTURE,
640 &(hcamcorder->sub_context->bencbin_capture));
641 _mmcam_dbg_warn("UseEncodebin [%d]", hcamcorder->sub_context->bencbin_capture);
643 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
644 /* get dual stream support info */
645 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
646 CONFIGURE_CATEGORY_MAIN_RECORD,
648 &(hcamcorder->sub_context->info_video->support_dual_stream));
649 _mmcam_dbg_warn("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
652 switch (display_surface_type) {
653 case MM_DISPLAY_SURFACE_X:
654 videosink_element_type = strdup("VideosinkElementX");
656 case MM_DISPLAY_SURFACE_EVAS:
657 videosink_element_type = strdup("VideosinkElementEvas");
659 case MM_DISPLAY_SURFACE_GL:
660 videosink_element_type = strdup("VideosinkElementGL");
662 case MM_DISPLAY_SURFACE_NULL:
663 videosink_element_type = strdup("VideosinkElementNull");
666 videosink_element_type = strdup("VideosinkElementX");
670 /* check string of videosink element */
671 if (videosink_element_type) {
672 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
673 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
674 videosink_element_type,
675 &hcamcorder->sub_context->VideosinkElement);
676 free(videosink_element_type);
677 videosink_element_type = NULL;
679 _mmcam_dbg_warn("strdup failed(display_surface_type %d). Use default X type",
680 display_surface_type);
682 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
683 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
684 _MMCAMCORDER_DEFAULT_VIDEOSINK_TYPE,
685 &hcamcorder->sub_context->VideosinkElement);
688 _mmcamcorder_conf_get_value_element_name(hcamcorder->sub_context->VideosinkElement, &videosink_name);
689 _mmcam_dbg_log("Videosink name : %s", videosink_name);
691 /* get videoconvert element */
692 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
693 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
694 "VideoconvertElement",
695 &hcamcorder->sub_context->VideoconvertElement);
697 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
698 CONFIGURE_CATEGORY_CTRL_CAPTURE,
699 "SensorEncodedCapture",
700 &(hcamcorder->sub_context->SensorEncodedCapture));
701 _mmcam_dbg_log("Support sensor encoded capture : %d", hcamcorder->sub_context->SensorEncodedCapture);
703 /* create pipeline */
704 ret = _mmcamcorder_create_pipeline(handle, hcamcorder->type);
705 if (ret != MM_ERROR_NONE) {
706 /* check internal error of gstreamer */
707 if (hcamcorder->sub_context->error_code != MM_ERROR_NONE) {
708 ret = hcamcorder->sub_context->error_code;
709 _mmcam_dbg_log("gstreamer error is occurred. return it %x", ret);
712 /* release sub context */
713 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
714 hcamcorder->sub_context = NULL;
715 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
718 /* set command function */
719 ret = _mmcamcorder_set_functions(handle, hcamcorder->type);
720 if (ret != MM_ERROR_NONE) {
721 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
722 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
723 hcamcorder->sub_context = NULL;
724 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
727 _mmcamcorder_set_state(handle, state_TO);
729 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
731 return MM_ERROR_NONE;
733 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
734 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
736 _ERR_CAMCORDER_CMD_PRECON:
737 _mmcam_dbg_err("Realize fail (type %d, state %d, ret %x)",
738 hcamcorder->type, state, ret);
740 /* rollback camera state to vconf key */
741 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
742 int vconf_camera_state = 0;
744 /* get current camera state of vconf key */
745 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
746 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_NULL);
748 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
749 vconf_camera_state, VCONFKEY_CAMERA_STATE_NULL);
756 int _mmcamcorder_unrealize(MMHandleType handle)
758 int ret = MM_ERROR_NONE;
759 int state = MM_CAMCORDER_STATE_NONE;
760 int state_FROM = MM_CAMCORDER_STATE_READY;
761 int state_TO = MM_CAMCORDER_STATE_NULL;
763 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
768 _mmcam_dbg_err("Not initialized");
769 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
773 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
774 _mmcam_dbg_err("Another command is running.");
775 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
776 goto _ERR_CAMCORDER_CMD_PRECON;
779 state = _mmcamcorder_get_state(handle);
780 if (state != state_FROM) {
781 _mmcam_dbg_err("Wrong state(%d)", state);
782 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
783 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
786 /* Release SubContext */
787 if (hcamcorder->sub_context) {
788 /* destroy pipeline */
789 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
790 /* Deallocate SubContext */
791 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
792 hcamcorder->sub_context = NULL;
795 /* Deinitialize main context member */
797 hcamcorder->command = NULL;
799 /* check who calls unrealize. it's no need to set ASM state if caller is ASM */
800 if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_ASM) {
804 /* set camera state to vconf key */
805 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
806 int vconf_camera_state = 0;
808 /* get current camera state of vconf key */
809 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
810 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_NULL);
812 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
813 vconf_camera_state, VCONFKEY_CAMERA_STATE_NULL);
816 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
818 _mmcamcorder_set_state(handle, state_TO);
820 return MM_ERROR_NONE;
822 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
823 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
825 _ERR_CAMCORDER_CMD_PRECON:
827 _mmcam_dbg_err("Unrealize fail (type %d, state %d, ret %x)",
828 hcamcorder->type, state, ret);
833 int _mmcamcorder_start(MMHandleType handle)
835 int ret = MM_ERROR_NONE;
836 int state = MM_CAMCORDER_STATE_NONE;
837 int state_FROM = MM_CAMCORDER_STATE_READY;
838 int state_TO =MM_CAMCORDER_STATE_PREPARE;
840 _MMCamcorderSubContext *sc = NULL;
841 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
846 _mmcam_dbg_err("Not initialized");
847 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
851 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
852 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
854 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
855 _mmcam_dbg_err("Another command is running.");
856 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
857 goto _ERR_CAMCORDER_CMD_PRECON;
860 state = _mmcamcorder_get_state(handle);
861 if (state != state_FROM) {
862 _mmcam_dbg_err("Wrong state(%d)", state);
863 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
864 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
867 /* initialize error code */
868 hcamcorder->sub_context->error_code = MM_ERROR_NONE;
870 /* set attributes related sensor */
871 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
872 _mmcamcorder_set_attribute_to_camsensor(handle);
875 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
876 if (ret != MM_ERROR_NONE) {
877 /* check internal error of gstreamer */
878 if (hcamcorder->sub_context->error_code != MM_ERROR_NONE) {
879 ret = hcamcorder->sub_context->error_code;
880 _mmcam_dbg_log("gstreamer error is occurred. return it %x", ret);
882 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
885 _mmcamcorder_set_state(handle, state_TO);
887 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
888 int vconf_camera_state = 0;
890 /* check camera state of vconf key */
891 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
893 /* set camera state to vconf key */
894 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_PREVIEW);
896 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
897 vconf_camera_state, VCONFKEY_CAMERA_STATE_PREVIEW);
900 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
902 return MM_ERROR_NONE;
904 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
905 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
907 _ERR_CAMCORDER_CMD_PRECON:
908 /* check internal error of gstreamer */
909 if (hcamcorder->sub_context &&
910 hcamcorder->sub_context->error_code != MM_ERROR_NONE) {
911 ret = hcamcorder->sub_context->error_code;
912 hcamcorder->sub_context->error_code = MM_ERROR_NONE;
914 _mmcam_dbg_log("gstreamer error is occurred. return it %x", ret);
917 _mmcam_dbg_err("Start fail (type %d, state %d, ret %x)",
918 hcamcorder->type, state, ret);
923 int _mmcamcorder_stop(MMHandleType handle)
925 int ret = MM_ERROR_NONE;
926 int state = MM_CAMCORDER_STATE_NONE;
927 int state_FROM = MM_CAMCORDER_STATE_PREPARE;
928 int state_TO = MM_CAMCORDER_STATE_READY;
930 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
935 _mmcam_dbg_err("Not initialized");
936 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
940 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
941 _mmcam_dbg_err("Another command is running.");
942 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
943 goto _ERR_CAMCORDER_CMD_PRECON;
946 state = _mmcamcorder_get_state(handle);
947 if (state != state_FROM) {
948 _mmcam_dbg_err("Wrong state(%d)", state);
949 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
950 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
953 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_STOP);
954 if (ret != MM_ERROR_NONE) {
955 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
958 _mmcamcorder_set_state(handle, state_TO);
960 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
961 int vconf_camera_state = 0;
963 /* check camera state of vconf key */
964 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
966 /* set camera state to vconf key */
967 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_OPEN);
969 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
970 vconf_camera_state, VCONFKEY_CAMERA_STATE_OPEN);
973 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
975 return MM_ERROR_NONE;
977 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
978 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
980 _ERR_CAMCORDER_CMD_PRECON:
982 _mmcam_dbg_err("Stop fail (type %d, state %d, ret %x)",
983 hcamcorder->type, state, ret);
989 int _mmcamcorder_capture_start(MMHandleType handle)
991 int ret = MM_ERROR_NONE;
992 int state = MM_CAMCORDER_STATE_NONE;
993 int state_FROM_0 = MM_CAMCORDER_STATE_PREPARE;
994 int state_FROM_1 = MM_CAMCORDER_STATE_RECORDING;
995 int state_FROM_2 = MM_CAMCORDER_STATE_PAUSED;
996 int state_TO = MM_CAMCORDER_STATE_CAPTURING;
998 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1003 _mmcam_dbg_err("Not initialized");
1004 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1008 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1009 _mmcam_dbg_err("Another command is running.");
1010 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1011 goto _ERR_CAMCORDER_CMD_PRECON;
1014 state = _mmcamcorder_get_state(handle);
1015 if (state != state_FROM_0 &&
1016 state != state_FROM_1 &&
1017 state != state_FROM_2) {
1018 _mmcam_dbg_err("Wrong state(%d)", state);
1019 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1020 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1023 /* Handle capture in recording case */
1024 if (state == state_FROM_1 || state == state_FROM_2) {
1025 if (hcamcorder->capture_in_recording == TRUE) {
1026 _mmcam_dbg_err("Capturing in recording (%d)", state);
1027 ret = MM_ERROR_CAMCORDER_DEVICE_BUSY;
1028 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1030 hcamcorder->capture_in_recording = TRUE;
1034 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CAPTURE);
1035 if (ret != MM_ERROR_NONE) {
1036 goto _ERR_CAMCORDER_CMD;
1039 /* Do not change state when recording snapshot capture */
1040 if (state == state_FROM_0) {
1041 _mmcamcorder_set_state(handle, state_TO);
1044 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1046 /* Init break continuous shot attr */
1047 if (mm_camcorder_set_attributes(handle, NULL, "capture-break-cont-shot", 0, NULL) != MM_ERROR_NONE) {
1048 _mmcam_dbg_warn("capture-break-cont-shot set 0 failed");
1051 return MM_ERROR_NONE;
1054 if (hcamcorder->capture_in_recording) {
1055 hcamcorder->capture_in_recording = FALSE;
1058 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1059 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1061 _ERR_CAMCORDER_CMD_PRECON:
1063 _mmcam_dbg_err("Capture start fail (type %d, state %d, ret %x)",
1064 hcamcorder->type, state, ret);
1069 int _mmcamcorder_capture_stop(MMHandleType handle)
1071 int ret = MM_ERROR_NONE;
1072 int state = MM_CAMCORDER_STATE_NONE;
1073 int state_FROM = MM_CAMCORDER_STATE_CAPTURING;
1074 int state_TO = MM_CAMCORDER_STATE_PREPARE;
1075 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1080 _mmcam_dbg_err("Not initialized");
1081 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1085 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1086 _mmcam_dbg_err("Another command is running.");
1087 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1088 goto _ERR_CAMCORDER_CMD_PRECON;
1091 state = _mmcamcorder_get_state(handle);
1092 if (state != state_FROM) {
1093 _mmcam_dbg_err("Wrong state(%d)", state);
1094 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1095 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1098 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1099 if (ret != MM_ERROR_NONE) {
1100 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1103 _mmcamcorder_set_state(handle, state_TO);
1105 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1107 return MM_ERROR_NONE;
1109 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1110 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1112 _ERR_CAMCORDER_CMD_PRECON:
1114 _mmcam_dbg_err("Capture stop fail (type %d, state %d, ret %x)",
1115 hcamcorder->type, state, ret);
1120 int _mmcamcorder_record(MMHandleType handle)
1122 int ret = MM_ERROR_NONE;
1123 int state = MM_CAMCORDER_STATE_NONE;
1124 int state_FROM1 = MM_CAMCORDER_STATE_PREPARE;
1125 int state_FROM2 = MM_CAMCORDER_STATE_PAUSED;
1126 int state_TO = MM_CAMCORDER_STATE_RECORDING;
1128 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1133 _mmcam_dbg_err("Not initialized");
1134 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1138 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1139 _mmcam_dbg_err("Another command is running.");
1140 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1141 goto _ERR_CAMCORDER_CMD_PRECON;
1144 state = _mmcamcorder_get_state(handle);
1145 if (state != state_FROM1 && state != state_FROM2) {
1146 _mmcam_dbg_err("Wrong state(%d)", state);
1147 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1148 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1151 /* initialize error code */
1152 hcamcorder->sub_context->error_code = MM_ERROR_NONE;
1154 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_RECORD);
1155 if (ret != MM_ERROR_NONE) {
1156 /* check internal error of gstreamer */
1157 if (hcamcorder->sub_context->error_code != MM_ERROR_NONE) {
1158 ret = hcamcorder->sub_context->error_code;
1159 _mmcam_dbg_log("gstreamer error is occurred. return it %x", ret);
1161 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1164 _mmcamcorder_set_state(handle, state_TO);
1166 /* set camera state to vconf key */
1167 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1168 int vconf_camera_state = 0;
1170 /* get current camera state of vconf key */
1171 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
1172 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_RECORDING);
1174 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
1175 vconf_camera_state, VCONFKEY_CAMERA_STATE_RECORDING);
1178 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1180 return MM_ERROR_NONE;
1182 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1183 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1185 _ERR_CAMCORDER_CMD_PRECON:
1186 /* check internal error of gstreamer */
1187 if (hcamcorder->sub_context &&
1188 hcamcorder->sub_context->error_code != MM_ERROR_NONE) {
1189 ret = hcamcorder->sub_context->error_code;
1190 hcamcorder->sub_context->error_code = MM_ERROR_NONE;
1192 _mmcam_dbg_log("gstreamer error is occurred. return it %x", ret);
1195 _mmcam_dbg_err("Record fail (type %d, state %d, ret %x)",
1196 hcamcorder->type, state, ret);
1202 int _mmcamcorder_pause(MMHandleType handle)
1204 int ret = MM_ERROR_NONE;
1205 int state = MM_CAMCORDER_STATE_NONE;
1206 int state_FROM = MM_CAMCORDER_STATE_RECORDING;
1207 int state_TO = MM_CAMCORDER_STATE_PAUSED;
1209 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1214 _mmcam_dbg_err("Not initialized");
1215 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1219 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1220 _mmcam_dbg_err("Another command is running.");
1221 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1222 goto _ERR_CAMCORDER_CMD_PRECON;
1225 state = _mmcamcorder_get_state(handle);
1226 if (state != state_FROM) {
1227 _mmcam_dbg_err("Wrong state(%d)", state);
1228 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1229 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1232 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PAUSE);
1233 if (ret != MM_ERROR_NONE) {
1234 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1237 _mmcamcorder_set_state(handle, state_TO);
1239 /* set camera state to vconf key */
1240 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1241 int vconf_camera_state = 0;
1243 /* get current camera state of vconf key */
1244 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
1245 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_RECORDING_PAUSE);
1247 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
1248 vconf_camera_state, VCONFKEY_CAMERA_STATE_RECORDING_PAUSE);
1251 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1253 return MM_ERROR_NONE;
1255 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1256 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1258 _ERR_CAMCORDER_CMD_PRECON:
1260 _mmcam_dbg_err("Pause fail (type %d, state %d, ret %x)",
1261 hcamcorder->type, state, ret);
1267 int _mmcamcorder_commit(MMHandleType handle)
1269 int ret = MM_ERROR_NONE;
1270 int state = MM_CAMCORDER_STATE_NONE;
1271 int state_FROM1 = MM_CAMCORDER_STATE_RECORDING;
1272 int state_FROM2 = MM_CAMCORDER_STATE_PAUSED;
1273 int state_TO = MM_CAMCORDER_STATE_PREPARE;
1275 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1280 _mmcam_dbg_err("Not initialized");
1281 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1285 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1286 _mmcam_dbg_err("Another command is running.");
1287 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1288 goto _ERR_CAMCORDER_CMD_PRECON;
1291 state = _mmcamcorder_get_state(handle);
1292 if (state != state_FROM1 && state != state_FROM2) {
1293 _mmcam_dbg_err("Wrong state(%d)", state);
1294 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1295 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1298 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_COMMIT);
1299 if (ret != MM_ERROR_NONE) {
1300 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1303 /* set camera state to vconf key */
1304 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1305 int vconf_camera_state = 0;
1307 /* get current camera state of vconf key */
1308 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
1309 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_PREVIEW);
1311 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
1312 vconf_camera_state, VCONFKEY_CAMERA_STATE_PREVIEW);
1315 /* check who calls unrealize. it's no need to set ASM state if caller is ASM */
1316 if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_ASM) {
1320 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1322 _mmcamcorder_set_state(handle,state_TO);
1324 return MM_ERROR_NONE;
1326 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1327 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1329 _ERR_CAMCORDER_CMD_PRECON:
1331 _mmcam_dbg_err("Commit fail (type %d, state %d, ret %x)",
1332 hcamcorder->type, state, ret);
1338 int _mmcamcorder_cancel(MMHandleType handle)
1340 int ret = MM_ERROR_NONE;
1341 int state = MM_CAMCORDER_STATE_NONE;
1342 int state_FROM1 = MM_CAMCORDER_STATE_RECORDING;
1343 int state_FROM2 = MM_CAMCORDER_STATE_PAUSED;
1344 int state_TO = MM_CAMCORDER_STATE_PREPARE;
1346 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1351 _mmcam_dbg_err("Not initialized");
1352 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1356 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1357 _mmcam_dbg_err("Another command is running.");
1358 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1359 goto _ERR_CAMCORDER_CMD_PRECON;
1362 state = _mmcamcorder_get_state(handle);
1363 if (state != state_FROM1 && state != state_FROM2) {
1364 _mmcam_dbg_err("Wrong state(%d)", state);
1365 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1366 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1369 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CANCEL);
1370 if (ret != MM_ERROR_NONE) {
1371 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1374 _mmcamcorder_set_state(handle, state_TO);
1376 /* set camera state to vconf key */
1377 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1378 int vconf_camera_state = 0;
1380 /* get current camera state of vconf key */
1381 vconf_get_int(VCONFKEY_CAMERA_STATE, &vconf_camera_state);
1382 vconf_set_int(VCONFKEY_CAMERA_STATE, VCONFKEY_CAMERA_STATE_PREVIEW);
1384 _mmcam_dbg_log("VCONFKEY_CAMERA_STATE prev %d -> cur %d",
1385 vconf_camera_state, VCONFKEY_CAMERA_STATE_PREVIEW);
1388 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1390 return MM_ERROR_NONE;
1392 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1393 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1395 _ERR_CAMCORDER_CMD_PRECON:
1397 _mmcam_dbg_err("Cancel fail (type %d, state %d, ret %x)",
1398 hcamcorder->type, state, ret);
1402 /* } Internal command functions */
1405 int _mmcamcorder_commit_async_end(MMHandleType handle)
1409 _mmcam_dbg_warn("_mmcamcorder_commit_async_end : MM_CAMCORDER_STATE_PREPARE");
1410 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1412 return MM_ERROR_NONE;
1416 int _mmcamcorder_set_message_callback(MMHandleType handle, MMMessageCallback callback, void *user_data)
1418 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1420 _mmcam_dbg_log("%p", hcamcorder);
1422 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1424 if (callback == NULL) {
1425 _mmcam_dbg_warn("Message Callback is disabled, because application sets it to NULL");
1428 if (!_MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(hcamcorder)) {
1429 _mmcam_dbg_warn("Application's message callback is running now");
1430 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1433 /* set message callback to message handle */
1434 hcamcorder->msg_cb = callback;
1435 hcamcorder->msg_cb_param = user_data;
1437 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1439 return MM_ERROR_NONE;
1443 int _mmcamcorder_set_video_stream_callback(MMHandleType handle, mm_camcorder_video_stream_callback callback, void *user_data)
1445 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1449 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1451 if (callback == NULL) {
1452 _mmcam_dbg_warn("Video Stream Callback is disabled, because application sets it to NULL");
1455 if (!_MMCAMCORDER_TRYLOCK_VSTREAM_CALLBACK(hcamcorder)) {
1456 _mmcam_dbg_warn("Application's video stream callback is running now");
1457 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1460 hcamcorder->vstream_cb = callback;
1461 hcamcorder->vstream_cb_param = user_data;
1463 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1465 return MM_ERROR_NONE;
1469 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle, mm_camcorder_audio_stream_callback callback, void *user_data)
1471 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1475 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1477 if (callback == NULL) {
1478 _mmcam_dbg_warn("Audio Stream Callback is disabled, because application sets it to NULL");
1481 if (!_MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(hcamcorder)) {
1482 _mmcam_dbg_warn("Application's audio stream callback is running now");
1483 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1486 hcamcorder->astream_cb = callback;
1487 hcamcorder->astream_cb_param = user_data;
1489 _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder);
1491 return MM_ERROR_NONE;
1495 int _mmcamcorder_set_video_capture_callback(MMHandleType handle, mm_camcorder_video_capture_callback callback, void *user_data)
1497 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1501 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1503 if (callback == NULL) {
1504 _mmcam_dbg_warn("Video Capture Callback is disabled, because application sets it to NULLL");
1507 if (!_MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(hcamcorder)) {
1508 _mmcam_dbg_warn("Application's video capture callback is running now");
1509 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1512 hcamcorder->vcapture_cb = callback;
1513 hcamcorder->vcapture_cb_param = user_data;
1515 _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(hcamcorder);
1517 return MM_ERROR_NONE;
1520 int _mmcamcorder_get_current_state(MMHandleType handle)
1522 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1526 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1528 return _mmcamcorder_get_state(handle);
1531 int _mmcamcorder_init_focusing(MMHandleType handle)
1534 int state = MM_CAMCORDER_STATE_NONE;
1535 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
1536 int af_range = MM_CAMCORDER_AUTO_FOCUS_NORMAL;
1537 int sensor_focus_mode = 0;
1538 int sensor_af_range = 0;
1539 int current_focus_mode = 0;
1540 int current_af_range = 0;
1541 mmf_camcorder_t *hcamcorder = NULL;
1542 _MMCamcorderSubContext *sc = NULL;
1543 GstCameraControl *control = NULL;
1547 hcamcorder = MMF_CAMCORDER(handle);
1548 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1550 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
1551 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1553 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1554 _mmcam_dbg_err("Another command is running.");
1555 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1558 state = _mmcamcorder_get_state(handle);
1560 if (state == MM_CAMCORDER_STATE_CAPTURING ||
1561 state < MM_CAMCORDER_STATE_PREPARE) {
1562 _mmcam_dbg_err( "Not proper state. state[%d]", state );
1563 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1564 return MM_ERROR_CAMCORDER_INVALID_STATE;
1567 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
1568 _mmcam_dbg_log("Can't cast Video source into camera control.");
1569 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1570 return MM_ERROR_NONE;
1572 control = GST_CAMERA_CONTROL (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1574 ret = gst_camera_control_stop_auto_focus(control);
1576 _mmcam_dbg_err("Auto focusing stop fail.");
1577 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1578 return MM_ERROR_CAMCORDER_DEVICE_IO;
1581 /* Initialize lens position */
1582 mm_camcorder_get_attributes(handle, NULL,
1583 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
1584 MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
1586 sensor_af_range = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_AF_SCAN_RANGE, af_range);
1587 sensor_focus_mode = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_FOCUS_MODE, focus_mode);
1589 gst_camera_control_get_focus(control, ¤t_focus_mode, ¤t_af_range);
1591 if (current_focus_mode != sensor_focus_mode ||
1592 current_af_range != sensor_af_range) {
1593 ret = gst_camera_control_set_focus(control, sensor_focus_mode, sensor_af_range);
1595 _mmcam_dbg_log("No need to init FOCUS [mode:%d, range:%d]", focus_mode, af_range );
1599 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1602 _mmcam_dbg_log("Lens init success.");
1603 return MM_ERROR_NONE;
1605 _mmcam_dbg_err("Lens init fail.");
1606 return MM_ERROR_CAMCORDER_DEVICE_IO;
1610 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction)
1613 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
1614 int ret = MM_ERROR_UNKNOWN;
1615 char *err_attr_name = NULL;
1617 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1618 mmf_return_val_if_fail(direction, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
1622 if (!_MMCAMCORDER_TRYLOCK_CMD(handle)) {
1623 _mmcam_dbg_err("Another command is running.");
1624 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1627 state = _mmcamcorder_get_state(handle);
1628 if (state == MM_CAMCORDER_STATE_CAPTURING ||
1629 state < MM_CAMCORDER_STATE_PREPARE) {
1630 _mmcam_dbg_err("Not proper state. state[%d]", state);
1631 _MMCAMCORDER_UNLOCK_CMD(handle);
1632 return MM_ERROR_CAMCORDER_INVALID_STATE;
1635 /* TODO : call a auto or manual focus function */
1636 ret = mm_camcorder_get_attributes(handle, &err_attr_name,
1637 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
1639 if (ret != MM_ERROR_NONE) {
1640 _mmcam_dbg_warn("Get focus-mode fail. (%s:%x)", err_attr_name, ret);
1641 SAFE_FREE (err_attr_name);
1642 _MMCAMCORDER_UNLOCK_CMD(handle);
1646 if (focus_mode == MM_CAMCORDER_FOCUS_MODE_MANUAL) {
1647 ret = _mmcamcorder_adjust_manual_focus(handle, direction);
1648 } else if (focus_mode == MM_CAMCORDER_FOCUS_MODE_AUTO ||
1649 focus_mode == MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO ||
1650 focus_mode == MM_CAMCORDER_FOCUS_MODE_CONTINUOUS) {
1651 ret = _mmcamcorder_adjust_auto_focus(handle);
1653 _mmcam_dbg_err("It doesn't adjust focus. Focusing mode(%d)", focus_mode);
1654 ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
1657 _MMCAMCORDER_UNLOCK_CMD(handle);
1662 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction)
1667 int focus_level = 0;
1668 float unit_level = 0;
1669 GstCameraControl *control = NULL;
1670 _MMCamcorderSubContext *sc = NULL;
1671 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1675 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1676 mmf_return_val_if_fail(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL != 1, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
1677 mmf_return_val_if_fail((direction >= MM_CAMCORDER_MF_LENS_DIR_FORWARD) &&
1678 (direction <= MM_CAMCORDER_MF_LENS_DIR_BACKWARD),
1679 MM_ERROR_CAMCORDER_INVALID_ARGUMENT );
1681 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
1682 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1684 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
1685 _mmcam_dbg_log("Can't cast Video source into camera control.");
1686 return MM_ERROR_NONE;
1688 control = GST_CAMERA_CONTROL (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1690 /* TODO : get max, min level */
1691 if (max_level - min_level + 1 < _MMFCAMCORDER_FOCUS_TOTAL_LEVEL) {
1692 _mmcam_dbg_warn("Total level of manual focus of MMF is greater than that of the camera driver.");
1695 unit_level = ((float)max_level - (float)min_level)/(float)(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL - 1);
1697 if (!gst_camera_control_get_focus_level(control, &cur_level)) {
1698 _mmcam_dbg_err("Can't get current level of manual focus.");
1699 return MM_ERROR_CAMCORDER_DEVICE_IO;
1702 //TODO : adjust unit level value
1703 if (direction == MM_CAMCORDER_MF_LENS_DIR_FORWARD) {
1704 focus_level = cur_level + unit_level;
1705 } else if (direction == MM_CAMCORDER_MF_LENS_DIR_BACKWARD) {
1706 focus_level = cur_level - unit_level;
1709 if (focus_level > max_level) {
1710 focus_level = max_level;
1711 } else if (focus_level < min_level) {
1712 focus_level = min_level;
1715 if (!gst_camera_control_set_focus_level(control, focus_level)) {
1716 _mmcam_dbg_err("Manual focusing fail.");
1717 return MM_ERROR_CAMCORDER_DEVICE_IO;
1720 return MM_ERROR_NONE;
1724 int _mmcamcorder_adjust_auto_focus(MMHandleType handle)
1727 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1728 GstCameraControl *control = NULL;
1729 _MMCamcorderSubContext *sc = NULL;
1731 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1735 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
1737 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
1738 _mmcam_dbg_log("Can't cast Video source into camera control.");
1739 return MM_ERROR_NONE;
1741 control = GST_CAMERA_CONTROL (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1744 ret = gst_camera_control_start_auto_focus(control);
1746 _mmcam_dbg_log("Auto focusing start success.");
1747 return MM_ERROR_NONE;
1749 _mmcam_dbg_err("Auto focusing start fail.");
1750 return MM_ERROR_CAMCORDER_DEVICE_IO;
1754 int _mmcamcorder_stop_focusing(MMHandleType handle)
1756 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1757 _MMCamcorderSubContext *sc = NULL;
1760 GstCameraControl *control = NULL;
1762 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1766 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
1768 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1769 _mmcam_dbg_err("Another command is running.");
1770 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1773 state = _mmcamcorder_get_state(handle);
1774 if (state == MM_CAMCORDER_STATE_CAPTURING ||
1775 state < MM_CAMCORDER_STATE_PREPARE) {
1776 _mmcam_dbg_err( "Not proper state. state[%d]", state );
1777 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1778 return MM_ERROR_CAMCORDER_INVALID_STATE;
1781 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
1782 _mmcam_dbg_log("Can't cast Video source into camera control.");
1783 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1784 return MM_ERROR_NONE;
1786 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
1788 ret = gst_camera_control_stop_auto_focus(control);
1790 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1793 _mmcam_dbg_log("Auto focusing stop success.");
1794 return MM_ERROR_NONE;
1796 _mmcam_dbg_err("Auto focusing stop fail.");
1797 return MM_ERROR_CAMCORDER_DEVICE_IO;
1802 /*-----------------------------------------------
1803 | CAMCORDER INTERNAL LOCAL |
1804 -----------------------------------------------*/
1806 __mmcamcorder_gstreamer_init(camera_conf * conf)
1808 static const int max_argc = 10;
1812 gchar **argv = NULL;
1814 gboolean ret = FALSE;
1815 type_string_array *GSTInitOption = NULL;
1817 mmf_return_val_if_fail(conf, FALSE);
1822 argc = malloc(sizeof(int));
1823 argv = malloc(sizeof(gchar *) * max_argc);
1825 if (!argc || !argv) {
1829 memset(argv, 0, sizeof(gchar *) * max_argc);
1833 argv[0] = g_strdup("mmcamcorder");
1836 _mmcamcorder_conf_get_value_string_array(conf,
1837 CONFIGURE_CATEGORY_MAIN_GENERAL,
1840 if (GSTInitOption != NULL && GSTInitOption->value) {
1841 cnt_str = GSTInitOption->count;
1842 for( ; *argc < max_argc && *argc <= cnt_str ; (*argc)++ )
1844 argv[*argc] = g_strdup(GSTInitOption->value[(*argc)-1]);
1848 _mmcam_dbg_log("initializing gstreamer with following parameter[argc:%d]", *argc);
1850 for (i = 0; i < *argc; i++) {
1851 _mmcam_dbg_log("argv[%d] : %s", i, argv[i]);
1854 /* initializing gstreamer */
1855 ret = gst_init_check (argc, &argv, &err);
1857 _mmcam_dbg_err("Could not initialize GStreamer: %s ",
1858 err ? err->message : "unknown error occurred");
1865 for (i = 0; i < *argc; i++) {
1885 _mmcam_dbg_err("failed to initialize gstreamer");
1901 int _mmcamcorder_get_state(MMHandleType handle)
1904 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1906 mmf_return_val_if_fail(hcamcorder, -1);
1908 _MMCAMCORDER_LOCK_STATE(handle);
1910 state = hcamcorder->state;
1911 _mmcam_dbg_log("state=%d",state);
1913 _MMCAMCORDER_UNLOCK_STATE(handle);
1919 void _mmcamcorder_set_state(MMHandleType handle, int state)
1922 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1923 _MMCamcorderMsgItem msg;
1925 mmf_return_if_fail(hcamcorder);
1929 _MMCAMCORDER_LOCK_STATE(handle);
1931 old_state = hcamcorder->state;
1932 if(old_state != state) {
1933 hcamcorder->state = state;
1934 hcamcorder->target_state = state;
1936 _mmcam_dbg_log("set state[%d] and send state-changed message", state);
1938 /* To discern who changes the state */
1939 switch (hcamcorder->state_change_by_system) {
1940 case _MMCAMCORDER_STATE_CHANGE_BY_ASM:
1941 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_ASM;
1943 case _MMCAMCORDER_STATE_CHANGE_NORMAL:
1945 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED;
1946 msg.param.state.code = MM_ERROR_NONE;
1950 msg.param.state.previous = old_state;
1951 msg.param.state.current = state;
1953 _mmcam_dbg_log("_mmcamcroder_send_message : msg : %p, id:%x", &msg, msg.id);
1954 _mmcamcroder_send_message(handle, &msg);
1957 _MMCAMCORDER_UNLOCK_STATE(handle);
1963 int _mmcamcorder_get_async_state(MMHandleType handle)
1966 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1968 _MMCAMCORDER_LOCK_STATE(handle);
1969 state = hcamcorder->target_state;
1971 _MMCAMCORDER_UNLOCK_STATE(handle);
1977 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
1980 _MMCamcorderSubContext *sc = NULL;
1984 /* alloc container */
1985 sc = (_MMCamcorderSubContext *)malloc(sizeof(_MMCamcorderSubContext));
1986 mmf_return_val_if_fail(sc != NULL, NULL);
1989 memset(sc, 0x00, sizeof(_MMCamcorderSubContext));
1991 sc->element_num = _MMCAMCORDER_PIPELINE_ELEMENT_NUM;
1992 sc->encode_element_num = _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM;
1994 /* alloc info for each mode */
1996 case MM_CAMCORDER_MODE_AUDIO:
1997 sc->info_audio = malloc( sizeof(_MMCamcorderAudioInfo));
1998 if(!sc->info_audio) {
1999 _mmcam_dbg_err("Failed to alloc info structure");
2000 goto ALLOC_SUBCONTEXT_FAILED;
2002 memset(sc->info_audio, 0x00, sizeof(_MMCamcorderAudioInfo));
2004 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2006 sc->info_image = malloc( sizeof(_MMCamcorderImageInfo));
2007 if(!sc->info_image) {
2008 _mmcam_dbg_err("Failed to alloc info structure");
2009 goto ALLOC_SUBCONTEXT_FAILED;
2011 memset(sc->info_image, 0x00, sizeof(_MMCamcorderImageInfo));
2013 /* init sound status */
2014 sc->info_image->sound_status = _SOUND_STATUS_INIT;
2016 sc->info_video = malloc( sizeof(_MMCamcorderVideoInfo));
2017 if(!sc->info_video) {
2018 _mmcam_dbg_err("Failed to alloc info structure");
2019 goto ALLOC_SUBCONTEXT_FAILED;
2021 memset(sc->info_video, 0x00, sizeof(_MMCamcorderVideoInfo));
2022 pthread_mutex_init(&(sc->info_video->size_check_lock), NULL);
2026 /* alloc element array */
2027 sc->element = (_MMCamcorderGstElement *)malloc(sizeof(_MMCamcorderGstElement) * sc->element_num);
2029 _mmcam_dbg_err("Failed to alloc element structure");
2030 goto ALLOC_SUBCONTEXT_FAILED;
2033 sc->encode_element = (_MMCamcorderGstElement *)malloc(sizeof(_MMCamcorderGstElement) * sc->encode_element_num);
2034 if(!sc->encode_element) {
2035 _mmcam_dbg_err("Failed to alloc encode element structure");
2036 goto ALLOC_SUBCONTEXT_FAILED;
2039 for (i = 0 ; i < sc->element_num ; i++) {
2040 sc->element[i].id = _MMCAMCORDER_NONE;
2041 sc->element[i].gst = NULL;
2044 for (i = 0 ; i < sc->encode_element_num ; i++) {
2045 sc->encode_element[i].id = _MMCAMCORDER_NONE;
2046 sc->encode_element[i].gst = NULL;
2049 sc->cam_stability_count = 0;
2050 sc->drop_vframe = 0;
2051 sc->pass_first_vframe = 0;
2052 sc->is_modified_rate = FALSE;
2056 ALLOC_SUBCONTEXT_FAILED:
2058 if (sc->info_audio) {
2059 free(sc->info_audio);
2060 sc->info_audio = NULL;
2062 if (sc->info_image) {
2063 free(sc->info_image);
2064 sc->info_image = NULL;
2066 if (sc->info_video) {
2067 pthread_mutex_destroy(&(sc->info_video->size_check_lock));
2068 free(sc->info_video);
2069 sc->info_video = NULL;
2075 if (sc->encode_element) {
2076 free(sc->encode_element);
2077 sc->encode_element = NULL;
2087 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
2093 _mmcam_dbg_log("release element");
2098 if (sc->encode_element) {
2099 _mmcam_dbg_log("release encode_element");
2100 free(sc->encode_element);
2101 sc->encode_element = NULL;
2104 if (sc->info_image) {
2105 _mmcam_dbg_log("release info_image");
2106 free(sc->info_image);
2107 sc->info_image = NULL;
2110 if (sc->info_video) {
2111 _mmcam_dbg_log("release info_video");
2112 if (sc->info_video->filename) {
2113 free(sc->info_video->filename);
2114 sc->info_video->filename = NULL;
2116 pthread_mutex_destroy(&(sc->info_video->size_check_lock));
2117 free(sc->info_video);
2118 sc->info_video = NULL;
2121 if (sc->info_audio) {
2122 _mmcam_dbg_log("release info_audio");
2123 if (sc->info_audio->filename) {
2124 free(sc->info_audio->filename);
2125 sc->info_audio->filename = NULL;
2127 free(sc->info_audio);
2128 sc->info_audio = NULL;
2139 int _mmcamcorder_set_functions(MMHandleType handle, int type)
2141 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2146 case MM_CAMCORDER_MODE_AUDIO:
2147 hcamcorder->command = _mmcamcorder_audio_command;
2149 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2151 hcamcorder->command = _mmcamcorder_video_capture_command;
2155 return MM_ERROR_NONE;
2159 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data)
2161 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2162 _MMCamcorderSubContext *sc = NULL;
2164 mmf_return_val_if_fail(hcamcorder, FALSE);
2165 mmf_return_val_if_fail(message, FALSE);
2166 //_mmcam_dbg_log("message type=(%d)", GST_MESSAGE_TYPE(message));
2168 switch (GST_MESSAGE_TYPE(message)) {
2169 case GST_MESSAGE_UNKNOWN:
2170 _mmcam_dbg_log("GST_MESSAGE_UNKNOWN");
2172 case GST_MESSAGE_EOS:
2174 _mmcam_dbg_log ("Got EOS from element \"%s\".",
2175 GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));
2177 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2178 mmf_return_val_if_fail(sc, TRUE);
2180 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2181 mmf_return_val_if_fail(sc->info_video, TRUE);
2182 if (sc->info_video->b_commiting) {
2183 _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
2186 mmf_return_val_if_fail(sc->info_audio, TRUE);
2187 if (sc->info_audio->b_commiting) {
2188 _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
2192 sc->bget_eos = TRUE;
2196 case GST_MESSAGE_ERROR:
2200 gst_message_parse_error(message, &err, &debug);
2202 _mmcam_dbg_err ("GSTERR: %s", err->message);
2203 _mmcam_dbg_err ("Error Debug: %s", debug);
2205 __mmcamcorder_handle_gst_error((MMHandleType)hcamcorder, message, err);
2211 case GST_MESSAGE_WARNING:
2215 gst_message_parse_warning (message, &err, &debug);
2217 _mmcam_dbg_warn("GSTWARN: %s", err->message);
2219 __mmcamcorder_handle_gst_warning((MMHandleType)hcamcorder, message, err);
2225 case GST_MESSAGE_INFO:
2226 _mmcam_dbg_log("GST_MESSAGE_INFO");
2228 case GST_MESSAGE_TAG:
2229 _mmcam_dbg_log("GST_MESSAGE_TAG");
2231 case GST_MESSAGE_BUFFERING:
2232 _mmcam_dbg_log("GST_MESSAGE_BUFFERING");
2234 case GST_MESSAGE_STATE_CHANGED:
2236 const GValue *vnewstate;
2238 GstElement *pipeline = NULL;
2240 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2241 if ((sc) && (sc->element)) {
2242 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst) {
2243 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
2244 if (message->src == (GstObject*)pipeline) {
2245 vnewstate = (GValue*)gst_structure_get_value(gst_message_get_structure(message), "new-state");
2246 newstate = (GstState)vnewstate->data[0].v_int;
2247 _mmcam_dbg_log("GST_MESSAGE_STATE_CHANGED[%s]",gst_element_state_get_name(newstate));
2253 case GST_MESSAGE_STATE_DIRTY:
2254 _mmcam_dbg_log("GST_MESSAGE_STATE_DIRTY");
2256 case GST_MESSAGE_STEP_DONE:
2257 _mmcam_dbg_log("GST_MESSAGE_STEP_DONE");
2259 case GST_MESSAGE_CLOCK_PROVIDE:
2260 _mmcam_dbg_log("GST_MESSAGE_CLOCK_PROVIDE");
2262 case GST_MESSAGE_CLOCK_LOST:
2263 _mmcam_dbg_log("GST_MESSAGE_CLOCK_LOST");
2265 case GST_MESSAGE_NEW_CLOCK:
2267 GstClock *pipe_clock = NULL;
2268 gst_message_parse_new_clock(message, &pipe_clock);
2269 _mmcam_dbg_log("GST_MESSAGE_NEW_CLOCK : %s", (pipe_clock ? GST_OBJECT_NAME (pipe_clock) : "NULL"));
2272 case GST_MESSAGE_STRUCTURE_CHANGE:
2273 _mmcam_dbg_log("GST_MESSAGE_STRUCTURE_CHANGE");
2275 case GST_MESSAGE_STREAM_STATUS:
2276 _mmcam_dbg_log("GST_MESSAGE_STREAM_STATUS");
2278 case GST_MESSAGE_APPLICATION:
2279 _mmcam_dbg_log("GST_MESSAGE_APPLICATION");
2281 case GST_MESSAGE_ELEMENT:
2282 _mmcam_dbg_log("GST_MESSAGE_ELEMENT");
2284 case GST_MESSAGE_SEGMENT_START:
2285 _mmcam_dbg_log("GST_MESSAGE_SEGMENT_START");
2287 case GST_MESSAGE_SEGMENT_DONE:
2288 _mmcam_dbg_log("GST_MESSAGE_SEGMENT_DONE");
2290 case GST_MESSAGE_DURATION_CHANGED:
2291 _mmcam_dbg_log("GST_MESSAGE_DURATION_CHANGED");
2293 case GST_MESSAGE_LATENCY:
2294 _mmcam_dbg_log("GST_MESSAGE_LATENCY");
2296 case GST_MESSAGE_ASYNC_START:
2297 _mmcam_dbg_log("GST_MESSAGE_ASYNC_START");
2299 case GST_MESSAGE_ASYNC_DONE:
2300 _mmcam_dbg_log("GST_MESSAGE_ASYNC_DONE");
2302 case GST_MESSAGE_ANY:
2303 _mmcam_dbg_log("GST_MESSAGE_ANY");
2305 case GST_MESSAGE_QOS:
2306 // _mmcam_dbg_log("GST_MESSAGE_QOS");
2309 _mmcam_dbg_log("not handled message type=(%d)", GST_MESSAGE_TYPE(message));
2317 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
2319 GstElement *element = NULL;
2321 gchar *debug_info = NULL;
2323 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2324 _MMCamcorderSubContext *sc = NULL;
2326 mmf_return_val_if_fail(hcamcorder, GST_BUS_PASS);
2327 mmf_return_val_if_fail(message, GST_BUS_PASS);
2329 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2330 mmf_return_val_if_fail(sc, GST_BUS_PASS);
2332 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
2333 /* parse error message */
2334 gst_message_parse_error(message, &err, &debug_info);
2337 _mmcam_dbg_err("GST ERROR : %s", debug_info);
2343 _mmcam_dbg_warn("failed to parse error message");
2344 return GST_BUS_PASS;
2347 /* set videosrc element to compare */
2348 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2350 /* check domain[RESOURCE] and element[VIDEOSRC] */
2351 if (err->domain == GST_RESOURCE_ERROR &&
2352 GST_ELEMENT_CAST(message->src) == element) {
2353 switch (err->code) {
2354 case GST_RESOURCE_ERROR_BUSY:
2355 _mmcam_dbg_err("Camera device [busy]");
2356 sc->error_code = MM_ERROR_CAMCORDER_DEVICE_BUSY;
2358 case GST_RESOURCE_ERROR_OPEN_WRITE:
2359 _mmcam_dbg_err("Camera device [open failed]");
2360 sc->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2361 //sc->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN; // SECURITY PART REQUEST PRIVILEGE
2363 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2364 _mmcam_dbg_err("Camera device [open failed]");
2365 sc->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN;
2367 case GST_RESOURCE_ERROR_OPEN_READ:
2368 _mmcam_dbg_err("Camera device [register trouble]");
2369 sc->error_code = MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE;
2371 case GST_RESOURCE_ERROR_NOT_FOUND:
2372 _mmcam_dbg_err("Camera device [device not found]");
2373 sc->error_code = MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND;
2375 case GST_RESOURCE_ERROR_TOO_LAZY:
2376 _mmcam_dbg_err("Camera device [timeout]");
2377 sc->error_code = MM_ERROR_CAMCORDER_DEVICE_TIMEOUT;
2379 case GST_RESOURCE_ERROR_SETTINGS:
2380 _mmcam_dbg_err("Camera device [not supported]");
2381 sc->error_code = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2383 case GST_RESOURCE_ERROR_FAILED:
2384 _mmcam_dbg_err("Camera device [working failed].");
2385 sc->error_code = MM_ERROR_CAMCORDER_DEVICE_IO;
2388 _mmcam_dbg_err("Camera device [General(%d)]", err->code);
2389 sc->error_code = MM_ERROR_CAMCORDER_DEVICE;
2393 sc->error_occurs = TRUE;
2398 /* store error code and drop this message if cmd is running */
2399 if (sc->error_code != MM_ERROR_NONE) {
2400 _MMCamcorderMsgItem msg;
2402 /* post error to application */
2403 sc->error_occurs = TRUE;
2404 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2405 msg.param.code = sc->error_code;
2406 _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg);
2410 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
2411 _MMCamcorderMsgItem msg;
2413 if (gst_structure_has_name(gst_message_get_structure(message), "avsysvideosrc-AF") ||
2414 gst_structure_has_name(gst_message_get_structure(message), "camerasrc-AF")) {
2415 int focus_state = 0;
2417 gst_structure_get_int(gst_message_get_structure(message), "focus-state", &focus_state);
2418 _mmcam_dbg_log("Focus State:%d", focus_state);
2420 msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED;
2421 msg.param.code = focus_state;
2422 _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg);
2425 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) {
2429 if (gst_structure_get_int(gst_message_get_structure(message), "progress", &progress)) {
2430 gst_structure_get_int(gst_message_get_structure(message), "status", &status);
2431 _mmcam_dbg_log("HDR progress %d percent, status %d", progress, status);
2433 msg.id = MM_MESSAGE_CAMCORDER_HDR_PROGRESS;
2434 msg.param.code = progress;
2435 _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg);
2439 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) {
2441 const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");;
2442 GstCameraControlFaceDetectInfo *fd_info = NULL;
2443 MMCamFaceDetectInfo *cam_fd_info = NULL;
2446 fd_info = (GstCameraControlFaceDetectInfo *)g_value_get_pointer(g_value);
2449 if (fd_info == NULL) {
2450 _mmcam_dbg_warn("fd_info is NULL");
2454 cam_fd_info = (MMCamFaceDetectInfo *)malloc(sizeof(MMCamFaceDetectInfo));
2455 if (cam_fd_info == NULL) {
2456 _mmcam_dbg_warn("cam_fd_info alloc failed");
2464 /* set total face count */
2465 cam_fd_info->num_of_faces = fd_info->num_of_faces;
2467 if (cam_fd_info->num_of_faces > 0) {
2468 cam_fd_info->face_info = (MMCamFaceInfo *)malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
2469 if (cam_fd_info->face_info) {
2470 /* set information of each face */
2471 for (i = 0 ; i < fd_info->num_of_faces ; i++) {
2472 cam_fd_info->face_info[i].id = fd_info->face_info[i].id;
2473 cam_fd_info->face_info[i].score = fd_info->face_info[i].score;
2474 cam_fd_info->face_info[i].rect.x = fd_info->face_info[i].rect.x;
2475 cam_fd_info->face_info[i].rect.y = fd_info->face_info[i].rect.y;
2476 cam_fd_info->face_info[i].rect.width = fd_info->face_info[i].rect.width;
2477 cam_fd_info->face_info[i].rect.height = fd_info->face_info[i].rect.height;
2479 _mmcam_dbg_log("id %d, score %d, [%d,%d,%dx%d]",
2480 fd_info->face_info[i].id,
2481 fd_info->face_info[i].score,
2482 fd_info->face_info[i].rect.x,
2483 fd_info->face_info[i].rect.y,
2484 fd_info->face_info[i].rect.width,
2485 fd_info->face_info[i].rect.height);
2489 _mmcam_dbg_warn("MMCamFaceInfo alloc failed");
2491 /* free allocated memory that is not sent */
2496 cam_fd_info->face_info = NULL;
2500 /* send message - cam_fd_info should be freed by application */
2501 msg.id = MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO;
2502 msg.param.data = cam_fd_info;
2503 msg.param.size = sizeof(MMCamFaceDetectInfo);
2506 _mmcamcroder_send_message((MMHandleType)hcamcorder, &msg);
2509 /* free fd_info allocated by plugin */
2514 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-Capture")) {
2515 int capture_done = FALSE;
2517 if (gst_structure_get_int(gst_message_get_structure(message), "capture-done", &capture_done)) {
2518 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2519 if (sc && sc->info_image) {
2520 /* play capture sound */
2521 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_FILEPATH_CAPTURE_SND, FALSE);
2529 return GST_BUS_PASS;
2532 gst_message_unref(message);
2535 return GST_BUS_DROP;
2539 int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
2541 int ret = MM_ERROR_NONE;
2542 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2543 _MMCamcorderSubContext *sc = NULL;
2544 GstElement *pipeline = NULL;
2546 _mmcam_dbg_log("handle : %x, type : %d", handle, type);
2548 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2550 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2551 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2554 case MM_CAMCORDER_MODE_AUDIO:
2555 ret = _mmcamcorder_create_audio_pipeline(handle);
2556 if (ret != MM_ERROR_NONE) {
2560 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2562 ret = _mmcamcorder_create_preview_pipeline(handle);
2563 if (ret != MM_ERROR_NONE) {
2567 /* connect capture signal */
2568 if (!sc->bencbin_capture) {
2569 ret = _mmcamcorder_connect_capture_signal(handle);
2570 if (ret != MM_ERROR_NONE) {
2577 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
2578 if (type != MM_CAMCORDER_MODE_AUDIO) {
2579 ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY);
2581 #ifdef _MMCAMCORDER_GET_DEVICE_INFO
2582 if (!_mmcamcorder_get_device_info(handle)) {
2583 _mmcam_dbg_err("Getting device information error!!");
2587 _mmcam_dbg_log("ret[%x]", ret);
2588 if (ret != MM_ERROR_NONE) {
2589 _mmcam_dbg_err("error : destroy pipeline");
2590 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
2597 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
2599 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2600 _MMCamcorderSubContext *sc = NULL;
2602 int element_num = 0;
2603 _MMCamcorderGstElement *element = NULL;
2606 mmf_return_if_fail(hcamcorder);
2608 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2609 mmf_return_if_fail(sc);
2613 /* Inside each pipeline destroy function, Set GST_STATE_NULL to Main pipeline */
2615 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2616 element = sc->element;
2617 element_num = sc->element_num;
2618 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
2619 _mmcamcorder_destroy_video_capture_pipeline(handle);
2621 case MM_CAMCORDER_MODE_AUDIO:
2622 element = sc->encode_element;
2623 element_num = sc->encode_element_num;
2624 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst));
2625 _mmcamcorder_destroy_audio_pipeline(handle);
2628 _mmcam_dbg_err("unknown type %d", type);
2632 _mmcam_dbg_log("Pipeline clear!!");
2634 /* Remove pipeline message callback */
2635 if (hcamcorder->pipeline_cb_event_id > 0) {
2636 g_source_remove(hcamcorder->pipeline_cb_event_id);
2637 hcamcorder->pipeline_cb_event_id = 0;
2640 /* Remove remained message in bus */
2642 GstMessage *gst_msg = NULL;
2643 while ((gst_msg = gst_bus_pop(bus)) != NULL) {
2644 _mmcamcorder_pipeline_cb_message(bus, gst_msg, (gpointer)hcamcorder);
2645 gst_message_unref( gst_msg );
2648 gst_object_unref( bus );
2652 /* checking unreleased element */
2653 for (i = 0 ; i < element_num ; i++ ) {
2654 if (element[i].gst) {
2655 if (GST_IS_ELEMENT(element[i].gst)) {
2656 _mmcam_dbg_warn("Still alive element - ID[%d], name [%s], ref count[%d], status[%s]",
2658 GST_OBJECT_NAME(element[i].gst),
2659 GST_OBJECT_REFCOUNT(element[i].gst),
2660 gst_element_state_get_name(GST_STATE(element[i].gst)));
2661 g_object_weak_unref(G_OBJECT(element[i].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sc);
2663 _mmcam_dbg_warn("The element[%d] is still aliving, check it", element[i].id);
2666 element[i].id = _MMCAMCORDER_NONE;
2667 element[i].gst = NULL;
2675 int _mmcamcorder_gst_set_state_async(MMHandleType handle, GstElement *pipeline, GstState target_state)
2677 GstStateChangeReturn setChangeReturn = GST_STATE_CHANGE_FAILURE;
2679 _MMCAMCORDER_LOCK_GST_STATE(handle);
2680 setChangeReturn = gst_element_set_state(pipeline, target_state);
2681 _MMCAMCORDER_UNLOCK_GST_STATE(handle);
2683 return setChangeReturn;
2687 #ifdef _MMCAMCORDER_USE_SET_ATTR_CB
2688 static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data)
2690 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2692 mmf_return_val_if_fail(hcamcorder, FALSE);
2696 _mmcamcorder_set_attribute_to_camsensor((MMHandleType)hcamcorder);
2699 hcamcorder->setting_event_id = 0;
2701 _mmcam_dbg_log("Done");
2706 #endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
2709 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state)
2712 _MMCamcorderSubContext *sc = NULL;
2713 GstState pipeline_state = GST_STATE_VOID_PENDING;
2714 GstStateChangeReturn setChangeReturn = GST_STATE_CHANGE_FAILURE;
2715 GstStateChangeReturn getChangeReturn = GST_STATE_CHANGE_FAILURE;
2716 GstClockTime get_timeout = __MMCAMCORDER_SET_GST_STATE_TIMEOUT * GST_SECOND;
2717 pthread_mutex_t *state_lock = NULL;
2719 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2720 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2721 mmf_return_val_if_fail(sc && sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2723 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == pipeline) {
2724 _mmcam_dbg_log("Set state to %d - PREVIEW PIPELINE", target_state);
2725 state_lock = &_MMCAMCORDER_GET_GST_STATE_LOCK(handle);
2727 _mmcam_dbg_log("Set state to %d - ENDODE PIPELINE", target_state);
2728 state_lock = &_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle);
2731 pthread_mutex_lock(state_lock);
2733 for (k = 0; k < _MMCAMCORDER_STATE_SET_COUNT; k++) {
2734 setChangeReturn = gst_element_set_state(pipeline, target_state);
2735 _mmcam_dbg_log("gst_element_set_state[%d] return %d",
2736 target_state, setChangeReturn);
2737 if (setChangeReturn != GST_STATE_CHANGE_FAILURE) {
2738 getChangeReturn = gst_element_get_state(pipeline, &pipeline_state, NULL, get_timeout);
2739 switch (getChangeReturn) {
2740 case GST_STATE_CHANGE_NO_PREROLL:
2741 _mmcam_dbg_log("status=GST_STATE_CHANGE_NO_PREROLL.");
2742 case GST_STATE_CHANGE_SUCCESS:
2743 /* if we reached the final target state, exit */
2744 if (pipeline_state == target_state) {
2745 _mmcam_dbg_log("Set state to %d - DONE", target_state);
2746 pthread_mutex_unlock(state_lock);
2747 return MM_ERROR_NONE;
2750 case GST_STATE_CHANGE_ASYNC:
2751 _mmcam_dbg_log("status=GST_STATE_CHANGE_ASYNC.");
2754 pthread_mutex_unlock(state_lock);
2755 _mmcam_dbg_log("status=GST_STATE_CHANGE_FAILURE.");
2756 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
2759 pthread_mutex_unlock(state_lock);
2761 _mmcam_dbg_err("timeout of gst_element_get_state()!!");
2763 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2765 usleep(_MMCAMCORDER_STATE_CHECK_INTERVAL);
2768 pthread_mutex_unlock(state_lock);
2770 _mmcam_dbg_err("Failure. gst_element_set_state timeout!!");
2772 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
2776 /* For performance check */
2777 int _mmcamcorder_video_current_framerate(MMHandleType handle)
2779 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2780 _MMCamcorderSubContext *sc = NULL;
2782 mmf_return_val_if_fail(hcamcorder, -1);
2784 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2785 mmf_return_val_if_fail(sc, -1);
2787 return sc->kpi.current_fps;
2791 int _mmcamcorder_video_average_framerate(MMHandleType handle)
2793 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2794 _MMCamcorderSubContext *sc = NULL;
2796 mmf_return_val_if_fail(hcamcorder, -1);
2798 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2799 mmf_return_val_if_fail(sc, -1);
2801 return sc->kpi.average_fps;
2805 void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
2807 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2808 _MMCamcorderSubContext *sc = NULL;
2810 mmf_return_if_fail(hcamcorder);
2812 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2813 mmf_return_if_fail(sc);
2815 memset(&(sc->kpi), 0x00, sizeof(_MMCamcorderKPIMeasure));
2821 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error)
2823 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2824 _MMCamcorderMsgItem msg;
2825 gchar *msg_src_element;
2826 _MMCamcorderSubContext *sc = NULL;
2828 return_val_if_fail(hcamcorder, FALSE);
2829 return_val_if_fail(error, FALSE);
2830 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2831 mmf_return_val_if_fail(sc, FALSE);
2835 /* filtering filesink related errors */
2836 if (hcamcorder->state == MM_CAMCORDER_STATE_RECORDING &&
2837 (error->code == GST_RESOURCE_ERROR_WRITE || error->code == GST_RESOURCE_ERROR_SEEK)) {
2838 if (sc->ferror_count == 2 && sc->ferror_send == FALSE) {
2839 sc->ferror_send = TRUE;
2840 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
2843 _mmcam_dbg_warn("Skip error");
2848 if (error->domain == GST_CORE_ERROR) {
2849 msg.param.code = __mmcamcorder_gst_handle_core_error(handle, error->code, message);
2850 } else if (error->domain == GST_LIBRARY_ERROR) {
2851 msg.param.code = __mmcamcorder_gst_handle_library_error(handle, error->code, message);
2852 } else if (error->domain == GST_RESOURCE_ERROR) {
2853 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
2854 } else if (error->domain == GST_STREAM_ERROR) {
2855 msg.param.code = __mmcamcorder_gst_handle_stream_error(handle, error->code, message);
2857 _mmcam_dbg_warn("This error domain is not defined.");
2859 /* we treat system error as an internal error */
2860 msg.param.code = MM_ERROR_CAMCORDER_INTERNAL;
2864 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
2865 _mmcam_dbg_err("-Msg src : [%s] Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
2866 msg_src_element, g_quark_to_string (error->domain), error->message, error->code, msg.param.code);
2868 _mmcam_dbg_err("Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
2869 g_quark_to_string (error->domain), error->message, error->code, msg.param.code);
2872 #ifdef _MMCAMCORDER_SKIP_GST_FLOW_ERROR
2873 /* Check whether send this error to application */
2874 if (msg.param.code == MM_ERROR_CAMCORDER_GST_FLOW_ERROR) {
2875 _mmcam_dbg_log("We got the error. But skip it.");
2878 #endif /* _MMCAMCORDER_SKIP_GST_FLOW_ERROR */
2880 /* post error to application */
2881 sc->error_occurs = TRUE;
2882 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2883 _mmcamcroder_send_message(handle, &msg);
2889 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message)
2891 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2892 _MMCamcorderSubContext *sc = NULL;
2893 GstElement *element = NULL;
2897 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2899 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2900 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2902 /* Specific plugin - video encoder plugin */
2903 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
2905 if (GST_ELEMENT_CAST(message->src) == element) {
2906 if (code == GST_CORE_ERROR_NEGOTIATION) {
2907 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
2909 return MM_ERROR_CAMCORDER_ENCODER;
2916 case GST_CORE_ERROR_STATE_CHANGE:
2917 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
2918 case GST_CORE_ERROR_NEGOTIATION:
2919 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
2920 case GST_CORE_ERROR_MISSING_PLUGIN:
2921 case GST_CORE_ERROR_SEEK:
2922 case GST_CORE_ERROR_NOT_IMPLEMENTED:
2923 case GST_CORE_ERROR_FAILED:
2924 case GST_CORE_ERROR_TOO_LAZY:
2925 case GST_CORE_ERROR_PAD:
2926 case GST_CORE_ERROR_THREAD:
2927 case GST_CORE_ERROR_EVENT:
2928 case GST_CORE_ERROR_CAPS:
2929 case GST_CORE_ERROR_TAG:
2930 case GST_CORE_ERROR_CLOCK:
2931 case GST_CORE_ERROR_DISABLED:
2933 return MM_ERROR_CAMCORDER_GST_CORE;
2938 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message)
2940 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2941 return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2945 /* Specific plugin - NONE */
2949 case GST_LIBRARY_ERROR_FAILED:
2950 case GST_LIBRARY_ERROR_TOO_LAZY:
2951 case GST_LIBRARY_ERROR_INIT:
2952 case GST_LIBRARY_ERROR_SHUTDOWN:
2953 case GST_LIBRARY_ERROR_SETTINGS:
2954 case GST_LIBRARY_ERROR_ENCODE:
2956 _mmcam_dbg_err("Library error(%d)", code);
2957 return MM_ERROR_CAMCORDER_GST_LIBRARY;
2962 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message)
2964 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2965 _MMCamcorderSubContext *sc = NULL;
2966 GstElement *element = NULL;
2968 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2970 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
2971 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2975 /* Specific plugin */
2977 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst);
2978 if (GST_ELEMENT_CAST(message->src) == element) {
2979 if (code == GST_RESOURCE_ERROR_WRITE) {
2980 _mmcam_dbg_err("Display device [Off]");
2981 return MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF;
2983 _mmcam_dbg_err("Display device [General(%d)]", code);
2988 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
2989 if (GST_ELEMENT_CAST(message->src) == element) {
2990 if (code == GST_RESOURCE_ERROR_FAILED) {
2991 _mmcam_dbg_err("Encoder [Resource error]");
2992 return MM_ERROR_CAMCORDER_ENCODER_BUFFER;
2994 _mmcam_dbg_err("Encoder [General(%d)]", code);
2995 return MM_ERROR_CAMCORDER_ENCODER;
3001 case GST_RESOURCE_ERROR_WRITE:
3002 _mmcam_dbg_err("File write error");
3003 return MM_ERROR_FILE_WRITE;
3004 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3005 _mmcam_dbg_err("No left space");
3006 return MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
3007 case GST_RESOURCE_ERROR_OPEN_WRITE:
3008 _mmcam_dbg_err("Out of storage");
3009 return MM_ERROR_OUT_OF_STORAGE;
3010 case GST_RESOURCE_ERROR_SEEK:
3011 _mmcam_dbg_err("File read(seek)");
3012 return MM_ERROR_FILE_READ;
3013 case GST_RESOURCE_ERROR_NOT_FOUND:
3014 case GST_RESOURCE_ERROR_FAILED:
3015 case GST_RESOURCE_ERROR_TOO_LAZY:
3016 case GST_RESOURCE_ERROR_BUSY:
3017 case GST_RESOURCE_ERROR_OPEN_READ:
3018 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3019 case GST_RESOURCE_ERROR_CLOSE:
3020 case GST_RESOURCE_ERROR_READ:
3021 case GST_RESOURCE_ERROR_SYNC:
3022 case GST_RESOURCE_ERROR_SETTINGS:
3024 _mmcam_dbg_err("Resource error(%d)", code);
3025 return MM_ERROR_CAMCORDER_GST_RESOURCE;
3030 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message)
3032 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3033 _MMCamcorderSubContext *sc = NULL;
3034 GstElement *element =NULL;
3036 mmf_return_val_if_fail( hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED );
3038 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3039 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3043 /* Specific plugin */
3045 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3046 if (GST_ELEMENT_CAST(message->src) == element) {
3048 case GST_STREAM_ERROR_WRONG_TYPE:
3049 _mmcam_dbg_err("Video encoder [wrong stream type]");
3050 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
3051 case GST_STREAM_ERROR_ENCODE:
3052 _mmcam_dbg_err("Video encoder [encode error]");
3053 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3054 case GST_STREAM_ERROR_FAILED:
3055 _mmcam_dbg_err("Video encoder [stream failed]");
3056 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3058 _mmcam_dbg_err("Video encoder [General(%d)]", code);
3059 return MM_ERROR_CAMCORDER_ENCODER;
3063 /* General plugin */
3065 case GST_STREAM_ERROR_FORMAT:
3066 _mmcam_dbg_err("General [negotiation error(%d)]", code);
3067 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3068 case GST_STREAM_ERROR_FAILED:
3069 _mmcam_dbg_err("General [flow error(%d)]", code);
3070 return MM_ERROR_CAMCORDER_GST_FLOW_ERROR;
3071 case GST_STREAM_ERROR_TYPE_NOT_FOUND:
3072 case GST_STREAM_ERROR_DECODE:
3073 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
3074 case GST_STREAM_ERROR_NOT_IMPLEMENTED:
3075 case GST_STREAM_ERROR_TOO_LAZY:
3076 case GST_STREAM_ERROR_ENCODE:
3077 case GST_STREAM_ERROR_DEMUX:
3078 case GST_STREAM_ERROR_MUX:
3079 case GST_STREAM_ERROR_DECRYPT:
3080 case GST_STREAM_ERROR_DECRYPT_NOKEY:
3081 case GST_STREAM_ERROR_WRONG_TYPE:
3083 _mmcam_dbg_err("General [error(%d)]", code);
3084 return MM_ERROR_CAMCORDER_GST_STREAM;
3089 static gboolean __mmcamcorder_handle_gst_warning (MMHandleType handle, GstMessage *message, GError *error)
3091 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3092 gchar *debug = NULL;
3095 return_val_if_fail(hcamcorder, FALSE);
3096 return_val_if_fail(error, FALSE);
3100 gst_message_parse_warning(message, &err, &debug);
3102 if (error->domain == GST_CORE_ERROR) {
3103 _mmcam_dbg_warn("GST warning: GST_CORE domain");
3104 } else if (error->domain == GST_LIBRARY_ERROR) {
3105 _mmcam_dbg_warn("GST warning: GST_LIBRARY domain");
3106 } else if (error->domain == GST_RESOURCE_ERROR) {
3107 _mmcam_dbg_warn("GST warning: GST_RESOURCE domain");
3108 __mmcamcorder_gst_handle_resource_warning(handle, message, error);
3109 } else if (error->domain == GST_STREAM_ERROR ) {
3110 _mmcam_dbg_warn("GST warning: GST_STREAM domain");
3112 _mmcam_dbg_warn("This error domain(%d) is not defined.", error->domain);
3119 if (debug != NULL) {
3120 _mmcam_dbg_err ("Debug: %s", debug);
3129 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error)
3131 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3132 _MMCamcorderSubContext *sc = NULL;
3133 GstElement *element =NULL;
3134 gchar *msg_src_element;
3136 mmf_return_val_if_fail( hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED );
3138 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3139 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3143 /* Special message handling */
3145 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
3146 if (GST_ELEMENT_CAST(message->src) == element) {
3147 if (error->code == GST_RESOURCE_ERROR_FAILED) {
3148 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3149 _mmcam_dbg_warn("-Msg src:[%s] Domain:[%s] Error:[%s]",
3150 msg_src_element, g_quark_to_string(error->domain), error->message);
3151 return MM_ERROR_NONE;
3155 /* General plugin */
3156 switch (error->code) {
3157 case GST_RESOURCE_ERROR_WRITE:
3158 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3159 case GST_RESOURCE_ERROR_SEEK:
3160 case GST_RESOURCE_ERROR_NOT_FOUND:
3161 case GST_RESOURCE_ERROR_FAILED:
3162 case GST_RESOURCE_ERROR_TOO_LAZY:
3163 case GST_RESOURCE_ERROR_BUSY:
3164 case GST_RESOURCE_ERROR_OPEN_READ:
3165 case GST_RESOURCE_ERROR_OPEN_WRITE:
3166 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3167 case GST_RESOURCE_ERROR_CLOSE:
3168 case GST_RESOURCE_ERROR_READ:
3169 case GST_RESOURCE_ERROR_SYNC:
3170 case GST_RESOURCE_ERROR_SETTINGS:
3172 _mmcam_dbg_warn("General GST warning(%d)", error->code);
3176 return MM_ERROR_NONE;