The error type of resource manager query is fixed
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index 18bec76..ae2dcbc 100644 (file)
 #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:                                                                |
@@ -161,6 +183,14 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        g_cond_init(&hcamcorder->task_thread_cond);
        hcamcorder->task_thread_state = _MMCAMCORDER_SOUND_STATE_NONE;
 
+       if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
+               /* init for gdbus */
+               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);
+       }
+
        /* create task thread */
        hcamcorder->task_thread = g_thread_try_new("MMCAM_TASK_THREAD",
                (GThreadFunc)_mmcamcorder_util_task_thread_func, (gpointer)hcamcorder, NULL);
@@ -196,6 +226,14 @@ 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();
 
@@ -563,6 +601,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);
 
@@ -603,7 +648,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 */
@@ -627,7 +671,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;
@@ -796,6 +840,16 @@ 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);
+       }
+
+       g_object_unref(hcamcorder->gdbus_conn);
+       hcamcorder->gdbus_conn = NULL;
+
        /* Release handle */
        memset(hcamcorder, 0x00, sizeof(mmf_camcorder_t));
        free(hcamcorder);
@@ -820,8 +874,6 @@ 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;
@@ -830,7 +882,7 @@ int _mmcamcorder_realize(MMHandleType handle)
        char *socket_path = NULL;
        int socket_path_len;
 #ifdef _MMCAMCORDER_RM_SUPPORT
-               int iret = RM_OK;
+       int iret = RM_OK;
 #endif /* _MMCAMCORDER_RM_SUPPORT */
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
@@ -850,7 +902,7 @@ 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;
@@ -928,7 +980,7 @@ int _mmcamcorder_realize(MMHandleType handle)
 #ifdef _MMCAMCORDER_RM_SUPPORT
        int preview_format = MM_PIXEL_FORMAT_NV12;
        int qret = RM_OK;
-       int qret_avail = RM_OK;
+       int qret_avail = 0; /* 0: not available, 1: available */
        rm_consumer_info rci;
        int app_pid = 0;
        int resource_count = 0;
@@ -970,7 +1022,7 @@ int _mmcamcorder_realize(MMHandleType handle)
 
                qret = rm_query(hcamcorder->rm_handle, RM_QUERY_ALLOCATION, &(hcamcorder->request_resources), &qret_avail);
 
-               if (qret != RM_OK || qret_avail != RM_OK) {
+               if (qret != RM_OK || qret_avail != 1) {
                        _mmcam_dbg_log("Resource manager main device request fail");
 
                        resource_count = 0;
@@ -1197,7 +1249,14 @@ int _mmcamcorder_realize(MMHandleType handle)
                goto _ERR_CAMCORDER_CMD;
        }
 
-       _mmcamcorder_set_state(handle, state_TO);
+       _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);
 
@@ -1264,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);
 
@@ -1284,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;
@@ -1381,9 +1438,16 @@ 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, state_TO);
+       _mmcamcorder_set_state(handle, MM_CAMCORDER_STATE_NULL);
 
        return MM_ERROR_NONE;
 
@@ -1401,8 +1465,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);
@@ -1425,7 +1487,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;
@@ -1435,22 +1497,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) {
@@ -1462,7 +1510,14 @@ 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);
+
+       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);
+       }
 
        _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
@@ -1500,8 +1555,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);
 
@@ -1520,7 +1573,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;
@@ -1530,9 +1583,12 @@ 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) {
+               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) {
                        _mmcam_dbg_warn("subscribe_id[%u] is remained. remove it.", hcamcorder->gdbus_info_sound.subscribe_id);
@@ -1547,13 +1603,9 @@ int _mmcamcorder_stop(MMHandleType handle)
                }
                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);
+               /* 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);
@@ -1578,7 +1630,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);
 
@@ -1632,7 +1683,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);
 
@@ -1661,8 +1712,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("");
@@ -1680,7 +1729,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;
@@ -1690,7 +1739,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);
 
@@ -1711,10 +1760,8 @@ 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;
+       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1733,7 +1780,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;
@@ -1768,7 +1815,20 @@ 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);
+
+       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);
 
@@ -1797,8 +1857,7 @@ 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;
+       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1817,7 +1876,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;
@@ -1827,7 +1886,17 @@ 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);
+
+       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);
 
@@ -1848,9 +1917,7 @@ 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;
+       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1869,7 +1936,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;
@@ -1882,9 +1949,22 @@ 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);
+
+       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_set_state(handle, state_TO);
+       _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
 
        return MM_ERROR_NONE;
 
@@ -1903,9 +1983,7 @@ 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;
+       int device_state = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -1924,7 +2002,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;
@@ -1934,7 +2012,20 @@ 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);
+
+       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);
 
@@ -3231,7 +3322,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;