From e5ab478585e02a615b8b94919efe0c5739c405a3 Mon Sep 17 00:00:00 2001 From: "backto.kim" Date: Wed, 11 Aug 2021 18:00:23 +0900 Subject: [PATCH] webrtc_source: enable loopback for filesrc 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 | 2 +- src/webrtc_source.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index eb9fc860..2673bd34 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 6faa920b..6a806861 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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; } -- 2.34.1