From de7e2c9b6b8f58aa59ee7377d446deeb980def6b Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Tue, 12 Jul 2022 01:55:54 +1000 Subject: [PATCH] adaptivedemux2: stream: Set period has_next_period flag before EOS Before sending EOS, update the period's has_next_period flag and/or create the next period. This closes a race where the output loop might receive the EOS event and either push it downstream (causing premature EOS), or receive it and try and switch to the next period before that period is completely set up. Part-of: --- .../adaptivedemux2/gstadaptivedemux-stream.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c index 3e40d24c0c..c9dc24f81d 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c @@ -1518,6 +1518,19 @@ gst_adaptive_demux2_stream_end_of_manifest (GstAdaptiveDemux2Stream * stream) GST_DEBUG_OBJECT (stream, "Combined flow %s", gst_flow_get_name (combined)); + if (gst_adaptive_demux_has_next_period (demux)) { + if (combined == GST_FLOW_EOS) { + GST_DEBUG_OBJECT (stream, "Next period available, advancing"); + gst_adaptive_demux_advance_period (demux); + } else { + /* Ensure the 'has_next_period' flag is set on the period before + * pushing EOS to the stream, so that the output loop knows not + * to actually output the event */ + GST_DEBUG_OBJECT (stream, "Marking current period has a next one"); + demux->input_period->has_next_period = TRUE; + } + } + if (demux->priv->outputs) { GstEvent *eos = gst_event_new_eos (); @@ -1530,11 +1543,6 @@ gst_adaptive_demux2_stream_end_of_manifest (GstAdaptiveDemux2Stream * stream) GST_ERROR_OBJECT (demux, "Can't push EOS on non-exposed pad"); gst_adaptive_demux2_stream_error (stream); } - - if (combined == GST_FLOW_EOS && gst_adaptive_demux_has_next_period (demux)) { - GST_DEBUG_OBJECT (stream, "Next period available, advancing"); - gst_adaptive_demux_advance_period (demux); - } } static gboolean