Commit d4e5d8d4 authored by Micah Galizia's avatar Micah Galizia Committed by Stefano Sabatini

lavf/hls: broker HTTP options

Signed-off-by: 's avatarStefano Sabatini <stefasab@gmail.com>
parent e3197257
......@@ -103,6 +103,8 @@ typedef struct HLSContext {
int64_t seek_timestamp;
int seek_flags;
AVIOInterruptCB *interrupt_callback;
char *user_agent; ///< holds HTTP user agent set as an AVOption to the HTTP protocol context
char *cookies; ///< holds HTTP cookie values set in either the initial response or as an AVOption to the HTTP protocol context
} HLSContext;
static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
......@@ -139,6 +141,8 @@ static void free_variant_list(HLSContext *c)
av_free(var);
}
av_freep(&c->variants);
av_freep(&c->cookies);
av_freep(&c->user_agent);
c->n_variants = 0;
}
......@@ -216,6 +220,11 @@ static int parse_playlist(HLSContext *c, const char *url,
close_in = 1;
/* Some HLS servers dont like being sent the range header */
av_dict_set(&opts, "seekable", "0", 0);
// broker prior HTTP options that should be consistent across requests
av_dict_set(&opts, "user-agent", c->user_agent, 0);
av_dict_set(&opts, "cookies", c->cookies, 0);
ret = avio_open2(&in, url, AVIO_FLAG_READ,
c->interrupt_callback, &opts);
av_dict_free(&opts);
......@@ -328,12 +337,17 @@ fail:
return ret;
}
static int open_input(struct variant *var)
static int open_input(HLSContext *c, struct variant *var)
{
AVDictionary *opts = NULL;
int ret;
struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no];
// broker prior HTTP options that should be consistent across requests
av_dict_set(&opts, "user-agent", c->user_agent, 0);
av_dict_set(&opts, "cookies", c->cookies, 0);
av_dict_set(&opts, "seekable", "0", 0);
if (seg->key_type == KEY_NONE) {
ret = ffurl_open(&var->input, seg->url, AVIO_FLAG_READ,
&var->parent->interrupt_callback, &opts);
......@@ -429,7 +443,7 @@ reload:
goto reload;
}
ret = open_input(v);
ret = open_input(c, v);
if (ret < 0)
return ret;
}
......@@ -461,11 +475,27 @@ reload:
static int hls_read_header(AVFormatContext *s)
{
URLContext *u = s->pb->opaque;
HLSContext *c = s->priv_data;
int ret = 0, i, j, stream_offset = 0;
c->interrupt_callback = &s->interrupt_callback;
// if the URL context is good, read important options we must broker later
if (u) {
// get the previous user agent & set back to null if string size is zero
av_free(c->user_agent);
av_opt_get(u->priv_data, "user-agent", 0, (uint8_t**)&(c->user_agent));
if (!strlen(c->user_agent))
av_freep(&c->user_agent);
// get the previous cookies & set back to null if string size is zero
av_free(c->cookies);
av_opt_get(u->priv_data, "cookies", 0, (uint8_t**)&(c->cookies));
if (!strlen(c->cookies))
av_freep(&c->cookies);
}
if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0)
goto fail;
......
......@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 61
#define LIBAVFORMAT_VERSION_MICRO 103
#define LIBAVFORMAT_VERSION_MICRO 104
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment