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 = _mmcamcorder_gdbus_info_new();
159 new_handle->gdbus_info_solo_sound = _mmcamcorder_gdbus_info_new();
162 /* create task thread */
163 new_handle->task_thread = g_thread_try_new("MMCAM_TASK_THREAD",
164 (GThreadFunc)_mmcamcorder_util_task_thread_func, (gpointer)new_handle, NULL);
165 if (new_handle->task_thread == NULL) {
166 MMCAM_LOG_ERROR("_mmcamcorder_create::failed to create task thread");
167 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
168 goto _INIT_HANDLE_FAILED;
171 /* Get Camera Configure information from Camcorder INI file */
172 ret = _mmcamcorder_conf_get_info((MMHandleType)new_handle, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &new_handle->conf_main);
173 if (ret != MM_ERROR_NONE) {
174 MMCAM_LOG_ERROR("Failed to get configure(main) info.");
175 goto _INIT_HANDLE_FAILED;
178 /* Get log level from conf */
179 _mmcamcorder_conf_get_value_int((MMHandleType)new_handle, new_handle->conf_main,
180 CONFIGURE_CATEGORY_MAIN_GENERAL,
184 _mmcamcorder_set_log_level(log_level);
186 /* allocate attribute */
187 new_handle->attributes = _mmcamcorder_alloc_attribute((MMHandleType)new_handle);
188 if (!new_handle->attributes) {
189 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
190 goto _INIT_HANDLE_FAILED;
193 *hcamcorder = new_handle;
195 MMCAM_LOG_INFO("new handle %p", new_handle);
197 return MM_ERROR_NONE;
200 __mmcamcorder_deinit_handle(new_handle);
205 static void __mmcamcorder_deinit_handle(mmf_camcorder_t *hcamcorder)
208 MMCAM_LOG_ERROR("NULL handle");
212 /* Remove exif info */
213 if (hcamcorder->exif_info) {
214 mm_exif_destory_exif_info(hcamcorder->exif_info);
215 hcamcorder->exif_info = NULL;
218 /* remove attributes */
219 if (hcamcorder->attributes) {
220 _mmcamcorder_dealloc_attribute((MMHandleType)hcamcorder, hcamcorder->attributes);
221 hcamcorder->attributes = 0;
224 /* Release configure info */
225 __mmcamcorder_deinit_configure(hcamcorder);
227 /* remove task thread */
228 if (hcamcorder->task_thread) {
229 g_mutex_lock(&hcamcorder->task_thread_lock);
230 MMCAM_LOG_INFO("send signal for task thread exit");
231 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_EXIT;
232 g_cond_signal(&hcamcorder->task_thread_cond);
233 g_mutex_unlock(&hcamcorder->task_thread_lock);
234 g_thread_join(hcamcorder->task_thread);
235 hcamcorder->task_thread = NULL;
238 /* Release lock, cond */
239 g_mutex_clear(&(hcamcorder->mtsafe).lock);
240 g_cond_clear(&(hcamcorder->mtsafe).cond);
241 g_mutex_clear(&(hcamcorder->mtsafe).cmd_lock);
242 g_cond_clear(&(hcamcorder->mtsafe).cmd_cond);
243 g_mutex_clear(&(hcamcorder->mtsafe).interrupt_lock);
244 g_mutex_clear(&(hcamcorder->mtsafe).state_lock);
245 g_mutex_clear(&(hcamcorder->mtsafe).gst_state_lock);
246 g_mutex_clear(&(hcamcorder->mtsafe).gst_encode_state_lock);
247 g_mutex_clear(&(hcamcorder->mtsafe).message_cb_lock);
248 g_mutex_clear(&(hcamcorder->mtsafe).vcapture_cb_lock);
249 g_mutex_clear(&(hcamcorder->mtsafe).vstream_cb_lock);
250 g_mutex_clear(&(hcamcorder->mtsafe).astream_cb_lock);
251 g_mutex_clear(&(hcamcorder->mtsafe).mstream_cb_lock);
252 g_mutex_clear(&(hcamcorder->mtsafe).vedecision_cb_lock);
253 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
254 g_mutex_clear(&(hcamcorder->mtsafe).resource_lock);
255 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
257 g_mutex_clear(&hcamcorder->snd_info.open_mutex);
258 g_cond_clear(&hcamcorder->snd_info.open_cond);
259 g_mutex_clear(&hcamcorder->restart_preview_lock);
261 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
262 _mmcamcorder_gdbus_info_check_free(hcamcorder->gdbus_info_sound);
263 _mmcamcorder_gdbus_info_check_free(hcamcorder->gdbus_info_solo_sound);
266 g_mutex_clear(&hcamcorder->task_thread_lock);
267 g_cond_clear(&hcamcorder->task_thread_cond);
269 if (hcamcorder->model_name)
270 free(hcamcorder->model_name);
272 if (hcamcorder->software_version)
273 free(hcamcorder->software_version);
276 memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
284 static void __mmcamcorder_get_system_info(mmf_camcorder_t *hcamcorder)
289 MMCAM_LOG_ERROR("NULL handle");
293 /* get shutter sound policy */
294 vconf_get_int(VCONFKEY_CAMERA_SHUTTER_SOUND_POLICY, &hcamcorder->shutter_sound_policy);
295 MMCAM_LOG_INFO("current shutter sound policy : %d", hcamcorder->shutter_sound_policy);
298 ret = system_info_get_platform_string("http://tizen.org/system/model_name", &hcamcorder->model_name);
300 MMCAM_LOG_WARNING("model name [%s], ret 0x%x",
301 hcamcorder->model_name ? hcamcorder->model_name : "NULL", ret);
303 /* get software version */
304 ret = system_info_get_platform_string("http://tizen.org/system/build.string", &hcamcorder->software_version);
306 MMCAM_LOG_WARNING("software version [%s], ret 0x%x",
307 hcamcorder->software_version ? hcamcorder->software_version : "NULL", ret);
313 static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcorder)
315 int ret = MM_ERROR_NONE;
316 int resolution_width = 0;
317 int resolution_height = 0;
318 int rcmd_fmt_capture = MM_PIXEL_FORMAT_YUYV;
319 int rcmd_fmt_recording = MM_PIXEL_FORMAT_NV12;
320 int rcmd_dpy_rotation = MM_DISPLAY_ROTATION_270;
321 int play_capture_sound = TRUE;
322 int camera_default_flip = MM_FLIP_NONE;
323 int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
324 int wb_temp_step = 1;
326 char *err_attr_name = NULL;
327 char conf_file_name[__MMCAMCORDER_CONF_FILENAME_LENGTH] = {'\0',};
328 const char *platform_privilege_camera = NULL;
329 MMCamAttrsInfo fps_info;
330 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
331 camera_conf_error_e ret_conf = CAMERA_CONF_MGR_ERROR_NONE;
332 char devicetype[__MMCAMCORDER_CONF_FILENAME_LENGTH] = {'\0',};
336 MMCAM_LOG_ERROR("NULL handle");
337 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
340 if (hcamcorder->is_network) {
341 snprintf(conf_file_name, sizeof(conf_file_name), "%s_network.ini",
342 CONFIGURE_CTRL_FILE_PREFIX);
344 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
345 snprintf(devicetype, sizeof(devicetype), "%d", hcamcorder->device_type);
346 memset(&hcamcorder->conf_device_info, 0x00, sizeof(camera_conf_device_info_s));
347 ret_conf = camera_conf_mgr_get_ids(devicetype, __MMCAMCORDER_DEVICE_TYPE_STRING_LEN,
348 &hcamcorder->conf_device_info);
349 if (ret_conf != CAMERA_CONF_MGR_ERROR_NONE) {
350 MMCAM_LOG_ERROR("Device [%s] is not found", devicetype);
351 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
354 snprintf(conf_file_name, sizeof(conf_file_name), "%s_%s_%s.ini",
355 CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->conf_device_info.vendor_id,
356 hcamcorder->conf_device_info.product_id);
358 MMCAM_LOG_INFO("device info : node[%s]",
359 hcamcorder->conf_device_info.node);
361 snprintf(conf_file_name, sizeof(conf_file_name), "%s%d.ini",
362 CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->device_type);
366 MMCAM_LOG_INFO("Load control configure file [%d][%s]",
367 hcamcorder->device_type, conf_file_name);
369 ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
370 CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
371 if (ret != MM_ERROR_NONE) {
372 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
373 snprintf(conf_file_name, sizeof(conf_file_name), "%s.ini",
374 CONFIGURE_CTRL_FILE_PREFIX);
375 ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
376 CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
377 if (ret != MM_ERROR_NONE) {
378 MMCAM_LOG_ERROR("Failed to get configure(control) info.");
382 MMCAM_LOG_ERROR("Failed to get configure(control) info.");
387 _mmcamcorder_conf_print_info(&hcamcorder->conf_main);
388 _mmcamcorder_conf_print_info(&hcamcorder->conf_ctrl);
390 ret = _mmcamcorder_init_convert_table((MMHandleType)hcamcorder);
391 if (ret != MM_ERROR_NONE) {
392 MMCAM_LOG_WARNING("converting table initialize error!!");
393 return MM_ERROR_CAMCORDER_INTERNAL;
396 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_ALL);
397 if (ret != MM_ERROR_NONE) {
398 MMCAM_LOG_WARNING("attribute initialize from configure error!!");
399 return MM_ERROR_CAMCORDER_INTERNAL;
402 /* Get device information for supported features from INI */
403 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
404 CONFIGURE_CATEGORY_CTRL_CAMERA,
405 "RecommendPreviewFormatCapture",
408 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
409 CONFIGURE_CATEGORY_CTRL_CAMERA,
410 "RecommendPreviewFormatRecord",
411 &rcmd_fmt_recording);
413 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
414 CONFIGURE_CATEGORY_CTRL_CAMERA,
415 "RecommendDisplayRotation",
418 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
419 CONFIGURE_CATEGORY_CTRL_CAMERA,
420 "SupportExtraPreview",
421 (int *)&hcamcorder->extra_preview.is_supported);
423 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
424 CONFIGURE_CATEGORY_CTRL_CAMERA,
426 (int *)&hcamcorder->extra_preview.mode);
428 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
429 CONFIGURE_CATEGORY_CTRL_CAMERA,
431 &camera_facing_direction);
433 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
434 CONFIGURE_CATEGORY_CTRL_EFFECT,
435 "BrightnessStepDenominator",
436 &hcamcorder->brightness_step_denominator);
438 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
439 CONFIGURE_CATEGORY_CTRL_CAPTURE,
441 &hcamcorder->support_zsl_capture);
443 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
444 CONFIGURE_CATEGORY_CTRL_EFFECT,
445 "WhiteBalanceTemperatureStep",
448 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
449 CONFIGURE_CATEGORY_CTRL_PHOTOGRAPH,
453 MMCAM_LOG_INFO("Recommend format[capture:%d, recording:%d]", rcmd_fmt_capture, rcmd_fmt_recording);
454 MMCAM_LOG_INFO("Recommend display rotation[%d]", rcmd_dpy_rotation);
455 MMCAM_LOG_INFO("Camera facing direction[%d]", camera_facing_direction);
456 MMCAM_LOG_INFO("Brightness step denominator[%d]", hcamcorder->brightness_step_denominator);
457 MMCAM_LOG_INFO("Support ZSL capture[%d]", hcamcorder->support_zsl_capture);
458 MMCAM_LOG_INFO("Step: wb_temp[%d], gain[%d]", wb_temp_step, gain_step);
460 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
461 CONFIGURE_CATEGORY_CTRL_CAMERA,
462 "AltUseZeroCopyFormat",
463 &hcamcorder->use_zero_copy_format);
464 if (hcamcorder->use_zero_copy_format == -1) {
465 MMCAM_LOG_WARNING("AltUseZeroCopyFormat is not set, so use \"UseZeroCopyFormat\".");
466 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
467 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
469 &hcamcorder->use_zero_copy_format);
472 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
473 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
475 &hcamcorder->support_user_buffer);
477 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
478 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
479 "SupportMediaPacketPreviewCb",
480 &hcamcorder->support_media_packet_preview_cb);
482 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
483 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
485 &hcamcorder->use_videoconvert);
487 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
488 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
490 &hcamcorder->measure_preview_fps);
492 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
493 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
494 "DefaultEncodedPreviewBitrate",
495 &hcamcorder->default_encoded_preview_bitrate);
497 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
498 CONFIGURE_CATEGORY_MAIN_CAPTURE,
500 &hcamcorder->capture_mode);
502 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
503 CONFIGURE_CATEGORY_MAIN_CAPTURE,
505 &play_capture_sound);
507 MMCAM_LOG_INFO("Support user buffer[%d]", hcamcorder->support_user_buffer);
508 MMCAM_LOG_INFO("Support media packet preview cb[%d]", hcamcorder->support_media_packet_preview_cb);
509 MMCAM_LOG_INFO("Support extra preview[%d]", hcamcorder->extra_preview.is_supported);
510 MMCAM_LOG_INFO("Extra preview mode[%d]", hcamcorder->extra_preview.mode);
511 MMCAM_LOG_INFO("Capture mode[%d]", hcamcorder->capture_mode);
512 MMCAM_LOG_INFO("Use zero copy format[%d]", hcamcorder->use_zero_copy_format);
513 MMCAM_LOG_INFO("Use video convert[%d]", hcamcorder->use_videoconvert);
514 MMCAM_LOG_INFO("Measure preview FPS[%d]", hcamcorder->measure_preview_fps);
515 MMCAM_LOG_INFO("Default encoded preview bitrate[%d]", hcamcorder->default_encoded_preview_bitrate);
516 MMCAM_LOG_INFO("Play capture sound[%d]", play_capture_sound);
518 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
519 MMCAM_CAMERA_WIDTH, &resolution_width,
520 MMCAM_CAMERA_HEIGHT, &resolution_height,
522 if (ret != MM_ERROR_NONE) {
523 MMCAM_LOG_ERROR("get attribute[resolution] error");
524 return MM_ERROR_CAMCORDER_INTERNAL;
527 ret = mm_camcorder_get_fps_list_by_resolution((MMHandleType)hcamcorder, resolution_width, resolution_height, &fps_info);
528 if (ret != MM_ERROR_NONE) {
529 MMCAM_LOG_ERROR("get fps list failed with [%dx%d]", resolution_width, resolution_height);
530 return MM_ERROR_CAMCORDER_INTERNAL;
533 MMCAM_LOG_INFO("res : %d X %d, Default FPS by resolution : %d",
534 resolution_width, resolution_height, fps_info.int_array.def);
536 if (camera_facing_direction == 1) {
537 if (rcmd_dpy_rotation == MM_DISPLAY_ROTATION_270 || rcmd_dpy_rotation == MM_DISPLAY_ROTATION_90)
538 camera_default_flip = MM_FLIP_VERTICAL;
540 camera_default_flip = MM_FLIP_HORIZONTAL;
542 MMCAM_LOG_INFO("camera_default_flip : [%d]", camera_default_flip);
545 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
546 CONFIGURE_CATEGORY_MAIN_GENERAL,
547 "PlatformPrivilegeCamera",
548 &platform_privilege_camera);
550 if (hcamcorder->is_network) {
551 _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
552 CONFIGURE_CATEGORY_MAIN_GENERAL,
553 "NetworkCameraHALName",
554 &hcamcorder->network_hal_name);
556 MMCAM_LOG_INFO("network HAL name[%s]", hcamcorder->network_hal_name);
559 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, &err_attr_name,
560 MMCAM_CAMERA_FACING_DIRECTION, camera_facing_direction,
561 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, rcmd_fmt_capture,
562 MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, rcmd_fmt_recording,
563 MMCAM_RECOMMEND_DISPLAY_ROTATION, rcmd_dpy_rotation,
564 MMCAM_SUPPORT_ZSL_CAPTURE, hcamcorder->support_zsl_capture,
565 MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
566 MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
567 MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
568 MMCAM_SUPPORT_EXTRA_PREVIEW, hcamcorder->extra_preview.is_supported,
569 MMCAM_CAMERA_FPS, fps_info.int_array.def,
570 MMCAM_DISPLAY_FLIP, camera_default_flip,
571 MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,
572 MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
573 platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
574 MMCAM_ENCODED_PREVIEW_BITRATE, hcamcorder->default_encoded_preview_bitrate,
575 MMCAM_FILTER_WB_TEMPERATURE_STEP, wb_temp_step,
576 MMCAM_CAMERA_GAIN_STEP, gain_step,
578 if (ret != MM_ERROR_NONE) {
579 MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
580 SAFE_FREE(err_attr_name);
581 return MM_ERROR_CAMCORDER_INTERNAL;
584 /* Get default value of brightness */
585 ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
586 MMCAM_FILTER_BRIGHTNESS, &hcamcorder->brightness_default,
588 if (ret != MM_ERROR_NONE) {
589 MMCAM_LOG_ERROR("Get brightness FAILED.");
590 return MM_ERROR_CAMCORDER_INTERNAL;
593 MMCAM_LOG_INFO("Default brightness : %d", hcamcorder->brightness_default);
599 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder)
601 int ret = MM_ERROR_NONE;
604 MMCAM_LOG_ERROR("NULL handle");
605 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
608 ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
609 if (ret != MM_ERROR_NONE) {
610 MMCAM_LOG_ERROR("there is no audio device");
611 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
618 static gint __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder)
620 int ret = MM_ERROR_NONE;
621 int device_count = 0;
622 const char *videosrc_name = NULL;
623 const char *audiosrc_name = NULL;
626 MMCAM_LOG_ERROR("NULL handle");
627 return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
630 _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
631 CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
635 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
636 hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
637 NULL, &videosrc_name);
639 _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
640 hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, "AudiosrcElement",
641 NULL, &audiosrc_name);
643 MMCAM_LOG_INFO("Device count[%d], Videosrc[%s], Audiosrc[%s]",
644 device_count, videosrc_name, audiosrc_name);
646 ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
647 MMCAM_CAMERA_DEVICE_COUNT, device_count,
648 MMCAM_VIDEOSRC_ELEMENT_NAME, videosrc_name, videosrc_name ? strlen(videosrc_name) : 0,
649 MMCAM_AUDIOSRC_ELEMENT_NAME, audiosrc_name, audiosrc_name ? strlen(audiosrc_name) : 0,
651 if (ret != MM_ERROR_NONE)
652 MMCAM_LOG_ERROR("Set FAILED[0x%x]", ret);
658 static void __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder)
661 MMCAM_LOG_ERROR("NULL handle");
665 if (hcamcorder->conf_ctrl)
666 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_ctrl);
668 if (hcamcorder->conf_main)
669 _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_main);
675 /*---------------------------------------------------------------------------------------
676 | GLOBAL FUNCTION DEFINITIONS: |
677 ---------------------------------------------------------------------------------------*/
678 /* Internal command functions {*/
679 int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
681 int ret = MM_ERROR_NONE;
682 mmf_camcorder_t *hcamcorder = NULL;
684 MMCAM_LOG_INFO("Entered");
686 mmf_return_val_if_fail(handle && info, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
688 /* check device type */
689 if (info->videodev_type < MM_VIDEO_DEVICE_NONE ||
690 info->videodev_type >= MM_VIDEO_DEVICE_NUM) {
691 MMCAM_LOG_ERROR("video device type[%d] is out of range.", info->videodev_type);
692 return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
696 ret = __mmcamcorder_init_handle(&hcamcorder, info->videodev_type);
697 if (ret != MM_ERROR_NONE)
700 /* set network camera flag */
701 hcamcorder->is_network = (gboolean)info->reserved[0];
703 /* get DPM handle for camera/microphone restriction */
704 hcamcorder->dpm_handle = dpm_manager_create();
706 MMCAM_LOG_WARNING("DPM handle %p", hcamcorder->dpm_handle);
708 ret = __mmcamcorder_init_configure_common(hcamcorder);
709 if (ret != MM_ERROR_NONE)
710 goto _ERR_DEFAULT_VALUE_INIT;
712 if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
713 ret = __mmcamcorder_init_configure_video_capture(hcamcorder);
714 if (ret != MM_ERROR_NONE)
715 goto _ERR_DEFAULT_VALUE_INIT;
717 /* add DPM camera policy changed callback */
718 if (hcamcorder->dpm_handle) {
719 ret = dpm_add_policy_changed_cb(hcamcorder->dpm_handle, "camera",
720 _mmcamcorder_dpm_camera_policy_changed_cb, (void *)hcamcorder, &hcamcorder->dpm_camera_cb_id);
721 if (ret != DPM_ERROR_NONE) {
722 MMCAM_LOG_ERROR("add DPM changed cb failed, keep going...");
723 hcamcorder->dpm_camera_cb_id = 0;
726 MMCAM_LOG_INFO("DPM camera changed cb id %d", hcamcorder->dpm_camera_cb_id);
729 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
730 /* initialize resource manager */
731 ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
732 __mmcamcorder_resource_release_cb, hcamcorder,
733 &hcamcorder->resource_manager);
734 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
735 MMCAM_LOG_ERROR("failed to initialize resource manager");
736 ret = MM_ERROR_CAMCORDER_INTERNAL;
737 goto _ERR_DEFAULT_VALUE_INIT;
739 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
741 ret = __mmcamcorder_init_configure_audio(hcamcorder);
742 if (ret != MM_ERROR_NONE)
743 goto _ERR_DEFAULT_VALUE_INIT;
746 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:CREATE:INIT_GSTREAMER");
748 ret = __mmcamcorder_init_gstreamer(hcamcorder->conf_main);
750 traceEnd(TTRACE_TAG_CAMERA);
753 MMCAM_LOG_ERROR("Failed to initialize gstreamer!!");
754 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
755 goto _ERR_DEFAULT_VALUE_INIT;
758 /* Make some attributes as read-only type */
759 _mmcamcorder_lock_readonly_attributes((MMHandleType)hcamcorder);
761 /* get system information */
762 __mmcamcorder_get_system_info(hcamcorder);
764 /* Set initial state */
765 _mmcamcorder_set_state((MMHandleType)hcamcorder, MM_CAMCORDER_STATE_NULL);
767 MMCAM_LOG_INFO("created handle %p", hcamcorder);
769 *handle = (MMHandleType)hcamcorder;
771 return MM_ERROR_NONE;
773 _ERR_DEFAULT_VALUE_INIT:
774 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
775 /* de-initialize resource manager */
776 if (hcamcorder->resource_manager != NULL)
777 mm_resource_manager_destroy(hcamcorder->resource_manager);
778 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
780 /* release DPM related handle */
781 if (hcamcorder->dpm_handle) {
782 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
783 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
785 /* remove camera policy changed callback */
786 if (hcamcorder->dpm_camera_cb_id > 0) {
787 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
788 hcamcorder->dpm_camera_cb_id = 0;
790 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
793 dpm_manager_destroy(hcamcorder->dpm_handle);
794 hcamcorder->dpm_handle = NULL;
797 /* release configure info */
798 __mmcamcorder_deinit_configure(hcamcorder);
800 /* deinitialize handle */
801 __mmcamcorder_deinit_handle(hcamcorder);
807 int _mmcamcorder_destroy(MMHandleType handle)
809 int ret = MM_ERROR_NONE;
810 int state = MM_CAMCORDER_STATE_NONE;
811 GstElement *sink_element = NULL;
812 int sink_element_size = 0;
814 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
819 MMCAM_LOG_ERROR("Not initialized");
820 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
821 goto _ERR_CAMCORDER_CMD_PRECON;
824 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
825 MMCAM_LOG_ERROR("Another command is running.");
826 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
827 goto _ERR_CAMCORDER_CMD_PRECON;
830 state = _mmcamcorder_get_state(handle);
831 if (state != MM_CAMCORDER_STATE_NULL) {
832 MMCAM_LOG_ERROR("Wrong state(%d)", state);
833 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
834 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
837 /* remove kept, but not used sink element in attribute */
838 mm_camcorder_get_attributes(handle, NULL,
839 MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
842 GstStateChangeReturn result = gst_element_set_state(sink_element, GST_STATE_NULL);
844 MMCAM_LOG_WARNING("remove sink element %p, set state NULL result %d", sink_element, result);
846 gst_object_unref(sink_element);
850 /* wait for completion of sound play */
851 _mmcamcorder_sound_solo_play_wait(handle);
853 /* Release SubContext and pipeline */
854 if (hcamcorder->sub_context) {
855 if (hcamcorder->sub_context->element)
856 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
858 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
859 hcamcorder->sub_context = NULL;
862 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
863 /* de-initialize resource manager */
864 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
866 if (hcamcorder->resource_manager != NULL) {
867 ret = mm_resource_manager_destroy(hcamcorder->resource_manager);
868 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
869 MMCAM_LOG_ERROR("failed to de-initialize resource manager 0x%x", ret);
872 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
873 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
875 /* Remove messages which are not called yet */
876 _mmcamcorder_remove_message_all(handle);
878 #ifdef _MMCAMCORDER_RM_SUPPORT
879 _mmcamcorder_rm_release(handle);
880 #endif /* _MMCAMCORDER_RM_SUPPORT */
882 /* release DPM handle */
883 if (hcamcorder->dpm_handle) {
884 MMCAM_LOG_INFO("release DPM handle %p, camera changed cb id %d",
885 hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
887 /* remove camera policy changed callback */
888 if (hcamcorder->dpm_camera_cb_id > 0) {
889 dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
890 hcamcorder->dpm_camera_cb_id = 0;
892 MMCAM_LOG_WARNING("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
895 dpm_manager_destroy(hcamcorder->dpm_handle);
896 hcamcorder->dpm_handle = NULL;
899 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
901 __mmcamcorder_deinit_handle(hcamcorder);
903 return MM_ERROR_NONE;
905 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
906 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
908 _ERR_CAMCORDER_CMD_PRECON:
910 MMCAM_LOG_ERROR("Destroy fail (type %d, state %d)", hcamcorder->type, state);
912 MMCAM_LOG_ERROR("Destroy fail (ret %x)", ret);
918 int _mmcamcorder_realize(MMHandleType handle)
920 int ret = MM_ERROR_NONE;
921 int state = MM_CAMCORDER_STATE_NONE;
922 int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
923 double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
924 char *videosink_element_type = NULL;
925 const char *videosink_name = NULL;
928 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
930 /*MMCAM_LOG_INFO("");*/
933 MMCAM_LOG_ERROR("Not initialized");
934 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
938 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
939 MMCAM_LOG_ERROR("Another command is running.");
940 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
941 goto _ERR_CAMCORDER_CMD_PRECON;
944 state = _mmcamcorder_get_state(handle);
945 if (state != MM_CAMCORDER_STATE_NULL) {
946 MMCAM_LOG_ERROR("Wrong state(%d)", state);
947 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
948 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
951 /* Get profile mode and gdbus connection */
952 mm_camcorder_get_attributes(handle, NULL,
953 MMCAM_MODE, &hcamcorder->type,
954 MMCAM_GDBUS_CONNECTION, &hcamcorder->gdbus_conn, &conn_size,
957 if (!hcamcorder->gdbus_conn) {
958 MMCAM_LOG_ERROR("gdbus connection NULL");
959 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
960 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
963 MMCAM_LOG_INFO("Profile mode [%d], gdbus connection [%p]",
964 hcamcorder->type, hcamcorder->gdbus_conn);
966 mm_camcorder_get_attributes(handle, NULL,
967 MMCAM_DISPLAY_SURFACE, &display_surface_type,
968 MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate,
971 /* alloc sub context */
972 hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
973 if (!hcamcorder->sub_context) {
974 ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
975 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
978 /* Set basic configure information */
979 if (motion_rate != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE)
980 hcamcorder->sub_context->is_modified_rate = TRUE;
982 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
983 /* get video recording info */
984 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
985 CONFIGURE_CATEGORY_MAIN_RECORD,
987 &(hcamcorder->sub_context->info_video->support_dual_stream));
988 MMCAM_LOG_WARNING("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
990 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
991 CONFIGURE_CATEGORY_MAIN_RECORD,
993 &(hcamcorder->sub_context->info_video->use_videoscale));
994 MMCAM_LOG_WARNING("UseVideoscale [%d]", hcamcorder->sub_context->info_video->use_videoscale);
997 switch (display_surface_type) {
998 case MM_DISPLAY_SURFACE_OVERLAY:
999 videosink_element_type = strdup("VideosinkElementOverlay");
1001 case MM_DISPLAY_SURFACE_EVAS:
1002 videosink_element_type = strdup("VideosinkElementEvas");
1004 case MM_DISPLAY_SURFACE_GL:
1005 videosink_element_type = strdup("VideosinkElementGL");
1007 case MM_DISPLAY_SURFACE_NULL:
1008 videosink_element_type = strdup("VideosinkElementNull");
1011 videosink_element_type = strdup("VideosinkElementOverlay");
1015 /* check string of videosink element */
1016 if (videosink_element_type) {
1017 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1018 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1019 videosink_element_type,
1020 &hcamcorder->sub_context->VideosinkElement);
1021 free(videosink_element_type);
1022 videosink_element_type = NULL;
1024 MMCAM_LOG_WARNING("strdup failed(display_surface_type %d). Use default Overlay type",
1025 display_surface_type);
1027 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1028 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1029 _MMCAMCORDER_DEFAULT_VIDEOSINK_TYPE,
1030 &hcamcorder->sub_context->VideosinkElement);
1033 _mmcamcorder_conf_get_value_element_name(hcamcorder->sub_context->VideosinkElement, &videosink_name);
1034 MMCAM_LOG_INFO("Videosink name : %s", videosink_name);
1036 /* get videoconvert element */
1037 _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
1038 CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
1039 "VideoconvertElement",
1040 &hcamcorder->sub_context->VideoconvertElement);
1042 _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
1043 CONFIGURE_CATEGORY_CTRL_CAPTURE,
1044 "SensorEncodedCapture",
1045 &(hcamcorder->sub_context->SensorEncodedCapture));
1046 MMCAM_LOG_INFO("Support sensor encoded capture : %d", hcamcorder->sub_context->SensorEncodedCapture);
1048 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1049 int dpm_camera_state = DPM_ALLOWED;
1051 /* check camera policy from DPM */
1052 if (hcamcorder->dpm_handle) {
1053 if (dpm_restriction_get_camera_state(hcamcorder->dpm_handle, &dpm_camera_state) == DPM_ERROR_NONE) {
1054 MMCAM_LOG_INFO("DPM camera state %d", dpm_camera_state);
1055 if (dpm_camera_state == DPM_DISALLOWED) {
1056 MMCAM_LOG_ERROR("CAMERA DISALLOWED by DPM");
1057 ret = MM_ERROR_POLICY_RESTRICTED;
1059 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
1061 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1064 MMCAM_LOG_ERROR("get DPM camera state failed, keep going...");
1067 MMCAM_LOG_WARNING("NULL dpm_handle");
1070 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1071 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1072 /* prepare resource manager for camera */
1073 if (hcamcorder->camera_resource == NULL) {
1074 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1075 MM_RESOURCE_MANAGER_RES_TYPE_CAMERA,
1077 &hcamcorder->camera_resource);
1078 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1079 MMCAM_LOG_ERROR("could not prepare for camera resource");
1080 ret = MM_ERROR_RESOURCE_INTERNAL;
1081 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1082 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1085 MMCAM_LOG_INFO("camera already acquired");
1088 /* prepare resource manager for "video_overlay only if display surface is X" */
1089 if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
1090 if (hcamcorder->video_overlay_resource == NULL) {
1091 ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager,
1092 MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY,
1093 MM_RESOURCE_MANAGER_RES_VOLUME_FULL,
1094 &hcamcorder->video_overlay_resource);
1095 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1096 MMCAM_LOG_ERROR("could not prepare for overlay resource");
1097 ret = MM_ERROR_RESOURCE_INTERNAL;
1098 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1099 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1102 MMCAM_LOG_INFO("overlay already acquired");
1106 /* acquire resources */
1107 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1108 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1109 MMCAM_LOG_ERROR("could not acquire resources");
1110 ret = MM_ERROR_RESOURCE_INTERNAL;
1111 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1112 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1114 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1115 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1117 #ifdef _MMCAMCORDER_RM_SUPPORT
1118 ret = _mmcamcorder_rm_create(handle);
1119 if (ret != MM_ERROR_NONE) {
1120 MMCAM_LOG_ERROR("Resource create failed");
1121 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1123 ret = _mmcamcorder_rm_allocate(handle);
1124 if (ret != MM_ERROR_NONE) {
1125 MMCAM_LOG_ERROR("Resource allocation request failed");
1126 _mmcamcorder_rm_release(handle);
1127 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1129 #endif /* _MMCAMCORDER_RM_SUPPORT */
1132 /* create pipeline */
1133 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:CREATE_PIPELINE");
1135 ret = _mmcamcorder_create_pipeline(handle, hcamcorder->type);
1137 traceEnd(TTRACE_TAG_CAMERA);
1139 if (ret != MM_ERROR_NONE) {
1140 /* check internal error of gstreamer */
1141 if (hcamcorder->error_code != MM_ERROR_NONE) {
1142 ret = hcamcorder->error_code;
1143 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1146 /* release sub context */
1147 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1148 hcamcorder->sub_context = NULL;
1149 goto _ERR_CAMCORDER_CMD;
1152 /* set command function */
1153 ret = _mmcamcorder_set_functions(handle, hcamcorder->type);
1154 if (ret != MM_ERROR_NONE) {
1155 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1156 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1157 hcamcorder->sub_context = NULL;
1158 goto _ERR_CAMCORDER_CMD;
1161 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1163 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1165 return MM_ERROR_NONE;
1168 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1169 /* release hw resources */
1170 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1171 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
1172 if (hcamcorder->camera_resource != NULL) {
1173 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1174 hcamcorder->camera_resource);
1175 hcamcorder->camera_resource = NULL;
1177 if (hcamcorder->video_overlay_resource != NULL) {
1178 mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1179 hcamcorder->video_overlay_resource);
1180 hcamcorder->video_overlay_resource = NULL;
1182 mm_resource_manager_commit(hcamcorder->resource_manager);
1184 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1185 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1186 #ifdef _MMCAMCORDER_RM_SUPPORT
1187 _mmcamcorder_rm_deallocate(handle);
1188 _mmcamcorder_rm_release(handle);
1189 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1191 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1192 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1194 _ERR_CAMCORDER_CMD_PRECON:
1195 MMCAM_LOG_ERROR("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1201 int _mmcamcorder_unrealize(MMHandleType handle)
1203 int ret = MM_ERROR_NONE;
1204 int state = MM_CAMCORDER_STATE_NONE;
1206 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1211 MMCAM_LOG_ERROR("Not initialized");
1212 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1216 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1217 MMCAM_LOG_ERROR("Another command is running.");
1218 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1219 goto _ERR_CAMCORDER_CMD_PRECON;
1222 state = _mmcamcorder_get_state(handle);
1223 if (state != MM_CAMCORDER_STATE_READY) {
1224 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1225 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1226 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1229 /* Release SubContext */
1230 if (hcamcorder->sub_context) {
1231 /* destroy pipeline */
1232 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
1233 /* Deallocate SubContext */
1234 _mmcamcorder_dealloc_subcontext(hcamcorder->sub_context);
1235 hcamcorder->sub_context = NULL;
1238 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
1239 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
1240 MMCAM_LOG_WARNING("lock resource - cb calling %d", hcamcorder->is_release_cb_calling);
1242 if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE &&
1243 hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM &&
1244 hcamcorder->is_release_cb_calling == FALSE) {
1246 /* release resource */
1247 if (hcamcorder->camera_resource != NULL) {
1248 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1249 hcamcorder->camera_resource);
1250 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1251 MMCAM_LOG_ERROR("could not mark camera resource for release");
1252 ret = MM_ERROR_CAMCORDER_INTERNAL;
1253 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1254 MMCAM_LOG_INFO("unlock resource");
1255 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1259 if (hcamcorder->video_overlay_resource != NULL) {
1260 ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager,
1261 hcamcorder->video_overlay_resource);
1262 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1263 MMCAM_LOG_ERROR("could not mark overlay resource for release");
1264 ret = MM_ERROR_CAMCORDER_INTERNAL;
1265 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1266 MMCAM_LOG_INFO("unlock resource");
1267 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1271 ret = mm_resource_manager_commit(hcamcorder->resource_manager);
1273 if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
1274 MMCAM_LOG_ERROR("failed to release resource, ret(0x%x)", ret);
1275 ret = MM_ERROR_CAMCORDER_INTERNAL;
1277 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1278 MMCAM_LOG_INFO("unlock resource");
1280 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1282 if (hcamcorder->camera_resource != NULL)
1283 hcamcorder->camera_resource = NULL;
1284 if (hcamcorder->video_overlay_resource != NULL)
1285 hcamcorder->video_overlay_resource = NULL;
1289 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
1291 MMCAM_LOG_WARNING("unlock resource");
1292 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
1294 #ifdef _MMCAMCORDER_RM_SUPPORT
1295 _mmcamcorder_rm_deallocate(handle);
1296 #endif /* _MMCAMCORDER_RM_SUPPORT*/
1298 /* Deinitialize main context member */
1299 hcamcorder->command = NULL;
1301 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1303 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
1305 return MM_ERROR_NONE;
1307 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1308 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1310 _ERR_CAMCORDER_CMD_PRECON:
1312 MMCAM_LOG_ERROR("Unrealize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1317 int _mmcamcorder_start(MMHandleType handle)
1319 int ret = MM_ERROR_NONE;
1320 int state = MM_CAMCORDER_STATE_NONE;
1322 _MMCamcorderSubContext *sc = NULL;
1323 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1328 MMCAM_LOG_ERROR("Not initialized");
1329 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1333 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1334 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1336 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1337 MMCAM_LOG_ERROR("Another command is running.");
1338 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1339 goto _ERR_CAMCORDER_CMD_PRECON;
1342 state = _mmcamcorder_get_state(handle);
1343 if (state != MM_CAMCORDER_STATE_READY) {
1344 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1345 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1346 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1349 /* initialize error code */
1350 hcamcorder->error_code = MM_ERROR_NONE;
1352 /* set attributes related sensor */
1353 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1354 _mmcamcorder_set_attribute_to_camsensor(handle);
1356 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1357 if (ret != MM_ERROR_NONE) {
1358 /* check internal error of gstreamer */
1359 if (hcamcorder->error_code != MM_ERROR_NONE) {
1360 ret = hcamcorder->error_code;
1361 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1363 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1366 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1368 /* set attributes related sensor - after start preview */
1369 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
1370 _mmcamcorder_set_attribute_to_camsensor2(handle);
1372 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1374 return MM_ERROR_NONE;
1376 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1377 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1379 _ERR_CAMCORDER_CMD_PRECON:
1380 /* check internal error of gstreamer */
1381 if (hcamcorder->error_code != MM_ERROR_NONE) {
1382 ret = hcamcorder->error_code;
1383 hcamcorder->error_code = MM_ERROR_NONE;
1385 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1388 MMCAM_LOG_ERROR("Start fail (type %d, state %d, ret %x)",
1389 hcamcorder->type, state, ret);
1394 int _mmcamcorder_stop(MMHandleType handle)
1396 int ret = MM_ERROR_NONE;
1397 int state = MM_CAMCORDER_STATE_NONE;
1399 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1404 MMCAM_LOG_ERROR("Not initialized");
1405 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1409 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1410 MMCAM_LOG_ERROR("Another command is running.");
1411 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1412 goto _ERR_CAMCORDER_CMD_PRECON;
1415 state = _mmcamcorder_get_state(handle);
1416 if (state != MM_CAMCORDER_STATE_PREPARE) {
1417 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1418 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1419 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1422 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_STOP);
1423 if (ret != MM_ERROR_NONE)
1424 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1426 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
1428 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1430 return MM_ERROR_NONE;
1432 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1433 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1435 _ERR_CAMCORDER_CMD_PRECON:
1437 MMCAM_LOG_ERROR("Stop fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1443 int _mmcamcorder_capture_start(MMHandleType handle)
1445 int ret = MM_ERROR_NONE;
1446 int state = MM_CAMCORDER_STATE_NONE;
1447 int state_FROM_0 = MM_CAMCORDER_STATE_PREPARE;
1448 int state_FROM_1 = MM_CAMCORDER_STATE_RECORDING;
1449 int state_FROM_2 = MM_CAMCORDER_STATE_PAUSED;
1451 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1456 MMCAM_LOG_ERROR("Not initialized");
1457 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1461 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1462 MMCAM_LOG_ERROR("Another command is running.");
1463 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1464 goto _ERR_CAMCORDER_CMD_PRECON;
1467 state = _mmcamcorder_get_state(handle);
1468 if (state != state_FROM_0 && state != state_FROM_1 && state != state_FROM_2) {
1469 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1470 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1471 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1474 /* Handle capture in recording case */
1475 if (state == state_FROM_1 || state == state_FROM_2) {
1476 if (hcamcorder->capture_in_recording == TRUE) {
1477 MMCAM_LOG_ERROR("Capturing in recording (%d)", state);
1478 ret = MM_ERROR_CAMCORDER_DEVICE_BUSY;
1479 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1481 g_mutex_lock(&hcamcorder->task_thread_lock);
1482 if (hcamcorder->task_thread_state == _MMCAMCORDER_TASK_THREAD_STATE_NONE) {
1483 hcamcorder->capture_in_recording = TRUE;
1484 hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_CHECK_CAPTURE_IN_RECORDING;
1485 MMCAM_LOG_INFO("send signal for capture in recording");
1486 g_cond_signal(&hcamcorder->task_thread_cond);
1487 g_mutex_unlock(&hcamcorder->task_thread_lock);
1489 MMCAM_LOG_ERROR("task thread busy : %d", hcamcorder->task_thread_state);
1490 g_mutex_unlock(&hcamcorder->task_thread_lock);
1491 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1492 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1497 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CAPTURE);
1498 if (ret != MM_ERROR_NONE)
1499 goto _ERR_CAMCORDER_CMD;
1501 /* Do not change state when recording snapshot capture */
1502 if (state == state_FROM_0)
1503 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_CAPTURING);
1505 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1507 /* Init break continuous shot attr */
1508 if (mm_camcorder_set_attributes(handle, NULL, MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, 0, NULL) != MM_ERROR_NONE)
1509 MMCAM_LOG_WARNING("capture-break-cont-shot set 0 failed");
1511 return MM_ERROR_NONE;
1514 if (hcamcorder->capture_in_recording)
1515 hcamcorder->capture_in_recording = FALSE;
1517 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1518 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1520 _ERR_CAMCORDER_CMD_PRECON:
1522 MMCAM_LOG_ERROR("Capture start fail (type %d, state %d, ret %x)",
1523 hcamcorder->type, state, ret);
1528 int _mmcamcorder_capture_stop(MMHandleType handle)
1530 int ret = MM_ERROR_NONE;
1531 int state = MM_CAMCORDER_STATE_NONE;
1532 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1537 MMCAM_LOG_ERROR("Not initialized");
1538 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1542 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1543 MMCAM_LOG_ERROR("Another command is running.");
1544 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1545 goto _ERR_CAMCORDER_CMD_PRECON;
1548 state = _mmcamcorder_get_state(handle);
1549 if (state != MM_CAMCORDER_STATE_CAPTURING) {
1550 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1551 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1552 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1555 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
1556 if (ret != MM_ERROR_NONE)
1557 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1559 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1561 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1563 return MM_ERROR_NONE;
1565 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1566 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1568 _ERR_CAMCORDER_CMD_PRECON:
1570 MMCAM_LOG_ERROR("Capture stop fail (type %d, state %d, ret %x)",
1571 hcamcorder->type, state, ret);
1576 int _mmcamcorder_record(MMHandleType handle)
1578 int ret = MM_ERROR_NONE;
1579 int state = MM_CAMCORDER_STATE_NONE;
1580 int dpm_mic_state = DPM_ALLOWED;
1582 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1583 _MMCamcorderSubContext *sc = NULL;
1587 if (!hcamcorder || !MMF_CAMCORDER_SUBCONTEXT(hcamcorder)) {
1588 MMCAM_LOG_ERROR("Not initialized");
1589 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1593 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
1595 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1596 MMCAM_LOG_ERROR("Another command is running.");
1597 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1598 goto _ERR_CAMCORDER_CMD_PRECON;
1601 state = _mmcamcorder_get_state(handle);
1602 if (state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_PAUSED) {
1603 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1604 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1605 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1608 /* initialize error code */
1609 hcamcorder->error_code = MM_ERROR_NONE;
1611 /* get audio disable */
1612 mm_camcorder_get_attributes(handle, NULL,
1613 MMCAM_AUDIO_DISABLE, &sc->audio_disable,
1616 sc->audio_disable |= sc->is_modified_rate;
1618 /* check mic policy from DPM */
1619 if (hcamcorder->dpm_handle && sc->audio_disable == FALSE) {
1620 if (dpm_restriction_get_microphone_state(hcamcorder->dpm_handle, &dpm_mic_state) == DPM_ERROR_NONE) {
1621 MMCAM_LOG_INFO("DPM mic state %d", dpm_mic_state);
1622 if (dpm_mic_state == DPM_DISALLOWED) {
1623 MMCAM_LOG_ERROR("MIC DISALLOWED by DPM");
1624 ret = MM_ERROR_COMMON_INVALID_PERMISSION;
1626 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
1628 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1631 MMCAM_LOG_ERROR("get DPM mic state failed, keep going...");
1634 MMCAM_LOG_WARNING("skip dpm check - handle %p, audio disable %d",
1635 hcamcorder->dpm_handle, sc->audio_disable);
1638 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_RECORD);
1639 if (ret != MM_ERROR_NONE) {
1640 /* check internal error of gstreamer */
1641 if (hcamcorder->error_code != MM_ERROR_NONE) {
1642 ret = hcamcorder->error_code;
1643 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1645 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1648 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_RECORDING);
1650 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1652 return MM_ERROR_NONE;
1654 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1655 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1657 _ERR_CAMCORDER_CMD_PRECON:
1658 /* check internal error of gstreamer */
1659 if (hcamcorder->error_code != MM_ERROR_NONE) {
1660 ret = hcamcorder->error_code;
1661 hcamcorder->error_code = MM_ERROR_NONE;
1663 MMCAM_LOG_INFO("gstreamer error is occurred. return it %x", ret);
1666 MMCAM_LOG_ERROR("Record fail (type %d, state %d, ret %x)",
1667 hcamcorder->type, state, ret);
1673 int _mmcamcorder_pause(MMHandleType handle)
1675 int ret = MM_ERROR_NONE;
1676 int state = MM_CAMCORDER_STATE_NONE;
1678 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1683 MMCAM_LOG_ERROR("Not initialized");
1684 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1688 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1689 MMCAM_LOG_ERROR("Another command is running.");
1690 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1691 goto _ERR_CAMCORDER_CMD_PRECON;
1694 state = _mmcamcorder_get_state(handle);
1695 if (state != MM_CAMCORDER_STATE_RECORDING) {
1696 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1697 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1698 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1701 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PAUSE);
1702 if (ret != MM_ERROR_NONE)
1703 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1705 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PAUSED);
1707 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1709 return MM_ERROR_NONE;
1711 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1712 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1714 _ERR_CAMCORDER_CMD_PRECON:
1716 MMCAM_LOG_ERROR("Pause fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1722 int _mmcamcorder_commit(MMHandleType handle)
1724 int ret = MM_ERROR_NONE;
1725 int state = MM_CAMCORDER_STATE_NONE;
1727 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1732 MMCAM_LOG_ERROR("Not initialized");
1733 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1737 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1738 MMCAM_LOG_ERROR("Another command is running.");
1739 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1740 goto _ERR_CAMCORDER_CMD_PRECON;
1743 state = _mmcamcorder_get_state(handle);
1744 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1745 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1746 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1747 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1750 /* initialize error code */
1751 hcamcorder->error_code = MM_ERROR_NONE;
1753 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_COMMIT);
1754 if (ret != MM_ERROR_NONE)
1755 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1757 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1759 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1761 return MM_ERROR_NONE;
1763 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1764 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1766 _ERR_CAMCORDER_CMD_PRECON:
1768 MMCAM_LOG_ERROR("Commit fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
1774 int _mmcamcorder_cancel(MMHandleType handle)
1776 int ret = MM_ERROR_NONE;
1777 int state = MM_CAMCORDER_STATE_NONE;
1779 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1784 MMCAM_LOG_ERROR("Not initialized");
1785 ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
1789 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
1790 MMCAM_LOG_ERROR("Another command is running.");
1791 ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
1792 goto _ERR_CAMCORDER_CMD_PRECON;
1795 state = _mmcamcorder_get_state(handle);
1796 if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
1797 MMCAM_LOG_ERROR("Wrong state(%d)", state);
1798 ret = MM_ERROR_CAMCORDER_INVALID_STATE;
1799 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1802 ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_CANCEL);
1803 if (ret != MM_ERROR_NONE)
1804 goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
1806 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1808 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1810 return MM_ERROR_NONE;
1812 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
1813 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
1815 _ERR_CAMCORDER_CMD_PRECON:
1817 MMCAM_LOG_ERROR("Cancel fail (type %d, state %d, ret %x)",
1818 hcamcorder->type, state, ret);
1822 /* } Internal command functions */
1825 int _mmcamcorder_commit_async_end(MMHandleType handle)
1829 MMCAM_LOG_WARNING("_mmcamcorder_commit_async_end : MM_CAMCORDER_STATE_PREPARE");
1830 _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
1832 return MM_ERROR_NONE;
1836 int _mmcamcorder_set_message_callback(MMHandleType handle, MMMessageCallback callback, void *user_data)
1838 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1840 MMCAM_LOG_INFO("%p", hcamcorder);
1842 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1844 if (callback == NULL)
1845 MMCAM_LOG_WARNING("Message Callback is disabled, because application sets it to NULL");
1847 if (!_MMCAMCORDER_TRYLOCK_MESSAGE_CALLBACK(hcamcorder)) {
1848 MMCAM_LOG_WARNING("Application's message callback is running now");
1849 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1852 /* set message callback to message handle */
1853 hcamcorder->msg_cb = callback;
1854 hcamcorder->msg_cb_param = user_data;
1856 _MMCAMCORDER_UNLOCK_MESSAGE_CALLBACK(hcamcorder);
1858 return MM_ERROR_NONE;
1862 int _mmcamcorder_set_video_stream_callback(MMHandleType handle, mm_camcorder_video_stream_callback callback, void *user_data)
1864 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1866 /*MMCAM_LOG_INFO("");*/
1868 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1870 if (callback == NULL)
1871 MMCAM_LOG_WARNING("Video Stream Callback is disabled, because application sets it to NULL");
1873 _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
1875 hcamcorder->vstream_cb = callback;
1876 hcamcorder->vstream_cb_param = user_data;
1878 _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
1880 return MM_ERROR_NONE;
1884 int _mmcamcorder_set_audio_stream_callback(MMHandleType handle, mm_camcorder_audio_stream_callback callback, void *user_data)
1886 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1890 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1892 if (callback == NULL)
1893 MMCAM_LOG_WARNING("Audio Stream Callback is disabled, because application sets it to NULL");
1895 if (!_MMCAMCORDER_TRYLOCK_ASTREAM_CALLBACK(hcamcorder)) {
1896 MMCAM_LOG_WARNING("Application's audio stream callback is running now");
1897 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1900 hcamcorder->astream_cb = callback;
1901 hcamcorder->astream_cb_param = user_data;
1903 _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder);
1905 return MM_ERROR_NONE;
1909 int _mmcamcorder_set_muxed_stream_callback(MMHandleType handle, mm_camcorder_muxed_stream_callback callback, void *user_data)
1911 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1915 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1917 if (callback == NULL)
1918 MMCAM_LOG_WARNING("Muxed Stream Callback is disabled, because application sets it to NULL");
1920 if (!_MMCAMCORDER_TRYLOCK_MSTREAM_CALLBACK(hcamcorder)) {
1921 MMCAM_LOG_WARNING("Application's muxed stream callback is running now");
1922 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1925 hcamcorder->mstream_cb = callback;
1926 hcamcorder->mstream_cb_param = user_data;
1928 _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
1930 return MM_ERROR_NONE;
1934 int _mmcamcorder_set_video_capture_callback(MMHandleType handle, mm_camcorder_video_capture_callback callback, void *user_data)
1936 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1940 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1942 if (callback == NULL)
1943 MMCAM_LOG_WARNING("Video Capture Callback is disabled, because application sets it to NULLL");
1945 if (!_MMCAMCORDER_TRYLOCK_VCAPTURE_CALLBACK(hcamcorder)) {
1946 MMCAM_LOG_WARNING("Application's video capture callback is running now");
1947 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1950 hcamcorder->vcapture_cb = callback;
1951 hcamcorder->vcapture_cb_param = user_data;
1953 _MMCAMCORDER_UNLOCK_VCAPTURE_CALLBACK(hcamcorder);
1955 return MM_ERROR_NONE;
1959 int _mmcamcorder_set_video_encode_decision_callback(MMHandleType handle, mm_camcorder_video_encode_decision_callback callback, void *user_data)
1961 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1965 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1967 if (callback == NULL)
1968 MMCAM_LOG_WARNING("Video Encode Decision Callback is disabled, because application sets it to NULL");
1970 if (!_MMCAMCORDER_TRYLOCK_VEDECISION_CALLBACK(hcamcorder)) {
1971 MMCAM_LOG_WARNING("Application's video encode decision callback is running now");
1972 return MM_ERROR_CAMCORDER_INVALID_CONDITION;
1975 hcamcorder->vedecision_cb = callback;
1976 hcamcorder->vedecision_cb_param = user_data;
1978 _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
1980 return MM_ERROR_NONE;
1984 int _mmcamcorder_get_current_state(MMHandleType handle)
1986 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
1990 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
1992 return _mmcamcorder_get_state(handle);
1995 int _mmcamcorder_init_focusing(MMHandleType handle)
1998 int state = MM_CAMCORDER_STATE_NONE;
1999 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2000 int af_range = MM_CAMCORDER_AUTO_FOCUS_NORMAL;
2001 int sensor_focus_mode = 0;
2002 int sensor_af_range = 0;
2003 int current_focus_mode = 0;
2004 int current_af_range = 0;
2005 mmf_camcorder_t *hcamcorder = NULL;
2006 _MMCamcorderSubContext *sc = NULL;
2007 GstCameraControl *control = NULL;
2011 hcamcorder = MMF_CAMCORDER(handle);
2012 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2014 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2015 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2017 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2018 MMCAM_LOG_ERROR("Another command is running.");
2019 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2022 state = _mmcamcorder_get_state(handle);
2024 if (state == MM_CAMCORDER_STATE_CAPTURING ||
2025 state < MM_CAMCORDER_STATE_PREPARE) {
2026 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2027 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2028 return MM_ERROR_CAMCORDER_INVALID_STATE;
2031 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2032 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2033 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2034 return MM_ERROR_NONE;
2037 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2038 if (control == NULL) {
2039 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2040 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2041 return MM_ERROR_CAMCORDER_INTERNAL;
2044 ret = gst_camera_control_stop_auto_focus(control);
2046 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2047 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2048 return MM_ERROR_CAMCORDER_DEVICE_IO;
2051 /* Initialize lens position */
2052 mm_camcorder_get_attributes(handle, NULL,
2053 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2054 MMCAM_CAMERA_AF_SCAN_RANGE, &af_range,
2056 sensor_af_range = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_AF_SCAN_RANGE, af_range);
2057 sensor_focus_mode = _mmcamcorder_convert_msl_to_sensor(handle, MM_CAM_CAMERA_FOCUS_MODE, focus_mode);
2059 gst_camera_control_get_focus(control, ¤t_focus_mode, ¤t_af_range);
2061 if (current_focus_mode != sensor_focus_mode || current_af_range != sensor_af_range) {
2062 ret = gst_camera_control_set_focus(control, sensor_focus_mode, sensor_af_range);
2064 MMCAM_LOG_INFO("No need to init FOCUS [mode:%d, range:%d]", focus_mode, af_range);
2068 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2071 MMCAM_LOG_INFO("Lens init success.");
2072 return MM_ERROR_NONE;
2074 MMCAM_LOG_ERROR("Lens init fail.");
2075 return MM_ERROR_CAMCORDER_DEVICE_IO;
2079 int _mmcamcorder_adjust_focus(MMHandleType handle, int direction)
2082 int focus_mode = MM_CAMCORDER_FOCUS_MODE_NONE;
2083 int ret = MM_ERROR_UNKNOWN;
2084 char *err_attr_name = NULL;
2086 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2087 mmf_return_val_if_fail(direction, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2089 /*MMCAM_LOG_INFO("");*/
2091 if (!_MMCAMCORDER_TRYLOCK_CMD(handle)) {
2092 MMCAM_LOG_ERROR("Another command is running.");
2093 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2096 state = _mmcamcorder_get_state(handle);
2097 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2098 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2099 _MMCAMCORDER_UNLOCK_CMD(handle);
2100 return MM_ERROR_CAMCORDER_INVALID_STATE;
2103 /* TODO : call a auto or manual focus function */
2104 ret = mm_camcorder_get_attributes(handle, &err_attr_name,
2105 MMCAM_CAMERA_FOCUS_MODE, &focus_mode,
2107 if (ret != MM_ERROR_NONE) {
2108 MMCAM_LOG_WARNING("Get focus-mode fail. (%s:%x)", err_attr_name, ret);
2109 SAFE_FREE(err_attr_name);
2110 _MMCAMCORDER_UNLOCK_CMD(handle);
2114 switch (focus_mode) {
2115 case MM_CAMCORDER_FOCUS_MODE_MANUAL:
2116 ret = _mmcamcorder_adjust_manual_focus(handle, direction);
2118 case MM_CAMCORDER_FOCUS_MODE_AUTO:
2119 case MM_CAMCORDER_FOCUS_MODE_TOUCH_AUTO:
2120 case MM_CAMCORDER_FOCUS_MODE_CONTINUOUS:
2121 ret = _mmcamcorder_adjust_auto_focus(handle);
2124 MMCAM_LOG_ERROR("It doesn't adjust focus. Focusing mode(%d)", focus_mode);
2125 ret = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2128 _MMCAMCORDER_UNLOCK_CMD(handle);
2133 int _mmcamcorder_adjust_manual_focus(MMHandleType handle, int direction)
2138 int focus_level = 0;
2139 float unit_level = 0;
2140 GstCameraControl *control = NULL;
2141 _MMCamcorderSubContext *sc = NULL;
2142 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2146 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2147 mmf_return_val_if_fail(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL != 1, MM_ERROR_CAMCORDER_NOT_SUPPORTED);
2148 mmf_return_val_if_fail((direction >= MM_CAMCORDER_MF_LENS_DIR_FORWARD) &&
2149 (direction <= MM_CAMCORDER_MF_LENS_DIR_BACKWARD),
2150 MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2152 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2153 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2155 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2156 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2157 return MM_ERROR_NONE;
2160 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2161 if (control == NULL) {
2162 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2163 return MM_ERROR_CAMCORDER_INTERNAL;
2166 /* TODO : get max, min level */
2167 if (max_level - min_level + 1 < _MMFCAMCORDER_FOCUS_TOTAL_LEVEL)
2168 MMCAM_LOG_WARNING("Total level of manual focus of MMF is greater than that of the camera driver.");
2170 unit_level = ((float)max_level - (float)min_level)/(float)(_MMFCAMCORDER_FOCUS_TOTAL_LEVEL - 1);
2172 if (!gst_camera_control_get_focus_level(control, &cur_level)) {
2173 MMCAM_LOG_ERROR("Can't get current level of manual focus.");
2174 return MM_ERROR_CAMCORDER_DEVICE_IO;
2177 /* TODO : adjust unit level value */
2178 if (direction == MM_CAMCORDER_MF_LENS_DIR_FORWARD)
2179 focus_level = cur_level + unit_level;
2180 else if (direction == MM_CAMCORDER_MF_LENS_DIR_BACKWARD)
2181 focus_level = cur_level - unit_level;
2183 if (focus_level > max_level)
2184 focus_level = max_level;
2185 else if (focus_level < min_level)
2186 focus_level = min_level;
2188 if (!gst_camera_control_set_focus_level(control, focus_level)) {
2189 MMCAM_LOG_ERROR("Manual focusing fail.");
2190 return MM_ERROR_CAMCORDER_DEVICE_IO;
2193 return MM_ERROR_NONE;
2197 int _mmcamcorder_adjust_auto_focus(MMHandleType handle)
2200 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2201 GstCameraControl *control = NULL;
2202 _MMCamcorderSubContext *sc = NULL;
2204 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2206 /*MMCAM_LOG_INFO("");*/
2208 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2210 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2211 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2212 return MM_ERROR_NONE;
2215 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2218 ret = gst_camera_control_start_auto_focus(control);
2220 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2225 MMCAM_LOG_INFO("Auto focusing start success.");
2226 return MM_ERROR_NONE;
2228 MMCAM_LOG_ERROR("Auto focusing start fail.");
2229 return MM_ERROR_CAMCORDER_DEVICE_IO;
2233 int _mmcamcorder_stop_focusing(MMHandleType handle)
2235 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2236 _MMCamcorderSubContext *sc = NULL;
2239 GstCameraControl *control = NULL;
2241 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2243 /*MMCAM_LOG_INFO("");*/
2245 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2247 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
2248 MMCAM_LOG_ERROR("Another command is running.");
2249 return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
2252 state = _mmcamcorder_get_state(handle);
2253 if (state == MM_CAMCORDER_STATE_CAPTURING || state < MM_CAMCORDER_STATE_PREPARE) {
2254 MMCAM_LOG_ERROR("Not proper state. state[%d]", state);
2255 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2256 return MM_ERROR_CAMCORDER_INVALID_STATE;
2259 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2260 MMCAM_LOG_INFO("Can't cast Video source into camera control.");
2261 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2262 return MM_ERROR_NONE;
2265 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2267 ret = gst_camera_control_stop_auto_focus(control);
2269 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2273 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
2276 MMCAM_LOG_INFO("Auto focusing stop success.");
2277 return MM_ERROR_NONE;
2279 MMCAM_LOG_ERROR("Auto focusing stop fail.");
2280 return MM_ERROR_CAMCORDER_DEVICE_IO;
2284 int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
2286 GstCameraControl *control = NULL;
2287 _MMCamcorderSubContext *sc = NULL;
2288 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2290 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2291 mmf_return_val_if_fail(level, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2293 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2294 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
2296 if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2297 MMCAM_LOG_ERROR("Can't cast Video source into camera control.");
2298 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2301 control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
2303 MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
2304 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2307 if (!gst_camera_control_get_focus_level(control, level)) {
2308 MMCAM_LOG_ERROR("get focus level failed");
2309 return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2312 MMCAM_LOG_INFO("focus level[%d]", *level);
2314 return MM_ERROR_NONE;
2318 /*-----------------------------------------------
2319 | CAMCORDER INTERNAL LOCAL |
2320 -----------------------------------------------*/
2321 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf)
2323 static const int max_argc = 10;
2327 gchar **argv = NULL;
2329 gboolean ret = FALSE;
2330 type_string_array *GSTInitOption = NULL;
2332 mmf_return_val_if_fail(conf, FALSE);
2337 argc = malloc(sizeof(int));
2338 argv = malloc(sizeof(gchar *) * max_argc);
2343 memset(argv, 0, sizeof(gchar *) * max_argc);
2347 argv[0] = g_strdup("mmcamcorder");
2350 _mmcamcorder_conf_get_value_string_array(conf,
2351 CONFIGURE_CATEGORY_MAIN_GENERAL,
2354 if (GSTInitOption != NULL && GSTInitOption->value) {
2355 cnt_str = GSTInitOption->count;
2356 for ( ; *argc < max_argc && *argc <= cnt_str ; (*argc)++)
2357 argv[*argc] = g_strdup(GSTInitOption->value[(*argc)-1]);
2360 MMCAM_LOG_INFO("initializing gstreamer with following parameter[argc:%d]", *argc);
2362 for (i = 0; i < *argc; i++)
2363 MMCAM_LOG_INFO("argv[%d] : %s", i, argv[i]);
2365 /* initializing gstreamer */
2366 ret = gst_init_check(argc, &argv, &err);
2368 MMCAM_LOG_ERROR("Could not initialize GStreamer: %s ", err ? err->message : "unknown error occurred");
2374 for (i = 0; i < *argc; i++) {
2394 MMCAM_LOG_ERROR("failed to initialize gstreamer");
2410 int _mmcamcorder_get_state(MMHandleType handle)
2413 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2415 mmf_return_val_if_fail(hcamcorder, -1);
2417 _MMCAMCORDER_LOCK_STATE(handle);
2419 state = hcamcorder->state;
2420 /*MMCAM_LOG_INFO("state=%d",state);*/
2422 _MMCAMCORDER_UNLOCK_STATE(handle);
2428 int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state)
2430 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2432 mmf_return_val_if_fail(hcamcorder && state && old_state, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
2434 _MMCAMCORDER_LOCK_STATE(handle);
2436 *state = hcamcorder->state;
2437 *old_state = hcamcorder->old_state;
2439 _MMCAMCORDER_UNLOCK_STATE(handle);
2441 return MM_ERROR_NONE;
2445 void _mmcamcorder_set_state(MMHandleType handle, int state)
2448 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2449 _MMCamcorderMsgItem msg;
2451 mmf_return_if_fail(hcamcorder);
2453 /*MMCAM_LOG_INFO("");*/
2455 _MMCAMCORDER_LOCK_STATE(handle);
2457 old_state = hcamcorder->state;
2458 if (old_state != state) {
2459 hcamcorder->state = state;
2460 hcamcorder->old_state = old_state;
2462 MMCAM_LOG_INFO("set state[%d -> %d] and send state-changed message", old_state, state);
2464 /* To discern who changes the state */
2465 switch (hcamcorder->state_change_by_system) {
2466 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
2467 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_RM;
2468 msg.param.state.code = MM_ERROR_NONE;
2470 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
2471 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY;
2472 msg.param.state.code = MM_ERROR_NONE;
2474 case _MMCAMCORDER_STATE_CHANGE_NORMAL:
2476 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGED;
2477 msg.param.state.code = MM_ERROR_NONE;
2481 msg.param.state.previous = old_state;
2482 msg.param.state.current = state;
2484 /*MMCAM_LOG_INFO("_mmcamcorder_send_message : msg : %p, id:%x", &msg, msg.id);*/
2485 _mmcamcorder_send_message(handle, &msg);
2488 _MMCAMCORDER_UNLOCK_STATE(handle);
2494 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
2497 _MMCamcorderSubContext *sc = NULL;
2499 /*MMCAM_LOG_INFO("");*/
2501 /* alloc container */
2502 sc = (_MMCamcorderSubContext *)g_malloc0(sizeof(_MMCamcorderSubContext));
2504 sc->element_num = _MMCAMCORDER_PIPELINE_ELEMENT_NUM;
2505 sc->encode_element_num = _MMCAMCORDER_ENCODE_PIPELINE_ELEMENT_NUM;
2507 /* alloc info for each mode */
2509 case MM_CAMCORDER_MODE_AUDIO:
2510 sc->info_audio = g_malloc0(sizeof(_MMCamcorderAudioInfo));
2512 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2514 sc->info_image = g_malloc0(sizeof(_MMCamcorderImageInfo));
2515 sc->info_video = g_malloc0(sizeof(_MMCamcorderVideoInfo));
2517 sc->info_image->sound_status = _SOUND_STATUS_INIT;
2518 g_mutex_init(&sc->info_video->size_check_lock);
2522 /* alloc element array */
2523 sc->element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->element_num);
2524 sc->encode_element = (_MMCamcorderGstElement *)g_malloc(sizeof(_MMCamcorderGstElement) * sc->encode_element_num);
2526 for (i = 0 ; i < sc->element_num ; i++) {
2527 sc->element[i].id = _MMCAMCORDER_NONE;
2528 sc->element[i].gst = NULL;
2531 for (i = 0 ; i < sc->encode_element_num ; i++) {
2532 sc->encode_element[i].id = _MMCAMCORDER_NONE;
2533 sc->encode_element[i].gst = NULL;
2536 sc->fourcc = 0x80000000;
2537 sc->frame_stability_count = 0;
2538 sc->drop_vframe = 0;
2539 sc->pass_first_vframe = 0;
2540 sc->is_modified_rate = FALSE;
2546 void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
2552 MMCAM_LOG_INFO("release element");
2553 g_free(sc->element);
2557 if (sc->encode_element) {
2558 MMCAM_LOG_INFO("release encode_element");
2559 g_free(sc->encode_element);
2560 sc->encode_element = NULL;
2563 if (sc->info_image) {
2564 MMCAM_LOG_INFO("release info_image");
2565 g_free(sc->info_image);
2566 sc->info_image = NULL;
2569 if (sc->info_video) {
2570 MMCAM_LOG_INFO("release info_video");
2571 SAFE_G_FREE(sc->info_video->filename);
2572 g_mutex_clear(&sc->info_video->size_check_lock);
2573 g_free(sc->info_video);
2574 sc->info_video = NULL;
2577 if (sc->info_audio) {
2578 MMCAM_LOG_INFO("release info_audio");
2579 SAFE_G_FREE(sc->info_audio->filename);
2580 g_free(sc->info_audio);
2581 sc->info_audio = NULL;
2592 int _mmcamcorder_set_functions(MMHandleType handle, int type)
2594 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
2596 /*MMCAM_LOG_INFO("");*/
2599 case MM_CAMCORDER_MODE_AUDIO:
2600 hcamcorder->command = _mmcamcorder_audio_command;
2602 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
2604 hcamcorder->command = _mmcamcorder_video_capture_command;
2608 return MM_ERROR_NONE;
2612 gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpointer data)
2614 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2615 _MMCamcorderSubContext *sc = NULL;
2617 mmf_return_val_if_fail(hcamcorder, FALSE);
2618 mmf_return_val_if_fail(message, FALSE);
2620 MMCAM_LOG_DEBUG("message type[0x%x]", GST_MESSAGE_TYPE(message));
2622 switch (GST_MESSAGE_TYPE(message)) {
2623 case GST_MESSAGE_EOS:
2625 MMCAM_LOG_ERROR("Got EOS from element[%s]... but should not be reached here!",
2626 GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));
2629 case GST_MESSAGE_ERROR:
2632 gchar *debug = NULL;
2634 gst_message_parse_error(message, &err, &debug);
2636 __mmcamcorder_handle_gst_error((MMHandleType)hcamcorder, message, err);
2639 MMCAM_LOG_ERROR("GSTERR: %s", err->message);
2645 MMCAM_LOG_ERROR("Error Debug: %s", debug);
2651 case GST_MESSAGE_WARNING:
2655 gst_message_parse_warning(message, &err, &debug);
2657 MMCAM_LOG_WARNING("GSTWARN: %s", err->message);
2659 __mmcamcorder_handle_gst_warning((MMHandleType)hcamcorder, message, err);
2665 case GST_MESSAGE_STATE_CHANGED:
2667 const GValue *vnewstate;
2669 GstElement *pipeline = NULL;
2671 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2672 if ((sc) && (sc->element)) {
2673 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst) {
2674 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
2675 if (message->src == (GstObject*)pipeline) {
2676 vnewstate = gst_structure_get_value(gst_message_get_structure(message), "new-state");
2678 newstate = (GstState)vnewstate->data[0].v_int;
2679 MMCAM_LOG_INFO("GST_MESSAGE_STATE_CHANGED[%s]", gst_element_state_get_name(newstate));
2681 MMCAM_LOG_WARNING("get new state failed from msg");
2688 case GST_MESSAGE_NEW_CLOCK:
2690 GstClock *pipe_clock = NULL;
2691 gst_message_parse_new_clock(message, &pipe_clock);
2692 MMCAM_LOG_INFO("GST_MESSAGE_NEW_CLOCK[%s]", (pipe_clock ? GST_OBJECT_NAME(pipe_clock) : "NULL"));
2696 MMCAM_LOG_DEBUG("unhandled message type[0x%x]", GST_MESSAGE_TYPE(message));
2704 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
2707 gchar *debug_info = NULL;
2709 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
2710 _MMCamcorderSubContext *sc = NULL;
2712 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
2713 mmf_return_val_if_fail(message, GST_BUS_DROP);
2715 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2716 mmf_return_val_if_fail(sc, GST_BUS_DROP);
2718 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
2719 /* parse error message */
2720 gst_message_parse_error(message, &err, &debug_info);
2723 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
2729 MMCAM_LOG_WARNING("failed to parse error message");
2730 return GST_BUS_PASS;
2733 /* check domain[RESOURCE] and element[VIDEOSRC] */
2734 if (err->domain == GST_RESOURCE_ERROR &&
2735 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
2736 switch (err->code) {
2737 case GST_RESOURCE_ERROR_BUSY:
2738 MMCAM_LOG_ERROR("Camera device [busy]");
2739 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_BUSY;
2741 case GST_RESOURCE_ERROR_OPEN_WRITE:
2742 MMCAM_LOG_ERROR("Camera device [open failed]");
2743 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2745 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2746 MMCAM_LOG_ERROR("Camera device [open failed]");
2747 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN;
2749 case GST_RESOURCE_ERROR_OPEN_READ:
2750 MMCAM_LOG_ERROR("Camera device [register trouble]");
2751 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_REG_TROUBLE;
2753 case GST_RESOURCE_ERROR_NOT_FOUND:
2754 MMCAM_LOG_ERROR("Camera device [device not found]");
2755 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND;
2757 case GST_RESOURCE_ERROR_TOO_LAZY:
2758 MMCAM_LOG_ERROR("Camera device [timeout]");
2759 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_TIMEOUT;
2761 case GST_RESOURCE_ERROR_SETTINGS:
2762 MMCAM_LOG_ERROR("Camera device [not supported]");
2763 hcamcorder->error_code = MM_ERROR_CAMCORDER_NOT_SUPPORTED;
2765 case GST_RESOURCE_ERROR_FAILED:
2766 MMCAM_LOG_ERROR("Camera device [working failed].");
2767 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE_IO;
2770 MMCAM_LOG_ERROR("Camera device [General(%d)]", err->code);
2771 hcamcorder->error_code = MM_ERROR_CAMCORDER_DEVICE;
2775 hcamcorder->error_occurs = TRUE;
2780 /* store error code and drop this message if cmd is running */
2781 if (hcamcorder->error_code != MM_ERROR_NONE) {
2782 _MMCamcorderMsgItem msg;
2784 /* post error to application */
2785 hcamcorder->error_occurs = TRUE;
2786 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2787 msg.param.code = hcamcorder->error_code;
2788 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2790 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
2791 _MMCamcorderMsgItem msg;
2793 if (gst_structure_has_name(gst_message_get_structure(message), "avsysvideosrc-AF") ||
2794 gst_structure_has_name(gst_message_get_structure(message), "camerasrc-AF")) {
2795 int focus_state = 0;
2797 gst_structure_get_int(gst_message_get_structure(message), "focus-state", &focus_state);
2798 MMCAM_LOG_INFO("Focus State:%d", focus_state);
2800 msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED;
2801 msg.param.code = focus_state;
2802 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2803 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) {
2807 if (gst_structure_get_int(gst_message_get_structure(message), "progress", &progress)) {
2808 gst_structure_get_int(gst_message_get_structure(message), "status", &status);
2809 MMCAM_LOG_INFO("HDR progress %d percent, status %d", progress, status);
2811 msg.id = MM_MESSAGE_CAMCORDER_HDR_PROGRESS;
2812 msg.param.code = progress;
2813 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2815 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) {
2817 const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");;
2818 GstCameraControlFaceDetectInfo *fd_info = NULL;
2819 MMCamFaceDetectInfo *cam_fd_info = NULL;
2822 fd_info = (GstCameraControlFaceDetectInfo *)g_value_get_pointer(g_value);
2824 if (fd_info == NULL) {
2825 MMCAM_LOG_WARNING("fd_info is NULL");
2826 gst_message_unref(message);
2827 return GST_BUS_DROP;
2830 cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
2832 /* set total face count */
2833 cam_fd_info->num_of_faces = fd_info->num_of_faces;
2835 if (cam_fd_info->num_of_faces > 0) {
2836 cam_fd_info->face_info = (MMCamFaceInfo *)g_malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
2837 MMCAM_LOG_DEBUG("face detection - count %d", cam_fd_info->num_of_faces);
2838 /* set information of each face */
2839 for (i = 0 ; i < cam_fd_info->num_of_faces ; i++) {
2840 cam_fd_info->face_info[i].id = fd_info->face_info[i].id;
2841 cam_fd_info->face_info[i].score = fd_info->face_info[i].score;
2842 cam_fd_info->face_info[i].rect.x = fd_info->face_info[i].rect.x;
2843 cam_fd_info->face_info[i].rect.y = fd_info->face_info[i].rect.y;
2844 cam_fd_info->face_info[i].rect.width = fd_info->face_info[i].rect.width;
2845 cam_fd_info->face_info[i].rect.height = fd_info->face_info[i].rect.height;
2847 MMCAM_LOG_VERBOSE(" [%d] id %d, score %d, [%d,%d,%dx%d]",
2848 i, fd_info->face_info[i].id,
2849 fd_info->face_info[i].score,
2850 fd_info->face_info[i].rect.x,
2851 fd_info->face_info[i].rect.y,
2852 fd_info->face_info[i].rect.width,
2853 fd_info->face_info[i].rect.height);
2856 cam_fd_info->face_info = NULL;
2859 /* send message - cam_fd_info should be freed by application */
2860 msg.id = MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO;
2861 msg.param.data = cam_fd_info;
2862 msg.param.size = sizeof(MMCamFaceDetectInfo);
2865 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2867 /* free fd_info allocated by plugin */
2870 } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-Capture")) {
2871 int capture_done = FALSE;
2873 if (gst_structure_get_int(gst_message_get_structure(message), "capture-done", &capture_done)) {
2874 if (sc->info_image) {
2875 /* play capture sound */
2876 _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE01, FALSE);
2880 _mmcamcorder_pipeline_cb_message(bus, message, data);
2883 _mmcamcorder_pipeline_cb_message(bus, message, data);
2886 gst_message_unref(message);
2888 return GST_BUS_DROP;
2892 static void __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code)
2894 _MMCamcorderMsgItem msg;
2896 mmf_return_if_fail(hcamcorder);
2899 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
2900 case GST_RESOURCE_ERROR_OPEN_WRITE:
2901 MMCAM_LOG_ERROR("audio device [open failed]");
2903 /* post error to application */
2904 hcamcorder->error_occurs = TRUE;
2905 hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
2907 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2908 msg.param.code = hcamcorder->error_code;
2910 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2913 MMCAM_LOG_ERROR("unhandled error code[%d]", err_code);
2919 static void __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code)
2921 gboolean b_committing = FALSE;
2922 storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE;
2923 _MMCamcorderMsgItem msg;
2924 _MMCamcorderSubContext *sc = NULL;
2926 mmf_return_if_fail(hcamcorder);
2928 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
2929 mmf_return_if_fail(sc);
2931 if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
2932 mmf_return_if_fail(sc->info_video);
2933 b_committing = sc->info_video->b_committing;
2935 mmf_return_if_fail(sc->info_audio);
2936 b_committing = sc->info_audio->b_committing;
2939 _MMCAMCORDER_LOCK(hcamcorder);
2942 case GST_RESOURCE_ERROR_WRITE:
2943 storage_get_state(hcamcorder->storage_info.id, &storage_state);
2944 if (storage_state == STORAGE_STATE_REMOVED ||
2945 storage_state == STORAGE_STATE_UNMOUNTABLE) {
2946 MMCAM_LOG_ERROR("storage was removed! [storage state %d]", storage_state);
2947 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2949 MMCAM_LOG_ERROR("File write error, storage state %d", storage_state);
2950 hcamcorder->error_code = MM_ERROR_FILE_WRITE;
2953 if (sc->ferror_send == FALSE) {
2954 sc->ferror_send = TRUE;
2956 MMCAM_LOG_ERROR("error was already sent");
2957 _MMCAMCORDER_UNLOCK(hcamcorder);
2961 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
2962 MMCAM_LOG_ERROR("No left space");
2963 hcamcorder->error_code = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
2965 case GST_RESOURCE_ERROR_OPEN_WRITE:
2966 MMCAM_LOG_ERROR("Out of storage");
2967 hcamcorder->error_code = MM_ERROR_OUT_OF_STORAGE;
2969 case GST_RESOURCE_ERROR_SEEK:
2970 MMCAM_LOG_ERROR("File read(seek)");
2971 hcamcorder->error_code = MM_ERROR_FILE_READ;
2974 MMCAM_LOG_ERROR("Resource error(%d)", err_code);
2975 hcamcorder->error_code = MM_ERROR_CAMCORDER_GST_RESOURCE;
2980 _MMCAMCORDER_SIGNAL(hcamcorder);
2981 _MMCAMCORDER_UNLOCK(hcamcorder);
2983 _MMCAMCORDER_UNLOCK(hcamcorder);
2985 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
2986 msg.param.code = hcamcorder->error_code;
2988 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
2993 static void __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message)
2996 gchar *debug_info = NULL;
2997 _MMCamcorderSubContext *sc = NULL;
2999 mmf_return_if_fail(hcamcorder);
3000 mmf_return_if_fail(message);
3002 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3003 mmf_return_if_fail(sc);
3005 /* parse error message */
3006 gst_message_parse_error(message, &err, &debug_info);
3009 MMCAM_LOG_ERROR("GST ERROR : %s", debug_info);
3015 MMCAM_LOG_ERROR("failed to parse error message");
3019 /* check domain[RESOURCE] and element[AUDIOSRC] */
3020 if (err->domain == GST_RESOURCE_ERROR &&
3021 GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst))
3022 __mmcamcorder_gst_handle_sync_audio_error(hcamcorder, err->code);
3024 __mmcamcorder_gst_handle_sync_others_error(hcamcorder, err->code);
3030 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
3032 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
3033 _MMCamcorderSubContext *sc = NULL;
3035 mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
3036 mmf_return_val_if_fail(message, GST_BUS_DROP);
3038 sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3039 mmf_return_val_if_fail(sc, GST_BUS_DROP);
3041 if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS) {
3042 MMCAM_LOG_INFO("got EOS from pipeline");
3044 _MMCAMCORDER_LOCK(hcamcorder);
3046 sc->bget_eos = TRUE;
3047 _MMCAMCORDER_SIGNAL(hcamcorder);
3049 _MMCAMCORDER_UNLOCK(hcamcorder);
3050 } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
3051 __mmcamcorder_handle_gst_sync_error(hcamcorder, message);
3053 _mmcamcorder_pipeline_cb_message(bus, message, data);
3056 gst_message_unref(message);
3058 return GST_BUS_DROP;
3062 void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *value, void *user_data)
3064 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
3065 int current_state = MM_CAMCORDER_STATE_NONE;
3067 mmf_return_if_fail(hcamcorder);
3068 mmf_return_if_fail(value);
3070 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3071 if (current_state <= MM_CAMCORDER_STATE_NONE || current_state >= MM_CAMCORDER_STATE_NUM) {
3072 MMCAM_LOG_ERROR("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
3076 MMCAM_LOG_WARNING("camera policy [%s], current state [%d]", value, current_state);
3078 if (!strcmp(value, "disallowed")) {
3079 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3081 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_DPM);
3083 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3085 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
3088 MMCAM_LOG_WARNING("done");
3094 int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
3096 int ret = MM_ERROR_NONE;
3097 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3098 _MMCamcorderSubContext *sc = NULL;
3099 GstElement *pipeline = NULL;
3101 MMCAM_LOG_INFO("handle : %p, type : %d", handle, type);
3103 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3105 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3106 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3109 case MM_CAMCORDER_MODE_AUDIO:
3110 ret = _mmcamcorder_create_audio_pipeline(handle);
3111 if (ret != MM_ERROR_NONE)
3115 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3118 ret = _mmcamcorder_create_preview_pipeline(handle);
3119 if (ret != MM_ERROR_NONE)
3124 pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
3125 if (type != MM_CAMCORDER_MODE_AUDIO) {
3126 traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:REALIZE:SET_READY_TO_PIPELINE");
3128 ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY);
3130 traceEnd(TTRACE_TAG_CAMERA);
3132 #ifdef _MMCAMCORDER_GET_DEVICE_INFO
3133 if (!_mmcamcorder_get_device_info(handle))
3134 MMCAM_LOG_ERROR("Getting device information error!!");
3137 MMCAM_LOG_INFO("ret[%x]", ret);
3138 if (ret != MM_ERROR_NONE) {
3139 MMCAM_LOG_ERROR("error : destroy pipeline");
3140 _mmcamcorder_destroy_pipeline(handle, hcamcorder->type);
3147 void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
3149 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3150 _MMCamcorderSubContext *sc = NULL;
3152 int element_num = 0;
3153 _MMCamcorderGstElement *element = NULL;
3155 mmf_return_if_fail(hcamcorder);
3157 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3158 mmf_return_if_fail(sc);
3162 /* Inside each pipeline destroy function, Set GST_STATE_NULL to Main pipeline */
3164 case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
3165 element = sc->element;
3166 element_num = sc->element_num;
3167 _mmcamcorder_destroy_video_capture_pipeline(handle);
3169 case MM_CAMCORDER_MODE_AUDIO:
3170 element = sc->encode_element;
3171 element_num = sc->encode_element_num;
3172 _mmcamcorder_destroy_audio_pipeline(handle);
3175 MMCAM_LOG_ERROR("unknown type %d", type);
3179 MMCAM_LOG_INFO("Pipeline clear!!");
3181 /* checking unreleased element */
3182 for (i = 0 ; i < element_num ; i++) {
3183 if (element[i].gst) {
3184 if (GST_IS_ELEMENT(element[i].gst)) {
3185 MMCAM_LOG_WARNING("Still alive element - ID[%d], name [%s], ref count[%d], status[%s]",
3187 GST_OBJECT_NAME(element[i].gst),
3188 GST_OBJECT_REFCOUNT(element[i].gst),
3189 gst_element_state_get_name(GST_STATE(element[i].gst)));
3190 g_object_weak_unref(G_OBJECT(element[i].gst), (GWeakNotify)_mmcamcorder_element_release_noti, sc);
3192 MMCAM_LOG_WARNING("The element[%d] is still alive, check it", element[i].id);
3195 element[i].id = _MMCAMCORDER_NONE;
3196 element[i].gst = NULL;
3204 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state)
3207 _MMCamcorderSubContext *sc = NULL;
3208 GstState pipeline_state = GST_STATE_VOID_PENDING;
3209 GstStateChangeReturn setChangeReturn = GST_STATE_CHANGE_FAILURE;
3210 GstStateChangeReturn getChangeReturn = GST_STATE_CHANGE_FAILURE;
3211 GstClockTime get_timeout = __MMCAMCORDER_SET_GST_STATE_TIMEOUT * GST_SECOND;
3212 GMutex *state_lock = NULL;
3214 mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3215 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3216 mmf_return_val_if_fail(sc && sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3218 if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == pipeline) {
3219 MMCAM_LOG_INFO("Set state to %d - PREVIEW PIPELINE", target_state);
3220 state_lock = &_MMCAMCORDER_GET_GST_STATE_LOCK(handle);
3222 MMCAM_LOG_INFO("Set state to %d - ENDODE PIPELINE", target_state);
3223 state_lock = &_MMCAMCORDER_GET_GST_ENCODE_STATE_LOCK(handle);
3226 g_mutex_lock(state_lock);
3228 for (k = 0; k < _MMCAMCORDER_STATE_SET_COUNT; k++) {
3229 setChangeReturn = gst_element_set_state(pipeline, target_state);
3230 MMCAM_LOG_INFO("gst_element_set_state[%d] return %d", target_state, setChangeReturn);
3232 if (setChangeReturn != GST_STATE_CHANGE_FAILURE) {
3233 getChangeReturn = gst_element_get_state(pipeline, &pipeline_state, NULL, get_timeout);
3234 switch (getChangeReturn) {
3235 case GST_STATE_CHANGE_NO_PREROLL:
3236 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_NO_PREROLL.");
3238 case GST_STATE_CHANGE_SUCCESS:
3239 /* if we reached the final target state, exit */
3240 if (pipeline_state == target_state) {
3241 MMCAM_LOG_INFO("Set state to %d - DONE", target_state);
3242 g_mutex_unlock(state_lock);
3243 return MM_ERROR_NONE;
3246 case GST_STATE_CHANGE_ASYNC:
3247 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_ASYNC.");
3250 g_mutex_unlock(state_lock);
3251 MMCAM_LOG_INFO("status=GST_STATE_CHANGE_FAILURE.");
3252 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3255 g_mutex_unlock(state_lock);
3257 MMCAM_LOG_ERROR("timeout of gst_element_get_state()!!");
3259 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3262 usleep(_MMCAMCORDER_STATE_CHECK_INTERVAL);
3265 g_mutex_unlock(state_lock);
3267 MMCAM_LOG_ERROR("Failure. gst_element_set_state timeout!!");
3269 return MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
3273 /* For performance check */
3274 int _mmcamcorder_video_current_framerate(MMHandleType handle)
3276 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3277 _MMCamcorderSubContext *sc = NULL;
3279 mmf_return_val_if_fail(hcamcorder, -1);
3281 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3282 mmf_return_val_if_fail(sc, -1);
3284 return sc->kpi.current_fps;
3288 int _mmcamcorder_video_average_framerate(MMHandleType handle)
3290 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3291 _MMCamcorderSubContext *sc = NULL;
3293 mmf_return_val_if_fail(hcamcorder, -1);
3295 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3296 mmf_return_val_if_fail(sc, -1);
3298 return sc->kpi.average_fps;
3302 void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
3304 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3305 _MMCamcorderSubContext *sc = NULL;
3307 mmf_return_if_fail(hcamcorder);
3309 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3310 mmf_return_if_fail(sc);
3312 memset(&(sc->kpi), 0x00, sizeof(_MMCamcorderKPIMeasure));
3318 void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder, int state_change_by_system)
3323 int result = MM_ERROR_NONE;
3324 int cmd_try_count = 0;
3325 int current_state = MM_CAMCORDER_STATE_NONE;
3326 _MMCamcorderMsgItem msg;
3328 mmf_return_if_fail(hcamcorder);
3330 /* check command running */
3332 if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
3333 if (cmd_try_count++ < __MMCAMCORDER_FORCE_STOP_TRY_COUNT) {
3334 MMCAM_LOG_WARNING("Another command is running. try again after %d ms", __MMCAMCORDER_FORCE_STOP_WAIT_TIME/1000);
3335 usleep(__MMCAMCORDER_FORCE_STOP_WAIT_TIME);
3337 MMCAM_LOG_ERROR("wait timeout");
3341 _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
3346 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3348 MMCAM_LOG_WARNING("Force STOP MMFW Camcorder by %d", state_change_by_system);
3350 /* set state_change_by_system for state change message */
3351 hcamcorder->state_change_by_system = state_change_by_system;
3353 if (current_state >= MM_CAMCORDER_STATE_READY) {
3354 MMCAM_LOG_WARNING("send state change started message to notify");
3356 memset(&msg, 0x0, sizeof(_MMCamcorderMsgItem));
3358 switch (state_change_by_system) {
3359 case _MMCAMCORDER_STATE_CHANGE_BY_RM:
3360 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_RM;
3362 case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
3363 msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_SECURITY;
3370 msg.param.state.code = hcamcorder->interrupt_code;
3371 _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
3373 MMCAM_LOG_ERROR("should not be reached here %d", state_change_by_system);
3377 for (loop = 0 ; current_state > MM_CAMCORDER_STATE_NULL && loop < __MMCAMCORDER_CMD_ITERATE_MAX * 3 ; loop++) {
3378 itr_cnt = __MMCAMCORDER_CMD_ITERATE_MAX;
3379 switch (current_state) {
3380 case MM_CAMCORDER_STATE_CAPTURING:
3382 _MMCamcorderSubContext *sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
3383 _MMCamcorderImageInfo *info = NULL;
3385 mmf_return_if_fail(sc);
3386 mmf_return_if_fail((info = sc->info_image));
3388 MMCAM_LOG_WARNING("Stop capturing.");
3390 /* if capturing isn't finished, waiting for 2 sec to finish real capture operation. check 'info->capturing'. */
3391 mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
3392 MMCAM_CAPTURE_BREAK_CONTINUOUS_SHOT, TRUE,
3395 for (i = 0; i < 20 && info->capturing; i++)
3399 MMCAM_LOG_ERROR("Timeout. Can't check stop capturing.");
3401 while ((itr_cnt--) && ((result = _mmcamcorder_capture_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3402 MMCAM_LOG_WARNING("Can't stop capturing.(%x)", result);
3406 case MM_CAMCORDER_STATE_RECORDING:
3407 case MM_CAMCORDER_STATE_PAUSED:
3409 MMCAM_LOG_WARNING("Stop recording.");
3411 while ((itr_cnt--) && ((result = _mmcamcorder_commit((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
3412 MMCAM_LOG_WARNING("Can't commit.(%x), cancel it.", result);
3413 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3418 case MM_CAMCORDER_STATE_PREPARE:
3420 MMCAM_LOG_WARNING("Stop preview.");
3422 while ((itr_cnt--) && ((result = _mmcamcorder_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
3423 MMCAM_LOG_WARNING("Can't stop preview.(%x)", result);
3427 case MM_CAMCORDER_STATE_READY:
3429 MMCAM_LOG_WARNING("unrealize");
3431 if ((result = _mmcamcorder_unrealize((MMHandleType)hcamcorder)) != MM_ERROR_NONE)
3432 MMCAM_LOG_WARNING("Can't unrealize.(%x)", result);
3437 MMCAM_LOG_WARNING("Already stopped.");
3441 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3445 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3447 MMCAM_LOG_WARNING("Done.");
3453 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error)
3455 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3456 _MMCamcorderMsgItem msg;
3457 gchar *msg_src_element = NULL;
3458 _MMCamcorderSubContext *sc = NULL;
3460 mmf_return_val_if_fail(hcamcorder, FALSE);
3461 mmf_return_val_if_fail(error, FALSE);
3463 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3464 mmf_return_val_if_fail(sc, FALSE);
3466 MMCAM_LOG_INFO("error code %d", error->code);
3468 mmf_return_val_if_fail(hcamcorder->state >= MM_CAMCORDER_STATE_READY, FALSE);
3470 /* filtering filesink related errors */
3471 if (hcamcorder->state == MM_CAMCORDER_STATE_RECORDING &&
3472 (error->code == GST_RESOURCE_ERROR_WRITE || error->code == GST_RESOURCE_ERROR_SEEK)) {
3473 if (sc->ferror_count == 2 && sc->ferror_send == FALSE) {
3474 sc->ferror_send = TRUE;
3475 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3478 MMCAM_LOG_WARNING("Skip error");
3483 if (error->domain == GST_CORE_ERROR) {
3484 msg.param.code = __mmcamcorder_gst_handle_core_error(handle, error->code, message);
3485 } else if (error->domain == GST_LIBRARY_ERROR) {
3486 msg.param.code = __mmcamcorder_gst_handle_library_error(handle, error->code, message);
3487 } else if (error->domain == GST_RESOURCE_ERROR) {
3488 msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);
3489 } else if (error->domain == GST_STREAM_ERROR) {
3490 msg.param.code = __mmcamcorder_gst_handle_stream_error(handle, error->code, message);
3492 MMCAM_LOG_WARNING("This error domain is not defined.");
3494 /* we treat system error as an internal error */
3495 msg.param.code = MM_ERROR_CAMCORDER_INTERNAL;
3499 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3500 MMCAM_LOG_ERROR("-Msg src : [%s] Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3501 msg_src_element, g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3503 MMCAM_LOG_ERROR("Domain : [%s] Error : [%s] Code : [%d] is tranlated to error code : [0x%x]",
3504 g_quark_to_string(error->domain), error->message, error->code, msg.param.code);
3507 #ifdef _MMCAMCORDER_SKIP_GST_FLOW_ERROR
3508 /* Check whether send this error to application */
3509 if (msg.param.code == MM_ERROR_CAMCORDER_GST_FLOW_ERROR) {
3510 MMCAM_LOG_INFO("We got the error. But skip it.");
3513 #endif /* _MMCAMCORDER_SKIP_GST_FLOW_ERROR */
3515 /* post error to application except RESTRICTED case */
3516 if (msg.param.code != MM_ERROR_POLICY_RESTRICTED) {
3517 hcamcorder->error_occurs = TRUE;
3518 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3519 _mmcamcorder_send_message(handle, &msg);
3526 static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message)
3528 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3529 _MMCamcorderSubContext *sc = NULL;
3530 GstElement *element = NULL;
3534 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3536 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3537 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3539 /* Specific plugin - video encoder plugin */
3540 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3542 if (GST_ELEMENT_CAST(message->src) == element) {
3543 if (code == GST_CORE_ERROR_NEGOTIATION)
3544 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3546 return MM_ERROR_CAMCORDER_ENCODER;
3551 case GST_CORE_ERROR_STATE_CHANGE:
3552 return MM_ERROR_CAMCORDER_GST_STATECHANGE;
3553 case GST_CORE_ERROR_NEGOTIATION:
3554 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3555 case GST_CORE_ERROR_MISSING_PLUGIN:
3556 case GST_CORE_ERROR_SEEK:
3557 case GST_CORE_ERROR_NOT_IMPLEMENTED:
3558 case GST_CORE_ERROR_FAILED:
3559 case GST_CORE_ERROR_TOO_LAZY:
3560 case GST_CORE_ERROR_PAD:
3561 case GST_CORE_ERROR_THREAD:
3562 case GST_CORE_ERROR_EVENT:
3563 case GST_CORE_ERROR_CAPS:
3564 case GST_CORE_ERROR_TAG:
3565 case GST_CORE_ERROR_CLOCK:
3566 case GST_CORE_ERROR_DISABLED:
3568 return MM_ERROR_CAMCORDER_GST_CORE;
3573 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message)
3575 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3576 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3580 /* Specific plugin - NONE */
3584 case GST_LIBRARY_ERROR_FAILED:
3585 case GST_LIBRARY_ERROR_TOO_LAZY:
3586 case GST_LIBRARY_ERROR_INIT:
3587 case GST_LIBRARY_ERROR_SHUTDOWN:
3588 case GST_LIBRARY_ERROR_SETTINGS:
3589 case GST_LIBRARY_ERROR_ENCODE:
3591 MMCAM_LOG_ERROR("Library error(%d)", code);
3592 return MM_ERROR_CAMCORDER_GST_LIBRARY;
3597 static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message)
3599 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3600 _MMCamcorderSubContext *sc = NULL;
3601 GstElement *element = NULL;
3603 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3605 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3606 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3610 /* Specific plugin */
3612 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst);
3613 if (GST_ELEMENT_CAST(message->src) == element) {
3614 if (code == GST_RESOURCE_ERROR_WRITE) {
3615 MMCAM_LOG_ERROR("Display device [Off]");
3616 return MM_ERROR_CAMCORDER_DISPLAY_DEVICE_OFF;
3618 MMCAM_LOG_ERROR("Display device [General(%d)]", code);
3623 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst);
3624 if (GST_ELEMENT_CAST(message->src) == element) {
3625 if (code == GST_RESOURCE_ERROR_FAILED) {
3626 int ret = MM_ERROR_NONE;
3627 int current_state = MM_CAMCORDER_STATE_NONE;
3629 MMCAM_LOG_ERROR("DPM mic DISALLOWED - current state %d", current_state);
3631 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3633 current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
3634 if (current_state >= MM_CAMCORDER_STATE_RECORDING) {
3635 /* set value to inform a status is changed by DPM */
3636 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_DPM;
3638 ret = _mmcamcorder_commit((MMHandleType)hcamcorder);
3639 MMCAM_LOG_INFO("commit result : 0x%x", ret);
3641 if (ret != MM_ERROR_NONE) {
3642 MMCAM_LOG_ERROR("commit failed, cancel it");
3643 ret = _mmcamcorder_cancel((MMHandleType)hcamcorder);
3648 hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
3650 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3652 _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
3654 return MM_ERROR_POLICY_RESTRICTED;
3659 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3660 if (GST_ELEMENT_CAST(message->src) == element) {
3661 if (code == GST_RESOURCE_ERROR_FAILED) {
3662 MMCAM_LOG_ERROR("Encoder [Resource error]");
3663 return MM_ERROR_CAMCORDER_ENCODER_BUFFER;
3665 MMCAM_LOG_ERROR("Encoder [General(%d)]", code);
3666 return MM_ERROR_CAMCORDER_ENCODER;
3672 case GST_RESOURCE_ERROR_WRITE:
3673 MMCAM_LOG_ERROR("File write error");
3674 return MM_ERROR_FILE_WRITE;
3675 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3676 MMCAM_LOG_ERROR("No left space");
3677 return MM_MESSAGE_CAMCORDER_NO_FREE_SPACE;
3678 case GST_RESOURCE_ERROR_OPEN_WRITE:
3679 MMCAM_LOG_ERROR("Out of storage");
3680 return MM_ERROR_OUT_OF_STORAGE;
3681 case GST_RESOURCE_ERROR_SEEK:
3682 MMCAM_LOG_ERROR("File read(seek)");
3683 return MM_ERROR_FILE_READ;
3684 case GST_RESOURCE_ERROR_NOT_FOUND:
3685 case GST_RESOURCE_ERROR_FAILED:
3686 case GST_RESOURCE_ERROR_TOO_LAZY:
3687 case GST_RESOURCE_ERROR_BUSY:
3688 case GST_RESOURCE_ERROR_OPEN_READ:
3689 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3690 case GST_RESOURCE_ERROR_CLOSE:
3691 case GST_RESOURCE_ERROR_READ:
3692 case GST_RESOURCE_ERROR_SYNC:
3693 case GST_RESOURCE_ERROR_SETTINGS:
3695 MMCAM_LOG_ERROR("Resource error(%d)", code);
3696 return MM_ERROR_CAMCORDER_GST_RESOURCE;
3701 static gint __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message)
3703 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3704 _MMCamcorderSubContext *sc = NULL;
3705 GstElement *element = NULL;
3707 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3709 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3710 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3714 /* Specific plugin */
3716 element = GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst);
3717 if (GST_ELEMENT_CAST(message->src) == element) {
3719 case GST_STREAM_ERROR_WRONG_TYPE:
3720 MMCAM_LOG_ERROR("Video encoder [wrong stream type]");
3721 return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
3722 case GST_STREAM_ERROR_ENCODE:
3723 MMCAM_LOG_ERROR("Video encoder [encode error]");
3724 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3725 case GST_STREAM_ERROR_FAILED:
3726 MMCAM_LOG_ERROR("Video encoder [stream failed]");
3727 return MM_ERROR_CAMCORDER_ENCODER_WORKING;
3729 MMCAM_LOG_ERROR("Video encoder [General(%d)]", code);
3730 return MM_ERROR_CAMCORDER_ENCODER;
3734 /* General plugin */
3736 case GST_STREAM_ERROR_FORMAT:
3737 MMCAM_LOG_ERROR("General [negotiation error(%d)]", code);
3738 return MM_ERROR_CAMCORDER_GST_NEGOTIATION;
3739 case GST_STREAM_ERROR_FAILED:
3740 MMCAM_LOG_ERROR("General [flow error(%d)]", code);
3741 return MM_ERROR_CAMCORDER_GST_FLOW_ERROR;
3742 case GST_STREAM_ERROR_TYPE_NOT_FOUND:
3743 case GST_STREAM_ERROR_DECODE:
3744 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
3745 case GST_STREAM_ERROR_NOT_IMPLEMENTED:
3746 case GST_STREAM_ERROR_TOO_LAZY:
3747 case GST_STREAM_ERROR_ENCODE:
3748 case GST_STREAM_ERROR_DEMUX:
3749 case GST_STREAM_ERROR_MUX:
3750 case GST_STREAM_ERROR_DECRYPT:
3751 case GST_STREAM_ERROR_DECRYPT_NOKEY:
3752 case GST_STREAM_ERROR_WRONG_TYPE:
3754 MMCAM_LOG_ERROR("General [error(%d)]", code);
3755 return MM_ERROR_CAMCORDER_GST_STREAM;
3760 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error)
3762 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3763 gchar *debug = NULL;
3766 mmf_return_val_if_fail(hcamcorder, FALSE);
3767 mmf_return_val_if_fail(error, FALSE);
3771 gst_message_parse_warning(message, &err, &debug);
3773 if (error->domain == GST_CORE_ERROR) {
3774 MMCAM_LOG_WARNING("GST warning: GST_CORE domain");
3775 } else if (error->domain == GST_LIBRARY_ERROR) {
3776 MMCAM_LOG_WARNING("GST warning: GST_LIBRARY domain");
3777 } else if (error->domain == GST_RESOURCE_ERROR) {
3778 MMCAM_LOG_WARNING("GST warning: GST_RESOURCE domain");
3779 __mmcamcorder_gst_handle_resource_warning(handle, message, error);
3780 } else if (error->domain == GST_STREAM_ERROR) {
3781 MMCAM_LOG_WARNING("GST warning: GST_STREAM domain");
3783 MMCAM_LOG_WARNING("This error domain(%d) is not defined.", error->domain);
3790 if (debug != NULL) {
3791 MMCAM_LOG_ERROR("Debug: %s", debug);
3800 static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error)
3802 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3803 _MMCamcorderSubContext *sc = NULL;
3804 GstElement *element = NULL;
3805 gchar *msg_src_element;
3807 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3809 sc = MMF_CAMCORDER_SUBCONTEXT(handle);
3810 mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
3814 /* Special message handling */
3816 element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
3817 if (GST_ELEMENT_CAST(message->src) == element) {
3818 if (error->code == GST_RESOURCE_ERROR_FAILED) {
3819 msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));
3820 MMCAM_LOG_WARNING("-Msg src:[%s] Domain:[%s] Error:[%s]",
3821 msg_src_element, g_quark_to_string(error->domain), error->message);
3822 return MM_ERROR_NONE;
3826 /* General plugin */
3827 switch (error->code) {
3828 case GST_RESOURCE_ERROR_WRITE:
3829 case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
3830 case GST_RESOURCE_ERROR_SEEK:
3831 case GST_RESOURCE_ERROR_NOT_FOUND:
3832 case GST_RESOURCE_ERROR_FAILED:
3833 case GST_RESOURCE_ERROR_TOO_LAZY:
3834 case GST_RESOURCE_ERROR_BUSY:
3835 case GST_RESOURCE_ERROR_OPEN_READ:
3836 case GST_RESOURCE_ERROR_OPEN_WRITE:
3837 case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
3838 case GST_RESOURCE_ERROR_CLOSE:
3839 case GST_RESOURCE_ERROR_READ:
3840 case GST_RESOURCE_ERROR_SYNC:
3841 case GST_RESOURCE_ERROR_SETTINGS:
3843 MMCAM_LOG_WARNING("General GST warning(%d)", error->code);
3847 return MM_ERROR_NONE;
3851 void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
3852 const char *interface_name, const char *signal_name, int value)
3854 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3856 mmf_return_if_fail(hcamcorder && object_name && interface_name && signal_name);
3858 MMCAM_LOG_INFO("object %s, interface %s, signal %s, value %d",
3859 object_name, interface_name, signal_name, value);
3861 _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, object_name, interface_name, signal_name, value);
3867 #ifdef _MMCAMCORDER_MM_RM_SUPPORT
3868 static int __mmcamcorder_resource_release_cb(mm_resource_manager_h rm,
3869 mm_resource_manager_res_h res, void *user_data)
3871 mmf_camcorder_t *hcamcorder = (mmf_camcorder_t *) user_data;
3873 mmf_return_val_if_fail(hcamcorder, FALSE);
3875 MMCAM_LOG_WARNING("enter");
3877 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3879 /* set flag for resource release callback */
3880 hcamcorder->is_release_cb_calling = TRUE;
3882 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3884 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3886 if (res == hcamcorder->video_encoder_resource) {
3887 /* Stop video recording */
3888 if (_mmcamcorder_commit((MMHandleType)hcamcorder) != MM_ERROR_NONE) {
3889 MMCAM_LOG_ERROR("commit failed, cancel it");
3890 _mmcamcorder_cancel((MMHandleType)hcamcorder);
3894 __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_RM);
3897 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3899 _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
3901 if (res == hcamcorder->camera_resource)
3902 hcamcorder->camera_resource = NULL;
3903 else if (res == hcamcorder->video_overlay_resource)
3904 hcamcorder->video_overlay_resource = NULL;
3905 else if (res == hcamcorder->video_encoder_resource)
3906 hcamcorder->video_encoder_resource = NULL;
3908 /* restore flag for resource release callback */
3909 hcamcorder->is_release_cb_calling = FALSE;
3911 _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
3913 MMCAM_LOG_WARNING("leave");
3917 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
3919 int _mmcamcorder_manage_external_storage_state(MMHandleType handle, int storage_state)
3921 int ret = MM_ERROR_NONE;
3922 int current_state = MM_CAMCORDER_STATE_NONE;
3923 mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
3924 _MMCamcorderMsgItem msg;
3926 mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
3928 MMCAM_LOG_WARNING("storage state %d", storage_state);
3930 /* check storage state */
3931 if (storage_state != STORAGE_STATE_UNMOUNTABLE &&
3932 storage_state != STORAGE_STATE_REMOVED) {
3933 MMCAM_LOG_WARNING("nothing to do");
3934 return MM_ERROR_NONE;
3937 _MMCAMCORDER_LOCK_INTERRUPT(hcamcorder);
3939 /* check recording state */
3940 current_state = _mmcamcorder_get_state(handle);
3942 MMCAM_LOG_WARNING("current_state %d", current_state);
3944 if (current_state < MM_CAMCORDER_STATE_RECORDING) {
3945 MMCAM_LOG_WARNING("no recording now");
3949 /* check storage type */
3950 if (hcamcorder->storage_info.type != STORAGE_TYPE_EXTERNAL) {
3951 MMCAM_LOG_WARNING("external storage is not used");
3955 /* cancel recording */
3956 ret = _mmcamcorder_cancel(handle);
3958 /* send error message */
3959 msg.id = MM_MESSAGE_CAMCORDER_ERROR;
3960 msg.param.code = MM_ERROR_OUT_OF_STORAGE;
3962 _mmcamcorder_send_message(handle, &msg);
3965 _MMCAMCORDER_UNLOCK_INTERRUPT(hcamcorder);
3967 MMCAM_LOG_WARNING("done - ret 0x%x", ret);