From 5846d8a91ebd953ad7cdad6a27267509e87e0821 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Mon, 27 Jan 2014 11:05:27 +0100 Subject: 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 --- libavformat/hls.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'libavformat/hls.c') diff --git a/libavformat/hls.c b/libavformat/hls.c index 148c79650c..e291950597 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; } -- cgit v1.2.3