[FFmpeg-cvslog] avformat/hls: Fix cookies and user agent with encrypted HLS streams

Mikael Finstad git at videolan.org
Tue Jan 28 19:12:06 CET 2014


ffmpeg | branch: master | Mikael Finstad <finstaden at gmail.com> | Mon Jan 27 11:05:27 2014 +0100| [5846d8a91ebd953ad7cdad6a27267509e87e0821] | committer: Michael Niedermayer

avformat/hls: Fix cookies and user agent with encrypted HLS streams

Session data (cookies, user-agent) is not being sent on payload requests with
encrypted HLS streams This causes services like Akamai to give a 403 forbidden
when requesting the TS files, because they expect the same cookies
and user-agent on all requests

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

 libavformat/hls.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 148c796..e291950 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -387,6 +387,7 @@ fail:
 static int open_input(HLSContext *c, struct playlist *pls)
 {
     AVDictionary *opts = NULL;
+    AVDictionary *opts2 = NULL;
     int ret;
     struct segment *seg = pls->segments[pls->cur_seq_no - pls->start_seq_no];
 
@@ -396,6 +397,9 @@ static int open_input(HLSContext *c, struct playlist *pls)
     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->key_type == KEY_NONE) {
         ret = ffurl_open(&pls->input, seg->url, AVIO_FLAG_READ,
                           &pls->parent->interrupt_callback, &opts);
@@ -405,7 +409,7 @@ static int open_input(HLSContext *c, struct playlist *pls)
         if (strcmp(seg->key, pls->key_url)) {
             URLContext *uc;
             if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
-                           &pls->parent->interrupt_callback, &opts) == 0) {
+                           &pls->parent->interrupt_callback, &opts2) == 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",
@@ -430,9 +434,7 @@ static int open_input(HLSContext *c, struct playlist *pls)
             goto cleanup;
         av_opt_set(pls->input->priv_data, "key", key, 0);
         av_opt_set(pls->input->priv_data, "iv", iv, 0);
-        /* Need to repopulate options */
-        av_dict_free(&opts);
-        av_dict_set(&opts, "seekable", "0", 0);
+
         if ((ret = ffurl_connect(pls->input, &opts)) < 0) {
             ffurl_close(pls->input);
             pls->input = NULL;
@@ -445,6 +447,7 @@ static int open_input(HLSContext *c, struct playlist *pls)
 
 cleanup:
     av_dict_free(&opts);
+    av_dict_free(&opts2);
     return ret;
 }
 



More information about the ffmpeg-cvslog mailing list