From b5cf96fc35f78f4435368331859568475205ea0c Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 27 Jan 2017 08:50:10 +0900 Subject: [PATCH] hls: m3u8: Set sequence position for live hls live starts playback from the allowed latest fragment, but its "sequence position" is set to zero, and so stream time is also set to zero. This does not make sense, because hls live allows seeking to past position, and it's negative stream time from downstream element's point of view. Note that, allowed seekable range (and seeking query) is from the first fragment of playlist to the allowed latest fragment. https://bugzilla.gnome.org/show_bug.cgi?id=777682 --- ext/hls/m3u8.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ext/hls/m3u8.c b/ext/hls/m3u8.c index eca52914b4..e85592ee3a 100644 --- a/ext/hls/m3u8.c +++ b/ext/hls/m3u8.c @@ -754,19 +754,30 @@ gst_m3u8_update (GstM3U8 * self, gchar * data) if (GST_M3U8_IS_LIVE (self)) { gint i; + GstClockTime sequence_pos = 0; file = g_list_last (self->files); + if (self->last_file_end >= GST_M3U8_MEDIA_FILE (file->data)->duration) { + sequence_pos = + self->last_file_end - GST_M3U8_MEDIA_FILE (file->data)->duration; + } + /* for live streams, start GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE from * the end of the playlist. See section 6.3.3 of HLS draft */ - for (i = 0; i < GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE && file->prev; ++i) + for (i = 0; i < GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE && file->prev && + GST_M3U8_MEDIA_FILE (file->prev->data)->duration <= sequence_pos; + ++i) { file = file->prev; + sequence_pos -= GST_M3U8_MEDIA_FILE (file->data)->duration; + } + self->sequence_position = sequence_pos; } else { file = g_list_first (self->files); + self->sequence_position = 0; } self->current_file = file; self->sequence = GST_M3U8_MEDIA_FILE (file->data)->sequence; - self->sequence_position = 0; GST_DEBUG ("first sequence: %u", (guint) self->sequence); }