diff options
author | Edward Hervey <edward@centricular.com> | 2015-10-14 17:38:39 +0200 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2015-10-15 10:34:19 +0200 |
commit | 2aea46912b6fa886d16a289da3bfb4d78ae4d3e4 (patch) | |
tree | 2e7bde878068653996958691a3a2ff96ce106501 | |
parent | 834a45392b564b00ed54918efc42388fe2040189 (diff) | |
download | gstreamer-plugins-bad-2aea46912b6fa886d16a289da3bfb4d78ae4d3e4.tar.gz |
hlsdemux: Avoid negative sequence numbers
For live streams, we want to make sure there's a certain distance
between the sequence to play and the last (earliest) fragment.
The problem is that it assumes there are at least 3 fragments in
the playlist, which might not always be the case (like in the case
of a server restarting and gradually adding fragments).
In order to avoid ending up with negative sequence numbers (which
will just loop forever), limit the new target sequence number to
the highest of:
* either the first sequence number of the playlist (fallback)
* or 3 fragments from the last one (standard behaviour)
-rw-r--r-- | ext/hls/gsthlsdemux.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/hls/gsthlsdemux.c b/ext/hls/gsthlsdemux.c index 91178e237..1c05fa860 100644 --- a/ext/hls/gsthlsdemux.c +++ b/ext/hls/gsthlsdemux.c @@ -955,18 +955,26 @@ retry: * three fragments before the end of the list */ if (update == FALSE && demux->client->current && gst_m3u8_client_is_live (demux->client)) { - gint64 last_sequence; + gint64 last_sequence, first_sequence; GST_M3U8_CLIENT_LOCK (demux->client); last_sequence = GST_M3U8_MEDIA_FILE (g_list_last (demux->client->current-> files)->data)->sequence; + first_sequence = + GST_M3U8_MEDIA_FILE (demux->client->current->files->data)->sequence; + GST_DEBUG_OBJECT (demux, + "sequence:%" G_GINT64_FORMAT " , first_sequence:%" G_GINT64_FORMAT + " , last_sequence:%" G_GINT64_FORMAT, demux->client->sequence, + first_sequence, last_sequence); if (demux->client->sequence >= last_sequence - 3) { - GST_DEBUG_OBJECT (demux, "Sequence is beyond playlist. Moving back to %u", - (guint) (last_sequence - 3)); //demux->need_segment = TRUE; - demux->client->sequence = last_sequence - 3; + /* Make sure we never go below the minimum sequence number */ + demux->client->sequence = MAX (first_sequence, last_sequence - 3); + GST_DEBUG_OBJECT (demux, + "Sequence is beyond playlist. Moving back to %" G_GINT64_FORMAT, + demux->client->sequence); } GST_M3U8_CLIENT_UNLOCK (demux->client); } else if (demux->client->current && !gst_m3u8_client_is_live (demux->client)) { |