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 <asm/types.h>
41 #include <system_info.h>
43 #ifdef _MMCAMCORDER_RM_SUPPORT
44 #include "mm_camcorder_rm.h"
45 #endif /* _MMCAMCORDER_RM_SUPPORT */
47 /*---------------------------------------------------------------------------------------
48 | LOCAL VARIABLE DEFINITIONS for internal |
49 ---------------------------------------------------------------------------------------*/
50 #define __MMCAMCORDER_CMD_ITERATE_MAX 3
51 #define __MMCAMCORDER_SET_GST_STATE_TIMEOUT 5
52 #define __MMCAMCORDER_FORCE_STOP_TRY_COUNT 30
53 #define __MMCAMCORDER_FORCE_STOP_WAIT_TIME 100000 /* us */
54 #define __MMCAMCORDER_SOUND_WAIT_TIMEOUT 3
55 #define __MMCAMCORDER_FOCUS_CHANGE_REASON_LEN 64
56 #define __MMCAMCORDER_CONF_FILENAME_LENGTH 64
58 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
59 #define __MMCAMCORDER_DEVICE_TYPE_STRING_LEN 1
64 #define DPM_DISALLOWED 0
66 /*---------------------------------------------------------------------------------------
67 | LOCAL FUNCTION PROTOTYPES: |
68 ---------------------------------------------------------------------------------------*/
69 /* STATIC INTERNAL FUNCTION */
70 static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_type);
71 static void __mmcamcorder_deinit_handle(mmf_camcorder_t *hcamcorder);
72 static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcorder);
73 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder);
74 static gint __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder);
75 static void __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder);
76 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf);
77 static void __mmcamcorder_get_system_info(mmf_camcorder_t *hcamcorder);
79 static void __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message);
80 static void __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code);
81 static void __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code);
82 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error);
83 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message);
84 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message);
85 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message);
86 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message);
87 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error);
88 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error);
89 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
90 static int __mmcamcorder_resource_release_cb(mm_resource_manager_h rm,
91 mm_resource_manager_res_h res, void *user_data);
92 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
94 /*=======================================================================================
95 | FUNCTION DEFINITIONS |
96 =======================================================================================*/
97 static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_type)
99 int ret = MM_ERROR_NONE;
100 int log_level = MM_CAMCORDER_LOG_LEVEL_INFO;
101 mmf_camcorder_t *new_handle = NULL;
104 MMCAM_LOG_ERROR("NULL handle");
105 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
108 /* Create mmf_camcorder_t handle and initialize every variable */
109 new_handle = (mmf_camcorder_t *)malloc(sizeof(mmf_camcorder_t));
111 MMCAM_LOG_ERROR("new handle allocation failed");
112 return MM_ERROR_CAMCORDER_LOW_MEMORY;
115 memset(new_handle, 0x00, sizeof(mmf_camcorder_t));
117 /* set device type */
118 new_handle->device_type = device_type;
120 MMCAM_LOG_WARNING("Device Type : %d", new_handle->device_type);
122 new_handle->type = MM_CAMCORDER_MODE_VIDEO_CAPTURE;
123 new_handle->state = MM_CAMCORDER_STATE_NONE;
124 new_handle->old_state = MM_CAMCORDER_STATE_NONE;
125 new_handle->capture_in_recording = FALSE;
127 /* init mutex and cond */
128 g_mutex_init(&(new_handle->mtsafe).lock);
129 g_cond_init(&(new_handle->mtsafe).cond);
130 g_mutex_init(&(new_handle->mtsafe).cmd_lock);
131 g_cond_init(&(new_handle->mtsafe).cmd_cond);
132 g_mutex_init(&(new_handle->mtsafe).interrupt_lock);
133 g_mutex_init(&(new_handle->mtsafe).state_lock);
134 g_mutex_init(&(new_handle->mtsafe).gst_state_lock);
135 g_mutex_init(&(new_handle->mtsafe).gst_encode_state_lock);
136 g_mutex_init(&(new_handle->mtsafe).message_cb_lock);
137 g_mutex_init(&(new_handle->mtsafe).vcapture_cb_lock);
138 g_mutex_init(&(new_handle->mtsafe).vstream_cb_lock);
139 g_mutex_init(&(new_handle->mtsafe).astream_cb_lock);
140 g_mutex_init(&(new_handle->mtsafe).mstream_cb_lock);
141 g_mutex_init(&(new_handle->mtsafe).vedecision_cb_lock);
142 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
143 g_mutex_init(&(new_handle->mtsafe).resource_lock);
144 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
146 g_mutex_init(&new_handle->restart_preview_lock);
148 g_mutex_init(&new_handle->snd_info.open_mutex);
149 g_cond_init(&new_handle->snd_info.open_cond);
150 g_mutex_init(&new_handle->snd_info.play_mutex);
151 g_cond_init(&new_handle->snd_info.play_cond);
153 g_mutex_init(&new_handle->task_thread_lock);
154 g_cond_init(&new_handle->task_thread_cond);
155 new_handle->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
157 if (device_type != MM_VIDEO_DEVICE_NONE) {
158 new_handle->gdbus_info_sound.mm_handle = new_handle;
159 g_mutex_init(&new_handle->gdbus_info_sound.sync_mutex);
160 g_cond_init(&new_handle->gdbus_info_sound.sync_cond);
162 new_handle->gdbus_info_solo_sound.mm_handle = new_handle;
163 g_mutex_init(&new_handle->gdbus_info_solo_sound.sync_mutex);
164 g_cond_init(&new_handle->gdbus_info_solo_sound.sync_cond);
167 /* create task thread */
168 new_handle->task_thread = g_thread_try_new("MMCAM_TASK_THREAD",
169 (GThreadFunc)_mmcamcorder_util_task_thread_func, (gpointer)new_handle, NULL);
170 if (new_handle->task_thread == NULL) {
171 MMCAM_LOG_ERROR("_mmcamcorder_create::failed to create task thread");
172 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
173 goto _INIT_HANDLE_FAILED;
176 /* Get Camera Configure information from Camcorder INI file */
177 ret = _mmcamcorder_conf_get_info((MMHandleType)new_handle, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &new_handle->conf_main);
178 if (ret != MM_ERROR_NONE) {
179 MMCAM_LOG_ERROR("Failed to get configure(main) info.");
180 goto _INIT_HANDLE_FAILED;
183 /* Get log level from conf */
184 _mmcamcorder_conf_get_value_int((MMHandleType)new_handle, new_handle->conf_main,
185 CONFIGURE_CATEGORY_MAIN_GENERAL,
189 _mmcamcorder_set_log_level(log_level);
191 /* allocate attribute */
192 new_handle->attributes = _mmcamcorder_alloc_attribute((MMHandleType)new_handle);
193 if (!new_handle->attributes) {
194 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
195 goto _INIT_HANDLE_FAILED;
198 *hcamcorder = new_handle;
200 MMCAM_LOG_INFO("new handle %p", new_handle);
202 return MM_ERROR_NONE;
205 __mmcamcorder_deinit_handle(new_handle);
210 static void __mmcamcorder_deinit_handle(mmf_camcorder_t *hcamcorder)
213 MMCAM_LOG_ERROR("NULL handle");
217 /* Remove exif info */
218 if (hcamcorder->exif_info) {
219 mm_exif_destory_exif_info(hcamcorder->exif_info);
220 hcamcorder->exif_info = NULL;
223 /* remove attributes */
224 if (hcamcorder->attributes) {
225 _mmcamcorder_dealloc_attribute((MMHandleType)hcamcorder, hcamcorder->attributes);
226 hcamcorder->attributes = 0;
229 /* Release configure info */
230 __mmcamcorder_deinit_configure(hcamcorder);
232 /* remove task thread */
233 if (hcamcorder->task_thread) {
234 g_mutex_lock(&hcamcorder->task_thread_lock);
235 MMCAM_LOG_INFO("send signal for task thread exit");
236 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_EXIT;
237 g_cond_signal(&hcamcorder->task_thread_cond);
238 g_mutex_unlock(&hcamcorder->task_thread_lock);
239 g_thread_join(hcamcorder->task_thread);
240 hcamcorder->task_thread = NULL;
243 /* Release lock, cond */
244 g_mutex_clear(&(hcamcorder->mtsafe).lock);
245 g_cond_clear(&(hcamcorder->mtsafe).cond);
246 g_mutex_clear(&(hcamcorder->mtsafe).cmd_lock);
247 g_cond_clear(&(hcamcorder->mtsafe).cmd_cond);
248 g_mutex_clear(&(hcamcorder->mtsafe).interrupt_lock);
249 g_mutex_clear(&(hcamcorder->mtsafe).state_lock);
250 g_mutex_clear(&(hcamcorder->mtsafe).gst_state_lock);
251 g_mutex_clear(&(hcamcorder->mtsafe).gst_encode_state_lock);
252 g_mutex_clear(&(hcamcorder->mtsafe).message_cb_lock);
253 g_mutex_clear(&(hcamcorder->mtsafe).vcapture_cb_lock);
254 g_mutex_clear(&(hcamcorder->mtsafe).vstream_cb_lock);
255 g_mutex_clear(&(hcamcorder->mtsafe).astream_cb_lock);
256 g_mutex_clear(&(hcamcorder->mtsafe).mstream_cb_lock);
257 g_mutex_clear(&(hcamcorder->mtsafe).vedecision_cb_lock);
258 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
259 g_mutex_clear(&(hcamcorder->mtsafe).resource_lock);
260 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
262 g_mutex_clear(&hcamcorder->snd_info.open_mutex);
263 g_cond_clear(&hcamcorder->snd_info.open_cond);
264 g_mutex_clear(&hcamcorder->restart_preview_lock);
266 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
267 g_mutex_clear(&hcamcorder->gdbus_info_sound.sync_mutex);
268 g_cond_clear(&hcamcorder->gdbus_info_sound.sync_cond);
269 g_mutex_clear(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
270 g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
273 g_mutex_clear(&hcamcorder->task_thread_lock);
274 g_cond_clear(&hcamcorder->task_thread_cond);
276 if (hcamcorder->model_name)
277 free(hcamcorder->model_name);
279 if (hcamcorder->software_version)
280 free(hcamcorder->software_version);
283 memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
291 static void __mmcamcorder_get_system_info(mmf_camcorder_t *hcamcorder)
296 MMCAM_LOG_ERROR("NULL handle");
300 /* get shutter sound policy */
301 vconf_get_int(VCONFKEY_CAMERA_SHUTTER_SOUND_POLICY, &hcamcorder->shutter_sound_policy);
302 MMCAM_LOG_INFO("current shutter sound policy : %d", hcamcorder->shutter_sound_policy);
305 ret = system_info_get_platform_string("http://tizen.org/system/model_name", &hcamcorder->model_name);
307 MMCAM_LOG_WARNING("model name [%s], ret 0x%x",
308 hcamcorder->model_name ? hcamcorder->model_name : "NULL", ret);
310 /* get software version */
311 ret = system_info_get_platform_string("http://tizen.org/system/build.string", &hcamcorder->software_version);
313 MMCAM_LOG_WARNING("software version [%s], ret 0x%x",
314 hcamcorder->software_version ? hcamcorder->software_version : "NULL", ret);
320 static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcorder)
322 int ret = MM_ERROR_NONE;
323 int resolution_width = 0;
324 int resolution_height = 0;
325 int rcmd_fmt_capture = MM_PIXEL_FORMAT_YUYV;
326 int rcmd_fmt_recording = MM_PIXEL_FORMAT_NV12;
327 int rcmd_dpy_rotation = MM_DISPLAY_ROTATION_270;
328 int play_capture_sound = TRUE;
329 int camera_default_flip = MM_FLIP_NONE;
330 int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
331 char *err_attr_name = NULL;
332 char conf_file_name[__MMCAMCORDER_CONF_FILENAME_LENGTH] = {'\0',};
333 const char *platform_privilege_camera = NULL;
334 MMCamAttrsInfo fps_info;
335 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
336 camera_conf_error_e ret_conf = CAMERA_CONF_MGR_ERROR_NONE;
337 char devicetype[__MMCAMCORDER_CONF_FILENAME_LENGTH] = {'\0',};
341 MMCAM_LOG_ERROR("NULL handle");
342 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
345 if (hcamcorder->is_network) {
346 snprintf(conf_file_name, sizeof(conf_file_name), "%s_network.ini",
347 CONFIGURE_CTRL_FILE_PREFIX);
349 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
350 snprintf(devicetype, sizeof(devicetype), "%d", hcamcorder->device_type);
351 memset(&hcamcorder->conf_device_info, 0x00, sizeof(camera_conf_device_info_s));
352 ret_conf = camera_conf_mgr_get_ids(devicetype, __MMCAMCORDER_DEVICE_TYPE_STRING_LEN,
353 &hcamcorder->conf_device_info);
354 if (ret_conf != CAMERA_CONF_MGR_ERROR_NONE) {
355 MMCAM_LOG_ERROR("Device [%s] is not found", devicetype);
356 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
359 snprintf(conf_file_name, sizeof(conf_file_name), "%s_%s_%s.ini",
360 CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->conf_device_info.vendor_id,
361 hcamcorder->conf_device_info.product_id);
363 MMCAM_LOG_INFO("device info : node[%s]",
364 hcamcorder->conf_device_info.node);
366 snprintf(conf_file_name, sizeof(conf_file_name), "%s%d.ini",
367 CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->device_type);
371 MMCAM_LOG_INFO("Load control configure file [%d][%s]",
372 hcamcorder->device_type, conf_file_name);
374 ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
375 CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
376 if (ret != MM_ERROR_NONE) {
377 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
378 snprintf(conf_file_name, sizeof(conf_file_name), "%s.ini",
379 CONFIGURE_CTRL_FILE_PREFIX);
380 ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
381 CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
382 if (ret != MM_ERROR_NONE) {
383 MMCAM_LOG_ERROR("Failed to get configure(control) info.");
387 MMCAM_LOG_ERROR("Failed to get configure(control) info.");
392 _mmcamcorder_conf_print_info(&hcamcorder->conf_main);
393 _mmcamcorder_conf_print_info(&hcamcorder->conf_ctrl);
395 ret = _mmcamcorder_init_convert_table((MMHandleType)hcamcorder);
396 if (ret != MM_ERROR_NONE) {
397 MMCAM_LOG_WARNING("converting table initialize error!!");
398 return MM_ERROR_CAMCORDER_INTERNAL;
401 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_ALL);
402 if (ret != MM_ERROR_NONE) {
403 MMCAM_LOG_WARNING("attribute initialize from configure error!!");
404 return MM_ERROR_CAMCORDER_INTERNAL;
407 /* Get device information for supported features from INI */
408 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
409 CONFIGURE_CATEGORY_CTRL_CAMERA,
410 "RecommendPreviewFormatCapture",
413 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
414 CONFIGURE_CATEGORY_CTRL_CAMERA,
415 "RecommendPreviewFormatRecord",
416 &rcmd_fmt_recording);
418 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
419 CONFIGURE_CATEGORY_CTRL_CAMERA,
420 "RecommendDisplayRotation",
423 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
424 CONFIGURE_CATEGORY_MAIN_CAPTURE,
426 &play_capture_sound);
428 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
429 CONFIGURE_CATEGORY_CTRL_CAMERA,
431 &camera_facing_direction);
433 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
434 CONFIGURE_CATEGORY_CTRL_EFFECT,
435 "BrightnessStepDenominator",
436 &hcamcorder->brightness_step_denominator);
438 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
439 CONFIGURE_CATEGORY_CTRL_CAPTURE,
441 &hcamcorder->support_zsl_capture);
443 MMCAM_LOG_INFO("Recommend fmt[cap:%d,rec:%d], dpy rot %d, cap snd %d, cam facing dir %d, step denom %d, support zsl %d",
444 rcmd_fmt_capture, rcmd_fmt_recording, rcmd_dpy_rotation,
445 play_capture_sound, camera_facing_direction,
446 hcamcorder->brightness_step_denominator, hcamcorder->support_zsl_capture);
448 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
449 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
451 &hcamcorder->use_zero_copy_format);
453 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
454 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
456 &hcamcorder->support_user_buffer);
458 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
459 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
460 "SupportMediaPacketPreviewCb",
461 &hcamcorder->support_media_packet_preview_cb);
463 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
464 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
465 "SupportExtraPreview",
466 &hcamcorder->support_extra_preview);
468 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
469 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
471 &hcamcorder->use_videoconvert);
473 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
474 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
476 &hcamcorder->measure_preview_fps);
478 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
479 MMCAM_CAMERA_WIDTH, &resolution_width,
480 MMCAM_CAMERA_HEIGHT, &resolution_height,
482 if (ret != MM_ERROR_NONE) {
483 MMCAM_LOG_ERROR("get attribute[resolution] error");
484 return MM_ERROR_CAMCORDER_INTERNAL;
487 ret = mm_camcorder_get_fps_list_by_resolution((MMHandleType)hcamcorder, resolution_width, resolution_height, &fps_info);
488 if (ret != MM_ERROR_NONE) {
489 MMCAM_LOG_ERROR("get fps list failed with [%dx%d]", resolution_width, resolution_height);
490 return MM_ERROR_CAMCORDER_INTERNAL;
493 MMCAM_LOG_INFO("ZC %d, UB %d, VC %d, MPPC %d, EP %d, MPFPS %d",
494 hcamcorder->use_zero_copy_format, hcamcorder->support_user_buffer,
495 hcamcorder->use_videoconvert, hcamcorder->support_media_packet_preview_cb,
496 hcamcorder->support_extra_preview, hcamcorder->measure_preview_fps);
498 MMCAM_LOG_INFO("res : %d X %d, Default FPS by resolution : %d",
499 resolution_width, resolution_height, fps_info.int_array.def);
501 if (camera_facing_direction == 1) {
502 if (rcmd_dpy_rotation == MM_DISPLAY_ROTATION_270 || rcmd_dpy_rotation == MM_DISPLAY_ROTATION_90)
503 camera_default_flip = MM_FLIP_VERTICAL;
505 camera_default_flip = MM_FLIP_HORIZONTAL;
507 MMCAM_LOG_INFO("camera_default_flip : [%d]", camera_default_flip);
510 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
511 CONFIGURE_CATEGORY_MAIN_GENERAL,
512 "PlatformPrivilegeCamera",
513 &platform_privilege_camera);
515 if (hcamcorder->is_network) {
516 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
517 CONFIGURE_CATEGORY_MAIN_GENERAL,
518 "NetworkCameraHALName",
519 &hcamcorder->network_hal_name);
521 MMCAM_LOG_INFO("network HAL name[%s]", hcamcorder->network_hal_name);
524 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, &err_attr_name,
525 MMCAM_CAMERA_FACING_DIRECTION, camera_facing_direction,
526 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, rcmd_fmt_capture,
527 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, rcmd_fmt_recording,
528 MMCAM_RECOMMEND_DISPLAY_ROTATION, rcmd_dpy_rotation,
529 MMCAM_SUPPORT_ZSL_CAPTURE, hcamcorder->support_zsl_capture,
530 MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
531 MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
532 MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
533 MMCAM_CAMERA_FPS, fps_info.int_array.def,
534 MMCAM_DISPLAY_FLIP, camera_default_flip,
535 MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,
536 MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
537 platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
539 if (ret != MM_ERROR_NONE) {
540 MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
541 SAFE_FREE(err_attr_name);
542 return MM_ERROR_CAMCORDER_INTERNAL;
545 /* Get default value of brightness */
546 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
547 MMCAM_FILTER_BRIGHTNESS, &hcamcorder->brightness_default,
549 if (ret != MM_ERROR_NONE) {
550 MMCAM_LOG_ERROR("Get brightness FAILED.");
551 return MM_ERROR_CAMCORDER_INTERNAL;
554 MMCAM_LOG_INFO("Default brightness : %d", hcamcorder->brightness_default);
560 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder)
562 int ret = MM_ERROR_NONE;
565 MMCAM_LOG_ERROR("NULL handle");
566 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
569 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
570 if (ret != MM_ERROR_NONE) {
571 MMCAM_LOG_ERROR("there is no audio device");
572 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
579 static gint __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder)
581 int ret = MM_ERROR_NONE;
582 int device_count = 0;
583 const char *videosrc_name = NULL;
584 const char *audiosrc_name = NULL;
585 type_element *SrcElement = NULL;
588 MMCAM_LOG_ERROR("NULL handle");
589 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
593 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
594 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
598 /* Videosrc element name */
599 _mmcamcorder_conf_get_element((MMHandleType)hcamcorder, hcamcorder->conf_main,
600 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
603 _mmcamcorder_conf_get_value_element_name(SrcElement, &videosrc_name);
605 /* Audiosrc element name */
606 _mmcamcorder_conf_get_element((MMHandleType)hcamcorder, hcamcorder->conf_main,
607 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
610 _mmcamcorder_conf_get_value_element_name(SrcElement, &audiosrc_name);
612 MMCAM_LOG_INFO("Device count[%d], Videosrc[%s], Audiosrc[%s]",
613 device_count, videosrc_name, audiosrc_name);
615 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
616 MMCAM_CAMERA_DEVICE_COUNT, device_count,
617 MMCAM_VIDEOSRC_ELEMENT_NAME, videosrc_name, videosrc_name ? strlen(videosrc_name) : 0,
618 MMCAM_AUDIOSRC_ELEMENT_NAME, audiosrc_name, audiosrc_name ? strlen(audiosrc_name) : 0,
620 if (ret != MM_ERROR_NONE)
621 MMCAM_LOG_ERROR("Set FAILED[0x%x]", ret);
627 static void __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder)
630 MMCAM_LOG_ERROR("NULL handle");
634 if (hcamcorder->conf_ctrl)
635 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_ctrl);
637 if (hcamcorder->conf_main)
638 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_main);
644 /*---------------------------------------------------------------------------------------
645 | GLOBAL FUNCTION DEFINITIONS: |
646 ---------------------------------------------------------------------------------------*/
647 /* Internal command functions {*/
648 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
650 int ret = MM_ERROR_NONE;
651 mmf_camcorder_t *hcamcorder = NULL;
653 MMCAM_LOG_INFO("Entered");
655 mmf_return_val_if_fail(handle && info, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
657 /* check device type */
658 if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
659 info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
660 MMCAM_LOG_ERROR("video device type[%d] is out of range.", info->videodev_type);
661 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
665 ret = __mmcamcorder_init_handle(&hcamcorder, info->videodev_type);
666 if (ret != MM_ERROR_NONE)
669 /* set network camera flag */
670 hcamcorder->is_network = (gboolean)info->reserved[0];
672 /* get DPM handle for camera/microphone restriction */
673 hcamcorder->dpm_handle = dpm_manager_create();
675 MMCAM_LOG_WARNING("DPM handle %p", hcamcorder->dpm_handle);
677 ret = __mmcamcorder_init_configure_common(hcamcorder);
678 if (ret != MM_ERROR_NONE)
679 goto _ERR_DEFAULT_VALUE_INIT;
681 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
682 ret = __mmcamcorder_init_configure_video_capture(hcamcorder);
683 if (ret != MM_ERROR_NONE)
684 goto _ERR_DEFAULT_VALUE_INIT;
686 /* add DPM camera policy changed callback */
687 if (hcamcorder->dpm_handle) {
688 ret = dpm_add_policy_changed_cb(hcamcorder->dpm_handle, "camera",
689 _mmcamcorder_dpm_camera_policy_changed_cb, (void *)hcamcorder, &hcamcorder->dpm_camera_cb_id);
690 if (ret != DPM_ERROR_NONE) {
691 MMCAM_LOG_ERROR("add DPM changed cb failed, keep going...");
692 hcamcorder->dpm_camera_cb_id = 0;
695 MMCAM_LOG_INFO("DPM camera changed cb id %d", hcamcorder->dpm_camera_cb_id);
698 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
699 /* initialize resource manager */
700 ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
701 __mmcamcorder_resource_release_cb, hcamcorder,
702 &hcamcorder->resource_manager);
703 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
704 MMCAM_LOG_ERROR("failed to initialize resource manager");
705 ret = MM_ERROR_CAMCORDER_INTERNAL;
706 goto _ERR_DEFAULT_VALUE_INIT;
708 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
710 ret = __mmcamcorder_init_configure_audio(hcamcorder);
711 if (ret != MM_ERROR_NONE)
712 goto _ERR_DEFAULT_VALUE_INIT;
715 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:CREATE:INIT_GSTREAMER");
717 ret = __mmcamcorder_init_gstreamer(hcamcorder->conf_main);
719 traceEnd(TTRACE_TAG_CAMERA);
722 MMCAM_LOG_ERROR("Failed to initialize gstreamer!!");
723 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
724 goto _ERR_DEFAULT_VALUE_INIT;
727 /* Make some attributes as read-only type */
728 _mmcamcorder_lock_readonly_attributes((MMHandleType)hcamcorder);
730 /* Disable attributes in each model */
731 _mmcamcorder_set_disabled_attributes((MMHandleType)hcamcorder);
733 /* get system information */
734 __mmcamcorder_get_system_info(hcamcorder);
736 /* Set initial state */
737 _mmcamcorder_set_state((MMHandleType)hcamcorder, MM_CAMCORDER_STATE_NULL);
739 MMCAM_LOG_INFO("created handle %p", hcamcorder);
741 *handle = (MMHandleType)hcamcorder;
743 return MM_ERROR_NONE;
745 _ERR_DEFAULT_VALUE_INIT:
746 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
747 /* de-initialize resource manager */
748 if (hcamcorder->resource_manager != NULL)
749 mm_resource_manager_destroy(hcamcorder->resource_manager);
750 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
752 /* release DPM related handle */
753 if (hcamcorder->dpm_handle) {
754 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
755 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
757 /* remove camera policy changed callback */
758 if (hcamcorder->dpm_camera_cb_id > 0) {
759 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
760 hcamcorder->dpm_camera_cb_id = 0;
762 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
765 dpm_manager_destroy(hcamcorder->dpm_handle);
766 hcamcorder->dpm_handle = NULL;
769 /* release configure info */
770 __mmcamcorder_deinit_configure(hcamcorder);
772 /* deinitialize handle */
773 __mmcamcorder_deinit_handle(hcamcorder);
779 int _mmcamcorder_destroy(MMHandleType handle)
781 int ret = MM_ERROR_NONE;
782 int state = MM_CAMCORDER_STATE_NONE;
783 GstElement *sink_element = NULL;
784 int sink_element_size = 0;
786 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
791 MMCAM_LOG_ERROR("Not initialized");
792 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
793 goto _ERR_CAMCORDER_CMD_PRECON;
796 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
797 MMCAM_LOG_ERROR("Another command is running.");
798 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
799 goto _ERR_CAMCORDER_CMD_PRECON;
802 state = _mmcamcorder_get_state(handle);
803 if (state != MM_CAMCORDER_STATE_NULL) {
804 MMCAM_LOG_ERROR("Wrong state(%d)", state);
805 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
806 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
809 /* remove kept, but not used sink element in attribute */
810 mm_camcorder_get_attributes(handle, NULL,
811 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
814 GstStateChangeReturn result = gst_element_set_state(sink_element, GST_STATE_NULL);
816 MMCAM_LOG_WARNING("remove sink element %p, set state NULL result %d", sink_element, result);
818 gst_object_unref(sink_element);
822 /* wait for completion of sound play */
823 _mmcamcorder_sound_solo_play_wait(handle);
825 /* Release SubContext and pipeline */
826 if (hcamcorder->sub_context) {
827 if (hcamcorder->sub_context->element)
828 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
830 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
831 hcamcorder->sub_context = NULL;
834 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
835 /* de-initialize resource manager */
836 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
838 if (hcamcorder->resource_manager != NULL) {
839 ret = mm_resource_manager_destroy(hcamcorder->resource_manager);
840 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
841 MMCAM_LOG_ERROR("failed to de-initialize resource manager 0x%x", ret);
844 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
845 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
847 /* Remove messages which are not called yet */
848 _mmcamcorder_remove_message_all(handle);
850 #ifdef _MMCAMCORDER_RM_SUPPORT
851 _mmcamcorder_rm_release(handle);
852 #endif /* _MMCAMCORDER_RM_SUPPORT */
854 /* release DPM handle */
855 if (hcamcorder->dpm_handle) {
856 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
857 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
859 /* remove camera policy changed callback */
860 if (hcamcorder->dpm_camera_cb_id > 0) {
861 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
862 hcamcorder->dpm_camera_cb_id = 0;
864 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
867 dpm_manager_destroy(hcamcorder->dpm_handle);
868 hcamcorder->dpm_handle = NULL;
871 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
873 __mmcamcorder_deinit_handle(hcamcorder);
875 return MM_ERROR_NONE;
877 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
878 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
880 _ERR_CAMCORDER_CMD_PRECON:
882 MMCAM_LOG_ERROR("Destroy fail (type %d, state %d)", hcamcorder->type, state);
884 MMCAM_LOG_ERROR("Destroy fail (ret %x)", ret);
890 int _mmcamcorder_realize(MMHandleType handle)
892 int ret = MM_ERROR_NONE;
893 int state = MM_CAMCORDER_STATE_NONE;
894 int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
895 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
896 char *videosink_element_type = NULL;
897 const char *videosink_name = NULL;
898 char *socket_path = NULL;
899 int socket_path_len = 0;
902 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
904 /*MMCAM_LOG_INFO("");*/
907 MMCAM_LOG_ERROR("Not initialized");
908 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
912 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
913 MMCAM_LOG_ERROR("Another command is running.");
914 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
915 goto _ERR_CAMCORDER_CMD_PRECON;
918 state = _mmcamcorder_get_state(handle);
919 if (state != MM_CAMCORDER_STATE_NULL) {
920 MMCAM_LOG_ERROR("Wrong state(%d)", state);
921 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
922 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
925 /* Get profile mode and gdbus connection */
926 mm_camcorder_get_attributes(handle, NULL,
927 MMCAM_MODE, &hcamcorder->type,
928 MMCAM_GDBUS_CONNECTION, &hcamcorder->gdbus_conn, &conn_size,
931 if (!hcamcorder->gdbus_conn) {
932 MMCAM_LOG_ERROR("gdbus connection NULL");
933 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
934 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
937 MMCAM_LOG_INFO("Profile mode [%d], gdbus connection [%p]",
938 hcamcorder->type, hcamcorder->gdbus_conn);
940 mm_camcorder_get_attributes(handle, NULL,
941 MMCAM_DISPLAY_SURFACE, &display_surface_type,
942 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
945 /* alloc sub context */
946 hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
947 if (!hcamcorder->sub_context) {
948 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
949 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
952 /* Set basic configure information */
953 if (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE)
954 hcamcorder->sub_context->is_modified_rate = TRUE;
956 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
957 CONFIGURE_CATEGORY_MAIN_CAPTURE,
959 &(hcamcorder->sub_context->bencbin_capture));
960 MMCAM_LOG_WARNING("UseEncodebin [%d]", hcamcorder->sub_context->bencbin_capture);
962 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
963 /* get video recording info */
964 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
965 CONFIGURE_CATEGORY_MAIN_RECORD,
967 &(hcamcorder->sub_context->info_video->support_dual_stream));
968 MMCAM_LOG_WARNING("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
970 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
971 CONFIGURE_CATEGORY_MAIN_RECORD,
973 &(hcamcorder->sub_context->info_video->use_videoscale));
974 MMCAM_LOG_WARNING("UseVideoscale [%d]", hcamcorder->sub_context->info_video->use_videoscale);
977 switch (display_surface_type) {
978 case MM_DISPLAY_SURFACE_OVERLAY:
979 videosink_element_type = strdup("VideosinkElementOverlay");
981 case MM_DISPLAY_SURFACE_EVAS:
982 videosink_element_type = strdup("VideosinkElementEvas");
984 case MM_DISPLAY_SURFACE_GL:
985 videosink_element_type = strdup("VideosinkElementGL");
987 case MM_DISPLAY_SURFACE_NULL:
988 videosink_element_type = strdup("VideosinkElementNull");
990 case MM_DISPLAY_SURFACE_REMOTE:
991 mm_camcorder_get_attributes(handle, NULL,
992 MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
994 if (socket_path == NULL) {
995 MMCAM_LOG_WARNING("REMOTE surface, but socket path is NULL -> to NullSink");
996 videosink_element_type = strdup("VideosinkElementNull");
998 videosink_element_type = strdup("VideosinkElementRemote");
1002 videosink_element_type = strdup("VideosinkElementOverlay");
1006 /* check string of videosink element */
1007 if (videosink_element_type) {
1008 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1009 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1010 videosink_element_type,
1011 &hcamcorder->sub_context->VideosinkElement);
1012 free(videosink_element_type);
1013 videosink_element_type = NULL;
1015 MMCAM_LOG_WARNING("strdup failed(display_surface_type %d). Use default X type",
1016 display_surface_type);
1018 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1019 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1020 _MMCAMCORDER_DEFAULT_VIDEOSINK_TYPE,
1021 &hcamcorder->sub_context->VideosinkElement);
1024 _mmcamcorder_conf_get_value_element_name(hcamcorder->sub_context->VideosinkElement, &videosink_name);
1025 MMCAM_LOG_INFO("Videosink name : %s", videosink_name);
1027 /* get videoconvert element */
1028 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1029 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1030 "VideoconvertElement",
1031 &hcamcorder->sub_context->VideoconvertElement);
1033 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1034 CONFIGURE_CATEGORY_CTRL_CAPTURE,
1035 "SensorEncodedCapture",
1036 &(hcamcorder->sub_context->SensorEncodedCapture));
1037 MMCAM_LOG_INFO("Support sensor encoded capture : %d", hcamcorder->sub_context->SensorEncodedCapture);
1039 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1040 int dpm_camera_state = DPM_ALLOWED;
1042 /* check camera policy from DPM */
1043 if (hcamcorder->dpm_handle) {
1044 if (dpm_restriction_get_camera_state(hcamcorder->dpm_handle, &dpm_camera_state) == DPM_ERROR_NONE) {
1045 MMCAM_LOG_INFO("DPM camera state %d", dpm_camera_state);
1046 if (dpm_camera_state == DPM_DISALLOWED) {
1047 MMCAM_LOG_ERROR("CAMERA DISALLOWED by DPM");
1048 ret = MM_ERROR_POLICY_RESTRICTED;
1050 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
1052 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1055 MMCAM_LOG_ERROR("get DPM camera state failed, keep going...");
1058 MMCAM_LOG_WARNING("NULL dpm_handle");
1061 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1062 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1063 /* prepare resource manager for camera */
1064 if (hcamcorder->camera_resource == NULL) {
1065 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1066 MM_RESOURCE_MANAGER_RES_TYPE_CAMERA,
1068 &hcamcorder->camera_resource);
1069 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1070 MMCAM_LOG_ERROR("could not prepare for camera resource");
1071 ret = MM_ERROR_RESOURCE_INTERNAL;
1072 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1073 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1076 MMCAM_LOG_INFO("camera already acquired");
1079 /* prepare resource manager for "video_overlay only if display surface is X" */
1080 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
1081 if (hcamcorder->video_overlay_resource == NULL) {
1082 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1083 MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY,
1084 MM_RESOURCE_MANAGER_RES_VOLUME_FULL,
1085 &hcamcorder->video_overlay_resource);
1086 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1087 MMCAM_LOG_ERROR("could not prepare for overlay resource");
1088 ret = MM_ERROR_RESOURCE_INTERNAL;
1089 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1090 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1093 MMCAM_LOG_INFO("overlay already acquired");
1097 /* acquire resources */
1098 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1099 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1100 MMCAM_LOG_ERROR("could not acquire resources");
1101 ret = MM_ERROR_RESOURCE_INTERNAL;
1102 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1103 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1105 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1106 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1108 #ifdef _MMCAMCORDER_RM_SUPPORT
1109 ret = _mmcamcorder_rm_create(handle);
1110 if (ret != MM_ERROR_NONE) {
1111 MMCAM_LOG_ERROR("Resource create failed");
1112 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1114 ret = _mmcamcorder_rm_allocate(handle);
1115 if (ret != MM_ERROR_NONE) {
1116 MMCAM_LOG_ERROR("Resource allocation request failed");
1117 _mmcamcorder_rm_release(handle);
1118 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1120 #endif /* _MMCAMCORDER_RM_SUPPORT */
1123 /* create pipeline */
1124 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:CREATE_PIPELINE");
1126 ret = _mmcamcorder_create_pipeline(handle, hcamcorder->type);
1128 traceEnd(TTRACE_TAG_CAMERA);
1130 if (ret != MM_ERROR_NONE) {
1131 /* check internal error of gstreamer */
1132 if (hcamcorder->error_code != MM_ERROR_NONE) {
1133 ret = hcamcorder->error_code;
1134 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1137 /* release sub context */
1138 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1139 hcamcorder->sub_context = NULL;
1140 goto _ERR_CAMCORDER_CMD;
1143 /* set command function */
1144 ret = _mmcamcorder_set_functions(handle, hcamcorder->type);
1145 if (ret != MM_ERROR_NONE) {
1146 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1147 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1148 hcamcorder->sub_context = NULL;
1149 goto _ERR_CAMCORDER_CMD;
1152 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1154 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1156 return MM_ERROR_NONE;
1159 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1160 /* release hw resources */
1161 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1162 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1163 if (hcamcorder->camera_resource != NULL) {
1164 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1165 hcamcorder->camera_resource);
1166 hcamcorder->camera_resource = NULL;
1168 if (hcamcorder->video_overlay_resource != NULL) {
1169 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1170 hcamcorder->video_overlay_resource);
1171 hcamcorder->video_overlay_resource = NULL;
1173 mm_resource_manager_commit(hcamcorder->resource_manager);
1175 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1176 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1177 #ifdef _MMCAMCORDER_RM_SUPPORT
1178 _mmcamcorder_rm_deallocate(handle);
1179 _mmcamcorder_rm_release(handle);
1180 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1182 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1183 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1185 _ERR_CAMCORDER_CMD_PRECON:
1186 MMCAM_LOG_ERROR("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1192 int _mmcamcorder_unrealize(MMHandleType handle)
1194 int ret = MM_ERROR_NONE;
1195 int state = MM_CAMCORDER_STATE_NONE;
1197 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1202 MMCAM_LOG_ERROR("Not initialized");
1203 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1207 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1208 MMCAM_LOG_ERROR("Another command is running.");
1209 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1210 goto _ERR_CAMCORDER_CMD_PRECON;
1213 state = _mmcamcorder_get_state(handle);
1214 if (state != MM_CAMCORDER_STATE_READY) {
1215 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1216 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1217 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1220 /* Release SubContext */
1221 if (hcamcorder->sub_context) {
1222 /* destroy pipeline */
1223 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1224 /* Deallocate SubContext */
1225 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1226 hcamcorder->sub_context = NULL;
1229 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1230 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1231 MMCAM_LOG_WARNING("lock resource - cb calling %d", hcamcorder->is_release_cb_calling);
1233 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE &&
1234 hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM &&
1235 hcamcorder->is_release_cb_calling == FALSE) {
1237 /* release resource */
1238 if (hcamcorder->camera_resource != NULL) {
1239 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1240 hcamcorder->camera_resource);
1241 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1242 MMCAM_LOG_ERROR("could not mark camera resource for release");
1243 ret = MM_ERROR_CAMCORDER_INTERNAL;
1244 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1245 MMCAM_LOG_INFO("unlock resource");
1246 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1250 if (hcamcorder->video_overlay_resource != NULL) {
1251 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1252 hcamcorder->video_overlay_resource);
1253 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1254 MMCAM_LOG_ERROR("could not mark overlay resource for release");
1255 ret = MM_ERROR_CAMCORDER_INTERNAL;
1256 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1257 MMCAM_LOG_INFO("unlock resource");
1258 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1262 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1264 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1265 MMCAM_LOG_ERROR("failed to release resource, ret(0x%x)", ret);
1266 ret = MM_ERROR_CAMCORDER_INTERNAL;
1268 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1269 MMCAM_LOG_INFO("unlock resource");
1271 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1273 if (hcamcorder->camera_resource != NULL)
1274 hcamcorder->camera_resource = NULL;
1275 if (hcamcorder->video_overlay_resource != NULL)
1276 hcamcorder->video_overlay_resource = NULL;
1280 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1282 MMCAM_LOG_WARNING("unlock resource");
1283 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1285 #ifdef _MMCAMCORDER_RM_SUPPORT
1286 _mmcamcorder_rm_deallocate(handle);
1287 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1289 /* Deinitialize main context member */
1290 hcamcorder->command = NULL;
1292 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1294 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
1296 return MM_ERROR_NONE;
1298 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1299 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1301 _ERR_CAMCORDER_CMD_PRECON:
1303 MMCAM_LOG_ERROR("Unrealize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1308 int _mmcamcorder_start(MMHandleType handle)
1310 int ret = MM_ERROR_NONE;
1311 int state = MM_CAMCORDER_STATE_NONE;
1313 _MMCamcorderSubContext *sc = NULL;
1314 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1319 MMCAM_LOG_ERROR("Not initialized");
1320 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1324 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1325 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1327 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1328 MMCAM_LOG_ERROR("Another command is running.");
1329 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1330 goto _ERR_CAMCORDER_CMD_PRECON;
1333 state = _mmcamcorder_get_state(handle);
1334 if (state != MM_CAMCORDER_STATE_READY) {
1335 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1336 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1337 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1340 /* initialize error code */
1341 hcamcorder->error_code = MM_ERROR_NONE;
1343 /* set attributes related sensor */
1344 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1345 _mmcamcorder_set_attribute_to_camsensor(handle);
1347 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1348 if (ret != MM_ERROR_NONE) {
1349 /* check internal error of gstreamer */
1350 if (hcamcorder->error_code != MM_ERROR_NONE) {
1351 ret = hcamcorder->error_code;
1352 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1354 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1357 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1359 /* set attributes related sensor - after start preview */
1360 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1361 _mmcamcorder_set_attribute_to_camsensor2(handle);
1363 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1365 return MM_ERROR_NONE;
1367 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1368 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1370 _ERR_CAMCORDER_CMD_PRECON:
1371 /* check internal error of gstreamer */
1372 if (hcamcorder->error_code != MM_ERROR_NONE) {
1373 ret = hcamcorder->error_code;
1374 hcamcorder->error_code = MM_ERROR_NONE;
1376 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1379 MMCAM_LOG_ERROR("Start fail (type %d, state %d, ret %x)",
1380 hcamcorder->type, state, ret);
1385 int _mmcamcorder_stop(MMHandleType handle)
1387 int ret = MM_ERROR_NONE;
1388 int state = MM_CAMCORDER_STATE_NONE;
1390 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1395 MMCAM_LOG_ERROR("Not initialized");
1396 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1400 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1401 MMCAM_LOG_ERROR("Another command is running.");
1402 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1403 goto _ERR_CAMCORDER_CMD_PRECON;
1406 state = _mmcamcorder_get_state(handle);
1407 if (state != MM_CAMCORDER_STATE_PREPARE) {
1408 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1409 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1410 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1413 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_STOP);
1414 if (ret != MM_ERROR_NONE)
1415 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1417 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1419 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1420 /* unsubscribe remained unsubscribed signal */
1421 g_mutex_lock(&hcamcorder->gdbus_info_sound.sync_mutex);
1422 if (hcamcorder->gdbus_info_sound.subscribe_id > 0) {
1423 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_sound.subscribe_id);
1424 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_sound.subscribe_id);
1426 g_mutex_unlock(&hcamcorder->gdbus_info_sound.sync_mutex);
1428 g_mutex_lock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1429 if (hcamcorder->gdbus_info_solo_sound.subscribe_id > 0) {
1430 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_solo_sound.subscribe_id);
1431 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_solo_sound.subscribe_id);
1433 g_mutex_unlock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1436 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1438 return MM_ERROR_NONE;
1440 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1441 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1443 _ERR_CAMCORDER_CMD_PRECON:
1445 MMCAM_LOG_ERROR("Stop fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1451 int _mmcamcorder_capture_start(MMHandleType handle)
1453 int ret = MM_ERROR_NONE;
1454 int state = MM_CAMCORDER_STATE_NONE;
1455 int state_FROM_0 = MM_CAMCORDER_STATE_PREPARE;
1456 int state_FROM_1 = MM_CAMCORDER_STATE_RECORDING;
1457 int state_FROM_2 = MM_CAMCORDER_STATE_PAUSED;
1459 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1464 MMCAM_LOG_ERROR("Not initialized");
1465 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1469 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1470 MMCAM_LOG_ERROR("Another command is running.");
1471 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1472 goto _ERR_CAMCORDER_CMD_PRECON;
1475 state = _mmcamcorder_get_state(handle);
1476 if (state != state_FROM_0 && state != state_FROM_1 && state != state_FROM_2) {
1477 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1478 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1479 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1482 /* Handle capture in recording case */
1483 if (state == state_FROM_1 || state == state_FROM_2) {
1484 if (hcamcorder->capture_in_recording == TRUE) {
1485 MMCAM_LOG_ERROR("Capturing in recording (%d)", state);
1486 ret = MM_ERROR_CAMCORDER_DEVICE_BUSY;
1487 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1489 g_mutex_lock(&hcamcorder->task_thread_lock);
1490 if (hcamcorder->task_thread_state == _MMCAMCORDER_TASK_THREAD_STATE_NONE) {
1491 hcamcorder->capture_in_recording = TRUE;
1492 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING;
1493 MMCAM_LOG_INFO("send signal for capture in recording");
1494 g_cond_signal(&hcamcorder->task_thread_cond);
1495 g_mutex_unlock(&hcamcorder->task_thread_lock);
1497 MMCAM_LOG_ERROR("task thread busy : %d", hcamcorder->task_thread_state);
1498 g_mutex_unlock(&hcamcorder->task_thread_lock);
1499 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1500 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1505 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CAPTURE);
1506 if (ret != MM_ERROR_NONE)
1507 goto _ERR_CAMCORDER_CMD;
1509 /* Do not change state when recording snapshot capture */
1510 if (state == state_FROM_0)
1511 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_CAPTURING);
1513 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1515 /* Init break continuous shot attr */
1516 if (mm_camcorder_set_attributes(handle, NULL, MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, 0, NULL) != MM_ERROR_NONE)
1517 MMCAM_LOG_WARNING("capture-break-cont-shot set 0 failed");
1519 return MM_ERROR_NONE;
1522 if (hcamcorder->capture_in_recording)
1523 hcamcorder->capture_in_recording = FALSE;
1525 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1526 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1528 _ERR_CAMCORDER_CMD_PRECON:
1530 MMCAM_LOG_ERROR("Capture start fail (type %d, state %d, ret %x)",
1531 hcamcorder->type, state, ret);
1536 int _mmcamcorder_capture_stop(MMHandleType handle)
1538 int ret = MM_ERROR_NONE;
1539 int state = MM_CAMCORDER_STATE_NONE;
1540 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1545 MMCAM_LOG_ERROR("Not initialized");
1546 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1550 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1551 MMCAM_LOG_ERROR("Another command is running.");
1552 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1553 goto _ERR_CAMCORDER_CMD_PRECON;
1556 state = _mmcamcorder_get_state(handle);
1557 if (state != MM_CAMCORDER_STATE_CAPTURING) {
1558 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1559 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1560 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1563 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1564 if (ret != MM_ERROR_NONE)
1565 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1567 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1569 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1571 return MM_ERROR_NONE;
1573 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1574 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1576 _ERR_CAMCORDER_CMD_PRECON:
1578 MMCAM_LOG_ERROR("Capture stop fail (type %d, state %d, ret %x)",
1579 hcamcorder->type, state, ret);
1584 int _mmcamcorder_record(MMHandleType handle)
1586 int ret = MM_ERROR_NONE;
1587 int state = MM_CAMCORDER_STATE_NONE;
1588 int dpm_mic_state = DPM_ALLOWED;
1590 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1591 _MMCamcorderSubContext *sc = NULL;
1595 if (!hcamcorder || !MMF_CAMCORDER_SUBCONTEXT(hcamcorder)) {
1596 MMCAM_LOG_ERROR("Not initialized");
1597 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1601 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1603 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1604 MMCAM_LOG_ERROR("Another command is running.");
1605 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1606 goto _ERR_CAMCORDER_CMD_PRECON;
1609 state = _mmcamcorder_get_state(handle);
1610 if (state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_PAUSED) {
1611 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1612 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1613 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1616 /* initialize error code */
1617 hcamcorder->error_code = MM_ERROR_NONE;
1619 /* get audio disable */
1620 mm_camcorder_get_attributes(handle, NULL,
1621 MMCAM_AUDIO_DISABLE, &sc->audio_disable,
1624 sc->audio_disable |= sc->is_modified_rate;
1626 /* check mic policy from DPM */
1627 if (hcamcorder->dpm_handle && sc->audio_disable == FALSE) {
1628 if (dpm_restriction_get_microphone_state(hcamcorder->dpm_handle, &dpm_mic_state) == DPM_ERROR_NONE) {
1629 MMCAM_LOG_INFO("DPM mic state %d", dpm_mic_state);
1630 if (dpm_mic_state == DPM_DISALLOWED) {
1631 MMCAM_LOG_ERROR("MIC DISALLOWED by DPM");
1632 ret = MM_ERROR_COMMON_INVALID_PERMISSION;
1634 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
1636 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1639 MMCAM_LOG_ERROR("get DPM mic state failed, keep going...");
1642 MMCAM_LOG_WARNING("skip dpm check - handle %p, audio disable %d",
1643 hcamcorder->dpm_handle, sc->audio_disable);
1646 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_RECORD);
1647 if (ret != MM_ERROR_NONE) {
1648 /* check internal error of gstreamer */
1649 if (hcamcorder->error_code != MM_ERROR_NONE) {
1650 ret = hcamcorder->error_code;
1651 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1653 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1656 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_RECORDING);
1658 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1660 return MM_ERROR_NONE;
1662 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1663 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1665 _ERR_CAMCORDER_CMD_PRECON:
1666 /* check internal error of gstreamer */
1667 if (hcamcorder->error_code != MM_ERROR_NONE) {
1668 ret = hcamcorder->error_code;
1669 hcamcorder->error_code = MM_ERROR_NONE;
1671 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1674 MMCAM_LOG_ERROR("Record fail (type %d, state %d, ret %x)",
1675 hcamcorder->type, state, ret);
1681 int _mmcamcorder_pause(MMHandleType handle)
1683 int ret = MM_ERROR_NONE;
1684 int state = MM_CAMCORDER_STATE_NONE;
1686 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1691 MMCAM_LOG_ERROR("Not initialized");
1692 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1696 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1697 MMCAM_LOG_ERROR("Another command is running.");
1698 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1699 goto _ERR_CAMCORDER_CMD_PRECON;
1702 state = _mmcamcorder_get_state(handle);
1703 if (state != MM_CAMCORDER_STATE_RECORDING) {
1704 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1705 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1706 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1709 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PAUSE);
1710 if (ret != MM_ERROR_NONE)
1711 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1713 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PAUSED);
1715 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1717 return MM_ERROR_NONE;
1719 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1720 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1722 _ERR_CAMCORDER_CMD_PRECON:
1724 MMCAM_LOG_ERROR("Pause fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1730 int _mmcamcorder_commit(MMHandleType handle)
1732 int ret = MM_ERROR_NONE;
1733 int state = MM_CAMCORDER_STATE_NONE;
1735 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1740 MMCAM_LOG_ERROR("Not initialized");
1741 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1745 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1746 MMCAM_LOG_ERROR("Another command is running.");
1747 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1748 goto _ERR_CAMCORDER_CMD_PRECON;
1751 state = _mmcamcorder_get_state(handle);
1752 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1753 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1754 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1755 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1758 /* initialize error code */
1759 hcamcorder->error_code = MM_ERROR_NONE;
1761 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_COMMIT);
1762 if (ret != MM_ERROR_NONE)
1763 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1765 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1767 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1769 return MM_ERROR_NONE;
1771 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1772 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1774 _ERR_CAMCORDER_CMD_PRECON:
1776 MMCAM_LOG_ERROR("Commit fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1782 int _mmcamcorder_cancel(MMHandleType handle)
1784 int ret = MM_ERROR_NONE;
1785 int state = MM_CAMCORDER_STATE_NONE;
1787 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1792 MMCAM_LOG_ERROR("Not initialized");
1793 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1797 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1798 MMCAM_LOG_ERROR("Another command is running.");
1799 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1800 goto _ERR_CAMCORDER_CMD_PRECON;
1803 state = _mmcamcorder_get_state(handle);
1804 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1805 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1806 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1807 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1810 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CANCEL);
1811 if (ret != MM_ERROR_NONE)
1812 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1814 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1816 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1818 return MM_ERROR_NONE;
1820 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1821 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1823 _ERR_CAMCORDER_CMD_PRECON:
1825 MMCAM_LOG_ERROR("Cancel fail (type %d, state %d, ret %x)",
1826 hcamcorder->type, state, ret);
1830 /* } Internal command functions */
1833 int _mmcamcorder_commit_async_end(MMHandleType handle)
1837 MMCAM_LOG_WARNING("_mmcamcorder_commit_async_end : MM_CAMCORDER_STATE_PREPARE");
1838 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1840 return MM_ERROR_NONE;
1844 int _mmcamcorder_set_message_callback(MMHandleType handle, MMMessageCallback callback, void *user_data)
1846 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1848 MMCAM_LOG_INFO("%p", hcamcorder);
1850 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1852 if (callback == NULL)
1853 MMCAM_LOG_WARNING("Message Callback is disabled, because application sets it to NULL");
1855 if (!_MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(hcamcorder)) {
1856 MMCAM_LOG_WARNING("Application's message callback is running now");
1857 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1860 /* set message callback to message handle */
1861 hcamcorder->msg_cb = callback;
1862 hcamcorder->msg_cb_param = user_data;
1864 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1866 return MM_ERROR_NONE;
1870 int _mmcamcorder_set_video_stream_callback(MMHandleType handle, mm_camcorder_video_stream_callback callback, void *user_data)
1872 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1874 /*MMCAM_LOG_INFO("");*/
1876 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1878 if (callback == NULL)
1879 MMCAM_LOG_WARNING("Video Stream Callback is disabled, because application sets it to NULL");
1881 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
1883 hcamcorder->vstream_cb = callback;
1884 hcamcorder->vstream_cb_param = user_data;
1886 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1888 return MM_ERROR_NONE;
1892 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle, mm_camcorder_audio_stream_callback callback, void *user_data)
1894 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1898 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1900 if (callback == NULL)
1901 MMCAM_LOG_WARNING("Audio Stream Callback is disabled, because application sets it to NULL");
1903 if (!_MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(hcamcorder)) {
1904 MMCAM_LOG_WARNING("Application's audio stream callback is running now");
1905 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1908 hcamcorder->astream_cb = callback;
1909 hcamcorder->astream_cb_param = user_data;
1911 _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder);
1913 return MM_ERROR_NONE;
1917 int _mmcamcorder_set_muxed_stream_callback(MMHandleType handle, mm_camcorder_muxed_stream_callback callback, void *user_data)
1919 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1923 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1925 if (callback == NULL)
1926 MMCAM_LOG_WARNING("Muxed Stream Callback is disabled, because application sets it to NULL");
1928 if (!_MMCAMCORDER_TRYLOCK_MSTREAM_CALLBACK(hcamcorder)) {
1929 MMCAM_LOG_WARNING("Application's muxed stream callback is running now");
1930 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1933 hcamcorder->mstream_cb = callback;
1934 hcamcorder->mstream_cb_param = user_data;
1936 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
1938 return MM_ERROR_NONE;
1942 int _mmcamcorder_set_video_capture_callback(MMHandleType handle, mm_camcorder_video_capture_callback callback, void *user_data)
1944 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1948 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1950 if (callback == NULL)
1951 MMCAM_LOG_WARNING("Video Capture Callback is disabled, because application sets it to NULLL");
1953 if (!_MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(hcamcorder)) {
1954 MMCAM_LOG_WARNING("Application's video capture callback is running now");
1955 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1958 hcamcorder->vcapture_cb = callback;
1959 hcamcorder->vcapture_cb_param = user_data;
1961 _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(hcamcorder);
1963 return MM_ERROR_NONE;
1967 int _mmcamcorder_set_video_encode_decision_callback(MMHandleType handle, mm_camcorder_video_encode_decision_callback callback, void *user_data)
1969 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1973 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1975 if (callback == NULL)
1976 MMCAM_LOG_WARNING("Video Encode Decision Callback is disabled, because application sets it to NULL");
1978 if (!_MMCAMCORDER_TRYLOCK_VEDECISION_CALLBACK(hcamcorder)) {
1979 MMCAM_LOG_WARNING("Application's video encode decision callback is running now");
1980 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1983 hcamcorder->vedecision_cb = callback;
1984 hcamcorder->vedecision_cb_param = user_data;
1986 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
1988 return MM_ERROR_NONE;
1992 int _mmcamcorder_get_current_state(MMHandleType handle)
1994 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1998 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2000 return _mmcamcorder_get_state(handle);
2003 int _mmcamcorder_init_focusing(MMHandleType handle)
2006 int state = MM_CAMCORDER_STATE_NONE;
2007 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2008 int af_range = MM_CAMCORDER_AUTO_FOCUS_NORMAL;
2009 int sensor_focus_mode = 0;
2010 int sensor_af_range = 0;
2011 int current_focus_mode = 0;
2012 int current_af_range = 0;
2013 mmf_camcorder_t *hcamcorder = NULL;
2014 _MMCamcorderSubContext *sc = NULL;
2015 GstCameraControl *control = NULL;
2019 hcamcorder = MMF_CAMCORDER(handle);
2020 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2022 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2023 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2025 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2026 MMCAM_LOG_ERROR("Another command is running.");
2027 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2030 state = _mmcamcorder_get_state(handle);
2032 if (state == MM_CAMCORDER_STATE_CAPTURING ||
2033 state < MM_CAMCORDER_STATE_PREPARE) {
2034 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2035 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2036 return MM_ERROR_CAMCORDER_INVALID_STATE;
2039 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2040 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2041 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2042 return MM_ERROR_NONE;
2045 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2046 if (control == NULL) {
2047 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2048 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2049 return MM_ERROR_CAMCORDER_INTERNAL;
2052 ret = gst_camera_control_stop_auto_focus(control);
2054 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2055 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2056 return MM_ERROR_CAMCORDER_DEVICE_IO;
2059 /* Initialize lens position */
2060 mm_camcorder_get_attributes(handle, NULL,
2061 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2062 MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
2064 sensor_af_range = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_AF_SCAN_RANGE, af_range);
2065 sensor_focus_mode = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_FOCUS_MODE, focus_mode);
2067 gst_camera_control_get_focus(control, ¤t_focus_mode, ¤t_af_range);
2069 if (current_focus_mode != sensor_focus_mode || current_af_range != sensor_af_range) {
2070 ret = gst_camera_control_set_focus(control, sensor_focus_mode, sensor_af_range);
2072 MMCAM_LOG_INFO("No need to init FOCUS [mode:%d, range:%d]", focus_mode, af_range);
2076 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2079 MMCAM_LOG_INFO("Lens init success.");
2080 return MM_ERROR_NONE;
2082 MMCAM_LOG_ERROR("Lens init fail.");
2083 return MM_ERROR_CAMCORDER_DEVICE_IO;
2087 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction)
2090 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2091 int ret = MM_ERROR_UNKNOWN;
2092 char *err_attr_name = NULL;
2094 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2095 mmf_return_val_if_fail(direction, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2097 /*MMCAM_LOG_INFO("");*/
2099 if (!_MMCAMCORDER_TRYLOCK_CMD(handle)) {
2100 MMCAM_LOG_ERROR("Another command is running.");
2101 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2104 state = _mmcamcorder_get_state(handle);
2105 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2106 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2107 _MMCAMCORDER_UNLOCK_CMD(handle);
2108 return MM_ERROR_CAMCORDER_INVALID_STATE;
2111 /* TODO : call a auto or manual focus function */
2112 ret = mm_camcorder_get_attributes(handle, &err_attr_name,
2113 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2115 if (ret != MM_ERROR_NONE) {
2116 MMCAM_LOG_WARNING("Get focus-mode fail. (%s:%x)", err_attr_name, ret);
2117 SAFE_FREE(err_attr_name);
2118 _MMCAMCORDER_UNLOCK_CMD(handle);
2122 switch (focus_mode) {
2123 case MM_CAMCORDER_FOCUS_MODE_MANUAL:
2124 ret = _mmcamcorder_adjust_manual_focus(handle, direction);
2126 case MM_CAMCORDER_FOCUS_MODE_AUTO:
2127 case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
2128 case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
2129 ret = _mmcamcorder_adjust_auto_focus(handle);
2132 MMCAM_LOG_ERROR("It doesn't adjust focus. Focusing mode(%d)", focus_mode);
2133 ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2136 _MMCAMCORDER_UNLOCK_CMD(handle);
2141 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction)
2146 int focus_level = 0;
2147 float unit_level = 0;
2148 GstCameraControl *control = NULL;
2149 _MMCamcorderSubContext *sc = NULL;
2150 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2154 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2155 mmf_return_val_if_fail(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL != 1, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
2156 mmf_return_val_if_fail((direction >= MM_CAMCORDER_MF_LENS_DIR_FORWARD) &&
2157 (direction <= MM_CAMCORDER_MF_LENS_DIR_BACKWARD),
2158 MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2160 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2161 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2163 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2164 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2165 return MM_ERROR_NONE;
2168 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2169 if (control == NULL) {
2170 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2171 return MM_ERROR_CAMCORDER_INTERNAL;
2174 /* TODO : get max, min level */
2175 if (max_level - min_level + 1 < _MMFCAMCORDER_FOCUS_TOTAL_LEVEL)
2176 MMCAM_LOG_WARNING("Total level of manual focus of MMF is greater than that of the camera driver.");
2178 unit_level = ((float)max_level - (float)min_level)/(float)(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL - 1);
2180 if (!gst_camera_control_get_focus_level(control, &cur_level)) {
2181 MMCAM_LOG_ERROR("Can't get current level of manual focus.");
2182 return MM_ERROR_CAMCORDER_DEVICE_IO;
2185 /* TODO : adjust unit level value */
2186 if (direction == MM_CAMCORDER_MF_LENS_DIR_FORWARD)
2187 focus_level = cur_level + unit_level;
2188 else if (direction == MM_CAMCORDER_MF_LENS_DIR_BACKWARD)
2189 focus_level = cur_level - unit_level;
2191 if (focus_level > max_level)
2192 focus_level = max_level;
2193 else if (focus_level < min_level)
2194 focus_level = min_level;
2196 if (!gst_camera_control_set_focus_level(control, focus_level)) {
2197 MMCAM_LOG_ERROR("Manual focusing fail.");
2198 return MM_ERROR_CAMCORDER_DEVICE_IO;
2201 return MM_ERROR_NONE;
2205 int _mmcamcorder_adjust_auto_focus(MMHandleType handle)
2208 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2209 GstCameraControl *control = NULL;
2210 _MMCamcorderSubContext *sc = NULL;
2212 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2214 /*MMCAM_LOG_INFO("");*/
2216 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2218 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2219 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2220 return MM_ERROR_NONE;
2223 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2226 ret = gst_camera_control_start_auto_focus(control);
2228 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2233 MMCAM_LOG_INFO("Auto focusing start success.");
2234 return MM_ERROR_NONE;
2236 MMCAM_LOG_ERROR("Auto focusing start fail.");
2237 return MM_ERROR_CAMCORDER_DEVICE_IO;
2241 int _mmcamcorder_stop_focusing(MMHandleType handle)
2243 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2244 _MMCamcorderSubContext *sc = NULL;
2247 GstCameraControl *control = NULL;
2249 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2251 /*MMCAM_LOG_INFO("");*/
2253 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2255 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2256 MMCAM_LOG_ERROR("Another command is running.");
2257 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2260 state = _mmcamcorder_get_state(handle);
2261 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2262 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2263 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2264 return MM_ERROR_CAMCORDER_INVALID_STATE;
2267 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2268 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2269 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2270 return MM_ERROR_NONE;
2273 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2275 ret = gst_camera_control_stop_auto_focus(control);
2277 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2281 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2284 MMCAM_LOG_INFO("Auto focusing stop success.");
2285 return MM_ERROR_NONE;
2287 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2288 return MM_ERROR_CAMCORDER_DEVICE_IO;
2292 int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
2294 GstCameraControl *control = NULL;
2295 _MMCamcorderSubContext *sc = NULL;
2296 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2298 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2299 mmf_return_val_if_fail(level, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2301 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2302 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2304 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2305 MMCAM_LOG_ERROR("Can't cast Video source into camera control.");
2306 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2309 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2311 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2312 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2315 if (!gst_camera_control_get_focus_level(control, level)) {
2316 MMCAM_LOG_ERROR("get focus level failed");
2317 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2320 MMCAM_LOG_INFO("focus level[%d]", *level);
2322 return MM_ERROR_NONE;
2326 /*-----------------------------------------------
2327 | CAMCORDER INTERNAL LOCAL |
2328 -----------------------------------------------*/
2329 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf)
2331 static const int max_argc = 10;
2335 gchar **argv = NULL;
2337 gboolean ret = FALSE;
2338 type_string_array *GSTInitOption = NULL;
2340 mmf_return_val_if_fail(conf, FALSE);
2345 argc = malloc(sizeof(int));
2346 argv = malloc(sizeof(gchar *) * max_argc);
2351 memset(argv, 0, sizeof(gchar *) * max_argc);
2355 argv[0] = g_strdup("mmcamcorder");
2358 _mmcamcorder_conf_get_value_string_array(conf,
2359 CONFIGURE_CATEGORY_MAIN_GENERAL,
2362 if (GSTInitOption != NULL && GSTInitOption->value) {
2363 cnt_str = GSTInitOption->count;
2364 for ( ; *argc < max_argc && *argc <= cnt_str ; (*argc)++)
2365 argv[*argc] = g_strdup(GSTInitOption->value[(*argc)-1]);
2368 MMCAM_LOG_INFO("initializing gstreamer with following parameter[argc:%d]", *argc);
2370 for (i = 0; i < *argc; i++)
2371 MMCAM_LOG_INFO("argv[%d] : %s", i, argv[i]);
2373 /* initializing gstreamer */
2374 ret = gst_init_check(argc, &argv, &err);
2376 MMCAM_LOG_ERROR("Could not initialize GStreamer: %s ", err ? err->message : "unknown error occurred");
2382 for (i = 0; i < *argc; i++) {
2402 MMCAM_LOG_ERROR("failed to initialize gstreamer");
2418 int _mmcamcorder_get_state(MMHandleType handle)
2421 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2423 mmf_return_val_if_fail(hcamcorder, -1);
2425 _MMCAMCORDER_LOCK_STATE(handle);
2427 state = hcamcorder->state;
2428 /*MMCAM_LOG_INFO("state=%d",state);*/
2430 _MMCAMCORDER_UNLOCK_STATE(handle);
2436 int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state)
2438 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2440 mmf_return_val_if_fail(hcamcorder && state && old_state, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2442 _MMCAMCORDER_LOCK_STATE(handle);
2444 *state = hcamcorder->state;
2445 *old_state = hcamcorder->old_state;
2447 _MMCAMCORDER_UNLOCK_STATE(handle);
2449 return MM_ERROR_NONE;
2453 void _mmcamcorder_set_state(MMHandleType handle, int state)
2456 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2457 _MMCamcorderMsgItem msg;
2459 mmf_return_if_fail(hcamcorder);
2461 /*MMCAM_LOG_INFO("");*/
2463 _MMCAMCORDER_LOCK_STATE(handle);
2465 old_state = hcamcorder->state;
2466 if (old_state != state) {
2467 hcamcorder->state = state;
2468 hcamcorder->old_state = old_state;
2470 MMCAM_LOG_INFO("set state[%d -> %d] and send state-changed message", old_state, state);
2472 /* To discern who changes the state */
2473 switch (hcamcorder->state_change_by_system) {
2474 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
2475 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_RM;
2476 msg.param.state.code = MM_ERROR_NONE;
2478 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
2479 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY;
2480 msg.param.state.code = MM_ERROR_NONE;
2482 case _MMCAMCORDER_STATE_CHANGE_NORMAL:
2484 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED;
2485 msg.param.state.code = MM_ERROR_NONE;
2489 msg.param.state.previous = old_state;
2490 msg.param.state.current = state;
2492 /*MMCAM_LOG_INFO("_mmcamcorder_send_message : msg : %p, id:%x", &msg, msg.id);*/
2493 _mmcamcorder_send_message(handle, &msg);
2496 _MMCAMCORDER_UNLOCK_STATE(handle);
2502 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
2505 _MMCamcorderSubContext *sc = NULL;
2507 /*MMCAM_LOG_INFO("");*/
2509 /* alloc container */
2510 sc = (_MMCamcorderSubContext *)g_malloc0(sizeof(_MMCamcorderSubContext));
2512 sc->element_num = _MMCAMCORDER_PIPELINE_ELEMENT_NUM;
2513 sc->encode_element_num = _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM;
2515 /* alloc info for each mode */
2517 case MM_CAMCORDER_MODE_AUDIO:
2518 sc->info_audio = g_malloc0(sizeof(_MMCamcorderAudioInfo));
2520 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2522 sc->info_image = g_malloc0(sizeof(_MMCamcorderImageInfo));
2523 sc->info_video = g_malloc0(sizeof(_MMCamcorderVideoInfo));
2525 sc->info_image->sound_status = _SOUND_STATUS_INIT;
2526 g_mutex_init(&sc->info_video->size_check_lock);
2530 /* alloc element array */
2531 sc->element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->element_num);
2532 sc->encode_element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->encode_element_num);
2534 for (i = 0 ; i < sc->element_num ; i++) {
2535 sc->element[i].id = _MMCAMCORDER_NONE;
2536 sc->element[i].gst = NULL;
2539 for (i = 0 ; i < sc->encode_element_num ; i++) {
2540 sc->encode_element[i].id = _MMCAMCORDER_NONE;
2541 sc->encode_element[i].gst = NULL;
2544 sc->fourcc = 0x80000000;
2545 sc->frame_stability_count = 0;
2546 sc->drop_vframe = 0;
2547 sc->pass_first_vframe = 0;
2548 sc->is_modified_rate = FALSE;
2554 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
2560 MMCAM_LOG_INFO("release element");
2561 g_free(sc->element);
2565 if (sc->encode_element) {
2566 MMCAM_LOG_INFO("release encode_element");
2567 g_free(sc->encode_element);
2568 sc->encode_element = NULL;
2571 if (sc->info_image) {
2572 MMCAM_LOG_INFO("release info_image");
2573 g_free(sc->info_image);
2574 sc->info_image = NULL;
2577 if (sc->info_video) {
2578 MMCAM_LOG_INFO("release info_video");
2579 SAFE_G_FREE(sc->info_video->filename);
2580 g_mutex_clear(&sc->info_video->size_check_lock);
2581 g_free(sc->info_video);
2582 sc->info_video = NULL;
2585 if (sc->info_audio) {
2586 MMCAM_LOG_INFO("release info_audio");
2587 SAFE_G_FREE(sc->info_audio->filename);
2588 g_free(sc->info_audio);
2589 sc->info_audio = NULL;
2600 int _mmcamcorder_set_functions(MMHandleType handle, int type)
2602 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2604 /*MMCAM_LOG_INFO("");*/
2607 case MM_CAMCORDER_MODE_AUDIO:
2608 hcamcorder->command = _mmcamcorder_audio_command;
2610 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2612 hcamcorder->command = _mmcamcorder_video_capture_command;
2616 return MM_ERROR_NONE;
2620 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data)
2622 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2623 _MMCamcorderSubContext *sc = NULL;
2625 mmf_return_val_if_fail(hcamcorder, FALSE);
2626 mmf_return_val_if_fail(message, FALSE);
2628 MMCAM_LOG_DEBUG("message type[0x%x]", GST_MESSAGE_TYPE(message));
2630 switch (GST_MESSAGE_TYPE(message)) {
2631 case GST_MESSAGE_EOS:
2633 MMCAM_LOG_ERROR("Got EOS from element[%s]... but should not be reached here!",
2634 GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));
2637 case GST_MESSAGE_ERROR:
2640 gchar *debug = NULL;
2642 gst_message_parse_error(message, &err, &debug);
2644 __mmcamcorder_handle_gst_error((MMHandleType)hcamcorder, message, err);
2647 MMCAM_LOG_ERROR("GSTERR: %s", err->message);
2653 MMCAM_LOG_ERROR("Error Debug: %s", debug);
2659 case GST_MESSAGE_WARNING:
2663 gst_message_parse_warning(message, &err, &debug);
2665 MMCAM_LOG_WARNING("GSTWARN: %s", err->message);
2667 __mmcamcorder_handle_gst_warning((MMHandleType)hcamcorder, message, err);
2673 case GST_MESSAGE_STATE_CHANGED:
2675 const GValue *vnewstate;
2677 GstElement *pipeline = NULL;
2679 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2680 if ((sc) && (sc->element)) {
2681 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst) {
2682 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
2683 if (message->src == (GstObject*)pipeline) {
2684 vnewstate = gst_structure_get_value(gst_message_get_structure(message), "new-state");
2686 newstate = (GstState)vnewstate->data[0].v_int;
2687 MMCAM_LOG_INFO("GST_MESSAGE_STATE_CHANGED[%s]", gst_element_state_get_name(newstate));
2689 MMCAM_LOG_WARNING("get new state failed from msg");
2696 case GST_MESSAGE_NEW_CLOCK:
2698 GstClock *pipe_clock = NULL;
2699 gst_message_parse_new_clock(message, &pipe_clock);
2700 MMCAM_LOG_INFO("GST_MESSAGE_NEW_CLOCK[%s]", (pipe_clock ? GST_OBJECT_NAME(pipe_clock) : "NULL"));
2704 MMCAM_LOG_DEBUG("unhandled message type[0x%x]", GST_MESSAGE_TYPE(message));
2712 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
2715 gchar *debug_info = NULL;
2717 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2718 _MMCamcorderSubContext *sc = NULL;
2720 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
2721 mmf_return_val_if_fail(message, GST_BUS_DROP);
2723 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2724 mmf_return_val_if_fail(sc, GST_BUS_DROP);
2726 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
2727 /* parse error message */
2728 gst_message_parse_error(message, &err, &debug_info);
2731 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
2737 MMCAM_LOG_WARNING("failed to parse error message");
2738 return GST_BUS_PASS;
2741 /* check domain[RESOURCE] and element[VIDEOSRC] */
2742 if (err->domain == GST_RESOURCE_ERROR &&
2743 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2744 switch (err->code) {
2745 case GST_RESOURCE_ERROR_BUSY:
2746 MMCAM_LOG_ERROR("Camera device [busy]");
2747 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_BUSY;
2749 case GST_RESOURCE_ERROR_OPEN_WRITE:
2750 MMCAM_LOG_ERROR("Camera device [open failed]");
2751 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2753 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2754 MMCAM_LOG_ERROR("Camera device [open failed]");
2755 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN;
2757 case GST_RESOURCE_ERROR_OPEN_READ:
2758 MMCAM_LOG_ERROR("Camera device [register trouble]");
2759 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE;
2761 case GST_RESOURCE_ERROR_NOT_FOUND:
2762 MMCAM_LOG_ERROR("Camera device [device not found]");
2763 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND;
2765 case GST_RESOURCE_ERROR_TOO_LAZY:
2766 MMCAM_LOG_ERROR("Camera device [timeout]");
2767 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_TIMEOUT;
2769 case GST_RESOURCE_ERROR_SETTINGS:
2770 MMCAM_LOG_ERROR("Camera device [not supported]");
2771 hcamcorder->error_code = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2773 case GST_RESOURCE_ERROR_FAILED:
2774 MMCAM_LOG_ERROR("Camera device [working failed].");
2775 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_IO;
2778 MMCAM_LOG_ERROR("Camera device [General(%d)]", err->code);
2779 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE;
2783 hcamcorder->error_occurs = TRUE;
2788 /* store error code and drop this message if cmd is running */
2789 if (hcamcorder->error_code != MM_ERROR_NONE) {
2790 _MMCamcorderMsgItem msg;
2792 /* post error to application */
2793 hcamcorder->error_occurs = TRUE;
2794 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2795 msg.param.code = hcamcorder->error_code;
2796 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2798 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
2799 _MMCamcorderMsgItem msg;
2801 if (gst_structure_has_name(gst_message_get_structure(message), "avsysvideosrc-AF") ||
2802 gst_structure_has_name(gst_message_get_structure(message), "camerasrc-AF")) {
2803 int focus_state = 0;
2805 gst_structure_get_int(gst_message_get_structure(message), "focus-state", &focus_state);
2806 MMCAM_LOG_INFO("Focus State:%d", focus_state);
2808 msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED;
2809 msg.param.code = focus_state;
2810 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2811 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) {
2815 if (gst_structure_get_int(gst_message_get_structure(message), "progress", &progress)) {
2816 gst_structure_get_int(gst_message_get_structure(message), "status", &status);
2817 MMCAM_LOG_INFO("HDR progress %d percent, status %d", progress, status);
2819 msg.id = MM_MESSAGE_CAMCORDER_HDR_PROGRESS;
2820 msg.param.code = progress;
2821 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2823 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) {
2825 const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");;
2826 GstCameraControlFaceDetectInfo *fd_info = NULL;
2827 MMCamFaceDetectInfo *cam_fd_info = NULL;
2830 fd_info = (GstCameraControlFaceDetectInfo *)g_value_get_pointer(g_value);
2832 if (fd_info == NULL) {
2833 MMCAM_LOG_WARNING("fd_info is NULL");
2834 gst_message_unref(message);
2835 return GST_BUS_DROP;
2838 cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
2840 /* set total face count */
2841 cam_fd_info->num_of_faces = fd_info->num_of_faces;
2843 if (cam_fd_info->num_of_faces > 0) {
2844 cam_fd_info->face_info = (MMCamFaceInfo *)g_malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
2845 MMCAM_LOG_DEBUG("face detection - count %d", cam_fd_info->num_of_faces);
2846 /* set information of each face */
2847 for (i = 0 ; i < cam_fd_info->num_of_faces ; i++) {
2848 cam_fd_info->face_info[i].id = fd_info->face_info[i].id;
2849 cam_fd_info->face_info[i].score = fd_info->face_info[i].score;
2850 cam_fd_info->face_info[i].rect.x = fd_info->face_info[i].rect.x;
2851 cam_fd_info->face_info[i].rect.y = fd_info->face_info[i].rect.y;
2852 cam_fd_info->face_info[i].rect.width = fd_info->face_info[i].rect.width;
2853 cam_fd_info->face_info[i].rect.height = fd_info->face_info[i].rect.height;
2855 MMCAM_LOG_VERBOSE(" [%d] id %d, score %d, [%d,%d,%dx%d]",
2856 i, fd_info->face_info[i].id,
2857 fd_info->face_info[i].score,
2858 fd_info->face_info[i].rect.x,
2859 fd_info->face_info[i].rect.y,
2860 fd_info->face_info[i].rect.width,
2861 fd_info->face_info[i].rect.height);
2864 cam_fd_info->face_info = NULL;
2867 /* send message - cam_fd_info should be freed by application */
2868 msg.id = MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO;
2869 msg.param.data = cam_fd_info;
2870 msg.param.size = sizeof(MMCamFaceDetectInfo);
2873 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2875 /* free fd_info allocated by plugin */
2878 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-Capture")) {
2879 int capture_done = FALSE;
2881 if (gst_structure_get_int(gst_message_get_structure(message), "capture-done", &capture_done)) {
2882 if (sc->info_image) {
2883 /* play capture sound */
2884 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE01, FALSE);
2888 _mmcamcorder_pipeline_cb_message(bus, message, data);
2891 _mmcamcorder_pipeline_cb_message(bus, message, data);
2894 gst_message_unref(message);
2896 return GST_BUS_DROP;
2900 static void __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code)
2902 _MMCamcorderMsgItem msg;
2904 mmf_return_if_fail(hcamcorder);
2907 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2908 case GST_RESOURCE_ERROR_OPEN_WRITE:
2909 MMCAM_LOG_ERROR("audio device [open failed]");
2911 /* post error to application */
2912 hcamcorder->error_occurs = TRUE;
2913 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2915 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2916 msg.param.code = hcamcorder->error_code;
2918 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2921 MMCAM_LOG_ERROR("unhandled error code[%d]", err_code);
2927 static void __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code)
2929 gboolean b_committing = FALSE;
2930 storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE;
2931 _MMCamcorderMsgItem msg;
2932 _MMCamcorderSubContext *sc = NULL;
2934 mmf_return_if_fail(hcamcorder);
2936 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2937 mmf_return_if_fail(sc);
2939 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2940 mmf_return_if_fail(sc->info_video);
2941 b_committing = sc->info_video->b_committing;
2943 mmf_return_if_fail(sc->info_audio);
2944 b_committing = sc->info_audio->b_committing;
2947 _MMCAMCORDER_LOCK(hcamcorder);
2950 case GST_RESOURCE_ERROR_WRITE:
2951 storage_get_state(hcamcorder->storage_info.id, &storage_state);
2952 if (storage_state == STORAGE_STATE_REMOVED ||
2953 storage_state == STORAGE_STATE_UNMOUNTABLE) {
2954 MMCAM_LOG_ERROR("storage was removed! [storage state %d]", storage_state);
2955 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2957 MMCAM_LOG_ERROR("File write error, storage state %d", storage_state);
2958 hcamcorder->error_code = MM_ERROR_FILE_WRITE;
2961 if (sc->ferror_send == FALSE) {
2962 sc->ferror_send = TRUE;
2964 MMCAM_LOG_ERROR("error was already sent");
2965 _MMCAMCORDER_UNLOCK(hcamcorder);
2969 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
2970 MMCAM_LOG_ERROR("No left space");
2971 hcamcorder->error_code = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
2973 case GST_RESOURCE_ERROR_OPEN_WRITE:
2974 MMCAM_LOG_ERROR("Out of storage");
2975 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2977 case GST_RESOURCE_ERROR_SEEK:
2978 MMCAM_LOG_ERROR("File read(seek)");
2979 hcamcorder->error_code = MM_ERROR_FILE_READ;
2982 MMCAM_LOG_ERROR("Resource error(%d)", err_code);
2983 hcamcorder->error_code = MM_ERROR_CAMCORDER_GST_RESOURCE;
2988 _MMCAMCORDER_SIGNAL(hcamcorder);
2989 _MMCAMCORDER_UNLOCK(hcamcorder);
2991 _MMCAMCORDER_UNLOCK(hcamcorder);
2993 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2994 msg.param.code = hcamcorder->error_code;
2996 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
3001 static void __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message)
3004 gchar *debug_info = NULL;
3005 _MMCamcorderSubContext *sc = NULL;
3007 mmf_return_if_fail(hcamcorder);
3008 mmf_return_if_fail(message);
3010 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3011 mmf_return_if_fail(sc);
3013 /* parse error message */
3014 gst_message_parse_error(message, &err, &debug_info);
3017 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
3023 MMCAM_LOG_ERROR("failed to parse error message");
3027 /* check domain[RESOURCE] and element[AUDIOSRC] */
3028 if (err->domain == GST_RESOURCE_ERROR &&
3029 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst))
3030 __mmcamcorder_gst_handle_sync_audio_error(hcamcorder, err->code);
3032 __mmcamcorder_gst_handle_sync_others_error(hcamcorder, err->code);
3038 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
3040 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
3041 _MMCamcorderSubContext *sc = NULL;
3043 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
3044 mmf_return_val_if_fail(message, GST_BUS_DROP);
3046 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3047 mmf_return_val_if_fail(sc, GST_BUS_DROP);
3049 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS) {
3050 MMCAM_LOG_INFO("got EOS from pipeline");
3052 _MMCAMCORDER_LOCK(hcamcorder);
3054 sc->bget_eos = TRUE;
3055 _MMCAMCORDER_SIGNAL(hcamcorder);
3057 _MMCAMCORDER_UNLOCK(hcamcorder);
3058 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
3059 __mmcamcorder_handle_gst_sync_error(hcamcorder, message);
3061 _mmcamcorder_pipeline_cb_message(bus, message, data);
3064 gst_message_unref(message);
3066 return GST_BUS_DROP;
3070 void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *value, void *user_data)
3072 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
3073 int current_state = MM_CAMCORDER_STATE_NONE;
3075 mmf_return_if_fail(hcamcorder);
3076 mmf_return_if_fail(value);
3078 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3079 if (current_state <= MM_CAMCORDER_STATE_NONE || current_state >= MM_CAMCORDER_STATE_NUM) {
3080 MMCAM_LOG_ERROR("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
3084 MMCAM_LOG_WARNING("camera policy [%s], current state [%d]", value, current_state);
3086 if (!strcmp(value, "disallowed")) {
3087 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3089 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_DPM);
3091 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3093 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
3096 MMCAM_LOG_WARNING("done");
3102 int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
3104 int ret = MM_ERROR_NONE;
3105 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3106 _MMCamcorderSubContext *sc = NULL;
3107 GstElement *pipeline = NULL;
3109 MMCAM_LOG_INFO("handle : %p, type : %d", handle, type);
3111 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3113 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3114 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3117 case MM_CAMCORDER_MODE_AUDIO:
3118 ret = _mmcamcorder_create_audio_pipeline(handle);
3119 if (ret != MM_ERROR_NONE)
3123 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3126 ret = _mmcamcorder_create_preview_pipeline(handle);
3127 if (ret != MM_ERROR_NONE)
3130 if (!sc->bencbin_capture) {
3131 ret = _mmcamcorder_connect_capture_signal(handle);
3132 if (ret != MM_ERROR_NONE)
3136 if (hcamcorder->support_extra_preview &&
3137 _mmcamcorder_initialize_extra_preview_stream(handle) != MM_ERROR_NONE)
3138 MMCAM_LOG_WARNING("connect extra preview stream signal failed");
3142 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
3143 if (type != MM_CAMCORDER_MODE_AUDIO) {
3144 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:SET_READY_TO_PIPELINE");
3146 ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY);
3148 traceEnd(TTRACE_TAG_CAMERA);
3150 #ifdef _MMCAMCORDER_GET_DEVICE_INFO
3151 if (!_mmcamcorder_get_device_info(handle))
3152 MMCAM_LOG_ERROR("Getting device information error!!");
3155 MMCAM_LOG_INFO("ret[%x]", ret);
3156 if (ret != MM_ERROR_NONE) {
3157 MMCAM_LOG_ERROR("error : destroy pipeline");
3158 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
3165 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
3167 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3168 _MMCamcorderSubContext *sc = NULL;
3170 int element_num = 0;
3171 _MMCamcorderGstElement *element = NULL;
3173 mmf_return_if_fail(hcamcorder);
3175 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3176 mmf_return_if_fail(sc);
3180 /* Inside each pipeline destroy function, Set GST_STATE_NULL to Main pipeline */
3182 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3183 element = sc->element;
3184 element_num = sc->element_num;
3185 _mmcamcorder_destroy_video_capture_pipeline(handle);
3187 case MM_CAMCORDER_MODE_AUDIO:
3188 element = sc->encode_element;
3189 element_num = sc->encode_element_num;
3190 _mmcamcorder_destroy_audio_pipeline(handle);
3193 MMCAM_LOG_ERROR("unknown type %d", type);
3197 MMCAM_LOG_INFO("Pipeline clear!!");
3199 /* checking unreleased element */
3200 for (i = 0 ; i < element_num ; i++) {
3201 if (element[i].gst) {
3202 if (GST_IS_ELEMENT(element[i].gst)) {
3203 MMCAM_LOG_WARNING("Still alive element - ID[%d], name [%s], ref count[%d], status[%s]",
3205 GST_OBJECT_NAME(element[i].gst),
3206 GST_OBJECT_REFCOUNT(element[i].gst),
3207 gst_element_state_get_name(GST_STATE(element[i].gst)));
3208 g_object_weak_unref(G_OBJECT(element[i].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3210 MMCAM_LOG_WARNING("The element[%d] is still alive, check it", element[i].id);
3213 element[i].id = _MMCAMCORDER_NONE;
3214 element[i].gst = NULL;
3222 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state)
3225 _MMCamcorderSubContext *sc = NULL;
3226 GstState pipeline_state = GST_STATE_VOID_PENDING;
3227 GstStateChangeReturn setChangeReturn = GST_STATE_CHANGE_FAILURE;
3228 GstStateChangeReturn getChangeReturn = GST_STATE_CHANGE_FAILURE;
3229 GstClockTime get_timeout = __MMCAMCORDER_SET_GST_STATE_TIMEOUT * GST_SECOND;
3230 GMutex *state_lock = NULL;
3232 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3233 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3234 mmf_return_val_if_fail(sc && sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3236 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == pipeline) {
3237 MMCAM_LOG_INFO("Set state to %d - PREVIEW PIPELINE", target_state);
3238 state_lock = &_MMCAMCORDER_GET_GST_STATE_LOCK(handle);
3240 MMCAM_LOG_INFO("Set state to %d - ENDODE PIPELINE", target_state);
3241 state_lock = &_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle);
3244 g_mutex_lock(state_lock);
3246 for (k = 0; k < _MMCAMCORDER_STATE_SET_COUNT; k++) {
3247 setChangeReturn = gst_element_set_state(pipeline, target_state);
3248 MMCAM_LOG_INFO("gst_element_set_state[%d] return %d", target_state, setChangeReturn);
3250 if (setChangeReturn != GST_STATE_CHANGE_FAILURE) {
3251 getChangeReturn = gst_element_get_state(pipeline, &pipeline_state, NULL, get_timeout);
3252 switch (getChangeReturn) {
3253 case GST_STATE_CHANGE_NO_PREROLL:
3254 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_NO_PREROLL.");
3256 case GST_STATE_CHANGE_SUCCESS:
3257 /* if we reached the final target state, exit */
3258 if (pipeline_state == target_state) {
3259 MMCAM_LOG_INFO("Set state to %d - DONE", target_state);
3260 g_mutex_unlock(state_lock);
3261 return MM_ERROR_NONE;
3264 case GST_STATE_CHANGE_ASYNC:
3265 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_ASYNC.");
3268 g_mutex_unlock(state_lock);
3269 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_FAILURE.");
3270 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3273 g_mutex_unlock(state_lock);
3275 MMCAM_LOG_ERROR("timeout of gst_element_get_state()!!");
3277 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3280 usleep(_MMCAMCORDER_STATE_CHECK_INTERVAL);
3283 g_mutex_unlock(state_lock);
3285 MMCAM_LOG_ERROR("Failure. gst_element_set_state timeout!!");
3287 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3291 /* For performance check */
3292 int _mmcamcorder_video_current_framerate(MMHandleType handle)
3294 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3295 _MMCamcorderSubContext *sc = NULL;
3297 mmf_return_val_if_fail(hcamcorder, -1);
3299 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3300 mmf_return_val_if_fail(sc, -1);
3302 return sc->kpi.current_fps;
3306 int _mmcamcorder_video_average_framerate(MMHandleType handle)
3308 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3309 _MMCamcorderSubContext *sc = NULL;
3311 mmf_return_val_if_fail(hcamcorder, -1);
3313 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3314 mmf_return_val_if_fail(sc, -1);
3316 return sc->kpi.average_fps;
3320 void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
3322 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3323 _MMCamcorderSubContext *sc = NULL;
3325 mmf_return_if_fail(hcamcorder);
3327 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3328 mmf_return_if_fail(sc);
3330 memset(&(sc->kpi), 0x00, sizeof(_MMCamcorderKPIMeasure));
3336 void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder, int state_change_by_system)
3341 int result = MM_ERROR_NONE;
3342 int cmd_try_count = 0;
3343 int current_state = MM_CAMCORDER_STATE_NONE;
3344 _MMCamcorderMsgItem msg;
3346 mmf_return_if_fail(hcamcorder);
3348 /* check command running */
3350 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
3351 if (cmd_try_count++ < __MMCAMCORDER_FORCE_STOP_TRY_COUNT) {
3352 MMCAM_LOG_WARNING("Another command is running. try again after %d ms", __MMCAMCORDER_FORCE_STOP_WAIT_TIME/1000);
3353 usleep(__MMCAMCORDER_FORCE_STOP_WAIT_TIME);
3355 MMCAM_LOG_ERROR("wait timeout");
3359 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
3364 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3366 MMCAM_LOG_WARNING("Force STOP MMFW Camcorder by %d", state_change_by_system);
3368 /* set state_change_by_system for state change message */
3369 hcamcorder->state_change_by_system = state_change_by_system;
3371 if (current_state >= MM_CAMCORDER_STATE_READY) {
3372 MMCAM_LOG_WARNING("send state change started message to notify");
3374 memset(&msg, 0x0, sizeof(_MMCamcorderMsgItem));
3376 switch (state_change_by_system) {
3377 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
3378 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_RM;
3380 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
3381 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_SECURITY;
3388 msg.param.state.code = hcamcorder->interrupt_code;
3389 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
3391 MMCAM_LOG_ERROR("should not be reached here %d", state_change_by_system);
3395 for (loop = 0 ; current_state > MM_CAMCORDER_STATE_NULL && loop < __MMCAMCORDER_CMD_ITERATE_MAX * 3 ; loop++) {
3396 itr_cnt = __MMCAMCORDER_CMD_ITERATE_MAX;
3397 switch (current_state) {
3398 case MM_CAMCORDER_STATE_CAPTURING:
3400 _MMCamcorderSubContext *sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3401 _MMCamcorderImageInfo *info = NULL;
3403 mmf_return_if_fail(sc);
3404 mmf_return_if_fail((info = sc->info_image));
3406 MMCAM_LOG_WARNING("Stop capturing.");
3408 /* if capturing isn't finished, waiting for 2 sec to finish real capture operation. check 'info->capturing'. */
3409 mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
3410 MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, TRUE,
3413 for (i = 0; i < 20 && info->capturing; i++)
3417 MMCAM_LOG_ERROR("Timeout. Can't check stop capturing.");
3419 while ((itr_cnt--) && ((result = _mmcamcorder_capture_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3420 MMCAM_LOG_WARNING("Can't stop capturing.(%x)", result);
3424 case MM_CAMCORDER_STATE_RECORDING:
3425 case MM_CAMCORDER_STATE_PAUSED:
3427 MMCAM_LOG_WARNING("Stop recording.");
3429 while ((itr_cnt--) && ((result = _mmcamcorder_commit((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
3430 MMCAM_LOG_WARNING("Can't commit.(%x), cancel it.", result);
3431 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3436 case MM_CAMCORDER_STATE_PREPARE:
3438 MMCAM_LOG_WARNING("Stop preview.");
3440 while ((itr_cnt--) && ((result = _mmcamcorder_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3441 MMCAM_LOG_WARNING("Can't stop preview.(%x)", result);
3445 case MM_CAMCORDER_STATE_READY:
3447 MMCAM_LOG_WARNING("unrealize");
3449 if ((result = _mmcamcorder_unrealize((MMHandleType)hcamcorder)) != MM_ERROR_NONE)
3450 MMCAM_LOG_WARNING("Can't unrealize.(%x)", result);
3455 MMCAM_LOG_WARNING("Already stopped.");
3459 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3463 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3465 MMCAM_LOG_WARNING("Done.");
3471 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error)
3473 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3474 _MMCamcorderMsgItem msg;
3475 gchar *msg_src_element = NULL;
3476 _MMCamcorderSubContext *sc = NULL;
3478 mmf_return_val_if_fail(hcamcorder, FALSE);
3479 mmf_return_val_if_fail(error, FALSE);
3481 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3482 mmf_return_val_if_fail(sc, FALSE);
3484 MMCAM_LOG_INFO("error code %d", error->code);
3486 mmf_return_val_if_fail(hcamcorder->state >= MM_CAMCORDER_STATE_READY, FALSE);
3488 /* filtering filesink related errors */
3489 if (hcamcorder->state == MM_CAMCORDER_STATE_RECORDING &&
3490 (error->code == GST_RESOURCE_ERROR_WRITE || error->code == GST_RESOURCE_ERROR_SEEK)) {
3491 if (sc->ferror_count == 2 && sc->ferror_send == FALSE) {
3492 sc->ferror_send = TRUE;
3493 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3496 MMCAM_LOG_WARNING("Skip error");
3501 if (error->domain == GST_CORE_ERROR) {
3502 msg.param.code = __mmcamcorder_gst_handle_core_error(handle, error->code, message);
3503 } else if (error->domain == GST_LIBRARY_ERROR) {
3504 msg.param.code = __mmcamcorder_gst_handle_library_error(handle, error->code, message);
3505 } else if (error->domain == GST_RESOURCE_ERROR) {
3506 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3507 } else if (error->domain == GST_STREAM_ERROR) {
3508 msg.param.code = __mmcamcorder_gst_handle_stream_error(handle, error->code, message);
3510 MMCAM_LOG_WARNING("This error domain is not defined.");
3512 /* we treat system error as an internal error */
3513 msg.param.code = MM_ERROR_CAMCORDER_INTERNAL;
3517 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3518 MMCAM_LOG_ERROR("-Msg src : [%s] Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3519 msg_src_element, g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3521 MMCAM_LOG_ERROR("Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3522 g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3525 #ifdef _MMCAMCORDER_SKIP_GST_FLOW_ERROR
3526 /* Check whether send this error to application */
3527 if (msg.param.code == MM_ERROR_CAMCORDER_GST_FLOW_ERROR) {
3528 MMCAM_LOG_INFO("We got the error. But skip it.");
3531 #endif /* _MMCAMCORDER_SKIP_GST_FLOW_ERROR */
3533 /* post error to application except RESTRICTED case */
3534 if (msg.param.code != MM_ERROR_POLICY_RESTRICTED) {
3535 hcamcorder->error_occurs = TRUE;
3536 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3537 _mmcamcorder_send_message(handle, &msg);
3544 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message)
3546 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3547 _MMCamcorderSubContext *sc = NULL;
3548 GstElement *element = NULL;
3552 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3554 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3555 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3557 /* Specific plugin - video encoder plugin */
3558 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3560 if (GST_ELEMENT_CAST(message->src) == element) {
3561 if (code == GST_CORE_ERROR_NEGOTIATION)
3562 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3564 return MM_ERROR_CAMCORDER_ENCODER;
3569 case GST_CORE_ERROR_STATE_CHANGE:
3570 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3571 case GST_CORE_ERROR_NEGOTIATION:
3572 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3573 case GST_CORE_ERROR_MISSING_PLUGIN:
3574 case GST_CORE_ERROR_SEEK:
3575 case GST_CORE_ERROR_NOT_IMPLEMENTED:
3576 case GST_CORE_ERROR_FAILED:
3577 case GST_CORE_ERROR_TOO_LAZY:
3578 case GST_CORE_ERROR_PAD:
3579 case GST_CORE_ERROR_THREAD:
3580 case GST_CORE_ERROR_EVENT:
3581 case GST_CORE_ERROR_CAPS:
3582 case GST_CORE_ERROR_TAG:
3583 case GST_CORE_ERROR_CLOCK:
3584 case GST_CORE_ERROR_DISABLED:
3586 return MM_ERROR_CAMCORDER_GST_CORE;
3591 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message)
3593 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3594 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3598 /* Specific plugin - NONE */
3602 case GST_LIBRARY_ERROR_FAILED:
3603 case GST_LIBRARY_ERROR_TOO_LAZY:
3604 case GST_LIBRARY_ERROR_INIT:
3605 case GST_LIBRARY_ERROR_SHUTDOWN:
3606 case GST_LIBRARY_ERROR_SETTINGS:
3607 case GST_LIBRARY_ERROR_ENCODE:
3609 MMCAM_LOG_ERROR("Library error(%d)", code);
3610 return MM_ERROR_CAMCORDER_GST_LIBRARY;
3615 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message)
3617 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3618 _MMCamcorderSubContext *sc = NULL;
3619 GstElement *element = NULL;
3621 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3623 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3624 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3628 /* Specific plugin */
3630 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst);
3631 if (GST_ELEMENT_CAST(message->src) == element) {
3632 if (code == GST_RESOURCE_ERROR_WRITE) {
3633 MMCAM_LOG_ERROR("Display device [Off]");
3634 return MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF;
3636 MMCAM_LOG_ERROR("Display device [General(%d)]", code);
3641 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst);
3642 if (GST_ELEMENT_CAST(message->src) == element) {
3643 if (code == GST_RESOURCE_ERROR_FAILED) {
3644 int ret = MM_ERROR_NONE;
3645 int current_state = MM_CAMCORDER_STATE_NONE;
3647 MMCAM_LOG_ERROR("DPM mic DISALLOWED - current state %d", current_state);
3649 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3651 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3652 if (current_state >= MM_CAMCORDER_STATE_RECORDING) {
3653 /* set value to inform a status is changed by DPM */
3654 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_DPM;
3656 ret = _mmcamcorder_commit((MMHandleType)hcamcorder);
3657 MMCAM_LOG_INFO("commit result : 0x%x", ret);
3659 if (ret != MM_ERROR_NONE) {
3660 MMCAM_LOG_ERROR("commit failed, cancel it");
3661 ret = _mmcamcorder_cancel((MMHandleType)hcamcorder);
3666 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3668 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3670 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
3672 return MM_ERROR_POLICY_RESTRICTED;
3677 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3678 if (GST_ELEMENT_CAST(message->src) == element) {
3679 if (code == GST_RESOURCE_ERROR_FAILED) {
3680 MMCAM_LOG_ERROR("Encoder [Resource error]");
3681 return MM_ERROR_CAMCORDER_ENCODER_BUFFER;
3683 MMCAM_LOG_ERROR("Encoder [General(%d)]", code);
3684 return MM_ERROR_CAMCORDER_ENCODER;
3690 case GST_RESOURCE_ERROR_WRITE:
3691 MMCAM_LOG_ERROR("File write error");
3692 return MM_ERROR_FILE_WRITE;
3693 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3694 MMCAM_LOG_ERROR("No left space");
3695 return MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
3696 case GST_RESOURCE_ERROR_OPEN_WRITE:
3697 MMCAM_LOG_ERROR("Out of storage");
3698 return MM_ERROR_OUT_OF_STORAGE;
3699 case GST_RESOURCE_ERROR_SEEK:
3700 MMCAM_LOG_ERROR("File read(seek)");
3701 return MM_ERROR_FILE_READ;
3702 case GST_RESOURCE_ERROR_NOT_FOUND:
3703 case GST_RESOURCE_ERROR_FAILED:
3704 case GST_RESOURCE_ERROR_TOO_LAZY:
3705 case GST_RESOURCE_ERROR_BUSY:
3706 case GST_RESOURCE_ERROR_OPEN_READ:
3707 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3708 case GST_RESOURCE_ERROR_CLOSE:
3709 case GST_RESOURCE_ERROR_READ:
3710 case GST_RESOURCE_ERROR_SYNC:
3711 case GST_RESOURCE_ERROR_SETTINGS:
3713 MMCAM_LOG_ERROR("Resource error(%d)", code);
3714 return MM_ERROR_CAMCORDER_GST_RESOURCE;
3719 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message)
3721 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3722 _MMCamcorderSubContext *sc = NULL;
3723 GstElement *element = NULL;
3725 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3727 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3728 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3732 /* Specific plugin */
3734 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3735 if (GST_ELEMENT_CAST(message->src) == element) {
3737 case GST_STREAM_ERROR_WRONG_TYPE:
3738 MMCAM_LOG_ERROR("Video encoder [wrong stream type]");
3739 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
3740 case GST_STREAM_ERROR_ENCODE:
3741 MMCAM_LOG_ERROR("Video encoder [encode error]");
3742 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3743 case GST_STREAM_ERROR_FAILED:
3744 MMCAM_LOG_ERROR("Video encoder [stream failed]");
3745 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3747 MMCAM_LOG_ERROR("Video encoder [General(%d)]", code);
3748 return MM_ERROR_CAMCORDER_ENCODER;
3752 /* General plugin */
3754 case GST_STREAM_ERROR_FORMAT:
3755 MMCAM_LOG_ERROR("General [negotiation error(%d)]", code);
3756 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3757 case GST_STREAM_ERROR_FAILED:
3758 MMCAM_LOG_ERROR("General [flow error(%d)]", code);
3759 return MM_ERROR_CAMCORDER_GST_FLOW_ERROR;
3760 case GST_STREAM_ERROR_TYPE_NOT_FOUND:
3761 case GST_STREAM_ERROR_DECODE:
3762 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
3763 case GST_STREAM_ERROR_NOT_IMPLEMENTED:
3764 case GST_STREAM_ERROR_TOO_LAZY:
3765 case GST_STREAM_ERROR_ENCODE:
3766 case GST_STREAM_ERROR_DEMUX:
3767 case GST_STREAM_ERROR_MUX:
3768 case GST_STREAM_ERROR_DECRYPT:
3769 case GST_STREAM_ERROR_DECRYPT_NOKEY:
3770 case GST_STREAM_ERROR_WRONG_TYPE:
3772 MMCAM_LOG_ERROR("General [error(%d)]", code);
3773 return MM_ERROR_CAMCORDER_GST_STREAM;
3778 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error)
3780 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3781 gchar *debug = NULL;
3784 mmf_return_val_if_fail(hcamcorder, FALSE);
3785 mmf_return_val_if_fail(error, FALSE);
3789 gst_message_parse_warning(message, &err, &debug);
3791 if (error->domain == GST_CORE_ERROR) {
3792 MMCAM_LOG_WARNING("GST warning: GST_CORE domain");
3793 } else if (error->domain == GST_LIBRARY_ERROR) {
3794 MMCAM_LOG_WARNING("GST warning: GST_LIBRARY domain");
3795 } else if (error->domain == GST_RESOURCE_ERROR) {
3796 MMCAM_LOG_WARNING("GST warning: GST_RESOURCE domain");
3797 __mmcamcorder_gst_handle_resource_warning(handle, message, error);
3798 } else if (error->domain == GST_STREAM_ERROR) {
3799 MMCAM_LOG_WARNING("GST warning: GST_STREAM domain");
3801 MMCAM_LOG_WARNING("This error domain(%d) is not defined.", error->domain);
3808 if (debug != NULL) {
3809 MMCAM_LOG_ERROR("Debug: %s", debug);
3818 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error)
3820 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3821 _MMCamcorderSubContext *sc = NULL;
3822 GstElement *element = NULL;
3823 gchar *msg_src_element;
3825 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3827 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3828 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3832 /* Special message handling */
3834 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
3835 if (GST_ELEMENT_CAST(message->src) == element) {
3836 if (error->code == GST_RESOURCE_ERROR_FAILED) {
3837 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3838 MMCAM_LOG_WARNING("-Msg src:[%s] Domain:[%s] Error:[%s]",
3839 msg_src_element, g_quark_to_string(error->domain), error->message);
3840 return MM_ERROR_NONE;
3844 /* General plugin */
3845 switch (error->code) {
3846 case GST_RESOURCE_ERROR_WRITE:
3847 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3848 case GST_RESOURCE_ERROR_SEEK:
3849 case GST_RESOURCE_ERROR_NOT_FOUND:
3850 case GST_RESOURCE_ERROR_FAILED:
3851 case GST_RESOURCE_ERROR_TOO_LAZY:
3852 case GST_RESOURCE_ERROR_BUSY:
3853 case GST_RESOURCE_ERROR_OPEN_READ:
3854 case GST_RESOURCE_ERROR_OPEN_WRITE:
3855 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3856 case GST_RESOURCE_ERROR_CLOSE:
3857 case GST_RESOURCE_ERROR_READ:
3858 case GST_RESOURCE_ERROR_SYNC:
3859 case GST_RESOURCE_ERROR_SETTINGS:
3861 MMCAM_LOG_WARNING("General GST warning(%d)", error->code);
3865 return MM_ERROR_NONE;
3869 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
3870 const char *interface_name, const char *signal_name, int value)
3872 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3874 mmf_return_if_fail(hcamcorder && object_name && interface_name && signal_name);
3876 MMCAM_LOG_INFO("object %s, interface %s, signal %s, value %d",
3877 object_name, interface_name, signal_name, value);
3879 _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, object_name, interface_name, signal_name, value);
3885 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
3886 static int __mmcamcorder_resource_release_cb(mm_resource_manager_h rm,
3887 mm_resource_manager_res_h res, void *user_data)
3889 mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *) user_data;
3891 mmf_return_val_if_fail(hcamcorder, FALSE);
3893 MMCAM_LOG_WARNING("enter");
3895 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3897 /* set flag for resource release callback */
3898 hcamcorder->is_release_cb_calling = TRUE;
3900 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3902 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3904 if (res == hcamcorder->video_encoder_resource) {
3905 /* Stop video recording */
3906 if (_mmcamcorder_commit((MMHandleType)hcamcorder) != MM_ERROR_NONE) {
3907 MMCAM_LOG_ERROR("commit failed, cancel it");
3908 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3912 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_RM);
3915 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3917 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3919 if (res == hcamcorder->camera_resource)
3920 hcamcorder->camera_resource = NULL;
3921 else if (res == hcamcorder->video_overlay_resource)
3922 hcamcorder->video_overlay_resource = NULL;
3923 else if (res == hcamcorder->video_encoder_resource)
3924 hcamcorder->video_encoder_resource = NULL;
3926 /* restore flag for resource release callback */
3927 hcamcorder->is_release_cb_calling = FALSE;
3929 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3931 MMCAM_LOG_WARNING("leave");
3935 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
3937 int _mmcamcorder_manage_external_storage_state(MMHandleType handle, int storage_state)
3939 int ret = MM_ERROR_NONE;
3940 int current_state = MM_CAMCORDER_STATE_NONE;
3941 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3942 _MMCamcorderMsgItem msg;
3944 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
3946 MMCAM_LOG_WARNING("storage state %d", storage_state);
3948 /* check storage state */
3949 if (storage_state != STORAGE_STATE_UNMOUNTABLE &&
3950 storage_state != STORAGE_STATE_REMOVED) {
3951 MMCAM_LOG_WARNING("nothing to do");
3952 return MM_ERROR_NONE;
3955 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3957 /* check recording state */
3958 current_state = _mmcamcorder_get_state(handle);
3960 MMCAM_LOG_WARNING("current_state %d", current_state);
3962 if (current_state < MM_CAMCORDER_STATE_RECORDING) {
3963 MMCAM_LOG_WARNING("no recording now");
3967 /* check storage type */
3968 if (hcamcorder->storage_info.type != STORAGE_TYPE_EXTERNAL) {
3969 MMCAM_LOG_WARNING("external storage is not used");
3973 /* cancel recording */
3974 ret = _mmcamcorder_cancel(handle);
3976 /* send error message */
3977 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3978 msg.param.code = MM_ERROR_OUT_OF_STORAGE;
3980 _mmcamcorder_send_message(handle, &msg);
3983 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3985 MMCAM_LOG_WARNING("done - ret 0x%x", ret);