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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7609>
This commit is contained in:
Edward Hervey 2024-10-03 17:16:08 +02:00 committed by GStreamer Marge Bot
parent f130382b08
commit c97126212f

View file

@ -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 static gboolean
copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data) 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, GST_DEBUG_OBJECT (gpad,
"store sticky event from %" GST_PTR_FORMAT " %" GST_PTR_FORMAT, pad, "store sticky event from %" GST_PTR_FORMAT " %" GST_PTR_FORMAT, pad,
*event); *event);
@ -1208,19 +1225,6 @@ setup_multiqueue (GstURISourceBin * urisrc, ChildSrcPadInfo * info,
gst_element_sync_state_with_parent (info->multiqueue); 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 */ /* Called with lock held */
static OutputSlotInfo * static OutputSlotInfo *
new_output_slot (ChildSrcPadInfo * info, GstPad * originating_pad) new_output_slot (ChildSrcPadInfo * info, GstPad * originating_pad)
@ -1231,6 +1235,7 @@ new_output_slot (ChildSrcPadInfo * info, GstPad * originating_pad)
GstElement *queue = NULL; GstElement *queue = NULL;
const gchar *elem_name; const gchar *elem_name;
gboolean use_downloadbuffer; gboolean use_downloadbuffer;
CopyEventData copy_data = { 0, };
GST_DEBUG_OBJECT (urisrc, GST_DEBUG_OBJECT (urisrc,
"use_queue2:%d use_downloadbuffer:%d, demuxer:%d, originating_pad:%" "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 = slot->queue_sinkpad =
gst_element_request_pad_simple (info->multiqueue, "sink_%u"); gst_element_request_pad_simple (info->multiqueue, "sink_%u");
srcpad = gst_pad_get_single_internal_link (slot->queue_sinkpad); srcpad = gst_pad_get_single_internal_link (slot->queue_sinkpad);
if (urisrc->is_adaptive || (slot->linked_info if (urisrc->is_adaptive || (info->demuxer_is_parsebin)) {
&& slot->linked_info->demuxer_is_parsebin)) { copy_data.rewrite_stream_start = TRUE;
/* 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);
} }
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,
&copy_data);
copy_data.target_pad = srcpad;
gst_pad_sticky_events_foreach (originating_pad, copy_sticky_events,
&copy_data);
}
slot->output_pad = create_output_pad (slot, srcpad); slot->output_pad = create_output_pad (slot, srcpad);
gst_object_unref (srcpad); gst_object_unref (srcpad);
gst_pad_link (originating_pad, slot->queue_sinkpad); gst_pad_link (originating_pad, slot->queue_sinkpad);
@ -1467,6 +1476,7 @@ static void
expose_output_pad (GstURISourceBin * urisrc, GstPad * pad) expose_output_pad (GstURISourceBin * urisrc, GstPad * pad)
{ {
GstPad *target; GstPad *target;
CopyEventData copy_data = { 0, };
if (gst_object_has_as_parent (GST_OBJECT (pad), GST_OBJECT (urisrc))) if (gst_object_has_as_parent (GST_OBJECT (pad), GST_OBJECT (urisrc)))
return; /* Pad is already exposed */ 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)); target = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
gst_pad_set_active (pad, TRUE); 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, &copy_data);
gst_object_unref (target); gst_object_unref (target);
GST_URI_SOURCE_BIN_LOCK (urisrc); GST_URI_SOURCE_BIN_LOCK (urisrc);