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 10
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_ctrl,
424 CONFIGURE_CATEGORY_CTRL_CAMERA,
425 "SupportExtraPreview",
426 &hcamcorder->support_extra_preview);
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 format[capture:%d, recording:%d]", rcmd_fmt_capture, rcmd_fmt_recording);
444 MMCAM_LOG_INFO("Recommend display rotation[%d]", rcmd_dpy_rotation);
445 MMCAM_LOG_INFO("Camera facing direction[%d]", camera_facing_direction);
446 MMCAM_LOG_INFO("Brightness step denominator[%d]", hcamcorder->brightness_step_denominator);
447 MMCAM_LOG_INFO("Support ZSL capture[%d]", hcamcorder->support_zsl_capture);
449 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
450 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
452 &hcamcorder->use_zero_copy_format);
454 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
455 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
457 &hcamcorder->support_user_buffer);
459 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
460 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
461 "SupportMediaPacketPreviewCb",
462 &hcamcorder->support_media_packet_preview_cb);
464 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
465 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
467 &hcamcorder->use_videoconvert);
469 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
470 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
472 &hcamcorder->measure_preview_fps);
474 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
475 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
476 "DefaultEncodedPreviewBitrate",
477 &hcamcorder->default_encoded_preview_bitrate);
479 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
480 CONFIGURE_CATEGORY_MAIN_CAPTURE,
482 &hcamcorder->capture_mode);
484 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
485 CONFIGURE_CATEGORY_MAIN_CAPTURE,
487 &play_capture_sound);
489 MMCAM_LOG_INFO("Support user buffer[%d]", hcamcorder->support_user_buffer);
490 MMCAM_LOG_INFO("Support media packet preview cb[%d]", hcamcorder->support_media_packet_preview_cb);
491 MMCAM_LOG_INFO("Support extra preview[%d]", hcamcorder->support_extra_preview);
492 MMCAM_LOG_INFO("Capture mode[%d]", hcamcorder->capture_mode);
493 MMCAM_LOG_INFO("Use zero copy format[%d]", hcamcorder->use_zero_copy_format);
494 MMCAM_LOG_INFO("Use video convert[%d]", hcamcorder->use_videoconvert);
495 MMCAM_LOG_INFO("Measure preview FPS[%d]", hcamcorder->measure_preview_fps);
496 MMCAM_LOG_INFO("Default encoded preview bitrate[%d]", hcamcorder->default_encoded_preview_bitrate);
497 MMCAM_LOG_INFO("Play capture sound[%d]", play_capture_sound);
499 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
500 MMCAM_CAMERA_WIDTH, &resolution_width,
501 MMCAM_CAMERA_HEIGHT, &resolution_height,
503 if (ret != MM_ERROR_NONE) {
504 MMCAM_LOG_ERROR("get attribute[resolution] error");
505 return MM_ERROR_CAMCORDER_INTERNAL;
508 ret = mm_camcorder_get_fps_list_by_resolution((MMHandleType)hcamcorder, resolution_width, resolution_height, &fps_info);
509 if (ret != MM_ERROR_NONE) {
510 MMCAM_LOG_ERROR("get fps list failed with [%dx%d]", resolution_width, resolution_height);
511 return MM_ERROR_CAMCORDER_INTERNAL;
514 MMCAM_LOG_INFO("res : %d X %d, Default FPS by resolution : %d",
515 resolution_width, resolution_height, fps_info.int_array.def);
517 if (camera_facing_direction == 1) {
518 if (rcmd_dpy_rotation == MM_DISPLAY_ROTATION_270 || rcmd_dpy_rotation == MM_DISPLAY_ROTATION_90)
519 camera_default_flip = MM_FLIP_VERTICAL;
521 camera_default_flip = MM_FLIP_HORIZONTAL;
523 MMCAM_LOG_INFO("camera_default_flip : [%d]", camera_default_flip);
526 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
527 CONFIGURE_CATEGORY_MAIN_GENERAL,
528 "PlatformPrivilegeCamera",
529 &platform_privilege_camera);
531 if (hcamcorder->is_network) {
532 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
533 CONFIGURE_CATEGORY_MAIN_GENERAL,
534 "NetworkCameraHALName",
535 &hcamcorder->network_hal_name);
537 MMCAM_LOG_INFO("network HAL name[%s]", hcamcorder->network_hal_name);
540 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, &err_attr_name,
541 MMCAM_CAMERA_FACING_DIRECTION, camera_facing_direction,
542 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, rcmd_fmt_capture,
543 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, rcmd_fmt_recording,
544 MMCAM_RECOMMEND_DISPLAY_ROTATION, rcmd_dpy_rotation,
545 MMCAM_SUPPORT_ZSL_CAPTURE, hcamcorder->support_zsl_capture,
546 MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
547 MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
548 MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
549 MMCAM_SUPPORT_EXTRA_PREVIEW, hcamcorder->support_extra_preview,
550 MMCAM_CAMERA_FPS, fps_info.int_array.def,
551 MMCAM_DISPLAY_FLIP, camera_default_flip,
552 MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,
553 MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
554 platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
555 MMCAM_ENCODED_PREVIEW_BITRATE, hcamcorder->default_encoded_preview_bitrate,
557 if (ret != MM_ERROR_NONE) {
558 MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
559 SAFE_FREE(err_attr_name);
560 return MM_ERROR_CAMCORDER_INTERNAL;
563 /* Get default value of brightness */
564 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
565 MMCAM_FILTER_BRIGHTNESS, &hcamcorder->brightness_default,
567 if (ret != MM_ERROR_NONE) {
568 MMCAM_LOG_ERROR("Get brightness FAILED.");
569 return MM_ERROR_CAMCORDER_INTERNAL;
572 MMCAM_LOG_INFO("Default brightness : %d", hcamcorder->brightness_default);
578 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder)
580 int ret = MM_ERROR_NONE;
583 MMCAM_LOG_ERROR("NULL handle");
584 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
587 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
588 if (ret != MM_ERROR_NONE) {
589 MMCAM_LOG_ERROR("there is no audio device");
590 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
597 static gint __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder)
599 int ret = MM_ERROR_NONE;
600 int device_count = 0;
601 const char *videosrc_name = NULL;
602 const char *audiosrc_name = NULL;
603 type_element *SrcElement = NULL;
606 MMCAM_LOG_ERROR("NULL handle");
607 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
611 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
612 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
616 /* Videosrc element name */
617 _mmcamcorder_conf_get_element((MMHandleType)hcamcorder, hcamcorder->conf_main,
618 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
621 _mmcamcorder_conf_get_value_element_name(SrcElement, &videosrc_name);
623 /* Audiosrc element name */
624 _mmcamcorder_conf_get_element((MMHandleType)hcamcorder, hcamcorder->conf_main,
625 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
628 _mmcamcorder_conf_get_value_element_name(SrcElement, &audiosrc_name);
630 MMCAM_LOG_INFO("Device count[%d], Videosrc[%s], Audiosrc[%s]",
631 device_count, videosrc_name, audiosrc_name);
633 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
634 MMCAM_CAMERA_DEVICE_COUNT, device_count,
635 MMCAM_VIDEOSRC_ELEMENT_NAME, videosrc_name, videosrc_name ? strlen(videosrc_name) : 0,
636 MMCAM_AUDIOSRC_ELEMENT_NAME, audiosrc_name, audiosrc_name ? strlen(audiosrc_name) : 0,
638 if (ret != MM_ERROR_NONE)
639 MMCAM_LOG_ERROR("Set FAILED[0x%x]", ret);
645 static void __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder)
648 MMCAM_LOG_ERROR("NULL handle");
652 if (hcamcorder->conf_ctrl)
653 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_ctrl);
655 if (hcamcorder->conf_main)
656 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_main);
662 /*---------------------------------------------------------------------------------------
663 | GLOBAL FUNCTION DEFINITIONS: |
664 ---------------------------------------------------------------------------------------*/
665 /* Internal command functions {*/
666 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
668 int ret = MM_ERROR_NONE;
669 mmf_camcorder_t *hcamcorder = NULL;
671 MMCAM_LOG_INFO("Entered");
673 mmf_return_val_if_fail(handle && info, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
675 /* check device type */
676 if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
677 info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
678 MMCAM_LOG_ERROR("video device type[%d] is out of range.", info->videodev_type);
679 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
683 ret = __mmcamcorder_init_handle(&hcamcorder, info->videodev_type);
684 if (ret != MM_ERROR_NONE)
687 /* set network camera flag */
688 hcamcorder->is_network = (gboolean)info->reserved[0];
690 /* get DPM handle for camera/microphone restriction */
691 hcamcorder->dpm_handle = dpm_manager_create();
693 MMCAM_LOG_WARNING("DPM handle %p", hcamcorder->dpm_handle);
695 ret = __mmcamcorder_init_configure_common(hcamcorder);
696 if (ret != MM_ERROR_NONE)
697 goto _ERR_DEFAULT_VALUE_INIT;
699 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
700 ret = __mmcamcorder_init_configure_video_capture(hcamcorder);
701 if (ret != MM_ERROR_NONE)
702 goto _ERR_DEFAULT_VALUE_INIT;
704 /* add DPM camera policy changed callback */
705 if (hcamcorder->dpm_handle) {
706 ret = dpm_add_policy_changed_cb(hcamcorder->dpm_handle, "camera",
707 _mmcamcorder_dpm_camera_policy_changed_cb, (void *)hcamcorder, &hcamcorder->dpm_camera_cb_id);
708 if (ret != DPM_ERROR_NONE) {
709 MMCAM_LOG_ERROR("add DPM changed cb failed, keep going...");
710 hcamcorder->dpm_camera_cb_id = 0;
713 MMCAM_LOG_INFO("DPM camera changed cb id %d", hcamcorder->dpm_camera_cb_id);
716 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
717 /* initialize resource manager */
718 ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
719 __mmcamcorder_resource_release_cb, hcamcorder,
720 &hcamcorder->resource_manager);
721 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
722 MMCAM_LOG_ERROR("failed to initialize resource manager");
723 ret = MM_ERROR_CAMCORDER_INTERNAL;
724 goto _ERR_DEFAULT_VALUE_INIT;
726 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
728 ret = __mmcamcorder_init_configure_audio(hcamcorder);
729 if (ret != MM_ERROR_NONE)
730 goto _ERR_DEFAULT_VALUE_INIT;
733 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:CREATE:INIT_GSTREAMER");
735 ret = __mmcamcorder_init_gstreamer(hcamcorder->conf_main);
737 traceEnd(TTRACE_TAG_CAMERA);
740 MMCAM_LOG_ERROR("Failed to initialize gstreamer!!");
741 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
742 goto _ERR_DEFAULT_VALUE_INIT;
745 /* Make some attributes as read-only type */
746 _mmcamcorder_lock_readonly_attributes((MMHandleType)hcamcorder);
748 /* get system information */
749 __mmcamcorder_get_system_info(hcamcorder);
751 /* Set initial state */
752 _mmcamcorder_set_state((MMHandleType)hcamcorder, MM_CAMCORDER_STATE_NULL);
754 MMCAM_LOG_INFO("created handle %p", hcamcorder);
756 *handle = (MMHandleType)hcamcorder;
758 return MM_ERROR_NONE;
760 _ERR_DEFAULT_VALUE_INIT:
761 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
762 /* de-initialize resource manager */
763 if (hcamcorder->resource_manager != NULL)
764 mm_resource_manager_destroy(hcamcorder->resource_manager);
765 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
767 /* release DPM related handle */
768 if (hcamcorder->dpm_handle) {
769 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
770 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
772 /* remove camera policy changed callback */
773 if (hcamcorder->dpm_camera_cb_id > 0) {
774 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
775 hcamcorder->dpm_camera_cb_id = 0;
777 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
780 dpm_manager_destroy(hcamcorder->dpm_handle);
781 hcamcorder->dpm_handle = NULL;
784 /* release configure info */
785 __mmcamcorder_deinit_configure(hcamcorder);
787 /* deinitialize handle */
788 __mmcamcorder_deinit_handle(hcamcorder);
794 int _mmcamcorder_destroy(MMHandleType handle)
796 int ret = MM_ERROR_NONE;
797 int state = MM_CAMCORDER_STATE_NONE;
798 GstElement *sink_element = NULL;
799 int sink_element_size = 0;
801 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
806 MMCAM_LOG_ERROR("Not initialized");
807 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
808 goto _ERR_CAMCORDER_CMD_PRECON;
811 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
812 MMCAM_LOG_ERROR("Another command is running.");
813 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
814 goto _ERR_CAMCORDER_CMD_PRECON;
817 state = _mmcamcorder_get_state(handle);
818 if (state != MM_CAMCORDER_STATE_NULL) {
819 MMCAM_LOG_ERROR("Wrong state(%d)", state);
820 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
821 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
824 /* remove kept, but not used sink element in attribute */
825 mm_camcorder_get_attributes(handle, NULL,
826 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
829 GstStateChangeReturn result = gst_element_set_state(sink_element, GST_STATE_NULL);
831 MMCAM_LOG_WARNING("remove sink element %p, set state NULL result %d", sink_element, result);
833 gst_object_unref(sink_element);
837 /* wait for completion of sound play */
838 _mmcamcorder_sound_solo_play_wait(handle);
840 /* Release SubContext and pipeline */
841 if (hcamcorder->sub_context) {
842 if (hcamcorder->sub_context->element)
843 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
845 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
846 hcamcorder->sub_context = NULL;
849 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
850 /* de-initialize resource manager */
851 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
853 if (hcamcorder->resource_manager != NULL) {
854 ret = mm_resource_manager_destroy(hcamcorder->resource_manager);
855 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
856 MMCAM_LOG_ERROR("failed to de-initialize resource manager 0x%x", ret);
859 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
860 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
862 /* Remove messages which are not called yet */
863 _mmcamcorder_remove_message_all(handle);
865 #ifdef _MMCAMCORDER_RM_SUPPORT
866 _mmcamcorder_rm_release(handle);
867 #endif /* _MMCAMCORDER_RM_SUPPORT */
869 /* release DPM handle */
870 if (hcamcorder->dpm_handle) {
871 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
872 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
874 /* remove camera policy changed callback */
875 if (hcamcorder->dpm_camera_cb_id > 0) {
876 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
877 hcamcorder->dpm_camera_cb_id = 0;
879 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
882 dpm_manager_destroy(hcamcorder->dpm_handle);
883 hcamcorder->dpm_handle = NULL;
886 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
888 __mmcamcorder_deinit_handle(hcamcorder);
890 return MM_ERROR_NONE;
892 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
893 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
895 _ERR_CAMCORDER_CMD_PRECON:
897 MMCAM_LOG_ERROR("Destroy fail (type %d, state %d)", hcamcorder->type, state);
899 MMCAM_LOG_ERROR("Destroy fail (ret %x)", ret);
905 int _mmcamcorder_realize(MMHandleType handle)
907 int ret = MM_ERROR_NONE;
908 int state = MM_CAMCORDER_STATE_NONE;
909 int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
910 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
911 char *videosink_element_type = NULL;
912 const char *videosink_name = NULL;
915 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
917 /*MMCAM_LOG_INFO("");*/
920 MMCAM_LOG_ERROR("Not initialized");
921 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
925 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
926 MMCAM_LOG_ERROR("Another command is running.");
927 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
928 goto _ERR_CAMCORDER_CMD_PRECON;
931 state = _mmcamcorder_get_state(handle);
932 if (state != MM_CAMCORDER_STATE_NULL) {
933 MMCAM_LOG_ERROR("Wrong state(%d)", state);
934 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
935 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
938 /* Get profile mode and gdbus connection */
939 mm_camcorder_get_attributes(handle, NULL,
940 MMCAM_MODE, &hcamcorder->type,
941 MMCAM_GDBUS_CONNECTION, &hcamcorder->gdbus_conn, &conn_size,
944 if (!hcamcorder->gdbus_conn) {
945 MMCAM_LOG_ERROR("gdbus connection NULL");
946 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
947 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
950 MMCAM_LOG_INFO("Profile mode [%d], gdbus connection [%p]",
951 hcamcorder->type, hcamcorder->gdbus_conn);
953 mm_camcorder_get_attributes(handle, NULL,
954 MMCAM_DISPLAY_SURFACE, &display_surface_type,
955 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
958 /* alloc sub context */
959 hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
960 if (!hcamcorder->sub_context) {
961 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
962 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
965 /* Set basic configure information */
966 if (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE)
967 hcamcorder->sub_context->is_modified_rate = TRUE;
969 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
970 /* get video recording info */
971 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
972 CONFIGURE_CATEGORY_MAIN_RECORD,
974 &(hcamcorder->sub_context->info_video->support_dual_stream));
975 MMCAM_LOG_WARNING("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
977 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
978 CONFIGURE_CATEGORY_MAIN_RECORD,
980 &(hcamcorder->sub_context->info_video->use_videoscale));
981 MMCAM_LOG_WARNING("UseVideoscale [%d]", hcamcorder->sub_context->info_video->use_videoscale);
984 switch (display_surface_type) {
985 case MM_DISPLAY_SURFACE_OVERLAY:
986 videosink_element_type = strdup("VideosinkElementOverlay");
988 case MM_DISPLAY_SURFACE_EVAS:
989 videosink_element_type = strdup("VideosinkElementEvas");
991 case MM_DISPLAY_SURFACE_GL:
992 videosink_element_type = strdup("VideosinkElementGL");
994 case MM_DISPLAY_SURFACE_NULL:
995 videosink_element_type = strdup("VideosinkElementNull");
998 videosink_element_type = strdup("VideosinkElementOverlay");
1002 /* check string of videosink element */
1003 if (videosink_element_type) {
1004 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1005 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1006 videosink_element_type,
1007 &hcamcorder->sub_context->VideosinkElement);
1008 free(videosink_element_type);
1009 videosink_element_type = NULL;
1011 MMCAM_LOG_WARNING("strdup failed(display_surface_type %d). Use default Overlay type",
1012 display_surface_type);
1014 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1015 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1016 _MMCAMCORDER_DEFAULT_VIDEOSINK_TYPE,
1017 &hcamcorder->sub_context->VideosinkElement);
1020 _mmcamcorder_conf_get_value_element_name(hcamcorder->sub_context->VideosinkElement, &videosink_name);
1021 MMCAM_LOG_INFO("Videosink name : %s", videosink_name);
1023 /* get videoconvert element */
1024 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1025 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1026 "VideoconvertElement",
1027 &hcamcorder->sub_context->VideoconvertElement);
1029 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1030 CONFIGURE_CATEGORY_CTRL_CAPTURE,
1031 "SensorEncodedCapture",
1032 &(hcamcorder->sub_context->SensorEncodedCapture));
1033 MMCAM_LOG_INFO("Support sensor encoded capture : %d", hcamcorder->sub_context->SensorEncodedCapture);
1035 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1036 int dpm_camera_state = DPM_ALLOWED;
1038 /* check camera policy from DPM */
1039 if (hcamcorder->dpm_handle) {
1040 if (dpm_restriction_get_camera_state(hcamcorder->dpm_handle, &dpm_camera_state) == DPM_ERROR_NONE) {
1041 MMCAM_LOG_INFO("DPM camera state %d", dpm_camera_state);
1042 if (dpm_camera_state == DPM_DISALLOWED) {
1043 MMCAM_LOG_ERROR("CAMERA DISALLOWED by DPM");
1044 ret = MM_ERROR_POLICY_RESTRICTED;
1046 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
1048 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1051 MMCAM_LOG_ERROR("get DPM camera state failed, keep going...");
1054 MMCAM_LOG_WARNING("NULL dpm_handle");
1057 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1058 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1059 /* prepare resource manager for camera */
1060 if (hcamcorder->camera_resource == NULL) {
1061 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1062 MM_RESOURCE_MANAGER_RES_TYPE_CAMERA,
1064 &hcamcorder->camera_resource);
1065 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1066 MMCAM_LOG_ERROR("could not prepare for camera resource");
1067 ret = MM_ERROR_RESOURCE_INTERNAL;
1068 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1069 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1072 MMCAM_LOG_INFO("camera already acquired");
1075 /* prepare resource manager for "video_overlay only if display surface is X" */
1076 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
1077 if (hcamcorder->video_overlay_resource == NULL) {
1078 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1079 MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY,
1080 MM_RESOURCE_MANAGER_RES_VOLUME_FULL,
1081 &hcamcorder->video_overlay_resource);
1082 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1083 MMCAM_LOG_ERROR("could not prepare for overlay resource");
1084 ret = MM_ERROR_RESOURCE_INTERNAL;
1085 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1086 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1089 MMCAM_LOG_INFO("overlay already acquired");
1093 /* acquire resources */
1094 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1095 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1096 MMCAM_LOG_ERROR("could not acquire resources");
1097 ret = MM_ERROR_RESOURCE_INTERNAL;
1098 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1099 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1101 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1102 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1104 #ifdef _MMCAMCORDER_RM_SUPPORT
1105 ret = _mmcamcorder_rm_create(handle);
1106 if (ret != MM_ERROR_NONE) {
1107 MMCAM_LOG_ERROR("Resource create failed");
1108 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1110 ret = _mmcamcorder_rm_allocate(handle);
1111 if (ret != MM_ERROR_NONE) {
1112 MMCAM_LOG_ERROR("Resource allocation request failed");
1113 _mmcamcorder_rm_release(handle);
1114 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1116 #endif /* _MMCAMCORDER_RM_SUPPORT */
1119 /* create pipeline */
1120 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:CREATE_PIPELINE");
1122 ret = _mmcamcorder_create_pipeline(handle, hcamcorder->type);
1124 traceEnd(TTRACE_TAG_CAMERA);
1126 if (ret != MM_ERROR_NONE) {
1127 /* check internal error of gstreamer */
1128 if (hcamcorder->error_code != MM_ERROR_NONE) {
1129 ret = hcamcorder->error_code;
1130 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1133 /* release sub context */
1134 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1135 hcamcorder->sub_context = NULL;
1136 goto _ERR_CAMCORDER_CMD;
1139 /* set command function */
1140 ret = _mmcamcorder_set_functions(handle, hcamcorder->type);
1141 if (ret != MM_ERROR_NONE) {
1142 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1143 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1144 hcamcorder->sub_context = NULL;
1145 goto _ERR_CAMCORDER_CMD;
1148 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1150 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1152 return MM_ERROR_NONE;
1155 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1156 /* release hw resources */
1157 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1158 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1159 if (hcamcorder->camera_resource != NULL) {
1160 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1161 hcamcorder->camera_resource);
1162 hcamcorder->camera_resource = NULL;
1164 if (hcamcorder->video_overlay_resource != NULL) {
1165 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1166 hcamcorder->video_overlay_resource);
1167 hcamcorder->video_overlay_resource = NULL;
1169 mm_resource_manager_commit(hcamcorder->resource_manager);
1171 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1172 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1173 #ifdef _MMCAMCORDER_RM_SUPPORT
1174 _mmcamcorder_rm_deallocate(handle);
1175 _mmcamcorder_rm_release(handle);
1176 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1178 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1179 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1181 _ERR_CAMCORDER_CMD_PRECON:
1182 MMCAM_LOG_ERROR("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1188 int _mmcamcorder_unrealize(MMHandleType handle)
1190 int ret = MM_ERROR_NONE;
1191 int state = MM_CAMCORDER_STATE_NONE;
1193 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1198 MMCAM_LOG_ERROR("Not initialized");
1199 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1203 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1204 MMCAM_LOG_ERROR("Another command is running.");
1205 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1206 goto _ERR_CAMCORDER_CMD_PRECON;
1209 state = _mmcamcorder_get_state(handle);
1210 if (state != MM_CAMCORDER_STATE_READY) {
1211 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1212 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1213 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1216 /* Release SubContext */
1217 if (hcamcorder->sub_context) {
1218 /* destroy pipeline */
1219 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1220 /* Deallocate SubContext */
1221 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1222 hcamcorder->sub_context = NULL;
1225 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1226 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1227 MMCAM_LOG_WARNING("lock resource - cb calling %d", hcamcorder->is_release_cb_calling);
1229 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE &&
1230 hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM &&
1231 hcamcorder->is_release_cb_calling == FALSE) {
1233 /* release resource */
1234 if (hcamcorder->camera_resource != NULL) {
1235 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1236 hcamcorder->camera_resource);
1237 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1238 MMCAM_LOG_ERROR("could not mark camera resource for release");
1239 ret = MM_ERROR_CAMCORDER_INTERNAL;
1240 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1241 MMCAM_LOG_INFO("unlock resource");
1242 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1246 if (hcamcorder->video_overlay_resource != NULL) {
1247 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1248 hcamcorder->video_overlay_resource);
1249 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1250 MMCAM_LOG_ERROR("could not mark overlay resource for release");
1251 ret = MM_ERROR_CAMCORDER_INTERNAL;
1252 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1253 MMCAM_LOG_INFO("unlock resource");
1254 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1258 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1260 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1261 MMCAM_LOG_ERROR("failed to release resource, ret(0x%x)", ret);
1262 ret = MM_ERROR_CAMCORDER_INTERNAL;
1264 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1265 MMCAM_LOG_INFO("unlock resource");
1267 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1269 if (hcamcorder->camera_resource != NULL)
1270 hcamcorder->camera_resource = NULL;
1271 if (hcamcorder->video_overlay_resource != NULL)
1272 hcamcorder->video_overlay_resource = NULL;
1276 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1278 MMCAM_LOG_WARNING("unlock resource");
1279 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1281 #ifdef _MMCAMCORDER_RM_SUPPORT
1282 _mmcamcorder_rm_deallocate(handle);
1283 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1285 /* Deinitialize main context member */
1286 hcamcorder->command = NULL;
1288 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1290 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
1292 return MM_ERROR_NONE;
1294 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1295 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1297 _ERR_CAMCORDER_CMD_PRECON:
1299 MMCAM_LOG_ERROR("Unrealize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1304 int _mmcamcorder_start(MMHandleType handle)
1306 int ret = MM_ERROR_NONE;
1307 int state = MM_CAMCORDER_STATE_NONE;
1309 _MMCamcorderSubContext *sc = NULL;
1310 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1315 MMCAM_LOG_ERROR("Not initialized");
1316 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1320 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1321 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1323 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1324 MMCAM_LOG_ERROR("Another command is running.");
1325 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1326 goto _ERR_CAMCORDER_CMD_PRECON;
1329 state = _mmcamcorder_get_state(handle);
1330 if (state != MM_CAMCORDER_STATE_READY) {
1331 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1332 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1333 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1336 /* initialize error code */
1337 hcamcorder->error_code = MM_ERROR_NONE;
1339 /* set attributes related sensor */
1340 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1341 _mmcamcorder_set_attribute_to_camsensor(handle);
1343 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1344 if (ret != MM_ERROR_NONE) {
1345 /* check internal error of gstreamer */
1346 if (hcamcorder->error_code != MM_ERROR_NONE) {
1347 ret = hcamcorder->error_code;
1348 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1350 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1353 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1355 /* set attributes related sensor - after start preview */
1356 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1357 _mmcamcorder_set_attribute_to_camsensor2(handle);
1359 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1361 return MM_ERROR_NONE;
1363 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1364 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1366 _ERR_CAMCORDER_CMD_PRECON:
1367 /* check internal error of gstreamer */
1368 if (hcamcorder->error_code != MM_ERROR_NONE) {
1369 ret = hcamcorder->error_code;
1370 hcamcorder->error_code = MM_ERROR_NONE;
1372 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1375 MMCAM_LOG_ERROR("Start fail (type %d, state %d, ret %x)",
1376 hcamcorder->type, state, ret);
1381 int _mmcamcorder_stop(MMHandleType handle)
1383 int ret = MM_ERROR_NONE;
1384 int state = MM_CAMCORDER_STATE_NONE;
1386 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1391 MMCAM_LOG_ERROR("Not initialized");
1392 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1396 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1397 MMCAM_LOG_ERROR("Another command is running.");
1398 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1399 goto _ERR_CAMCORDER_CMD_PRECON;
1402 state = _mmcamcorder_get_state(handle);
1403 if (state != MM_CAMCORDER_STATE_PREPARE) {
1404 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1405 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1406 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1409 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_STOP);
1410 if (ret != MM_ERROR_NONE)
1411 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1413 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1415 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1416 /* unsubscribe remained unsubscribed signal */
1417 g_mutex_lock(&hcamcorder->gdbus_info_sound.sync_mutex);
1418 if (hcamcorder->gdbus_info_sound.subscribe_id > 0) {
1419 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_sound.subscribe_id);
1420 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_sound.subscribe_id);
1422 g_mutex_unlock(&hcamcorder->gdbus_info_sound.sync_mutex);
1424 g_mutex_lock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1425 if (hcamcorder->gdbus_info_solo_sound.subscribe_id > 0) {
1426 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_solo_sound.subscribe_id);
1427 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_solo_sound.subscribe_id);
1429 g_mutex_unlock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1432 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1434 return MM_ERROR_NONE;
1436 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1437 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1439 _ERR_CAMCORDER_CMD_PRECON:
1441 MMCAM_LOG_ERROR("Stop fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1447 int _mmcamcorder_capture_start(MMHandleType handle)
1449 int ret = MM_ERROR_NONE;
1450 int state = MM_CAMCORDER_STATE_NONE;
1451 int state_FROM_0 = MM_CAMCORDER_STATE_PREPARE;
1452 int state_FROM_1 = MM_CAMCORDER_STATE_RECORDING;
1453 int state_FROM_2 = MM_CAMCORDER_STATE_PAUSED;
1455 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1460 MMCAM_LOG_ERROR("Not initialized");
1461 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1465 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1466 MMCAM_LOG_ERROR("Another command is running.");
1467 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1468 goto _ERR_CAMCORDER_CMD_PRECON;
1471 state = _mmcamcorder_get_state(handle);
1472 if (state != state_FROM_0 && state != state_FROM_1 && state != state_FROM_2) {
1473 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1474 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1475 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1478 /* Handle capture in recording case */
1479 if (state == state_FROM_1 || state == state_FROM_2) {
1480 if (hcamcorder->capture_in_recording == TRUE) {
1481 MMCAM_LOG_ERROR("Capturing in recording (%d)", state);
1482 ret = MM_ERROR_CAMCORDER_DEVICE_BUSY;
1483 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1485 g_mutex_lock(&hcamcorder->task_thread_lock);
1486 if (hcamcorder->task_thread_state == _MMCAMCORDER_TASK_THREAD_STATE_NONE) {
1487 hcamcorder->capture_in_recording = TRUE;
1488 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING;
1489 MMCAM_LOG_INFO("send signal for capture in recording");
1490 g_cond_signal(&hcamcorder->task_thread_cond);
1491 g_mutex_unlock(&hcamcorder->task_thread_lock);
1493 MMCAM_LOG_ERROR("task thread busy : %d", hcamcorder->task_thread_state);
1494 g_mutex_unlock(&hcamcorder->task_thread_lock);
1495 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1496 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1501 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CAPTURE);
1502 if (ret != MM_ERROR_NONE)
1503 goto _ERR_CAMCORDER_CMD;
1505 /* Do not change state when recording snapshot capture */
1506 if (state == state_FROM_0)
1507 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_CAPTURING);
1509 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1511 /* Init break continuous shot attr */
1512 if (mm_camcorder_set_attributes(handle, NULL, MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, 0, NULL) != MM_ERROR_NONE)
1513 MMCAM_LOG_WARNING("capture-break-cont-shot set 0 failed");
1515 return MM_ERROR_NONE;
1518 if (hcamcorder->capture_in_recording)
1519 hcamcorder->capture_in_recording = FALSE;
1521 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1522 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1524 _ERR_CAMCORDER_CMD_PRECON:
1526 MMCAM_LOG_ERROR("Capture start fail (type %d, state %d, ret %x)",
1527 hcamcorder->type, state, ret);
1532 int _mmcamcorder_capture_stop(MMHandleType handle)
1534 int ret = MM_ERROR_NONE;
1535 int state = MM_CAMCORDER_STATE_NONE;
1536 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1541 MMCAM_LOG_ERROR("Not initialized");
1542 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1546 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1547 MMCAM_LOG_ERROR("Another command is running.");
1548 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1549 goto _ERR_CAMCORDER_CMD_PRECON;
1552 state = _mmcamcorder_get_state(handle);
1553 if (state != MM_CAMCORDER_STATE_CAPTURING) {
1554 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1555 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1556 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1559 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1560 if (ret != MM_ERROR_NONE)
1561 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1563 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1565 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1567 return MM_ERROR_NONE;
1569 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1570 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1572 _ERR_CAMCORDER_CMD_PRECON:
1574 MMCAM_LOG_ERROR("Capture stop fail (type %d, state %d, ret %x)",
1575 hcamcorder->type, state, ret);
1580 int _mmcamcorder_record(MMHandleType handle)
1582 int ret = MM_ERROR_NONE;
1583 int state = MM_CAMCORDER_STATE_NONE;
1584 int dpm_mic_state = DPM_ALLOWED;
1586 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1587 _MMCamcorderSubContext *sc = NULL;
1591 if (!hcamcorder || !MMF_CAMCORDER_SUBCONTEXT(hcamcorder)) {
1592 MMCAM_LOG_ERROR("Not initialized");
1593 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1597 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1599 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1600 MMCAM_LOG_ERROR("Another command is running.");
1601 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1602 goto _ERR_CAMCORDER_CMD_PRECON;
1605 state = _mmcamcorder_get_state(handle);
1606 if (state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_PAUSED) {
1607 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1608 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1609 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1612 /* initialize error code */
1613 hcamcorder->error_code = MM_ERROR_NONE;
1615 /* get audio disable */
1616 mm_camcorder_get_attributes(handle, NULL,
1617 MMCAM_AUDIO_DISABLE, &sc->audio_disable,
1620 sc->audio_disable |= sc->is_modified_rate;
1622 /* check mic policy from DPM */
1623 if (hcamcorder->dpm_handle && sc->audio_disable == FALSE) {
1624 if (dpm_restriction_get_microphone_state(hcamcorder->dpm_handle, &dpm_mic_state) == DPM_ERROR_NONE) {
1625 MMCAM_LOG_INFO("DPM mic state %d", dpm_mic_state);
1626 if (dpm_mic_state == DPM_DISALLOWED) {
1627 MMCAM_LOG_ERROR("MIC DISALLOWED by DPM");
1628 ret = MM_ERROR_COMMON_INVALID_PERMISSION;
1630 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
1632 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1635 MMCAM_LOG_ERROR("get DPM mic state failed, keep going...");
1638 MMCAM_LOG_WARNING("skip dpm check - handle %p, audio disable %d",
1639 hcamcorder->dpm_handle, sc->audio_disable);
1642 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_RECORD);
1643 if (ret != MM_ERROR_NONE) {
1644 /* check internal error of gstreamer */
1645 if (hcamcorder->error_code != MM_ERROR_NONE) {
1646 ret = hcamcorder->error_code;
1647 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1649 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1652 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_RECORDING);
1654 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1656 return MM_ERROR_NONE;
1658 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1659 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1661 _ERR_CAMCORDER_CMD_PRECON:
1662 /* check internal error of gstreamer */
1663 if (hcamcorder->error_code != MM_ERROR_NONE) {
1664 ret = hcamcorder->error_code;
1665 hcamcorder->error_code = MM_ERROR_NONE;
1667 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1670 MMCAM_LOG_ERROR("Record fail (type %d, state %d, ret %x)",
1671 hcamcorder->type, state, ret);
1677 int _mmcamcorder_pause(MMHandleType handle)
1679 int ret = MM_ERROR_NONE;
1680 int state = MM_CAMCORDER_STATE_NONE;
1682 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1687 MMCAM_LOG_ERROR("Not initialized");
1688 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1692 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1693 MMCAM_LOG_ERROR("Another command is running.");
1694 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1695 goto _ERR_CAMCORDER_CMD_PRECON;
1698 state = _mmcamcorder_get_state(handle);
1699 if (state != MM_CAMCORDER_STATE_RECORDING) {
1700 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1701 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1702 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1705 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PAUSE);
1706 if (ret != MM_ERROR_NONE)
1707 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1709 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PAUSED);
1711 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1713 return MM_ERROR_NONE;
1715 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1716 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1718 _ERR_CAMCORDER_CMD_PRECON:
1720 MMCAM_LOG_ERROR("Pause fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1726 int _mmcamcorder_commit(MMHandleType handle)
1728 int ret = MM_ERROR_NONE;
1729 int state = MM_CAMCORDER_STATE_NONE;
1731 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1736 MMCAM_LOG_ERROR("Not initialized");
1737 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1741 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1742 MMCAM_LOG_ERROR("Another command is running.");
1743 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1744 goto _ERR_CAMCORDER_CMD_PRECON;
1747 state = _mmcamcorder_get_state(handle);
1748 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1749 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1750 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1751 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1754 /* initialize error code */
1755 hcamcorder->error_code = MM_ERROR_NONE;
1757 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_COMMIT);
1758 if (ret != MM_ERROR_NONE)
1759 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1761 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1763 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1765 return MM_ERROR_NONE;
1767 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1768 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1770 _ERR_CAMCORDER_CMD_PRECON:
1772 MMCAM_LOG_ERROR("Commit fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1778 int _mmcamcorder_cancel(MMHandleType handle)
1780 int ret = MM_ERROR_NONE;
1781 int state = MM_CAMCORDER_STATE_NONE;
1783 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1788 MMCAM_LOG_ERROR("Not initialized");
1789 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1793 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1794 MMCAM_LOG_ERROR("Another command is running.");
1795 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1796 goto _ERR_CAMCORDER_CMD_PRECON;
1799 state = _mmcamcorder_get_state(handle);
1800 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1801 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1802 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1803 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1806 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CANCEL);
1807 if (ret != MM_ERROR_NONE)
1808 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1810 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1812 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1814 return MM_ERROR_NONE;
1816 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1817 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1819 _ERR_CAMCORDER_CMD_PRECON:
1821 MMCAM_LOG_ERROR("Cancel fail (type %d, state %d, ret %x)",
1822 hcamcorder->type, state, ret);
1826 /* } Internal command functions */
1829 int _mmcamcorder_commit_async_end(MMHandleType handle)
1833 MMCAM_LOG_WARNING("_mmcamcorder_commit_async_end : MM_CAMCORDER_STATE_PREPARE");
1834 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1836 return MM_ERROR_NONE;
1840 int _mmcamcorder_set_message_callback(MMHandleType handle, MMMessageCallback callback, void *user_data)
1842 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1844 MMCAM_LOG_INFO("%p", hcamcorder);
1846 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1848 if (callback == NULL)
1849 MMCAM_LOG_WARNING("Message Callback is disabled, because application sets it to NULL");
1851 if (!_MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(hcamcorder)) {
1852 MMCAM_LOG_WARNING("Application's message callback is running now");
1853 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1856 /* set message callback to message handle */
1857 hcamcorder->msg_cb = callback;
1858 hcamcorder->msg_cb_param = user_data;
1860 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1862 return MM_ERROR_NONE;
1866 int _mmcamcorder_set_video_stream_callback(MMHandleType handle, mm_camcorder_video_stream_callback callback, void *user_data)
1868 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1870 /*MMCAM_LOG_INFO("");*/
1872 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1874 if (callback == NULL)
1875 MMCAM_LOG_WARNING("Video Stream Callback is disabled, because application sets it to NULL");
1877 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
1879 hcamcorder->vstream_cb = callback;
1880 hcamcorder->vstream_cb_param = user_data;
1882 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1884 return MM_ERROR_NONE;
1888 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle, mm_camcorder_audio_stream_callback callback, void *user_data)
1890 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1894 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1896 if (callback == NULL)
1897 MMCAM_LOG_WARNING("Audio Stream Callback is disabled, because application sets it to NULL");
1899 if (!_MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(hcamcorder)) {
1900 MMCAM_LOG_WARNING("Application's audio stream callback is running now");
1901 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1904 hcamcorder->astream_cb = callback;
1905 hcamcorder->astream_cb_param = user_data;
1907 _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder);
1909 return MM_ERROR_NONE;
1913 int _mmcamcorder_set_muxed_stream_callback(MMHandleType handle, mm_camcorder_muxed_stream_callback callback, void *user_data)
1915 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1919 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1921 if (callback == NULL)
1922 MMCAM_LOG_WARNING("Muxed Stream Callback is disabled, because application sets it to NULL");
1924 if (!_MMCAMCORDER_TRYLOCK_MSTREAM_CALLBACK(hcamcorder)) {
1925 MMCAM_LOG_WARNING("Application's muxed stream callback is running now");
1926 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1929 hcamcorder->mstream_cb = callback;
1930 hcamcorder->mstream_cb_param = user_data;
1932 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
1934 return MM_ERROR_NONE;
1938 int _mmcamcorder_set_video_capture_callback(MMHandleType handle, mm_camcorder_video_capture_callback callback, void *user_data)
1940 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1944 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1946 if (callback == NULL)
1947 MMCAM_LOG_WARNING("Video Capture Callback is disabled, because application sets it to NULLL");
1949 if (!_MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(hcamcorder)) {
1950 MMCAM_LOG_WARNING("Application's video capture callback is running now");
1951 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1954 hcamcorder->vcapture_cb = callback;
1955 hcamcorder->vcapture_cb_param = user_data;
1957 _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(hcamcorder);
1959 return MM_ERROR_NONE;
1963 int _mmcamcorder_set_video_encode_decision_callback(MMHandleType handle, mm_camcorder_video_encode_decision_callback callback, void *user_data)
1965 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1969 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1971 if (callback == NULL)
1972 MMCAM_LOG_WARNING("Video Encode Decision Callback is disabled, because application sets it to NULL");
1974 if (!_MMCAMCORDER_TRYLOCK_VEDECISION_CALLBACK(hcamcorder)) {
1975 MMCAM_LOG_WARNING("Application's video encode decision callback is running now");
1976 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1979 hcamcorder->vedecision_cb = callback;
1980 hcamcorder->vedecision_cb_param = user_data;
1982 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
1984 return MM_ERROR_NONE;
1988 int _mmcamcorder_get_current_state(MMHandleType handle)
1990 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1994 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1996 return _mmcamcorder_get_state(handle);
1999 int _mmcamcorder_init_focusing(MMHandleType handle)
2002 int state = MM_CAMCORDER_STATE_NONE;
2003 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2004 int af_range = MM_CAMCORDER_AUTO_FOCUS_NORMAL;
2005 int sensor_focus_mode = 0;
2006 int sensor_af_range = 0;
2007 int current_focus_mode = 0;
2008 int current_af_range = 0;
2009 mmf_camcorder_t *hcamcorder = NULL;
2010 _MMCamcorderSubContext *sc = NULL;
2011 GstCameraControl *control = NULL;
2015 hcamcorder = MMF_CAMCORDER(handle);
2016 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2018 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2019 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2021 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2022 MMCAM_LOG_ERROR("Another command is running.");
2023 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2026 state = _mmcamcorder_get_state(handle);
2028 if (state == MM_CAMCORDER_STATE_CAPTURING ||
2029 state < MM_CAMCORDER_STATE_PREPARE) {
2030 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2031 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2032 return MM_ERROR_CAMCORDER_INVALID_STATE;
2035 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2036 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2037 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2038 return MM_ERROR_NONE;
2041 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2042 if (control == NULL) {
2043 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2044 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2045 return MM_ERROR_CAMCORDER_INTERNAL;
2048 ret = gst_camera_control_stop_auto_focus(control);
2050 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2051 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2052 return MM_ERROR_CAMCORDER_DEVICE_IO;
2055 /* Initialize lens position */
2056 mm_camcorder_get_attributes(handle, NULL,
2057 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2058 MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
2060 sensor_af_range = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_AF_SCAN_RANGE, af_range);
2061 sensor_focus_mode = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_FOCUS_MODE, focus_mode);
2063 gst_camera_control_get_focus(control, ¤t_focus_mode, ¤t_af_range);
2065 if (current_focus_mode != sensor_focus_mode || current_af_range != sensor_af_range) {
2066 ret = gst_camera_control_set_focus(control, sensor_focus_mode, sensor_af_range);
2068 MMCAM_LOG_INFO("No need to init FOCUS [mode:%d, range:%d]", focus_mode, af_range);
2072 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2075 MMCAM_LOG_INFO("Lens init success.");
2076 return MM_ERROR_NONE;
2078 MMCAM_LOG_ERROR("Lens init fail.");
2079 return MM_ERROR_CAMCORDER_DEVICE_IO;
2083 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction)
2086 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2087 int ret = MM_ERROR_UNKNOWN;
2088 char *err_attr_name = NULL;
2090 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2091 mmf_return_val_if_fail(direction, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2093 /*MMCAM_LOG_INFO("");*/
2095 if (!_MMCAMCORDER_TRYLOCK_CMD(handle)) {
2096 MMCAM_LOG_ERROR("Another command is running.");
2097 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2100 state = _mmcamcorder_get_state(handle);
2101 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2102 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2103 _MMCAMCORDER_UNLOCK_CMD(handle);
2104 return MM_ERROR_CAMCORDER_INVALID_STATE;
2107 /* TODO : call a auto or manual focus function */
2108 ret = mm_camcorder_get_attributes(handle, &err_attr_name,
2109 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2111 if (ret != MM_ERROR_NONE) {
2112 MMCAM_LOG_WARNING("Get focus-mode fail. (%s:%x)", err_attr_name, ret);
2113 SAFE_FREE(err_attr_name);
2114 _MMCAMCORDER_UNLOCK_CMD(handle);
2118 switch (focus_mode) {
2119 case MM_CAMCORDER_FOCUS_MODE_MANUAL:
2120 ret = _mmcamcorder_adjust_manual_focus(handle, direction);
2122 case MM_CAMCORDER_FOCUS_MODE_AUTO:
2123 case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
2124 case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
2125 ret = _mmcamcorder_adjust_auto_focus(handle);
2128 MMCAM_LOG_ERROR("It doesn't adjust focus. Focusing mode(%d)", focus_mode);
2129 ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2132 _MMCAMCORDER_UNLOCK_CMD(handle);
2137 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction)
2142 int focus_level = 0;
2143 float unit_level = 0;
2144 GstCameraControl *control = NULL;
2145 _MMCamcorderSubContext *sc = NULL;
2146 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2150 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2151 mmf_return_val_if_fail(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL != 1, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
2152 mmf_return_val_if_fail((direction >= MM_CAMCORDER_MF_LENS_DIR_FORWARD) &&
2153 (direction <= MM_CAMCORDER_MF_LENS_DIR_BACKWARD),
2154 MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2156 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2157 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2159 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2160 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2161 return MM_ERROR_NONE;
2164 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2165 if (control == NULL) {
2166 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2167 return MM_ERROR_CAMCORDER_INTERNAL;
2170 /* TODO : get max, min level */
2171 if (max_level - min_level + 1 < _MMFCAMCORDER_FOCUS_TOTAL_LEVEL)
2172 MMCAM_LOG_WARNING("Total level of manual focus of MMF is greater than that of the camera driver.");
2174 unit_level = ((float)max_level - (float)min_level)/(float)(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL - 1);
2176 if (!gst_camera_control_get_focus_level(control, &cur_level)) {
2177 MMCAM_LOG_ERROR("Can't get current level of manual focus.");
2178 return MM_ERROR_CAMCORDER_DEVICE_IO;
2181 /* TODO : adjust unit level value */
2182 if (direction == MM_CAMCORDER_MF_LENS_DIR_FORWARD)
2183 focus_level = cur_level + unit_level;
2184 else if (direction == MM_CAMCORDER_MF_LENS_DIR_BACKWARD)
2185 focus_level = cur_level - unit_level;
2187 if (focus_level > max_level)
2188 focus_level = max_level;
2189 else if (focus_level < min_level)
2190 focus_level = min_level;
2192 if (!gst_camera_control_set_focus_level(control, focus_level)) {
2193 MMCAM_LOG_ERROR("Manual focusing fail.");
2194 return MM_ERROR_CAMCORDER_DEVICE_IO;
2197 return MM_ERROR_NONE;
2201 int _mmcamcorder_adjust_auto_focus(MMHandleType handle)
2204 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2205 GstCameraControl *control = NULL;
2206 _MMCamcorderSubContext *sc = NULL;
2208 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2210 /*MMCAM_LOG_INFO("");*/
2212 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2214 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2215 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2216 return MM_ERROR_NONE;
2219 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2222 ret = gst_camera_control_start_auto_focus(control);
2224 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2229 MMCAM_LOG_INFO("Auto focusing start success.");
2230 return MM_ERROR_NONE;
2232 MMCAM_LOG_ERROR("Auto focusing start fail.");
2233 return MM_ERROR_CAMCORDER_DEVICE_IO;
2237 int _mmcamcorder_stop_focusing(MMHandleType handle)
2239 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2240 _MMCamcorderSubContext *sc = NULL;
2243 GstCameraControl *control = NULL;
2245 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2247 /*MMCAM_LOG_INFO("");*/
2249 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2251 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2252 MMCAM_LOG_ERROR("Another command is running.");
2253 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2256 state = _mmcamcorder_get_state(handle);
2257 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2258 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2259 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2260 return MM_ERROR_CAMCORDER_INVALID_STATE;
2263 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2264 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2265 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2266 return MM_ERROR_NONE;
2269 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2271 ret = gst_camera_control_stop_auto_focus(control);
2273 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2277 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2280 MMCAM_LOG_INFO("Auto focusing stop success.");
2281 return MM_ERROR_NONE;
2283 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2284 return MM_ERROR_CAMCORDER_DEVICE_IO;
2288 int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
2290 GstCameraControl *control = NULL;
2291 _MMCamcorderSubContext *sc = NULL;
2292 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2294 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2295 mmf_return_val_if_fail(level, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2297 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2298 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2300 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2301 MMCAM_LOG_ERROR("Can't cast Video source into camera control.");
2302 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2305 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2307 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2308 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2311 if (!gst_camera_control_get_focus_level(control, level)) {
2312 MMCAM_LOG_ERROR("get focus level failed");
2313 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2316 MMCAM_LOG_INFO("focus level[%d]", *level);
2318 return MM_ERROR_NONE;
2322 /*-----------------------------------------------
2323 | CAMCORDER INTERNAL LOCAL |
2324 -----------------------------------------------*/
2325 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf)
2327 static const int max_argc = 10;
2331 gchar **argv = NULL;
2333 gboolean ret = FALSE;
2334 type_string_array *GSTInitOption = NULL;
2336 mmf_return_val_if_fail(conf, FALSE);
2341 argc = malloc(sizeof(int));
2342 argv = malloc(sizeof(gchar *) * max_argc);
2347 memset(argv, 0, sizeof(gchar *) * max_argc);
2351 argv[0] = g_strdup("mmcamcorder");
2354 _mmcamcorder_conf_get_value_string_array(conf,
2355 CONFIGURE_CATEGORY_MAIN_GENERAL,
2358 if (GSTInitOption != NULL && GSTInitOption->value) {
2359 cnt_str = GSTInitOption->count;
2360 for ( ; *argc < max_argc && *argc <= cnt_str ; (*argc)++)
2361 argv[*argc] = g_strdup(GSTInitOption->value[(*argc)-1]);
2364 MMCAM_LOG_INFO("initializing gstreamer with following parameter[argc:%d]", *argc);
2366 for (i = 0; i < *argc; i++)
2367 MMCAM_LOG_INFO("argv[%d] : %s", i, argv[i]);
2369 /* initializing gstreamer */
2370 ret = gst_init_check(argc, &argv, &err);
2372 MMCAM_LOG_ERROR("Could not initialize GStreamer: %s ", err ? err->message : "unknown error occurred");
2378 for (i = 0; i < *argc; i++) {
2398 MMCAM_LOG_ERROR("failed to initialize gstreamer");
2414 int _mmcamcorder_get_state(MMHandleType handle)
2417 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2419 mmf_return_val_if_fail(hcamcorder, -1);
2421 _MMCAMCORDER_LOCK_STATE(handle);
2423 state = hcamcorder->state;
2424 /*MMCAM_LOG_INFO("state=%d",state);*/
2426 _MMCAMCORDER_UNLOCK_STATE(handle);
2432 int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state)
2434 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2436 mmf_return_val_if_fail(hcamcorder && state && old_state, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2438 _MMCAMCORDER_LOCK_STATE(handle);
2440 *state = hcamcorder->state;
2441 *old_state = hcamcorder->old_state;
2443 _MMCAMCORDER_UNLOCK_STATE(handle);
2445 return MM_ERROR_NONE;
2449 void _mmcamcorder_set_state(MMHandleType handle, int state)
2452 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2453 _MMCamcorderMsgItem msg;
2455 mmf_return_if_fail(hcamcorder);
2457 /*MMCAM_LOG_INFO("");*/
2459 _MMCAMCORDER_LOCK_STATE(handle);
2461 old_state = hcamcorder->state;
2462 if (old_state != state) {
2463 hcamcorder->state = state;
2464 hcamcorder->old_state = old_state;
2466 MMCAM_LOG_INFO("set state[%d -> %d] and send state-changed message", old_state, state);
2468 /* To discern who changes the state */
2469 switch (hcamcorder->state_change_by_system) {
2470 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
2471 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_RM;
2472 msg.param.state.code = MM_ERROR_NONE;
2474 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
2475 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY;
2476 msg.param.state.code = MM_ERROR_NONE;
2478 case _MMCAMCORDER_STATE_CHANGE_NORMAL:
2480 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED;
2481 msg.param.state.code = MM_ERROR_NONE;
2485 msg.param.state.previous = old_state;
2486 msg.param.state.current = state;
2488 /*MMCAM_LOG_INFO("_mmcamcorder_send_message : msg : %p, id:%x", &msg, msg.id);*/
2489 _mmcamcorder_send_message(handle, &msg);
2492 _MMCAMCORDER_UNLOCK_STATE(handle);
2498 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
2501 _MMCamcorderSubContext *sc = NULL;
2503 /*MMCAM_LOG_INFO("");*/
2505 /* alloc container */
2506 sc = (_MMCamcorderSubContext *)g_malloc0(sizeof(_MMCamcorderSubContext));
2508 sc->element_num = _MMCAMCORDER_PIPELINE_ELEMENT_NUM;
2509 sc->encode_element_num = _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM;
2511 /* alloc info for each mode */
2513 case MM_CAMCORDER_MODE_AUDIO:
2514 sc->info_audio = g_malloc0(sizeof(_MMCamcorderAudioInfo));
2516 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2518 sc->info_image = g_malloc0(sizeof(_MMCamcorderImageInfo));
2519 sc->info_video = g_malloc0(sizeof(_MMCamcorderVideoInfo));
2521 sc->info_image->sound_status = _SOUND_STATUS_INIT;
2522 g_mutex_init(&sc->info_video->size_check_lock);
2526 /* alloc element array */
2527 sc->element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->element_num);
2528 sc->encode_element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->encode_element_num);
2530 for (i = 0 ; i < sc->element_num ; i++) {
2531 sc->element[i].id = _MMCAMCORDER_NONE;
2532 sc->element[i].gst = NULL;
2535 for (i = 0 ; i < sc->encode_element_num ; i++) {
2536 sc->encode_element[i].id = _MMCAMCORDER_NONE;
2537 sc->encode_element[i].gst = NULL;
2540 sc->fourcc = 0x80000000;
2541 sc->frame_stability_count = 0;
2542 sc->drop_vframe = 0;
2543 sc->pass_first_vframe = 0;
2544 sc->is_modified_rate = FALSE;
2550 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
2556 MMCAM_LOG_INFO("release element");
2557 g_free(sc->element);
2561 if (sc->encode_element) {
2562 MMCAM_LOG_INFO("release encode_element");
2563 g_free(sc->encode_element);
2564 sc->encode_element = NULL;
2567 if (sc->info_image) {
2568 MMCAM_LOG_INFO("release info_image");
2569 g_free(sc->info_image);
2570 sc->info_image = NULL;
2573 if (sc->info_video) {
2574 MMCAM_LOG_INFO("release info_video");
2575 SAFE_G_FREE(sc->info_video->filename);
2576 g_mutex_clear(&sc->info_video->size_check_lock);
2577 g_free(sc->info_video);
2578 sc->info_video = NULL;
2581 if (sc->info_audio) {
2582 MMCAM_LOG_INFO("release info_audio");
2583 SAFE_G_FREE(sc->info_audio->filename);
2584 g_free(sc->info_audio);
2585 sc->info_audio = NULL;
2596 int _mmcamcorder_set_functions(MMHandleType handle, int type)
2598 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2600 /*MMCAM_LOG_INFO("");*/
2603 case MM_CAMCORDER_MODE_AUDIO:
2604 hcamcorder->command = _mmcamcorder_audio_command;
2606 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2608 hcamcorder->command = _mmcamcorder_video_capture_command;
2612 return MM_ERROR_NONE;
2616 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data)
2618 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2619 _MMCamcorderSubContext *sc = NULL;
2621 mmf_return_val_if_fail(hcamcorder, FALSE);
2622 mmf_return_val_if_fail(message, FALSE);
2624 MMCAM_LOG_DEBUG("message type[0x%x]", GST_MESSAGE_TYPE(message));
2626 switch (GST_MESSAGE_TYPE(message)) {
2627 case GST_MESSAGE_EOS:
2629 MMCAM_LOG_ERROR("Got EOS from element[%s]... but should not be reached here!",
2630 GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));
2633 case GST_MESSAGE_ERROR:
2636 gchar *debug = NULL;
2638 gst_message_parse_error(message, &err, &debug);
2640 __mmcamcorder_handle_gst_error((MMHandleType)hcamcorder, message, err);
2643 MMCAM_LOG_ERROR("GSTERR: %s", err->message);
2649 MMCAM_LOG_ERROR("Error Debug: %s", debug);
2655 case GST_MESSAGE_WARNING:
2659 gst_message_parse_warning(message, &err, &debug);
2661 MMCAM_LOG_WARNING("GSTWARN: %s", err->message);
2663 __mmcamcorder_handle_gst_warning((MMHandleType)hcamcorder, message, err);
2669 case GST_MESSAGE_STATE_CHANGED:
2671 const GValue *vnewstate;
2673 GstElement *pipeline = NULL;
2675 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2676 if ((sc) && (sc->element)) {
2677 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst) {
2678 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
2679 if (message->src == (GstObject*)pipeline) {
2680 vnewstate = gst_structure_get_value(gst_message_get_structure(message), "new-state");
2682 newstate = (GstState)vnewstate->data[0].v_int;
2683 MMCAM_LOG_INFO("GST_MESSAGE_STATE_CHANGED[%s]", gst_element_state_get_name(newstate));
2685 MMCAM_LOG_WARNING("get new state failed from msg");
2692 case GST_MESSAGE_NEW_CLOCK:
2694 GstClock *pipe_clock = NULL;
2695 gst_message_parse_new_clock(message, &pipe_clock);
2696 MMCAM_LOG_INFO("GST_MESSAGE_NEW_CLOCK[%s]", (pipe_clock ? GST_OBJECT_NAME(pipe_clock) : "NULL"));
2700 MMCAM_LOG_DEBUG("unhandled message type[0x%x]", GST_MESSAGE_TYPE(message));
2708 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
2711 gchar *debug_info = NULL;
2713 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2714 _MMCamcorderSubContext *sc = NULL;
2716 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
2717 mmf_return_val_if_fail(message, GST_BUS_DROP);
2719 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2720 mmf_return_val_if_fail(sc, GST_BUS_DROP);
2722 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
2723 /* parse error message */
2724 gst_message_parse_error(message, &err, &debug_info);
2727 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
2733 MMCAM_LOG_WARNING("failed to parse error message");
2734 return GST_BUS_PASS;
2737 /* check domain[RESOURCE] and element[VIDEOSRC] */
2738 if (err->domain == GST_RESOURCE_ERROR &&
2739 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2740 switch (err->code) {
2741 case GST_RESOURCE_ERROR_BUSY:
2742 MMCAM_LOG_ERROR("Camera device [busy]");
2743 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_BUSY;
2745 case GST_RESOURCE_ERROR_OPEN_WRITE:
2746 MMCAM_LOG_ERROR("Camera device [open failed]");
2747 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2749 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2750 MMCAM_LOG_ERROR("Camera device [open failed]");
2751 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN;
2753 case GST_RESOURCE_ERROR_OPEN_READ:
2754 MMCAM_LOG_ERROR("Camera device [register trouble]");
2755 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE;
2757 case GST_RESOURCE_ERROR_NOT_FOUND:
2758 MMCAM_LOG_ERROR("Camera device [device not found]");
2759 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND;
2761 case GST_RESOURCE_ERROR_TOO_LAZY:
2762 MMCAM_LOG_ERROR("Camera device [timeout]");
2763 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_TIMEOUT;
2765 case GST_RESOURCE_ERROR_SETTINGS:
2766 MMCAM_LOG_ERROR("Camera device [not supported]");
2767 hcamcorder->error_code = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2769 case GST_RESOURCE_ERROR_FAILED:
2770 MMCAM_LOG_ERROR("Camera device [working failed].");
2771 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_IO;
2774 MMCAM_LOG_ERROR("Camera device [General(%d)]", err->code);
2775 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE;
2779 hcamcorder->error_occurs = TRUE;
2784 /* store error code and drop this message if cmd is running */
2785 if (hcamcorder->error_code != MM_ERROR_NONE) {
2786 _MMCamcorderMsgItem msg;
2788 /* post error to application */
2789 hcamcorder->error_occurs = TRUE;
2790 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2791 msg.param.code = hcamcorder->error_code;
2792 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2794 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
2795 _MMCamcorderMsgItem msg;
2797 if (gst_structure_has_name(gst_message_get_structure(message), "avsysvideosrc-AF") ||
2798 gst_structure_has_name(gst_message_get_structure(message), "camerasrc-AF")) {
2799 int focus_state = 0;
2801 gst_structure_get_int(gst_message_get_structure(message), "focus-state", &focus_state);
2802 MMCAM_LOG_INFO("Focus State:%d", focus_state);
2804 msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED;
2805 msg.param.code = focus_state;
2806 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2807 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) {
2811 if (gst_structure_get_int(gst_message_get_structure(message), "progress", &progress)) {
2812 gst_structure_get_int(gst_message_get_structure(message), "status", &status);
2813 MMCAM_LOG_INFO("HDR progress %d percent, status %d", progress, status);
2815 msg.id = MM_MESSAGE_CAMCORDER_HDR_PROGRESS;
2816 msg.param.code = progress;
2817 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2819 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) {
2821 const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");;
2822 GstCameraControlFaceDetectInfo *fd_info = NULL;
2823 MMCamFaceDetectInfo *cam_fd_info = NULL;
2826 fd_info = (GstCameraControlFaceDetectInfo *)g_value_get_pointer(g_value);
2828 if (fd_info == NULL) {
2829 MMCAM_LOG_WARNING("fd_info is NULL");
2830 gst_message_unref(message);
2831 return GST_BUS_DROP;
2834 cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
2836 /* set total face count */
2837 cam_fd_info->num_of_faces = fd_info->num_of_faces;
2839 if (cam_fd_info->num_of_faces > 0) {
2840 cam_fd_info->face_info = (MMCamFaceInfo *)g_malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
2841 MMCAM_LOG_DEBUG("face detection - count %d", cam_fd_info->num_of_faces);
2842 /* set information of each face */
2843 for (i = 0 ; i < cam_fd_info->num_of_faces ; i++) {
2844 cam_fd_info->face_info[i].id = fd_info->face_info[i].id;
2845 cam_fd_info->face_info[i].score = fd_info->face_info[i].score;
2846 cam_fd_info->face_info[i].rect.x = fd_info->face_info[i].rect.x;
2847 cam_fd_info->face_info[i].rect.y = fd_info->face_info[i].rect.y;
2848 cam_fd_info->face_info[i].rect.width = fd_info->face_info[i].rect.width;
2849 cam_fd_info->face_info[i].rect.height = fd_info->face_info[i].rect.height;
2851 MMCAM_LOG_VERBOSE(" [%d] id %d, score %d, [%d,%d,%dx%d]",
2852 i, fd_info->face_info[i].id,
2853 fd_info->face_info[i].score,
2854 fd_info->face_info[i].rect.x,
2855 fd_info->face_info[i].rect.y,
2856 fd_info->face_info[i].rect.width,
2857 fd_info->face_info[i].rect.height);
2860 cam_fd_info->face_info = NULL;
2863 /* send message - cam_fd_info should be freed by application */
2864 msg.id = MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO;
2865 msg.param.data = cam_fd_info;
2866 msg.param.size = sizeof(MMCamFaceDetectInfo);
2869 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2871 /* free fd_info allocated by plugin */
2874 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-Capture")) {
2875 int capture_done = FALSE;
2877 if (gst_structure_get_int(gst_message_get_structure(message), "capture-done", &capture_done)) {
2878 if (sc->info_image) {
2879 /* play capture sound */
2880 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE01, FALSE);
2884 _mmcamcorder_pipeline_cb_message(bus, message, data);
2887 _mmcamcorder_pipeline_cb_message(bus, message, data);
2890 gst_message_unref(message);
2892 return GST_BUS_DROP;
2896 static void __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code)
2898 _MMCamcorderMsgItem msg;
2900 mmf_return_if_fail(hcamcorder);
2903 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2904 case GST_RESOURCE_ERROR_OPEN_WRITE:
2905 MMCAM_LOG_ERROR("audio device [open failed]");
2907 /* post error to application */
2908 hcamcorder->error_occurs = TRUE;
2909 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2911 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2912 msg.param.code = hcamcorder->error_code;
2914 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2917 MMCAM_LOG_ERROR("unhandled error code[%d]", err_code);
2923 static void __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code)
2925 gboolean b_committing = FALSE;
2926 storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE;
2927 _MMCamcorderMsgItem msg;
2928 _MMCamcorderSubContext *sc = NULL;
2930 mmf_return_if_fail(hcamcorder);
2932 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2933 mmf_return_if_fail(sc);
2935 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2936 mmf_return_if_fail(sc->info_video);
2937 b_committing = sc->info_video->b_committing;
2939 mmf_return_if_fail(sc->info_audio);
2940 b_committing = sc->info_audio->b_committing;
2943 _MMCAMCORDER_LOCK(hcamcorder);
2946 case GST_RESOURCE_ERROR_WRITE:
2947 storage_get_state(hcamcorder->storage_info.id, &storage_state);
2948 if (storage_state == STORAGE_STATE_REMOVED ||
2949 storage_state == STORAGE_STATE_UNMOUNTABLE) {
2950 MMCAM_LOG_ERROR("storage was removed! [storage state %d]", storage_state);
2951 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2953 MMCAM_LOG_ERROR("File write error, storage state %d", storage_state);
2954 hcamcorder->error_code = MM_ERROR_FILE_WRITE;
2957 if (sc->ferror_send == FALSE) {
2958 sc->ferror_send = TRUE;
2960 MMCAM_LOG_ERROR("error was already sent");
2961 _MMCAMCORDER_UNLOCK(hcamcorder);
2965 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
2966 MMCAM_LOG_ERROR("No left space");
2967 hcamcorder->error_code = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
2969 case GST_RESOURCE_ERROR_OPEN_WRITE:
2970 MMCAM_LOG_ERROR("Out of storage");
2971 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2973 case GST_RESOURCE_ERROR_SEEK:
2974 MMCAM_LOG_ERROR("File read(seek)");
2975 hcamcorder->error_code = MM_ERROR_FILE_READ;
2978 MMCAM_LOG_ERROR("Resource error(%d)", err_code);
2979 hcamcorder->error_code = MM_ERROR_CAMCORDER_GST_RESOURCE;
2984 _MMCAMCORDER_SIGNAL(hcamcorder);
2985 _MMCAMCORDER_UNLOCK(hcamcorder);
2987 _MMCAMCORDER_UNLOCK(hcamcorder);
2989 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2990 msg.param.code = hcamcorder->error_code;
2992 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2997 static void __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message)
3000 gchar *debug_info = NULL;
3001 _MMCamcorderSubContext *sc = NULL;
3003 mmf_return_if_fail(hcamcorder);
3004 mmf_return_if_fail(message);
3006 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3007 mmf_return_if_fail(sc);
3009 /* parse error message */
3010 gst_message_parse_error(message, &err, &debug_info);
3013 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
3019 MMCAM_LOG_ERROR("failed to parse error message");
3023 /* check domain[RESOURCE] and element[AUDIOSRC] */
3024 if (err->domain == GST_RESOURCE_ERROR &&
3025 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst))
3026 __mmcamcorder_gst_handle_sync_audio_error(hcamcorder, err->code);
3028 __mmcamcorder_gst_handle_sync_others_error(hcamcorder, err->code);
3034 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
3036 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
3037 _MMCamcorderSubContext *sc = NULL;
3039 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
3040 mmf_return_val_if_fail(message, GST_BUS_DROP);
3042 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3043 mmf_return_val_if_fail(sc, GST_BUS_DROP);
3045 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS) {
3046 MMCAM_LOG_INFO("got EOS from pipeline");
3048 _MMCAMCORDER_LOCK(hcamcorder);
3050 sc->bget_eos = TRUE;
3051 _MMCAMCORDER_SIGNAL(hcamcorder);
3053 _MMCAMCORDER_UNLOCK(hcamcorder);
3054 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
3055 __mmcamcorder_handle_gst_sync_error(hcamcorder, message);
3057 _mmcamcorder_pipeline_cb_message(bus, message, data);
3060 gst_message_unref(message);
3062 return GST_BUS_DROP;
3066 void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *value, void *user_data)
3068 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
3069 int current_state = MM_CAMCORDER_STATE_NONE;
3071 mmf_return_if_fail(hcamcorder);
3072 mmf_return_if_fail(value);
3074 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3075 if (current_state <= MM_CAMCORDER_STATE_NONE || current_state >= MM_CAMCORDER_STATE_NUM) {
3076 MMCAM_LOG_ERROR("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
3080 MMCAM_LOG_WARNING("camera policy [%s], current state [%d]", value, current_state);
3082 if (!strcmp(value, "disallowed")) {
3083 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3085 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_DPM);
3087 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3089 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
3092 MMCAM_LOG_WARNING("done");
3098 int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
3100 int ret = MM_ERROR_NONE;
3101 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3102 _MMCamcorderSubContext *sc = NULL;
3103 GstElement *pipeline = NULL;
3105 MMCAM_LOG_INFO("handle : %p, type : %d", handle, type);
3107 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3109 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3110 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3113 case MM_CAMCORDER_MODE_AUDIO:
3114 ret = _mmcamcorder_create_audio_pipeline(handle);
3115 if (ret != MM_ERROR_NONE)
3119 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3122 ret = _mmcamcorder_create_preview_pipeline(handle);
3123 if (ret != MM_ERROR_NONE)
3126 if (hcamcorder->capture_mode == MM_CAMCORDER_CAPTURE_MODE_CAMERA_CONTROL) {
3127 ret = _mmcamcorder_prepare_capture_mode_camera_control(handle);
3128 if (ret != MM_ERROR_NONE)
3130 } else if (hcamcorder->capture_mode == MM_CAMCORDER_CAPTURE_MODE_IMAGE_PAD) {
3131 ret = _mmcamcorder_prepare_capture_mode_image_pad(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);