dashdemux: Find the current period in a live stream

Start from the correct period on a live stream

https://bugzilla.gnome.org/show_bug.cgi?id=737421
This commit is contained in:
David Waring 2014-10-10 11:24:08 +01:00 committed by Thiago Santos
parent 306ca0cdf6
commit 95c3fdc193
3 changed files with 67 additions and 9 deletions

View file

@ -488,9 +488,37 @@ gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
{
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
gboolean ret = TRUE;
GstDateTime *now = NULL;
guint period_idx;
/* setup video, audio and subtitle streams, starting from first Period */
if (!gst_mpd_client_set_period_index (dashdemux->client, 0) ||
/* setup video, audio and subtitle streams, starting from first Period if
* non-live */
period_idx = 0;
if (gst_mpd_client_is_live (dashdemux->client)) {
/* get period index for period encompassing the current time */
now = gst_date_time_new_now_utc ();
if (dashdemux->client->mpd_node->suggestedPresentationDelay != -1) {
GstDateTime *target = gst_mpd_client_add_time_difference (now,
dashdemux->client->mpd_node->suggestedPresentationDelay * -1000);
gst_date_time_unref (now);
now = target;
}
period_idx =
gst_mpd_client_get_period_index_at_time (dashdemux->client, now);
if (period_idx == G_MAXUINT) {
#ifndef GST_DISABLE_GST_DEBUG
gchar *date_str = gst_date_time_to_iso8601_string (now);
GST_DEBUG_OBJECT (demux, "Unable to find live period active at %s",
date_str);
g_free (date_str);
#endif
ret = FALSE;
goto done;
}
}
if (!gst_mpd_client_set_period_index (dashdemux->client, period_idx) ||
!gst_dash_demux_setup_all_streams (dashdemux)) {
ret = FALSE;
goto done;
@ -500,16 +528,9 @@ gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
* is closest to current time */
if (gst_mpd_client_is_live (dashdemux->client)) {
GList *iter;
GstDateTime *now = gst_date_time_new_now_utc ();
gint seg_idx;
GST_DEBUG_OBJECT (demux, "Seeking to current time of day for live stream ");
if (dashdemux->client->mpd_node->suggestedPresentationDelay != -1) {
GstDateTime *target = gst_mpd_client_add_time_difference (now,
dashdemux->client->mpd_node->suggestedPresentationDelay * -1000);
gst_date_time_unref (now);
now = target;
}
for (iter = demux->streams; iter; iter = g_list_next (iter)) {
GstDashDemuxStream *stream = iter->data;
GstActiveStream *active_stream = stream->active_stream;
@ -539,6 +560,8 @@ gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
}
done:
if (now != NULL)
gst_date_time_unref (now);
return ret;
}

View file

@ -2598,6 +2598,40 @@ gst_mpdparser_build_URL_from_template (const gchar * url_template,
return ret;
}
guint
gst_mpd_client_get_period_index_at_time (GstMpdClient * client,
GstDateTime * time)
{
GList *iter;
guint period_idx = G_MAXUINT;
guint idx;
gint64 time_offset;
GstDateTime *avail_start =
gst_mpd_client_get_availability_start_time (client);
GstStreamPeriod *stream_period;
if (avail_start == NULL)
return 0;
time_offset = gst_mpd_client_calculate_time_difference (avail_start, time);
gst_date_time_unref (avail_start);
if (time_offset < 0)
return 0;
for (idx = 0, iter = client->periods; iter;
idx++, iter = g_list_next (iter)) {
stream_period = iter->data;
if (stream_period->start <= time_offset
&& stream_period->start + stream_period->duration > time_offset) {
period_idx = idx;
break;
}
}
return period_idx;
}
static GstStreamPeriod *
gst_mpdparser_get_stream_period (GstMpdClient * client)
{

View file

@ -502,6 +502,7 @@ gint gst_mpd_client_get_segment_index_at_time (GstMpdClient *client, GstActiveSt
gint gst_mpd_client_check_time_position (GstMpdClient * client, GstActiveStream * stream, GstClockTime ts, gint64 * diff);
/* Period selection */
guint gst_mpd_client_get_period_index_at_time (GstMpdClient * client, GstDateTime * time);
gboolean gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx);
gboolean gst_mpd_client_set_period_id (GstMpdClient *client, const gchar * period_id);
guint gst_mpd_client_get_period_index (GstMpdClient *client);