[FFmpeg-devel] [PATCH] lavc/decode: do not use a context variable for function-local data

Michael Niedermayer michael at niedermayer.cc
Fri May 22 22:22:04 EEST 2020


On Fri, May 22, 2020 at 02:32:07PM -0300, James Almer wrote:
> On 5/22/2020 1:56 PM, Anton Khirnov wrote:
> > ---
> >  libavcodec/decode.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index f3327d74af..dbecdf3f46 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -586,6 +586,7 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
> >  int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
> >  {
> >      AVCodecInternal *avci = avctx->internal;
> > +    AVPacket buffer_pkt = { NULL };
> >      int ret;
> >  
> >      if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
> > @@ -597,16 +598,15 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
> >      if (avpkt && !avpkt->size && avpkt->data)
> >          return AVERROR(EINVAL);
> >  
> > -    av_packet_unref(avci->buffer_pkt);
> >      if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
> > -        ret = av_packet_ref(avci->buffer_pkt, avpkt);
> > +        ret = av_packet_ref(&buffer_pkt, avpkt);
> >          if (ret < 0)
> >              return ret;
> >      }
> >  
> > -    ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
> > +    ret = av_bsf_send_packet(avci->bsf, &buffer_pkt);
> >      if (ret < 0) {
> > -        av_packet_unref(avci->buffer_pkt);
> > +        av_packet_unref(&buffer_pkt);
> >          return ret;
> >      }
> 
> What's the gain here? You're not removing the context variable since
> it's used in the encode framework as well, and you're introducing a

> stack AVPacket (that, while harmless, is not even properly initialized).

It would be nice if we could avoid all such code, so that we can extend
AVPacket like other structs without Major bumping

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200522/11a37aa5/attachment.sig>


More information about the ffmpeg-devel mailing list