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 ========================================================================================*/
30 #include <gst/gstutils.h>
31 #include <gst/gstpad.h>
35 #include "mm_camcorder_internal.h"
38 #include <gst/video/colorbalance.h>
39 #include <gst/video/cameracontrol.h>
40 #include <asm/types.h>
42 #include <system_info.h>
44 #ifdef _MMCAMCORDER_RM_SUPPORT
45 #include "mm_camcorder_rm.h"
46 #endif /* _MMCAMCORDER_RM_SUPPORT */
49 int mmcam_log_level = MM_CAMCORDER_LOG_LEVEL_INFO;
51 /*---------------------------------------------------------------------------------------
52 | LOCAL VARIABLE DEFINITIONS for internal |
53 ---------------------------------------------------------------------------------------*/
54 #define __MMCAMCORDER_CMD_ITERATE_MAX 3
55 #define __MMCAMCORDER_SET_GST_STATE_TIMEOUT 5
56 #define __MMCAMCORDER_FORCE_STOP_TRY_COUNT 30
57 #define __MMCAMCORDER_FORCE_STOP_WAIT_TIME 100000 /* us */
58 #define __MMCAMCORDER_SOUND_WAIT_TIMEOUT 3
59 #define __MMCAMCORDER_FOCUS_CHANGE_REASON_LEN 64
60 #define __MMCAMCORDER_CONF_FILENAME_LENGTH 64
62 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
63 #define __MMCAMCORDER_DEVICE_TYPE_STRING_LEN 1
68 #define DPM_DISALLOWED 0
70 /*---------------------------------------------------------------------------------------
71 | LOCAL FUNCTION PROTOTYPES: |
72 ---------------------------------------------------------------------------------------*/
73 /* STATIC INTERNAL FUNCTION */
74 static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_type);
75 static void __mmcamcorder_deinit_handle(mmf_camcorder_t *hcamcorder);
76 static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcorder);
77 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder);
78 static void __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder);
79 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf);
80 static void __mmcamcorder_get_system_info(mmf_camcorder_t *hcamcorder);
82 static GstBusSyncReply __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message);
83 static GstBusSyncReply __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code);
84 static GstBusSyncReply __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code);
85 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error);
86 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message);
87 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message);
88 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message);
89 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message);
90 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error);
91 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error);
92 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
93 static int __mmcamcorder_resource_release_cb(mm_resource_manager_h rm,
94 mm_resource_manager_res_h res, void *user_data);
95 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
96 #ifdef _MMCAMCORDER_USE_SET_ATTR_CB
97 static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data);
98 #endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
100 /*=======================================================================================
101 | FUNCTION DEFINITIONS |
102 =======================================================================================*/
103 static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_type)
105 int ret = MM_ERROR_NONE;
106 mmf_camcorder_t *new_handle = NULL;
109 MMCAM_LOG_ERROR("NULL handle");
110 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
113 /* Create mmf_camcorder_t handle and initialize every variable */
114 new_handle = (mmf_camcorder_t *)malloc(sizeof(mmf_camcorder_t));
116 MMCAM_LOG_ERROR("new handle allocation failed");
117 return MM_ERROR_CAMCORDER_LOW_MEMORY;
120 memset(new_handle, 0x00, sizeof(mmf_camcorder_t));
122 /* set device type */
123 new_handle->device_type = device_type;
125 MMCAM_LOG_WARNING("Device Type : %d", new_handle->device_type);
127 new_handle->type = MM_CAMCORDER_MODE_VIDEO_CAPTURE;
128 new_handle->state = MM_CAMCORDER_STATE_NONE;
129 new_handle->old_state = MM_CAMCORDER_STATE_NONE;
130 new_handle->capture_in_recording = FALSE;
132 /* init mutex and cond */
133 g_mutex_init(&(new_handle->mtsafe).lock);
134 g_cond_init(&(new_handle->mtsafe).cond);
135 g_mutex_init(&(new_handle->mtsafe).cmd_lock);
136 g_cond_init(&(new_handle->mtsafe).cmd_cond);
137 g_mutex_init(&(new_handle->mtsafe).interrupt_lock);
138 g_mutex_init(&(new_handle->mtsafe).state_lock);
139 g_mutex_init(&(new_handle->mtsafe).gst_state_lock);
140 g_mutex_init(&(new_handle->mtsafe).gst_encode_state_lock);
141 g_mutex_init(&(new_handle->mtsafe).message_cb_lock);
142 g_mutex_init(&(new_handle->mtsafe).vcapture_cb_lock);
143 g_mutex_init(&(new_handle->mtsafe).vstream_cb_lock);
144 g_mutex_init(&(new_handle->mtsafe).astream_cb_lock);
145 g_mutex_init(&(new_handle->mtsafe).mstream_cb_lock);
146 g_mutex_init(&(new_handle->mtsafe).vedecision_cb_lock);
147 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
148 g_mutex_init(&(new_handle->mtsafe).resource_lock);
149 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
151 g_mutex_init(&new_handle->restart_preview_lock);
153 g_mutex_init(&new_handle->snd_info.open_mutex);
154 g_cond_init(&new_handle->snd_info.open_cond);
155 g_mutex_init(&new_handle->snd_info.play_mutex);
156 g_cond_init(&new_handle->snd_info.play_cond);
158 g_mutex_init(&new_handle->task_thread_lock);
159 g_cond_init(&new_handle->task_thread_cond);
160 new_handle->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
162 if (device_type != MM_VIDEO_DEVICE_NONE) {
163 new_handle->gdbus_info_sound.mm_handle = new_handle;
164 g_mutex_init(&new_handle->gdbus_info_sound.sync_mutex);
165 g_cond_init(&new_handle->gdbus_info_sound.sync_cond);
167 new_handle->gdbus_info_solo_sound.mm_handle = new_handle;
168 g_mutex_init(&new_handle->gdbus_info_solo_sound.sync_mutex);
169 g_cond_init(&new_handle->gdbus_info_solo_sound.sync_cond);
172 /* create task thread */
173 new_handle->task_thread = g_thread_try_new("MMCAM_TASK_THREAD",
174 (GThreadFunc)_mmcamcorder_util_task_thread_func, (gpointer)new_handle, NULL);
175 if (new_handle->task_thread == NULL) {
176 MMCAM_LOG_ERROR("_mmcamcorder_create::failed to create task thread");
177 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
178 goto _INIT_HANDLE_FAILED;
181 /* Get Camera Configure information from Camcorder INI file */
182 ret = _mmcamcorder_conf_get_info((MMHandleType)new_handle, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &new_handle->conf_main);
183 if (ret != MM_ERROR_NONE) {
184 MMCAM_LOG_ERROR("Failed to get configure(main) info.");
185 goto _INIT_HANDLE_FAILED;
188 /* Get log level from conf */
189 _mmcamcorder_conf_get_value_int((MMHandleType)new_handle, new_handle->conf_main,
190 CONFIGURE_CATEGORY_MAIN_GENERAL,
194 /* allocate attribute */
195 new_handle->attributes = _mmcamcorder_alloc_attribute((MMHandleType)new_handle);
196 if (!new_handle->attributes) {
197 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
198 goto _INIT_HANDLE_FAILED;
201 /* Set log level to attribute */
202 ret = mm_camcorder_set_attributes((MMHandleType)new_handle, NULL,
203 MMCAM_LOG_LEVEL, mmcam_log_level,
206 MMCAM_LOG_INFO("set log level[%d], ret[0x%x]", mmcam_log_level, ret);
208 *hcamcorder = new_handle;
210 MMCAM_LOG_INFO("new handle %p", new_handle);
212 return MM_ERROR_NONE;
215 __mmcamcorder_deinit_handle(new_handle);
220 static void __mmcamcorder_deinit_handle(mmf_camcorder_t *hcamcorder)
223 MMCAM_LOG_ERROR("NULL handle");
227 /* Remove exif info */
228 if (hcamcorder->exif_info) {
229 mm_exif_destory_exif_info(hcamcorder->exif_info);
230 hcamcorder->exif_info = NULL;
233 /* remove attributes */
234 if (hcamcorder->attributes) {
235 _mmcamcorder_dealloc_attribute((MMHandleType)hcamcorder, hcamcorder->attributes);
236 hcamcorder->attributes = 0;
239 /* Release configure info */
240 __mmcamcorder_deinit_configure(hcamcorder);
242 /* remove task thread */
243 if (hcamcorder->task_thread) {
244 g_mutex_lock(&hcamcorder->task_thread_lock);
245 MMCAM_LOG_INFO("send signal for task thread exit");
246 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_EXIT;
247 g_cond_signal(&hcamcorder->task_thread_cond);
248 g_mutex_unlock(&hcamcorder->task_thread_lock);
249 g_thread_join(hcamcorder->task_thread);
250 hcamcorder->task_thread = NULL;
253 /* Release lock, cond */
254 g_mutex_clear(&(hcamcorder->mtsafe).lock);
255 g_cond_clear(&(hcamcorder->mtsafe).cond);
256 g_mutex_clear(&(hcamcorder->mtsafe).cmd_lock);
257 g_cond_clear(&(hcamcorder->mtsafe).cmd_cond);
258 g_mutex_clear(&(hcamcorder->mtsafe).interrupt_lock);
259 g_mutex_clear(&(hcamcorder->mtsafe).state_lock);
260 g_mutex_clear(&(hcamcorder->mtsafe).gst_state_lock);
261 g_mutex_clear(&(hcamcorder->mtsafe).gst_encode_state_lock);
262 g_mutex_clear(&(hcamcorder->mtsafe).message_cb_lock);
263 g_mutex_clear(&(hcamcorder->mtsafe).vcapture_cb_lock);
264 g_mutex_clear(&(hcamcorder->mtsafe).vstream_cb_lock);
265 g_mutex_clear(&(hcamcorder->mtsafe).astream_cb_lock);
266 g_mutex_clear(&(hcamcorder->mtsafe).mstream_cb_lock);
267 g_mutex_clear(&(hcamcorder->mtsafe).vedecision_cb_lock);
268 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
269 g_mutex_clear(&(hcamcorder->mtsafe).resource_lock);
270 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
272 g_mutex_clear(&hcamcorder->snd_info.open_mutex);
273 g_cond_clear(&hcamcorder->snd_info.open_cond);
274 g_mutex_clear(&hcamcorder->restart_preview_lock);
276 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
277 g_mutex_clear(&hcamcorder->gdbus_info_sound.sync_mutex);
278 g_cond_clear(&hcamcorder->gdbus_info_sound.sync_cond);
279 g_mutex_clear(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
280 g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
283 g_mutex_clear(&hcamcorder->task_thread_lock);
284 g_cond_clear(&hcamcorder->task_thread_cond);
286 if (hcamcorder->model_name)
287 free(hcamcorder->model_name);
289 if (hcamcorder->software_version)
290 free(hcamcorder->software_version);
293 memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
301 static void __mmcamcorder_get_system_info(mmf_camcorder_t *hcamcorder)
306 MMCAM_LOG_ERROR("NULL handle");
310 /* get shutter sound policy */
311 vconf_get_int(VCONFKEY_CAMERA_SHUTTER_SOUND_POLICY, &hcamcorder->shutter_sound_policy);
312 MMCAM_LOG_INFO("current shutter sound policy : %d", hcamcorder->shutter_sound_policy);
315 ret = system_info_get_platform_string("http://tizen.org/system/model_name", &hcamcorder->model_name);
317 MMCAM_LOG_WARNING("model name [%s], ret 0x%x",
318 hcamcorder->model_name ? hcamcorder->model_name : "NULL", ret);
320 /* get software version */
321 ret = system_info_get_platform_string("http://tizen.org/system/build.string", &hcamcorder->software_version);
323 MMCAM_LOG_WARNING("software version [%s], ret 0x%x",
324 hcamcorder->software_version ? hcamcorder->software_version : "NULL", ret);
330 static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcorder)
332 int ret = MM_ERROR_NONE;
333 int resolution_width = 0;
334 int resolution_height = 0;
335 int rcmd_fmt_capture = MM_PIXEL_FORMAT_YUYV;
336 int rcmd_fmt_recording = MM_PIXEL_FORMAT_NV12;
337 int rcmd_dpy_rotation = MM_DISPLAY_ROTATION_270;
338 int play_capture_sound = TRUE;
339 int camera_device_count = MM_VIDEO_DEVICE_NUM;
340 int camera_default_flip = MM_FLIP_NONE;
341 int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
342 char *err_attr_name = NULL;
343 char conf_file_name[__MMCAMCORDER_CONF_FILENAME_LENGTH] = {'\0',};
344 const char *platform_privilege_camera = NULL;
345 MMCamAttrsInfo fps_info;
346 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
347 camera_conf_error_e ret_conf = CAMERA_CONF_MGR_ERROR_NONE;
348 char devicetype[__MMCAMCORDER_CONF_FILENAME_LENGTH] = {'\0',};
352 MMCAM_LOG_ERROR("NULL handle");
353 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
356 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
357 snprintf(devicetype, sizeof(devicetype), "%d", hcamcorder->device_type);
358 memset(&hcamcorder->conf_device_info, 0x00, sizeof(camera_conf_device_info_s));
359 ret_conf = camera_conf_mgr_get_ids(devicetype, __MMCAMCORDER_DEVICE_TYPE_STRING_LEN,
360 &hcamcorder->conf_device_info);
361 if (ret_conf != CAMERA_CONF_MGR_ERROR_NONE) {
362 MMCAM_LOG_ERROR("Device [%s] is not found", devicetype);
363 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
366 snprintf(conf_file_name, sizeof(conf_file_name), "%s_%s_%s.ini",
367 CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->conf_device_info.vendor_id,
368 hcamcorder->conf_device_info.product_id);
370 MMCAM_LOG_INFO("Load control configure file [%d][%s][%s]", hcamcorder->device_type,
371 conf_file_name, hcamcorder->conf_device_info.node);
373 snprintf(conf_file_name, sizeof(conf_file_name), "%s%d.ini",
374 CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->device_type);
375 MMCAM_LOG_INFO("Load control configure file [%d][%s]", hcamcorder->device_type, conf_file_name);
378 ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
379 CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
380 if (ret != MM_ERROR_NONE) {
381 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
382 snprintf(conf_file_name, sizeof(conf_file_name), "%s.ini",
383 CONFIGURE_CTRL_FILE_PREFIX);
384 ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
385 CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
386 if (ret != MM_ERROR_NONE) {
387 MMCAM_LOG_ERROR("Failed to get configure(control) info.");
391 MMCAM_LOG_ERROR("Failed to get configure(control) info.");
396 _mmcamcorder_conf_print_info(&hcamcorder->conf_main);
397 _mmcamcorder_conf_print_info(&hcamcorder->conf_ctrl);
399 ret = _mmcamcorder_init_convert_table((MMHandleType)hcamcorder);
400 if (ret != MM_ERROR_NONE) {
401 MMCAM_LOG_WARNING("converting table initialize error!!");
402 return MM_ERROR_CAMCORDER_INTERNAL;
405 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_ALL);
406 if (ret != MM_ERROR_NONE) {
407 MMCAM_LOG_WARNING("attribute initialize from configure error!!");
408 return MM_ERROR_CAMCORDER_INTERNAL;
411 /* Get device information for supported features from INI */
412 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
413 CONFIGURE_CATEGORY_CTRL_CAMERA,
414 "RecommendPreviewFormatCapture",
417 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
418 CONFIGURE_CATEGORY_CTRL_CAMERA,
419 "RecommendPreviewFormatRecord",
420 &rcmd_fmt_recording);
422 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
423 CONFIGURE_CATEGORY_CTRL_CAMERA,
424 "RecommendDisplayRotation",
427 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
428 CONFIGURE_CATEGORY_MAIN_CAPTURE,
430 &play_capture_sound);
432 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
433 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
435 &camera_device_count);
437 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
438 CONFIGURE_CATEGORY_CTRL_CAMERA,
440 &camera_facing_direction);
442 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
443 CONFIGURE_CATEGORY_CTRL_EFFECT,
444 "BrightnessStepDenominator",
445 &hcamcorder->brightness_step_denominator);
447 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
448 CONFIGURE_CATEGORY_CTRL_CAPTURE,
450 &hcamcorder->support_zsl_capture);
452 MMCAM_LOG_INFO("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",
453 rcmd_fmt_capture, rcmd_fmt_recording, rcmd_dpy_rotation,
454 play_capture_sound, camera_device_count, camera_facing_direction,
455 hcamcorder->brightness_step_denominator, hcamcorder->support_zsl_capture);
457 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
458 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
460 &hcamcorder->use_zero_copy_format);
462 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
463 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
465 &hcamcorder->support_user_buffer);
467 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
468 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
469 "SupportMediaPacketPreviewCb",
470 &hcamcorder->support_media_packet_preview_cb);
472 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
473 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
475 &hcamcorder->use_videoconvert);
477 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
478 MMCAM_CAMERA_WIDTH, &resolution_width,
479 MMCAM_CAMERA_HEIGHT, &resolution_height,
481 if (ret != MM_ERROR_NONE) {
482 MMCAM_LOG_ERROR("get attribute[resolution] error");
483 return MM_ERROR_CAMCORDER_INTERNAL;
486 ret = mm_camcorder_get_fps_list_by_resolution((MMHandleType)hcamcorder, resolution_width, resolution_height, &fps_info);
487 if (ret != MM_ERROR_NONE) {
488 MMCAM_LOG_ERROR("get fps list failed with [%dx%d]", resolution_width, resolution_height);
489 return MM_ERROR_CAMCORDER_INTERNAL;
492 MMCAM_LOG_INFO("ZeroCopy %d, UserBuffer %d, Videoconvert %d, MPPreviewCb %d",
493 hcamcorder->use_zero_copy_format, hcamcorder->support_user_buffer,
494 hcamcorder->use_videoconvert, hcamcorder->support_media_packet_preview_cb);
496 MMCAM_LOG_INFO("res : %d X %d, Default FPS by resolution : %d",
497 resolution_width, resolution_height, fps_info.int_array.def);
499 if (camera_facing_direction == 1) {
500 if (rcmd_dpy_rotation == MM_DISPLAY_ROTATION_270 || rcmd_dpy_rotation == MM_DISPLAY_ROTATION_90)
501 camera_default_flip = MM_FLIP_VERTICAL;
503 camera_default_flip = MM_FLIP_HORIZONTAL;
505 MMCAM_LOG_INFO("camera_default_flip : [%d]", camera_default_flip);
508 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
509 CONFIGURE_CATEGORY_MAIN_GENERAL,
510 "PlatformPrivilegeCamera",
511 &platform_privilege_camera);
513 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, &err_attr_name,
514 MMCAM_CAMERA_DEVICE_COUNT, camera_device_count,
515 MMCAM_CAMERA_FACING_DIRECTION, camera_facing_direction,
516 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, rcmd_fmt_capture,
517 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, rcmd_fmt_recording,
518 MMCAM_RECOMMEND_DISPLAY_ROTATION, rcmd_dpy_rotation,
519 MMCAM_SUPPORT_ZSL_CAPTURE, hcamcorder->support_zsl_capture,
520 MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
521 MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
522 MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
523 MMCAM_CAMERA_FPS, fps_info.int_array.def,
524 MMCAM_DISPLAY_FLIP, camera_default_flip,
525 MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,
526 MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
527 platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
529 if (ret != MM_ERROR_NONE) {
530 MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
531 SAFE_FREE(err_attr_name);
532 return MM_ERROR_CAMCORDER_INTERNAL;
535 /* Get default value of brightness */
536 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
537 MMCAM_FILTER_BRIGHTNESS, &hcamcorder->brightness_default,
539 if (ret != MM_ERROR_NONE) {
540 MMCAM_LOG_ERROR("Get brightness FAILED.");
541 return MM_ERROR_CAMCORDER_INTERNAL;
544 MMCAM_LOG_INFO("Default brightness : %d", hcamcorder->brightness_default);
550 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder)
552 int ret = MM_ERROR_NONE;
553 int camera_device_count = 0;
556 MMCAM_LOG_ERROR("NULL handle");
557 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
560 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
561 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
563 &camera_device_count);
565 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
566 MMCAM_CAMERA_DEVICE_COUNT, camera_device_count,
568 if (ret != MM_ERROR_NONE) {
569 MMCAM_LOG_ERROR("Set device count FAILED");
570 return MM_ERROR_CAMCORDER_INTERNAL;
573 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
574 if (ret != MM_ERROR_NONE) {
575 MMCAM_LOG_ERROR("there is no audio device");
576 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
583 static void __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder)
586 MMCAM_LOG_ERROR("NULL handle");
590 if (hcamcorder->conf_ctrl)
591 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_ctrl);
593 if (hcamcorder->conf_main)
594 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_main);
600 /*---------------------------------------------------------------------------------------
601 | GLOBAL FUNCTION DEFINITIONS: |
602 ---------------------------------------------------------------------------------------*/
603 /* Internal command functions {*/
604 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
606 int ret = MM_ERROR_NONE;
607 mmf_camcorder_t *hcamcorder = NULL;
609 MMCAM_LOG_INFO("Entered");
611 mmf_return_val_if_fail(handle && info, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
613 /* check device type */
614 if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
615 info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
616 MMCAM_LOG_ERROR("video device type[%d] is out of range.", info->videodev_type);
617 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
621 ret = __mmcamcorder_init_handle(&hcamcorder, info->videodev_type);
622 if (ret != MM_ERROR_NONE)
625 /* get DPM handle for camera/microphone restriction */
626 hcamcorder->dpm_handle = dpm_manager_create();
628 MMCAM_LOG_WARNING("DPM handle %p", hcamcorder->dpm_handle);
630 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
631 ret = __mmcamcorder_init_configure_video_capture(hcamcorder);
632 if (ret != MM_ERROR_NONE) {
633 goto _ERR_DEFAULT_VALUE_INIT;
636 /* add DPM camera policy changed callback */
637 if (hcamcorder->dpm_handle) {
638 ret = dpm_add_policy_changed_cb(hcamcorder->dpm_handle, "camera",
639 _mmcamcorder_dpm_camera_policy_changed_cb, (void *)hcamcorder, &hcamcorder->dpm_camera_cb_id);
640 if (ret != DPM_ERROR_NONE) {
641 MMCAM_LOG_ERROR("add DPM changed cb failed, keep going...");
642 hcamcorder->dpm_camera_cb_id = 0;
645 MMCAM_LOG_INFO("DPM camera changed cb id %d", hcamcorder->dpm_camera_cb_id);
648 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
649 /* initialize resource manager */
650 ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
651 __mmcamcorder_resource_release_cb, hcamcorder,
652 &hcamcorder->resource_manager);
653 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
654 MMCAM_LOG_ERROR("failed to initialize resource manager");
655 ret = MM_ERROR_CAMCORDER_INTERNAL;
656 goto _ERR_DEFAULT_VALUE_INIT;
658 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
660 ret = __mmcamcorder_init_configure_audio(hcamcorder);
661 if (ret != MM_ERROR_NONE) {
662 goto _ERR_DEFAULT_VALUE_INIT;
666 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:CREATE:INIT_GSTREAMER");
668 ret = __mmcamcorder_init_gstreamer(hcamcorder->conf_main);
670 traceEnd(TTRACE_TAG_CAMERA);
673 MMCAM_LOG_ERROR("Failed to initialize gstreamer!!");
674 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
675 goto _ERR_DEFAULT_VALUE_INIT;
678 /* Make some attributes as read-only type */
679 _mmcamcorder_lock_readonly_attributes((MMHandleType)hcamcorder);
681 /* Disable attributes in each model */
682 _mmcamcorder_set_disabled_attributes((MMHandleType)hcamcorder);
684 /* get system information */
685 __mmcamcorder_get_system_info(hcamcorder);
687 /* Set initial state */
688 _mmcamcorder_set_state((MMHandleType)hcamcorder, MM_CAMCORDER_STATE_NULL);
690 MMCAM_LOG_INFO("created handle %p", hcamcorder);
692 *handle = (MMHandleType)hcamcorder;
694 return MM_ERROR_NONE;
696 _ERR_DEFAULT_VALUE_INIT:
697 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
698 /* de-initialize resource manager */
699 if (hcamcorder->resource_manager != NULL)
700 mm_resource_manager_destroy(hcamcorder->resource_manager);
701 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
703 /* release DPM related handle */
704 if (hcamcorder->dpm_handle) {
705 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
706 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
708 /* remove camera policy changed callback */
709 if (hcamcorder->dpm_camera_cb_id > 0) {
710 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
711 hcamcorder->dpm_camera_cb_id = 0;
713 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
716 dpm_manager_destroy(hcamcorder->dpm_handle);
717 hcamcorder->dpm_handle = NULL;
720 /* release configure info */
721 __mmcamcorder_deinit_configure(hcamcorder);
723 /* deinitialize handle */
724 __mmcamcorder_deinit_handle(hcamcorder);
730 int _mmcamcorder_destroy(MMHandleType handle)
732 int ret = MM_ERROR_NONE;
733 int state = MM_CAMCORDER_STATE_NONE;
734 GstElement *sink_element = NULL;
735 int sink_element_size = 0;
737 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
742 MMCAM_LOG_ERROR("Not initialized");
743 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
744 goto _ERR_CAMCORDER_CMD_PRECON;
747 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
748 MMCAM_LOG_ERROR("Another command is running.");
749 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
750 goto _ERR_CAMCORDER_CMD_PRECON;
753 state = _mmcamcorder_get_state(handle);
754 if (state != MM_CAMCORDER_STATE_NULL) {
755 MMCAM_LOG_ERROR("Wrong state(%d)", state);
756 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
757 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
760 /* remove kept, but not used sink element in attribute */
761 mm_camcorder_get_attributes(handle, NULL,
762 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
765 GstStateChangeReturn result = gst_element_set_state(sink_element, GST_STATE_NULL);
767 MMCAM_LOG_WARNING("remove sink element %p, set state NULL result %d", sink_element, result);
769 gst_object_unref(sink_element);
773 /* wait for completion of sound play */
774 _mmcamcorder_sound_solo_play_wait(handle);
776 /* Release SubContext and pipeline */
777 if (hcamcorder->sub_context) {
778 if (hcamcorder->sub_context->element)
779 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
781 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
782 hcamcorder->sub_context = NULL;
785 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
786 /* de-initialize resource manager */
787 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
789 if (hcamcorder->resource_manager != NULL) {
790 ret = mm_resource_manager_destroy(hcamcorder->resource_manager);
791 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
792 MMCAM_LOG_ERROR("failed to de-initialize resource manager 0x%x", ret);
795 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
796 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
798 /* Remove idle function which is not called yet */
799 if (hcamcorder->setting_event_id) {
800 MMCAM_LOG_INFO("Remove remaining idle function");
801 g_source_remove(hcamcorder->setting_event_id);
802 hcamcorder->setting_event_id = 0;
805 /* Remove messages which are not called yet */
806 _mmcamcorder_remove_message_all(handle);
808 #ifdef _MMCAMCORDER_RM_SUPPORT
809 _mmcamcorder_rm_release(handle);
810 #endif /* _MMCAMCORDER_RM_SUPPORT */
812 /* release DPM handle */
813 if (hcamcorder->dpm_handle) {
814 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
815 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
817 /* remove camera policy changed callback */
818 if (hcamcorder->dpm_camera_cb_id > 0) {
819 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
820 hcamcorder->dpm_camera_cb_id = 0;
822 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
825 dpm_manager_destroy(hcamcorder->dpm_handle);
826 hcamcorder->dpm_handle = NULL;
829 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
831 __mmcamcorder_deinit_handle(hcamcorder);
833 return MM_ERROR_NONE;
835 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
836 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
838 _ERR_CAMCORDER_CMD_PRECON:
840 MMCAM_LOG_ERROR("Destroy fail (type %d, state %d)", hcamcorder->type, state);
842 MMCAM_LOG_ERROR("Destroy fail (ret %x)", ret);
848 int _mmcamcorder_realize(MMHandleType handle)
850 int ret = MM_ERROR_NONE;
851 int state = MM_CAMCORDER_STATE_NONE;
852 int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
853 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
854 char *videosink_element_type = NULL;
855 const char *videosink_name = NULL;
856 char *socket_path = NULL;
857 int socket_path_len = 0;
860 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
862 /*MMCAM_LOG_INFO("");*/
865 MMCAM_LOG_ERROR("Not initialized");
866 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
870 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
871 MMCAM_LOG_ERROR("Another command is running.");
872 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
873 goto _ERR_CAMCORDER_CMD_PRECON;
876 state = _mmcamcorder_get_state(handle);
877 if (state != MM_CAMCORDER_STATE_NULL) {
878 MMCAM_LOG_ERROR("Wrong state(%d)", state);
879 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
880 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
883 /* Get profile mode and gdbus connection */
884 mm_camcorder_get_attributes(handle, NULL,
885 MMCAM_MODE, &hcamcorder->type,
886 MMCAM_GDBUS_CONNECTION, &hcamcorder->gdbus_conn, &conn_size,
889 if (!hcamcorder->gdbus_conn) {
890 MMCAM_LOG_ERROR("gdbus connection NULL");
891 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
892 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
895 MMCAM_LOG_INFO("Profile mode [%d], gdbus connection [%p]",
896 hcamcorder->type, hcamcorder->gdbus_conn);
898 mm_camcorder_get_attributes(handle, NULL,
899 MMCAM_DISPLAY_SURFACE, &display_surface_type,
900 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
903 /* alloc sub context */
904 hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
905 if (!hcamcorder->sub_context) {
906 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
907 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
910 /* Set basic configure information */
911 if (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE)
912 hcamcorder->sub_context->is_modified_rate = TRUE;
914 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
915 CONFIGURE_CATEGORY_MAIN_CAPTURE,
917 &(hcamcorder->sub_context->bencbin_capture));
918 MMCAM_LOG_WARNING("UseEncodebin [%d]", hcamcorder->sub_context->bencbin_capture);
920 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
921 /* get video recording info */
922 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
923 CONFIGURE_CATEGORY_MAIN_RECORD,
925 &(hcamcorder->sub_context->info_video->support_dual_stream));
926 MMCAM_LOG_WARNING("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
928 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
929 CONFIGURE_CATEGORY_MAIN_RECORD,
931 &(hcamcorder->sub_context->info_video->use_videoscale));
932 MMCAM_LOG_WARNING("UseVideoscale [%d]", hcamcorder->sub_context->info_video->use_videoscale);
935 switch (display_surface_type) {
936 case MM_DISPLAY_SURFACE_OVERLAY:
937 videosink_element_type = strdup("VideosinkElementOverlay");
939 case MM_DISPLAY_SURFACE_EVAS:
940 videosink_element_type = strdup("VideosinkElementEvas");
942 case MM_DISPLAY_SURFACE_GL:
943 videosink_element_type = strdup("VideosinkElementGL");
945 case MM_DISPLAY_SURFACE_NULL:
946 videosink_element_type = strdup("VideosinkElementNull");
948 case MM_DISPLAY_SURFACE_REMOTE:
949 mm_camcorder_get_attributes(handle, NULL,
950 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
952 if (socket_path == NULL) {
953 MMCAM_LOG_WARNING("REMOTE surface, but socket path is NULL -> to NullSink");
954 videosink_element_type = strdup("VideosinkElementNull");
956 videosink_element_type = strdup("VideosinkElementRemote");
960 videosink_element_type = strdup("VideosinkElementOverlay");
964 /* check string of videosink element */
965 if (videosink_element_type) {
966 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
967 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
968 videosink_element_type,
969 &hcamcorder->sub_context->VideosinkElement);
970 free(videosink_element_type);
971 videosink_element_type = NULL;
973 MMCAM_LOG_WARNING("strdup failed(display_surface_type %d). Use default X type",
974 display_surface_type);
976 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
977 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
978 _MMCAMCORDER_DEFAULT_VIDEOSINK_TYPE,
979 &hcamcorder->sub_context->VideosinkElement);
982 _mmcamcorder_conf_get_value_element_name(hcamcorder->sub_context->VideosinkElement, &videosink_name);
983 MMCAM_LOG_INFO("Videosink name : %s", videosink_name);
985 /* get videoconvert element */
986 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
987 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
988 "VideoconvertElement",
989 &hcamcorder->sub_context->VideoconvertElement);
991 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
992 CONFIGURE_CATEGORY_CTRL_CAPTURE,
993 "SensorEncodedCapture",
994 &(hcamcorder->sub_context->SensorEncodedCapture));
995 MMCAM_LOG_INFO("Support sensor encoded capture : %d", hcamcorder->sub_context->SensorEncodedCapture);
997 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
998 int dpm_camera_state = DPM_ALLOWED;
1000 /* check camera policy from DPM */
1001 if (hcamcorder->dpm_handle) {
1002 if (dpm_restriction_get_camera_state(hcamcorder->dpm_handle, &dpm_camera_state) == DPM_ERROR_NONE) {
1003 MMCAM_LOG_INFO("DPM camera state %d", dpm_camera_state);
1004 if (dpm_camera_state == DPM_DISALLOWED) {
1005 MMCAM_LOG_ERROR("CAMERA DISALLOWED by DPM");
1006 ret = MM_ERROR_POLICY_RESTRICTED;
1008 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
1010 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1013 MMCAM_LOG_ERROR("get DPM camera state failed, keep going...");
1016 MMCAM_LOG_WARNING("NULL dpm_handle");
1019 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1020 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1021 /* prepare resource manager for camera */
1022 if (hcamcorder->camera_resource == NULL) {
1023 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1024 MM_RESOURCE_MANAGER_RES_TYPE_CAMERA,
1026 &hcamcorder->camera_resource);
1027 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1028 MMCAM_LOG_ERROR("could not prepare for camera resource");
1029 ret = MM_ERROR_RESOURCE_INTERNAL;
1030 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1031 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1034 MMCAM_LOG_INFO("camera already acquired");
1037 /* prepare resource manager for "video_overlay only if display surface is X" */
1038 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
1039 if (hcamcorder->video_overlay_resource == NULL) {
1040 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1041 MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY,
1042 MM_RESOURCE_MANAGER_RES_VOLUME_FULL,
1043 &hcamcorder->video_overlay_resource);
1044 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1045 MMCAM_LOG_ERROR("could not prepare for overlay resource");
1046 ret = MM_ERROR_RESOURCE_INTERNAL;
1047 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1048 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1051 MMCAM_LOG_INFO("overlay already acquired");
1055 /* acquire resources */
1056 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1057 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1058 MMCAM_LOG_ERROR("could not acquire resources");
1059 ret = MM_ERROR_RESOURCE_INTERNAL;
1060 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1061 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1063 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1064 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1066 #ifdef _MMCAMCORDER_RM_SUPPORT
1067 ret = _mmcamcorder_rm_create(handle);
1068 if (ret != MM_ERROR_NONE) {
1069 MMCAM_LOG_ERROR("Resource create failed");
1070 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1072 ret = _mmcamcorder_rm_allocate(handle);
1073 if (ret != MM_ERROR_NONE) {
1074 MMCAM_LOG_ERROR("Resource allocation request failed");
1075 _mmcamcorder_rm_release(handle);
1076 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1078 #endif /* _MMCAMCORDER_RM_SUPPORT */
1081 /* create pipeline */
1082 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:CREATE_PIPELINE");
1084 ret = _mmcamcorder_create_pipeline(handle, hcamcorder->type);
1086 traceEnd(TTRACE_TAG_CAMERA);
1088 if (ret != MM_ERROR_NONE) {
1089 /* check internal error of gstreamer */
1090 if (hcamcorder->error_code != MM_ERROR_NONE) {
1091 ret = hcamcorder->error_code;
1092 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1095 /* release sub context */
1096 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1097 hcamcorder->sub_context = NULL;
1098 goto _ERR_CAMCORDER_CMD;
1101 /* set command function */
1102 ret = _mmcamcorder_set_functions(handle, hcamcorder->type);
1103 if (ret != MM_ERROR_NONE) {
1104 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1105 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1106 hcamcorder->sub_context = NULL;
1107 goto _ERR_CAMCORDER_CMD;
1110 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1112 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1114 return MM_ERROR_NONE;
1117 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1118 /* release hw resources */
1119 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1120 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1121 if (hcamcorder->camera_resource != NULL) {
1122 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1123 hcamcorder->camera_resource);
1124 hcamcorder->camera_resource = NULL;
1126 if (hcamcorder->video_overlay_resource != NULL) {
1127 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1128 hcamcorder->video_overlay_resource);
1129 hcamcorder->video_overlay_resource = NULL;
1131 mm_resource_manager_commit(hcamcorder->resource_manager);
1133 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1134 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1135 #ifdef _MMCAMCORDER_RM_SUPPORT
1136 _mmcamcorder_rm_deallocate(handle);
1137 _mmcamcorder_rm_release(handle);
1138 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1140 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1141 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1143 _ERR_CAMCORDER_CMD_PRECON:
1144 MMCAM_LOG_ERROR("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1150 int _mmcamcorder_unrealize(MMHandleType handle)
1152 int ret = MM_ERROR_NONE;
1153 int state = MM_CAMCORDER_STATE_NONE;
1155 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1160 MMCAM_LOG_ERROR("Not initialized");
1161 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1165 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1166 MMCAM_LOG_ERROR("Another command is running.");
1167 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1168 goto _ERR_CAMCORDER_CMD_PRECON;
1171 state = _mmcamcorder_get_state(handle);
1172 if (state != MM_CAMCORDER_STATE_READY) {
1173 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1174 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1175 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1178 /* Release SubContext */
1179 if (hcamcorder->sub_context) {
1180 /* destroy pipeline */
1181 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1182 /* Deallocate SubContext */
1183 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1184 hcamcorder->sub_context = NULL;
1187 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1188 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1189 MMCAM_LOG_WARNING("lock resource - cb calling %d", hcamcorder->is_release_cb_calling);
1191 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE &&
1192 hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM &&
1193 hcamcorder->is_release_cb_calling == FALSE) {
1195 /* release resource */
1196 if (hcamcorder->camera_resource != NULL) {
1197 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1198 hcamcorder->camera_resource);
1199 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1200 MMCAM_LOG_ERROR("could not mark camera resource for release");
1201 ret = MM_ERROR_CAMCORDER_INTERNAL;
1202 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1203 MMCAM_LOG_INFO("unlock resource");
1204 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1208 if (hcamcorder->video_overlay_resource != NULL) {
1209 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1210 hcamcorder->video_overlay_resource);
1211 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1212 MMCAM_LOG_ERROR("could not mark overlay resource for release");
1213 ret = MM_ERROR_CAMCORDER_INTERNAL;
1214 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1215 MMCAM_LOG_INFO("unlock resource");
1216 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1220 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1222 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1223 MMCAM_LOG_ERROR("failed to release resource, ret(0x%x)", ret);
1224 ret = MM_ERROR_CAMCORDER_INTERNAL;
1226 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1227 MMCAM_LOG_INFO("unlock resource");
1229 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1231 if (hcamcorder->camera_resource != NULL)
1232 hcamcorder->camera_resource = NULL;
1233 if (hcamcorder->video_overlay_resource != NULL)
1234 hcamcorder->video_overlay_resource = NULL;
1238 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1240 MMCAM_LOG_WARNING("unlock resource");
1241 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1243 #ifdef _MMCAMCORDER_RM_SUPPORT
1244 _mmcamcorder_rm_deallocate(handle);
1245 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1247 /* Deinitialize main context member */
1248 hcamcorder->command = NULL;
1250 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1252 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
1254 return MM_ERROR_NONE;
1256 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1257 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1259 _ERR_CAMCORDER_CMD_PRECON:
1261 MMCAM_LOG_ERROR("Unrealize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1266 int _mmcamcorder_start(MMHandleType handle)
1268 int ret = MM_ERROR_NONE;
1269 int state = MM_CAMCORDER_STATE_NONE;
1271 _MMCamcorderSubContext *sc = NULL;
1272 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1277 MMCAM_LOG_ERROR("Not initialized");
1278 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1282 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1283 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1285 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1286 MMCAM_LOG_ERROR("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 != MM_CAMCORDER_STATE_READY) {
1293 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1294 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1295 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1298 /* initialize error code */
1299 hcamcorder->error_code = MM_ERROR_NONE;
1301 /* set attributes related sensor */
1302 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1303 _mmcamcorder_set_attribute_to_camsensor(handle);
1305 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1306 if (ret != MM_ERROR_NONE) {
1307 /* check internal error of gstreamer */
1308 if (hcamcorder->error_code != MM_ERROR_NONE) {
1309 ret = hcamcorder->error_code;
1310 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1312 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1315 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1317 /* set attributes related sensor - after start preview */
1318 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1319 _mmcamcorder_set_attribute_to_camsensor2(handle);
1321 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1323 return MM_ERROR_NONE;
1325 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1326 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1328 _ERR_CAMCORDER_CMD_PRECON:
1329 /* check internal error of gstreamer */
1330 if (hcamcorder->error_code != MM_ERROR_NONE) {
1331 ret = hcamcorder->error_code;
1332 hcamcorder->error_code = MM_ERROR_NONE;
1334 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1337 MMCAM_LOG_ERROR("Start fail (type %d, state %d, ret %x)",
1338 hcamcorder->type, state, ret);
1343 int _mmcamcorder_stop(MMHandleType handle)
1345 int ret = MM_ERROR_NONE;
1346 int state = MM_CAMCORDER_STATE_NONE;
1348 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1353 MMCAM_LOG_ERROR("Not initialized");
1354 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1358 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1359 MMCAM_LOG_ERROR("Another command is running.");
1360 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1361 goto _ERR_CAMCORDER_CMD_PRECON;
1364 state = _mmcamcorder_get_state(handle);
1365 if (state != MM_CAMCORDER_STATE_PREPARE) {
1366 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1367 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1368 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1371 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_STOP);
1372 if (ret != MM_ERROR_NONE)
1373 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1375 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1377 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1378 /* unsubscribe remained unsubscribed signal */
1379 g_mutex_lock(&hcamcorder->gdbus_info_sound.sync_mutex);
1380 if (hcamcorder->gdbus_info_sound.subscribe_id > 0) {
1381 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_sound.subscribe_id);
1382 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_sound.subscribe_id);
1384 g_mutex_unlock(&hcamcorder->gdbus_info_sound.sync_mutex);
1386 g_mutex_lock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1387 if (hcamcorder->gdbus_info_solo_sound.subscribe_id > 0) {
1388 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_solo_sound.subscribe_id);
1389 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_solo_sound.subscribe_id);
1391 g_mutex_unlock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1394 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1396 return MM_ERROR_NONE;
1398 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1399 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1401 _ERR_CAMCORDER_CMD_PRECON:
1403 MMCAM_LOG_ERROR("Stop fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1409 int _mmcamcorder_capture_start(MMHandleType handle)
1411 int ret = MM_ERROR_NONE;
1412 int state = MM_CAMCORDER_STATE_NONE;
1413 int state_FROM_0 = MM_CAMCORDER_STATE_PREPARE;
1414 int state_FROM_1 = MM_CAMCORDER_STATE_RECORDING;
1415 int state_FROM_2 = MM_CAMCORDER_STATE_PAUSED;
1417 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1422 MMCAM_LOG_ERROR("Not initialized");
1423 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1427 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1428 MMCAM_LOG_ERROR("Another command is running.");
1429 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1430 goto _ERR_CAMCORDER_CMD_PRECON;
1433 state = _mmcamcorder_get_state(handle);
1434 if (state != state_FROM_0 && state != state_FROM_1 && state != state_FROM_2) {
1435 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1436 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1437 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1440 /* Handle capture in recording case */
1441 if (state == state_FROM_1 || state == state_FROM_2) {
1442 if (hcamcorder->capture_in_recording == TRUE) {
1443 MMCAM_LOG_ERROR("Capturing in recording (%d)", state);
1444 ret = MM_ERROR_CAMCORDER_DEVICE_BUSY;
1445 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1447 g_mutex_lock(&hcamcorder->task_thread_lock);
1448 if (hcamcorder->task_thread_state == _MMCAMCORDER_TASK_THREAD_STATE_NONE) {
1449 hcamcorder->capture_in_recording = TRUE;
1450 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING;
1451 MMCAM_LOG_INFO("send signal for capture in recording");
1452 g_cond_signal(&hcamcorder->task_thread_cond);
1453 g_mutex_unlock(&hcamcorder->task_thread_lock);
1455 MMCAM_LOG_ERROR("task thread busy : %d", hcamcorder->task_thread_state);
1456 g_mutex_unlock(&hcamcorder->task_thread_lock);
1457 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1458 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1463 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CAPTURE);
1464 if (ret != MM_ERROR_NONE)
1465 goto _ERR_CAMCORDER_CMD;
1467 /* Do not change state when recording snapshot capture */
1468 if (state == state_FROM_0)
1469 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_CAPTURING);
1471 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1473 /* Init break continuous shot attr */
1474 if (mm_camcorder_set_attributes(handle, NULL, MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, 0, NULL) != MM_ERROR_NONE)
1475 MMCAM_LOG_WARNING("capture-break-cont-shot set 0 failed");
1477 return MM_ERROR_NONE;
1480 if (hcamcorder->capture_in_recording)
1481 hcamcorder->capture_in_recording = FALSE;
1483 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1484 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1486 _ERR_CAMCORDER_CMD_PRECON:
1488 MMCAM_LOG_ERROR("Capture start fail (type %d, state %d, ret %x)",
1489 hcamcorder->type, state, ret);
1494 int _mmcamcorder_capture_stop(MMHandleType handle)
1496 int ret = MM_ERROR_NONE;
1497 int state = MM_CAMCORDER_STATE_NONE;
1498 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1503 MMCAM_LOG_ERROR("Not initialized");
1504 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1508 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1509 MMCAM_LOG_ERROR("Another command is running.");
1510 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1511 goto _ERR_CAMCORDER_CMD_PRECON;
1514 state = _mmcamcorder_get_state(handle);
1515 if (state != MM_CAMCORDER_STATE_CAPTURING) {
1516 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1517 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1518 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1521 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1522 if (ret != MM_ERROR_NONE)
1523 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1525 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1527 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1529 return MM_ERROR_NONE;
1531 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1532 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1534 _ERR_CAMCORDER_CMD_PRECON:
1536 MMCAM_LOG_ERROR("Capture stop fail (type %d, state %d, ret %x)",
1537 hcamcorder->type, state, ret);
1542 int _mmcamcorder_record(MMHandleType handle)
1544 int ret = MM_ERROR_NONE;
1545 int state = MM_CAMCORDER_STATE_NONE;
1546 int dpm_mic_state = DPM_ALLOWED;
1548 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1549 _MMCamcorderSubContext *sc = NULL;
1553 if (!hcamcorder || !MMF_CAMCORDER_SUBCONTEXT(hcamcorder)) {
1554 MMCAM_LOG_ERROR("Not initialized");
1555 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1559 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1561 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1562 MMCAM_LOG_ERROR("Another command is running.");
1563 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1564 goto _ERR_CAMCORDER_CMD_PRECON;
1567 state = _mmcamcorder_get_state(handle);
1568 if (state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_PAUSED) {
1569 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1570 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1571 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1574 /* initialize error code */
1575 hcamcorder->error_code = MM_ERROR_NONE;
1577 /* get audio disable */
1578 mm_camcorder_get_attributes(handle, NULL,
1579 MMCAM_AUDIO_DISABLE, &sc->audio_disable,
1582 sc->audio_disable |= sc->is_modified_rate;
1584 /* check mic policy from DPM */
1585 if (hcamcorder->dpm_handle && sc->audio_disable == FALSE) {
1586 if (dpm_restriction_get_microphone_state(hcamcorder->dpm_handle, &dpm_mic_state) == DPM_ERROR_NONE) {
1587 MMCAM_LOG_INFO("DPM mic state %d", dpm_mic_state);
1588 if (dpm_mic_state == DPM_DISALLOWED) {
1589 MMCAM_LOG_ERROR("MIC DISALLOWED by DPM");
1590 ret = MM_ERROR_COMMON_INVALID_PERMISSION;
1592 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
1594 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1597 MMCAM_LOG_ERROR("get DPM mic state failed, keep going...");
1600 MMCAM_LOG_WARNING("skip dpm check - handle %p, audio disable %d",
1601 hcamcorder->dpm_handle, sc->audio_disable);
1604 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_RECORD);
1605 if (ret != MM_ERROR_NONE) {
1606 /* check internal error of gstreamer */
1607 if (hcamcorder->error_code != MM_ERROR_NONE) {
1608 ret = hcamcorder->error_code;
1609 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1611 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1614 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_RECORDING);
1616 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1618 return MM_ERROR_NONE;
1620 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1621 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1623 _ERR_CAMCORDER_CMD_PRECON:
1624 /* check internal error of gstreamer */
1625 if (hcamcorder->error_code != MM_ERROR_NONE) {
1626 ret = hcamcorder->error_code;
1627 hcamcorder->error_code = MM_ERROR_NONE;
1629 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1632 MMCAM_LOG_ERROR("Record fail (type %d, state %d, ret %x)",
1633 hcamcorder->type, state, ret);
1639 int _mmcamcorder_pause(MMHandleType handle)
1641 int ret = MM_ERROR_NONE;
1642 int state = MM_CAMCORDER_STATE_NONE;
1644 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1649 MMCAM_LOG_ERROR("Not initialized");
1650 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1654 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1655 MMCAM_LOG_ERROR("Another command is running.");
1656 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1657 goto _ERR_CAMCORDER_CMD_PRECON;
1660 state = _mmcamcorder_get_state(handle);
1661 if (state != MM_CAMCORDER_STATE_RECORDING) {
1662 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1663 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1664 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1667 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PAUSE);
1668 if (ret != MM_ERROR_NONE)
1669 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1671 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PAUSED);
1673 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1675 return MM_ERROR_NONE;
1677 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1678 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1680 _ERR_CAMCORDER_CMD_PRECON:
1682 MMCAM_LOG_ERROR("Pause fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1688 int _mmcamcorder_commit(MMHandleType handle)
1690 int ret = MM_ERROR_NONE;
1691 int state = MM_CAMCORDER_STATE_NONE;
1693 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1698 MMCAM_LOG_ERROR("Not initialized");
1699 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1703 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1704 MMCAM_LOG_ERROR("Another command is running.");
1705 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1706 goto _ERR_CAMCORDER_CMD_PRECON;
1709 state = _mmcamcorder_get_state(handle);
1710 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1711 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1712 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1713 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1716 /* initialize error code */
1717 hcamcorder->error_code = MM_ERROR_NONE;
1719 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_COMMIT);
1720 if (ret != MM_ERROR_NONE)
1721 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1723 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1725 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1727 return MM_ERROR_NONE;
1729 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1730 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1732 _ERR_CAMCORDER_CMD_PRECON:
1734 MMCAM_LOG_ERROR("Commit fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1740 int _mmcamcorder_cancel(MMHandleType handle)
1742 int ret = MM_ERROR_NONE;
1743 int state = MM_CAMCORDER_STATE_NONE;
1745 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1750 MMCAM_LOG_ERROR("Not initialized");
1751 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1755 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1756 MMCAM_LOG_ERROR("Another command is running.");
1757 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1758 goto _ERR_CAMCORDER_CMD_PRECON;
1761 state = _mmcamcorder_get_state(handle);
1762 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1763 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1764 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1765 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1768 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CANCEL);
1769 if (ret != MM_ERROR_NONE)
1770 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1772 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1774 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1776 return MM_ERROR_NONE;
1778 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1779 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1781 _ERR_CAMCORDER_CMD_PRECON:
1783 MMCAM_LOG_ERROR("Cancel fail (type %d, state %d, ret %x)",
1784 hcamcorder->type, state, ret);
1788 /* } Internal command functions */
1791 int _mmcamcorder_commit_async_end(MMHandleType handle)
1795 MMCAM_LOG_WARNING("_mmcamcorder_commit_async_end : MM_CAMCORDER_STATE_PREPARE");
1796 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1798 return MM_ERROR_NONE;
1802 int _mmcamcorder_set_message_callback(MMHandleType handle, MMMessageCallback callback, void *user_data)
1804 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1806 MMCAM_LOG_INFO("%p", hcamcorder);
1808 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1810 if (callback == NULL)
1811 MMCAM_LOG_WARNING("Message Callback is disabled, because application sets it to NULL");
1813 if (!_MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(hcamcorder)) {
1814 MMCAM_LOG_WARNING("Application's message callback is running now");
1815 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1818 /* set message callback to message handle */
1819 hcamcorder->msg_cb = callback;
1820 hcamcorder->msg_cb_param = user_data;
1822 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1824 return MM_ERROR_NONE;
1828 int _mmcamcorder_set_video_stream_callback(MMHandleType handle, mm_camcorder_video_stream_callback callback, void *user_data)
1830 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1832 /*MMCAM_LOG_INFO("");*/
1834 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1836 if (callback == NULL)
1837 MMCAM_LOG_WARNING("Video Stream Callback is disabled, because application sets it to NULL");
1839 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
1841 hcamcorder->vstream_cb = callback;
1842 hcamcorder->vstream_cb_param = user_data;
1844 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1846 return MM_ERROR_NONE;
1850 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle, mm_camcorder_audio_stream_callback callback, void *user_data)
1852 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1856 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1858 if (callback == NULL)
1859 MMCAM_LOG_WARNING("Audio Stream Callback is disabled, because application sets it to NULL");
1861 if (!_MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(hcamcorder)) {
1862 MMCAM_LOG_WARNING("Application's audio stream callback is running now");
1863 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1866 hcamcorder->astream_cb = callback;
1867 hcamcorder->astream_cb_param = user_data;
1869 _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder);
1871 return MM_ERROR_NONE;
1875 int _mmcamcorder_set_muxed_stream_callback(MMHandleType handle, mm_camcorder_muxed_stream_callback callback, void *user_data)
1877 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1881 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1883 if (callback == NULL)
1884 MMCAM_LOG_WARNING("Muxed Stream Callback is disabled, because application sets it to NULL");
1886 if (!_MMCAMCORDER_TRYLOCK_MSTREAM_CALLBACK(hcamcorder)) {
1887 MMCAM_LOG_WARNING("Application's muxed stream callback is running now");
1888 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1891 hcamcorder->mstream_cb = callback;
1892 hcamcorder->mstream_cb_param = user_data;
1894 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
1896 return MM_ERROR_NONE;
1900 int _mmcamcorder_set_video_capture_callback(MMHandleType handle, mm_camcorder_video_capture_callback callback, void *user_data)
1902 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1906 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1908 if (callback == NULL)
1909 MMCAM_LOG_WARNING("Video Capture Callback is disabled, because application sets it to NULLL");
1911 if (!_MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(hcamcorder)) {
1912 MMCAM_LOG_WARNING("Application's video capture callback is running now");
1913 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1916 hcamcorder->vcapture_cb = callback;
1917 hcamcorder->vcapture_cb_param = user_data;
1919 _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(hcamcorder);
1921 return MM_ERROR_NONE;
1925 int _mmcamcorder_set_video_encode_decision_callback(MMHandleType handle, mm_camcorder_video_encode_decision_callback callback, void *user_data)
1927 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1931 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1933 if (callback == NULL)
1934 MMCAM_LOG_WARNING("Video Encode Decision Callback is disabled, because application sets it to NULL");
1936 if (!_MMCAMCORDER_TRYLOCK_VEDECISION_CALLBACK(hcamcorder)) {
1937 MMCAM_LOG_WARNING("Application's video encode decision callback is running now");
1938 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1941 hcamcorder->vedecision_cb = callback;
1942 hcamcorder->vedecision_cb_param = user_data;
1944 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
1946 return MM_ERROR_NONE;
1950 int _mmcamcorder_get_current_state(MMHandleType handle)
1952 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1956 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1958 return _mmcamcorder_get_state(handle);
1961 int _mmcamcorder_init_focusing(MMHandleType handle)
1964 int state = MM_CAMCORDER_STATE_NONE;
1965 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
1966 int af_range = MM_CAMCORDER_AUTO_FOCUS_NORMAL;
1967 int sensor_focus_mode = 0;
1968 int sensor_af_range = 0;
1969 int current_focus_mode = 0;
1970 int current_af_range = 0;
1971 mmf_camcorder_t *hcamcorder = NULL;
1972 _MMCamcorderSubContext *sc = NULL;
1973 GstCameraControl *control = NULL;
1977 hcamcorder = MMF_CAMCORDER(handle);
1978 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1980 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
1981 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1983 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1984 MMCAM_LOG_ERROR("Another command is running.");
1985 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1988 state = _mmcamcorder_get_state(handle);
1990 if (state == MM_CAMCORDER_STATE_CAPTURING ||
1991 state < MM_CAMCORDER_STATE_PREPARE) {
1992 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
1993 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1994 return MM_ERROR_CAMCORDER_INVALID_STATE;
1997 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
1998 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
1999 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2000 return MM_ERROR_NONE;
2003 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2004 if (control == NULL) {
2005 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2006 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2007 return MM_ERROR_CAMCORDER_INTERNAL;
2010 ret = gst_camera_control_stop_auto_focus(control);
2012 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2013 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2014 return MM_ERROR_CAMCORDER_DEVICE_IO;
2017 /* Initialize lens position */
2018 mm_camcorder_get_attributes(handle, NULL,
2019 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2020 MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
2022 sensor_af_range = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_AF_SCAN_RANGE, af_range);
2023 sensor_focus_mode = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_FOCUS_MODE, focus_mode);
2025 gst_camera_control_get_focus(control, ¤t_focus_mode, ¤t_af_range);
2027 if (current_focus_mode != sensor_focus_mode || current_af_range != sensor_af_range) {
2028 ret = gst_camera_control_set_focus(control, sensor_focus_mode, sensor_af_range);
2030 MMCAM_LOG_INFO("No need to init FOCUS [mode:%d, range:%d]", focus_mode, af_range);
2034 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2037 MMCAM_LOG_INFO("Lens init success.");
2038 return MM_ERROR_NONE;
2040 MMCAM_LOG_ERROR("Lens init fail.");
2041 return MM_ERROR_CAMCORDER_DEVICE_IO;
2045 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction)
2048 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2049 int ret = MM_ERROR_UNKNOWN;
2050 char *err_attr_name = NULL;
2052 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2053 mmf_return_val_if_fail(direction, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2055 /*MMCAM_LOG_INFO("");*/
2057 if (!_MMCAMCORDER_TRYLOCK_CMD(handle)) {
2058 MMCAM_LOG_ERROR("Another command is running.");
2059 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2062 state = _mmcamcorder_get_state(handle);
2063 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2064 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2065 _MMCAMCORDER_UNLOCK_CMD(handle);
2066 return MM_ERROR_CAMCORDER_INVALID_STATE;
2069 /* TODO : call a auto or manual focus function */
2070 ret = mm_camcorder_get_attributes(handle, &err_attr_name,
2071 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2073 if (ret != MM_ERROR_NONE) {
2074 MMCAM_LOG_WARNING("Get focus-mode fail. (%s:%x)", err_attr_name, ret);
2075 SAFE_FREE(err_attr_name);
2076 _MMCAMCORDER_UNLOCK_CMD(handle);
2080 switch (focus_mode) {
2081 case MM_CAMCORDER_FOCUS_MODE_MANUAL:
2082 ret = _mmcamcorder_adjust_manual_focus(handle, direction);
2084 case MM_CAMCORDER_FOCUS_MODE_AUTO:
2085 case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
2086 case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
2087 ret = _mmcamcorder_adjust_auto_focus(handle);
2090 MMCAM_LOG_ERROR("It doesn't adjust focus. Focusing mode(%d)", focus_mode);
2091 ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2094 _MMCAMCORDER_UNLOCK_CMD(handle);
2099 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction)
2104 int focus_level = 0;
2105 float unit_level = 0;
2106 GstCameraControl *control = NULL;
2107 _MMCamcorderSubContext *sc = NULL;
2108 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2112 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2113 mmf_return_val_if_fail(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL != 1, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
2114 mmf_return_val_if_fail((direction >= MM_CAMCORDER_MF_LENS_DIR_FORWARD) &&
2115 (direction <= MM_CAMCORDER_MF_LENS_DIR_BACKWARD),
2116 MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2118 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2119 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2121 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2122 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2123 return MM_ERROR_NONE;
2126 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2127 if (control == NULL) {
2128 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2129 return MM_ERROR_CAMCORDER_INTERNAL;
2132 /* TODO : get max, min level */
2133 if (max_level - min_level + 1 < _MMFCAMCORDER_FOCUS_TOTAL_LEVEL)
2134 MMCAM_LOG_WARNING("Total level of manual focus of MMF is greater than that of the camera driver.");
2136 unit_level = ((float)max_level - (float)min_level)/(float)(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL - 1);
2138 if (!gst_camera_control_get_focus_level(control, &cur_level)) {
2139 MMCAM_LOG_ERROR("Can't get current level of manual focus.");
2140 return MM_ERROR_CAMCORDER_DEVICE_IO;
2143 /* TODO : adjust unit level value */
2144 if (direction == MM_CAMCORDER_MF_LENS_DIR_FORWARD)
2145 focus_level = cur_level + unit_level;
2146 else if (direction == MM_CAMCORDER_MF_LENS_DIR_BACKWARD)
2147 focus_level = cur_level - unit_level;
2149 if (focus_level > max_level)
2150 focus_level = max_level;
2151 else if (focus_level < min_level)
2152 focus_level = min_level;
2154 if (!gst_camera_control_set_focus_level(control, focus_level)) {
2155 MMCAM_LOG_ERROR("Manual focusing fail.");
2156 return MM_ERROR_CAMCORDER_DEVICE_IO;
2159 return MM_ERROR_NONE;
2163 int _mmcamcorder_adjust_auto_focus(MMHandleType handle)
2166 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2167 GstCameraControl *control = NULL;
2168 _MMCamcorderSubContext *sc = NULL;
2170 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2172 /*MMCAM_LOG_INFO("");*/
2174 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2176 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2177 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2178 return MM_ERROR_NONE;
2181 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2184 ret = gst_camera_control_start_auto_focus(control);
2186 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2191 MMCAM_LOG_INFO("Auto focusing start success.");
2192 return MM_ERROR_NONE;
2194 MMCAM_LOG_ERROR("Auto focusing start fail.");
2195 return MM_ERROR_CAMCORDER_DEVICE_IO;
2199 int _mmcamcorder_stop_focusing(MMHandleType handle)
2201 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2202 _MMCamcorderSubContext *sc = NULL;
2205 GstCameraControl *control = NULL;
2207 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2209 /*MMCAM_LOG_INFO("");*/
2211 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2213 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2214 MMCAM_LOG_ERROR("Another command is running.");
2215 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2218 state = _mmcamcorder_get_state(handle);
2219 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2220 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2221 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2222 return MM_ERROR_CAMCORDER_INVALID_STATE;
2225 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2226 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2227 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2228 return MM_ERROR_NONE;
2231 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2233 ret = gst_camera_control_stop_auto_focus(control);
2235 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2239 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2242 MMCAM_LOG_INFO("Auto focusing stop success.");
2243 return MM_ERROR_NONE;
2245 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2246 return MM_ERROR_CAMCORDER_DEVICE_IO;
2251 /*-----------------------------------------------
2252 | CAMCORDER INTERNAL LOCAL |
2253 -----------------------------------------------*/
2254 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf)
2256 static const int max_argc = 10;
2260 gchar **argv = NULL;
2262 gboolean ret = FALSE;
2263 type_string_array *GSTInitOption = NULL;
2265 mmf_return_val_if_fail(conf, FALSE);
2270 argc = malloc(sizeof(int));
2271 argv = malloc(sizeof(gchar *) * max_argc);
2276 memset(argv, 0, sizeof(gchar *) * max_argc);
2280 argv[0] = g_strdup("mmcamcorder");
2283 _mmcamcorder_conf_get_value_string_array(conf,
2284 CONFIGURE_CATEGORY_MAIN_GENERAL,
2287 if (GSTInitOption != NULL && GSTInitOption->value) {
2288 cnt_str = GSTInitOption->count;
2289 for ( ; *argc < max_argc && *argc <= cnt_str ; (*argc)++)
2290 argv[*argc] = g_strdup(GSTInitOption->value[(*argc)-1]);
2293 MMCAM_LOG_INFO("initializing gstreamer with following parameter[argc:%d]", *argc);
2295 for (i = 0; i < *argc; i++)
2296 MMCAM_LOG_INFO("argv[%d] : %s", i, argv[i]);
2298 /* initializing gstreamer */
2299 ret = gst_init_check(argc, &argv, &err);
2301 MMCAM_LOG_ERROR("Could not initialize GStreamer: %s ", err ? err->message : "unknown error occurred");
2307 for (i = 0; i < *argc; i++) {
2327 MMCAM_LOG_ERROR("failed to initialize gstreamer");
2343 int _mmcamcorder_get_state(MMHandleType handle)
2346 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2348 mmf_return_val_if_fail(hcamcorder, -1);
2350 _MMCAMCORDER_LOCK_STATE(handle);
2352 state = hcamcorder->state;
2353 /*MMCAM_LOG_INFO("state=%d",state);*/
2355 _MMCAMCORDER_UNLOCK_STATE(handle);
2361 int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state)
2363 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2365 mmf_return_val_if_fail(hcamcorder && state && old_state, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2367 _MMCAMCORDER_LOCK_STATE(handle);
2369 *state = hcamcorder->state;
2370 *old_state = hcamcorder->old_state;
2372 _MMCAMCORDER_UNLOCK_STATE(handle);
2374 return MM_ERROR_NONE;
2378 void _mmcamcorder_set_state(MMHandleType handle, int state)
2381 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2382 _MMCamcorderMsgItem msg;
2384 mmf_return_if_fail(hcamcorder);
2386 /*MMCAM_LOG_INFO("");*/
2388 _MMCAMCORDER_LOCK_STATE(handle);
2390 old_state = hcamcorder->state;
2391 if (old_state != state) {
2392 hcamcorder->state = state;
2393 hcamcorder->old_state = old_state;
2395 MMCAM_LOG_INFO("set state[%d -> %d] and send state-changed message", old_state, state);
2397 /* To discern who changes the state */
2398 switch (hcamcorder->state_change_by_system) {
2399 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
2400 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_RM;
2401 msg.param.state.code = MM_ERROR_NONE;
2403 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
2404 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY;
2405 msg.param.state.code = MM_ERROR_NONE;
2407 case _MMCAMCORDER_STATE_CHANGE_NORMAL:
2409 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED;
2410 msg.param.state.code = MM_ERROR_NONE;
2414 msg.param.state.previous = old_state;
2415 msg.param.state.current = state;
2417 /*MMCAM_LOG_INFO("_mmcamcorder_send_message : msg : %p, id:%x", &msg, msg.id);*/
2418 _mmcamcorder_send_message(handle, &msg);
2421 _MMCAMCORDER_UNLOCK_STATE(handle);
2427 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
2430 _MMCamcorderSubContext *sc = NULL;
2432 /*MMCAM_LOG_INFO("");*/
2434 /* alloc container */
2435 sc = (_MMCamcorderSubContext *)g_malloc0(sizeof(_MMCamcorderSubContext));
2437 sc->element_num = _MMCAMCORDER_PIPELINE_ELEMENT_NUM;
2438 sc->encode_element_num = _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM;
2440 /* alloc info for each mode */
2442 case MM_CAMCORDER_MODE_AUDIO:
2443 sc->info_audio = g_malloc0(sizeof(_MMCamcorderAudioInfo));
2445 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2447 sc->info_image = g_malloc0(sizeof(_MMCamcorderImageInfo));
2448 sc->info_video = g_malloc0(sizeof(_MMCamcorderVideoInfo));
2450 sc->info_image->sound_status = _SOUND_STATUS_INIT;
2451 g_mutex_init(&sc->info_video->size_check_lock);
2455 /* alloc element array */
2456 sc->element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->element_num);
2457 sc->encode_element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->encode_element_num);
2459 for (i = 0 ; i < sc->element_num ; i++) {
2460 sc->element[i].id = _MMCAMCORDER_NONE;
2461 sc->element[i].gst = NULL;
2464 for (i = 0 ; i < sc->encode_element_num ; i++) {
2465 sc->encode_element[i].id = _MMCAMCORDER_NONE;
2466 sc->encode_element[i].gst = NULL;
2469 sc->fourcc = 0x80000000;
2470 sc->frame_stability_count = 0;
2471 sc->drop_vframe = 0;
2472 sc->pass_first_vframe = 0;
2473 sc->is_modified_rate = FALSE;
2479 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
2485 MMCAM_LOG_INFO("release element");
2486 g_free(sc->element);
2490 if (sc->encode_element) {
2491 MMCAM_LOG_INFO("release encode_element");
2492 g_free(sc->encode_element);
2493 sc->encode_element = NULL;
2496 if (sc->info_image) {
2497 MMCAM_LOG_INFO("release info_image");
2498 g_free(sc->info_image);
2499 sc->info_image = NULL;
2502 if (sc->info_video) {
2503 MMCAM_LOG_INFO("release info_video");
2504 SAFE_G_FREE(sc->info_video->filename);
2505 g_mutex_clear(&sc->info_video->size_check_lock);
2506 g_free(sc->info_video);
2507 sc->info_video = NULL;
2510 if (sc->info_audio) {
2511 MMCAM_LOG_INFO("release info_audio");
2512 SAFE_G_FREE(sc->info_audio->filename);
2513 g_free(sc->info_audio);
2514 sc->info_audio = NULL;
2525 int _mmcamcorder_set_functions(MMHandleType handle, int type)
2527 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2529 /*MMCAM_LOG_INFO("");*/
2532 case MM_CAMCORDER_MODE_AUDIO:
2533 hcamcorder->command = _mmcamcorder_audio_command;
2535 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2537 hcamcorder->command = _mmcamcorder_video_capture_command;
2541 return MM_ERROR_NONE;
2545 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data)
2547 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2548 _MMCamcorderSubContext *sc = NULL;
2550 mmf_return_val_if_fail(hcamcorder, FALSE);
2551 mmf_return_val_if_fail(message, FALSE);
2552 /* MMCAM_LOG_INFO("message type=(%d)", GST_MESSAGE_TYPE(message)); */
2554 switch (GST_MESSAGE_TYPE(message)) {
2555 case GST_MESSAGE_UNKNOWN:
2556 MMCAM_LOG_INFO("GST_MESSAGE_UNKNOWN");
2558 case GST_MESSAGE_EOS:
2560 MMCAM_LOG_ERROR("Got EOS from element \"%s\"... but should not be reached here!",
2561 GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));
2564 case GST_MESSAGE_ERROR:
2567 gchar *debug = NULL;
2569 gst_message_parse_error(message, &err, &debug);
2571 __mmcamcorder_handle_gst_error((MMHandleType)hcamcorder, message, err);
2574 MMCAM_LOG_ERROR("GSTERR: %s", err->message);
2580 MMCAM_LOG_ERROR("Error Debug: %s", debug);
2586 case GST_MESSAGE_WARNING:
2590 gst_message_parse_warning(message, &err, &debug);
2592 MMCAM_LOG_WARNING("GSTWARN: %s", err->message);
2594 __mmcamcorder_handle_gst_warning((MMHandleType)hcamcorder, message, err);
2600 case GST_MESSAGE_INFO:
2601 MMCAM_LOG_INFO("GST_MESSAGE_INFO");
2603 case GST_MESSAGE_TAG:
2604 MMCAM_LOG_INFO("GST_MESSAGE_TAG");
2606 case GST_MESSAGE_BUFFERING:
2607 MMCAM_LOG_INFO("GST_MESSAGE_BUFFERING");
2609 case GST_MESSAGE_STATE_CHANGED:
2611 const GValue *vnewstate;
2613 GstElement *pipeline = NULL;
2615 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2616 if ((sc) && (sc->element)) {
2617 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst) {
2618 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
2619 if (message->src == (GstObject*)pipeline) {
2620 vnewstate = gst_structure_get_value(gst_message_get_structure(message), "new-state");
2622 newstate = (GstState)vnewstate->data[0].v_int;
2623 MMCAM_LOG_INFO("GST_MESSAGE_STATE_CHANGED[%s]", gst_element_state_get_name(newstate));
2625 MMCAM_LOG_WARNING("get new state failed from msg");
2632 case GST_MESSAGE_STATE_DIRTY:
2633 MMCAM_LOG_INFO("GST_MESSAGE_STATE_DIRTY");
2635 case GST_MESSAGE_STEP_DONE:
2636 MMCAM_LOG_INFO("GST_MESSAGE_STEP_DONE");
2638 case GST_MESSAGE_CLOCK_PROVIDE:
2639 MMCAM_LOG_INFO("GST_MESSAGE_CLOCK_PROVIDE");
2641 case GST_MESSAGE_CLOCK_LOST:
2642 MMCAM_LOG_INFO("GST_MESSAGE_CLOCK_LOST");
2644 case GST_MESSAGE_NEW_CLOCK:
2646 GstClock *pipe_clock = NULL;
2647 gst_message_parse_new_clock(message, &pipe_clock);
2648 /*MMCAM_LOG_INFO("GST_MESSAGE_NEW_CLOCK : %s", (clock ? GST_OBJECT_NAME (clock) : "NULL"));*/
2651 case GST_MESSAGE_STRUCTURE_CHANGE:
2652 MMCAM_LOG_INFO("GST_MESSAGE_STRUCTURE_CHANGE");
2654 case GST_MESSAGE_STREAM_STATUS:
2655 /*MMCAM_LOG_INFO("GST_MESSAGE_STREAM_STATUS");*/
2657 case GST_MESSAGE_APPLICATION:
2658 MMCAM_LOG_INFO("GST_MESSAGE_APPLICATION");
2660 case GST_MESSAGE_ELEMENT:
2661 /*MMCAM_LOG_INFO("GST_MESSAGE_ELEMENT");*/
2663 case GST_MESSAGE_SEGMENT_START:
2664 MMCAM_LOG_INFO("GST_MESSAGE_SEGMENT_START");
2666 case GST_MESSAGE_SEGMENT_DONE:
2667 MMCAM_LOG_INFO("GST_MESSAGE_SEGMENT_DONE");
2669 case GST_MESSAGE_DURATION_CHANGED:
2670 MMCAM_LOG_INFO("GST_MESSAGE_DURATION_CHANGED");
2672 case GST_MESSAGE_LATENCY:
2673 MMCAM_LOG_INFO("GST_MESSAGE_LATENCY");
2675 case GST_MESSAGE_ASYNC_START:
2676 MMCAM_LOG_INFO("GST_MESSAGE_ASYNC_START");
2678 case GST_MESSAGE_ASYNC_DONE:
2679 /*MMCAM_LOG_INFO("GST_MESSAGE_ASYNC_DONE");*/
2681 case GST_MESSAGE_ANY:
2682 MMCAM_LOG_INFO("GST_MESSAGE_ANY");
2684 case GST_MESSAGE_QOS:
2685 /* MMCAM_LOG_INFO("GST_MESSAGE_QOS"); */
2688 MMCAM_LOG_INFO("not handled message type=(%d)", GST_MESSAGE_TYPE(message));
2696 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
2698 GstElement *element = NULL;
2700 gchar *debug_info = NULL;
2702 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2703 _MMCamcorderSubContext *sc = NULL;
2705 mmf_return_val_if_fail(hcamcorder, GST_BUS_PASS);
2706 mmf_return_val_if_fail(message, GST_BUS_PASS);
2708 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2709 mmf_return_val_if_fail(sc, GST_BUS_PASS);
2711 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
2712 /* parse error message */
2713 gst_message_parse_error(message, &err, &debug_info);
2716 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
2722 MMCAM_LOG_WARNING("failed to parse error message");
2723 return GST_BUS_PASS;
2726 /* set videosrc element to compare */
2727 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2729 /* check domain[RESOURCE] and element[VIDEOSRC] */
2730 if (err->domain == GST_RESOURCE_ERROR && GST_ELEMENT_CAST(message->src) == element) {
2731 switch (err->code) {
2732 case GST_RESOURCE_ERROR_BUSY:
2733 MMCAM_LOG_ERROR("Camera device [busy]");
2734 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_BUSY;
2736 case GST_RESOURCE_ERROR_OPEN_WRITE:
2737 MMCAM_LOG_ERROR("Camera device [open failed]");
2738 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2739 /* sc->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN; // SECURITY PART REQUEST PRIVILEGE */
2741 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2742 MMCAM_LOG_ERROR("Camera device [open failed]");
2743 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN;
2745 case GST_RESOURCE_ERROR_OPEN_READ:
2746 MMCAM_LOG_ERROR("Camera device [register trouble]");
2747 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE;
2749 case GST_RESOURCE_ERROR_NOT_FOUND:
2750 MMCAM_LOG_ERROR("Camera device [device not found]");
2751 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND;
2753 case GST_RESOURCE_ERROR_TOO_LAZY:
2754 MMCAM_LOG_ERROR("Camera device [timeout]");
2755 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_TIMEOUT;
2757 case GST_RESOURCE_ERROR_SETTINGS:
2758 MMCAM_LOG_ERROR("Camera device [not supported]");
2759 hcamcorder->error_code = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2761 case GST_RESOURCE_ERROR_FAILED:
2762 MMCAM_LOG_ERROR("Camera device [working failed].");
2763 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_IO;
2766 MMCAM_LOG_ERROR("Camera device [General(%d)]", err->code);
2767 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE;
2771 hcamcorder->error_occurs = TRUE;
2776 /* store error code and drop this message if cmd is running */
2777 if (hcamcorder->error_code != MM_ERROR_NONE) {
2778 _MMCamcorderMsgItem msg;
2780 /* post error to application */
2781 hcamcorder->error_occurs = TRUE;
2782 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2783 msg.param.code = hcamcorder->error_code;
2784 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2788 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
2789 _MMCamcorderMsgItem msg;
2791 if (gst_structure_has_name(gst_message_get_structure(message), "avsysvideosrc-AF") ||
2792 gst_structure_has_name(gst_message_get_structure(message), "camerasrc-AF")) {
2793 int focus_state = 0;
2795 gst_structure_get_int(gst_message_get_structure(message), "focus-state", &focus_state);
2796 MMCAM_LOG_INFO("Focus State:%d", focus_state);
2798 msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED;
2799 msg.param.code = focus_state;
2800 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2803 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) {
2807 if (gst_structure_get_int(gst_message_get_structure(message), "progress", &progress)) {
2808 gst_structure_get_int(gst_message_get_structure(message), "status", &status);
2809 MMCAM_LOG_INFO("HDR progress %d percent, status %d", progress, status);
2811 msg.id = MM_MESSAGE_CAMCORDER_HDR_PROGRESS;
2812 msg.param.code = progress;
2813 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2817 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) {
2819 const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");;
2820 GstCameraControlFaceDetectInfo *fd_info = NULL;
2821 MMCamFaceDetectInfo *cam_fd_info = NULL;
2824 fd_info = (GstCameraControlFaceDetectInfo *)g_value_get_pointer(g_value);
2826 if (fd_info == NULL) {
2827 MMCAM_LOG_WARNING("fd_info is NULL");
2831 cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
2833 /* set total face count */
2834 cam_fd_info->num_of_faces = fd_info->num_of_faces;
2836 if (cam_fd_info->num_of_faces > 0) {
2837 cam_fd_info->face_info = (MMCamFaceInfo *)g_malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
2838 MMCAM_LOG_DEBUG("face detection - count %d", cam_fd_info->num_of_faces);
2839 /* set information of each face */
2840 for (i = 0 ; i < cam_fd_info->num_of_faces ; i++) {
2841 cam_fd_info->face_info[i].id = fd_info->face_info[i].id;
2842 cam_fd_info->face_info[i].score = fd_info->face_info[i].score;
2843 cam_fd_info->face_info[i].rect.x = fd_info->face_info[i].rect.x;
2844 cam_fd_info->face_info[i].rect.y = fd_info->face_info[i].rect.y;
2845 cam_fd_info->face_info[i].rect.width = fd_info->face_info[i].rect.width;
2846 cam_fd_info->face_info[i].rect.height = fd_info->face_info[i].rect.height;
2848 MMCAM_LOG_VERBOSE(" [%d] id %d, score %d, [%d,%d,%dx%d]",
2849 i, fd_info->face_info[i].id,
2850 fd_info->face_info[i].score,
2851 fd_info->face_info[i].rect.x,
2852 fd_info->face_info[i].rect.y,
2853 fd_info->face_info[i].rect.width,
2854 fd_info->face_info[i].rect.height);
2857 cam_fd_info->face_info = NULL;
2860 /* send message - cam_fd_info should be freed by application */
2861 msg.id = MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO;
2862 msg.param.data = cam_fd_info;
2863 msg.param.size = sizeof(MMCamFaceDetectInfo);
2866 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2868 /* free fd_info allocated by plugin */
2873 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-Capture")) {
2874 int capture_done = FALSE;
2876 if (gst_structure_get_int(gst_message_get_structure(message), "capture-done", &capture_done)) {
2877 if (sc->info_image) {
2878 /* play capture sound */
2879 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE01, FALSE);
2887 return GST_BUS_PASS;
2890 gst_message_unref(message);
2892 return GST_BUS_DROP;
2896 static GstBusSyncReply __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code)
2898 _MMCamcorderMsgItem msg;
2901 MMCAM_LOG_ERROR("NULL handle");
2902 return GST_BUS_PASS;
2906 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2907 case GST_RESOURCE_ERROR_OPEN_WRITE:
2908 MMCAM_LOG_ERROR("audio device [open failed]");
2910 /* post error to application */
2911 hcamcorder->error_occurs = TRUE;
2912 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2914 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2915 msg.param.code = hcamcorder->error_code;
2917 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2919 MMCAM_LOG_ERROR("error : sc->error_occurs %d", hcamcorder->error_occurs);
2921 return GST_BUS_DROP;
2926 return GST_BUS_PASS;
2930 static GstBusSyncReply __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code)
2932 gboolean b_committing = FALSE;
2933 storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE;
2934 _MMCamcorderMsgItem msg;
2935 _MMCamcorderSubContext *sc = NULL;
2938 MMCAM_LOG_ERROR("NULL handle");
2939 return GST_BUS_PASS;
2942 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2943 mmf_return_val_if_fail(sc, GST_BUS_PASS);
2945 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2946 mmf_return_val_if_fail(sc->info_video, GST_BUS_PASS);
2947 b_committing = sc->info_video->b_committing;
2949 mmf_return_val_if_fail(sc->info_audio, GST_BUS_PASS);
2950 b_committing = sc->info_audio->b_committing;
2953 _MMCAMCORDER_LOCK(hcamcorder);
2956 case GST_RESOURCE_ERROR_WRITE:
2957 storage_get_state(hcamcorder->storage_info.id, &storage_state);
2958 if (storage_state == STORAGE_STATE_REMOVED ||
2959 storage_state == STORAGE_STATE_UNMOUNTABLE) {
2960 MMCAM_LOG_ERROR("storage was removed! [storage state %d]", storage_state);
2961 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2963 MMCAM_LOG_ERROR("File write error, storage state %d", storage_state);
2964 hcamcorder->error_code = MM_ERROR_FILE_WRITE;
2967 if (sc->ferror_send == FALSE) {
2968 sc->ferror_send = TRUE;
2970 MMCAM_LOG_ERROR("error was already sent");
2971 _MMCAMCORDER_UNLOCK(hcamcorder);
2972 return GST_BUS_DROP;
2975 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
2976 MMCAM_LOG_ERROR("No left space");
2977 hcamcorder->error_code = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
2979 case GST_RESOURCE_ERROR_OPEN_WRITE:
2980 MMCAM_LOG_ERROR("Out of storage");
2981 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2983 case GST_RESOURCE_ERROR_SEEK:
2984 MMCAM_LOG_ERROR("File read(seek)");
2985 hcamcorder->error_code = MM_ERROR_FILE_READ;
2988 MMCAM_LOG_ERROR("Resource error(%d)", err_code);
2989 hcamcorder->error_code = MM_ERROR_CAMCORDER_GST_RESOURCE;
2994 _MMCAMCORDER_SIGNAL(hcamcorder);
2995 _MMCAMCORDER_UNLOCK(hcamcorder);
2997 _MMCAMCORDER_UNLOCK(hcamcorder);
2999 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3000 msg.param.code = hcamcorder->error_code;
3002 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
3005 return GST_BUS_DROP;
3009 static GstBusSyncReply __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message)
3012 gchar *debug_info = NULL;
3013 GstBusSyncReply ret = GST_BUS_PASS;
3014 _MMCamcorderSubContext *sc = NULL;
3016 if (!message || !hcamcorder) {
3017 MMCAM_LOG_ERROR("NULL message(%p) or handle(%p)", message, hcamcorder);
3018 return GST_BUS_PASS;
3021 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3022 mmf_return_val_if_fail(sc, GST_BUS_PASS);
3024 /* parse error message */
3025 gst_message_parse_error(message, &err, &debug_info);
3028 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
3034 MMCAM_LOG_WARNING("failed to parse error message");
3035 return GST_BUS_PASS;
3038 /* check domain[RESOURCE] and element[AUDIOSRC] */
3039 if (err->domain == GST_RESOURCE_ERROR &&
3040 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst))
3041 ret = __mmcamcorder_gst_handle_sync_audio_error(hcamcorder, err->code);
3043 ret = __mmcamcorder_gst_handle_sync_others_error(hcamcorder, err->code);
3051 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
3053 GstBusSyncReply ret = GST_BUS_PASS;
3055 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
3056 _MMCamcorderSubContext *sc = NULL;
3058 mmf_return_val_if_fail(hcamcorder, GST_BUS_PASS);
3059 mmf_return_val_if_fail(message, GST_BUS_PASS);
3061 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3062 mmf_return_val_if_fail(sc, GST_BUS_PASS);
3064 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS) {
3065 MMCAM_LOG_INFO("got EOS from pipeline");
3067 _MMCAMCORDER_LOCK(hcamcorder);
3069 sc->bget_eos = TRUE;
3070 _MMCAMCORDER_SIGNAL(hcamcorder);
3072 _MMCAMCORDER_UNLOCK(hcamcorder);
3075 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
3076 ret = __mmcamcorder_handle_gst_sync_error(hcamcorder, message);
3079 if (ret == GST_BUS_DROP)
3080 gst_message_unref(message);
3086 void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *value, void *user_data)
3088 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
3089 int current_state = MM_CAMCORDER_STATE_NONE;
3091 mmf_return_if_fail(hcamcorder);
3092 mmf_return_if_fail(value);
3094 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3095 if (current_state <= MM_CAMCORDER_STATE_NONE || current_state >= MM_CAMCORDER_STATE_NUM) {
3096 MMCAM_LOG_ERROR("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
3100 MMCAM_LOG_WARNING("camera policy [%s], current state [%d]", value, current_state);
3102 if (!strcmp(value, "disallowed")) {
3103 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3105 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_DPM);
3107 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3109 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
3112 MMCAM_LOG_WARNING("done");
3118 int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
3120 int ret = MM_ERROR_NONE;
3121 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3122 _MMCamcorderSubContext *sc = NULL;
3123 GstElement *pipeline = NULL;
3125 MMCAM_LOG_INFO("handle : %p, type : %d", handle, type);
3127 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3129 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3130 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3133 case MM_CAMCORDER_MODE_AUDIO:
3134 ret = _mmcamcorder_create_audio_pipeline(handle);
3135 if (ret != MM_ERROR_NONE)
3139 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3141 ret = _mmcamcorder_create_preview_pipeline(handle);
3142 if (ret != MM_ERROR_NONE)
3145 /* connect capture signal */
3146 if (!sc->bencbin_capture) {
3147 ret = _mmcamcorder_connect_capture_signal(handle);
3148 if (ret != MM_ERROR_NONE)
3154 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
3155 if (type != MM_CAMCORDER_MODE_AUDIO) {
3156 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:SET_READY_TO_PIPELINE");
3158 ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY);
3160 traceEnd(TTRACE_TAG_CAMERA);
3162 #ifdef _MMCAMCORDER_GET_DEVICE_INFO
3163 if (!_mmcamcorder_get_device_info(handle))
3164 MMCAM_LOG_ERROR("Getting device information error!!");
3167 MMCAM_LOG_INFO("ret[%x]", ret);
3168 if (ret != MM_ERROR_NONE) {
3169 MMCAM_LOG_ERROR("error : destroy pipeline");
3170 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
3177 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
3179 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3180 _MMCamcorderSubContext *sc = NULL;
3182 int element_num = 0;
3183 _MMCamcorderGstElement *element = NULL;
3186 mmf_return_if_fail(hcamcorder);
3188 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3189 mmf_return_if_fail(sc);
3193 /* Inside each pipeline destroy function, Set GST_STATE_NULL to Main pipeline */
3195 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3196 element = sc->element;
3197 element_num = sc->element_num;
3198 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
3199 _mmcamcorder_destroy_video_capture_pipeline(handle);
3201 case MM_CAMCORDER_MODE_AUDIO:
3202 element = sc->encode_element;
3203 element_num = sc->encode_element_num;
3204 bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst));
3205 _mmcamcorder_destroy_audio_pipeline(handle);
3208 MMCAM_LOG_ERROR("unknown type %d", type);
3212 MMCAM_LOG_INFO("Pipeline clear!!");
3214 /* Remove pipeline message callback */
3215 if (hcamcorder->pipeline_cb_event_id > 0) {
3216 g_source_remove(hcamcorder->pipeline_cb_event_id);
3217 hcamcorder->pipeline_cb_event_id = 0;
3220 /* Remove remained message in bus */
3222 GstMessage *gst_msg = NULL;
3223 while ((gst_msg = gst_bus_pop(bus)) != NULL) {
3224 _mmcamcorder_pipeline_cb_message(bus, gst_msg, (gpointer)hcamcorder);
3225 gst_message_unref(gst_msg);
3228 gst_object_unref(bus);
3232 /* checking unreleased element */
3233 for (i = 0 ; i < element_num ; i++) {
3234 if (element[i].gst) {
3235 if (GST_IS_ELEMENT(element[i].gst)) {
3236 MMCAM_LOG_WARNING("Still alive element - ID[%d], name [%s], ref count[%d], status[%s]",
3238 GST_OBJECT_NAME(element[i].gst),
3239 GST_OBJECT_REFCOUNT(element[i].gst),
3240 gst_element_state_get_name(GST_STATE(element[i].gst)));
3241 g_object_weak_unref(G_OBJECT(element[i].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3243 MMCAM_LOG_WARNING("The element[%d] is still alive, check it", element[i].id);
3246 element[i].id = _MMCAMCORDER_NONE;
3247 element[i].gst = NULL;
3255 #ifdef _MMCAMCORDER_USE_SET_ATTR_CB
3256 static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data)
3258 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
3260 mmf_return_val_if_fail(hcamcorder, FALSE);
3264 _mmcamcorder_set_attribute_to_camsensor((MMHandleType)hcamcorder);
3267 hcamcorder->setting_event_id = 0;
3269 MMCAM_LOG_INFO("Done");
3274 #endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
3277 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state)
3280 _MMCamcorderSubContext *sc = NULL;
3281 GstState pipeline_state = GST_STATE_VOID_PENDING;
3282 GstStateChangeReturn setChangeReturn = GST_STATE_CHANGE_FAILURE;
3283 GstStateChangeReturn getChangeReturn = GST_STATE_CHANGE_FAILURE;
3284 GstClockTime get_timeout = __MMCAMCORDER_SET_GST_STATE_TIMEOUT * GST_SECOND;
3285 GMutex *state_lock = NULL;
3287 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3288 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3289 mmf_return_val_if_fail(sc && sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3291 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == pipeline) {
3292 MMCAM_LOG_INFO("Set state to %d - PREVIEW PIPELINE", target_state);
3293 state_lock = &_MMCAMCORDER_GET_GST_STATE_LOCK(handle);
3295 MMCAM_LOG_INFO("Set state to %d - ENDODE PIPELINE", target_state);
3296 state_lock = &_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle);
3299 g_mutex_lock(state_lock);
3301 for (k = 0; k < _MMCAMCORDER_STATE_SET_COUNT; k++) {
3302 setChangeReturn = gst_element_set_state(pipeline, target_state);
3303 MMCAM_LOG_INFO("gst_element_set_state[%d] return %d", target_state, setChangeReturn);
3305 if (setChangeReturn != GST_STATE_CHANGE_FAILURE) {
3306 getChangeReturn = gst_element_get_state(pipeline, &pipeline_state, NULL, get_timeout);
3307 switch (getChangeReturn) {
3308 case GST_STATE_CHANGE_NO_PREROLL:
3309 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_NO_PREROLL.");
3311 case GST_STATE_CHANGE_SUCCESS:
3312 /* if we reached the final target state, exit */
3313 if (pipeline_state == target_state) {
3314 MMCAM_LOG_INFO("Set state to %d - DONE", target_state);
3315 g_mutex_unlock(state_lock);
3316 return MM_ERROR_NONE;
3319 case GST_STATE_CHANGE_ASYNC:
3320 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_ASYNC.");
3323 g_mutex_unlock(state_lock);
3324 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_FAILURE.");
3325 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3328 g_mutex_unlock(state_lock);
3330 MMCAM_LOG_ERROR("timeout of gst_element_get_state()!!");
3332 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3335 usleep(_MMCAMCORDER_STATE_CHECK_INTERVAL);
3338 g_mutex_unlock(state_lock);
3340 MMCAM_LOG_ERROR("Failure. gst_element_set_state timeout!!");
3342 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3346 /* For performance check */
3347 int _mmcamcorder_video_current_framerate(MMHandleType handle)
3349 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3350 _MMCamcorderSubContext *sc = NULL;
3352 mmf_return_val_if_fail(hcamcorder, -1);
3354 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3355 mmf_return_val_if_fail(sc, -1);
3357 return sc->kpi.current_fps;
3361 int _mmcamcorder_video_average_framerate(MMHandleType handle)
3363 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3364 _MMCamcorderSubContext *sc = NULL;
3366 mmf_return_val_if_fail(hcamcorder, -1);
3368 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3369 mmf_return_val_if_fail(sc, -1);
3371 return sc->kpi.average_fps;
3375 void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
3377 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3378 _MMCamcorderSubContext *sc = NULL;
3380 mmf_return_if_fail(hcamcorder);
3382 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3383 mmf_return_if_fail(sc);
3385 memset(&(sc->kpi), 0x00, sizeof(_MMCamcorderKPIMeasure));
3391 void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder, int state_change_by_system)
3396 int result = MM_ERROR_NONE;
3397 int cmd_try_count = 0;
3398 int current_state = MM_CAMCORDER_STATE_NONE;
3399 _MMCamcorderMsgItem msg;
3401 mmf_return_if_fail(hcamcorder);
3403 /* check command running */
3405 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
3406 if (cmd_try_count++ < __MMCAMCORDER_FORCE_STOP_TRY_COUNT) {
3407 MMCAM_LOG_WARNING("Another command is running. try again after %d ms", __MMCAMCORDER_FORCE_STOP_WAIT_TIME/1000);
3408 usleep(__MMCAMCORDER_FORCE_STOP_WAIT_TIME);
3410 MMCAM_LOG_ERROR("wait timeout");
3414 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
3419 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3421 MMCAM_LOG_WARNING("Force STOP MMFW Camcorder by %d", state_change_by_system);
3423 /* set state_change_by_system for state change message */
3424 hcamcorder->state_change_by_system = state_change_by_system;
3426 if (current_state >= MM_CAMCORDER_STATE_READY) {
3427 MMCAM_LOG_WARNING("send state change started message to notify");
3429 memset(&msg, 0x0, sizeof(_MMCamcorderMsgItem));
3431 switch (state_change_by_system) {
3432 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
3433 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_RM;
3435 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
3436 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_SECURITY;
3443 msg.param.state.code = hcamcorder->interrupt_code;
3444 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
3446 MMCAM_LOG_ERROR("should not be reached here %d", state_change_by_system);
3450 for (loop = 0 ; current_state > MM_CAMCORDER_STATE_NULL && loop < __MMCAMCORDER_CMD_ITERATE_MAX * 3 ; loop++) {
3451 itr_cnt = __MMCAMCORDER_CMD_ITERATE_MAX;
3452 switch (current_state) {
3453 case MM_CAMCORDER_STATE_CAPTURING:
3455 _MMCamcorderSubContext *sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3456 _MMCamcorderImageInfo *info = NULL;
3458 mmf_return_if_fail(sc);
3459 mmf_return_if_fail((info = sc->info_image));
3461 MMCAM_LOG_WARNING("Stop capturing.");
3463 /* if capturing isn't finished, waiting for 2 sec to finish real capture operation. check 'info->capturing'. */
3464 mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
3465 MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, TRUE,
3468 for (i = 0; i < 20 && info->capturing; i++)
3472 MMCAM_LOG_ERROR("Timeout. Can't check stop capturing.");
3474 while ((itr_cnt--) && ((result = _mmcamcorder_capture_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3475 MMCAM_LOG_WARNING("Can't stop capturing.(%x)", result);
3479 case MM_CAMCORDER_STATE_RECORDING:
3480 case MM_CAMCORDER_STATE_PAUSED:
3482 MMCAM_LOG_WARNING("Stop recording.");
3484 while ((itr_cnt--) && ((result = _mmcamcorder_commit((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
3485 MMCAM_LOG_WARNING("Can't commit.(%x), cancel it.", result);
3486 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3491 case MM_CAMCORDER_STATE_PREPARE:
3493 MMCAM_LOG_WARNING("Stop preview.");
3495 while ((itr_cnt--) && ((result = _mmcamcorder_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3496 MMCAM_LOG_WARNING("Can't stop preview.(%x)", result);
3500 case MM_CAMCORDER_STATE_READY:
3502 MMCAM_LOG_WARNING("unrealize");
3504 if ((result = _mmcamcorder_unrealize((MMHandleType)hcamcorder)) != MM_ERROR_NONE)
3505 MMCAM_LOG_WARNING("Can't unrealize.(%x)", result);
3510 MMCAM_LOG_WARNING("Already stopped.");
3514 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3518 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3520 MMCAM_LOG_WARNING("Done.");
3526 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error)
3528 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3529 _MMCamcorderMsgItem msg;
3530 gchar *msg_src_element = NULL;
3531 _MMCamcorderSubContext *sc = NULL;
3533 mmf_return_val_if_fail(hcamcorder, FALSE);
3534 mmf_return_val_if_fail(error, FALSE);
3535 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3536 mmf_return_val_if_fail(sc, FALSE);
3540 /* filtering filesink related errors */
3541 if (hcamcorder->state == MM_CAMCORDER_STATE_RECORDING &&
3542 (error->code == GST_RESOURCE_ERROR_WRITE || error->code == GST_RESOURCE_ERROR_SEEK)) {
3543 if (sc->ferror_count == 2 && sc->ferror_send == FALSE) {
3544 sc->ferror_send = TRUE;
3545 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3548 MMCAM_LOG_WARNING("Skip error");
3553 if (error->domain == GST_CORE_ERROR) {
3554 msg.param.code = __mmcamcorder_gst_handle_core_error(handle, error->code, message);
3555 } else if (error->domain == GST_LIBRARY_ERROR) {
3556 msg.param.code = __mmcamcorder_gst_handle_library_error(handle, error->code, message);
3557 } else if (error->domain == GST_RESOURCE_ERROR) {
3558 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3559 } else if (error->domain == GST_STREAM_ERROR) {
3560 msg.param.code = __mmcamcorder_gst_handle_stream_error(handle, error->code, message);
3562 MMCAM_LOG_WARNING("This error domain is not defined.");
3564 /* we treat system error as an internal error */
3565 msg.param.code = MM_ERROR_CAMCORDER_INTERNAL;
3569 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3570 MMCAM_LOG_ERROR("-Msg src : [%s] Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3571 msg_src_element, g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3573 MMCAM_LOG_ERROR("Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3574 g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3577 #ifdef _MMCAMCORDER_SKIP_GST_FLOW_ERROR
3578 /* Check whether send this error to application */
3579 if (msg.param.code == MM_ERROR_CAMCORDER_GST_FLOW_ERROR) {
3580 MMCAM_LOG_INFO("We got the error. But skip it.");
3583 #endif /* _MMCAMCORDER_SKIP_GST_FLOW_ERROR */
3585 /* post error to application except RESTRICTED case */
3586 if (msg.param.code != MM_ERROR_POLICY_RESTRICTED) {
3587 hcamcorder->error_occurs = TRUE;
3588 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3589 _mmcamcorder_send_message(handle, &msg);
3596 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message)
3598 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3599 _MMCamcorderSubContext *sc = NULL;
3600 GstElement *element = NULL;
3604 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3606 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3607 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3609 /* Specific plugin - video encoder plugin */
3610 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3612 if (GST_ELEMENT_CAST(message->src) == element) {
3613 if (code == GST_CORE_ERROR_NEGOTIATION)
3614 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3616 return MM_ERROR_CAMCORDER_ENCODER;
3621 case GST_CORE_ERROR_STATE_CHANGE:
3622 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3623 case GST_CORE_ERROR_NEGOTIATION:
3624 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3625 case GST_CORE_ERROR_MISSING_PLUGIN:
3626 case GST_CORE_ERROR_SEEK:
3627 case GST_CORE_ERROR_NOT_IMPLEMENTED:
3628 case GST_CORE_ERROR_FAILED:
3629 case GST_CORE_ERROR_TOO_LAZY:
3630 case GST_CORE_ERROR_PAD:
3631 case GST_CORE_ERROR_THREAD:
3632 case GST_CORE_ERROR_EVENT:
3633 case GST_CORE_ERROR_CAPS:
3634 case GST_CORE_ERROR_TAG:
3635 case GST_CORE_ERROR_CLOCK:
3636 case GST_CORE_ERROR_DISABLED:
3638 return MM_ERROR_CAMCORDER_GST_CORE;
3643 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message)
3645 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3646 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3650 /* Specific plugin - NONE */
3654 case GST_LIBRARY_ERROR_FAILED:
3655 case GST_LIBRARY_ERROR_TOO_LAZY:
3656 case GST_LIBRARY_ERROR_INIT:
3657 case GST_LIBRARY_ERROR_SHUTDOWN:
3658 case GST_LIBRARY_ERROR_SETTINGS:
3659 case GST_LIBRARY_ERROR_ENCODE:
3661 MMCAM_LOG_ERROR("Library error(%d)", code);
3662 return MM_ERROR_CAMCORDER_GST_LIBRARY;
3667 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message)
3669 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3670 _MMCamcorderSubContext *sc = NULL;
3671 GstElement *element = NULL;
3673 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3675 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3676 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3680 /* Specific plugin */
3682 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst);
3683 if (GST_ELEMENT_CAST(message->src) == element) {
3684 if (code == GST_RESOURCE_ERROR_WRITE) {
3685 MMCAM_LOG_ERROR("Display device [Off]");
3686 return MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF;
3688 MMCAM_LOG_ERROR("Display device [General(%d)]", code);
3693 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst);
3694 if (GST_ELEMENT_CAST(message->src) == element) {
3695 if (code == GST_RESOURCE_ERROR_FAILED) {
3696 int ret = MM_ERROR_NONE;
3697 int current_state = MM_CAMCORDER_STATE_NONE;
3699 MMCAM_LOG_ERROR("DPM mic DISALLOWED - current state %d", current_state);
3701 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3703 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3704 if (current_state >= MM_CAMCORDER_STATE_RECORDING) {
3705 /* set value to inform a status is changed by DPM */
3706 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_DPM;
3708 ret = _mmcamcorder_commit((MMHandleType)hcamcorder);
3709 MMCAM_LOG_INFO("commit result : 0x%x", ret);
3711 if (ret != MM_ERROR_NONE) {
3712 MMCAM_LOG_ERROR("commit failed, cancel it");
3713 ret = _mmcamcorder_cancel((MMHandleType)hcamcorder);
3718 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3720 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3722 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
3724 return MM_ERROR_POLICY_RESTRICTED;
3729 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3730 if (GST_ELEMENT_CAST(message->src) == element) {
3731 if (code == GST_RESOURCE_ERROR_FAILED) {
3732 MMCAM_LOG_ERROR("Encoder [Resource error]");
3733 return MM_ERROR_CAMCORDER_ENCODER_BUFFER;
3735 MMCAM_LOG_ERROR("Encoder [General(%d)]", code);
3736 return MM_ERROR_CAMCORDER_ENCODER;
3742 case GST_RESOURCE_ERROR_WRITE:
3743 MMCAM_LOG_ERROR("File write error");
3744 return MM_ERROR_FILE_WRITE;
3745 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3746 MMCAM_LOG_ERROR("No left space");
3747 return MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
3748 case GST_RESOURCE_ERROR_OPEN_WRITE:
3749 MMCAM_LOG_ERROR("Out of storage");
3750 return MM_ERROR_OUT_OF_STORAGE;
3751 case GST_RESOURCE_ERROR_SEEK:
3752 MMCAM_LOG_ERROR("File read(seek)");
3753 return MM_ERROR_FILE_READ;
3754 case GST_RESOURCE_ERROR_NOT_FOUND:
3755 case GST_RESOURCE_ERROR_FAILED:
3756 case GST_RESOURCE_ERROR_TOO_LAZY:
3757 case GST_RESOURCE_ERROR_BUSY:
3758 case GST_RESOURCE_ERROR_OPEN_READ:
3759 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3760 case GST_RESOURCE_ERROR_CLOSE:
3761 case GST_RESOURCE_ERROR_READ:
3762 case GST_RESOURCE_ERROR_SYNC:
3763 case GST_RESOURCE_ERROR_SETTINGS:
3765 MMCAM_LOG_ERROR("Resource error(%d)", code);
3766 return MM_ERROR_CAMCORDER_GST_RESOURCE;
3771 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message)
3773 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3774 _MMCamcorderSubContext *sc = NULL;
3775 GstElement *element = NULL;
3777 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3779 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3780 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3784 /* Specific plugin */
3786 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3787 if (GST_ELEMENT_CAST(message->src) == element) {
3789 case GST_STREAM_ERROR_WRONG_TYPE:
3790 MMCAM_LOG_ERROR("Video encoder [wrong stream type]");
3791 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
3792 case GST_STREAM_ERROR_ENCODE:
3793 MMCAM_LOG_ERROR("Video encoder [encode error]");
3794 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3795 case GST_STREAM_ERROR_FAILED:
3796 MMCAM_LOG_ERROR("Video encoder [stream failed]");
3797 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3799 MMCAM_LOG_ERROR("Video encoder [General(%d)]", code);
3800 return MM_ERROR_CAMCORDER_ENCODER;
3804 /* General plugin */
3806 case GST_STREAM_ERROR_FORMAT:
3807 MMCAM_LOG_ERROR("General [negotiation error(%d)]", code);
3808 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3809 case GST_STREAM_ERROR_FAILED:
3810 MMCAM_LOG_ERROR("General [flow error(%d)]", code);
3811 return MM_ERROR_CAMCORDER_GST_FLOW_ERROR;
3812 case GST_STREAM_ERROR_TYPE_NOT_FOUND:
3813 case GST_STREAM_ERROR_DECODE:
3814 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
3815 case GST_STREAM_ERROR_NOT_IMPLEMENTED:
3816 case GST_STREAM_ERROR_TOO_LAZY:
3817 case GST_STREAM_ERROR_ENCODE:
3818 case GST_STREAM_ERROR_DEMUX:
3819 case GST_STREAM_ERROR_MUX:
3820 case GST_STREAM_ERROR_DECRYPT:
3821 case GST_STREAM_ERROR_DECRYPT_NOKEY:
3822 case GST_STREAM_ERROR_WRONG_TYPE:
3824 MMCAM_LOG_ERROR("General [error(%d)]", code);
3825 return MM_ERROR_CAMCORDER_GST_STREAM;
3830 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error)
3832 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3833 gchar *debug = NULL;
3836 mmf_return_val_if_fail(hcamcorder, FALSE);
3837 mmf_return_val_if_fail(error, FALSE);
3841 gst_message_parse_warning(message, &err, &debug);
3843 if (error->domain == GST_CORE_ERROR) {
3844 MMCAM_LOG_WARNING("GST warning: GST_CORE domain");
3845 } else if (error->domain == GST_LIBRARY_ERROR) {
3846 MMCAM_LOG_WARNING("GST warning: GST_LIBRARY domain");
3847 } else if (error->domain == GST_RESOURCE_ERROR) {
3848 MMCAM_LOG_WARNING("GST warning: GST_RESOURCE domain");
3849 __mmcamcorder_gst_handle_resource_warning(handle, message, error);
3850 } else if (error->domain == GST_STREAM_ERROR) {
3851 MMCAM_LOG_WARNING("GST warning: GST_STREAM domain");
3853 MMCAM_LOG_WARNING("This error domain(%d) is not defined.", error->domain);
3860 if (debug != NULL) {
3861 MMCAM_LOG_ERROR("Debug: %s", debug);
3870 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error)
3872 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3873 _MMCamcorderSubContext *sc = NULL;
3874 GstElement *element = NULL;
3875 gchar *msg_src_element;
3877 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3879 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3880 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3884 /* Special message handling */
3886 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
3887 if (GST_ELEMENT_CAST(message->src) == element) {
3888 if (error->code == GST_RESOURCE_ERROR_FAILED) {
3889 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3890 MMCAM_LOG_WARNING("-Msg src:[%s] Domain:[%s] Error:[%s]",
3891 msg_src_element, g_quark_to_string(error->domain), error->message);
3892 return MM_ERROR_NONE;
3896 /* General plugin */
3897 switch (error->code) {
3898 case GST_RESOURCE_ERROR_WRITE:
3899 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3900 case GST_RESOURCE_ERROR_SEEK:
3901 case GST_RESOURCE_ERROR_NOT_FOUND:
3902 case GST_RESOURCE_ERROR_FAILED:
3903 case GST_RESOURCE_ERROR_TOO_LAZY:
3904 case GST_RESOURCE_ERROR_BUSY:
3905 case GST_RESOURCE_ERROR_OPEN_READ:
3906 case GST_RESOURCE_ERROR_OPEN_WRITE:
3907 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3908 case GST_RESOURCE_ERROR_CLOSE:
3909 case GST_RESOURCE_ERROR_READ:
3910 case GST_RESOURCE_ERROR_SYNC:
3911 case GST_RESOURCE_ERROR_SETTINGS:
3913 MMCAM_LOG_WARNING("General GST warning(%d)", error->code);
3917 return MM_ERROR_NONE;
3921 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
3922 const char *interface_name, const char *signal_name, int value)
3924 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3926 mmf_return_if_fail(hcamcorder && object_name && interface_name && signal_name);
3928 MMCAM_LOG_INFO("object %s, interface %s, signal %s, value %d",
3929 object_name, interface_name, signal_name, value);
3931 _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, object_name, interface_name, signal_name, value);
3937 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
3938 static int __mmcamcorder_resource_release_cb(mm_resource_manager_h rm,
3939 mm_resource_manager_res_h res, void *user_data)
3941 mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *) user_data;
3943 mmf_return_val_if_fail(hcamcorder, FALSE);
3945 MMCAM_LOG_WARNING("enter");
3947 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3949 /* set flag for resource release callback */
3950 hcamcorder->is_release_cb_calling = TRUE;
3952 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3954 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3956 if (res == hcamcorder->video_encoder_resource) {
3957 /* Stop video recording */
3958 if (_mmcamcorder_commit((MMHandleType)hcamcorder) != MM_ERROR_NONE) {
3959 MMCAM_LOG_ERROR("commit failed, cancel it");
3960 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3964 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_RM);
3967 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3969 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3971 if (res == hcamcorder->camera_resource)
3972 hcamcorder->camera_resource = NULL;
3973 else if (res == hcamcorder->video_overlay_resource)
3974 hcamcorder->video_overlay_resource = NULL;
3975 else if (res == hcamcorder->video_encoder_resource)
3976 hcamcorder->video_encoder_resource = NULL;
3978 /* restore flag for resource release callback */
3979 hcamcorder->is_release_cb_calling = FALSE;
3981 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3983 MMCAM_LOG_WARNING("leave");
3987 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
3989 int _mmcamcorder_manage_external_storage_state(MMHandleType handle, int storage_state)
3991 int ret = MM_ERROR_NONE;
3992 int current_state = MM_CAMCORDER_STATE_NONE;
3993 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3994 _MMCamcorderMsgItem msg;
3996 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
3998 MMCAM_LOG_WARNING("storage state %d", storage_state);
4000 /* check storage state */
4001 if (storage_state != STORAGE_STATE_UNMOUNTABLE &&
4002 storage_state != STORAGE_STATE_REMOVED) {
4003 MMCAM_LOG_WARNING("nothing to do");
4004 return MM_ERROR_NONE;
4007 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
4009 /* check recording state */
4010 current_state = _mmcamcorder_get_state(handle);
4012 MMCAM_LOG_WARNING("current_state %d", current_state);
4014 if (current_state < MM_CAMCORDER_STATE_RECORDING) {
4015 MMCAM_LOG_WARNING("no recording now");
4019 /* check storage type */
4020 if (hcamcorder->storage_info.type != STORAGE_TYPE_EXTERNAL) {
4021 MMCAM_LOG_WARNING("external storage is not used");
4025 /* cancel recording */
4026 ret = _mmcamcorder_cancel(handle);
4028 /* send error message */
4029 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
4030 msg.param.code = MM_ERROR_OUT_OF_STORAGE;
4032 _mmcamcorder_send_message(handle, &msg);
4035 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
4037 MMCAM_LOG_WARNING("done - ret 0x%x", ret);