[FFmpeg-devel] [PATCH] avformat/hlsenc: set the options when open the key info files

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sat Mar 7 05:06:46 EET 2020


Steven Liu:
> make the options same as segments for the http put method
> 
> Signed-off-by: Steven Liu <liuqi05 at kuaishou.com>
> ---
>  libavformat/hlsenc.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f6dd894343..88062ac536 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -685,6 +685,7 @@ static int do_encrypt(AVFormatContext *s, VariantStream *vs)
>      }
>  
>      if (!*hls->key_string) {
> +        AVDictionary *options = NULL;
>          if (!hls->key) {
>              if ((ret = randomize(key, sizeof(key))) < 0) {
>                  av_log(s, AV_LOG_ERROR, "Cannot generate a strong random key\n");
> @@ -695,8 +696,10 @@ static int do_encrypt(AVFormatContext *s, VariantStream *vs)
>          }
>  
>          ff_data_to_hex(hls->key_string, key, sizeof(key), 0);
> -        if ((ret = s->io_open(s, &pb, hls->key_file, AVIO_FLAG_WRITE, NULL)) < 0)
> +        set_http_options(s, &options, hls);
> +        if ((ret = s->io_open(s, &pb, hls->key_file, AVIO_FLAG_WRITE, &options)) < 0)

Here and below the options might leak on error. The easiest way to fix
this is to free the options before checking whether opening IO failed
or not.

>              return ret;
> +        av_dict_free(&options);
>          avio_seek(pb, 0, SEEK_CUR);
>          avio_write(pb, key, KEYSIZE);
>          avio_close(pb);
> @@ -711,13 +714,15 @@ static int hls_encryption_start(AVFormatContext *s)
>      int ret;
>      AVIOContext *pb;
>      uint8_t key[KEYSIZE];
> +     AVDictionary *options = NULL;

There seems to be a whitespace issue.
>  
> -    if ((ret = s->io_open(s, &pb, hls->key_info_file, AVIO_FLAG_READ, NULL)) < 0) {
> +    set_http_options(s, &options, hls);
> +    if ((ret = s->io_open(s, &pb, hls->key_info_file, AVIO_FLAG_READ, &options)) < 0) {
>          av_log(hls, AV_LOG_ERROR,
>                 "error opening key info file %s\n", hls->key_info_file);
>          return ret;
>      }
> -
> +    av_dict_free(&options);
>      ff_get_line(pb, hls->key_uri, sizeof(hls->key_uri));
>      hls->key_uri[strcspn(hls->key_uri, "\r\n")] = '\0';
>  
> 



More information about the ffmpeg-devel mailing list