adaptivedemux2: Move stream_seek() to the Stream class
authorJan Schmidt <jan@centricular.com>
Wed, 2 Nov 2022 14:48:08 +0000 (01:48 +1100)
committerJan Schmidt <jan@centricular.com>
Fri, 4 Nov 2022 17:00:31 +0000 (04:00 +1100)
Move the last stream specific vfunc from the demux
class to the stream class.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>

subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstdashdemux.c
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.h
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h
subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c

index 3820937..ab7445f 100644 (file)
@@ -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 =
index 630ba71..a72cefe 100644 (file)
@@ -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);
index 60eaceb..56a5cf3 100644 (file)
@@ -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)
index 7049b10..6cbde86 100644 (file)
@@ -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
index 07b8ffd..07619bc 100644 (file)
@@ -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)
index 883b562..d1ad49a 100644 (file)
@@ -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
index 43bcfd5..280a420 100644 (file)
@@ -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