diff --git a/gst/hls/m3u8.c b/gst/hls/m3u8.c index ea5aa68590..5ad06052b2 100644 --- a/gst/hls/m3u8.c +++ b/gst/hls/m3u8.c @@ -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; +} diff --git a/gst/hls/m3u8.h b/gst/hls/m3u8.h index df893e08de..499aa52551 100644 --- a/gst/hls/m3u8.h +++ b/gst/hls/m3u8.h @@ -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)