webrtc_source: Use list to carry elements for loopback pipeline 61/265461/4
authorbackto.kim <backto.kim@samsung.com>
Wed, 20 Oct 2021 02:49:19 +0000 (11:49 +0900)
committerbackto.kim <backto.kim@samsung.com>
Thu, 21 Oct 2021 07:49:24 +0000 (16:49 +0900)
[Version] 0.2.137
[Issue Type] Refactoring

Change-Id: I35530c0bb7fdb89bdcdde5897d068a8acfaa599c

packaging/capi-media-webrtc.spec
src/webrtc_source.c

index a12b938ba2659297183e95970b8b0351b0450c20..75a38075b1d52e54d7a0ec14cf4cf15cba46a5cc 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.136
+Version:    0.2.137
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index bf68f4b04c8da19c1f0d94e92836880eb7b2457b..66d52c01a5bc97898e76d1139afc4402e3fbb48b 100644 (file)
@@ -1338,7 +1338,6 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, switch_src_list);
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(switch_src_list);
@@ -1408,7 +1407,6 @@ static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return ret;
@@ -1475,7 +1473,6 @@ static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool us
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return ret;
@@ -1537,7 +1534,6 @@ static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return ret;
@@ -1595,7 +1591,6 @@ static int __build_custom_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return ret;
@@ -1659,7 +1654,6 @@ static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return ret;
@@ -1723,7 +1717,6 @@ static int __build_filesrc_bin(webrtc_gst_slot_s *source, media_type_e media_typ
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return WEBRTC_ERROR_INVALID_OPERATION;
@@ -1922,7 +1915,6 @@ static int __create_rest_of_elements_for_filesrc_pipeline(webrtc_gst_slot_s *sou
        return WEBRTC_ERROR_NONE;
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return WEBRTC_ERROR_INVALID_OPERATION;
@@ -2303,7 +2295,6 @@ static int __complete_mediapacketsrc_from_raw_format(webrtc_s *webrtc, webrtc_gs
        return _set_ghost_pad_target(*src_pad, capsfilter, true);
 
 exit_with_remove_from_bin:
-       /* elements will be dereferenced */
        __remove_elements_from_bin(source->bin, element_list);
        SAFE_G_LIST_FREE(element_list);
        return ret;
@@ -3720,6 +3711,7 @@ static int __build_loopback_audiosink(webrtc_gst_slot_s *source, GstElement *lin
        GstElement *audiosink;
        GstElement *audioconvert;
        GstElement *audioresample;
+       GList *element_list = NULL;
        int ret = WEBRTC_ERROR_NONE;
 
        RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
@@ -3728,53 +3720,52 @@ static int __build_loopback_audiosink(webrtc_gst_slot_s *source, GstElement *lin
 
        webrtc = source->webrtc;
 
-       if (!(audiosink = _create_element(webrtc->ini.rendering_sink.a_sink_element, NULL)))
+       if (!(audioconvert = _create_element(DEFAULT_ELEMENT_AUDIOCONVERT, NULL)))
                return WEBRTC_ERROR_INVALID_OPERATION;
+       APPEND_ELEMENT(element_list, audioconvert);
+
+       if (!(audioresample = _create_element(DEFAULT_ELEMENT_AUDIORESAMPLE, NULL)))
+               goto exit;
+       APPEND_ELEMENT(element_list, audioresample);
+
+       if (!(audiosink = _create_element(webrtc->ini.rendering_sink.a_sink_element, NULL)))
+               goto exit;
+       APPEND_ELEMENT(element_list, audiosink);
 
        if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(audiosink)), "stream-properties")) {
                if (source->sound_stream_info.type) {
                        ret = _apply_stream_info(audiosink, source->sound_stream_info.type, source->sound_stream_info.index);
-                       if (ret != WEBRTC_ERROR_NONE) {
-                               SAFE_GST_OBJECT_UNREF(audiosink);
-                               return WEBRTC_ERROR_INVALID_OPERATION;
-                       }
+                       if (ret != WEBRTC_ERROR_NONE)
+                               goto exit;
                }
        }
        g_object_set(G_OBJECT(audiosink), "sync", FALSE, NULL);
 
-       if (!(audioconvert = _create_element(DEFAULT_ELEMENT_AUDIOCONVERT, NULL))) {
-               SAFE_GST_OBJECT_UNREF(audiosink);
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
-
-       if (!(audioresample = _create_element(DEFAULT_ELEMENT_AUDIORESAMPLE, NULL))) {
-               SAFE_GST_OBJECT_UNREF(audiosink);
-               SAFE_GST_OBJECT_UNREF(audioconvert);
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       if (!__add_elements_to_bin(GST_BIN(source->av[AV_IDX_AUDIO].render.pipeline), element_list))
+               goto exit;
 
-       gst_bin_add_many(GST_BIN(source->av[AV_IDX_AUDIO].render.pipeline), audioconvert, audioresample, audiosink, NULL);
+       if (!__link_elements(element_list))
+               goto exit_with_remove_from_bin;
 
-       if (!gst_element_sync_state_with_parent(audioconvert)) {
-               LOG_ERROR("failed to gst_element_sync_state_with_parent() for [%s]", GST_ELEMENT_NAME(audioconvert));
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
-       if (!gst_element_sync_state_with_parent(audioresample)) {
-               LOG_ERROR("failed to gst_element_sync_state_with_parent() for [%s]", GST_ELEMENT_NAME(audioresample));
-               return WEBRTC_ERROR_INVALID_OPERATION;
+       if (!gst_element_link(link_with, audioconvert)) {
+               LOG_ERROR("failed to gst_element_link(), [%s] - [%s]", GST_ELEMENT_NAME(link_with), GST_ELEMENT_NAME(audioconvert));
+               goto exit_with_remove_from_bin;
        }
 
-       if (!gst_element_sync_state_with_parent(audiosink)) {
-               LOG_ERROR("failed to gst_element_sync_state_with_parent() for [%s]", GST_ELEMENT_NAME(audiosink));
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       if (!__sync_elements_state_with_parent(element_list))
+               goto exit_with_remove_from_bin;
 
-       if (!gst_element_link_many(link_with, audioconvert, audioresample, audiosink, NULL)) {
-               LOG_ERROR("failed to gst_element_link_many()");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       SAFE_G_LIST_FREE(element_list);
 
        return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+       __remove_elements_from_bin(source->bin, element_list);
+       SAFE_G_LIST_FREE(element_list);
+       return WEBRTC_ERROR_INVALID_OPERATION;
+exit:
+       SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref);
+       return WEBRTC_ERROR_INVALID_OPERATION;
 }
 
 static int __build_loopback_videosink(webrtc_gst_slot_s *source, GstElement *link_with)
@@ -3783,6 +3774,7 @@ static int __build_loopback_videosink(webrtc_gst_slot_s *source, GstElement *lin
        const char *videosink_factory_name;
        GstElement *videosink;
        GstElement *videoconvert;
+       GList *element_list = NULL;
 
        RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
        RET_VAL_IF(link_with == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "link_with is NULL");
@@ -3805,24 +3797,22 @@ static int __build_loopback_videosink(webrtc_gst_slot_s *source, GstElement *lin
                return WEBRTC_ERROR_INVALID_OPERATION;
        }
 
-       if (!(videosink = _create_element(videosink_factory_name, NULL)))
-               return WEBRTC_ERROR_INVALID_OPERATION;
-
-       if (!(videoconvert = _create_element(DEFAULT_ELEMENT_VIDEOCONVERT, NULL))) {
-               SAFE_GST_OBJECT_UNREF(videosink);
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
-
 #ifndef TIZEN_TV
        if (source->display->type == WEBRTC_DISPLAY_TYPE_OVERLAY && webrtc->ini.resource_acquisition.video_overlay) {
                int ret;
-               if ((ret = _acquire_resource_for_type(webrtc, MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY)) != WEBRTC_ERROR_NONE) {
-                       SAFE_GST_OBJECT_UNREF(videosink);
-                       SAFE_GST_OBJECT_UNREF(videoconvert);
+               if ((ret = _acquire_resource_for_type(webrtc, MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_OVERLAY)) != WEBRTC_ERROR_NONE)
                        return ret;
-               }
        }
 #endif
+
+       if (!(videoconvert = _create_element(DEFAULT_ELEMENT_VIDEOCONVERT, NULL)))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       APPEND_ELEMENT(element_list, videoconvert);
+
+       if (!(videosink = _create_element(videosink_factory_name, NULL)))
+               goto exit;
+       APPEND_ELEMENT(element_list, videosink);
+
        if (source->display->type == WEBRTC_DISPLAY_TYPE_OVERLAY ||
                source->display->type == WEBRTC_DISPLAY_TYPE_ECORE_WL) {
                gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(videosink), source->display->overlay_surface_id);
@@ -3840,26 +3830,33 @@ static int __build_loopback_videosink(webrtc_gst_slot_s *source, GstElement *lin
                _connect_and_append_signal(&source->signals, (GObject *)videosink, "handoff", G_CALLBACK(_video_stream_decoded_cb), source->display);
        }
 
-       gst_bin_add_many(GST_BIN(source->av[AV_IDX_VIDEO].render.pipeline), videoconvert, videosink, NULL);
+       if (!__add_elements_to_bin(GST_BIN(source->av[AV_IDX_VIDEO].render.pipeline), element_list))
+               goto exit;
 
-       if (!gst_element_sync_state_with_parent(videoconvert)) {
-               LOG_ERROR("failed to gst_element_sync_state_with_parent() for [%s]", GST_ELEMENT_NAME(videoconvert));
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       if (!__link_elements(element_list))
+               goto exit_with_remove_from_bin;
 
-       if (!gst_element_sync_state_with_parent(videosink)) {
-               LOG_ERROR("failed to gst_element_sync_state_with_parent() for [%s]", GST_ELEMENT_NAME(videosink));
-               return WEBRTC_ERROR_INVALID_OPERATION;
+       if (!gst_element_link(link_with, videoconvert)) {
+               LOG_ERROR("failed to gst_element_link(), [%s] - [%s]", GST_ELEMENT_NAME(link_with), GST_ELEMENT_NAME(videoconvert));
+               goto exit_with_remove_from_bin;
        }
 
-       if (!gst_element_link_many(link_with, videoconvert, videosink, NULL)) {
-               LOG_ERROR("failed to gst_element_link_many()");
-               return WEBRTC_ERROR_INVALID_OPERATION;
-       }
+       if (!__sync_elements_state_with_parent(element_list))
+               goto exit_with_remove_from_bin;
 
        source->display->sink_element = videosink;
 
+       SAFE_G_LIST_FREE(element_list);
+
        return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+       __remove_elements_from_bin(source->bin, element_list);
+       SAFE_G_LIST_FREE(element_list);
+       return WEBRTC_ERROR_INVALID_OPERATION;
+exit:
+       SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref);
+       return WEBRTC_ERROR_INVALID_OPERATION;
 }
 
 //LCOV_EXCL_START