From 12b689f6b5f3b5b8dd496e1a1e528bb96d0e04d1 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Wed, 8 Feb 2023 12:02:45 +0100 Subject: [PATCH] adaptivedemux2: Fix early seeking When seeking is handled by the collection posting thread, there is a possibility that some leftover data will be pushed by the stream thread. Properly detect and reject those early segments (and buffers) by comparing it to the main segment seqnum Part-of: --- .../ext/adaptivedemux2/gstadaptivedemux-track.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-track.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-track.c index b620772..d3fe0dd 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-track.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-track.c @@ -510,6 +510,18 @@ _track_sink_chain_function (GstPad * pad, GstObject * parent, TRACKS_LOCK (demux); + /* Discard buffers that are received outside of a valid segment. This can + * happen if a flushing seek (which resets the track segment seqnums) was + * received but the stream is still providing buffers before returning. + */ + if (track->input_segment_seqnum == GST_SEQNUM_INVALID) { + GST_DEBUG_OBJECT (pad, + "Dropping buffer because we do not have a valid input segment"); + gst_buffer_unref (buffer); + TRACKS_UNLOCK (demux); + return GST_FLOW_OK; + } + ts = GST_BUFFER_DTS_OR_PTS (buffer); /* Buffers coming out of parsebin *should* always be timestamped (it's the @@ -659,6 +671,14 @@ _track_sink_event_function (GstPad * pad, GstObject * parent, GstEvent * event) return TRUE; } + if (seg_seqnum != demux->priv->segment_seqnum) { + GST_DEBUG_OBJECT (pad, "Ignoring non-current segment"); + gst_event_unref (event); + TRACKS_UNLOCK (demux); + + return TRUE; + } + track->input_segment_seqnum = seg_seqnum; gst_event_copy_segment (event, &track->input_segment); if (track->input_segment.rate >= 0) -- 2.7.4