webrtc_source: enable loopback for filesrc 67/262467/10 accepted/tizen/unified/20210813.125502 submit/tizen/20210813.072227
authorbackto.kim <backto.kim@samsung.com>
Wed, 11 Aug 2021 09:00:23 +0000 (18:00 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 13 Aug 2021 05:57:15 +0000 (05:57 +0000)
When the pipeline status becomes NULL, the decodebin destroys all of the added pads and associated probes.
so, the probe information related to loopback should be reinitialized when the pad in the decodebin is removed.

[Version] 0.2.77
[Issue Type] Improvement

Change-Id: I2e07ac17736304bf32b1d31bfa52d99e75613fdb

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

index eb9fc8607214e98b5159ab41950af0192437913e..2673bd34e19ae885f5bafdcb0bb400bc1f8dd310 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.76
+Version:    0.2.77
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 6faa920b9110dc20b324a93531b6d597e14c31f8..6a806861777be907a1d5da8f09b86103b2877094 100644 (file)
@@ -1782,6 +1782,7 @@ static void __filesrc_decodebin_pad_added_cb(GstElement *element, GstPad *pad, g
        const gchar *media_type = NULL;
        GstElement *payload = NULL;
        gboolean is_audio;
+       int av_idx;
 
        RET_IF(source == NULL, "source is NULL");
 
@@ -1796,8 +1797,9 @@ static void __filesrc_decodebin_pad_added_cb(GstElement *element, GstPad *pad, g
        }
 
        is_audio = (g_strrstr(media_type, "audio")) ? TRUE : FALSE;
+       av_idx = (is_audio) ? AV_IDX_AUDIO : AV_IDX_VIDEO;
 
-       if (source->av[is_audio ? AV_IDX_AUDIO : AV_IDX_VIDEO].src_pad_probe_id > 0) {
+       if (source->av[av_idx].src_pad_probe_id > 0) {
                LOG_INFO("Pipeline already built");
                __link_decodebin_with_payload(pad, source, is_audio, false);
                return;
@@ -1829,6 +1831,10 @@ static void __filesrc_decodebin_pad_added_cb(GstElement *element, GstPad *pad, g
                g_hash_table_remove(source->webrtc->gst.source_slots, GST_ELEMENT_NAME(source->bin));
                return;
        }
+
+       source->av[av_idx].render.need_decoding = true;
+       source->av[av_idx].render.appsrc_caps = gst_pad_get_current_caps(pad);
+       __add_probe_to_pad_for_render(source, av_idx, pad, __source_data_probe_cb);
 }
 
 static GstAutoplugSelectResult __filesrc_decodebin_autoplug_select_cb(GstElement *bin, GstPad *pad, GstCaps *caps, GstElementFactory* factory, gpointer udata)
@@ -1843,6 +1849,29 @@ static GstAutoplugSelectResult __filesrc_decodebin_autoplug_select_cb(GstElement
        return GST_AUTOPLUG_SELECT_TRY;
 }
 
+static void __filesrc_decodebin_pad_removed_cb(GstElement *element, GstPad *pad, gpointer data)
+{
+       webrtc_gst_slot_s *source = data;
+       int idx = 0;
+
+       RET_IF(source == NULL, "source is NULL");
+
+       if (GST_PAD_DIRECTION(pad) != GST_PAD_SRC)
+               return;
+
+       LOG_INFO("[%s] removed_pad[%s]", GST_ELEMENT_NAME(element), GST_PAD_NAME(pad));
+
+       for (idx = 0; idx < AV_IDX_MAX; idx++) {
+               if (source->av[idx].render.src_pad_probe_id > 0) {
+                       source->av[idx].render.src_pad_probe_id = 0;
+                       source->av[idx].render.src_pad = NULL;
+
+                       gst_caps_unref(source->av[idx].render.appsrc_caps);
+                       source->av[idx].render.appsrc_caps = NULL;
+               }
+       }
+}
+
 static int __build_filesrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 {
        GstElement *filesrc = NULL;
@@ -1870,6 +1899,7 @@ static int __build_filesrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
 
        g_signal_connect(decodebin, "autoplug-select", G_CALLBACK(__filesrc_decodebin_autoplug_select_cb), NULL);
        g_signal_connect(decodebin, "pad-added", G_CALLBACK(__filesrc_decodebin_pad_added_cb), (gpointer)source);
+       g_signal_connect(decodebin, "pad-removed", G_CALLBACK(__filesrc_decodebin_pad_removed_cb), (gpointer)source);
 
        return WEBRTC_ERROR_NONE;
 }