avdemux: Pass the URI from the URI query to avformat_open_input()
authorSebastian Dröge <sebastian@centricular.com>
Thu, 23 Jan 2020 07:45:59 +0000 (09:45 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 23 Jan 2020 09:58:29 +0000 (11:58 +0200)
Some demuxers make use of it in various ways, for example the HLS
demuxer.

ext/libav/gstavdemux.c

index fa5fd4e..66f6bb1 100644 (file)
@@ -1218,6 +1218,8 @@ gst_ffmpegdemux_open (GstFFMpegDemux * demux)
   GstTagList *tags;
   GstEvent *event;
   GList *cached_events;
+  GstQuery *query;
+  gchar *uri = NULL;
 
   /* to be sure... */
   gst_ffmpegdemux_close (demux);
@@ -1231,9 +1233,32 @@ gst_ffmpegdemux_open (GstFFMpegDemux * demux)
   if (res < 0)
     goto beach;
 
+  query = gst_query_new_uri ();
+  if (gst_pad_peer_query (demux->sinkpad, query)) {
+    gchar *query_uri, *redirect_uri;
+    gboolean permanent;
+
+    gst_query_parse_uri (query, &query_uri);
+    gst_query_parse_uri_redirection (query, &redirect_uri);
+    gst_query_parse_uri_redirection_permanent (query, &permanent);
+
+    if (permanent && redirect_uri) {
+      uri = redirect_uri;
+      g_free (query_uri);
+    } else {
+      uri = query_uri;
+      g_free (redirect_uri);
+    }
+  }
+  gst_query_unref (query);
+
+  GST_DEBUG_OBJECT (demux, "Opening context with URI %s", GST_STR_NULL (uri));
+
   demux->context = avformat_alloc_context ();
   demux->context->pb = iocontext;
-  res = avformat_open_input (&demux->context, NULL, oclass->in_plugin, NULL);
+  res = avformat_open_input (&demux->context, uri, oclass->in_plugin, NULL);
+
+  g_free (uri);
 
   GST_DEBUG_OBJECT (demux, "av_open_input returned %d", res);
   if (res < 0)