dashdemux: Always use the redirect target to resolve relative URIs
authorSebastian Dröge <sebastian@centricular.com>
Wed, 28 May 2014 10:43:43 +0000 (12:43 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 28 May 2014 10:47:51 +0000 (12:47 +0200)
But redownload the playlists from the original URI if it's not
a permanent redirect.

ext/dash/gstdashdemux.c
ext/dash/gstmpdparser.c
ext/dash/gstmpdparser.h

index 02c4b62542beaaa6fcbefe1ec462a534eb817717..e087b4c1fe0308ed2bb9e5edcb587c53cec8eb7a 100644 (file)
@@ -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);
 
index b1e30fd7747ee733adc77666800a5f0b69904fe5..0b3b5ecc1c17c0dc2b1366c6797deb36dd1a0ddf 100644 (file)
@@ -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);
 }
index 9ce41f33b03f29080922303ab2b062a6e1b9e676..5d059b8ed1d06fff6f20464c65e626428f4d10a1 100644 (file)
@@ -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;
 };