[FFmpeg-devel] Re: [PATCH 2/6] lavc: split LSCR decoder out of PNG decoder

Anton Khirnov anton at khirnov.net
Wed Feb 24 10:35:13 EET 2021


Quoting James Almer (2021-02-20 15:38:42)
> > +
> > +static void handle_row(LSCRContext *s, AVFrame *frame)
> 
> Unused frame argument.

Right, dropped locally.

> > +static int decode_frame_lscr(AVCodecContext *avctx,
> > +                             void *data, int *got_frame,
> > +                             AVPacket *avpkt)
> > +{
> > +    LSCRContext *const s = avctx->priv_data;
> > +    GetByteContext *gb = &s->gb;
> > +    AVFrame *frame = data;
> > +    int ret, nb_blocks, offset = 0;
> > +
> > +    if (avpkt->size < 2)
> > +        return AVERROR_INVALIDDATA;
> > +    if (avpkt->size == 2)
> > +        return 0;
> > +
> > +    bytestream2_init(gb, avpkt->data, avpkt->size);
> > +
> > +    if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
> > +        return ret;
> > +
> > +    nb_blocks = bytestream2_get_le16(gb);
> > +    if (bytestream2_get_bytes_left(gb) < 2 + nb_blocks * (12 + 8))
> > +        return AVERROR_INVALIDDATA;
> > +
> > +    if (s->last_picture->data[0]) {
> > +        ret = av_frame_copy(frame, s->last_picture);
> 
> You could use ff_reget_buf() instead. And if nb_blocks can be 0 (meaning 
> no changes since the previous frame), you could even use the 
> FF_REGET_BUFFER_FLAG_READONLY flag and completely avoid any memcpy.

Good idea, but I'd do it in a separate patch, so that the split is
closer to just a move.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list