Enhance session backward compatibility
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_attribute.c
index e679985..c92fcc8 100644 (file)
@@ -29,7 +29,6 @@
 #include <gst/video/colorbalance.h>
 #include <gst/video/cameracontrol.h>
 #include <gst/video/videooverlay.h>
-#include <gst/wayland/wayland.h>
 
 /*-----------------------------------------------------------------------
 |    MACRO DEFINITIONS:                                                        |
@@ -1534,17 +1533,6 @@ _mmcamcorder_alloc_attribute(MMHandleType handle, MMCamPreset *info)
                        NULL,
                },
                {
-                       MM_CAM_SOUND_STREAM_TYPE,
-                       "sound-stream-type",
-                       MMF_VALUE_TYPE_STRING,
-                       MM_ATTRS_FLAG_RW,
-                       {(void*)NULL},
-                       MM_ATTRS_VALID_TYPE_NONE,
-                       {0},
-                       {0},
-                       NULL,
-               },
-               {
                        MM_CAM_SOUND_STREAM_INDEX,
                        "sound-stream-index",
                        MMF_VALUE_TYPE_INT,
@@ -1553,6 +1541,17 @@ _mmcamcorder_alloc_attribute(MMHandleType handle, MMCamPreset *info)
                        MM_ATTRS_VALID_TYPE_INT_RANGE,
                        {.int_min = -1},
                        {.int_max = _MMCAMCORDER_MAX_INT},
+                       NULL,
+               },
+               {
+                       MM_CAM_SOUND_STREAM_TYPE,
+                       "sound-stream-type",
+                       MMF_VALUE_TYPE_STRING,
+                       MM_ATTRS_FLAG_RW,
+                       {(void*)NULL},
+                       MM_ATTRS_VALID_TYPE_NONE,
+                       {0},
+                       {0},
                        _mmcamcorder_commit_sound_stream_info,
                },
                {
@@ -1576,6 +1575,17 @@ _mmcamcorder_alloc_attribute(MMHandleType handle, MMCamPreset *info)
                        {0},
                        {0},
                        NULL,
+               },
+               {
+                       MM_CAM_GDBUS_CONNECTION,
+                       "gdbus-connection",
+                       MMF_VALUE_TYPE_DATA,
+                       MM_ATTRS_FLAG_RW,
+                       {(void*)NULL},
+                       MM_ATTRS_VALID_TYPE_NONE,
+                       {0},
+                       {0},
+                       NULL,
                }
        };
 
@@ -1720,6 +1730,7 @@ _mmcamcorder_set_attributes(MMHandleType handle, char **err_attr_name, const cha
        MMHandleType attrs = 0;
        int ret = MM_ERROR_NONE;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+       va_list var_args_copy;
 
        mmf_return_val_if_fail(handle, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
        /*mmf_return_val_if_fail(err_attr_name, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);*/
@@ -1729,19 +1740,25 @@ _mmcamcorder_set_attributes(MMHandleType handle, char **err_attr_name, const cha
                return MM_ERROR_CAMCORDER_CMD_IS_RUNNING;
        }
 
+       /* copy var_args to keep original var_args */
+       va_copy(var_args_copy, var_args);
+
        attrs = MMF_CAMCORDER_ATTRS(handle);
        if (attrs) {
                ret = __mmcamcorder_check_valid_pair(handle, err_attr_name, attribute_name, var_args);
        } else {
-               _mmcam_dbg_err("handle 0x%x, attrs is NULL, attr name [%s]", handle, attribute_name);
+               _mmcam_dbg_err("handle %p, attrs is NULL, attr name [%s]", handle, attribute_name);
                ret = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
        }
 
        if (ret == MM_ERROR_NONE) {
                hcamcorder->error_code = MM_ERROR_NONE;
-               ret = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, var_args);
+               /* In 64bit environment, unexpected result is returned if var_args is used again. */
+               ret = mm_attrs_set_valist(attrs, err_attr_name, attribute_name, var_args_copy);
        }
 
+       va_end(var_args_copy);
+
        _MMCAMCORDER_UNLOCK_CMD(handle);
 
        if (ret != MM_ERROR_NONE) {
@@ -1987,6 +2004,7 @@ bool _mmcamcorder_commit_capture_break_cont_shot(MMHandleType handle, int attr_i
        const char *videosrc_name = NULL;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
+       _MMCamcorderImageInfo *info = NULL;
        GstCameraControl *control = NULL;
        type_element *VideosrcElement = NULL;
 
@@ -2005,7 +2023,18 @@ bool _mmcamcorder_commit_capture_break_cont_shot(MMHandleType handle, int attr_i
        if (!sc)
                return TRUE;
 
+       info = sc->info_image;
+       if (!info) {
+               _mmcam_dbg_err("info image is NULL");
+               return FALSE;
+       }
+
        if (ivalue && current_state == MM_CAMCORDER_STATE_CAPTURING) {
+               if (info->capture_send_count > 0) {
+                       info->capturing = FALSE;
+                       _mmcam_dbg_warn("capturing -> FALSE and skip capture callback since now");
+               }
+
                if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
                        _mmcam_dbg_warn("Can't cast Video source into camera control.");
                        return TRUE;
@@ -2546,9 +2575,7 @@ bool _mmcamcorder_commit_camera_ptz_type(MMHandleType handle, int attr_idx, cons
                        }
                }
 
-               if (item == NULL) {
-                       _mmcam_dbg_warn("failed to find tilt control channel");
-               }
+               _mmcam_dbg_warn("failed to find tilt control channel");
        }
 
        return FALSE;
@@ -2613,9 +2640,7 @@ bool _mmcamcorder_commit_camera_pan(MMHandleType handle, int attr_idx, const mmf
                        }
                }
 
-               if (item == NULL) {
-                       _mmcam_dbg_warn("failed to find pan control channel");
-               }
+               _mmcam_dbg_warn("failed to find pan control channel");
        }
 
        return FALSE;
@@ -2680,9 +2705,7 @@ bool _mmcamcorder_commit_camera_tilt(MMHandleType handle, int attr_idx, const mm
                        }
                }
 
-               if (item == NULL) {
-                       _mmcam_dbg_warn("failed to find tilt control channel");
-               }
+               _mmcam_dbg_warn("failed to find tilt control channel");
        }
 
        return FALSE;
@@ -3372,16 +3395,11 @@ bool _mmcamcorder_commit_image_encoder_quality(MMHandleType handle, int attr_idx
 
 bool _mmcamcorder_commit_target_filename(MMHandleType handle, int attr_idx, const mmf_value_t *value)
 {
-       _MMCamcorderSubContext *sc = NULL;
-       const char *filename = NULL;
        int size = 0;
+       const char *filename = NULL;
 
        mmf_return_val_if_fail(handle && value, FALSE);
 
-       sc = MMF_CAMCORDER_SUBCONTEXT(handle);
-       if (!sc)
-               return TRUE;
-
        /* get string */
        filename = mmf_value_get_string(value, &size);
        if (filename == NULL) {
@@ -3389,22 +3407,7 @@ bool _mmcamcorder_commit_target_filename(MMHandleType handle, int attr_idx, cons
                return FALSE;
        }
 
-       if (sc->info_video) {
-               SAFE_G_FREE(sc->info_video->filename);
-               sc->info_video->filename = g_strdup(filename);
-               if (sc->info_video->filename == NULL) {
-                       _mmcam_dbg_err("failed to strdup filename [%s]", filename);
-                       return FALSE;
-               }
-       }
-
-       if (sc->encode_element && sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
-               _mmcam_dbg_log("new file location set.[%s] filesink %p", filename, sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst);
-               MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, "location", filename);
-               _mmcam_dbg_log("new file location set.(%s)", filename);
-       } else {
-               _mmcam_dbg_log("element is not created yet. [%s] will be set later...", filename);
-       }
+       _mmcam_dbg_log("set filename [%s]", filename);
 
        return TRUE;
 }
@@ -3783,11 +3786,11 @@ bool _mmcamcorder_commit_display_mode(MMHandleType handle, int attr_idx, const m
        if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "waylandsink")) {
                _mmcam_dbg_log("Commit : display mode [%d]", value->value.i_val);
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "display-mode", value->value.i_val);
-               return TRUE;
        } else {
-               _mmcam_dbg_warn("Commit : This element [%s] does not support display mode", videosink_name);
-               return FALSE;
+               _mmcam_dbg_warn("[%s] does not support display mode, but no error", videosink_name);
        }
+
+       return TRUE;
 }
 
 
@@ -3877,11 +3880,11 @@ bool _mmcamcorder_commit_display_visible(MMHandleType handle, int attr_idx, cons
                !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "evasimagesink")) {
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "visible", value->value.i_val);
                _mmcam_dbg_log("Set visible [%d] done.", value->value.i_val);
-               return TRUE;
        } else {
-               _mmcam_dbg_warn("videosink[%s] does not support VISIBLE.", videosink_name);
-               return FALSE;
+               _mmcam_dbg_warn("[%s] does not support VISIBLE, but no error", videosink_name);
        }
+
+       return TRUE;
 }
 
 
@@ -3922,11 +3925,11 @@ bool _mmcamcorder_commit_display_geometry_method(MMHandleType handle, int attr_i
            !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "evasimagesink")) {
                method = value->value.i_val;
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "display-geometry-method", method);
-               return TRUE;
        } else {
-               _mmcam_dbg_warn("videosink[%s] does not support geometry method.", videosink_name);
-               return FALSE;
+               _mmcam_dbg_warn("[%s] does not support geometry method, but no error", videosink_name);
        }
+
+       return TRUE;
 }
 
 
@@ -4043,12 +4046,11 @@ bool _mmcamcorder_commit_display_rect(MMHandleType handle, int attr_idx, const m
                                        NULL);
                        }
                }
-
-               return TRUE;
        } else {
-               _mmcam_dbg_warn("videosink[%s] does not support display rect.", videosink_name);
-               return FALSE;
+               _mmcam_dbg_warn("[%s] does not support display rect, but no error", videosink_name);
        }
+
+       return TRUE;
 }
 
 
@@ -4522,41 +4524,75 @@ bool _mmcamcorder_commit_pid_for_sound_focus(MMHandleType handle, int attr_idx,
 
        new_pid = value->value.i_val;
 
-       _mmcam_dbg_log("Commit : pid %d, current sound_focus_register %d, sound_focus_id %d",
-               new_pid, hcamcorder->sound_focus_register, hcamcorder->sound_focus_id);
+       _mmcam_dbg_warn("Commit : pid %d, current focus id %d, subscribe id %u",
+               new_pid, hcamcorder->sound_focus_id, hcamcorder->sound_focus_subscribe_id);
 
-       /* unregister sound focus before set new one */
-       if (hcamcorder->sound_focus_register && hcamcorder->sound_focus_id > 0) {
-               if (MM_ERROR_NONE != mm_sound_unregister_focus(hcamcorder->sound_focus_id)) {
-                       _mmcam_dbg_err("mm_sound_unregister_focus[id %d] failed", hcamcorder->sound_focus_id);
+       /* unregister sound focus and unsubscribe sound signal before set new one */
+       if (hcamcorder->sound_focus_id > 0) {
+               mm_sound_unregister_focus(hcamcorder->sound_focus_id);
+               _mmcam_dbg_log("unregister sound focus done");
+               hcamcorder->sound_focus_id = 0;
+       }
+
+       if (hcamcorder->sound_focus_subscribe_id > 0) {
+               mm_sound_unsubscribe_signal(hcamcorder->sound_focus_subscribe_id);
+               _mmcam_dbg_log("unsubscribe sound signal done");
+               hcamcorder->sound_focus_subscribe_id = 0;
+       }
+
+       ret = _mm_session_util_read_information(new_pid, &hcamcorder->session_type, &hcamcorder->session_flags);
+       if (ret == MM_ERROR_NONE) {
+               if (hcamcorder->session_type == MM_SESSION_TYPE_REPLACED_BY_STREAM) {
+                       hcamcorder->sound_focus_register = FALSE;
+                       _mmcam_dbg_warn("no need to use sound focus internally");
                } else {
-                       _mmcam_dbg_log("mm_sound_unregister_focus[id %d] done", hcamcorder->sound_focus_id);
+                       /* check my session type : allow only media & call series here */
+                       if ((hcamcorder->session_type != MM_SESSION_TYPE_MEDIA) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_MEDIA_RECORD) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_CALL) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_VIDEOCALL) &&
+                               (hcamcorder->session_type != MM_SESSION_TYPE_VOIP)) {
+                               _mmcam_dbg_err("Blocked by session policy, my session_type[%s]", hcamcorder->session_type);
+                               hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
+                               return FALSE;
+                       }
+
+                       ret = mm_sound_focus_get_id(&hcamcorder->sound_focus_id);
+                       if (ret != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("mm_sound_focus_get_id failed");
+                               hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
+                               return FALSE;
+                       }
+
+                       ret = mm_sound_register_focus_for_session(hcamcorder->sound_focus_id,
+                               new_pid, "media", _mmcamcorder_sound_focus_cb, hcamcorder);
+                       if (ret != MM_ERROR_NONE) {
+                               _mmcam_dbg_err("mm_sound_register_focus_for_session failed 0x%x", ret);
+                               hcamcorder->sound_focus_id = 0;
+                               hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
+                               return FALSE;
+                       }
+
+                       hcamcorder->sound_focus_register = TRUE;
+
+                       _mmcam_dbg_log("mm_sound_register_focus_for_session done - id %d, session type %d, flags 0x%x",
+                               hcamcorder->sound_focus_id, hcamcorder->session_type, hcamcorder->session_flags);
                }
        } else {
-               _mmcam_dbg_log("no need to unregister sound focus");
-       }
+               hcamcorder->session_type = 0;
+               hcamcorder->session_flags = 0;
+               hcamcorder->sound_focus_register = TRUE;
 
-       /* register sound focus */
-       if (hcamcorder->sound_focus_register) {
-               hcamcorder->sound_focus_id = 0;
-               if (MM_ERROR_NONE != mm_sound_focus_get_id(&hcamcorder->sound_focus_id)) {
-                       _mmcam_dbg_err("mm_sound_focus_get_uniq failed");
-                       hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
-                       return FALSE;
-               }
+               _mmcam_dbg_warn("read session info failed. sound focus watch cb will be set.");
 
-               ret = mm_sound_register_focus_for_session(hcamcorder->sound_focus_id,
-                       new_pid, "media", _mmcamcorder_sound_focus_cb, hcamcorder);
+               ret = mm_sound_subscribe_signal_for_daemon(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS,
+                       new_pid, &hcamcorder->sound_focus_subscribe_id,
+                       (mm_sound_signal_callback)_mmcamcorder_sound_signal_callback, (void*)hcamcorder);
                if (ret != MM_ERROR_NONE) {
-                       _mmcam_dbg_err("mm_sound_register_focus failed");
+                       _mmcam_dbg_err("subscribe sound signal failed [0x%x]", ret);
                        hcamcorder->error_code = MM_ERROR_POLICY_BLOCKED;
                        return FALSE;
                }
-
-               _mmcam_dbg_log("mm_sound_register_focus done - id %d, session type %d, flags 0x%x",
-                       hcamcorder->sound_focus_id, hcamcorder->session_type, hcamcorder->session_flags);
-       } else {
-               _mmcam_dbg_log("no need to register sound focus");
        }
 
        return TRUE;
@@ -4565,31 +4601,39 @@ bool _mmcamcorder_commit_pid_for_sound_focus(MMHandleType handle, int attr_idx,
 
 bool _mmcamcorder_commit_sound_stream_info(MMHandleType handle, int attr_idx, const mmf_value_t *value)
 {
+       int stream_index = 0;
        char *stream_type = NULL;
-       int stream_type_len = 0;
        _MMCamcorderSubContext *sc = NULL;
 
        mmf_return_val_if_fail(handle && value, FALSE);
 
-       sc = MMF_CAMCORDER_SUBCONTEXT(handle);
-       if (!sc || !sc->encode_element ||
-           !sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) {
-               _mmcam_dbg_log("audiosrc element is not initialized, it will be set later");
-               return TRUE;
+       stream_type = value->value.s_val;
+       if (!stream_type) {
+               _mmcam_dbg_err("NULL string");
+               return FALSE;
        }
 
        mm_camcorder_get_attributes(handle, NULL,
-               MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len,
+               MMCAM_SOUND_STREAM_INDEX, &stream_index,
                NULL);
-
-       if (stream_type == NULL) {
-               _mmcam_dbg_err("stream type is not set");
+       if (stream_index < 0) {
+               _mmcam_dbg_err("invalid stream index %d", stream_index);
                return FALSE;
        }
 
-       _mmcam_dbg_log("Commit : sound stream info - type %s", stream_type);
+       /* unset watch callback if existed */
+       _mmcamcorder_sound_signal_callback(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 1, (void *)handle);
 
-       return _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, value->value.i_val);
+       sc = MMF_CAMCORDER_SUBCONTEXT(handle);
+       if (!sc || !sc->encode_element ||
+           !sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) {
+               _mmcam_dbg_warn("audiosrc element is not initialized, it will be set later");
+               return TRUE;
+       }
+
+       _mmcam_dbg_warn("Commit : sound stream info - type %s, index %d", stream_type, stream_index);
+
+       return _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
 }
 
 
@@ -4655,7 +4699,6 @@ bool _mmcamcorder_set_attribute_to_camsensor(MMHandleType handle)
                MM_CAM_CAMERA_WDR,
                MM_CAM_FILTER_CONTRAST,
                MM_CAM_FILTER_HUE,
-               MM_CAM_STROBE_MODE,
                MM_CAM_DETECT_MODE
        };
 
@@ -4671,7 +4714,7 @@ bool _mmcamcorder_set_attribute_to_camsensor(MMHandleType handle)
 
        mmf_return_val_if_fail(hcamcorder, FALSE);
 
-       _mmcam_dbg_log("Set all attribute again.");
+       _mmcam_dbg_log("commit some attributes again");
 
        attr = (mmf_attrs_t *)MMF_CAMCORDER_ATTRS(handle);
        if (attr == NULL) {
@@ -4712,6 +4755,45 @@ bool _mmcamcorder_set_attribute_to_camsensor(MMHandleType handle)
 }
 
 
+bool _mmcamcorder_set_attribute_to_camsensor2(MMHandleType handle)
+{
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+       mmf_attrs_t *attr = NULL;
+
+       unsigned int i = 0;
+       int ret = TRUE;
+       int attr_idxs[] = {
+               MM_CAM_STROBE_MODE
+       };
+
+       mmf_return_val_if_fail(hcamcorder, FALSE);
+
+       _mmcam_dbg_log("commit some attribute again[2]");
+
+       attr = (mmf_attrs_t *)MMF_CAMCORDER_ATTRS(handle);
+       if (attr == NULL) {
+               _mmcam_dbg_err("Get attribute handle failed.");
+               return FALSE;
+       } else {
+               _mmcam_dbg_log("attribute count(%d)", attr->count);
+
+               for (i = 0 ; i < ARRAY_SIZE(attr_idxs) ; i++) {
+                       if (__mmcamcorder_attrs_is_supported((MMHandleType)attr, attr_idxs[i]))
+                               mmf_attribute_set_modified(&(attr->items[attr_idxs[i]]));
+               }
+
+               if (mmf_attrs_commit((MMHandleType)attr) == -1)
+                       ret = FALSE;
+               else
+                       ret = TRUE;
+       }
+
+       _mmcam_dbg_log("Done.");
+
+       return ret;
+}
+
+
 int _mmcamcorder_lock_readonly_attributes(MMHandleType handle)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);