Unset focus watch callback when sound stream info is set
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index 5b80a1e..61e71a6 100644 (file)
@@ -399,6 +399,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,
@@ -423,16 +433,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);
@@ -492,27 +492,29 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        }
 
 #ifdef _MMCAMCORDER_MURPHY_SUPPORT
-       _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
+       if (info->videodev_type != MM_VIDEO_DEVICE_NONE) {
+               _MMCAMCORDER_LOCK_RESOURCE(hcamcorder);
 
-       if (hcamcorder->resource_manager.is_connected == FALSE) {
-               gint64 end_time = 0;
+               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...");
+                       /* 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);
+                       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;
-                       goto _ERR_DEFAULT_VALUE_INIT;
+                       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;
+                               goto _ERR_DEFAULT_VALUE_INIT;
+                       }
                }
-       }
 
-       _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
+               _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
+       }
 #endif /* _MMCAMCORDER_MURPHY_SUPPORT */
 
        /* Set initial state */
@@ -1496,6 +1498,10 @@ int _mmcamcorder_start(MMHandleType handle)
 
        _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;
@@ -2813,8 +2819,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");
+                                       }
                                }
                        }
                }
@@ -3271,7 +3281,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) {
@@ -3299,26 +3309,26 @@ 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);
 
-               _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 */
@@ -3326,6 +3336,8 @@ void _mmcamcorder_sound_focus_cb(int id, mm_sound_focus_type_e focus_type,
 
        _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
 
+       _mmcam_dbg_warn("done");
+
        return;
 }
 
@@ -3336,17 +3348,30 @@ 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;
                }
        }
@@ -3377,7 +3402,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) {
@@ -3405,20 +3430,20 @@ 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 released");
+               _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 acquired : 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);
 
-               _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 */
@@ -3426,6 +3451,8 @@ void _mmcamcorder_sound_focus_watch_cb(int id, mm_sound_focus_type_e focus_type,
 
        _MMCAMCORDER_UNLOCK_ASM(hcamcorder);
 
+       _mmcam_dbg_warn("done");
+
        return;
 }