hlsdemux: m3u8: add support to get the duration from a playlist
authorAndoni Morales Alastruey <ylatuya@gmail.com>
Sat, 12 Mar 2011 11:20:32 +0000 (12:20 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 30 Mar 2011 07:19:22 +0000 (09:19 +0200)
gst/hls/m3u8.c
gst/hls/m3u8.h

index ea5aa68590dfc31410357abd6139bf616936f4d2..5ad06052b22f4220353d0a3ea232de4d6aeb2e62 100644 (file)
@@ -450,3 +450,24 @@ gst_m3u8_client_get_next_fragment (GstM3U8Client * client,
 
   return file->uri;
 }
+
+static void
+_sum_duration (GstM3U8MediaFile * self, GstClockTime * duration)
+{
+  *duration += self->duration;
+}
+
+GstClockTime
+gst_m3u8_client_get_duration (GstM3U8Client * client)
+{
+  GstClockTime duration = 0;
+
+  g_return_val_if_fail (client != NULL, GST_CLOCK_TIME_NONE);
+
+  /* We can only get the duration for on-demand streams */
+  if (!client->current->endlist)
+    return GST_CLOCK_TIME_NONE;
+
+  g_list_foreach (client->current->files, (GFunc) _sum_duration, &duration);
+  return duration;
+}
index df893e08debeb7cf42c9df683f33744390359d59..499aa52551cbecc73d75bbed0cb038518f459026 100644 (file)
@@ -77,6 +77,7 @@ gboolean gst_m3u8_client_update (GstM3U8Client * client, gchar * data);
 void gst_m3u8_client_set_current (GstM3U8Client * client, GstM3U8 * m3u8);
 const gchar *gst_m3u8_client_get_next_fragment (GstM3U8Client * client,
     gboolean * discontinuity);
+GstClockTime gst_m3u8_client_get_duration (GstM3U8Client * client);
 #define gst_m3u8_client_get_uri(Client) ((Client)->main->uri)
 #define gst_m3u8_client_has_variant_playlist(Client) ((Client)->main->lists)
 #define gst_m3u8_client_is_live(Client) (!(Client)->main->lists && !(Client)->current->endlist)