[FFmpeg-devel] [PATCH] Maintain HTTP options across multiple requests in HLS demuxer

Michael Niedermayer michaelni at gmx.at
Tue Jan 8 14:07:07 CET 2013


On Sat, Jan 05, 2013 at 11:23:11AM -0500, Micah Galizia wrote:
> Hello,
> 
> After a discussion on IRC it was suggested that http add a cookies
> option and hls broker the http options between different http
> requests. Attached is a patch that does that.
> 
> The cookies are stored as the string value of the "Set-Cookie: " field
> delimited by a newline when more than one set cookie field was sent.
> Then when making a request, they are parsed and added to the header.

Do you have some testcase / how can this be tested ?


> 
> Thanks in advance!
> --
> "The mark of an immature man is that he wants to die nobly for a
> cause, while the mark of the mature man is that he wants to live
> humbly for one."   --W. Stekel

>  hls.c  |   29 +++++++++++++++++-
>  http.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 127 insertions(+), 2 deletions(-)
> fe2a76d0614a16b57b07f5e5583bec87ab30f66a  hls_http_options3.patch
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index f515dfb..3cb1398 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;
> +    char *cookies;
>  } HLSContext;
>  
>  static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
> @@ -216,6 +218,9 @@ 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 consistant across reqs */
> +        if (c->user_agent) av_dict_set(&opts, "user-agent", c->user_agent, 0);
> +        if (c->cookies) 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,11 +333,13 @@ 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];
> +    if (c->user_agent) av_dict_set(&opts, "user-agent", c->user_agent, 0);
> +    if (c->cookies) 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,
> @@ -429,7 +436,7 @@ reload:
>              goto reload;
>          }
>  
> -        ret = open_input(v);
> +        ret = open_input(c, v);
>          if (ret < 0)
>              return ret;
>      }
> @@ -461,11 +468,29 @@ 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_opt_get(u->priv_data, "user-agent", 0, (uint8_t**)&(c->user_agent));
> +        if (!strlen(c->user_agent)) {
    
> +            av_free(c->user_agent);
> +            c->user_agent = NULL;

av_freep() could be used here


> +        }
> +
> +        // get the previous cookies & set back to null if string size is zero
> +        av_opt_get(u->priv_data, "cookies", 0, (uint8_t**)&(c->cookies));
> +        if (!strlen(c->cookies)) {
    
> +            av_free(c->cookies);
> +            c->cookies = NULL;

and here

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130108/47fe42ed/attachment.asc>


More information about the ffmpeg-devel mailing list