adaptivedemux: Fix startup SEGMENT seeking and setting for live
authorSeungha Yang <sh.yang@lge.com>
Thu, 10 Nov 2016 14:07:50 +0000 (23:07 +0900)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 15 Nov 2016 12:47:46 +0000 (14:47 +0200)
Because fragment.timestamp is relative value to period_start,
startup SEGMENT seeking should be pointed to "fragment.timestamp + period_start"

https://bugzilla.gnome.org/show_bug.cgi?id=774196

gst-libs/gst/adaptivedemux/gstadaptivedemux.c

index 98f5f85..634e4f3 100644 (file)
@@ -989,6 +989,8 @@ gst_adaptive_demux_expose_streams (GstAdaptiveDemux * demux,
     }
   }
 
+  period_start = gst_adaptive_demux_get_period_start_time (demux);
+
   /* For live streams, the subclass is supposed to seek to the current
    * fragment and then tell us its timestamp in stream->fragment.timestamp.
    * We now also have to seek our demuxer segment to reflect this.
@@ -997,12 +999,10 @@ gst_adaptive_demux_expose_streams (GstAdaptiveDemux * demux,
    */
   if (first_and_live) {
     gst_segment_do_seek (&demux->segment, demux->segment.rate, GST_FORMAT_TIME,
-        GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, min_pts, GST_SEEK_TYPE_NONE, -1,
-        NULL);
+        GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, min_pts + period_start,
+        GST_SEEK_TYPE_NONE, -1, NULL);
   }
 
-  period_start = gst_adaptive_demux_get_period_start_time (demux);
-
   for (iter = demux->streams; iter; iter = g_list_next (iter)) {
     GstAdaptiveDemuxStream *stream = iter->data;
     GstClockTime offset;
@@ -1059,7 +1059,13 @@ gst_adaptive_demux_expose_streams (GstAdaptiveDemux * demux,
      * equivalent.
      */
 
-    if (demux->segment.start > period_start) {
+    /* If first and live, demuxer did seek to the current position already */
+    if (first_and_live) {
+      stream->segment.start = demux->segment.start - period_start + offset;
+      stream->segment.position = stream->segment.start;
+      stream->segment.time = demux->segment.time;
+      stream->segment.base = demux->segment.base;
+    } else if (demux->segment.start > period_start) {
       stream->segment.start = demux->segment.start - period_start + offset;
       stream->segment.position = offset;
       stream->segment.time = demux->segment.time;