From 565f47b4f3f23c07cb405e56f2d66ae1d3ba95f6 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Thu, 3 Nov 2022 01:48:08 +1100 Subject: [PATCH] adaptivedemux2: Move stream_seek() to the Stream class Move the last stream specific vfunc from the demux class to the stream class. Part-of: --- .../ext/adaptivedemux2/dash/gstdashdemux.c | 2 +- .../ext/adaptivedemux2/gstadaptivedemux-private.h | 4 +- .../ext/adaptivedemux2/gstadaptivedemux-stream.c | 16 ++++++- .../ext/adaptivedemux2/gstadaptivedemux-stream.h | 6 +++ .../ext/adaptivedemux2/gstadaptivedemux.c | 49 ++++++++++------------ .../ext/adaptivedemux2/gstadaptivedemux.h | 6 --- .../ext/adaptivedemux2/hls/gsthlsdemux.c | 2 +- 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstdashdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstdashdemux.c index 3820937..ab7445f 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstdashdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstdashdemux.c @@ -477,6 +477,7 @@ gst_dash_demux_stream_class_init (GstDashDemux2StreamClass * klass) gst_dash_demux_stream_update_fragment_info; adaptivedemux2stream_class->has_next_fragment = gst_dash_demux_stream_has_next_fragment; + adaptivedemux2stream_class->stream_seek = gst_dash_demux_stream_seek; adaptivedemux2stream_class->advance_fragment = gst_dash_demux_stream_advance_fragment; adaptivedemux2stream_class->get_fragment_waiting_time = @@ -656,7 +657,6 @@ gst_dash_demux2_class_init (GstDashDemux2Class * klass) gstadaptivedemux_class->has_next_period = gst_dash_demux_has_next_period; gstadaptivedemux_class->advance_period = gst_dash_demux_advance_period; - gstadaptivedemux_class->stream_seek = gst_dash_demux_stream_seek; gstadaptivedemux_class->get_live_seek_range = gst_dash_demux_get_live_seek_range; gstadaptivedemux_class->get_period_start_time = diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h index 630ba71..a72cefe 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h @@ -183,8 +183,8 @@ void gst_adaptive_demux2_stream_on_manifest_update (GstAdaptiveDemux2Stream * st void gst_adaptive_demux2_stream_on_output_space_available (GstAdaptiveDemux2Stream *stream); gboolean gst_adaptive_demux2_stream_has_next_fragment (GstAdaptiveDemux2Stream * stream); -GstFlowReturn gst_adaptive_demux2_stream_seek (GstAdaptiveDemux * demux, - GstAdaptiveDemux2Stream * stream, gboolean forward, GstSeekFlags flags, +GstFlowReturn gst_adaptive_demux2_stream_seek (GstAdaptiveDemux2Stream * stream, + gboolean forward, GstSeekFlags flags, GstClockTimeDiff ts, GstClockTimeDiff * final_ts); gboolean gst_adaptive_demux_get_live_seek_range (GstAdaptiveDemux * demux, gint64 * range_start, gint64 * range_stop); diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c index 60eaceb..56a5cf3 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c @@ -1941,7 +1941,7 @@ gst_adaptive_demux2_stream_next_download (GstAdaptiveDemux2Stream * stream) if (GST_CLOCK_STIME_IS_VALID (stream_time)) { /* TODO check return */ - gst_adaptive_demux2_stream_seek (demux, stream, demux->segment.rate >= 0, + gst_adaptive_demux2_stream_seek (stream, demux->segment.rate >= 0, 0, stream_time, &stream_time); stream->current_position = stream->start_position; @@ -2197,6 +2197,20 @@ gst_adaptive_demux2_stream_has_next_fragment (GstAdaptiveDemux2Stream * stream) return ret; } +/* must be called from the scheduler */ +GstFlowReturn +gst_adaptive_demux2_stream_seek (GstAdaptiveDemux2Stream * stream, + gboolean forward, GstSeekFlags flags, + GstClockTimeDiff ts, GstClockTimeDiff * final_ts) +{ + GstAdaptiveDemux2StreamClass *klass = + GST_ADAPTIVE_DEMUX2_STREAM_GET_CLASS (stream); + + if (klass->stream_seek) + return klass->stream_seek (stream, forward, flags, ts, final_ts); + return GST_FLOW_ERROR; +} + static gboolean gst_adaptive_demux2_stream_select_bitrate (GstAdaptiveDemux * demux, GstAdaptiveDemux2Stream * stream, guint64 bitrate) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.h index 7049b10..6cbde86 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.h @@ -131,6 +131,12 @@ struct _GstAdaptiveDemux2StreamClass gboolean (*has_next_fragment) (GstAdaptiveDemux2Stream * stream); GstFlowReturn (*advance_fragment) (GstAdaptiveDemux2Stream * stream); + GstFlowReturn (*stream_seek) (GstAdaptiveDemux2Stream * stream, + gboolean forward, + GstSeekFlags flags, + GstClockTimeDiff target_ts, + GstClockTimeDiff * final_ts); + /** * can_start: * @stream: a #GstAdaptiveDemux2Stream diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c index 07b8ffd..07619bc 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c @@ -2206,15 +2206,24 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux, * different positions, so just pick one and align all others to that * position. */ - if (IS_SNAP_SEEK (flags) && demux_class->stream_seek) { - GstAdaptiveDemux2Stream *stream = NULL; + + GstAdaptiveDemux2Stream *stream = NULL; + GList *iter; + /* Pick a random active stream on which to do the stream seek */ + for (iter = demux->output_period->streams; iter; iter = iter->next) { + GstAdaptiveDemux2Stream *cand = iter->data; + if (gst_adaptive_demux2_stream_is_selected_locked (cand)) { + stream = cand; + break; + } + } + + if (stream && IS_SNAP_SEEK (flags)) { GstClockTimeDiff ts; GstSeekFlags stream_seek_flags = flags; - GList *iter; - /* snap-seek on the stream that received the event and then + /* snap-seek on the chosen stream and then * use the resulting position to seek on all streams */ - if (rate >= 0) { if (start_type != GST_SEEK_TYPE_NONE) ts = start; @@ -2233,16 +2242,13 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux, } } - /* Pick a random active stream on which to do the stream seek */ - for (iter = demux->output_period->streams; iter; iter = iter->next) { - GstAdaptiveDemux2Stream *cand = iter->data; - if (gst_adaptive_demux2_stream_is_selected_locked (cand)) { - stream = cand; - break; - } - } - if (stream) { - demux_class->stream_seek (stream, rate >= 0, stream_seek_flags, ts, &ts); + if (gst_adaptive_demux2_stream_seek (stream, rate >= 0, stream_seek_flags, + ts, &ts) != GST_FLOW_OK) { + GST_ADAPTIVE_SCHEDULER_UNLOCK (demux); + + GST_API_UNLOCK (demux); + gst_event_unref (event); + return FALSE; } /* replace event with a new one without snapping to seek on all streams */ @@ -3567,19 +3573,6 @@ gst_adaptive_demux_is_live (GstAdaptiveDemux * demux) return FALSE; } -/* must be called from the scheduler */ -GstFlowReturn -gst_adaptive_demux2_stream_seek (GstAdaptiveDemux * demux, - GstAdaptiveDemux2Stream * stream, gboolean forward, GstSeekFlags flags, - GstClockTimeDiff ts, GstClockTimeDiff * final_ts) -{ - GstAdaptiveDemuxClass *klass = GST_ADAPTIVE_DEMUX_GET_CLASS (demux); - - if (klass->stream_seek) - return klass->stream_seek (stream, forward, flags, ts, final_ts); - return GST_FLOW_ERROR; -} - static void handle_manifest_download_complete (DownloadRequest * request, DownloadRequestState state, GstAdaptiveDemux * demux) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h index 883b562..d1ad49a 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h @@ -400,12 +400,6 @@ struct _GstAdaptiveDemuxClass */ void (*advance_period) (GstAdaptiveDemux * demux); - GstFlowReturn (*stream_seek) (GstAdaptiveDemux2Stream * stream, - gboolean forward, - GstSeekFlags flags, - GstClockTimeDiff target_ts, - GstClockTimeDiff * final_ts); - /** * get_live_seek_range: * @demux: #GstAdaptiveDemux diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c index 43bcfd5..280a420 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c @@ -166,6 +166,7 @@ gst_hls_demux_stream_class_init (GstHLSDemuxStreamClass * klass) gst_hls_demux_stream_update_fragment_info; adaptivedemux2stream_class->has_next_fragment = gst_hls_demux_stream_has_next_fragment; + adaptivedemux2stream_class->stream_seek = gst_hls_demux_stream_seek; adaptivedemux2stream_class->advance_fragment = gst_hls_demux_stream_advance_fragment; adaptivedemux2stream_class->select_bitrate = @@ -295,7 +296,6 @@ gst_hls_demux2_class_init (GstHLSDemux2Class * klass) adaptivedemux_class->update_manifest = gst_hls_demux_update_manifest; adaptivedemux_class->reset = gst_hls_demux_reset; adaptivedemux_class->seek = gst_hls_demux_seek; - adaptivedemux_class->stream_seek = gst_hls_demux_stream_seek; } static void -- 2.7.4