hlsdemux: select correct starting position for live streams

When playing live HLS streams, the media playback starts from the
beginning of the media playlist. When playing a live HLS stream,
media playback should start from 3 fragments from the end of the
playlist.

See section 6.3.3. of the HLS draft [1]

This commit changes the logic to select 3 fragments from the end when
playing a live stream.

[1] http://tools.ietf.org/html/draft-pantos-http-live-streaming-12#page-29

https://bugzilla.gnome.org/show_bug.cgi?id=727742
This commit is contained in:
Alex Ashley 2015-02-20 13:55:05 +00:00 committed by Thiago Santos
parent a4040f2ee9
commit a08dd85608
3 changed files with 18 additions and 5 deletions

View file

@ -851,7 +851,16 @@ gst_m3u8_client_update (GstM3U8Client * self, gchar * data)
if (m3u8->files && self->sequence == -1) {
self->current_file = g_list_first (m3u8->files);
self->sequence = GST_M3U8_MEDIA_FILE (self->current_file->data)->sequence;
if (GST_M3U8_CLIENT_IS_LIVE (self)) {
/* for live streams, start GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE from
the end of the playlist. See section 6.3.3 of HLS draft */
gint pos =
g_list_length (m3u8->files) - GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE;
self->sequence =
GST_M3U8_MEDIA_FILE (g_list_nth_data (m3u8->files,
pos >= 0 ? pos : 0))->sequence;
} else
self->sequence = GST_M3U8_MEDIA_FILE (self->current_file->data)->sequence;
self->sequence_position = 0;
GST_DEBUG ("Setting first sequence at %u", (guint) self->sequence);
}

View file

@ -42,6 +42,12 @@ typedef struct _GstM3U8Client GstM3U8Client;
value is three fragments */
#define GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE 3
/* hlsdemux must not get closer to the end of a live stream than
GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE fragments. Section 6.3.3
"Playing the Playlist file" of the HLS draft states that this
value is three fragments */
#define GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE 3
struct _GstM3U8
{
gchar *uri; /* actually downloaded URI */

View file

@ -496,8 +496,7 @@ GST_START_TEST (test_live_playlist)
pl = client->current;
/* Check that we are live */
assert_equals_int (gst_m3u8_client_is_live (client), TRUE);
/* FIXME: Sequence should last - 3. Should it? */
assert_equals_int (client->sequence, 2680);
assert_equals_int (client->sequence, 2681);
/* Check number of entries */
assert_equals_int (g_list_length (pl->files), 4);
/* Check first media segments */
@ -528,8 +527,7 @@ GST_START_TEST (test_live_playlist_rotated)
client = load_playlist (LIVE_PLAYLIST);
pl = client->current;
/* FIXME: Sequence should last - 3. Should it? */
assert_equals_int (client->sequence, 2680);
assert_equals_int (client->sequence, 2681);
/* Check first media segments */
file = GST_M3U8_MEDIA_FILE (g_list_first (pl->files)->data);
assert_equals_int (file->sequence, 2680);