hlsdemux: schedule next update based on the fragment duration
authorArnaud Vrac <avrac@freebox.fr>
Thu, 25 Jul 2013 17:36:48 +0000 (19:36 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 12 Feb 2014 14:18:29 +0000 (15:18 +0100)
ext/hls/gsthlsdemux.c
ext/hls/m3u8.c
ext/hls/m3u8.h

index 11cf476..14518a9 100644 (file)
@@ -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);
index 5bdcc4b..97ac3cc 100644 (file)
@@ -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;
+}
index d035172..14bf429 100644 (file)
@@ -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__ */