[FFmpeg-devel] [PATCH] HTTP options in HLS (again)

Stefano Sabatini stefasab at gmail.com
Wed Jan 16 18:29:27 CET 2013


On date Tuesday 2013-01-15 21:39:09 -0500, Micah Galizia encoded:
> Hello,
> 
> Attached is a patch that preserves the user-agent and cookies HTTP protocol
> options in the HLS demuxer.  Its the same as the one I previously submitted
> without the HTTP changes. If there are no problems with this, I'll submit a
> git format-patch version.
> 
> 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

> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index f515dfb..a38327e 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);

nit: vertical align

I think you can skip the if() checks.

>          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);

same

>      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,25 @@ 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_freep(c->user_agent);

Note: an av_opt_get_string() may solve the ""/NULL confusion.

> +
> +        // 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_freep(c->cookies);

Aren't you leaking c->user_agent/cookies?
-- 
FFmpeg = Fabulous and Fantastic Marvellous Purposeless Encoding/decoding Gorilla


More information about the ffmpeg-devel mailing list