smoothstreaming: start closer to the edge in live streams
authorHosang Lee <hosang10.lee@lge.com>
Tue, 16 Jun 2020 03:42:16 +0000 (12:42 +0900)
committerHosang Lee <hosang10.lee@lge.com>
Mon, 10 Aug 2020 07:13:30 +0000 (16:13 +0900)
It is more appropriate to start closer to the live edge in
live streams. Some live streams maintain a large dvr window
(over few hours in some cases), so starting from the first
fragment will be too far away from the live edge.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1346>

ext/smoothstreaming/gstmssmanifest.c

index 5d195eb..0ab4096 100644 (file)
@@ -54,6 +54,8 @@ GST_DEBUG_CATEGORY_EXTERN (mssdemux_debug);
 #define MSS_PROP_TIMESCALE            "TimeScale"
 #define MSS_PROP_URL                  "Url"
 
+#define GST_MSSMANIFEST_LIVE_MIN_FRAGMENT_DISTANCE 3
+
 typedef struct _GstMssStreamFragment
 {
   guint number;
@@ -286,7 +288,21 @@ _gst_mss_stream_init (GstMssManifest * manifest, GstMssStream * stream,
 
   if (builder.fragments) {
     stream->fragments = g_list_reverse (builder.fragments);
-    stream->current_fragment = stream->fragments;
+    if (manifest->is_live) {
+      GList *iter = g_list_last (stream->fragments);
+      gint i;
+
+      for (i = 0; i < GST_MSSMANIFEST_LIVE_MIN_FRAGMENT_DISTANCE; i++) {
+        if (g_list_previous (iter)) {
+          iter = g_list_previous (iter);
+        } else {
+          break;
+        }
+      }
+      stream->current_fragment = iter;
+    } else {
+      stream->current_fragment = stream->fragments;
+    }
   }
 
   /* order them from smaller to bigger based on bitrates */