adaptivedemux2: Handle early key-unit seek

Is a seek is done on stream-collection post, there are no selected streams
yet. Therefore none would be chosen to adjust the key-unit seek.

If no streams are selected, fallback to a default stream (i.e. one which has
track(s) with GST_STREAM_FLAG_SELECT).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3914>
This commit is contained in:
Edward Hervey 2023-02-08 17:24:18 +01:00 committed by GStreamer Marge Bot
parent 39c8b060f4
commit 2c9aef64c0
3 changed files with 101 additions and 73 deletions

View file

@ -199,6 +199,7 @@ gboolean gst_adaptive_demux_get_live_seek_range (GstAdaptiveDemux * demux,
gboolean gst_adaptive_demux2_stream_in_live_seek_range (GstAdaptiveDemux * demux, gboolean gst_adaptive_demux2_stream_in_live_seek_range (GstAdaptiveDemux * demux,
GstAdaptiveDemux2Stream * stream); GstAdaptiveDemux2Stream * stream);
gboolean gst_adaptive_demux2_stream_is_selected_locked (GstAdaptiveDemux2Stream *stream); gboolean gst_adaptive_demux2_stream_is_selected_locked (GstAdaptiveDemux2Stream *stream);
gboolean gst_adaptive_demux2_stream_is_default_locked (GstAdaptiveDemux2Stream *stream);
gboolean gst_adaptive_demux_has_next_period (GstAdaptiveDemux * demux); gboolean gst_adaptive_demux_has_next_period (GstAdaptiveDemux * demux);
void gst_adaptive_demux_advance_period (GstAdaptiveDemux * demux); void gst_adaptive_demux_advance_period (GstAdaptiveDemux * demux);

View file

@ -2229,6 +2229,20 @@ gst_adaptive_demux2_stream_is_selected_locked (GstAdaptiveDemux2Stream * stream)
return FALSE; return FALSE;
} }
gboolean
gst_adaptive_demux2_stream_is_default_locked (GstAdaptiveDemux2Stream * stream)
{
GList *tmp;
for (tmp = stream->tracks; tmp; tmp = tmp->next) {
GstAdaptiveDemuxTrack *track = tmp->data;
if (track->flags & GST_STREAM_FLAG_SELECT)
return TRUE;
}
return FALSE;
}
/** /**
* gst_adaptive_demux2_stream_is_selected: * gst_adaptive_demux2_stream_is_selected:
* @stream: A #GstAdaptiveDemux2Stream * @stream: A #GstAdaptiveDemux2Stream

View file

@ -2267,9 +2267,14 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux,
GST_ADAPTIVE_DEMUX_SEGMENT_LOCK (demux); GST_ADAPTIVE_DEMUX_SEGMENT_LOCK (demux);
if (IS_SNAP_SEEK (flags)) {
GstAdaptiveDemux2Stream *default_stream = NULL;
GstAdaptiveDemux2Stream *stream = NULL;
GList *iter;
/* /*
* Handle snap seeks as follows: * Handle snap seeks as follows:
* 1) do the snap seeking a (random) active stream * 1) do the snap seeking a (random) active stream
* 1.1) If none are active yet (early-seek), pick a random default one
* 2) use the final position on this stream to seek * 2) use the final position on this stream to seek
* on the other streams to the same position * on the other streams to the same position
* *
@ -2278,8 +2283,6 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux,
* position. * position.
*/ */
GstAdaptiveDemux2Stream *stream = NULL;
GList *iter;
/* Pick a random active stream on which to do the stream seek */ /* Pick a random active stream on which to do the stream seek */
for (iter = demux->output_period->streams; iter; iter = iter->next) { for (iter = demux->output_period->streams; iter; iter = iter->next) {
GstAdaptiveDemux2Stream *cand = iter->data; GstAdaptiveDemux2Stream *cand = iter->data;
@ -2287,9 +2290,15 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux,
stream = cand; stream = cand;
break; break;
} }
if (default_stream == NULL
&& gst_adaptive_demux2_stream_is_default_locked (cand))
default_stream = cand;
} }
if (stream && IS_SNAP_SEEK (flags)) { if (stream == NULL)
stream = default_stream;
if (stream) {
GstClockTimeDiff ts; GstClockTimeDiff ts;
GstSeekFlags stream_seek_flags = flags; GstSeekFlags stream_seek_flags = flags;
@ -2332,11 +2341,14 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux,
GST_ADAPTIVE_SCHEDULER_UNLOCK (demux); GST_ADAPTIVE_SCHEDULER_UNLOCK (demux);
GST_ADAPTIVE_DEMUX_SEGMENT_UNLOCK (demux); GST_ADAPTIVE_DEMUX_SEGMENT_UNLOCK (demux);
GST_API_UNLOCK (demux);
gst_event_unref (event);
return FALSE;
}
GST_API_UNLOCK (demux);
gst_event_unref (event);
return FALSE;
}
/* replace event with a new one without snapping to seek on all streams */ /* replace event with a new one without snapping to seek on all streams */
gst_event_unref (event); gst_event_unref (event);
if (rate >= 0) { if (rate >= 0) {
@ -2349,6 +2361,7 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux,
start_type, start, stop_type, stop); start_type, start, stop_type, stop);
GST_DEBUG_OBJECT (demux, "Adapted snap seek to %" GST_PTR_FORMAT, event); GST_DEBUG_OBJECT (demux, "Adapted snap seek to %" GST_PTR_FORMAT, event);
} }
}
ret = gst_segment_do_seek (&demux->segment, rate, format, flags, start_type, ret = gst_segment_do_seek (&demux->segment, rate, format, flags, start_type,
start, stop_type, stop, &update); start, stop_type, stop, &update);