Add mm_handle field to use it in gdbus sound eos callback
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index c6f48b1..b117f6e 100644 (file)
@@ -39,8 +39,6 @@
 #include <asm/types.h>
 
 #include <system_info.h>
-#include <mm_session.h>
-#include <mm_session_private.h>
 
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
 #include <murphy/common/glib-glue.h>
@@ -161,7 +159,18 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        /* init for sound thread */
        g_mutex_init(&hcamcorder->task_thread_lock);
        g_cond_init(&hcamcorder->task_thread_cond);
-       hcamcorder->task_thread_state = _MMCAMCORDER_SOUND_STATE_NONE;
+       hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_NONE;
+
+       if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
+               /* init for gdbus */
+               hcamcorder->gdbus_info_sound.mm_handle = hcamcorder;
+               g_mutex_init(&hcamcorder->gdbus_info_sound.sync_mutex);
+               g_cond_init(&hcamcorder->gdbus_info_sound.sync_cond);
+
+               hcamcorder->gdbus_info_solo_sound.mm_handle = hcamcorder;
+               g_mutex_init(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
+               g_cond_init(&hcamcorder->gdbus_info_solo_sound.sync_cond);
+       }
 
        /* create task thread */
        hcamcorder->task_thread = g_thread_try_new("MMCAM_TASK_THREAD",
@@ -183,31 +192,6 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        hcamcorder->device_type = info->videodev_type;
        _mmcam_dbg_warn("Device Type : %d", hcamcorder->device_type);
 
-       if (MM_ERROR_NONE == _mm_session_util_read_information(-1, &hcamcorder->session_type, &hcamcorder->session_flags)) {
-               _mmcam_dbg_log("use sound focus function.");
-               hcamcorder->sound_focus_register = TRUE;
-
-               if (MM_ERROR_NONE != mm_sound_focus_get_id(&hcamcorder->sound_focus_id)) {
-                       _mmcam_dbg_err("mm_sound_focus_get_uniq failed");
-                       ret = MM_ERROR_POLICY_BLOCKED;
-                       goto _ERR_DEFAULT_VALUE_INIT;
-               }
-
-               ret = mm_sound_register_focus_for_session(hcamcorder->sound_focus_id,
-                       getpid(), "media", _mmcamcorder_sound_focus_cb, hcamcorder);
-               if (ret != MM_ERROR_NONE) {
-                       _mmcam_dbg_err("mm_sound_register_focus failed");
-                       ret = MM_ERROR_POLICY_BLOCKED;
-                       goto _ERR_DEFAULT_VALUE_INIT;
-               }
-
-               _mmcam_dbg_log("mm_sound_register_focus done - id %d, session type %d, flags 0x%x",
-                       hcamcorder->sound_focus_id, hcamcorder->session_type, hcamcorder->session_flags);
-       } else {
-               _mmcam_dbg_log("_mm_session_util_read_information failed. skip sound focus function.");
-               hcamcorder->sound_focus_register = FALSE;
-       }
-
        /* Get Camera Configure information from Camcorder INI file */
        ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder, CONFIGURE_TYPE_MAIN, CONFIGURE_MAIN_FILE, &hcamcorder->conf_main);
        if (ret != MM_ERROR_NONE) {
@@ -545,18 +529,6 @@ _ERR_DEFAULT_VALUE_INIT:
        _mmcamcorder_resource_manager_deinit(&hcamcorder->resource_manager);
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
-       /* unregister sound focus */
-       if (hcamcorder->sound_focus_register && hcamcorder->sound_focus_id > 0) {
-               if (MM_ERROR_NONE != mm_sound_unregister_focus(hcamcorder->sound_focus_id)) {
-                       _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed", hcamcorder->sound_focus_id);
-               } else {
-                       _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done", hcamcorder->sound_focus_id);
-               }
-       } else {
-               _mmcam_dbg_warn("no need to unregister sound focus[%d, id %d]",
-                       hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
-       }
-
        /* release DPM related handle */
        if (hcamcorder->dpm_handle) {
                _mmcam_dbg_log("release DPM handle %p, camera changed cb id %d",
@@ -602,6 +574,13 @@ _ERR_DEFAULT_VALUE_INIT:
        g_cond_clear(&hcamcorder->snd_info.open_cond);
        g_mutex_clear(&hcamcorder->restart_preview_lock);
 
+       if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
+               g_mutex_clear(&hcamcorder->gdbus_info_sound.sync_mutex);
+               g_cond_clear(&hcamcorder->gdbus_info_sound.sync_cond);
+               g_mutex_clear(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
+               g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
+       }
+
        if (hcamcorder->conf_ctrl)
                _mmcamcorder_conf_release_info((MMHandleType)hcamcorder, &hcamcorder->conf_ctrl);
 
@@ -642,7 +621,6 @@ int _mmcamcorder_destroy(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM = MM_CAMCORDER_STATE_NULL;
 #ifdef _MMCAMCORDER_RM_SUPPORT
        int iret = RM_OK;
 #endif /* _MMCAMCORDER_RM_SUPPORT */
@@ -666,7 +644,7 @@ int _mmcamcorder_destroy(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM) {
+       if (state != MM_CAMCORDER_STATE_NULL) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -744,19 +722,29 @@ int _mmcamcorder_destroy(MMHandleType handle)
        /* Remove messages which are not called yet */
        _mmcamcorder_remove_message_all(handle);
 
-       /* unregister sound focus */
-       if (hcamcorder->sound_focus_register && hcamcorder->sound_focus_id > 0) {
-               if (mm_sound_unregister_focus(hcamcorder->sound_focus_id) != MM_ERROR_NONE) {
-                       _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed",
-                               hcamcorder->sound_focus_id);
-               } else {
-                       _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done",
-                       hcamcorder->sound_focus_id);
-               }
-       } else {
-               _mmcam_dbg_log("no need to unregister sound focus.[%d, id %d]",
-                       hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
+       /* unset remained watch cb */
+       if (hcamcorder->sound_focus_watch_id > 0) {
+               mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+               _mmcam_dbg_warn("unset sound focus watch cb [id %d] done", hcamcorder->sound_focus_watch_id);
+               hcamcorder->sound_focus_watch_id = 0;
        }
+
+       /* unregister sound focus and unsubscribe sound signal */
+       _mmcam_dbg_log("sound focus id %d, sound signal subscribe id %u",
+               hcamcorder->sound_focus_id, hcamcorder->sound_focus_subscribe_id);
+
+       if (hcamcorder->sound_focus_id > 0) {
+               mm_sound_unregister_focus(hcamcorder->sound_focus_id);
+               _mmcam_dbg_log("unregister sound focus done");
+               hcamcorder->sound_focus_id = 0;
+       }
+
+       if (hcamcorder->sound_focus_subscribe_id > 0) {
+               mm_sound_unsubscribe_signal(hcamcorder->sound_focus_subscribe_id);
+               _mmcam_dbg_log("unsubscribe sound signal done");
+               hcamcorder->sound_focus_subscribe_id = 0;
+       }
+
 #ifdef _MMCAMCORDER_RM_SUPPORT
        if (hcamcorder->rm_handle != 0) {
                iret = rm_unregister(hcamcorder->rm_handle);
@@ -825,6 +813,13 @@ int _mmcamcorder_destroy(MMHandleType handle)
        g_mutex_clear(&hcamcorder->task_thread_lock);
        g_cond_clear(&hcamcorder->task_thread_cond);
 
+       if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
+               g_mutex_clear(&hcamcorder->gdbus_info_sound.sync_mutex);
+               g_cond_clear(&hcamcorder->gdbus_info_sound.sync_cond);
+               g_mutex_clear(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
+               g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
+       }
+
        /* Release handle */
        memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
        free(hcamcorder);
@@ -849,17 +844,22 @@ int _mmcamcorder_realize(MMHandleType handle)
        int ret = MM_ERROR_NONE;
        int ret_sound = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM = MM_CAMCORDER_STATE_NULL;
-       int state_TO = MM_CAMCORDER_STATE_READY;
        int display_surface_type = MM_DISPLAY_SURFACE_OVERLAY;
        int pid_for_sound_focus = 0;
        double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE;
        char *videosink_element_type = NULL;
        const char *videosink_name = NULL;
        char *socket_path = NULL;
-       int socket_path_len;
+       int socket_path_len = 0;
+       int conn_size = 0;
 #ifdef _MMCAMCORDER_RM_SUPPORT
-               int iret = RM_OK;
+       int iret = RM_OK;
+       int preview_format = MM_PIXEL_FORMAT_NV12;
+       int qret = RM_OK;
+       int qret_avail = 0; /* 0: not available, 1: available */
+       rm_consumer_info rci;
+       int app_pid = 0;
+       int resource_count = 0;
 #endif /* _MMCAMCORDER_RM_SUPPORT */
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
@@ -879,18 +879,26 @@ int _mmcamcorder_realize(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM) {
+       if (state != MM_CAMCORDER_STATE_NULL) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
        }
 
+       /* Get profile mode and gdbus connection */
        mm_camcorder_get_attributes(handle, NULL,
                MMCAM_MODE, &hcamcorder->type,
+               MMCAM_GDBUS_CONNECTION, &hcamcorder->gdbus_conn, &conn_size,
                NULL);
 
-       /* Get profile mode */
-       _mmcam_dbg_log("Profile mode [%d]", hcamcorder->type);
+       if (!hcamcorder->gdbus_conn) {
+               _mmcam_dbg_err("gdbus connection NULL");
+               ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
+               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+       }
+
+       _mmcam_dbg_log("Profile mode [%d], gdbus connection [%p]",
+               hcamcorder->type, hcamcorder->gdbus_conn);
 
        mm_camcorder_get_attributes(handle, NULL,
                MMCAM_DISPLAY_SURFACE, &display_surface_type,
@@ -899,29 +907,15 @@ int _mmcamcorder_realize(MMHandleType handle)
 
        /* sound focus */
        if (hcamcorder->sound_focus_register) {
-               mm_camcorder_get_attributes(handle, NULL,
-                       MMCAM_PID_FOR_SOUND_FOCUS, &pid_for_sound_focus,
-                       NULL);
-
-               if (pid_for_sound_focus == 0) {
-                       pid_for_sound_focus = getpid();
-                       _mmcam_dbg_warn("pid for sound focus is not set, use my pid %d", pid_for_sound_focus);
-               }
-
                /* acquire sound focus or set sound focus watch callback */
-               hcamcorder->acquired_focus = 0;
-               hcamcorder->sound_focus_watch_id = 0;
-
-               /* check session flags */
                if (hcamcorder->session_flags & MM_SESSION_OPTION_PAUSE_OTHERS) {
                        /* acquire sound focus */
                        _mmcam_dbg_log("PAUSE_OTHERS - acquire sound focus");
 
-                       ret_sound = mm_sound_acquire_focus(0, FOCUS_FOR_BOTH, NULL);
+                       ret_sound = mm_sound_acquire_focus(hcamcorder->sound_focus_id, FOCUS_FOR_BOTH, NULL);
                        if (ret_sound != MM_ERROR_NONE) {
                                _mmcam_dbg_err("mm_sound_acquire_focus failed [0x%x]", ret_sound);
 
-                               /* TODO: MM_ERROR_POLICY_BLOCKED_BY_CALL, MM_ERROR_POLICY_BLOCKED_BY_ALARM*/
                                ret = MM_ERROR_POLICY_BLOCKED;
                                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
                        }
@@ -931,7 +925,23 @@ int _mmcamcorder_realize(MMHandleType handle)
                        /* do nothing */
                        _mmcam_dbg_log("SESSION_UNINTERRUPTIBLE - do nothing for sound focus");
                } else {
+                       /* unset remained watch cb */
+                       if (hcamcorder->sound_focus_watch_id > 0) {
+                               mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+                               _mmcam_dbg_warn("unset sound focus watch cb [id %d] done", hcamcorder->sound_focus_watch_id);
+                               hcamcorder->sound_focus_watch_id = 0;
+                       }
+
                        /* set sound focus watch callback */
+                       mm_camcorder_get_attributes(handle, NULL,
+                               MMCAM_PID_FOR_SOUND_FOCUS, &pid_for_sound_focus,
+                               NULL);
+
+                       if (pid_for_sound_focus == 0) {
+                               pid_for_sound_focus = getpid();
+                               _mmcam_dbg_warn("pid for sound focus is not set, use my pid %d", pid_for_sound_focus);
+                       }
+
                        _mmcam_dbg_log("ETC - set sound focus watch callback - pid %d", pid_for_sound_focus);
 
                        ret_sound = mm_sound_set_focus_watch_callback_for_session(pid_for_sound_focus,
@@ -942,7 +952,6 @@ int _mmcamcorder_realize(MMHandleType handle)
                        if (ret_sound != MM_ERROR_NONE) {
                                _mmcam_dbg_err("mm_sound_set_focus_watch_callback failed [0x%x]", ret_sound);
 
-                               /* TODO: MM_ERROR_POLICY_BLOCKED_BY_CALL, MM_ERROR_POLICY_BLOCKED_BY_ALARM*/
                                ret = MM_ERROR_POLICY_BLOCKED;
                                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
                        }
@@ -953,83 +962,11 @@ int _mmcamcorder_realize(MMHandleType handle)
                _mmcam_dbg_log("no need to register sound focus");
        }
 
-#ifdef _MMCAMCORDER_RM_SUPPORT
-       int preview_format = MM_PIXEL_FORMAT_NV12;
-       int qret = RM_OK;
-       int qret_avail = RM_OK;
-       rm_consumer_info rci;
-       int app_pid = 0;
-       int resource_count = 0;
-
-       mm_camcorder_get_attributes(handle, NULL,
-               MMCAM_PID_FOR_SOUND_FOCUS, &app_pid,
-               NULL);
-       rci.app_pid = app_pid;
-       aul_app_get_appid_bypid(rci.app_pid, rci.app_id, sizeof(rci.app_id));
-
-       /* RM register */
-       if (hcamcorder->rm_handle == 0) {
-               iret = rm_register((rm_resource_cb)_mmcamcorder_rm_callback, (void*)hcamcorder,
-                       &(hcamcorder->rm_handle), &rci);
-               if (iret != RM_OK) {
-                       _mmcam_dbg_err("rm_register fail");
-                       ret = MM_ERROR_POLICY_BLOCKED;
-                       goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
-               }
-       }
-
-       mm_camcorder_get_attributes(handle, NULL,
-               MMCAM_CAMERA_FORMAT, &preview_format,
-               NULL);
-
-       if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO && preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-               resource_count = 0;
-               memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
-               memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
-               hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
-               hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER;
-               _mmcam_dbg_log("request video decoder resource - device category 0x%x", hcamcorder->request_resources.category_id[resource_count]);
-
-               resource_count++;
-               hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
-               hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER;
-               hcamcorder->request_resources.request_num = resource_count + 1;
-               _mmcam_dbg_log("request scaler resource - device category 0x%x", hcamcorder->request_resources.category_id[resource_count]);
-
-               qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail);
-
-               if (qret != RM_OK || qret_avail != RM_OK) {
-                       _mmcam_dbg_log("Resource manager main device request fail");
-
-                       resource_count = 0;
-                       hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER_SUB;
-                       _mmcam_dbg_log("request video decoder resource - device category 0x%x", hcamcorder->request_resources.category_id[resource_count]);
-
-                       resource_count++;
-                       hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER_SUB;
-                       _mmcam_dbg_log("request scaler resource - device category 0x%x", hcamcorder->request_resources.category_id[resource_count]);
-               }
-
-               resource_count++;
-               hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
-               hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_CAMERA;
-               hcamcorder->request_resources.request_num = resource_count + 1;
-               _mmcam_dbg_log("request camera resource - device category 0x%x", hcamcorder->request_resources.category_id[resource_count]);
-
-               iret = rm_allocate_resources(hcamcorder->rm_handle, &(hcamcorder->request_resources), &hcamcorder->returned_devices);
-               if (iret != RM_OK) {
-                       _mmcam_dbg_err("Resource allocation request failed");
-                       ret = MM_ERROR_POLICY_BLOCKED;
-                       goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
-           }
-       }
-#endif /* _MMCAMCORDER_RM_SUPPORT */
-
        /* alloc sub context */
        hcamcorder->sub_context = _mmcamcorder_alloc_subcontext(hcamcorder->type);
        if (!hcamcorder->sub_context) {
                ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
-               goto _ERR_CAMCORDER_CMD;
+               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
        }
 
        /* Set basic configure information */
@@ -1048,6 +985,7 @@ int _mmcamcorder_realize(MMHandleType handle)
                        CONFIGURE_CATEGORY_MAIN_RECORD,
                        "SupportDualStream",
                        &(hcamcorder->sub_context->info_video->support_dual_stream));
+
                _mmcam_dbg_warn("SupportDualStream [%d]", hcamcorder->sub_context->info_video->support_dual_stream);
        }
 
@@ -1131,6 +1069,7 @@ int _mmcamcorder_realize(MMHandleType handle)
                } else {
                        _mmcam_dbg_warn("NULL dpm_handle");
                }
+
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
                ret = _mmcamcorder_resource_create_resource_set(&hcamcorder->resource_manager);
                if (ret != MM_ERROR_NONE) {
@@ -1148,10 +1087,6 @@ int _mmcamcorder_realize(MMHandleType handle)
                }
 
                /* prepare resource manager for "video_overlay only if display surface is X" */
-               mm_camcorder_get_attributes(handle, NULL,
-                       MMCAM_DISPLAY_SURFACE, &display_surface_type,
-                       NULL);
-
                if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
                        ret = _mmcamcorder_resource_manager_prepare(&hcamcorder->resource_manager, MM_CAMCORDER_RESOURCE_TYPE_VIDEO_OVERLAY);
                        if (ret != MM_ERROR_NONE) {
@@ -1194,6 +1129,86 @@ int _mmcamcorder_realize(MMHandleType handle)
 
                _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
+
+#ifdef _MMCAMCORDER_RM_SUPPORT
+               mm_camcorder_get_attributes(handle, NULL,
+                       MMCAM_PID_FOR_SOUND_FOCUS, &app_pid,
+                       NULL);
+               rci.app_pid = app_pid;
+               aul_app_get_appid_bypid(rci.app_pid, rci.app_id, sizeof(rci.app_id));
+
+               /* RM register */
+               if (hcamcorder->rm_handle == 0) {
+                       iret = rm_register((rm_resource_cb)_mmcamcorder_rm_callback, (void*)hcamcorder, &(hcamcorder->rm_handle), &rci);
+                       if (iret != RM_OK) {
+                               _mmcam_dbg_err("rm_register fail");
+                               ret = MM_ERROR_POLICY_BLOCKED;
+                               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+                       }
+               }
+
+               mm_camcorder_get_attributes(handle, NULL,
+                       MMCAM_CAMERA_FORMAT, &preview_format,
+                       NULL);
+
+               resource_count = 0;
+               memset(&hcamcorder->request_resources, 0x0, sizeof(rm_category_request_s));
+               memset(&hcamcorder->returned_devices, 0x0, sizeof(rm_device_return_s));
+
+               if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
+                       hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
+                       hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER;
+
+                       _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER);
+
+                       resource_count++;
+               }
+
+               if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
+                       hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
+                       hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER;
+
+                       _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER);
+
+                       resource_count++;
+               }
+
+               hcamcorder->request_resources.request_num = resource_count;
+
+               if (resource_count > 0) {
+                       qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail);
+                       if (qret != RM_OK || qret_avail != 1) {
+                               _mmcam_dbg_log("rm query failed. retry with sub devices");
+
+                               resource_count = 0;
+
+                               if (preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
+                                       hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_VIDEO_DECODER_SUB;
+                                       _mmcam_dbg_log("request dec rsc - category 0x%x", RM_CATEGORY_VIDEO_DECODER_SUB);
+                                       resource_count++;
+                               }
+
+                               if (display_surface_type == MM_DISPLAY_SURFACE_OVERLAY) {
+                                       hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_SCALER_SUB;
+                                       _mmcam_dbg_log("request scaler rsc - category 0x%x", RM_CATEGORY_SCALER_SUB);
+                                       resource_count++;
+                               }
+                       }
+               }
+
+               hcamcorder->request_resources.state[resource_count] = RM_STATE_EXCLUSIVE;
+               hcamcorder->request_resources.category_id[resource_count] = RM_CATEGORY_CAMERA;
+
+               hcamcorder->request_resources.request_num = resource_count + 1;
+               _mmcam_dbg_log("request camera rsc - category 0x%x", RM_CATEGORY_CAMERA);
+
+               iret = rm_allocate_resources(hcamcorder->rm_handle, &(hcamcorder->request_resources), &hcamcorder->returned_devices);
+               if (iret != RM_OK) {
+                       _mmcam_dbg_err("Resource allocation request failed");
+                       ret = MM_ERROR_POLICY_BLOCKED;
+                       goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+               }
+#endif /* _MMCAMCORDER_RM_SUPPORT */
        }
 
        /* create pipeline */
@@ -1225,7 +1240,7 @@ int _mmcamcorder_realize(MMHandleType handle)
                goto _ERR_CAMCORDER_CMD;
        }
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
@@ -1243,27 +1258,6 @@ _ERR_CAMCORDER_CMD:
                }
        }
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
-
-_ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
-       _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
-
-       if (hcamcorder->sound_focus_register) {
-               if (hcamcorder->sound_focus_watch_id > 0) {
-                       if (mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id) != MM_ERROR_NONE) {
-                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback[id %d] failed", hcamcorder->sound_focus_watch_id);
-                       } else {
-                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback[id %d] done", hcamcorder->sound_focus_watch_id);
-                       }
-               }
-
-               if (hcamcorder->acquired_focus > 0) {
-                               if (mm_sound_release_focus(0, hcamcorder->acquired_focus, NULL) != MM_ERROR_NONE) {
-                                       _mmcam_dbg_err("mm_sound_release_focus[focus %d] failed", hcamcorder->acquired_focus);
-                               } else {
-                                       _mmcam_dbg_err("mm_sound_release_focus[focus %d] done", hcamcorder->acquired_focus);
-                               }
-               }
-       }
 #ifdef _MMCAMCORDER_RM_SUPPORT
        if (hcamcorder->rm_handle) {
                if (hcamcorder->returned_devices.allocated_num > 0) {
@@ -1278,6 +1272,7 @@ _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
                        if (iret != RM_OK)
                                _mmcam_dbg_err("Resource deallocation request failed ");
                }
+
                /* unregister RM */
                int ires = rm_unregister(hcamcorder->rm_handle);
                if (ires != RM_OK)
@@ -1286,6 +1281,21 @@ _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
        }
 #endif /* _MMCAMCORDER_RM_SUPPORT*/
 
+_ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
+       _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
+
+       if (hcamcorder->sound_focus_watch_id > 0) {
+               mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+               _mmcam_dbg_warn("unset sound focus watch cb [id %d] done", hcamcorder->sound_focus_watch_id);
+               hcamcorder->sound_focus_watch_id = 0;
+       }
+
+       if (hcamcorder->acquired_focus > 0) {
+               mm_sound_release_focus(hcamcorder->sound_focus_id, hcamcorder->acquired_focus, NULL);
+               _mmcam_dbg_warn("release sound focus [focus %d] done", hcamcorder->acquired_focus);
+               hcamcorder->acquired_focus = 0;
+       }
+
 _ERR_CAMCORDER_CMD_PRECON:
        _mmcam_dbg_err("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
 
@@ -1297,8 +1307,6 @@ int _mmcamcorder_unrealize(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM = MM_CAMCORDER_STATE_READY;
-       int state_TO = MM_CAMCORDER_STATE_NULL;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1317,7 +1325,7 @@ int _mmcamcorder_unrealize(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM) {
+       if (state != MM_CAMCORDER_STATE_READY) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1392,41 +1400,31 @@ int _mmcamcorder_unrealize(MMHandleType handle)
                hcamcorder->sound_focus_register, hcamcorder->session_flags, hcamcorder->state_change_by_system);
 
        /* release sound focus or unset sound focus watch callback */
-       if (hcamcorder->sound_focus_register) {
-               int ret_sound = MM_ERROR_NONE;
-
-               _mmcam_dbg_log("state_change_by_system %d, session flag 0x%x, acquired_focus %d, sound_focus_id %d, sound_focus_watch_id %d",
-                       hcamcorder->state_change_by_system, hcamcorder->session_flags, hcamcorder->acquired_focus,
-                       hcamcorder->sound_focus_id, hcamcorder->sound_focus_watch_id);
+       _mmcam_dbg_log("by_system %d, flag 0x%x, acquired_focus %d, focus_id %d, watch_id %d",
+               hcamcorder->state_change_by_system, hcamcorder->session_flags, hcamcorder->acquired_focus,
+               hcamcorder->sound_focus_id, hcamcorder->sound_focus_watch_id);
 
-               if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_FOCUS &&
-                   hcamcorder->sound_focus_watch_id > 0) {
-                       ret_sound = mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
-                       if (ret_sound != MM_ERROR_NONE) {
-                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback failed [0x%x]", ret_sound);
-                       } else {
-                               _mmcam_dbg_warn("mm_sound_unset_focus_watch_callback done");
-                       }
-               } else {
-                       _mmcam_dbg_warn("no need to unset watch callback.[state_change_by_system %d, sound_focus_watch_id %d]",
-                               hcamcorder->state_change_by_system, hcamcorder->sound_focus_watch_id);
+       if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_FOCUS) {
+               if (hcamcorder->sound_focus_watch_id > 0) {
+                       mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+                       _mmcam_dbg_warn("unset sound focus watch cb [id %d] done", hcamcorder->sound_focus_watch_id);
+                       hcamcorder->sound_focus_watch_id = 0;
                }
 
                if (hcamcorder->acquired_focus > 0) {
-                       ret_sound = mm_sound_release_focus(0, hcamcorder->acquired_focus, NULL);
-                       if (ret_sound != MM_ERROR_NONE) {
-                               _mmcam_dbg_warn("mm_sound_release_focus failed [0x%x]", ret_sound);
-                       } else {
-                               _mmcam_dbg_log("mm_sound_release_focus done");
-                       }
-               } else {
-                       _mmcam_dbg_warn("no need to release focus - current acquired focus %d", hcamcorder->acquired_focus);
+                       mm_sound_release_focus(hcamcorder->sound_focus_id, hcamcorder->acquired_focus, NULL);
+                       _mmcam_dbg_warn("release sound focus [focus %d] done", hcamcorder->acquired_focus);
+                       hcamcorder->acquired_focus = 0;
                }
+       } else {
+               _mmcam_dbg_warn("state change by focus. so, no need to unset watch callback");
+               /* acquired focus will be released automatically */
+               hcamcorder->acquired_focus = 0;
        }
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
 
        return MM_ERROR_NONE;
 
@@ -1444,8 +1442,6 @@ int _mmcamcorder_start(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM = MM_CAMCORDER_STATE_READY;
-       int state_TO = MM_CAMCORDER_STATE_PREPARE;
 
        _MMCamcorderSubContext *sc = NULL;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
@@ -1468,7 +1464,7 @@ int _mmcamcorder_start(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM) {
+       if (state != MM_CAMCORDER_STATE_READY) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1478,22 +1474,8 @@ int _mmcamcorder_start(MMHandleType handle)
        hcamcorder->error_code = MM_ERROR_NONE;
 
        /* set attributes related sensor */
-       if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
-               /* init for gdbus */
-               hcamcorder->gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-               if (hcamcorder->gdbus_conn == NULL) {
-                       _mmcam_dbg_err("failed to get gdbus");
-                       ret = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
-                       goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
-               }
-
-               g_mutex_init(&hcamcorder->gdbus_info_sound.sync_mutex);
-               g_cond_init(&hcamcorder->gdbus_info_sound.sync_cond);
-               g_mutex_init(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
-               g_cond_init(&hcamcorder->gdbus_info_solo_sound.sync_cond);
-
+       if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
                _mmcamcorder_set_attribute_to_camsensor(handle);
-       }
 
        ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_PREVIEW_START);
        if (ret != MM_ERROR_NONE) {
@@ -1505,23 +1487,13 @@ int _mmcamcorder_start(MMHandleType handle)
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
        }
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
 
 _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
-       if (hcamcorder->gdbus_conn) {
-               g_object_unref(hcamcorder->gdbus_conn);
-               hcamcorder->gdbus_conn = NULL;
-
-               g_mutex_clear(&hcamcorder->gdbus_info_sound.sync_mutex);
-               g_cond_clear(&hcamcorder->gdbus_info_sound.sync_cond);
-               g_mutex_clear(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
-               g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
-       }
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
 _ERR_CAMCORDER_CMD_PRECON:
@@ -1543,8 +1515,6 @@ int _mmcamcorder_stop(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM = MM_CAMCORDER_STATE_PREPARE;
-       int state_TO = MM_CAMCORDER_STATE_READY;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1563,7 +1533,7 @@ int _mmcamcorder_stop(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM) {
+       if (state != MM_CAMCORDER_STATE_PREPARE) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1573,9 +1543,10 @@ int _mmcamcorder_stop(MMHandleType handle)
        if (ret != MM_ERROR_NONE)
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
 
        if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
+               /* unsubscribe remained unsubscribed signal */
                g_mutex_lock(&hcamcorder->gdbus_info_sound.sync_mutex);
                if (hcamcorder->gdbus_info_sound.subscribe_id > 0) {
                        _mmcam_dbg_warn("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_sound.subscribe_id);
@@ -1589,14 +1560,6 @@ int _mmcamcorder_stop(MMHandleType handle)
                        g_dbus_connection_signal_unsubscribe(hcamcorder->gdbus_conn, hcamcorder->gdbus_info_solo_sound.subscribe_id);
                }
                g_mutex_unlock(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
-
-               g_object_unref(hcamcorder->gdbus_conn);
-               hcamcorder->gdbus_conn = NULL;
-
-               g_mutex_clear(&hcamcorder->gdbus_info_sound.sync_mutex);
-               g_cond_clear(&hcamcorder->gdbus_info_sound.sync_cond);
-               g_mutex_clear(&hcamcorder->gdbus_info_solo_sound.sync_mutex);
-               g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
        }
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
@@ -1621,7 +1584,6 @@ int _mmcamcorder_capture_start(MMHandleType handle)
        int state_FROM_0 = MM_CAMCORDER_STATE_PREPARE;
        int state_FROM_1 = MM_CAMCORDER_STATE_RECORDING;
        int state_FROM_2 = MM_CAMCORDER_STATE_PAUSED;
-       int state_TO = MM_CAMCORDER_STATE_CAPTURING;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1675,7 +1637,7 @@ int _mmcamcorder_capture_start(MMHandleType handle)
 
        /* Do not change state when recording snapshot capture */
        if (state == state_FROM_0)
-               _mmcamcorder_set_state(handle, state_TO);
+               _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_CAPTURING);
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
@@ -1704,8 +1666,6 @@ int _mmcamcorder_capture_stop(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM = MM_CAMCORDER_STATE_CAPTURING;
-       int state_TO = MM_CAMCORDER_STATE_PREPARE;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
        _mmcam_dbg_log("");
@@ -1723,7 +1683,7 @@ int _mmcamcorder_capture_stop(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM) {
+       if (state != MM_CAMCORDER_STATE_CAPTURING) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1733,7 +1693,7 @@ int _mmcamcorder_capture_stop(MMHandleType handle)
        if (ret != MM_ERROR_NONE)
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
@@ -1754,9 +1714,6 @@ int _mmcamcorder_record(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM1 = MM_CAMCORDER_STATE_PREPARE;
-       int state_FROM2 = MM_CAMCORDER_STATE_PAUSED;
-       int state_TO = MM_CAMCORDER_STATE_RECORDING;
        int dpm_mic_state = DPM_ALLOWED;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
@@ -1776,7 +1733,7 @@ int _mmcamcorder_record(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM1 && state != state_FROM2) {
+       if (state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_PAUSED) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1811,7 +1768,7 @@ int _mmcamcorder_record(MMHandleType handle)
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
        }
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_RECORDING);
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
@@ -1840,8 +1797,6 @@ int _mmcamcorder_pause(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM = MM_CAMCORDER_STATE_RECORDING;
-       int state_TO = MM_CAMCORDER_STATE_PAUSED;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1860,7 +1815,7 @@ int _mmcamcorder_pause(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM) {
+       if (state != MM_CAMCORDER_STATE_RECORDING) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1870,7 +1825,7 @@ int _mmcamcorder_pause(MMHandleType handle)
        if (ret != MM_ERROR_NONE)
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PAUSED);
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
@@ -1891,9 +1846,6 @@ int _mmcamcorder_commit(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM1 = MM_CAMCORDER_STATE_RECORDING;
-       int state_FROM2 = MM_CAMCORDER_STATE_PAUSED;
-       int state_TO = MM_CAMCORDER_STATE_PREPARE;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1912,7 +1864,7 @@ int _mmcamcorder_commit(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM1 && state != state_FROM2) {
+       if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1925,9 +1877,9 @@ int _mmcamcorder_commit(MMHandleType handle)
        if (ret != MM_ERROR_NONE)
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
 
-       _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
 
@@ -1946,9 +1898,6 @@ int _mmcamcorder_cancel(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int state_FROM1 = MM_CAMCORDER_STATE_RECORDING;
-       int state_FROM2 = MM_CAMCORDER_STATE_PAUSED;
-       int state_TO = MM_CAMCORDER_STATE_PREPARE;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1967,7 +1916,7 @@ int _mmcamcorder_cancel(MMHandleType handle)
        }
 
        state = _mmcamcorder_get_state(handle);
-       if (state != state_FROM1 && state != state_FROM2) {
+       if (state != MM_CAMCORDER_STATE_RECORDING && state != MM_CAMCORDER_STATE_PAUSED) {
                _mmcam_dbg_err("Wrong state(%d)", state);
                ret = MM_ERROR_CAMCORDER_INVALID_STATE;
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1977,7 +1926,7 @@ int _mmcamcorder_cancel(MMHandleType handle)
        if (ret != MM_ERROR_NONE)
                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
@@ -3274,7 +3223,7 @@ DROP_MESSAGE:
 
 void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
        mm_sound_focus_state_e focus_state, const char *reason_for_change,
-       const char *additional_info, void *user_data)
+       int option, const char *additional_info, void *user_data)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
        int current_state = MM_CAMCORDER_STATE_NONE;
@@ -3346,7 +3295,39 @@ void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
 }
 
 
-void _mmcamcorder_sound_focus_watch_cb(mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
+void _mmcamcorder_sound_signal_callback(mm_sound_signal_name_t signal, int value, void *user_data)
+{
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
+
+       mmf_return_if_fail(hcamcorder);
+
+       _mmcam_dbg_log("sound signal %d - value %d", signal, value);
+
+       _MMCAMCORDER_LOCK_ASM(hcamcorder);
+
+       if (signal == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS && value == 1) {
+               _mmcam_dbg_log("watch cb id %d", hcamcorder->sound_focus_watch_id);
+
+               /* unregister watch callback */
+               if (hcamcorder->sound_focus_watch_id > 0) {
+                       mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+                       _mmcam_dbg_log("unset watch cb done");
+                       hcamcorder->sound_focus_watch_id = 0;
+               }
+       }
+
+       /* reset flag not to run sound focus related code since now */
+       hcamcorder->sound_focus_register = FALSE;
+
+       _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
+
+       _mmcam_dbg_warn("done");
+
+       return;
+}
+
+
+void _mmcamcorder_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
        const char *reason_for_change, const char *additional_info, void *user_data)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(user_data);
@@ -3361,8 +3342,8 @@ void _mmcamcorder_sound_focus_watch_cb(mm_sound_focus_type_e focus_type, mm_soun
                return;
        }
 
-       _mmcam_dbg_log("sound focus watch callback : focus state %d, reason %s",
-               focus_state, reason_for_change ? reason_for_change : "N/A");
+       _mmcam_dbg_log("sound focus watch callback : id %d, focus state %d, reason %s",
+               id, focus_state, reason_for_change ? reason_for_change : "N/A");
 
        if (hcamcorder->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
                _mmcam_dbg_warn("session flag is UNINTERRUPTIBLE. do nothing.");
@@ -3389,14 +3370,14 @@ void _mmcamcorder_sound_focus_watch_cb(mm_sound_focus_type_e focus_type, mm_soun
        if (focus_state == FOCUS_IS_RELEASED) {
                _MMCamcorderMsgItem msg;
 
-               _mmcam_dbg_log("other process's FOCUS is acquired");
+               _mmcam_dbg_log("other process's FOCUS is released");
 
                msg.id = MM_MESSAGE_READY_TO_RESUME;
                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
 
                _mmcam_dbg_log("Finish opeartion");
        } else if (focus_state == FOCUS_IS_ACQUIRED) {
-               _mmcam_dbg_log("other process's FOCUS is released : Stop pipeline[state:%d]", current_state);
+               _mmcam_dbg_log("other process's FOCUS is acquired : Stop pipeline[state:%d]", current_state);
 
                __mmcamcorder_force_stop(hcamcorder);
 
@@ -4233,33 +4214,23 @@ static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMe
        return MM_ERROR_NONE;
 }
 
-int _mmcamcorder_get_video_caps(MMHandleType handle, char **caps)
+
+void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
+       const char *interface_name, const char *signal_name, int value)
 {
-       GstPad *pad = NULL;
-       GstCaps *sink_caps = NULL;
-       _MMCamcorderSubContext *sc = NULL;
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
-       sc = MMF_CAMCORDER_SUBCONTEXT(handle);
-       _mmcam_dbg_warn("Entered ");
-       pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "sink");
-       if (!pad) {
-               _mmcam_dbg_err("static pad is NULL");
-               return MM_ERROR_CAMCORDER_INVALID_STATE;
-       }
+       mmf_return_if_fail(hcamcorder && object_name && interface_name && signal_name);
 
-       sink_caps = gst_pad_get_current_caps(pad);
-       gst_object_unref(pad);
-       if (!sink_caps) {
-               _mmcam_dbg_err("fail to get caps");
-               return MM_ERROR_CAMCORDER_INVALID_STATE;
-       }
+       _mmcam_dbg_log("object %s, interface %s, signal %s, value %d",
+               object_name, interface_name, signal_name, value);
 
-       *caps = gst_caps_to_string(sink_caps);
-       _mmcam_dbg_err("video caps : %s", *caps);
-       gst_caps_unref(sink_caps);
+       _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, object_name, interface_name, signal_name, value);
 
-       return MM_ERROR_NONE;
+       return;
 }
+
+
 #ifdef _MMCAMCORDER_RM_SUPPORT
 rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
        rm_device_request_s *info, void* cb_data)