Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
avformat/hls: Update Cookies response with Setcookie
Context cookies must be updated when a playlist response return Setcookie header.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
  • Loading branch information
rokam authored and wm4 committed Sep 25, 2015
1 parent a8602dd commit 770dd10
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions libavformat/hls.c
Expand Up @@ -525,6 +525,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;
Expand All @@ -534,6 +542,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);

Expand Down Expand Up @@ -958,18 +972,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)
{
AVDictionary *opts = NULL;
AVDictionary *opts2 = NULL;
int ret;
struct segment *seg = pls->segments[pls->cur_seq_no - pls->start_seq_no];

Expand All @@ -979,9 +984,6 @@ 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->size >= 0) {
/* try to restrict the HTTP request to the part we want
* (if this is in fact a HTTP request) */
Expand All @@ -999,14 +1001,12 @@ static int open_input(HLSContext *c, struct playlist *pls)
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",
Expand Down Expand Up @@ -1055,7 +1055,6 @@ static int open_input(HLSContext *c, struct playlist *pls)

cleanup:
av_dict_free(&opts);
av_dict_free(&opts2);
pls->cur_seg_offset = 0;
return ret;
}
Expand Down

5 comments on commit 770dd10

@rokam
Copy link
Contributor Author

@rokam rokam commented on 770dd10 Oct 23, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this commit wasn't added to 2.8.1?

@michaelni
Copy link
Member

@michaelni michaelni commented on 770dd10 Oct 24, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelni
Copy link
Member

@michaelni michaelni commented on 770dd10 Oct 24, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rokam
Copy link
Contributor Author

@rokam rokam commented on 770dd10 Oct 24, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rokam
Copy link
Contributor Author

@rokam rokam commented on 770dd10 Oct 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already sent the patch to be merged on release/2.8 to ffmpeg-devel but with no response. Do I need to do anything else?

Please sign in to comment.