diff options
author | Micah Galizia <micahgalizia@gmail.com> | 2013-01-22 21:09:57 -0500 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2013-01-23 19:27:14 +0100 |
commit | d4e5d8d4c264955f3df8c6947b38913f9ee3eb18 (patch) | |
tree | 845089d9dee3373676446ee52d975883d9b0fc3b | |
parent | e3197257171c347353538152523f9d3fe880aee6 (diff) | |
download | ffmpeg-d4e5d8d4c264955f3df8c6947b38913f9ee3eb18.tar.gz |
lavf/hls: broker HTTP options
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
-rw-r--r-- | libavformat/hls.c | 34 | ||||
-rw-r--r-- | libavformat/version.h | 2 |
2 files changed, 33 insertions, 3 deletions
diff --git a/libavformat/hls.c b/libavformat/hls.c index f515dfb7f1..8e46c2b875 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -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; diff --git a/libavformat/version.h b/libavformat/version.h index dcac2568b4..3e85a3d8a2 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -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, \ |