From 6e54b8ee53eea1ca318c1a4efbbd642ba9155117 Mon Sep 17 00:00:00 2001 From: Arnaud Vrac Date: Thu, 25 Jul 2013 19:36:48 +0200 Subject: [PATCH] hlsdemux: schedule next update based on the fragment duration --- ext/hls/gsthlsdemux.c | 3 ++- ext/hls/m3u8.c | 28 ++++++++++++++++++++++++++++ ext/hls/m3u8.h | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ext/hls/gsthlsdemux.c b/ext/hls/gsthlsdemux.c index 11cf476..14518a9 100644 --- a/ext/hls/gsthlsdemux.c +++ b/ext/hls/gsthlsdemux.c @@ -1254,7 +1254,8 @@ gst_hls_demux_schedule (GstHLSDemux * demux) /* schedule the next update using the target duration field of the * playlist */ - demux->next_update += gst_m3u8_client_get_target_duration (demux->client) + demux->next_update += + gst_m3u8_client_get_current_fragment_duration (demux->client) / GST_SECOND * G_USEC_PER_SEC * update_factor; GST_DEBUG_OBJECT (demux, "Next update scheduled at %" G_GINT64_FORMAT, demux->next_update); diff --git a/ext/hls/m3u8.c b/ext/hls/m3u8.c index 5bdcc4b..97ac3cc 100644 --- a/ext/hls/m3u8.c +++ b/ext/hls/m3u8.c @@ -555,6 +555,12 @@ out: return ret; } +static gint +_find_current (GstM3U8MediaFile * file, GstM3U8Client * client) +{ + return file->sequence == client->sequence; +} + static gboolean _find_next (GstM3U8MediaFile * file, GstM3U8Client * client) { @@ -786,3 +792,25 @@ out: g_free (uri_copy); return ret; } + +guint64 +gst_m3u8_client_get_current_fragment_duration (GstM3U8Client * client) +{ + guint64 dur; + GList *list; + + g_return_val_if_fail (client != NULL, 0); + + GST_M3U8_CLIENT_LOCK (client); + + list = g_list_find_custom (client->current->files, client, + (GCompareFunc) _find_current); + if (list == NULL) { + dur = -1; + } else { + dur = GST_M3U8_MEDIA_FILE (list->data)->duration; + } + + GST_M3U8_CLIENT_UNLOCK (client); + return dur; +} diff --git a/ext/hls/m3u8.h b/ext/hls/m3u8.h index d035172..14bf429 100644 --- a/ext/hls/m3u8.h +++ b/ext/hls/m3u8.h @@ -98,5 +98,7 @@ gboolean gst_m3u8_client_is_live(GstM3U8Client * client); GList * gst_m3u8_client_get_playlist_for_bitrate (GstM3U8Client * client, guint bitrate); +guint64 gst_m3u8_client_get_current_fragment_duration (GstM3U8Client * client); + G_END_DECLS #endif /* __M3U8_H__ */ -- 2.7.4