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
This commit is contained in:
Mikael Finstad 2014-01-27 11:05:27 +01:00 committed by Michael Niedermayer
parent 406cb21b63
commit 5846d8a91e

View File

@ -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;
}