From c97126212fe2ae12c9c932319090c0d74ed1da3d Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Thu, 3 Oct 2024 17:16:08 +0200 Subject: [PATCH] urisourcebin: Streamline event forwarding code Instead of two different functions for copying events and rewriting the stream-start event, just have a single one. This is needed, since we want to do both of those in one go, with the pad lock taken. Part-of: --- .../gst/playback/gsturisourcebin.c | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/subprojects/gst-plugins-base/gst/playback/gsturisourcebin.c b/subprojects/gst-plugins-base/gst/playback/gsturisourcebin.c index efe48ef8e8..bc54a04feb 100644 --- a/subprojects/gst-plugins-base/gst/playback/gsturisourcebin.c +++ b/subprojects/gst-plugins-base/gst/playback/gsturisourcebin.c @@ -717,11 +717,28 @@ gst_uri_source_bin_get_property (GObject * object, guint prop_id, } } +typedef struct +{ + GstPad *target_pad; + gboolean rewrite_stream_start; +} CopyEventData; + static gboolean copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data) { - GstPad *gpad = GST_PAD_CAST (user_data); + CopyEventData *data = user_data; + GstPad *gpad = data->target_pad; + if (data->rewrite_stream_start && + GST_EVENT_TYPE (*event) == GST_EVENT_STREAM_START) { + GstStructure *s; + /* This is a temporary hack to notify downstream decodebin3 to *not* + * plug in an extra parsebin */ + *event = gst_event_make_writable (*event); + s = (GstStructure *) gst_event_get_structure (*event); + gst_structure_set (s, "urisourcebin-parsed-data", G_TYPE_BOOLEAN, TRUE, + NULL); + } GST_DEBUG_OBJECT (gpad, "store sticky event from %" GST_PTR_FORMAT " %" GST_PTR_FORMAT, pad, *event); @@ -1208,19 +1225,6 @@ setup_multiqueue (GstURISourceBin * urisrc, ChildSrcPadInfo * info, gst_element_sync_state_with_parent (info->multiqueue); } -static gboolean -mark_stream_start_parsed (GstPad * pad, GstEvent ** event, gpointer user_data) -{ - if (GST_EVENT_TYPE (*event) == GST_EVENT_STREAM_START) { - GstStructure *s; - *event = gst_event_make_writable (*event); - s = (GstStructure *) gst_event_get_structure (*event); - gst_structure_set (s, "urisourcebin-parsed-data", G_TYPE_BOOLEAN, TRUE, - NULL); - } - return TRUE; -} - /* Called with lock held */ static OutputSlotInfo * new_output_slot (ChildSrcPadInfo * info, GstPad * originating_pad) @@ -1231,6 +1235,7 @@ new_output_slot (ChildSrcPadInfo * info, GstPad * originating_pad) GstElement *queue = NULL; const gchar *elem_name; gboolean use_downloadbuffer; + CopyEventData copy_data = { 0, }; GST_DEBUG_OBJECT (urisrc, "use_queue2:%d use_downloadbuffer:%d, demuxer:%d, originating_pad:%" @@ -1260,14 +1265,18 @@ new_output_slot (ChildSrcPadInfo * info, GstPad * originating_pad) slot->queue_sinkpad = gst_element_request_pad_simple (info->multiqueue, "sink_%u"); srcpad = gst_pad_get_single_internal_link (slot->queue_sinkpad); - if (urisrc->is_adaptive || (slot->linked_info - && slot->linked_info->demuxer_is_parsebin)) { - /* This is a temporary hack to notify downstream decodebin3 to *not* - * plug in an extra parsebin */ - gst_pad_sticky_events_foreach (originating_pad, mark_stream_start_parsed, - NULL); + if (urisrc->is_adaptive || (info->demuxer_is_parsebin)) { + copy_data.rewrite_stream_start = TRUE; } - gst_pad_sticky_events_foreach (originating_pad, copy_sticky_events, srcpad); + copy_data.target_pad = slot->queue_sinkpad; + gst_pad_sticky_events_foreach (originating_pad, copy_sticky_events, + ©_data); + copy_data.target_pad = srcpad; + gst_pad_sticky_events_foreach (originating_pad, copy_sticky_events, + ©_data); + + } + slot->output_pad = create_output_pad (slot, srcpad); gst_object_unref (srcpad); gst_pad_link (originating_pad, slot->queue_sinkpad); @@ -1467,6 +1476,7 @@ static void expose_output_pad (GstURISourceBin * urisrc, GstPad * pad) { GstPad *target; + CopyEventData copy_data = { 0, }; if (gst_object_has_as_parent (GST_OBJECT (pad), GST_OBJECT (urisrc))) return; /* Pad is already exposed */ @@ -1474,7 +1484,8 @@ expose_output_pad (GstURISourceBin * urisrc, GstPad * pad) target = gst_ghost_pad_get_target (GST_GHOST_PAD (pad)); gst_pad_set_active (pad, TRUE); - gst_pad_sticky_events_foreach (target, copy_sticky_events, pad); + copy_data.target_pad = pad; + gst_pad_sticky_events_foreach (target, copy_sticky_events, ©_data); gst_object_unref (target); GST_URI_SOURCE_BIN_LOCK (urisrc);