From f7553b6b0d91c9d62d9ab8587f9ff5cb561c399e Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 8 May 2012 11:33:50 -0400 Subject: [PATCH] hlsdemux: If we update the playlist, make sure the sequence number is never more than 3 fragments before the end --- gst/hls/gsthlsdemux.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gst/hls/gsthlsdemux.c b/gst/hls/gsthlsdemux.c index baa0207df9..ca3894342d 100644 --- a/gst/hls/gsthlsdemux.c +++ b/gst/hls/gsthlsdemux.c @@ -940,6 +940,7 @@ gst_hls_demux_update_playlist (GstHLSDemux * demux) GstFragment *download; GstBuffer *buf; gchar *playlist; + gboolean updated = FALSE; const gchar *uri = gst_m3u8_client_get_current_uri (demux->client); @@ -957,7 +958,29 @@ gst_hls_demux_update_playlist (GstHLSDemux * demux) return FALSE; } - return gst_m3u8_client_update (demux->client, playlist); + updated = gst_m3u8_client_update (demux->client, playlist); + + /* If it's a live source, do not let the sequence number go beyond + * three fragments before the end of the list */ + if (updated && demux->client->current && + gst_m3u8_client_is_live (demux->client)) { + guint last_sequence; + + GST_M3U8_CLIENT_LOCK (demux->client); + last_sequence = + GST_M3U8_MEDIA_FILE (g_list_last (demux->client->current->files)-> + data)->sequence; + + if (demux->client->sequence >= last_sequence - 3) { + GST_DEBUG_OBJECT (demux, "Sequence is beyond playlist. Moving back to %d", + last_sequence - 3); + demux->need_segment = TRUE; + demux->client->sequence = last_sequence - 3; + } + GST_M3U8_CLIENT_UNLOCK (demux->client); + } + + return updated; } static gboolean