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 (int *)&hcamcorder->extra_preview.is_supported);
428 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
429 CONFIGURE_CATEGORY_CTRL_CAMERA,
431 (int *)&hcamcorder->extra_preview.mode);
433 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
434 CONFIGURE_CATEGORY_CTRL_CAMERA,
436 &camera_facing_direction);
438 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
439 CONFIGURE_CATEGORY_CTRL_EFFECT,
440 "BrightnessStepDenominator",
441 &hcamcorder->brightness_step_denominator);
443 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
444 CONFIGURE_CATEGORY_CTRL_CAPTURE,
446 &hcamcorder->support_zsl_capture);
448 MMCAM_LOG_INFO("Recommend format[capture:%d, recording:%d]", rcmd_fmt_capture, rcmd_fmt_recording);
449 MMCAM_LOG_INFO("Recommend display rotation[%d]", rcmd_dpy_rotation);
450 MMCAM_LOG_INFO("Camera facing direction[%d]", camera_facing_direction);
451 MMCAM_LOG_INFO("Brightness step denominator[%d]", hcamcorder->brightness_step_denominator);
452 MMCAM_LOG_INFO("Support ZSL capture[%d]", hcamcorder->support_zsl_capture);
454 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
455 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
457 &hcamcorder->use_zero_copy_format);
459 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
460 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
462 &hcamcorder->support_user_buffer);
464 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
465 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
466 "SupportMediaPacketPreviewCb",
467 &hcamcorder->support_media_packet_preview_cb);
469 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
470 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
472 &hcamcorder->use_videoconvert);
474 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
475 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
477 &hcamcorder->measure_preview_fps);
479 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
480 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
481 "DefaultEncodedPreviewBitrate",
482 &hcamcorder->default_encoded_preview_bitrate);
484 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
485 CONFIGURE_CATEGORY_MAIN_CAPTURE,
487 &hcamcorder->capture_mode);
489 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
490 CONFIGURE_CATEGORY_MAIN_CAPTURE,
492 &play_capture_sound);
494 MMCAM_LOG_INFO("Support user buffer[%d]", hcamcorder->support_user_buffer);
495 MMCAM_LOG_INFO("Support media packet preview cb[%d]", hcamcorder->support_media_packet_preview_cb);
496 MMCAM_LOG_INFO("Support extra preview[%d]", hcamcorder->extra_preview.is_supported);
497 MMCAM_LOG_INFO("Extra preview mode[%d]", hcamcorder->extra_preview.mode);
498 MMCAM_LOG_INFO("Capture mode[%d]", hcamcorder->capture_mode);
499 MMCAM_LOG_INFO("Use zero copy format[%d]", hcamcorder->use_zero_copy_format);
500 MMCAM_LOG_INFO("Use video convert[%d]", hcamcorder->use_videoconvert);
501 MMCAM_LOG_INFO("Measure preview FPS[%d]", hcamcorder->measure_preview_fps);
502 MMCAM_LOG_INFO("Default encoded preview bitrate[%d]", hcamcorder->default_encoded_preview_bitrate);
503 MMCAM_LOG_INFO("Play capture sound[%d]", play_capture_sound);
505 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
506 MMCAM_CAMERA_WIDTH, &resolution_width,
507 MMCAM_CAMERA_HEIGHT, &resolution_height,
509 if (ret != MM_ERROR_NONE) {
510 MMCAM_LOG_ERROR("get attribute[resolution] error");
511 return MM_ERROR_CAMCORDER_INTERNAL;
514 ret = mm_camcorder_get_fps_list_by_resolution((MMHandleType)hcamcorder, resolution_width, resolution_height, &fps_info);
515 if (ret != MM_ERROR_NONE) {
516 MMCAM_LOG_ERROR("get fps list failed with [%dx%d]", resolution_width, resolution_height);
517 return MM_ERROR_CAMCORDER_INTERNAL;
520 MMCAM_LOG_INFO("res : %d X %d, Default FPS by resolution : %d",
521 resolution_width, resolution_height, fps_info.int_array.def);
523 if (camera_facing_direction == 1) {
524 if (rcmd_dpy_rotation == MM_DISPLAY_ROTATION_270 || rcmd_dpy_rotation == MM_DISPLAY_ROTATION_90)
525 camera_default_flip = MM_FLIP_VERTICAL;
527 camera_default_flip = MM_FLIP_HORIZONTAL;
529 MMCAM_LOG_INFO("camera_default_flip : [%d]", camera_default_flip);
532 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
533 CONFIGURE_CATEGORY_MAIN_GENERAL,
534 "PlatformPrivilegeCamera",
535 &platform_privilege_camera);
537 if (hcamcorder->is_network) {
538 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
539 CONFIGURE_CATEGORY_MAIN_GENERAL,
540 "NetworkCameraHALName",
541 &hcamcorder->network_hal_name);
543 MMCAM_LOG_INFO("network HAL name[%s]", hcamcorder->network_hal_name);
546 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, &err_attr_name,
547 MMCAM_CAMERA_FACING_DIRECTION, camera_facing_direction,
548 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, rcmd_fmt_capture,
549 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, rcmd_fmt_recording,
550 MMCAM_RECOMMEND_DISPLAY_ROTATION, rcmd_dpy_rotation,
551 MMCAM_SUPPORT_ZSL_CAPTURE, hcamcorder->support_zsl_capture,
552 MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
553 MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
554 MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
555 MMCAM_SUPPORT_EXTRA_PREVIEW, hcamcorder->extra_preview.is_supported,
556 MMCAM_CAMERA_FPS, fps_info.int_array.def,
557 MMCAM_DISPLAY_FLIP, camera_default_flip,
558 MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,
559 MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
560 platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
561 MMCAM_ENCODED_PREVIEW_BITRATE, hcamcorder->default_encoded_preview_bitrate,
563 if (ret != MM_ERROR_NONE) {
564 MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
565 SAFE_FREE(err_attr_name);
566 return MM_ERROR_CAMCORDER_INTERNAL;
569 /* Get default value of brightness */
570 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
571 MMCAM_FILTER_BRIGHTNESS, &hcamcorder->brightness_default,
573 if (ret != MM_ERROR_NONE) {
574 MMCAM_LOG_ERROR("Get brightness FAILED.");
575 return MM_ERROR_CAMCORDER_INTERNAL;
578 MMCAM_LOG_INFO("Default brightness : %d", hcamcorder->brightness_default);
584 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder)
586 int ret = MM_ERROR_NONE;
589 MMCAM_LOG_ERROR("NULL handle");
590 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
593 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
594 if (ret != MM_ERROR_NONE) {
595 MMCAM_LOG_ERROR("there is no audio device");
596 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
603 static gint __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder)
605 int ret = MM_ERROR_NONE;
606 int device_count = 0;
607 const char *videosrc_name = NULL;
608 const char *audiosrc_name = NULL;
611 MMCAM_LOG_ERROR("NULL handle");
612 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
615 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
616 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
620 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
621 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
622 NULL, &videosrc_name);
624 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
625 CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, "AudiosrcElement",
626 NULL, &audiosrc_name);
628 MMCAM_LOG_INFO("Device count[%d], Videosrc[%s], Audiosrc[%s]",
629 device_count, videosrc_name, audiosrc_name);
631 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
632 MMCAM_CAMERA_DEVICE_COUNT, device_count,
633 MMCAM_VIDEOSRC_ELEMENT_NAME, videosrc_name, videosrc_name ? strlen(videosrc_name) : 0,
634 MMCAM_AUDIOSRC_ELEMENT_NAME, audiosrc_name, audiosrc_name ? strlen(audiosrc_name) : 0,
636 if (ret != MM_ERROR_NONE)
637 MMCAM_LOG_ERROR("Set FAILED[0x%x]", ret);
643 static void __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder)
646 MMCAM_LOG_ERROR("NULL handle");
650 if (hcamcorder->conf_ctrl)
651 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_ctrl);
653 if (hcamcorder->conf_main)
654 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_main);
660 /*---------------------------------------------------------------------------------------
661 | GLOBAL FUNCTION DEFINITIONS: |
662 ---------------------------------------------------------------------------------------*/
663 /* Internal command functions {*/
664 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
666 int ret = MM_ERROR_NONE;
667 mmf_camcorder_t *hcamcorder = NULL;
669 MMCAM_LOG_INFO("Entered");
671 mmf_return_val_if_fail(handle && info, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
673 /* check device type */
674 if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
675 info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
676 MMCAM_LOG_ERROR("video device type[%d] is out of range.", info->videodev_type);
677 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
681 ret = __mmcamcorder_init_handle(&hcamcorder, info->videodev_type);
682 if (ret != MM_ERROR_NONE)
685 /* set network camera flag */
686 hcamcorder->is_network = (gboolean)info->reserved[0];
688 /* get DPM handle for camera/microphone restriction */
689 hcamcorder->dpm_handle = dpm_manager_create();
691 MMCAM_LOG_WARNING("DPM handle %p", hcamcorder->dpm_handle);
693 ret = __mmcamcorder_init_configure_common(hcamcorder);
694 if (ret != MM_ERROR_NONE)
695 goto _ERR_DEFAULT_VALUE_INIT;
697 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
698 ret = __mmcamcorder_init_configure_video_capture(hcamcorder);
699 if (ret != MM_ERROR_NONE)
700 goto _ERR_DEFAULT_VALUE_INIT;
702 /* add DPM camera policy changed callback */
703 if (hcamcorder->dpm_handle) {
704 ret = dpm_add_policy_changed_cb(hcamcorder->dpm_handle, "camera",
705 _mmcamcorder_dpm_camera_policy_changed_cb, (void *)hcamcorder, &hcamcorder->dpm_camera_cb_id);
706 if (ret != DPM_ERROR_NONE) {
707 MMCAM_LOG_ERROR("add DPM changed cb failed, keep going...");
708 hcamcorder->dpm_camera_cb_id = 0;
711 MMCAM_LOG_INFO("DPM camera changed cb id %d", hcamcorder->dpm_camera_cb_id);
714 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
715 /* initialize resource manager */
716 ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
717 __mmcamcorder_resource_release_cb, hcamcorder,
718 &hcamcorder->resource_manager);
719 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
720 MMCAM_LOG_ERROR("failed to initialize resource manager");
721 ret = MM_ERROR_CAMCORDER_INTERNAL;
722 goto _ERR_DEFAULT_VALUE_INIT;
724 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
726 ret = __mmcamcorder_init_configure_audio(hcamcorder);
727 if (ret != MM_ERROR_NONE)
728 goto _ERR_DEFAULT_VALUE_INIT;
731 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:CREATE:INIT_GSTREAMER");
733 ret = __mmcamcorder_init_gstreamer(hcamcorder->conf_main);
735 traceEnd(TTRACE_TAG_CAMERA);
738 MMCAM_LOG_ERROR("Failed to initialize gstreamer!!");
739 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
740 goto _ERR_DEFAULT_VALUE_INIT;
743 /* Make some attributes as read-only type */
744 _mmcamcorder_lock_readonly_attributes((MMHandleType)hcamcorder);
746 /* get system information */
747 __mmcamcorder_get_system_info(hcamcorder);
749 /* Set initial state */
750 _mmcamcorder_set_state((MMHandleType)hcamcorder, MM_CAMCORDER_STATE_NULL);
752 MMCAM_LOG_INFO("created handle %p", hcamcorder);
754 *handle = (MMHandleType)hcamcorder;
756 return MM_ERROR_NONE;
758 _ERR_DEFAULT_VALUE_INIT:
759 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
760 /* de-initialize resource manager */
761 if (hcamcorder->resource_manager != NULL)
762 mm_resource_manager_destroy(hcamcorder->resource_manager);
763 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
765 /* release DPM related handle */
766 if (hcamcorder->dpm_handle) {
767 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
768 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
770 /* remove camera policy changed callback */
771 if (hcamcorder->dpm_camera_cb_id > 0) {
772 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
773 hcamcorder->dpm_camera_cb_id = 0;
775 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
778 dpm_manager_destroy(hcamcorder->dpm_handle);
779 hcamcorder->dpm_handle = NULL;
782 /* release configure info */
783 __mmcamcorder_deinit_configure(hcamcorder);
785 /* deinitialize handle */
786 __mmcamcorder_deinit_handle(hcamcorder);
792 int _mmcamcorder_destroy(MMHandleType handle)
794 int ret = MM_ERROR_NONE;
795 int state = MM_CAMCORDER_STATE_NONE;
796 GstElement *sink_element = NULL;
797 int sink_element_size = 0;
799 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
804 MMCAM_LOG_ERROR("Not initialized");
805 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
806 goto _ERR_CAMCORDER_CMD_PRECON;
809 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
810 MMCAM_LOG_ERROR("Another command is running.");
811 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
812 goto _ERR_CAMCORDER_CMD_PRECON;
815 state = _mmcamcorder_get_state(handle);
816 if (state != MM_CAMCORDER_STATE_NULL) {
817 MMCAM_LOG_ERROR("Wrong state(%d)", state);
818 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
819 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
822 /* remove kept, but not used sink element in attribute */
823 mm_camcorder_get_attributes(handle, NULL,
824 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
827 GstStateChangeReturn result = gst_element_set_state(sink_element, GST_STATE_NULL);
829 MMCAM_LOG_WARNING("remove sink element %p, set state NULL result %d", sink_element, result);
831 gst_object_unref(sink_element);
835 /* wait for completion of sound play */
836 _mmcamcorder_sound_solo_play_wait(handle);
838 /* Release SubContext and pipeline */
839 if (hcamcorder->sub_context) {
840 if (hcamcorder->sub_context->element)
841 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
843 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
844 hcamcorder->sub_context = NULL;
847 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
848 /* de-initialize resource manager */
849 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
851 if (hcamcorder->resource_manager != NULL) {
852 ret = mm_resource_manager_destroy(hcamcorder->resource_manager);
853 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
854 MMCAM_LOG_ERROR("failed to de-initialize resource manager 0x%x", ret);
857 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
858 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
860 /* Remove messages which are not called yet */
861 _mmcamcorder_remove_message_all(handle);
863 #ifdef _MMCAMCORDER_RM_SUPPORT
864 _mmcamcorder_rm_release(handle);
865 #endif /* _MMCAMCORDER_RM_SUPPORT */
867 /* release DPM handle */
868 if (hcamcorder->dpm_handle) {
869 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
870 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
872 /* remove camera policy changed callback */
873 if (hcamcorder->dpm_camera_cb_id > 0) {
874 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
875 hcamcorder->dpm_camera_cb_id = 0;
877 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
880 dpm_manager_destroy(hcamcorder->dpm_handle);
881 hcamcorder->dpm_handle = NULL;
884 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
886 __mmcamcorder_deinit_handle(hcamcorder);
888 return MM_ERROR_NONE;
890 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
891 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
893 _ERR_CAMCORDER_CMD_PRECON:
895 MMCAM_LOG_ERROR("Destroy fail (type %d, state %d)", hcamcorder->type, state);
897 MMCAM_LOG_ERROR("Destroy fail (ret %x)", ret);
903 int _mmcamcorder_realize(MMHandleType handle)
905 int ret = MM_ERROR_NONE;
906 int state = MM_CAMCORDER_STATE_NONE;
907 int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
908 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
909 char *videosink_element_type = NULL;
910 const char *videosink_name = NULL;
913 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
915 /*MMCAM_LOG_INFO("");*/
918 MMCAM_LOG_ERROR("Not initialized");
919 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
923 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
924 MMCAM_LOG_ERROR("Another command is running.");
925 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
926 goto _ERR_CAMCORDER_CMD_PRECON;
929 state = _mmcamcorder_get_state(handle);
930 if (state != MM_CAMCORDER_STATE_NULL) {
931 MMCAM_LOG_ERROR("Wrong state(%d)", state);
932 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
933 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
936 /* Get profile mode and gdbus connection */
937 mm_camcorder_get_attributes(handle, NULL,
938 MMCAM_MODE, &hcamcorder->type,
939 MMCAM_GDBUS_CONNECTION, &hcamcorder->gdbus_conn, &conn_size,
942 if (!hcamcorder->gdbus_conn) {
943 MMCAM_LOG_ERROR("gdbus connection NULL");
944 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
945 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
948 MMCAM_LOG_INFO("Profile mode [%d], gdbus connection [%p]",
949 hcamcorder->type, hcamcorder->gdbus_conn);
951 mm_camcorder_get_attributes(handle, NULL,
952 MMCAM_DISPLAY_SURFACE, &display_surface_type,
953 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
956 /* alloc sub context */
957 hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
958 if (!hcamcorder->sub_context) {
959 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
960 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
963 /* Set basic configure information */
964 if (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE)
965 hcamcorder->sub_context->is_modified_rate = TRUE;
967 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
968 /* get video recording info */
969 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
970 CONFIGURE_CATEGORY_MAIN_RECORD,
972 &(hcamcorder->sub_context->info_video->support_dual_stream));
973 MMCAM_LOG_WARNING("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
975 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
976 CONFIGURE_CATEGORY_MAIN_RECORD,
978 &(hcamcorder->sub_context->info_video->use_videoscale));
979 MMCAM_LOG_WARNING("UseVideoscale [%d]", hcamcorder->sub_context->info_video->use_videoscale);
982 switch (display_surface_type) {
983 case MM_DISPLAY_SURFACE_OVERLAY:
984 videosink_element_type = strdup("VideosinkElementOverlay");
986 case MM_DISPLAY_SURFACE_EVAS:
987 videosink_element_type = strdup("VideosinkElementEvas");
989 case MM_DISPLAY_SURFACE_GL:
990 videosink_element_type = strdup("VideosinkElementGL");
992 case MM_DISPLAY_SURFACE_NULL:
993 videosink_element_type = strdup("VideosinkElementNull");
996 videosink_element_type = strdup("VideosinkElementOverlay");
1000 /* check string of videosink element */
1001 if (videosink_element_type) {
1002 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1003 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1004 videosink_element_type,
1005 &hcamcorder->sub_context->VideosinkElement);
1006 free(videosink_element_type);
1007 videosink_element_type = NULL;
1009 MMCAM_LOG_WARNING("strdup failed(display_surface_type %d). Use default Overlay type",
1010 display_surface_type);
1012 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1013 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1014 _MMCAMCORDER_DEFAULT_VIDEOSINK_TYPE,
1015 &hcamcorder->sub_context->VideosinkElement);
1018 _mmcamcorder_conf_get_value_element_name(hcamcorder->sub_context->VideosinkElement, &videosink_name);
1019 MMCAM_LOG_INFO("Videosink name : %s", videosink_name);
1021 /* get videoconvert element */
1022 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1023 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1024 "VideoconvertElement",
1025 &hcamcorder->sub_context->VideoconvertElement);
1027 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1028 CONFIGURE_CATEGORY_CTRL_CAPTURE,
1029 "SensorEncodedCapture",
1030 &(hcamcorder->sub_context->SensorEncodedCapture));
1031 MMCAM_LOG_INFO("Support sensor encoded capture : %d", hcamcorder->sub_context->SensorEncodedCapture);
1033 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1034 int dpm_camera_state = DPM_ALLOWED;
1036 /* check camera policy from DPM */
1037 if (hcamcorder->dpm_handle) {
1038 if (dpm_restriction_get_camera_state(hcamcorder->dpm_handle, &dpm_camera_state) == DPM_ERROR_NONE) {
1039 MMCAM_LOG_INFO("DPM camera state %d", dpm_camera_state);
1040 if (dpm_camera_state == DPM_DISALLOWED) {
1041 MMCAM_LOG_ERROR("CAMERA DISALLOWED by DPM");
1042 ret = MM_ERROR_POLICY_RESTRICTED;
1044 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
1046 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1049 MMCAM_LOG_ERROR("get DPM camera state failed, keep going...");
1052 MMCAM_LOG_WARNING("NULL dpm_handle");
1055 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1056 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1057 /* prepare resource manager for camera */
1058 if (hcamcorder->camera_resource == NULL) {
1059 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1060 MM_RESOURCE_MANAGER_RES_TYPE_CAMERA,
1062 &hcamcorder->camera_resource);
1063 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1064 MMCAM_LOG_ERROR("could not prepare for camera resource");
1065 ret = MM_ERROR_RESOURCE_INTERNAL;
1066 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1067 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1070 MMCAM_LOG_INFO("camera already acquired");
1073 /* prepare resource manager for "video_overlay only if display surface is X" */
1074 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
1075 if (hcamcorder->video_overlay_resource == NULL) {
1076 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1077 MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY,
1078 MM_RESOURCE_MANAGER_RES_VOLUME_FULL,
1079 &hcamcorder->video_overlay_resource);
1080 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1081 MMCAM_LOG_ERROR("could not prepare for overlay resource");
1082 ret = MM_ERROR_RESOURCE_INTERNAL;
1083 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1084 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1087 MMCAM_LOG_INFO("overlay already acquired");
1091 /* acquire resources */
1092 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1093 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1094 MMCAM_LOG_ERROR("could not acquire resources");
1095 ret = MM_ERROR_RESOURCE_INTERNAL;
1096 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1097 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1099 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1100 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1102 #ifdef _MMCAMCORDER_RM_SUPPORT
1103 ret = _mmcamcorder_rm_create(handle);
1104 if (ret != MM_ERROR_NONE) {
1105 MMCAM_LOG_ERROR("Resource create failed");
1106 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1108 ret = _mmcamcorder_rm_allocate(handle);
1109 if (ret != MM_ERROR_NONE) {
1110 MMCAM_LOG_ERROR("Resource allocation request failed");
1111 _mmcamcorder_rm_release(handle);
1112 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1114 #endif /* _MMCAMCORDER_RM_SUPPORT */
1117 /* create pipeline */
1118 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:CREATE_PIPELINE");
1120 ret = _mmcamcorder_create_pipeline(handle, hcamcorder->type);
1122 traceEnd(TTRACE_TAG_CAMERA);
1124 if (ret != MM_ERROR_NONE) {
1125 /* check internal error of gstreamer */
1126 if (hcamcorder->error_code != MM_ERROR_NONE) {
1127 ret = hcamcorder->error_code;
1128 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1131 /* release sub context */
1132 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1133 hcamcorder->sub_context = NULL;
1134 goto _ERR_CAMCORDER_CMD;
1137 /* set command function */
1138 ret = _mmcamcorder_set_functions(handle, hcamcorder->type);
1139 if (ret != MM_ERROR_NONE) {
1140 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1141 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1142 hcamcorder->sub_context = NULL;
1143 goto _ERR_CAMCORDER_CMD;
1146 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1148 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1150 return MM_ERROR_NONE;
1153 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1154 /* release hw resources */
1155 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1156 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1157 if (hcamcorder->camera_resource != NULL) {
1158 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1159 hcamcorder->camera_resource);
1160 hcamcorder->camera_resource = NULL;
1162 if (hcamcorder->video_overlay_resource != NULL) {
1163 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1164 hcamcorder->video_overlay_resource);
1165 hcamcorder->video_overlay_resource = NULL;
1167 mm_resource_manager_commit(hcamcorder->resource_manager);
1169 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1170 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1171 #ifdef _MMCAMCORDER_RM_SUPPORT
1172 _mmcamcorder_rm_deallocate(handle);
1173 _mmcamcorder_rm_release(handle);
1174 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1176 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1177 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1179 _ERR_CAMCORDER_CMD_PRECON:
1180 MMCAM_LOG_ERROR("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1186 int _mmcamcorder_unrealize(MMHandleType handle)
1188 int ret = MM_ERROR_NONE;
1189 int state = MM_CAMCORDER_STATE_NONE;
1191 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1196 MMCAM_LOG_ERROR("Not initialized");
1197 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1201 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1202 MMCAM_LOG_ERROR("Another command is running.");
1203 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1204 goto _ERR_CAMCORDER_CMD_PRECON;
1207 state = _mmcamcorder_get_state(handle);
1208 if (state != MM_CAMCORDER_STATE_READY) {
1209 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1210 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1211 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1214 /* Release SubContext */
1215 if (hcamcorder->sub_context) {
1216 /* destroy pipeline */
1217 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1218 /* Deallocate SubContext */
1219 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1220 hcamcorder->sub_context = NULL;
1223 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1224 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1225 MMCAM_LOG_WARNING("lock resource - cb calling %d", hcamcorder->is_release_cb_calling);
1227 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE &&
1228 hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM &&
1229 hcamcorder->is_release_cb_calling == FALSE) {
1231 /* release resource */
1232 if (hcamcorder->camera_resource != NULL) {
1233 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1234 hcamcorder->camera_resource);
1235 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1236 MMCAM_LOG_ERROR("could not mark camera resource for release");
1237 ret = MM_ERROR_CAMCORDER_INTERNAL;
1238 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1239 MMCAM_LOG_INFO("unlock resource");
1240 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1244 if (hcamcorder->video_overlay_resource != NULL) {
1245 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1246 hcamcorder->video_overlay_resource);
1247 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1248 MMCAM_LOG_ERROR("could not mark overlay resource for release");
1249 ret = MM_ERROR_CAMCORDER_INTERNAL;
1250 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1251 MMCAM_LOG_INFO("unlock resource");
1252 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1256 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1258 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1259 MMCAM_LOG_ERROR("failed to release resource, ret(0x%x)", ret);
1260 ret = MM_ERROR_CAMCORDER_INTERNAL;
1262 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1263 MMCAM_LOG_INFO("unlock resource");
1265 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1267 if (hcamcorder->camera_resource != NULL)
1268 hcamcorder->camera_resource = NULL;
1269 if (hcamcorder->video_overlay_resource != NULL)
1270 hcamcorder->video_overlay_resource = NULL;
1274 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1276 MMCAM_LOG_WARNING("unlock resource");
1277 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1279 #ifdef _MMCAMCORDER_RM_SUPPORT
1280 _mmcamcorder_rm_deallocate(handle);
1281 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1283 /* Deinitialize main context member */
1284 hcamcorder->command = NULL;
1286 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1288 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
1290 return MM_ERROR_NONE;
1292 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1293 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1295 _ERR_CAMCORDER_CMD_PRECON:
1297 MMCAM_LOG_ERROR("Unrealize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1302 int _mmcamcorder_start(MMHandleType handle)
1304 int ret = MM_ERROR_NONE;
1305 int state = MM_CAMCORDER_STATE_NONE;
1307 _MMCamcorderSubContext *sc = NULL;
1308 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1313 MMCAM_LOG_ERROR("Not initialized");
1314 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1318 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1319 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1321 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1322 MMCAM_LOG_ERROR("Another command is running.");
1323 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1324 goto _ERR_CAMCORDER_CMD_PRECON;
1327 state = _mmcamcorder_get_state(handle);
1328 if (state != MM_CAMCORDER_STATE_READY) {
1329 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1330 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1331 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1334 /* initialize error code */
1335 hcamcorder->error_code = MM_ERROR_NONE;
1337 /* set attributes related sensor */
1338 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1339 _mmcamcorder_set_attribute_to_camsensor(handle);
1341 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1342 if (ret != MM_ERROR_NONE) {
1343 /* check internal error of gstreamer */
1344 if (hcamcorder->error_code != MM_ERROR_NONE) {
1345 ret = hcamcorder->error_code;
1346 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1348 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1351 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1353 /* set attributes related sensor - after start preview */
1354 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1355 _mmcamcorder_set_attribute_to_camsensor2(handle);
1357 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1359 return MM_ERROR_NONE;
1361 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1362 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1364 _ERR_CAMCORDER_CMD_PRECON:
1365 /* check internal error of gstreamer */
1366 if (hcamcorder->error_code != MM_ERROR_NONE) {
1367 ret = hcamcorder->error_code;
1368 hcamcorder->error_code = MM_ERROR_NONE;
1370 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1373 MMCAM_LOG_ERROR("Start fail (type %d, state %d, ret %x)",
1374 hcamcorder->type, state, ret);
1379 int _mmcamcorder_stop(MMHandleType handle)
1381 int ret = MM_ERROR_NONE;
1382 int state = MM_CAMCORDER_STATE_NONE;
1384 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1389 MMCAM_LOG_ERROR("Not initialized");
1390 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1394 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1395 MMCAM_LOG_ERROR("Another command is running.");
1396 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1397 goto _ERR_CAMCORDER_CMD_PRECON;
1400 state = _mmcamcorder_get_state(handle);
1401 if (state != MM_CAMCORDER_STATE_PREPARE) {
1402 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1403 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1404 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1407 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_STOP);
1408 if (ret != MM_ERROR_NONE)
1409 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1411 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1413 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
1414 /* unsubscribe remained unsubscribed signal */
1415 g_mutex_lock(&hcamcorder->gdbus_info_sound.sync_mutex);
1416 if (hcamcorder->gdbus_info_sound.subscribe_id > 0) {
1417 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_sound.subscribe_id);
1418 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_sound.subscribe_id);
1420 g_mutex_unlock(&hcamcorder->gdbus_info_sound.sync_mutex);
1422 g_mutex_lock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1423 if (hcamcorder->gdbus_info_solo_sound.subscribe_id > 0) {
1424 MMCAM_LOG_WARNING("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_solo_sound.subscribe_id);
1425 g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_solo_sound.subscribe_id);
1427 g_mutex_unlock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
1430 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1432 return MM_ERROR_NONE;
1434 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1435 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1437 _ERR_CAMCORDER_CMD_PRECON:
1439 MMCAM_LOG_ERROR("Stop fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1445 int _mmcamcorder_capture_start(MMHandleType handle)
1447 int ret = MM_ERROR_NONE;
1448 int state = MM_CAMCORDER_STATE_NONE;
1449 int state_FROM_0 = MM_CAMCORDER_STATE_PREPARE;
1450 int state_FROM_1 = MM_CAMCORDER_STATE_RECORDING;
1451 int state_FROM_2 = MM_CAMCORDER_STATE_PAUSED;
1453 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1458 MMCAM_LOG_ERROR("Not initialized");
1459 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1463 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1464 MMCAM_LOG_ERROR("Another command is running.");
1465 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1466 goto _ERR_CAMCORDER_CMD_PRECON;
1469 state = _mmcamcorder_get_state(handle);
1470 if (state != state_FROM_0 && state != state_FROM_1 && state != state_FROM_2) {
1471 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1472 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1473 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1476 /* Handle capture in recording case */
1477 if (state == state_FROM_1 || state == state_FROM_2) {
1478 if (hcamcorder->capture_in_recording == TRUE) {
1479 MMCAM_LOG_ERROR("Capturing in recording (%d)", state);
1480 ret = MM_ERROR_CAMCORDER_DEVICE_BUSY;
1481 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1483 g_mutex_lock(&hcamcorder->task_thread_lock);
1484 if (hcamcorder->task_thread_state == _MMCAMCORDER_TASK_THREAD_STATE_NONE) {
1485 hcamcorder->capture_in_recording = TRUE;
1486 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING;
1487 MMCAM_LOG_INFO("send signal for capture in recording");
1488 g_cond_signal(&hcamcorder->task_thread_cond);
1489 g_mutex_unlock(&hcamcorder->task_thread_lock);
1491 MMCAM_LOG_ERROR("task thread busy : %d", hcamcorder->task_thread_state);
1492 g_mutex_unlock(&hcamcorder->task_thread_lock);
1493 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1494 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1499 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CAPTURE);
1500 if (ret != MM_ERROR_NONE)
1501 goto _ERR_CAMCORDER_CMD;
1503 /* Do not change state when recording snapshot capture */
1504 if (state == state_FROM_0)
1505 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_CAPTURING);
1507 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1509 /* Init break continuous shot attr */
1510 if (mm_camcorder_set_attributes(handle, NULL, MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, 0, NULL) != MM_ERROR_NONE)
1511 MMCAM_LOG_WARNING("capture-break-cont-shot set 0 failed");
1513 return MM_ERROR_NONE;
1516 if (hcamcorder->capture_in_recording)
1517 hcamcorder->capture_in_recording = FALSE;
1519 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1520 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1522 _ERR_CAMCORDER_CMD_PRECON:
1524 MMCAM_LOG_ERROR("Capture start fail (type %d, state %d, ret %x)",
1525 hcamcorder->type, state, ret);
1530 int _mmcamcorder_capture_stop(MMHandleType handle)
1532 int ret = MM_ERROR_NONE;
1533 int state = MM_CAMCORDER_STATE_NONE;
1534 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1539 MMCAM_LOG_ERROR("Not initialized");
1540 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1544 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1545 MMCAM_LOG_ERROR("Another command is running.");
1546 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1547 goto _ERR_CAMCORDER_CMD_PRECON;
1550 state = _mmcamcorder_get_state(handle);
1551 if (state != MM_CAMCORDER_STATE_CAPTURING) {
1552 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1553 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1554 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1557 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1558 if (ret != MM_ERROR_NONE)
1559 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1561 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1563 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1565 return MM_ERROR_NONE;
1567 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1568 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1570 _ERR_CAMCORDER_CMD_PRECON:
1572 MMCAM_LOG_ERROR("Capture stop fail (type %d, state %d, ret %x)",
1573 hcamcorder->type, state, ret);
1578 int _mmcamcorder_record(MMHandleType handle)
1580 int ret = MM_ERROR_NONE;
1581 int state = MM_CAMCORDER_STATE_NONE;
1582 int dpm_mic_state = DPM_ALLOWED;
1584 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1585 _MMCamcorderSubContext *sc = NULL;
1589 if (!hcamcorder || !MMF_CAMCORDER_SUBCONTEXT(hcamcorder)) {
1590 MMCAM_LOG_ERROR("Not initialized");
1591 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1595 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1597 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1598 MMCAM_LOG_ERROR("Another command is running.");
1599 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1600 goto _ERR_CAMCORDER_CMD_PRECON;
1603 state = _mmcamcorder_get_state(handle);
1604 if (state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_PAUSED) {
1605 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1606 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1607 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1610 /* initialize error code */
1611 hcamcorder->error_code = MM_ERROR_NONE;
1613 /* get audio disable */
1614 mm_camcorder_get_attributes(handle, NULL,
1615 MMCAM_AUDIO_DISABLE, &sc->audio_disable,
1618 sc->audio_disable |= sc->is_modified_rate;
1620 /* check mic policy from DPM */
1621 if (hcamcorder->dpm_handle && sc->audio_disable == FALSE) {
1622 if (dpm_restriction_get_microphone_state(hcamcorder->dpm_handle, &dpm_mic_state) == DPM_ERROR_NONE) {
1623 MMCAM_LOG_INFO("DPM mic state %d", dpm_mic_state);
1624 if (dpm_mic_state == DPM_DISALLOWED) {
1625 MMCAM_LOG_ERROR("MIC DISALLOWED by DPM");
1626 ret = MM_ERROR_COMMON_INVALID_PERMISSION;
1628 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
1630 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1633 MMCAM_LOG_ERROR("get DPM mic state failed, keep going...");
1636 MMCAM_LOG_WARNING("skip dpm check - handle %p, audio disable %d",
1637 hcamcorder->dpm_handle, sc->audio_disable);
1640 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_RECORD);
1641 if (ret != MM_ERROR_NONE) {
1642 /* check internal error of gstreamer */
1643 if (hcamcorder->error_code != MM_ERROR_NONE) {
1644 ret = hcamcorder->error_code;
1645 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1647 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1650 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_RECORDING);
1652 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1654 return MM_ERROR_NONE;
1656 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1657 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1659 _ERR_CAMCORDER_CMD_PRECON:
1660 /* check internal error of gstreamer */
1661 if (hcamcorder->error_code != MM_ERROR_NONE) {
1662 ret = hcamcorder->error_code;
1663 hcamcorder->error_code = MM_ERROR_NONE;
1665 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1668 MMCAM_LOG_ERROR("Record fail (type %d, state %d, ret %x)",
1669 hcamcorder->type, state, ret);
1675 int _mmcamcorder_pause(MMHandleType handle)
1677 int ret = MM_ERROR_NONE;
1678 int state = MM_CAMCORDER_STATE_NONE;
1680 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1685 MMCAM_LOG_ERROR("Not initialized");
1686 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1690 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1691 MMCAM_LOG_ERROR("Another command is running.");
1692 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1693 goto _ERR_CAMCORDER_CMD_PRECON;
1696 state = _mmcamcorder_get_state(handle);
1697 if (state != MM_CAMCORDER_STATE_RECORDING) {
1698 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1699 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1700 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1703 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PAUSE);
1704 if (ret != MM_ERROR_NONE)
1705 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1707 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PAUSED);
1709 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1711 return MM_ERROR_NONE;
1713 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1714 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1716 _ERR_CAMCORDER_CMD_PRECON:
1718 MMCAM_LOG_ERROR("Pause fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1724 int _mmcamcorder_commit(MMHandleType handle)
1726 int ret = MM_ERROR_NONE;
1727 int state = MM_CAMCORDER_STATE_NONE;
1729 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1734 MMCAM_LOG_ERROR("Not initialized");
1735 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1739 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1740 MMCAM_LOG_ERROR("Another command is running.");
1741 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1742 goto _ERR_CAMCORDER_CMD_PRECON;
1745 state = _mmcamcorder_get_state(handle);
1746 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1747 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1748 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1749 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1752 /* initialize error code */
1753 hcamcorder->error_code = MM_ERROR_NONE;
1755 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_COMMIT);
1756 if (ret != MM_ERROR_NONE)
1757 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1759 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1761 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1763 return MM_ERROR_NONE;
1765 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1766 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1768 _ERR_CAMCORDER_CMD_PRECON:
1770 MMCAM_LOG_ERROR("Commit fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1776 int _mmcamcorder_cancel(MMHandleType handle)
1778 int ret = MM_ERROR_NONE;
1779 int state = MM_CAMCORDER_STATE_NONE;
1781 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1786 MMCAM_LOG_ERROR("Not initialized");
1787 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1791 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1792 MMCAM_LOG_ERROR("Another command is running.");
1793 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1794 goto _ERR_CAMCORDER_CMD_PRECON;
1797 state = _mmcamcorder_get_state(handle);
1798 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1799 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1800 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1801 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1804 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CANCEL);
1805 if (ret != MM_ERROR_NONE)
1806 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1808 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1810 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1812 return MM_ERROR_NONE;
1814 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1815 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1817 _ERR_CAMCORDER_CMD_PRECON:
1819 MMCAM_LOG_ERROR("Cancel fail (type %d, state %d, ret %x)",
1820 hcamcorder->type, state, ret);
1824 /* } Internal command functions */
1827 int _mmcamcorder_commit_async_end(MMHandleType handle)
1831 MMCAM_LOG_WARNING("_mmcamcorder_commit_async_end : MM_CAMCORDER_STATE_PREPARE");
1832 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1834 return MM_ERROR_NONE;
1838 int _mmcamcorder_set_message_callback(MMHandleType handle, MMMessageCallback callback, void *user_data)
1840 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1842 MMCAM_LOG_INFO("%p", hcamcorder);
1844 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1846 if (callback == NULL)
1847 MMCAM_LOG_WARNING("Message Callback is disabled, because application sets it to NULL");
1849 if (!_MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(hcamcorder)) {
1850 MMCAM_LOG_WARNING("Application's message callback is running now");
1851 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1854 /* set message callback to message handle */
1855 hcamcorder->msg_cb = callback;
1856 hcamcorder->msg_cb_param = user_data;
1858 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1860 return MM_ERROR_NONE;
1864 int _mmcamcorder_set_video_stream_callback(MMHandleType handle, mm_camcorder_video_stream_callback callback, void *user_data)
1866 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1868 /*MMCAM_LOG_INFO("");*/
1870 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1872 if (callback == NULL)
1873 MMCAM_LOG_WARNING("Video Stream Callback is disabled, because application sets it to NULL");
1875 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
1877 hcamcorder->vstream_cb = callback;
1878 hcamcorder->vstream_cb_param = user_data;
1880 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1882 return MM_ERROR_NONE;
1886 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle, mm_camcorder_audio_stream_callback callback, void *user_data)
1888 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1892 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1894 if (callback == NULL)
1895 MMCAM_LOG_WARNING("Audio Stream Callback is disabled, because application sets it to NULL");
1897 if (!_MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(hcamcorder)) {
1898 MMCAM_LOG_WARNING("Application's audio stream callback is running now");
1899 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1902 hcamcorder->astream_cb = callback;
1903 hcamcorder->astream_cb_param = user_data;
1905 _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder);
1907 return MM_ERROR_NONE;
1911 int _mmcamcorder_set_muxed_stream_callback(MMHandleType handle, mm_camcorder_muxed_stream_callback callback, void *user_data)
1913 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1917 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1919 if (callback == NULL)
1920 MMCAM_LOG_WARNING("Muxed Stream Callback is disabled, because application sets it to NULL");
1922 if (!_MMCAMCORDER_TRYLOCK_MSTREAM_CALLBACK(hcamcorder)) {
1923 MMCAM_LOG_WARNING("Application's muxed stream callback is running now");
1924 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1927 hcamcorder->mstream_cb = callback;
1928 hcamcorder->mstream_cb_param = user_data;
1930 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
1932 return MM_ERROR_NONE;
1936 int _mmcamcorder_set_video_capture_callback(MMHandleType handle, mm_camcorder_video_capture_callback callback, void *user_data)
1938 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1942 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1944 if (callback == NULL)
1945 MMCAM_LOG_WARNING("Video Capture Callback is disabled, because application sets it to NULLL");
1947 if (!_MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(hcamcorder)) {
1948 MMCAM_LOG_WARNING("Application's video capture callback is running now");
1949 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1952 hcamcorder->vcapture_cb = callback;
1953 hcamcorder->vcapture_cb_param = user_data;
1955 _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(hcamcorder);
1957 return MM_ERROR_NONE;
1961 int _mmcamcorder_set_video_encode_decision_callback(MMHandleType handle, mm_camcorder_video_encode_decision_callback callback, void *user_data)
1963 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1967 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1969 if (callback == NULL)
1970 MMCAM_LOG_WARNING("Video Encode Decision Callback is disabled, because application sets it to NULL");
1972 if (!_MMCAMCORDER_TRYLOCK_VEDECISION_CALLBACK(hcamcorder)) {
1973 MMCAM_LOG_WARNING("Application's video encode decision callback is running now");
1974 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1977 hcamcorder->vedecision_cb = callback;
1978 hcamcorder->vedecision_cb_param = user_data;
1980 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
1982 return MM_ERROR_NONE;
1986 int _mmcamcorder_get_current_state(MMHandleType handle)
1988 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1992 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1994 return _mmcamcorder_get_state(handle);
1997 int _mmcamcorder_init_focusing(MMHandleType handle)
2000 int state = MM_CAMCORDER_STATE_NONE;
2001 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2002 int af_range = MM_CAMCORDER_AUTO_FOCUS_NORMAL;
2003 int sensor_focus_mode = 0;
2004 int sensor_af_range = 0;
2005 int current_focus_mode = 0;
2006 int current_af_range = 0;
2007 mmf_camcorder_t *hcamcorder = NULL;
2008 _MMCamcorderSubContext *sc = NULL;
2009 GstCameraControl *control = NULL;
2013 hcamcorder = MMF_CAMCORDER(handle);
2014 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2016 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2017 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2019 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2020 MMCAM_LOG_ERROR("Another command is running.");
2021 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2024 state = _mmcamcorder_get_state(handle);
2026 if (state == MM_CAMCORDER_STATE_CAPTURING ||
2027 state < MM_CAMCORDER_STATE_PREPARE) {
2028 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2029 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2030 return MM_ERROR_CAMCORDER_INVALID_STATE;
2033 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2034 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2035 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2036 return MM_ERROR_NONE;
2039 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2040 if (control == NULL) {
2041 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2042 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2043 return MM_ERROR_CAMCORDER_INTERNAL;
2046 ret = gst_camera_control_stop_auto_focus(control);
2048 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2049 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2050 return MM_ERROR_CAMCORDER_DEVICE_IO;
2053 /* Initialize lens position */
2054 mm_camcorder_get_attributes(handle, NULL,
2055 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2056 MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
2058 sensor_af_range = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_AF_SCAN_RANGE, af_range);
2059 sensor_focus_mode = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_FOCUS_MODE, focus_mode);
2061 gst_camera_control_get_focus(control, ¤t_focus_mode, ¤t_af_range);
2063 if (current_focus_mode != sensor_focus_mode || current_af_range != sensor_af_range) {
2064 ret = gst_camera_control_set_focus(control, sensor_focus_mode, sensor_af_range);
2066 MMCAM_LOG_INFO("No need to init FOCUS [mode:%d, range:%d]", focus_mode, af_range);
2070 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2073 MMCAM_LOG_INFO("Lens init success.");
2074 return MM_ERROR_NONE;
2076 MMCAM_LOG_ERROR("Lens init fail.");
2077 return MM_ERROR_CAMCORDER_DEVICE_IO;
2081 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction)
2084 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2085 int ret = MM_ERROR_UNKNOWN;
2086 char *err_attr_name = NULL;
2088 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2089 mmf_return_val_if_fail(direction, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2091 /*MMCAM_LOG_INFO("");*/
2093 if (!_MMCAMCORDER_TRYLOCK_CMD(handle)) {
2094 MMCAM_LOG_ERROR("Another command is running.");
2095 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2098 state = _mmcamcorder_get_state(handle);
2099 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2100 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2101 _MMCAMCORDER_UNLOCK_CMD(handle);
2102 return MM_ERROR_CAMCORDER_INVALID_STATE;
2105 /* TODO : call a auto or manual focus function */
2106 ret = mm_camcorder_get_attributes(handle, &err_attr_name,
2107 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2109 if (ret != MM_ERROR_NONE) {
2110 MMCAM_LOG_WARNING("Get focus-mode fail. (%s:%x)", err_attr_name, ret);
2111 SAFE_FREE(err_attr_name);
2112 _MMCAMCORDER_UNLOCK_CMD(handle);
2116 switch (focus_mode) {
2117 case MM_CAMCORDER_FOCUS_MODE_MANUAL:
2118 ret = _mmcamcorder_adjust_manual_focus(handle, direction);
2120 case MM_CAMCORDER_FOCUS_MODE_AUTO:
2121 case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
2122 case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
2123 ret = _mmcamcorder_adjust_auto_focus(handle);
2126 MMCAM_LOG_ERROR("It doesn't adjust focus. Focusing mode(%d)", focus_mode);
2127 ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2130 _MMCAMCORDER_UNLOCK_CMD(handle);
2135 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction)
2140 int focus_level = 0;
2141 float unit_level = 0;
2142 GstCameraControl *control = NULL;
2143 _MMCamcorderSubContext *sc = NULL;
2144 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2148 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2149 mmf_return_val_if_fail(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL != 1, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
2150 mmf_return_val_if_fail((direction >= MM_CAMCORDER_MF_LENS_DIR_FORWARD) &&
2151 (direction <= MM_CAMCORDER_MF_LENS_DIR_BACKWARD),
2152 MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2154 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2155 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2157 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2158 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2159 return MM_ERROR_NONE;
2162 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2163 if (control == NULL) {
2164 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2165 return MM_ERROR_CAMCORDER_INTERNAL;
2168 /* TODO : get max, min level */
2169 if (max_level - min_level + 1 < _MMFCAMCORDER_FOCUS_TOTAL_LEVEL)
2170 MMCAM_LOG_WARNING("Total level of manual focus of MMF is greater than that of the camera driver.");
2172 unit_level = ((float)max_level - (float)min_level)/(float)(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL - 1);
2174 if (!gst_camera_control_get_focus_level(control, &cur_level)) {
2175 MMCAM_LOG_ERROR("Can't get current level of manual focus.");
2176 return MM_ERROR_CAMCORDER_DEVICE_IO;
2179 /* TODO : adjust unit level value */
2180 if (direction == MM_CAMCORDER_MF_LENS_DIR_FORWARD)
2181 focus_level = cur_level + unit_level;
2182 else if (direction == MM_CAMCORDER_MF_LENS_DIR_BACKWARD)
2183 focus_level = cur_level - unit_level;
2185 if (focus_level > max_level)
2186 focus_level = max_level;
2187 else if (focus_level < min_level)
2188 focus_level = min_level;
2190 if (!gst_camera_control_set_focus_level(control, focus_level)) {
2191 MMCAM_LOG_ERROR("Manual focusing fail.");
2192 return MM_ERROR_CAMCORDER_DEVICE_IO;
2195 return MM_ERROR_NONE;
2199 int _mmcamcorder_adjust_auto_focus(MMHandleType handle)
2202 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2203 GstCameraControl *control = NULL;
2204 _MMCamcorderSubContext *sc = NULL;
2206 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2208 /*MMCAM_LOG_INFO("");*/
2210 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2212 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2213 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2214 return MM_ERROR_NONE;
2217 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2220 ret = gst_camera_control_start_auto_focus(control);
2222 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2227 MMCAM_LOG_INFO("Auto focusing start success.");
2228 return MM_ERROR_NONE;
2230 MMCAM_LOG_ERROR("Auto focusing start fail.");
2231 return MM_ERROR_CAMCORDER_DEVICE_IO;
2235 int _mmcamcorder_stop_focusing(MMHandleType handle)
2237 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2238 _MMCamcorderSubContext *sc = NULL;
2241 GstCameraControl *control = NULL;
2243 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2245 /*MMCAM_LOG_INFO("");*/
2247 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2249 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2250 MMCAM_LOG_ERROR("Another command is running.");
2251 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2254 state = _mmcamcorder_get_state(handle);
2255 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2256 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2257 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2258 return MM_ERROR_CAMCORDER_INVALID_STATE;
2261 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2262 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2263 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2264 return MM_ERROR_NONE;
2267 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2269 ret = gst_camera_control_stop_auto_focus(control);
2271 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2275 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2278 MMCAM_LOG_INFO("Auto focusing stop success.");
2279 return MM_ERROR_NONE;
2281 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2282 return MM_ERROR_CAMCORDER_DEVICE_IO;
2286 int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
2288 GstCameraControl *control = NULL;
2289 _MMCamcorderSubContext *sc = NULL;
2290 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2292 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2293 mmf_return_val_if_fail(level, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2295 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2296 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2298 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2299 MMCAM_LOG_ERROR("Can't cast Video source into camera control.");
2300 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2303 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2305 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2306 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2309 if (!gst_camera_control_get_focus_level(control, level)) {
2310 MMCAM_LOG_ERROR("get focus level failed");
2311 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2314 MMCAM_LOG_INFO("focus level[%d]", *level);
2316 return MM_ERROR_NONE;
2320 /*-----------------------------------------------
2321 | CAMCORDER INTERNAL LOCAL |
2322 -----------------------------------------------*/
2323 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf)
2325 static const int max_argc = 10;
2329 gchar **argv = NULL;
2331 gboolean ret = FALSE;
2332 type_string_array *GSTInitOption = NULL;
2334 mmf_return_val_if_fail(conf, FALSE);
2339 argc = malloc(sizeof(int));
2340 argv = malloc(sizeof(gchar *) * max_argc);
2345 memset(argv, 0, sizeof(gchar *) * max_argc);
2349 argv[0] = g_strdup("mmcamcorder");
2352 _mmcamcorder_conf_get_value_string_array(conf,
2353 CONFIGURE_CATEGORY_MAIN_GENERAL,
2356 if (GSTInitOption != NULL && GSTInitOption->value) {
2357 cnt_str = GSTInitOption->count;
2358 for ( ; *argc < max_argc && *argc <= cnt_str ; (*argc)++)
2359 argv[*argc] = g_strdup(GSTInitOption->value[(*argc)-1]);
2362 MMCAM_LOG_INFO("initializing gstreamer with following parameter[argc:%d]", *argc);
2364 for (i = 0; i < *argc; i++)
2365 MMCAM_LOG_INFO("argv[%d] : %s", i, argv[i]);
2367 /* initializing gstreamer */
2368 ret = gst_init_check(argc, &argv, &err);
2370 MMCAM_LOG_ERROR("Could not initialize GStreamer: %s ", err ? err->message : "unknown error occurred");
2376 for (i = 0; i < *argc; i++) {
2396 MMCAM_LOG_ERROR("failed to initialize gstreamer");
2412 int _mmcamcorder_get_state(MMHandleType handle)
2415 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2417 mmf_return_val_if_fail(hcamcorder, -1);
2419 _MMCAMCORDER_LOCK_STATE(handle);
2421 state = hcamcorder->state;
2422 /*MMCAM_LOG_INFO("state=%d",state);*/
2424 _MMCAMCORDER_UNLOCK_STATE(handle);
2430 int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state)
2432 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2434 mmf_return_val_if_fail(hcamcorder && state && old_state, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2436 _MMCAMCORDER_LOCK_STATE(handle);
2438 *state = hcamcorder->state;
2439 *old_state = hcamcorder->old_state;
2441 _MMCAMCORDER_UNLOCK_STATE(handle);
2443 return MM_ERROR_NONE;
2447 void _mmcamcorder_set_state(MMHandleType handle, int state)
2450 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2451 _MMCamcorderMsgItem msg;
2453 mmf_return_if_fail(hcamcorder);
2455 /*MMCAM_LOG_INFO("");*/
2457 _MMCAMCORDER_LOCK_STATE(handle);
2459 old_state = hcamcorder->state;
2460 if (old_state != state) {
2461 hcamcorder->state = state;
2462 hcamcorder->old_state = old_state;
2464 MMCAM_LOG_INFO("set state[%d -> %d] and send state-changed message", old_state, state);
2466 /* To discern who changes the state */
2467 switch (hcamcorder->state_change_by_system) {
2468 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
2469 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_RM;
2470 msg.param.state.code = MM_ERROR_NONE;
2472 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
2473 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY;
2474 msg.param.state.code = MM_ERROR_NONE;
2476 case _MMCAMCORDER_STATE_CHANGE_NORMAL:
2478 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED;
2479 msg.param.state.code = MM_ERROR_NONE;
2483 msg.param.state.previous = old_state;
2484 msg.param.state.current = state;
2486 /*MMCAM_LOG_INFO("_mmcamcorder_send_message : msg : %p, id:%x", &msg, msg.id);*/
2487 _mmcamcorder_send_message(handle, &msg);
2490 _MMCAMCORDER_UNLOCK_STATE(handle);
2496 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
2499 _MMCamcorderSubContext *sc = NULL;
2501 /*MMCAM_LOG_INFO("");*/
2503 /* alloc container */
2504 sc = (_MMCamcorderSubContext *)g_malloc0(sizeof(_MMCamcorderSubContext));
2506 sc->element_num = _MMCAMCORDER_PIPELINE_ELEMENT_NUM;
2507 sc->encode_element_num = _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM;
2509 /* alloc info for each mode */
2511 case MM_CAMCORDER_MODE_AUDIO:
2512 sc->info_audio = g_malloc0(sizeof(_MMCamcorderAudioInfo));
2514 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2516 sc->info_image = g_malloc0(sizeof(_MMCamcorderImageInfo));
2517 sc->info_video = g_malloc0(sizeof(_MMCamcorderVideoInfo));
2519 sc->info_image->sound_status = _SOUND_STATUS_INIT;
2520 g_mutex_init(&sc->info_video->size_check_lock);
2524 /* alloc element array */
2525 sc->element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->element_num);
2526 sc->encode_element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->encode_element_num);
2528 for (i = 0 ; i < sc->element_num ; i++) {
2529 sc->element[i].id = _MMCAMCORDER_NONE;
2530 sc->element[i].gst = NULL;
2533 for (i = 0 ; i < sc->encode_element_num ; i++) {
2534 sc->encode_element[i].id = _MMCAMCORDER_NONE;
2535 sc->encode_element[i].gst = NULL;
2538 sc->fourcc = 0x80000000;
2539 sc->frame_stability_count = 0;
2540 sc->drop_vframe = 0;
2541 sc->pass_first_vframe = 0;
2542 sc->is_modified_rate = FALSE;
2548 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
2554 MMCAM_LOG_INFO("release element");
2555 g_free(sc->element);
2559 if (sc->encode_element) {
2560 MMCAM_LOG_INFO("release encode_element");
2561 g_free(sc->encode_element);
2562 sc->encode_element = NULL;
2565 if (sc->info_image) {
2566 MMCAM_LOG_INFO("release info_image");
2567 g_free(sc->info_image);
2568 sc->info_image = NULL;
2571 if (sc->info_video) {
2572 MMCAM_LOG_INFO("release info_video");
2573 SAFE_G_FREE(sc->info_video->filename);
2574 g_mutex_clear(&sc->info_video->size_check_lock);
2575 g_free(sc->info_video);
2576 sc->info_video = NULL;
2579 if (sc->info_audio) {
2580 MMCAM_LOG_INFO("release info_audio");
2581 SAFE_G_FREE(sc->info_audio->filename);
2582 g_free(sc->info_audio);
2583 sc->info_audio = NULL;
2594 int _mmcamcorder_set_functions(MMHandleType handle, int type)
2596 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2598 /*MMCAM_LOG_INFO("");*/
2601 case MM_CAMCORDER_MODE_AUDIO:
2602 hcamcorder->command = _mmcamcorder_audio_command;
2604 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2606 hcamcorder->command = _mmcamcorder_video_capture_command;
2610 return MM_ERROR_NONE;
2614 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data)
2616 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2617 _MMCamcorderSubContext *sc = NULL;
2619 mmf_return_val_if_fail(hcamcorder, FALSE);
2620 mmf_return_val_if_fail(message, FALSE);
2622 MMCAM_LOG_DEBUG("message type[0x%x]", GST_MESSAGE_TYPE(message));
2624 switch (GST_MESSAGE_TYPE(message)) {
2625 case GST_MESSAGE_EOS:
2627 MMCAM_LOG_ERROR("Got EOS from element[%s]... but should not be reached here!",
2628 GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));
2631 case GST_MESSAGE_ERROR:
2634 gchar *debug = NULL;
2636 gst_message_parse_error(message, &err, &debug);
2638 __mmcamcorder_handle_gst_error((MMHandleType)hcamcorder, message, err);
2641 MMCAM_LOG_ERROR("GSTERR: %s", err->message);
2647 MMCAM_LOG_ERROR("Error Debug: %s", debug);
2653 case GST_MESSAGE_WARNING:
2657 gst_message_parse_warning(message, &err, &debug);
2659 MMCAM_LOG_WARNING("GSTWARN: %s", err->message);
2661 __mmcamcorder_handle_gst_warning((MMHandleType)hcamcorder, message, err);
2667 case GST_MESSAGE_STATE_CHANGED:
2669 const GValue *vnewstate;
2671 GstElement *pipeline = NULL;
2673 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2674 if ((sc) && (sc->element)) {
2675 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst) {
2676 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
2677 if (message->src == (GstObject*)pipeline) {
2678 vnewstate = gst_structure_get_value(gst_message_get_structure(message), "new-state");
2680 newstate = (GstState)vnewstate->data[0].v_int;
2681 MMCAM_LOG_INFO("GST_MESSAGE_STATE_CHANGED[%s]", gst_element_state_get_name(newstate));
2683 MMCAM_LOG_WARNING("get new state failed from msg");
2690 case GST_MESSAGE_NEW_CLOCK:
2692 GstClock *pipe_clock = NULL;
2693 gst_message_parse_new_clock(message, &pipe_clock);
2694 MMCAM_LOG_INFO("GST_MESSAGE_NEW_CLOCK[%s]", (pipe_clock ? GST_OBJECT_NAME(pipe_clock) : "NULL"));
2698 MMCAM_LOG_DEBUG("unhandled message type[0x%x]", GST_MESSAGE_TYPE(message));
2706 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
2709 gchar *debug_info = NULL;
2711 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2712 _MMCamcorderSubContext *sc = NULL;
2714 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
2715 mmf_return_val_if_fail(message, GST_BUS_DROP);
2717 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2718 mmf_return_val_if_fail(sc, GST_BUS_DROP);
2720 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
2721 /* parse error message */
2722 gst_message_parse_error(message, &err, &debug_info);
2725 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
2731 MMCAM_LOG_WARNING("failed to parse error message");
2732 return GST_BUS_PASS;
2735 /* check domain[RESOURCE] and element[VIDEOSRC] */
2736 if (err->domain == GST_RESOURCE_ERROR &&
2737 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2738 switch (err->code) {
2739 case GST_RESOURCE_ERROR_BUSY:
2740 MMCAM_LOG_ERROR("Camera device [busy]");
2741 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_BUSY;
2743 case GST_RESOURCE_ERROR_OPEN_WRITE:
2744 MMCAM_LOG_ERROR("Camera device [open failed]");
2745 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2747 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2748 MMCAM_LOG_ERROR("Camera device [open failed]");
2749 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN;
2751 case GST_RESOURCE_ERROR_OPEN_READ:
2752 MMCAM_LOG_ERROR("Camera device [register trouble]");
2753 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE;
2755 case GST_RESOURCE_ERROR_NOT_FOUND:
2756 MMCAM_LOG_ERROR("Camera device [device not found]");
2757 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND;
2759 case GST_RESOURCE_ERROR_TOO_LAZY:
2760 MMCAM_LOG_ERROR("Camera device [timeout]");
2761 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_TIMEOUT;
2763 case GST_RESOURCE_ERROR_SETTINGS:
2764 MMCAM_LOG_ERROR("Camera device [not supported]");
2765 hcamcorder->error_code = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2767 case GST_RESOURCE_ERROR_FAILED:
2768 MMCAM_LOG_ERROR("Camera device [working failed].");
2769 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_IO;
2772 MMCAM_LOG_ERROR("Camera device [General(%d)]", err->code);
2773 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE;
2777 hcamcorder->error_occurs = TRUE;
2782 /* store error code and drop this message if cmd is running */
2783 if (hcamcorder->error_code != MM_ERROR_NONE) {
2784 _MMCamcorderMsgItem msg;
2786 /* post error to application */
2787 hcamcorder->error_occurs = TRUE;
2788 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2789 msg.param.code = hcamcorder->error_code;
2790 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2792 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
2793 _MMCamcorderMsgItem msg;
2795 if (gst_structure_has_name(gst_message_get_structure(message), "avsysvideosrc-AF") ||
2796 gst_structure_has_name(gst_message_get_structure(message), "camerasrc-AF")) {
2797 int focus_state = 0;
2799 gst_structure_get_int(gst_message_get_structure(message), "focus-state", &focus_state);
2800 MMCAM_LOG_INFO("Focus State:%d", focus_state);
2802 msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED;
2803 msg.param.code = focus_state;
2804 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2805 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) {
2809 if (gst_structure_get_int(gst_message_get_structure(message), "progress", &progress)) {
2810 gst_structure_get_int(gst_message_get_structure(message), "status", &status);
2811 MMCAM_LOG_INFO("HDR progress %d percent, status %d", progress, status);
2813 msg.id = MM_MESSAGE_CAMCORDER_HDR_PROGRESS;
2814 msg.param.code = progress;
2815 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2817 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) {
2819 const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");;
2820 GstCameraControlFaceDetectInfo *fd_info = NULL;
2821 MMCamFaceDetectInfo *cam_fd_info = NULL;
2824 fd_info = (GstCameraControlFaceDetectInfo *)g_value_get_pointer(g_value);
2826 if (fd_info == NULL) {
2827 MMCAM_LOG_WARNING("fd_info is NULL");
2828 gst_message_unref(message);
2829 return GST_BUS_DROP;
2832 cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
2834 /* set total face count */
2835 cam_fd_info->num_of_faces = fd_info->num_of_faces;
2837 if (cam_fd_info->num_of_faces > 0) {
2838 cam_fd_info->face_info = (MMCamFaceInfo *)g_malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
2839 MMCAM_LOG_DEBUG("face detection - count %d", cam_fd_info->num_of_faces);
2840 /* set information of each face */
2841 for (i = 0 ; i < cam_fd_info->num_of_faces ; i++) {
2842 cam_fd_info->face_info[i].id = fd_info->face_info[i].id;
2843 cam_fd_info->face_info[i].score = fd_info->face_info[i].score;
2844 cam_fd_info->face_info[i].rect.x = fd_info->face_info[i].rect.x;
2845 cam_fd_info->face_info[i].rect.y = fd_info->face_info[i].rect.y;
2846 cam_fd_info->face_info[i].rect.width = fd_info->face_info[i].rect.width;
2847 cam_fd_info->face_info[i].rect.height = fd_info->face_info[i].rect.height;
2849 MMCAM_LOG_VERBOSE(" [%d] id %d, score %d, [%d,%d,%dx%d]",
2850 i, fd_info->face_info[i].id,
2851 fd_info->face_info[i].score,
2852 fd_info->face_info[i].rect.x,
2853 fd_info->face_info[i].rect.y,
2854 fd_info->face_info[i].rect.width,
2855 fd_info->face_info[i].rect.height);
2858 cam_fd_info->face_info = NULL;
2861 /* send message - cam_fd_info should be freed by application */
2862 msg.id = MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO;
2863 msg.param.data = cam_fd_info;
2864 msg.param.size = sizeof(MMCamFaceDetectInfo);
2867 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2869 /* free fd_info allocated by plugin */
2872 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-Capture")) {
2873 int capture_done = FALSE;
2875 if (gst_structure_get_int(gst_message_get_structure(message), "capture-done", &capture_done)) {
2876 if (sc->info_image) {
2877 /* play capture sound */
2878 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE01, FALSE);
2882 _mmcamcorder_pipeline_cb_message(bus, message, data);
2885 _mmcamcorder_pipeline_cb_message(bus, message, data);
2888 gst_message_unref(message);
2890 return GST_BUS_DROP;
2894 static void __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code)
2896 _MMCamcorderMsgItem msg;
2898 mmf_return_if_fail(hcamcorder);
2901 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2902 case GST_RESOURCE_ERROR_OPEN_WRITE:
2903 MMCAM_LOG_ERROR("audio device [open failed]");
2905 /* post error to application */
2906 hcamcorder->error_occurs = TRUE;
2907 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2909 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2910 msg.param.code = hcamcorder->error_code;
2912 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2915 MMCAM_LOG_ERROR("unhandled error code[%d]", err_code);
2921 static void __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code)
2923 gboolean b_committing = FALSE;
2924 storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE;
2925 _MMCamcorderMsgItem msg;
2926 _MMCamcorderSubContext *sc = NULL;
2928 mmf_return_if_fail(hcamcorder);
2930 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2931 mmf_return_if_fail(sc);
2933 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2934 mmf_return_if_fail(sc->info_video);
2935 b_committing = sc->info_video->b_committing;
2937 mmf_return_if_fail(sc->info_audio);
2938 b_committing = sc->info_audio->b_committing;
2941 _MMCAMCORDER_LOCK(hcamcorder);
2944 case GST_RESOURCE_ERROR_WRITE:
2945 storage_get_state(hcamcorder->storage_info.id, &storage_state);
2946 if (storage_state == STORAGE_STATE_REMOVED ||
2947 storage_state == STORAGE_STATE_UNMOUNTABLE) {
2948 MMCAM_LOG_ERROR("storage was removed! [storage state %d]", storage_state);
2949 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2951 MMCAM_LOG_ERROR("File write error, storage state %d", storage_state);
2952 hcamcorder->error_code = MM_ERROR_FILE_WRITE;
2955 if (sc->ferror_send == FALSE) {
2956 sc->ferror_send = TRUE;
2958 MMCAM_LOG_ERROR("error was already sent");
2959 _MMCAMCORDER_UNLOCK(hcamcorder);
2963 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
2964 MMCAM_LOG_ERROR("No left space");
2965 hcamcorder->error_code = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
2967 case GST_RESOURCE_ERROR_OPEN_WRITE:
2968 MMCAM_LOG_ERROR("Out of storage");
2969 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2971 case GST_RESOURCE_ERROR_SEEK:
2972 MMCAM_LOG_ERROR("File read(seek)");
2973 hcamcorder->error_code = MM_ERROR_FILE_READ;
2976 MMCAM_LOG_ERROR("Resource error(%d)", err_code);
2977 hcamcorder->error_code = MM_ERROR_CAMCORDER_GST_RESOURCE;
2982 _MMCAMCORDER_SIGNAL(hcamcorder);
2983 _MMCAMCORDER_UNLOCK(hcamcorder);
2985 _MMCAMCORDER_UNLOCK(hcamcorder);
2987 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2988 msg.param.code = hcamcorder->error_code;
2990 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2995 static void __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message)
2998 gchar *debug_info = NULL;
2999 _MMCamcorderSubContext *sc = NULL;
3001 mmf_return_if_fail(hcamcorder);
3002 mmf_return_if_fail(message);
3004 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3005 mmf_return_if_fail(sc);
3007 /* parse error message */
3008 gst_message_parse_error(message, &err, &debug_info);
3011 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
3017 MMCAM_LOG_ERROR("failed to parse error message");
3021 /* check domain[RESOURCE] and element[AUDIOSRC] */
3022 if (err->domain == GST_RESOURCE_ERROR &&
3023 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst))
3024 __mmcamcorder_gst_handle_sync_audio_error(hcamcorder, err->code);
3026 __mmcamcorder_gst_handle_sync_others_error(hcamcorder, err->code);
3032 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
3034 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
3035 _MMCamcorderSubContext *sc = NULL;
3037 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
3038 mmf_return_val_if_fail(message, GST_BUS_DROP);
3040 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3041 mmf_return_val_if_fail(sc, GST_BUS_DROP);
3043 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS) {
3044 MMCAM_LOG_INFO("got EOS from pipeline");
3046 _MMCAMCORDER_LOCK(hcamcorder);
3048 sc->bget_eos = TRUE;
3049 _MMCAMCORDER_SIGNAL(hcamcorder);
3051 _MMCAMCORDER_UNLOCK(hcamcorder);
3052 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
3053 __mmcamcorder_handle_gst_sync_error(hcamcorder, message);
3055 _mmcamcorder_pipeline_cb_message(bus, message, data);
3058 gst_message_unref(message);
3060 return GST_BUS_DROP;
3064 void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *value, void *user_data)
3066 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
3067 int current_state = MM_CAMCORDER_STATE_NONE;
3069 mmf_return_if_fail(hcamcorder);
3070 mmf_return_if_fail(value);
3072 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3073 if (current_state <= MM_CAMCORDER_STATE_NONE || current_state >= MM_CAMCORDER_STATE_NUM) {
3074 MMCAM_LOG_ERROR("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
3078 MMCAM_LOG_WARNING("camera policy [%s], current state [%d]", value, current_state);
3080 if (!strcmp(value, "disallowed")) {
3081 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3083 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_DPM);
3085 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3087 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
3090 MMCAM_LOG_WARNING("done");
3096 int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
3098 int ret = MM_ERROR_NONE;
3099 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3100 _MMCamcorderSubContext *sc = NULL;
3101 GstElement *pipeline = NULL;
3103 MMCAM_LOG_INFO("handle : %p, type : %d", handle, type);
3105 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3107 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3108 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3111 case MM_CAMCORDER_MODE_AUDIO:
3112 ret = _mmcamcorder_create_audio_pipeline(handle);
3113 if (ret != MM_ERROR_NONE)
3117 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3120 ret = _mmcamcorder_create_preview_pipeline(handle);
3121 if (ret != MM_ERROR_NONE)
3126 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
3127 if (type != MM_CAMCORDER_MODE_AUDIO) {
3128 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:SET_READY_TO_PIPELINE");
3130 ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY);
3132 traceEnd(TTRACE_TAG_CAMERA);
3134 #ifdef _MMCAMCORDER_GET_DEVICE_INFO
3135 if (!_mmcamcorder_get_device_info(handle))
3136 MMCAM_LOG_ERROR("Getting device information error!!");
3139 MMCAM_LOG_INFO("ret[%x]", ret);
3140 if (ret != MM_ERROR_NONE) {
3141 MMCAM_LOG_ERROR("error : destroy pipeline");
3142 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
3149 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
3151 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3152 _MMCamcorderSubContext *sc = NULL;
3154 int element_num = 0;
3155 _MMCamcorderGstElement *element = NULL;
3157 mmf_return_if_fail(hcamcorder);
3159 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3160 mmf_return_if_fail(sc);
3164 /* Inside each pipeline destroy function, Set GST_STATE_NULL to Main pipeline */
3166 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3167 element = sc->element;
3168 element_num = sc->element_num;
3169 _mmcamcorder_destroy_video_capture_pipeline(handle);
3171 case MM_CAMCORDER_MODE_AUDIO:
3172 element = sc->encode_element;
3173 element_num = sc->encode_element_num;
3174 _mmcamcorder_destroy_audio_pipeline(handle);
3177 MMCAM_LOG_ERROR("unknown type %d", type);
3181 MMCAM_LOG_INFO("Pipeline clear!!");
3183 /* checking unreleased element */
3184 for (i = 0 ; i < element_num ; i++) {
3185 if (element[i].gst) {
3186 if (GST_IS_ELEMENT(element[i].gst)) {
3187 MMCAM_LOG_WARNING("Still alive element - ID[%d], name [%s], ref count[%d], status[%s]",
3189 GST_OBJECT_NAME(element[i].gst),
3190 GST_OBJECT_REFCOUNT(element[i].gst),
3191 gst_element_state_get_name(GST_STATE(element[i].gst)));
3192 g_object_weak_unref(G_OBJECT(element[i].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3194 MMCAM_LOG_WARNING("The element[%d] is still alive, check it", element[i].id);
3197 element[i].id = _MMCAMCORDER_NONE;
3198 element[i].gst = NULL;
3206 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state)
3209 _MMCamcorderSubContext *sc = NULL;
3210 GstState pipeline_state = GST_STATE_VOID_PENDING;
3211 GstStateChangeReturn setChangeReturn = GST_STATE_CHANGE_FAILURE;
3212 GstStateChangeReturn getChangeReturn = GST_STATE_CHANGE_FAILURE;
3213 GstClockTime get_timeout = __MMCAMCORDER_SET_GST_STATE_TIMEOUT * GST_SECOND;
3214 GMutex *state_lock = NULL;
3216 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3217 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3218 mmf_return_val_if_fail(sc && sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3220 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == pipeline) {
3221 MMCAM_LOG_INFO("Set state to %d - PREVIEW PIPELINE", target_state);
3222 state_lock = &_MMCAMCORDER_GET_GST_STATE_LOCK(handle);
3224 MMCAM_LOG_INFO("Set state to %d - ENDODE PIPELINE", target_state);
3225 state_lock = &_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle);
3228 g_mutex_lock(state_lock);
3230 for (k = 0; k < _MMCAMCORDER_STATE_SET_COUNT; k++) {
3231 setChangeReturn = gst_element_set_state(pipeline, target_state);
3232 MMCAM_LOG_INFO("gst_element_set_state[%d] return %d", target_state, setChangeReturn);
3234 if (setChangeReturn != GST_STATE_CHANGE_FAILURE) {
3235 getChangeReturn = gst_element_get_state(pipeline, &pipeline_state, NULL, get_timeout);
3236 switch (getChangeReturn) {
3237 case GST_STATE_CHANGE_NO_PREROLL:
3238 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_NO_PREROLL.");
3240 case GST_STATE_CHANGE_SUCCESS:
3241 /* if we reached the final target state, exit */
3242 if (pipeline_state == target_state) {
3243 MMCAM_LOG_INFO("Set state to %d - DONE", target_state);
3244 g_mutex_unlock(state_lock);
3245 return MM_ERROR_NONE;
3248 case GST_STATE_CHANGE_ASYNC:
3249 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_ASYNC.");
3252 g_mutex_unlock(state_lock);
3253 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_FAILURE.");
3254 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3257 g_mutex_unlock(state_lock);
3259 MMCAM_LOG_ERROR("timeout of gst_element_get_state()!!");
3261 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3264 usleep(_MMCAMCORDER_STATE_CHECK_INTERVAL);
3267 g_mutex_unlock(state_lock);
3269 MMCAM_LOG_ERROR("Failure. gst_element_set_state timeout!!");
3271 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3275 /* For performance check */
3276 int _mmcamcorder_video_current_framerate(MMHandleType handle)
3278 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3279 _MMCamcorderSubContext *sc = NULL;
3281 mmf_return_val_if_fail(hcamcorder, -1);
3283 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3284 mmf_return_val_if_fail(sc, -1);
3286 return sc->kpi.current_fps;
3290 int _mmcamcorder_video_average_framerate(MMHandleType handle)
3292 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3293 _MMCamcorderSubContext *sc = NULL;
3295 mmf_return_val_if_fail(hcamcorder, -1);
3297 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3298 mmf_return_val_if_fail(sc, -1);
3300 return sc->kpi.average_fps;
3304 void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
3306 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3307 _MMCamcorderSubContext *sc = NULL;
3309 mmf_return_if_fail(hcamcorder);
3311 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3312 mmf_return_if_fail(sc);
3314 memset(&(sc->kpi), 0x00, sizeof(_MMCamcorderKPIMeasure));
3320 void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder, int state_change_by_system)
3325 int result = MM_ERROR_NONE;
3326 int cmd_try_count = 0;
3327 int current_state = MM_CAMCORDER_STATE_NONE;
3328 _MMCamcorderMsgItem msg;
3330 mmf_return_if_fail(hcamcorder);
3332 /* check command running */
3334 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
3335 if (cmd_try_count++ < __MMCAMCORDER_FORCE_STOP_TRY_COUNT) {
3336 MMCAM_LOG_WARNING("Another command is running. try again after %d ms", __MMCAMCORDER_FORCE_STOP_WAIT_TIME/1000);
3337 usleep(__MMCAMCORDER_FORCE_STOP_WAIT_TIME);
3339 MMCAM_LOG_ERROR("wait timeout");
3343 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
3348 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3350 MMCAM_LOG_WARNING("Force STOP MMFW Camcorder by %d", state_change_by_system);
3352 /* set state_change_by_system for state change message */
3353 hcamcorder->state_change_by_system = state_change_by_system;
3355 if (current_state >= MM_CAMCORDER_STATE_READY) {
3356 MMCAM_LOG_WARNING("send state change started message to notify");
3358 memset(&msg, 0x0, sizeof(_MMCamcorderMsgItem));
3360 switch (state_change_by_system) {
3361 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
3362 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_RM;
3364 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
3365 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_SECURITY;
3372 msg.param.state.code = hcamcorder->interrupt_code;
3373 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
3375 MMCAM_LOG_ERROR("should not be reached here %d", state_change_by_system);
3379 for (loop = 0 ; current_state > MM_CAMCORDER_STATE_NULL && loop < __MMCAMCORDER_CMD_ITERATE_MAX * 3 ; loop++) {
3380 itr_cnt = __MMCAMCORDER_CMD_ITERATE_MAX;
3381 switch (current_state) {
3382 case MM_CAMCORDER_STATE_CAPTURING:
3384 _MMCamcorderSubContext *sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3385 _MMCamcorderImageInfo *info = NULL;
3387 mmf_return_if_fail(sc);
3388 mmf_return_if_fail((info = sc->info_image));
3390 MMCAM_LOG_WARNING("Stop capturing.");
3392 /* if capturing isn't finished, waiting for 2 sec to finish real capture operation. check 'info->capturing'. */
3393 mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
3394 MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, TRUE,
3397 for (i = 0; i < 20 && info->capturing; i++)
3401 MMCAM_LOG_ERROR("Timeout. Can't check stop capturing.");
3403 while ((itr_cnt--) && ((result = _mmcamcorder_capture_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3404 MMCAM_LOG_WARNING("Can't stop capturing.(%x)", result);
3408 case MM_CAMCORDER_STATE_RECORDING:
3409 case MM_CAMCORDER_STATE_PAUSED:
3411 MMCAM_LOG_WARNING("Stop recording.");
3413 while ((itr_cnt--) && ((result = _mmcamcorder_commit((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
3414 MMCAM_LOG_WARNING("Can't commit.(%x), cancel it.", result);
3415 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3420 case MM_CAMCORDER_STATE_PREPARE:
3422 MMCAM_LOG_WARNING("Stop preview.");
3424 while ((itr_cnt--) && ((result = _mmcamcorder_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3425 MMCAM_LOG_WARNING("Can't stop preview.(%x)", result);
3429 case MM_CAMCORDER_STATE_READY:
3431 MMCAM_LOG_WARNING("unrealize");
3433 if ((result = _mmcamcorder_unrealize((MMHandleType)hcamcorder)) != MM_ERROR_NONE)
3434 MMCAM_LOG_WARNING("Can't unrealize.(%x)", result);
3439 MMCAM_LOG_WARNING("Already stopped.");
3443 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3447 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3449 MMCAM_LOG_WARNING("Done.");
3455 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error)
3457 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3458 _MMCamcorderMsgItem msg;
3459 gchar *msg_src_element = NULL;
3460 _MMCamcorderSubContext *sc = NULL;
3462 mmf_return_val_if_fail(hcamcorder, FALSE);
3463 mmf_return_val_if_fail(error, FALSE);
3465 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3466 mmf_return_val_if_fail(sc, FALSE);
3468 MMCAM_LOG_INFO("error code %d", error->code);
3470 mmf_return_val_if_fail(hcamcorder->state >= MM_CAMCORDER_STATE_READY, FALSE);
3472 /* filtering filesink related errors */
3473 if (hcamcorder->state == MM_CAMCORDER_STATE_RECORDING &&
3474 (error->code == GST_RESOURCE_ERROR_WRITE || error->code == GST_RESOURCE_ERROR_SEEK)) {
3475 if (sc->ferror_count == 2 && sc->ferror_send == FALSE) {
3476 sc->ferror_send = TRUE;
3477 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3480 MMCAM_LOG_WARNING("Skip error");
3485 if (error->domain == GST_CORE_ERROR) {
3486 msg.param.code = __mmcamcorder_gst_handle_core_error(handle, error->code, message);
3487 } else if (error->domain == GST_LIBRARY_ERROR) {
3488 msg.param.code = __mmcamcorder_gst_handle_library_error(handle, error->code, message);
3489 } else if (error->domain == GST_RESOURCE_ERROR) {
3490 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3491 } else if (error->domain == GST_STREAM_ERROR) {
3492 msg.param.code = __mmcamcorder_gst_handle_stream_error(handle, error->code, message);
3494 MMCAM_LOG_WARNING("This error domain is not defined.");
3496 /* we treat system error as an internal error */
3497 msg.param.code = MM_ERROR_CAMCORDER_INTERNAL;
3501 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3502 MMCAM_LOG_ERROR("-Msg src : [%s] Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3503 msg_src_element, g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3505 MMCAM_LOG_ERROR("Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3506 g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3509 #ifdef _MMCAMCORDER_SKIP_GST_FLOW_ERROR
3510 /* Check whether send this error to application */
3511 if (msg.param.code == MM_ERROR_CAMCORDER_GST_FLOW_ERROR) {
3512 MMCAM_LOG_INFO("We got the error. But skip it.");
3515 #endif /* _MMCAMCORDER_SKIP_GST_FLOW_ERROR */
3517 /* post error to application except RESTRICTED case */
3518 if (msg.param.code != MM_ERROR_POLICY_RESTRICTED) {
3519 hcamcorder->error_occurs = TRUE;
3520 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3521 _mmcamcorder_send_message(handle, &msg);
3528 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message)
3530 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3531 _MMCamcorderSubContext *sc = NULL;
3532 GstElement *element = NULL;
3536 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3538 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3539 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3541 /* Specific plugin - video encoder plugin */
3542 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3544 if (GST_ELEMENT_CAST(message->src) == element) {
3545 if (code == GST_CORE_ERROR_NEGOTIATION)
3546 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3548 return MM_ERROR_CAMCORDER_ENCODER;
3553 case GST_CORE_ERROR_STATE_CHANGE:
3554 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3555 case GST_CORE_ERROR_NEGOTIATION:
3556 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3557 case GST_CORE_ERROR_MISSING_PLUGIN:
3558 case GST_CORE_ERROR_SEEK:
3559 case GST_CORE_ERROR_NOT_IMPLEMENTED:
3560 case GST_CORE_ERROR_FAILED:
3561 case GST_CORE_ERROR_TOO_LAZY:
3562 case GST_CORE_ERROR_PAD:
3563 case GST_CORE_ERROR_THREAD:
3564 case GST_CORE_ERROR_EVENT:
3565 case GST_CORE_ERROR_CAPS:
3566 case GST_CORE_ERROR_TAG:
3567 case GST_CORE_ERROR_CLOCK:
3568 case GST_CORE_ERROR_DISABLED:
3570 return MM_ERROR_CAMCORDER_GST_CORE;
3575 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message)
3577 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3578 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3582 /* Specific plugin - NONE */
3586 case GST_LIBRARY_ERROR_FAILED:
3587 case GST_LIBRARY_ERROR_TOO_LAZY:
3588 case GST_LIBRARY_ERROR_INIT:
3589 case GST_LIBRARY_ERROR_SHUTDOWN:
3590 case GST_LIBRARY_ERROR_SETTINGS:
3591 case GST_LIBRARY_ERROR_ENCODE:
3593 MMCAM_LOG_ERROR("Library error(%d)", code);
3594 return MM_ERROR_CAMCORDER_GST_LIBRARY;
3599 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message)
3601 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3602 _MMCamcorderSubContext *sc = NULL;
3603 GstElement *element = NULL;
3605 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3607 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3608 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3612 /* Specific plugin */
3614 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst);
3615 if (GST_ELEMENT_CAST(message->src) == element) {
3616 if (code == GST_RESOURCE_ERROR_WRITE) {
3617 MMCAM_LOG_ERROR("Display device [Off]");
3618 return MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF;
3620 MMCAM_LOG_ERROR("Display device [General(%d)]", code);
3625 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst);
3626 if (GST_ELEMENT_CAST(message->src) == element) {
3627 if (code == GST_RESOURCE_ERROR_FAILED) {
3628 int ret = MM_ERROR_NONE;
3629 int current_state = MM_CAMCORDER_STATE_NONE;
3631 MMCAM_LOG_ERROR("DPM mic DISALLOWED - current state %d", current_state);
3633 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3635 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3636 if (current_state >= MM_CAMCORDER_STATE_RECORDING) {
3637 /* set value to inform a status is changed by DPM */
3638 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_DPM;
3640 ret = _mmcamcorder_commit((MMHandleType)hcamcorder);
3641 MMCAM_LOG_INFO("commit result : 0x%x", ret);
3643 if (ret != MM_ERROR_NONE) {
3644 MMCAM_LOG_ERROR("commit failed, cancel it");
3645 ret = _mmcamcorder_cancel((MMHandleType)hcamcorder);
3650 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3652 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3654 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
3656 return MM_ERROR_POLICY_RESTRICTED;
3661 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3662 if (GST_ELEMENT_CAST(message->src) == element) {
3663 if (code == GST_RESOURCE_ERROR_FAILED) {
3664 MMCAM_LOG_ERROR("Encoder [Resource error]");
3665 return MM_ERROR_CAMCORDER_ENCODER_BUFFER;
3667 MMCAM_LOG_ERROR("Encoder [General(%d)]", code);
3668 return MM_ERROR_CAMCORDER_ENCODER;
3674 case GST_RESOURCE_ERROR_WRITE:
3675 MMCAM_LOG_ERROR("File write error");
3676 return MM_ERROR_FILE_WRITE;
3677 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3678 MMCAM_LOG_ERROR("No left space");
3679 return MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
3680 case GST_RESOURCE_ERROR_OPEN_WRITE:
3681 MMCAM_LOG_ERROR("Out of storage");
3682 return MM_ERROR_OUT_OF_STORAGE;
3683 case GST_RESOURCE_ERROR_SEEK:
3684 MMCAM_LOG_ERROR("File read(seek)");
3685 return MM_ERROR_FILE_READ;
3686 case GST_RESOURCE_ERROR_NOT_FOUND:
3687 case GST_RESOURCE_ERROR_FAILED:
3688 case GST_RESOURCE_ERROR_TOO_LAZY:
3689 case GST_RESOURCE_ERROR_BUSY:
3690 case GST_RESOURCE_ERROR_OPEN_READ:
3691 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3692 case GST_RESOURCE_ERROR_CLOSE:
3693 case GST_RESOURCE_ERROR_READ:
3694 case GST_RESOURCE_ERROR_SYNC:
3695 case GST_RESOURCE_ERROR_SETTINGS:
3697 MMCAM_LOG_ERROR("Resource error(%d)", code);
3698 return MM_ERROR_CAMCORDER_GST_RESOURCE;
3703 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message)
3705 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3706 _MMCamcorderSubContext *sc = NULL;
3707 GstElement *element = NULL;
3709 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3711 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3712 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3716 /* Specific plugin */
3718 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3719 if (GST_ELEMENT_CAST(message->src) == element) {
3721 case GST_STREAM_ERROR_WRONG_TYPE:
3722 MMCAM_LOG_ERROR("Video encoder [wrong stream type]");
3723 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
3724 case GST_STREAM_ERROR_ENCODE:
3725 MMCAM_LOG_ERROR("Video encoder [encode error]");
3726 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3727 case GST_STREAM_ERROR_FAILED:
3728 MMCAM_LOG_ERROR("Video encoder [stream failed]");
3729 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3731 MMCAM_LOG_ERROR("Video encoder [General(%d)]", code);
3732 return MM_ERROR_CAMCORDER_ENCODER;
3736 /* General plugin */
3738 case GST_STREAM_ERROR_FORMAT:
3739 MMCAM_LOG_ERROR("General [negotiation error(%d)]", code);
3740 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3741 case GST_STREAM_ERROR_FAILED:
3742 MMCAM_LOG_ERROR("General [flow error(%d)]", code);
3743 return MM_ERROR_CAMCORDER_GST_FLOW_ERROR;
3744 case GST_STREAM_ERROR_TYPE_NOT_FOUND:
3745 case GST_STREAM_ERROR_DECODE:
3746 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
3747 case GST_STREAM_ERROR_NOT_IMPLEMENTED:
3748 case GST_STREAM_ERROR_TOO_LAZY:
3749 case GST_STREAM_ERROR_ENCODE:
3750 case GST_STREAM_ERROR_DEMUX:
3751 case GST_STREAM_ERROR_MUX:
3752 case GST_STREAM_ERROR_DECRYPT:
3753 case GST_STREAM_ERROR_DECRYPT_NOKEY:
3754 case GST_STREAM_ERROR_WRONG_TYPE:
3756 MMCAM_LOG_ERROR("General [error(%d)]", code);
3757 return MM_ERROR_CAMCORDER_GST_STREAM;
3762 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error)
3764 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3765 gchar *debug = NULL;
3768 mmf_return_val_if_fail(hcamcorder, FALSE);
3769 mmf_return_val_if_fail(error, FALSE);
3773 gst_message_parse_warning(message, &err, &debug);
3775 if (error->domain == GST_CORE_ERROR) {
3776 MMCAM_LOG_WARNING("GST warning: GST_CORE domain");
3777 } else if (error->domain == GST_LIBRARY_ERROR) {
3778 MMCAM_LOG_WARNING("GST warning: GST_LIBRARY domain");
3779 } else if (error->domain == GST_RESOURCE_ERROR) {
3780 MMCAM_LOG_WARNING("GST warning: GST_RESOURCE domain");
3781 __mmcamcorder_gst_handle_resource_warning(handle, message, error);
3782 } else if (error->domain == GST_STREAM_ERROR) {
3783 MMCAM_LOG_WARNING("GST warning: GST_STREAM domain");
3785 MMCAM_LOG_WARNING("This error domain(%d) is not defined.", error->domain);
3792 if (debug != NULL) {
3793 MMCAM_LOG_ERROR("Debug: %s", debug);
3802 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error)
3804 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3805 _MMCamcorderSubContext *sc = NULL;
3806 GstElement *element = NULL;
3807 gchar *msg_src_element;
3809 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3811 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3812 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3816 /* Special message handling */
3818 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
3819 if (GST_ELEMENT_CAST(message->src) == element) {
3820 if (error->code == GST_RESOURCE_ERROR_FAILED) {
3821 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3822 MMCAM_LOG_WARNING("-Msg src:[%s] Domain:[%s] Error:[%s]",
3823 msg_src_element, g_quark_to_string(error->domain), error->message);
3824 return MM_ERROR_NONE;
3828 /* General plugin */
3829 switch (error->code) {
3830 case GST_RESOURCE_ERROR_WRITE:
3831 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3832 case GST_RESOURCE_ERROR_SEEK:
3833 case GST_RESOURCE_ERROR_NOT_FOUND:
3834 case GST_RESOURCE_ERROR_FAILED:
3835 case GST_RESOURCE_ERROR_TOO_LAZY:
3836 case GST_RESOURCE_ERROR_BUSY:
3837 case GST_RESOURCE_ERROR_OPEN_READ:
3838 case GST_RESOURCE_ERROR_OPEN_WRITE:
3839 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3840 case GST_RESOURCE_ERROR_CLOSE:
3841 case GST_RESOURCE_ERROR_READ:
3842 case GST_RESOURCE_ERROR_SYNC:
3843 case GST_RESOURCE_ERROR_SETTINGS:
3845 MMCAM_LOG_WARNING("General GST warning(%d)", error->code);
3849 return MM_ERROR_NONE;
3853 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
3854 const char *interface_name, const char *signal_name, int value)
3856 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3858 mmf_return_if_fail(hcamcorder && object_name && interface_name && signal_name);
3860 MMCAM_LOG_INFO("object %s, interface %s, signal %s, value %d",
3861 object_name, interface_name, signal_name, value);
3863 _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, object_name, interface_name, signal_name, value);
3869 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
3870 static int __mmcamcorder_resource_release_cb(mm_resource_manager_h rm,
3871 mm_resource_manager_res_h res, void *user_data)
3873 mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *) user_data;
3875 mmf_return_val_if_fail(hcamcorder, FALSE);
3877 MMCAM_LOG_WARNING("enter");
3879 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3881 /* set flag for resource release callback */
3882 hcamcorder->is_release_cb_calling = TRUE;
3884 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3886 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3888 if (res == hcamcorder->video_encoder_resource) {
3889 /* Stop video recording */
3890 if (_mmcamcorder_commit((MMHandleType)hcamcorder) != MM_ERROR_NONE) {
3891 MMCAM_LOG_ERROR("commit failed, cancel it");
3892 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3896 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_RM);
3899 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3901 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3903 if (res == hcamcorder->camera_resource)
3904 hcamcorder->camera_resource = NULL;
3905 else if (res == hcamcorder->video_overlay_resource)
3906 hcamcorder->video_overlay_resource = NULL;
3907 else if (res == hcamcorder->video_encoder_resource)
3908 hcamcorder->video_encoder_resource = NULL;
3910 /* restore flag for resource release callback */
3911 hcamcorder->is_release_cb_calling = FALSE;
3913 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3915 MMCAM_LOG_WARNING("leave");
3919 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
3921 int _mmcamcorder_manage_external_storage_state(MMHandleType handle, int storage_state)
3923 int ret = MM_ERROR_NONE;
3924 int current_state = MM_CAMCORDER_STATE_NONE;
3925 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3926 _MMCamcorderMsgItem msg;
3928 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
3930 MMCAM_LOG_WARNING("storage state %d", storage_state);
3932 /* check storage state */
3933 if (storage_state != STORAGE_STATE_UNMOUNTABLE &&
3934 storage_state != STORAGE_STATE_REMOVED) {
3935 MMCAM_LOG_WARNING("nothing to do");
3936 return MM_ERROR_NONE;
3939 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3941 /* check recording state */
3942 current_state = _mmcamcorder_get_state(handle);
3944 MMCAM_LOG_WARNING("current_state %d", current_state);
3946 if (current_state < MM_CAMCORDER_STATE_RECORDING) {
3947 MMCAM_LOG_WARNING("no recording now");
3951 /* check storage type */
3952 if (hcamcorder->storage_info.type != STORAGE_TYPE_EXTERNAL) {
3953 MMCAM_LOG_WARNING("external storage is not used");
3957 /* cancel recording */
3958 ret = _mmcamcorder_cancel(handle);
3960 /* send error message */
3961 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3962 msg.param.code = MM_ERROR_OUT_OF_STORAGE;
3964 _mmcamcorder_send_message(handle, &msg);
3967 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3969 MMCAM_LOG_WARNING("done - ret 0x%x", ret);