[FFmpeg-cvslog] avformat/hls: update cookies on setcookie response

Lucas de Andrade git at videolan.org
Fri Oct 30 18:15:35 CET 2015


ffmpeg | branch: release/2.8 | Lucas de Andrade <lucas at mindello.com.br> | Fri Oct 30 09:51:26 2015 -0200| [fcb8ee98f686e86a9adc7df22756136fe423b502] | committer: Michael Niedermayer

avformat/hls: update cookies on setcookie response

Context cookies must be updated when a playlist response return Setcookie header.

See: 770dd105044d00263da041f509a08b316296a78e
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fcb8ee98f686e86a9adc7df22756136fe423b502
---

 libavformat/hls.c |   31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 1e338dc..d3cb14b 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -606,6 +606,14 @@ static int url_connect(struct playlist *pls, AVDictionary *opts, AVDictionary *o
     return ret;
 }
 
+static void update_options(char **dest, const char *name, void *src)
+{
+    av_freep(dest);
+    av_opt_get(src, name, 0, (uint8_t**)dest);
+    if (*dest && !strlen(*dest))
+        av_freep(dest);
+}
+
 static int open_url(HLSContext *c, URLContext **uc, const char *url, AVDictionary *opts)
 {
     AVDictionary *tmp = NULL;
@@ -615,6 +623,12 @@ static int open_url(HLSContext *c, URLContext **uc, const char *url, AVDictionar
     av_dict_copy(&tmp, opts, 0);
 
     ret = ffurl_open(uc, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp);
+    if( ret >= 0) {
+        // update cookies on http response with setcookies.
+        URLContext *u = *uc;
+        update_options(&c->cookies, "cookies", u->priv_data);
+        av_dict_set(&opts, "cookies", c->cookies, 0);
+    }
 
     av_dict_free(&tmp);
 
@@ -1055,18 +1069,9 @@ static void intercept_id3(struct playlist *pls, uint8_t *buf,
         pls->is_id3_timestamped = (pls->id3_mpegts_timestamp != AV_NOPTS_VALUE);
 }
 
-static void update_options(char **dest, const char *name, void *src)
-{
-    av_freep(dest);
-    av_opt_get(src, name, 0, (uint8_t**)dest);
-    if (*dest && !strlen(*dest))
-        av_freep(dest);
-}
-
 static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
 {
     AVDictionary *opts = NULL;
-    AVDictionary *opts2 = NULL;
     int ret;
 
     // broker prior HTTP options that should be consistent across requests
@@ -1075,9 +1080,6 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
     av_dict_set(&opts, "headers", c->headers, 0);
     av_dict_set(&opts, "seekable", "0", 0);
 
-    // Same opts for key request (ffurl_open mutilates the opts so it cannot be used twice)
-    av_dict_copy(&opts2, opts, 0);
-
     if (seg->size >= 0) {
         /* try to restrict the HTTP request to the part we want
          * (if this is in fact a HTTP request) */
@@ -1095,14 +1097,12 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
         char iv[33], key[33], url[MAX_URL_SIZE];
         if (strcmp(seg->key, pls->key_url)) {
             URLContext *uc;
-            if (open_url(pls->parent->priv_data, &uc, seg->key, opts2) == 0) {
+            if (open_url(pls->parent->priv_data, &uc, seg->key, opts) == 0) {
                 if (ffurl_read_complete(uc, pls->key, sizeof(pls->key))
                     != sizeof(pls->key)) {
                     av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
                            seg->key);
                 }
-                update_options(&c->cookies, "cookies", uc->priv_data);
-                av_dict_set(&opts, "cookies", c->cookies, 0);
                 ffurl_close(uc);
             } else {
                 av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n",
@@ -1151,7 +1151,6 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg)
 
 cleanup:
     av_dict_free(&opts);
-    av_dict_free(&opts2);
     pls->cur_seg_offset = 0;
     return ret;
 }



More information about the ffmpeg-cvslog mailing list