Fix deadlock if sound stream info is set after audiosrc is created
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_attribute.c
index 331ac68..e6c056a 100644 (file)
@@ -1534,17 +1534,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 +1542,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,
                },
                {
@@ -4606,12 +4606,18 @@ 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);
 
+       stream_type = value->value.s_val;
+       if (!stream_type) {
+               _mmcam_dbg_err("NULL string");
+               return FALSE;
+       }
+
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        if (!sc || !sc->encode_element ||
            !sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) {
@@ -4620,17 +4626,16 @@ bool _mmcamcorder_commit_sound_stream_info(MMHandleType handle, int attr_idx, co
        }
 
        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);
+       _mmcam_dbg_log("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, value->value.i_val);
+       return _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
 }