Bug fix - Recording is failed without setting filename
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index 855f456..61db73b 100644 (file)
@@ -869,6 +869,9 @@ int _mmcamcorder_realize(MMHandleType handle)
        int app_pid = 0;
        int resource_count = 0;
 #endif /* _MMCAMCORDER_RM_SUPPORT */
+       char *stream_type = NULL;
+       char *ext_info = NULL;
+       int option = 0;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
@@ -933,6 +936,37 @@ int _mmcamcorder_realize(MMHandleType handle)
                        /* do nothing */
                        _mmcam_dbg_log("SESSION_UNINTERRUPTIBLE - do nothing for sound focus");
                } else {
+                       /* check previous acquired focus */
+                       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 (!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]", stream_type);
+                                       ret = MM_ERROR_POLICY_BLOCKED;
+                               }
+                       } else {
+                               _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;
+                       }
+
+                       if (stream_type) {
+                               free(stream_type);
+                               stream_type = NULL;
+                       }
+
+                       if (ext_info) {
+                               free(ext_info);
+                               ext_info = NULL;
+                       }
+
+                       if (ret != MM_ERROR_NONE)
+                               goto _ERR_CAMCORDER_CMD_PRECON_AFTER_LOCK;
+
                        /* unset remained watch cb */
                        if (hcamcorder->sound_focus_watch_id > 0) {
                                mm_sound_unset_focus_watch_callback(hcamcorder->sound_focus_watch_id);
@@ -1742,15 +1776,18 @@ int _mmcamcorder_record(MMHandleType handle)
        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;
@@ -1767,8 +1804,15 @@ 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_handle) {
+       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) {
@@ -1783,7 +1827,8 @@ int _mmcamcorder_record(MMHandleType handle)
                        _mmcam_dbg_err("get DPM mic state failed, keep going...");
                }
        } else {
-               _mmcam_dbg_warn("NULL dpm_handle");
+               _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);