[FFmpeg-devel] [PATCH 3/4] lavf/demux: stop calling avcodec_close()

Anton Khirnov anton at khirnov.net
Mon Feb 5 18:59:42 EET 2024


Quoting Leo Izen (2024-02-03 03:35:45)
> On 2/1/24 03:29, Anton Khirnov wrote:
> > Replace it with recreating the codec context.
> > 
> > This is the last remaining blocker for deprecating avcodec_close().
> > ---
> >   libavformat/demux.c | 53 ++++++++++++++++++++++++++++++++++++++++-----
> >   1 file changed, 48 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavformat/demux.c b/libavformat/demux.c
> > index 6f640b92b1..c1640c459c 100644
> > --- a/libavformat/demux.c
> > +++ b/libavformat/demux.c
> > @@ -1250,6 +1250,52 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts)
> >       return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den);
> >   }
> >   
> > +static int codec_close(FFStream *sti)
> > +{
> > +    AVCodecContext *avctx_new = NULL;
> > +    AVCodecParameters *par_tmp = NULL;
> > +    int ret = 0;
> > +
> 
> I believe we can drop the initialization from avctx_new and from ret, 
> because avctx_new is assigned immediately, and ret is assigned before 
> each goto before it's assigned properly.

It's safer wrt future modifications of the code, e.g. if someone would
insert something that could fail before allocating avctx.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list