[FFmpeg-devel] [PATCH 2/5] avformat/ffmdec: replace most codec uses by codecpar

Andreas Cadhalpun andreas.cadhalpun at googlemail.com
Sat Dec 3 02:19:05 EET 2016


On 03.12.2016 00:52, Michael Niedermayer wrote:
> This is a bit messy as codecar does not support AVOptions so we need
> to use AVCodecContext where AVOptions are required and copy back and forth.
> 
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
>  libavformat/ffmdec.c | 159 ++++++++++++++++++++++++++-------------------------
>  1 file changed, 82 insertions(+), 77 deletions(-)
> 
> diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
> index 9192bff507..25edeebb7e 100644
> --- a/libavformat/ffmdec.c
> +++ b/libavformat/ffmdec.c
> @@ -250,11 +250,6 @@ static void adjust_write_index(AVFormatContext *s)
>  
>  static int ffm_close(AVFormatContext *s)
>  {
> -    int i;
> -
> -    for (i = 0; i < s->nb_streams; i++)
> -        av_freep(&s->streams[i]->codec->rc_eq);
> -
>      return 0;
>  }

Why not remove the entire function?

> @@ -514,9 +518,6 @@ static int ffm2_read_header(AVFormatContext *s)
>          avio_seek(pb, next, SEEK_SET);
>      }
>  
> -    for (i = 0; i < s->nb_streams; i++)
> -        avcodec_parameters_from_context(s->streams[i]->codecpar, s->streams[i]->codec);
> -

This loop is the only place the variable i is used, so please remove it's
declaration, too.

> @@ -539,7 +542,8 @@ static int ffm_read_header(AVFormatContext *s)
>      FFMContext *ffm = s->priv_data;
>      AVStream *st;
>      AVIOContext *pb = s->pb;
> -    AVCodecContext *codec;
> +    AVCodecContext *codec, *dummy_codec = NULL;
> +    AVCodecParameters *codecpar;
>      const AVCodecDescriptor *codec_desc;
>      int i, nb_streams, ret;
>      uint32_t tag;
> @@ -562,6 +566,7 @@ static int ffm_read_header(AVFormatContext *s)
>      } else {
>          ffm->file_size = (UINT64_C(1) << 63) - 1;
>      }
> +    dummy_codec = avcodec_alloc_context3(NULL);
>  
>      nb_streams = avio_rb32(pb);
>      avio_rb32(pb); /* total bitrate */
> @@ -577,31 +582,31 @@ static int ffm_read_header(AVFormatContext *s)
>  
>          codec = st->codec;

Here should be:
           codecpar = st->codecpar;

>          /* generic info */
> -        codec->codec_id = avio_rb32(pb);
> -        codec_desc = avcodec_descriptor_get(codec->codec_id);
> +        codecpar->codec_id = avio_rb32(pb);

Otherwise codecpar is uninitialized here.

Best regards,
Andreas



More information about the ffmpeg-devel mailing list