Udpate for force stop function
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index a494057..76193cf 100644 (file)
 #define DPM_ALLOWED                             1
 #define DPM_DISALLOWED                          0
 
-#ifdef _MMCAMCORDER_MURPHY_SUPPORT
-#define __MMCAMCORDER_RESOURCE_WAIT_TIME        5
-#endif /* _MMCAMCORDER_MURPHY_SUPPORT */
-
-#define __MMCAMCORDER_DBUS_OBJECT               "/org/tizen/MMCamcorder"
-#define __MMCAMCORDER_DBUS_INTERFACE_CAMERA     "org.tizen.MMCamcorder.Camera"
-#define __MMCAMCORDER_DBUS_INTERFACE_RECORDER   "org.tizen.MMCamcorder.Recorder"
-#define __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED "DeviceStateChanged"
-
-enum {
-       CAMERA_DEVICE_STATE_NULL = 0,   /**< Not opened */
-       CAMERA_DEVICE_STATE_OPENED,     /**< Opened */
-       CAMERA_DEVICE_STATE_WORKING     /**< Now previewing or capturing or is being used for video recording */
-};
-
-enum {
-       RECORDER_TYPE_AUDIO = 0,        /**< Audio only recorder */
-       RECORDER_TYPE_VIDEO             /**< Video recorder (audio is optional) */
-};
-
-enum {
-       RECORDER_DEVICE_STATE_NULL = 0,     /**< No recorder is working */
-       RECORDER_DEVICE_STATE_RECORDING,    /**< Now recording */
-       RECORDER_DEVICE_STATE_PAUSED        /**< All recordings are paused */
-};
-
-
 /*---------------------------------------------------------------------------------------
 |    LOCAL FUNCTION PROTOTYPES:                                                                |
 ---------------------------------------------------------------------------------------*/
@@ -149,7 +122,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;
 
@@ -165,6 +138,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);
@@ -181,12 +155,15 @@ 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);
        }
@@ -226,14 +203,6 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                goto _ERR_DEFAULT_VALUE_INIT;
        }
 
-       /* 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_DEFAULT_VALUE_INIT;
-       }
-
        /* get DPM handle for camera/microphone restriction */
        hcamcorder->dpm_handle = dpm_manager_create();
 
@@ -425,6 +394,16 @@ 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
+               /* 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 */
        } else {
                _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
                        CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
@@ -449,16 +428,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);
@@ -518,27 +487,13 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        }
 
 #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);
-
-               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;
+       if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
+               ret = _mmcamcorder_resource_wait_for_connection(&hcamcorder->resource_manager, (void *)hcamcorder);
+               if (ret != MM_ERROR_NONE) {
+                       _mmcam_dbg_err("failed to connect resource manager");
                        goto _ERR_DEFAULT_VALUE_INIT;
                }
        }
-
-       _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
        /* Set initial state */
@@ -592,6 +547,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);
@@ -829,6 +785,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);
@@ -847,9 +804,6 @@ int _mmcamcorder_destroy(MMHandleType handle)
                g_cond_clear(&hcamcorder->gdbus_info_solo_sound.sync_cond);
        }
 
-       g_object_unref(hcamcorder->gdbus_conn);
-       hcamcorder->gdbus_conn = NULL;
-
        /* Release handle */
        memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
        free(hcamcorder);
@@ -880,9 +834,16 @@ int _mmcamcorder_realize(MMHandleType handle)
        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);
@@ -908,12 +869,20 @@ int _mmcamcorder_realize(MMHandleType handle)
                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,
@@ -927,7 +896,7 @@ int _mmcamcorder_realize(MMHandleType handle)
                        /* acquire sound focus */
                        _mmcam_dbg_log("PAUSE_OTHERS - acquire sound focus");
 
-                       ret_sound = mm_sound_acquire_focus(0, FOCUS_FOR_BOTH, NULL);
+                       ret_sound = mm_sound_acquire_focus(hcamcorder->sound_focus_id, FOCUS_FOR_BOTH, NULL);
                        if (ret_sound != MM_ERROR_NONE) {
                                _mmcam_dbg_err("mm_sound_acquire_focus failed [0x%x]", ret_sound);
 
@@ -977,83 +946,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 */
@@ -1072,6 +969,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);
        }
 
@@ -1147,6 +1045,9 @@ int _mmcamcorder_realize(MMHandleType handle)
                                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 {
@@ -1155,7 +1056,30 @@ int _mmcamcorder_realize(MMHandleType handle)
                } else {
                        _mmcam_dbg_warn("NULL dpm_handle");
                }
+
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
+               /* check connection */
+               if (hcamcorder->resource_manager.is_connected == FALSE) {
+                       _mmcam_dbg_warn("resource manager disconnected before, try to reconnect");
+
+                       /* release remained resource */
+                       _mmcamcorder_resource_manager_deinit(&hcamcorder->resource_manager);
+
+                       /* init resource manager and wait for connection */
+                       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_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+                       }
+
+                       ret = _mmcamcorder_resource_wait_for_connection(&hcamcorder->resource_manager, (void *)hcamcorder);
+                       if (ret != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("failed to connect resource manager");
+                               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+                       }
+               }
+
                ret = _mmcamcorder_resource_create_resource_set(&hcamcorder->resource_manager);
                if (ret != MM_ERROR_NONE) {
                        goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
@@ -1172,10 +1096,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) {
@@ -1188,7 +1108,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");
@@ -1218,6 +1139,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 */
@@ -1251,13 +1252,6 @@ int _mmcamcorder_realize(MMHandleType handle)
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
 
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
-               int value = hcamcorder->device_type << 16 | CAMERA_DEVICE_STATE_OPENED;
-
-               _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-                       __MMCAMCORDER_DBUS_INTERFACE_CAMERA, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, value);
-       }
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
@@ -1274,22 +1268,6 @@ _ERR_CAMCORDER_CMD:
                }
        }
 #endif /* _MMCAMCORDER_MURPHY_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(0, hcamcorder->acquired_focus, NULL);
-               _mmcam_dbg_warn("release sound focus [focus %d] done", hcamcorder->acquired_focus);
-               hcamcorder->acquired_focus = 0;
-       }
-
 #ifdef _MMCAMCORDER_RM_SUPPORT
        if (hcamcorder->rm_handle) {
                if (hcamcorder->returned_devices.allocated_num > 0) {
@@ -1304,6 +1282,7 @@ _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
                        if (iret != RM_OK)
                                _mmcam_dbg_err("Resource deallocation request failed ");
                }
+
                /* unregister RM */
                int ires = rm_unregister(hcamcorder->rm_handle);
                if (ires != RM_OK)
@@ -1312,6 +1291,21 @@ _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
        }
 #endif /* _MMCAMCORDER_RM_SUPPORT*/
 
+_ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK:
+       _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
+
+       if (hcamcorder->sound_focus_watch_id > 0) {
+               mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
+               _mmcam_dbg_warn("unset sound focus watch cb [id %d] done", hcamcorder->sound_focus_watch_id);
+               hcamcorder->sound_focus_watch_id = 0;
+       }
+
+       if (hcamcorder->acquired_focus > 0) {
+               mm_sound_release_focus(hcamcorder->sound_focus_id, hcamcorder->acquired_focus, NULL);
+               _mmcam_dbg_warn("release sound focus [focus %d] done", hcamcorder->acquired_focus);
+               hcamcorder->acquired_focus = 0;
+       }
+
 _ERR_CAMCORDER_CMD_PRECON:
        _mmcam_dbg_err("Realize fail (type %d, state %d, ret %x)", hcamcorder->type, state, ret);
 
@@ -1357,13 +1351,15 @@ int _mmcamcorder_unrealize(MMHandleType handle)
        }
 
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
+       _mmcam_dbg_warn("lock resource - cb calling %d", hcamcorder->resource_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_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) {
@@ -1387,10 +1383,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
@@ -1428,7 +1425,7 @@ int _mmcamcorder_unrealize(MMHandleType handle)
                }
 
                if (hcamcorder->acquired_focus > 0) {
-                       mm_sound_release_focus(0, hcamcorder->acquired_focus, NULL);
+                       mm_sound_release_focus(hcamcorder->sound_focus_id, hcamcorder->acquired_focus, NULL);
                        _mmcam_dbg_warn("release sound focus [focus %d] done", hcamcorder->acquired_focus);
                        hcamcorder->acquired_focus = 0;
                }
@@ -1438,13 +1435,6 @@ int _mmcamcorder_unrealize(MMHandleType handle)
                hcamcorder->acquired_focus = 0;
        }
 
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
-               int value = hcamcorder->device_type << 16 | CAMERA_DEVICE_STATE_NULL;
-
-               _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-                       __MMCAMCORDER_DBUS_INTERFACE_CAMERA, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, value);
-       }
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
@@ -1512,28 +1502,15 @@ int _mmcamcorder_start(MMHandleType handle)
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
 
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE) {
-               int value = hcamcorder->device_type << 16 | CAMERA_DEVICE_STATE_WORKING;
-
-               _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-                       __MMCAMCORDER_DBUS_INTERFACE_CAMERA, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, value);
-       }
+       /* 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:
@@ -1586,8 +1563,6 @@ int _mmcamcorder_stop(MMHandleType handle)
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_READY);
 
        if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
-               int value = hcamcorder->device_type << 16 | CAMERA_DEVICE_STATE_OPENED;
-
                /* unsubscribe remained unsubscribed signal */
                g_mutex_lock(&hcamcorder->gdbus_info_sound.sync_mutex);
                if (hcamcorder->gdbus_info_sound.subscribe_id > 0) {
@@ -1602,10 +1577,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);
-
-               /* emit signal for camera device state */
-               _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-                       __MMCAMCORDER_DBUS_INTERFACE_CAMERA, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, value);
        }
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
@@ -1761,7 +1732,6 @@ int _mmcamcorder_record(MMHandleType handle)
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
        int dpm_mic_state = DPM_ALLOWED;
-       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1796,6 +1766,9 @@ int _mmcamcorder_record(MMHandleType handle)
                        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 {
@@ -1817,19 +1790,6 @@ int _mmcamcorder_record(MMHandleType handle)
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_RECORDING);
 
-       if (state == MM_CAMCORDER_STATE_PREPARE)
-               device_state = RECORDER_DEVICE_STATE_NULL << 8 | RECORDER_DEVICE_STATE_RECORDING;
-       else
-               device_state = RECORDER_DEVICE_STATE_PAUSED << 8 | RECORDER_DEVICE_STATE_RECORDING;
-
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE)
-               device_state = RECORDER_TYPE_VIDEO << 16 | device_state;
-       else
-               device_state = RECORDER_TYPE_AUDIO << 16 | device_state;
-
-       _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-               __MMCAMCORDER_DBUS_INTERFACE_RECORDER, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, device_state);
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
@@ -1857,7 +1817,6 @@ int _mmcamcorder_pause(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1888,16 +1847,6 @@ int _mmcamcorder_pause(MMHandleType handle)
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PAUSED);
 
-       device_state = RECORDER_DEVICE_STATE_RECORDING << 8 | RECORDER_DEVICE_STATE_PAUSED;
-
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE)
-               device_state = RECORDER_TYPE_VIDEO << 16 | device_state;
-       else
-               device_state = RECORDER_TYPE_AUDIO << 16 | device_state;
-
-       _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-               __MMCAMCORDER_DBUS_INTERFACE_RECORDER, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, device_state);
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
@@ -1917,7 +1866,6 @@ int _mmcamcorder_commit(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1951,19 +1899,6 @@ int _mmcamcorder_commit(MMHandleType handle)
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
 
-       if (state == MM_CAMCORDER_STATE_RECORDING)
-               device_state = RECORDER_DEVICE_STATE_RECORDING << 8 | RECORDER_DEVICE_STATE_NULL;
-       else
-               device_state = RECORDER_DEVICE_STATE_PAUSED << 8 | RECORDER_DEVICE_STATE_NULL;
-
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE)
-               device_state = RECORDER_TYPE_VIDEO << 16 | device_state;
-       else
-               device_state = RECORDER_TYPE_AUDIO << 16 | device_state;
-
-       _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-               __MMCAMCORDER_DBUS_INTERFACE_RECORDER, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, device_state);
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
@@ -1983,7 +1918,6 @@ int _mmcamcorder_cancel(MMHandleType handle)
 {
        int ret = MM_ERROR_NONE;
        int state = MM_CAMCORDER_STATE_NONE;
-       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -2014,19 +1948,6 @@ int _mmcamcorder_cancel(MMHandleType handle)
 
        _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_PREPARE);
 
-       if (state == MM_CAMCORDER_STATE_RECORDING)
-               device_state = RECORDER_DEVICE_STATE_RECORDING << 8 | RECORDER_DEVICE_STATE_NULL;
-       else
-               device_state = RECORDER_DEVICE_STATE_PAUSED << 8 | RECORDER_DEVICE_STATE_NULL;
-
-       if (hcamcorder->type == MM_CAMCORDER_MODE_VIDEO_CAPTURE)
-               device_state = RECORDER_TYPE_VIDEO << 16 | device_state;
-       else
-               device_state = RECORDER_TYPE_AUDIO << 16 | device_state;
-
-       _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, __MMCAMCORDER_DBUS_OBJECT,
-               __MMCAMCORDER_DBUS_INTERFACE_RECORDER, __MMCAMCORDER_DBUS_SIGNAL_STATE_CHANGED, device_state);
-
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
@@ -2131,6 +2052,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);
@@ -2567,6 +2513,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;
@@ -2582,9 +2545,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) {
@@ -2620,20 +2583,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;
@@ -2877,8 +2826,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");
+                                       }
                                }
                        }
                }
@@ -3295,9 +3248,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) {
@@ -3335,7 +3288,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) {
@@ -3345,9 +3298,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) ||
@@ -3363,33 +3313,32 @@ 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 acquired [type %d, new focus %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;
 }
 
@@ -3400,21 +3349,37 @@ void _mmcamcorder_sound_signal_callback(mm_sound_signal_name_t signal, int value
 
        mmf_return_if_fail(hcamcorder);
 
-       _mmcam_dbg_log("sound signal %d - value %d", signal, value);
+       _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_log("watch cb id %d", hcamcorder->sound_focus_watch_id);
+               _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, NULL);
+                               _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;
+               }
 
-               /* unregister watch callback */
                if (hcamcorder->sound_focus_watch_id > 0) {
                        mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
-                       _mmcam_dbg_log("unset watch cb done");
+                       _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");
@@ -3438,7 +3403,7 @@ void _mmcamcorder_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_type,
                return;
        }
 
-       _mmcam_dbg_log("sound focus watch callback : id %d, focus state %d, reason %s",
+       _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) {
@@ -3448,9 +3413,6 @@ void _mmcamcorder_sound_focus_watch_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) ||
@@ -3466,27 +3428,26 @@ void _mmcamcorder_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_type,
        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;
 }
 
@@ -3510,15 +3471,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");
@@ -3664,18 +3621,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)
 {
@@ -3812,7 +3757,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;
@@ -3841,7 +3786,10 @@ 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;
 
        for (loop = 0 ; current_state > MM_CAMCORDER_STATE_NULL && loop < __MMCAMCORDER_CMD_ITERATE_MAX * 3 ; loop++) {
                itr_cnt = __MMCAMCORDER_CMD_ITERATE_MAX;
@@ -3878,7 +3826,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;
@@ -3912,6 +3861,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;
@@ -4114,6 +4066,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;
                }
        }
@@ -4310,33 +4264,23 @@ static gint __mmcamcorder_gst_handle_resource_warning(MMHandleType handle, GstMe
        return MM_ERROR_NONE;
 }
 
-int _mmcamcorder_get_video_caps(MMHandleType handle, char **caps)
+
+void _mmcamcorder_emit_signal(MMHandleType handle, const char *object_name,
+       const char *interface_name, const char *signal_name, int value)
 {
-       GstPad *pad = NULL;
-       GstCaps *sink_caps = NULL;
-       _MMCamcorderSubContext *sc = NULL;
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
-       sc = MMF_CAMCORDER_SUBCONTEXT(handle);
-       _mmcam_dbg_warn("Entered ");
-       pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "sink");
-       if (!pad) {
-               _mmcam_dbg_err("static pad is NULL");
-               return MM_ERROR_CAMCORDER_INVALID_STATE;
-       }
+       mmf_return_if_fail(hcamcorder && object_name && interface_name && signal_name);
 
-       sink_caps = gst_pad_get_current_caps(pad);
-       gst_object_unref(pad);
-       if (!sink_caps) {
-               _mmcam_dbg_err("fail to get caps");
-               return MM_ERROR_CAMCORDER_INVALID_STATE;
-       }
+       _mmcam_dbg_log("object %s, interface %s, signal %s, value %d",
+               object_name, interface_name, signal_name, value);
 
-       *caps = gst_caps_to_string(sink_caps);
-       _mmcam_dbg_err("video caps : %s", *caps);
-       gst_caps_unref(sink_caps);
+       _mmcamcorder_emit_dbus_signal(hcamcorder->gdbus_conn, object_name, interface_name, signal_name, value);
 
-       return MM_ERROR_NONE;
+       return;
 }
+
+
 #ifdef _MMCAMCORDER_RM_SUPPORT
 rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
        rm_device_request_s *info, void* cb_data)
@@ -4354,9 +4298,6 @@ rm_cb_result _mmcamcorder_rm_callback(int handle, rm_callback_type event_src,
 
        _MMCAMCORDER_LOCK_ASM(hcamcorder);
 
-       /* set value to inform a status is changed by RM */
-       hcamcorder->state_change_by_system = _MMCAMCORDER_STATE_CHANGE_BY_RM;
-
        /* set RM event code for sending it to application */
        hcamcorder->interrupt_code = event_src;
 
@@ -4364,15 +4305,12 @@ 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;