From ae679506b1ed7df0e6a463ffefe43906d4f2b5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 28 May 2014 12:43:43 +0200 Subject: [PATCH] dashdemux: Always use the redirect target to resolve relative URIs But redownload the playlists from the original URI if it's not a permanent redirect. --- ext/dash/gstdashdemux.c | 30 ++++++++++++++++++++++++++---- ext/dash/gstmpdparser.c | 16 +++++++++------- ext/dash/gstmpdparser.h | 2 ++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/ext/dash/gstdashdemux.c b/ext/dash/gstdashdemux.c index 02c4b62542..e087b4c1fe 100644 --- a/ext/dash/gstdashdemux.c +++ b/ext/dash/gstdashdemux.c @@ -787,9 +787,24 @@ gst_dash_demux_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) query = gst_query_new_uri (); query_res = gst_pad_peer_query (pad, query); if (query_res) { - gst_query_parse_uri (query, &demux->client->mpd_uri); - GST_DEBUG_OBJECT (demux, "Fetched MPD file at URI: %s", - demux->client->mpd_uri); + gchar *uri, *redirect_uri; + gboolean permanent; + + gst_query_parse_uri (query, &uri); + gst_query_parse_uri_redirection (query, &redirect_uri); + gst_query_parse_uri_redirection_permanent (query, &permanent); + + if (permanent && redirect_uri) { + demux->client->mpd_uri = redirect_uri; + demux->client->mpd_base_uri = NULL; + g_free (uri); + } else { + demux->client->mpd_uri = uri; + demux->client->mpd_base_uri = redirect_uri; + } + + GST_DEBUG_OBJECT (demux, "Fetched MPD file at URI: %s (base: %s)", + demux->client->mpd_uri, GST_STR_NULL (demux->client->mpd_base_uri)); } else { GST_WARNING_OBJECT (demux, "MPD URI query failed."); } @@ -1282,7 +1297,14 @@ gst_dash_demux_refresh_mpd (GstDashDemux * demux) GstMapInfo mapinfo; new_client = gst_mpd_client_new (); - new_client->mpd_uri = g_strdup (demux->client->mpd_uri); + + if (download->redirect_permanent && download->redirect_uri) { + new_client->mpd_uri = g_strdup (download->redirect_uri); + new_client->mpd_base_uri = NULL; + } else { + new_client->mpd_uri = g_strdup (download->uri); + new_client->mpd_base_uri = g_strdup (download->redirect_uri); + } gst_buffer_map (buffer, &mapinfo, GST_MAP_READ); diff --git a/ext/dash/gstmpdparser.c b/ext/dash/gstmpdparser.c index b1e30fd774..0b3b5ecc1c 100644 --- a/ext/dash/gstmpdparser.c +++ b/ext/dash/gstmpdparser.c @@ -2653,6 +2653,7 @@ gst_mpdparser_parse_baseURL (GstMpdClient * client, GstActiveStream * stream, { GstStreamPeriod *stream_period; GstBaseURL *baseURL; + gchar *mpd_uri; GList *list; static gchar *baseURL_array[5]; static gchar empty[] = ""; @@ -2704,7 +2705,8 @@ gst_mpdparser_parse_baseURL (GstMpdClient * client, GstActiveStream * stream, ret = g_strjoinv (NULL, baseURL_array); /* get base URI from MPD file URI, if the "http" scheme is missing */ - if (client->mpd_uri != NULL && strncmp (ret, "http://", 7) != 0) { + mpd_uri = client->mpd_base_uri ? client->mpd_base_uri : client->mpd_uri; + if (mpd_uri != NULL && strncmp (ret, "http://", 7) != 0) { gchar *last_sep, *tmp1, *tmp2; if (ret[0] == '?') { @@ -2717,9 +2719,9 @@ gst_mpdparser_parse_baseURL (GstMpdClient * client, GstActiveStream * stream, *query = NULL; } - last_sep = strrchr (client->mpd_uri, '/'); + last_sep = strrchr (mpd_uri, '/'); if (last_sep) { - tmp1 = g_strndup (client->mpd_uri, last_sep - client->mpd_uri + 1); + tmp1 = g_strndup (mpd_uri, last_sep - mpd_uri + 1); if (ret) { tmp2 = ret; ret = g_strconcat (tmp1, tmp2, NULL); @@ -2819,10 +2821,10 @@ gst_mpd_client_free (GstMpdClient * client) g_mutex_clear (&client->lock); - if (client->mpd_uri) { - g_free (client->mpd_uri); - client->mpd_uri = NULL; - } + g_free (client->mpd_uri); + client->mpd_uri = NULL; + g_free (client->mpd_base_uri); + client->mpd_base_uri = NULL; g_free (client); } diff --git a/ext/dash/gstmpdparser.h b/ext/dash/gstmpdparser.h index 9ce41f33b0..5d059b8ed1 100644 --- a/ext/dash/gstmpdparser.h +++ b/ext/dash/gstmpdparser.h @@ -469,6 +469,8 @@ struct _GstMpdClient guint update_failed_count; gchar *mpd_uri; /* manifest file URI */ + gchar *mpd_base_uri; /* base URI for resolving relative URIs. + * this will be different for redirects */ GMutex lock; };