mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-28 11:55:39 +00:00
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)
This commit is contained in:
parent
f58cd983b6
commit
8d86a8b75d
1 changed files with 12 additions and 4 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue