Disable initialization for sub resource manager instance
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index 9558219..ce6442f 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>
 #define DPM_ALLOWED                             1
 #define DPM_DISALLOWED                          0
 
-#ifdef _MMCAMCORDER_MURPHY_SUPPORT
-#define __MMCAMCORDER_RESOURCE_WAIT_TIME        5
-#endif /* _MMCAMCORDER_MURPHY_SUPPORT */
-
-
 /*---------------------------------------------------------------------------------------
 |    LOCAL FUNCTION PROTOTYPES:                                                                |
 ---------------------------------------------------------------------------------------*/
@@ -81,6 +74,7 @@ static gint     __mmcamcorder_gst_handle_library_error(MMHandleType handle, int
 static gint     __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, GstMessage *message);
 static gint     __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMessage *message , GError *error);
 static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage *message, GError *error);
+static int      __mmcamcorder_simulate_asm_conflict_table(int session_type, int pid);
 
 #ifdef _MMCAMCORDER_RM_SUPPORT
 rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
@@ -129,7 +123,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        hcamcorder->type = 0;
        hcamcorder->state = MM_CAMCORDER_STATE_NONE;
        hcamcorder->sub_context = NULL;
-       hcamcorder->target_state = MM_CAMCORDER_STATE_NULL;
+       hcamcorder->old_state = MM_CAMCORDER_STATE_NONE;
        hcamcorder->capture_in_recording = FALSE;
        hcamcorder->session_type = MM_SESSION_TYPE_MEDIA;
 
@@ -145,6 +139,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        g_mutex_init(&(hcamcorder->mtsafe).vcapture_cb_lock);
        g_mutex_init(&(hcamcorder->mtsafe).vstream_cb_lock);
        g_mutex_init(&(hcamcorder->mtsafe).astream_cb_lock);
+       g_mutex_init(&(hcamcorder->mtsafe).mstream_cb_lock);
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
        g_cond_init(&(hcamcorder->mtsafe).resource_cond);
        g_mutex_init(&(hcamcorder->mtsafe).resource_lock);
@@ -161,7 +156,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 +189,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) {
@@ -223,18 +204,10 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                goto _ERR_DEFAULT_VALUE_INIT;
        }
 
-       /* get DPM context for camera/microphone restriction */
-       hcamcorder->dpm_context = dpm_context_create();
-       if (hcamcorder->dpm_context) {
-               hcamcorder->dpm_policy = dpm_context_acquire_restriction_policy(hcamcorder->dpm_context);
-               if (hcamcorder->dpm_policy == NULL) {
-                       _mmcam_dbg_err("dpm_context_acquire_restriction_policy failed");
-                       dpm_context_destroy(hcamcorder->dpm_context);
-                       hcamcorder->dpm_context = NULL;
-               }
-       }
+       /* get DPM handle for camera/microphone restriction */
+       hcamcorder->dpm_handle = dpm_manager_create();
 
-       _mmcam_dbg_warn("DPM context %p, policy %p", hcamcorder->dpm_context, hcamcorder->dpm_policy);
+       _mmcam_dbg_warn("DPM handle %p", hcamcorder->dpm_handle);
 
        if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
                _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
@@ -412,8 +385,8 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                }
 
                /* add DPM camera policy changed callback */
-               if (hcamcorder->dpm_context) {
-                       ret = dpm_context_add_policy_changed_cb(hcamcorder->dpm_context, "camera",
+               if (hcamcorder->dpm_handle) {
+                       ret = dpm_add_policy_changed_cb(hcamcorder->dpm_handle, "camera",
                                _mmcamcorder_dpm_camera_policy_changed_cb, (void *)hcamcorder, &hcamcorder->dpm_camera_cb_id);
                        if (ret != DPM_ERROR_NONE) {
                                _mmcam_dbg_err("add DPM changed cb failed, keep going...");
@@ -422,6 +395,30 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
 
                        _mmcam_dbg_log("DPM camera changed cb id %d", hcamcorder->dpm_camera_cb_id);
                }
+
+#ifdef _MMCAMCORDER_MURPHY_SUPPORT
+               /* set camcorder handle */
+               hcamcorder->resource_manager.id = MM_CAMCORDER_RESOURCE_ID_MAIN;
+               hcamcorder->resource_manager.hcamcorder = hcamcorder;
+               hcamcorder->resource_manager_sub.id = MM_CAMCORDER_RESOURCE_ID_SUB;
+               hcamcorder->resource_manager_sub.hcamcorder = hcamcorder;
+
+               /* initialize resource manager */
+               ret = _mmcamcorder_resource_manager_init(&hcamcorder->resource_manager);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("failed to initialize resource manager");
+                       ret = MM_ERROR_CAMCORDER_INTERNAL;
+                       goto _ERR_DEFAULT_VALUE_INIT;
+               }
+#ifdef _MMCAMCORDER_INIT_RESOURCE_MANAGER_SUB
+               ret = _mmcamcorder_resource_manager_init(&hcamcorder->resource_manager_sub);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("failed to initialize resource manager sub");
+                       ret = MM_ERROR_CAMCORDER_INTERNAL;
+                       goto _ERR_DEFAULT_VALUE_INIT;
+               }
+#endif
+#endif /* _MMCAMCORDER_MURPHY_SUPPORT */
        } else {
                _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
                        CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
@@ -446,16 +443,6 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                }
        }
 
-#ifdef _MMCAMCORDER_MURPHY_SUPPORT
-       /* initialize resource manager */
-       ret = _mmcamcorder_resource_manager_init(&hcamcorder->resource_manager, (void *)hcamcorder);
-       if (ret != MM_ERROR_NONE) {
-               _mmcam_dbg_err("failed to initialize resource manager");
-               ret = MM_ERROR_CAMCORDER_INTERNAL;
-               goto _ERR_DEFAULT_VALUE_INIT;
-       }
-#endif /* _MMCAMCORDER_MURPHY_SUPPORT */
-
        traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:CREATE:INIT_GSTREAMER");
 
        ret = __mmcamcorder_gstreamer_init(hcamcorder->conf_main);
@@ -500,42 +487,31 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
 
        /* get model name */
        sys_info_ret = system_info_get_platform_string("http://tizen.org/system/model_name", &hcamcorder->model_name);
-       if (hcamcorder->model_name) {
-               _mmcam_dbg_log("model name [%s], sys_info_ret 0x%x", hcamcorder->model_name, sys_info_ret);
-       } else {
-               _mmcam_dbg_warn("failed get model name, sys_info_ret 0x%x", sys_info_ret);
-       }
+
+       _mmcam_dbg_warn("model name [%s], ret 0x%x",
+               hcamcorder->model_name ? hcamcorder->model_name : "NULL", sys_info_ret);
 
        /* get software version */
        sys_info_ret = system_info_get_platform_string("http://tizen.org/system/build.string", &hcamcorder->software_version);
-       if (hcamcorder->software_version) {
-               _mmcam_dbg_log("software version [%s], sys_info_ret 0x%d", hcamcorder->software_version, sys_info_ret);
-       } else {
-               _mmcam_dbg_warn("failed get software version, sys_info_ret 0x%x", sys_info_ret);
-       }
-
-#ifdef _MMCAMCORDER_MURPHY_SUPPORT
-       _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
-
-       if (hcamcorder->resource_manager.is_connected == FALSE) {
-               gint64 end_time = 0;
-
-               /* wait for resource manager connected */
-               _mmcam_dbg_log("resource manager is not connected. wait for signal...");
 
-               end_time = g_get_monotonic_time() + (__MMCAMCORDER_RESOURCE_WAIT_TIME * G_TIME_SPAN_SECOND);
+       _mmcam_dbg_warn("software version [%s], ret 0x%x",
+               hcamcorder->software_version ? hcamcorder->software_version : "NULL", sys_info_ret);
 
-               if (_MMCAMCORDER_RESOURCE_WAIT_UNTIL(hcamcorder, end_time)) {
-                       _mmcam_dbg_warn("signal received");
-               } else {
-                       _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
-                       _mmcam_dbg_err("timeout");
-                       ret = MM_ERROR_RESOURCE_INTERNAL;
+#ifdef _MMCAMCORDER_MURPHY_SUPPORT
+       if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
+               ret = _mmcamcorder_resource_wait_for_connection(&hcamcorder->resource_manager);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("failed to connect resource manager");
+                       goto _ERR_DEFAULT_VALUE_INIT;
+               }
+#ifdef _MMCAMCORDER_INIT_RESOURCE_MANAGER_SUB
+               ret = _mmcamcorder_resource_wait_for_connection(&hcamcorder->resource_manager_sub);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("failed to connect resource manager");
                        goto _ERR_DEFAULT_VALUE_INIT;
                }
+#endif
        }
-
-       _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
        /* Set initial state */
@@ -550,41 +526,27 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
 _ERR_DEFAULT_VALUE_INIT:
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
        /* de-initialize resource manager */
+#ifdef _MMCAMCORDER_INIT_RESOURCE_MANAGER_SUB
+       _mmcamcorder_resource_manager_deinit(&hcamcorder->resource_manager_sub);
+#endif
        _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_context) {
-               _mmcam_dbg_log("release DPM context %p, camera changed cb id %d",
-                       hcamcorder->dpm_context, hcamcorder->dpm_camera_cb_id);
+       if (hcamcorder->dpm_handle) {
+               _mmcam_dbg_log("release DPM handle %p, camera changed cb id %d",
+                       hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
 
                /* remove camera policy changed callback */
                if (hcamcorder->dpm_camera_cb_id > 0) {
-                       dpm_context_remove_policy_changed_cb(hcamcorder->dpm_context, hcamcorder->dpm_camera_cb_id);
+                       dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
                        hcamcorder->dpm_camera_cb_id = 0;
                } else {
                        _mmcam_dbg_warn("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
                }
 
-               if (hcamcorder->dpm_policy) {
-                       dpm_context_release_restriction_policy(hcamcorder->dpm_context, hcamcorder->dpm_policy);
-                       hcamcorder->dpm_policy = NULL;
-               }
-
-               dpm_context_destroy(hcamcorder->dpm_context);
-               hcamcorder->dpm_context = NULL;
+               dpm_manager_destroy(hcamcorder->dpm_handle);
+               hcamcorder->dpm_handle = NULL;
        }
 
        /* Remove attributes */
@@ -606,6 +568,7 @@ _ERR_DEFAULT_VALUE_INIT:
        g_mutex_clear(&(hcamcorder->mtsafe).vcapture_cb_lock);
        g_mutex_clear(&(hcamcorder->mtsafe).vstream_cb_lock);
        g_mutex_clear(&(hcamcorder->mtsafe).astream_cb_lock);
+       g_mutex_clear(&(hcamcorder->mtsafe).mstream_cb_lock);
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
        g_cond_clear(&(hcamcorder->mtsafe).resource_cond);
        g_mutex_clear(&(hcamcorder->mtsafe).resource_lock);
@@ -615,6 +578,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);
 
@@ -655,7 +625,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 */
@@ -679,7 +648,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;
@@ -725,6 +694,10 @@ int _mmcamcorder_destroy(MMHandleType handle)
        if (ret != MM_ERROR_NONE)
                _mmcam_dbg_err("failed to de-initialize resource manager 0x%x", ret);
 
+       ret = _mmcamcorder_resource_manager_deinit(&hcamcorder->resource_manager_sub);
+       if (ret != MM_ERROR_NONE)
+               _mmcam_dbg_err("failed to de-initialize resource manager sub 0x%x", ret);
+
        _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
@@ -757,19 +730,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);
@@ -790,26 +773,21 @@ int _mmcamcorder_destroy(MMHandleType handle)
                hcamcorder->software_version = NULL;
        }
 
-       /* release DPM related handle */
-       if (hcamcorder->dpm_context) {
-               _mmcam_dbg_log("release DPM context %p, camera changed cb id %d",
-                       hcamcorder->dpm_context, hcamcorder->dpm_camera_cb_id);
+       /* release DPM handle */
+       if (hcamcorder->dpm_handle) {
+               _mmcam_dbg_log("release DPM handle %p, camera changed cb id %d",
+                       hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
 
                /* remove camera policy changed callback */
                if (hcamcorder->dpm_camera_cb_id > 0) {
-                       dpm_context_remove_policy_changed_cb(hcamcorder->dpm_context, hcamcorder->dpm_camera_cb_id);
+                       dpm_remove_policy_changed_cb(hcamcorder->dpm_handle, hcamcorder->dpm_camera_cb_id);
                        hcamcorder->dpm_camera_cb_id = 0;
                } else {
                        _mmcam_dbg_warn("invalid dpm camera cb id %d", hcamcorder->dpm_camera_cb_id);
                }
 
-               if (hcamcorder->dpm_policy) {
-                       dpm_context_release_restriction_policy(hcamcorder->dpm_context, hcamcorder->dpm_policy);
-                       hcamcorder->dpm_policy = NULL;
-               }
-
-               dpm_context_destroy(hcamcorder->dpm_context);
-               hcamcorder->dpm_context = NULL;
+               dpm_manager_destroy(hcamcorder->dpm_handle);
+               hcamcorder->dpm_handle = NULL;
        }
 
        /* join task thread */
@@ -832,6 +810,7 @@ int _mmcamcorder_destroy(MMHandleType handle)
        g_mutex_clear(&(hcamcorder->mtsafe).vcapture_cb_lock);
        g_mutex_clear(&(hcamcorder->mtsafe).vstream_cb_lock);
        g_mutex_clear(&(hcamcorder->mtsafe).astream_cb_lock);
+       g_mutex_clear(&(hcamcorder->mtsafe).mstream_cb_lock);
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
        g_cond_clear(&(hcamcorder->mtsafe).resource_cond);
        g_mutex_clear(&(hcamcorder->mtsafe).resource_lock);
@@ -843,6 +822,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);
@@ -867,17 +853,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);
@@ -897,18 +888,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,
@@ -926,20 +925,19 @@ int _mmcamcorder_realize(MMHandleType handle)
                        _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;
+               ret = __mmcamcorder_simulate_asm_conflict_table(hcamcorder->session_type, pid_for_sound_focus);
+               if (ret != MM_ERROR_NONE)
+                       goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
 
-               /* check session flags */
+               /* acquire sound focus or set sound focus watch callback */
                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, "mm-camcorder acquire focus");
                        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;
                        }
@@ -949,6 +947,13 @@ 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 */
                        _mmcam_dbg_log("ETC - set sound focus watch callback - pid %d", pid_for_sound_focus);
 
@@ -960,7 +965,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;
                        }
@@ -971,83 +975,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 */
@@ -1066,6 +998,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);
        }
 
@@ -1135,25 +1068,34 @@ int _mmcamcorder_realize(MMHandleType handle)
                int dpm_camera_state = DPM_ALLOWED;
 
                /* check camera policy from DPM */
-               if (hcamcorder->dpm_policy) {
-                       if (dpm_restriction_get_camera_state(hcamcorder->dpm_policy, &dpm_camera_state) == DPM_ERROR_NONE) {
+               if (hcamcorder->dpm_handle) {
+                       if (dpm_restriction_get_camera_state(hcamcorder->dpm_handle, &dpm_camera_state) == DPM_ERROR_NONE) {
                                _mmcam_dbg_log("DPM camera state %d", dpm_camera_state);
                                if (dpm_camera_state == DPM_DISALLOWED) {
                                        _mmcam_dbg_err("CAMERA DISALLOWED by DPM");
                                        ret = MM_ERROR_POLICY_RESTRICTED;
+
+                                       _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
+
                                        goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
                                }
                        } else {
                                _mmcam_dbg_err("get DPM camera state failed, keep going...");
                        }
                } else {
-                       _mmcam_dbg_warn("NULL dpm_policy");
+                       _mmcam_dbg_warn("NULL dpm_handle");
                }
+
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
+               /* check connection */
+               ret = _mmcamcorder_resource_check_connection(&hcamcorder->resource_manager);
+               if (ret != MM_ERROR_NONE)
+                       goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+
+               /* create resource set */
                ret = _mmcamcorder_resource_create_resource_set(&hcamcorder->resource_manager);
-               if (ret != MM_ERROR_NONE) {
+               if (ret != MM_ERROR_NONE)
                        goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
-               }
 
                hcamcorder->resource_manager.acquire_count = 0;
 
@@ -1166,10 +1108,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) {
@@ -1182,7 +1120,8 @@ int _mmcamcorder_realize(MMHandleType handle)
                /* acquire resources */
                _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
 
-               if (hcamcorder->resource_manager.rset && _mmcamcorder_resource_manager_acquire(&hcamcorder->resource_manager)) {
+               ret = _mmcamcorder_resource_manager_acquire(&hcamcorder->resource_manager);
+               if (ret != MM_ERROR_NONE) {
                        _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
 
                        _mmcam_dbg_err("could not acquire resources");
@@ -1212,6 +1151,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 */
@@ -1243,7 +1262,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);
 
@@ -1252,36 +1271,9 @@ int _mmcamcorder_realize(MMHandleType handle)
 _ERR_CAMCORDER_CMD:
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
        /* release hw resources */
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
-               int ret_resource = _mmcamcorder_resource_manager_release(&hcamcorder->resource_manager);
-               if (ret_resource == MM_ERROR_RESOURCE_INVALID_STATE) {
-                       _mmcam_dbg_warn("it could be in the middle of resource callback or there's no acquired resource");
-               } else if (ret_resource != MM_ERROR_NONE) {
-                       _mmcam_dbg_err("failed to release resource, ret_resource(0x%x)", ret_resource);
-               }
-       }
+       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE)
+               _mmcamcorder_resource_manager_release(&hcamcorder->resource_manager);
 #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) {
@@ -1296,13 +1288,29 @@ _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)
                        _mmcam_dbg_err("rm_unregister() failed");
                hcamcorder->rm_handle = 0;
        }
-#endif /* _MMCAMCORDER_RM_SUPPORT*/
+#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, "mm-camcorder release focus");
+               _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);
@@ -1315,8 +1323,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);
 
@@ -1335,7 +1341,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;
@@ -1351,13 +1357,15 @@ int _mmcamcorder_unrealize(MMHandleType handle)
        }
 
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
+       _mmcam_dbg_warn("lock resource - cb calling %d", hcamcorder->resource_manager.is_release_cb_calling);
+
+       _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
+
        if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE &&
-               hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM) {
+               hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_RM &&
+               hcamcorder->resource_manager.is_release_cb_calling == FALSE) {
                gint64 end_time = 0;
 
-               _mmcam_dbg_log("lock resource");
-               _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
-
                /* release resource */
                ret = _mmcamcorder_resource_manager_release(&hcamcorder->resource_manager);
                if (ret == MM_ERROR_RESOURCE_INVALID_STATE) {
@@ -1381,10 +1389,11 @@ int _mmcamcorder_unrealize(MMHandleType handle)
 
                        _MMCAMCORDER_RESOURCE_WAIT_UNTIL(hcamcorder, end_time);
                }
-
-               _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
-               _mmcam_dbg_log("unlock resource");
        }
+
+       _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
+
+       _mmcam_dbg_warn("unlock resource");
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
 #ifdef _MMCAMCORDER_RM_SUPPORT
@@ -1410,41 +1419,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, "mm-camcorder release focus");
+                       _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;
 
@@ -1462,8 +1461,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);
@@ -1486,7 +1483,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;
@@ -1496,22 +1493,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) {
@@ -1523,23 +1506,17 @@ 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);
+
+       /* set attributes related sensor - after start preview */
+       if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO)
+               _mmcamcorder_set_attribute_to_camsensor2(handle);
 
        _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:
@@ -1561,8 +1538,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);
 
@@ -1581,7 +1556,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;
@@ -1591,9 +1566,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);
@@ -1607,14 +1583,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);
@@ -1639,7 +1607,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);
 
@@ -1693,7 +1660,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);
 
@@ -1722,8 +1689,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("");
@@ -1741,7 +1706,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;
@@ -1751,7 +1716,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);
 
@@ -1772,21 +1737,21 @@ 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);
+       _MMCamcorderSubContext *sc = NULL;
 
        _mmcam_dbg_log("");
 
-       if (!hcamcorder) {
+       if (!hcamcorder || !MMF_CAMCORDER_SUBCONTEXT(hcamcorder)) {
                _mmcam_dbg_err("Not initialized");
                ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
                return ret;
        }
 
+       sc = MMF_CAMCORDER_SUBCONTEXT(handle);
+
        if (!_MMCAMCORDER_TRYLOCK_CMD(hcamcorder)) {
                _mmcam_dbg_err("Another command is running.");
                ret = MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
@@ -1794,7 +1759,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;
@@ -1803,20 +1768,31 @@ int _mmcamcorder_record(MMHandleType handle)
        /* initialize error code */
        hcamcorder->error_code = MM_ERROR_NONE;
 
+       /* get audio disable */
+       mm_camcorder_get_attributes(handle, NULL,
+               MMCAM_AUDIO_DISABLE, &sc->audio_disable,
+               NULL);
+
+       sc->audio_disable |= sc->is_modified_rate;
+
        /* check mic policy from DPM */
-       if (hcamcorder->dpm_policy) {
-               if (dpm_restriction_get_microphone_state(hcamcorder->dpm_policy, &dpm_mic_state) == DPM_ERROR_NONE) {
+       if (hcamcorder->dpm_handle && sc->audio_disable == FALSE) {
+               if (dpm_restriction_get_microphone_state(hcamcorder->dpm_handle, &dpm_mic_state) == DPM_ERROR_NONE) {
                        _mmcam_dbg_log("DPM mic state %d", dpm_mic_state);
                        if (dpm_mic_state == DPM_DISALLOWED) {
                                _mmcam_dbg_err("MIC DISALLOWED by DPM");
                                ret = MM_ERROR_COMMON_INVALID_PERMISSION;
+
+                               _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
+
                                goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
                        }
                } else {
                        _mmcam_dbg_err("get DPM mic state failed, keep going...");
                }
        } else {
-               _mmcam_dbg_warn("NULL dpm_policy");
+               _mmcam_dbg_warn("skip dpm check - handle %p, audio disable %d",
+                       hcamcorder->dpm_handle, sc->audio_disable);
        }
 
        ret = hcamcorder->command((MMHandleType)hcamcorder, _MMCamcorder_CMD_RECORD);
@@ -1829,7 +1805,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);
 
@@ -1858,8 +1834,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);
 
@@ -1878,7 +1852,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;
@@ -1888,7 +1862,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);
 
@@ -1909,9 +1883,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);
 
@@ -1930,7 +1901,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;
@@ -1943,9 +1914,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;
 
@@ -1964,9 +1935,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);
 
@@ -1985,7 +1953,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;
@@ -1995,7 +1963,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);
 
@@ -2062,10 +2030,7 @@ int _mmcamcorder_set_video_stream_callback(MMHandleType handle, mm_camcorder_vid
        if (callback == NULL)
                _mmcam_dbg_warn("Video Stream Callback is disabled, because application sets it to NULL");
 
-       if (!_MMCAMCORDER_TRYLOCK_VSTREAM_CALLBACK(hcamcorder)) {
-               _mmcam_dbg_warn("Application's video stream callback is running now");
-               return MM_ERROR_CAMCORDER_INVALID_CONDITION;
-       }
+       _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
 
        hcamcorder->vstream_cb = callback;
        hcamcorder->vstream_cb_param = user_data;
@@ -2101,6 +2066,31 @@ int _mmcamcorder_set_audio_stream_callback(MMHandleType handle, mm_camcorder_aud
 }
 
 
+int _mmcamcorder_set_muxed_stream_callback(MMHandleType handle, mm_camcorder_muxed_stream_callback callback, void *user_data)
+{
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+       _mmcam_dbg_log("");
+
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
+       if (callback == NULL)
+               _mmcam_dbg_warn("Muxed Stream Callback is disabled, because application sets it to NULL");
+
+       if (!_MMCAMCORDER_TRYLOCK_MSTREAM_CALLBACK(hcamcorder)) {
+               _mmcam_dbg_warn("Application's muxed stream callback is running now");
+               return MM_ERROR_CAMCORDER_INVALID_CONDITION;
+       }
+
+       hcamcorder->mstream_cb = callback;
+       hcamcorder->mstream_cb_param = user_data;
+
+       _MMCAMCORDER_UNLOCK_MSTREAM_CALLBACK(hcamcorder);
+
+       return MM_ERROR_NONE;
+}
+
+
 int _mmcamcorder_set_video_capture_callback(MMHandleType handle, mm_camcorder_video_capture_callback callback, void *user_data)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
@@ -2537,6 +2527,23 @@ int _mmcamcorder_get_state(MMHandleType handle)
 }
 
 
+int _mmcamcorder_get_state2(MMHandleType handle, int *state, int *old_state)
+{
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+       mmf_return_val_if_fail(hcamcorder && state && old_state, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       _MMCAMCORDER_LOCK_STATE(handle);
+
+       *state = hcamcorder->state;
+       *old_state = hcamcorder->old_state;
+
+       _MMCAMCORDER_UNLOCK_STATE(handle);
+
+       return MM_ERROR_NONE;
+}
+
+
 void _mmcamcorder_set_state(MMHandleType handle, int state)
 {
        int old_state;
@@ -2552,9 +2559,9 @@ void _mmcamcorder_set_state(MMHandleType handle, int state)
        old_state = hcamcorder->state;
        if (old_state != state) {
                hcamcorder->state = state;
-               hcamcorder->target_state = state;
+               hcamcorder->old_state = old_state;
 
-               _mmcam_dbg_log("set state[%d] and send state-changed message", state);
+               _mmcam_dbg_log("set state[%d -> %d] and send state-changed message", old_state, state);
 
                /* To discern who changes the state */
                switch (hcamcorder->state_change_by_system) {
@@ -2590,20 +2597,6 @@ void _mmcamcorder_set_state(MMHandleType handle, int state)
 }
 
 
-int _mmcamcorder_get_async_state(MMHandleType handle)
-{
-       int state;
-       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
-
-       _MMCAMCORDER_LOCK_STATE(handle);
-       state = hcamcorder->target_state;
-
-       _MMCAMCORDER_UNLOCK_STATE(handle);
-
-       return state;
-}
-
-
 _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
 {
        int i;
@@ -2847,8 +2840,12 @@ gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpoi
                                pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst;
                                if (message->src == (GstObject*)pipeline) {
                                        vnewstate = gst_structure_get_value(gst_message_get_structure(message), "new-state");
-                                       newstate = (GstState)vnewstate->data[0].v_int;
-                                       _mmcam_dbg_log("GST_MESSAGE_STATE_CHANGED[%s]", gst_element_state_get_name(newstate));
+                                       if (vnewstate) {
+                                               newstate = (GstState)vnewstate->data[0].v_int;
+                                               _mmcam_dbg_log("GST_MESSAGE_STATE_CHANGED[%s]", gst_element_state_get_name(newstate));
+                                       } else {
+                                               _mmcam_dbg_warn("get new state failed from msg");
+                                       }
                                }
                        }
                }
@@ -3265,9 +3262,9 @@ GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstM
 
                                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
                        }
-               }
 
-               goto DROP_MESSAGE;
+                       goto DROP_MESSAGE;
+               }
        }
 
        if (err) {
@@ -3292,7 +3289,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;
@@ -3305,7 +3302,7 @@ void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
                return;
        }
 
-       _mmcam_dbg_log("sound focus callback : focus state %d, reason %s",
+       _mmcam_dbg_warn("sound focus callback : focus state %d, reason %s",
                                   focus_state, reason_for_change ? reason_for_change : "N/A");
 
        if (hcamcorder->session_flags & MM_SESSION_OPTION_UNINTERRUPTIBLE) {
@@ -3315,9 +3312,6 @@ void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
 
        _MMCAMCORDER_LOCK_ASM(hcamcorder);
 
-       /* set value to inform a status is changed by asm */
-       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_FOCUS;
-
        /* check the reason */
        if (!strncmp(reason_for_change, "ringtone-voip", __MMCAMCORDER_FOCUS_CHANGE_REASON_LEN) ||
            !strncmp(reason_for_change, "ringtone-call", __MMCAMCORDER_FOCUS_CHANGE_REASON_LEN) ||
@@ -3333,38 +3327,80 @@ void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
        if (focus_state == FOCUS_IS_RELEASED) {
                hcamcorder->acquired_focus &= ~focus_type;
 
-               _mmcam_dbg_log("FOCUS is released [type %d, remained focus %d] : Stop pipeline[state:%d]",
+               _mmcam_dbg_warn("FOCUS is released [type %d, remained focus %d] : Stop pipeline[state:%d]",
                        focus_type, hcamcorder->acquired_focus, current_state);
 
-               __mmcamcorder_force_stop(hcamcorder);
+               __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_FOCUS);
 
-               _mmcam_dbg_log("Finish opeartion. Pipeline is released");
+               _mmcam_dbg_warn("Finish opeartion. Pipeline is released");
        } else if (focus_state == FOCUS_IS_ACQUIRED) {
                _MMCamcorderMsgItem msg;
 
-               hcamcorder->acquired_focus |= focus_type;
-
-               _mmcam_dbg_log("FOCUS is acquired [type %d, new focus %d]",
+               _mmcam_dbg_warn("FOCUS is ready to acquired [type %d, current %d]",
                        focus_type, hcamcorder->acquired_focus);
 
                msg.id = MM_MESSAGE_READY_TO_RESUME;
                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
 
-               _mmcam_dbg_log("Finish opeartion");
+               _mmcam_dbg_warn("Finish opeartion");
        } else {
-               _mmcam_dbg_log("unknown focus state %d", focus_state);
+               _mmcam_dbg_warn("unknown focus state %d", focus_state);
        }
 
-       /* restore value */
-       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
+       _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
+
+       _mmcam_dbg_warn("done");
+
+       return;
+}
+
+
+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_warn("sound signal %d - value %d", signal, value);
+
+       _MMCAMCORDER_LOCK_ASM(hcamcorder);
+
+       if (signal == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS && value == 1) {
+               _mmcam_dbg_warn("focus id %d, focus watch id %d",
+                       hcamcorder->sound_focus_id, hcamcorder->sound_focus_watch_id);
+
+               /* unregister focus related callback */
+               if (hcamcorder->sound_focus_id > 0) {
+                       if (hcamcorder->acquired_focus > 0) {
+                               mm_sound_release_focus(hcamcorder->sound_focus_id, hcamcorder->acquired_focus, "mm-camcorder release focus");
+                               _mmcam_dbg_warn("release acquired focus [focus %d] done", hcamcorder->acquired_focus);
+                               hcamcorder->acquired_focus = 0;
+                       }
+
+                       mm_sound_unregister_focus(hcamcorder->sound_focus_id);
+                       _mmcam_dbg_warn("unregister sound focus done");
+                       hcamcorder->sound_focus_id = 0;
+               }
+
+               if (hcamcorder->sound_focus_watch_id > 0) {
+                       mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+                       _mmcam_dbg_warn("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(mm_sound_focus_type_e focus_type, mm_sound_focus_state_e focus_state,
+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);
@@ -3379,8 +3415,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_warn("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,9 +3425,6 @@ void _mmcamcorder_sound_focus_watch_cb(mm_sound_focus_type_e focus_type, mm_soun
 
        _MMCAMCORDER_LOCK_ASM(hcamcorder);
 
-       /* set value to inform a status is changed by asm */
-       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_FOCUS;
-
        /* check the reason */
        if (!strncmp(reason_for_change, "ringtone-voip", __MMCAMCORDER_FOCUS_CHANGE_REASON_LEN) ||
            !strncmp(reason_for_change, "ringtone-call", __MMCAMCORDER_FOCUS_CHANGE_REASON_LEN) ||
@@ -3407,27 +3440,26 @@ 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_warn("other process's FOCUS is released");
 
                msg.id = MM_MESSAGE_READY_TO_RESUME;
                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
 
-               _mmcam_dbg_log("Finish opeartion");
+               _mmcam_dbg_warn("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_warn("other process's FOCUS is acquired : Stop pipeline[state:%d]", current_state);
 
-               __mmcamcorder_force_stop(hcamcorder);
+               __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_FOCUS);
 
-               _mmcam_dbg_log("Finish opeartion. Pipeline is released");
+               _mmcam_dbg_warn("Finish opeartion. Pipeline is released");
        } else {
-               _mmcam_dbg_log("unknown focus state %d", focus_state);
+               _mmcam_dbg_warn("unknown focus state %d", focus_state);
        }
 
-       /* restore value */
-       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
-
        _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
 
+       _mmcam_dbg_warn("done");
+
        return;
 }
 
@@ -3451,15 +3483,11 @@ void _mmcamcorder_dpm_camera_policy_changed_cb(const char *name, const char *val
        if (!strcmp(value, "disallowed")) {
                _MMCAMCORDER_LOCK_ASM(hcamcorder);
 
-               /* set value to inform a status is changed by DPM */
-               hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_DPM;
-
-               __mmcamcorder_force_stop(hcamcorder);
-
-               /* restore value */
-               hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
+               __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_DPM);
 
                _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
+
+               _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "camera");
        }
 
        _mmcam_dbg_warn("done");
@@ -3475,7 +3503,7 @@ int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
        _MMCamcorderSubContext *sc = NULL;
        GstElement *pipeline = NULL;
 
-       _mmcam_dbg_log("handle : %x, type : %d", handle, type);
+       _mmcam_dbg_log("handle : %p, type : %d", handle, type);
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
@@ -3605,18 +3633,6 @@ void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
 }
 
 
-int _mmcamcorder_gst_set_state_async(MMHandleType handle, GstElement *pipeline, GstState target_state)
-{
-       GstStateChangeReturn setChangeReturn = GST_STATE_CHANGE_FAILURE;
-
-       _MMCAMCORDER_LOCK_GST_STATE(handle);
-       setChangeReturn = gst_element_set_state(pipeline, target_state);
-       _MMCAMCORDER_UNLOCK_GST_STATE(handle);
-
-       return setChangeReturn;
-}
-
-
 #ifdef _MMCAMCORDER_USE_SET_ATTR_CB
 static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data)
 {
@@ -3753,7 +3769,7 @@ void _mmcamcorder_video_current_framerate_init(MMHandleType handle)
 }
 
 
-void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
+void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder, int state_change_by_system)
 {
        int i = 0;
        int loop = 0;
@@ -3761,6 +3777,7 @@ void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
        int result = MM_ERROR_NONE;
        int cmd_try_count = 0;
        int current_state = MM_CAMCORDER_STATE_NONE;
+       _MMCamcorderMsgItem msg;
 
        mmf_return_if_fail(hcamcorder);
 
@@ -3782,7 +3799,37 @@ void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
 
        current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
 
-       _mmcam_dbg_warn("Force STOP MMFW Camcorder");
+       _mmcam_dbg_warn("Force STOP MMFW Camcorder by %d", state_change_by_system);
+
+       /* set state_change_by_system for state change message */
+       hcamcorder->state_change_by_system = state_change_by_system;
+
+       if (current_state >= MM_CAMCORDER_STATE_READY) {
+               _mmcam_dbg_warn("send state change started message to notify");
+
+               memset(&msg, 0x0, sizeof(_MMCamcorderMsgItem));
+
+               switch (state_change_by_system) {
+               case _MMCAMCORDER_STATE_CHANGE_BY_FOCUS:
+                       msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_ASM;
+                       break;
+               case _MMCAMCORDER_STATE_CHANGE_BY_RM:
+                       msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_RM;
+                       break;
+               case _MMCAMCORDER_STATE_CHANGE_BY_DPM:
+                       msg.id = MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_SECURITY;
+                       break;
+               default:
+                       break;
+               }
+
+               if (msg.id != 0) {
+                       msg.param.state.code = hcamcorder->interrupt_code;
+                       _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
+               } else {
+                       _mmcam_dbg_err("should not be reached here %d", state_change_by_system);
+               }
+       }
 
        for (loop = 0 ; current_state > MM_CAMCORDER_STATE_NULL && loop < __MMCAMCORDER_CMD_ITERATE_MAX * 3 ; loop++) {
                itr_cnt = __MMCAMCORDER_CMD_ITERATE_MAX;
@@ -3819,7 +3866,8 @@ void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
                        _mmcam_dbg_warn("Stop recording.");
 
                        while ((itr_cnt--) && ((result = _mmcamcorder_commit((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
-                               _mmcam_dbg_warn("Can't commit.(%x)", result);
+                               _mmcam_dbg_warn("Can't commit.(%x), cancel it.", result);
+                               _mmcamcorder_cancel((MMHandleType)hcamcorder);
                        }
 
                        break;
@@ -3828,9 +3876,8 @@ void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
                {
                        _mmcam_dbg_warn("Stop preview.");
 
-                       while ((itr_cnt--) && ((result = _mmcamcorder_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE)) {
+                       while ((itr_cnt--) && ((result = _mmcamcorder_stop((MMHandleType)hcamcorder)) != MM_ERROR_NONE))
                                _mmcam_dbg_warn("Can't stop preview.(%x)", result);
-                       }
 
                        break;
                }
@@ -3838,13 +3885,11 @@ void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
                {
                        _mmcam_dbg_warn("unrealize");
 
-                       if ((result = _mmcamcorder_unrealize((MMHandleType)hcamcorder)) != MM_ERROR_NONE) {
+                       if ((result = _mmcamcorder_unrealize((MMHandleType)hcamcorder)) != MM_ERROR_NONE)
                                _mmcam_dbg_warn("Can't unrealize.(%x)", result);
-                       }
 
                        break;
                }
-               case MM_CAMCORDER_STATE_NULL:
                default:
                        _mmcam_dbg_warn("Already stopped.");
                        break;
@@ -3853,6 +3898,9 @@ void __mmcamcorder_force_stop(mmf_camcorder_t *hcamcorder)
                current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
        }
 
+       /* restore */
+       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
+
        _mmcam_dbg_warn("Done.");
 
        return;
@@ -3866,8 +3914,8 @@ static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *
        gchar *msg_src_element = NULL;
        _MMCamcorderSubContext *sc = NULL;
 
-       return_val_if_fail(hcamcorder, FALSE);
-       return_val_if_fail(error, FALSE);
+       mmf_return_val_if_fail(hcamcorder, FALSE);
+       mmf_return_val_if_fail(error, FALSE);
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        mmf_return_val_if_fail(sc, FALSE);
 
@@ -3979,7 +4027,7 @@ static gint __mmcamcorder_gst_handle_core_error(MMHandleType handle, int code, G
 static gint __mmcamcorder_gst_handle_library_error(MMHandleType handle, int code, GstMessage *message)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
-       return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
        _mmcam_dbg_log("");
 
@@ -4055,6 +4103,8 @@ static gint __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int cod
 
                        _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
 
+                       _mmcamcorder_request_dpm_popup(hcamcorder->gdbus_conn, "microphone");
+
                        return MM_ERROR_POLICY_RESTRICTED;
                }
        }
@@ -4167,8 +4217,8 @@ static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage
        gchar *debug = NULL;
        GError *err = NULL;
 
-       return_val_if_fail(hcamcorder, FALSE);
-       return_val_if_fail(error, FALSE);
+       mmf_return_val_if_fail(hcamcorder, FALSE);
+       mmf_return_val_if_fail(error, FALSE);
 
        _mmcam_dbg_log("");
 
@@ -4251,33 +4301,81 @@ static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMe
        return MM_ERROR_NONE;
 }
 
-int _mmcamcorder_get_video_caps(MMHandleType handle, char **caps)
+/* Conditions below are from ASM conflict table of Tizen 2.4 */
+static int __mmcamcorder_simulate_asm_conflict_table(int session_type, int pid)
 {
-       GstPad *pad = NULL;
-       GstCaps *sink_caps = NULL;
-       _MMCamcorderSubContext *sc = NULL;
+       int ret = MM_ERROR_NONE;
+       char *stream_type = NULL;
+       char *ext_info = NULL;
+       int option = 0;
+
+       /* check previous acquired focus of other PID */
+       ret = mm_sound_get_stream_type_of_acquired_focus(FOCUS_FOR_BOTH, &stream_type, &option, &ext_info);
+       if (ret == MM_ERROR_NONE && stream_type) {
+               if (ext_info && (pid != atoi(ext_info))) { /* 'ext_info' should contain pid */
+                       if ((session_type == MM_SESSION_TYPE_CALL) ||
+                               (session_type == MM_SESSION_TYPE_VIDEOCALL) ||
+                               (session_type == MM_SESSION_TYPE_VOIP)) {
+                               /* case 1. if my session type is call/videocall/voip */
+                               if (!strcmp(stream_type, "call-voice") ||
+                                       !strcmp(stream_type, "call-video") ||
+                                       !strcmp(stream_type, "ringtone-call")) {
+                                       _mmcam_dbg_err("Blocked by session policy, stream_type[%s] of acquired focus", stream_type);
+                                       ret = MM_ERROR_POLICY_BLOCKED;
+                               }
+                       } else if ((session_type == MM_SESSION_TYPE_MEDIA) ||
+                               (session_type == MM_SESSION_TYPE_MEDIA_RECORD)) {
+                               /* case 2. if my session type is media */
+                               if (!strcmp(stream_type, "alarm") ||
+                                       !strcmp(stream_type, "ringtone-voip") ||
+                                       !strcmp(stream_type, "ringtone-call") ||
+                                       !strcmp(stream_type, "voip") ||
+                                       !strcmp(stream_type, "call-voice") ||
+                                       !strcmp(stream_type, "call-video")) {
+                                       _mmcam_dbg_err("Blocked by session policy, stream_type[%s] of acquired focus", stream_type);
+                                       ret = MM_ERROR_POLICY_BLOCKED;
+                               }
+                       }
+               } else {
+                       _mmcam_dbg_log("acquired focus is same process with it, skip it");
+               }
+       } else {
+               /* No data case */
+               _mmcam_dbg_warn("get stream type failed 0x%x, stream type %s, but ignore it",
+                       ret, stream_type ? stream_type : "NULL");
+               ret = MM_ERROR_NONE;
+       }
 
-       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;
+       if (stream_type) {
+               free(stream_type);
+               stream_type = NULL;
        }
 
-       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;
+       if (ext_info) {
+               free(ext_info);
+               ext_info = NULL;
        }
 
-       *caps = gst_caps_to_string(sink_caps);
-       _mmcam_dbg_err("video caps : %s", *caps);
-       gst_caps_unref(sink_caps);
+       return ret;
+}
+
 
-       return MM_ERROR_NONE;
+void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
+       const char *interface_name, const char *signal_name, int value)
+{
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+       mmf_return_if_fail(hcamcorder && object_name && interface_name && signal_name);
+
+       _mmcam_dbg_log("object %s, interface %s, signal %s, value %d",
+               object_name, interface_name, signal_name, value);
+
+       _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, object_name, interface_name, signal_name, value);
+
+       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)
@@ -4289,14 +4387,10 @@ rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
        mmf_return_val_if_fail((MMHandleType)hcamcorder, RM_CB_RESULT_OK);
 
        current_state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
-       if (current_state <= MM_CAMCORDER_STATE_NONE || current_state >= MM_CAMCORDER_STATE_NUM) {
-               _mmcam_dbg_err("Abnormal state. Or null handle. (%p, %d)", hcamcorder, current_state);
-       }
 
-       _MMCAMCORDER_LOCK_ASM(hcamcorder);
+       _mmcam_dbg_warn("current state %d (handle %p)", current_state, hcamcorder);
 
-       /* set value to inform a status is changed by RM */
-       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_RM;
+       _MMCAMCORDER_LOCK_ASM(hcamcorder);
 
        /* set RM event code for sending it to application */
        hcamcorder->interrupt_code = event_src;
@@ -4305,17 +4399,68 @@ rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
        switch (event_src) {
        case RM_CALLBACK_TYPE_RESOURCE_CONFLICT:
        case RM_CALLBACK_TYPE_RESOURCE_CONFLICT_UD:
-               __mmcamcorder_force_stop(hcamcorder);
+               __mmcamcorder_force_stop(hcamcorder, _MMCAMCORDER_STATE_CHANGE_BY_RM);
                break;
        default:
                break;
        }
 
-       /* restore value */
-       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_NORMAL;
-
        _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
 
        return cb_res;
 }
 #endif /* _MMCAMCORDER_RM_SUPPORT */
+
+
+int _mmcamcorder_manage_external_storage_state(MMHandleType handle, int storage_state)
+{
+       int ret = MM_ERROR_NONE;
+       int current_state = MM_CAMCORDER_STATE_NONE;
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+       _MMCamcorderMsgItem msg;
+
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       _mmcam_dbg_warn("storage state %d", storage_state);
+
+       /* check storage state */
+       if (storage_state != STORAGE_STATE_UNMOUNTABLE &&
+               storage_state != STORAGE_STATE_REMOVED) {
+               _mmcam_dbg_warn("nothing to do");
+               return MM_ERROR_NONE;
+       }
+
+       _MMCAMCORDER_LOCK_ASM(hcamcorder);
+
+       /* check recording state */
+       current_state = _mmcamcorder_get_state(handle);
+
+       _mmcam_dbg_warn("current_state %d", current_state);
+
+       if (current_state < MM_CAMCORDER_STATE_RECORDING) {
+               _mmcam_dbg_warn("no recording now");
+               goto _MANAGE_DONE;
+       }
+
+       /* check storage type */
+       if (hcamcorder->storage_info.type != STORAGE_TYPE_EXTERNAL) {
+               _mmcam_dbg_warn("external storage is not used");
+               goto _MANAGE_DONE;
+       }
+
+       /* cancel recording */
+       ret = _mmcamcorder_cancel(handle);
+
+       /* send error message */
+       msg.id = MM_MESSAGE_CAMCORDER_ERROR;
+       msg.param.code = MM_ERROR_OUT_OF_STORAGE;
+
+       _mmcamcorder_send_message(handle, &msg);
+
+_MANAGE_DONE:
+       _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
+
+       _mmcam_dbg_warn("done - ret 0x%x", ret);
+
+       return ret;
+}