hls: Check whether the AVIOContext contains a new redirected URL
authorMartin Storsjö <martin@martin.st>
Thu, 21 Nov 2013 09:31:53 +0000 (11:31 +0200)
committerMartin Storsjö <martin@martin.st>
Fri, 22 Nov 2013 12:27:08 +0000 (14:27 +0200)
This allows both the main playlist itself as well as the variant
playlists to handle redirects combined with relative URLs.

Signed-off-by: Martin Storsjö <martin@martin.st>
libavformat/hls.c

index ea16f8a..14fdf8f 100644 (file)
@@ -211,6 +211,7 @@ static int parse_playlist(HLSContext *c, const char *url,
     char line[1024];
     const char *ptr;
     int close_in = 0;
+    uint8_t *new_url = NULL;
 
     if (!in) {
         close_in = 1;
@@ -219,6 +220,9 @@ static int parse_playlist(HLSContext *c, const char *url,
             return ret;
     }
 
+    if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0)
+        url = new_url;
+
     read_chomp_line(in, line, sizeof(line));
     if (strcmp(line, "#EXTM3U")) {
         ret = AVERROR_INVALIDDATA;
@@ -319,6 +323,7 @@ static int parse_playlist(HLSContext *c, const char *url,
         var->last_load_time = av_gettime();
 
 fail:
+    av_free(new_url);
     if (close_in)
         avio_close(in);
     return ret;