[FFmpeg-devel] [PATCH, v2] lavc/vaapi_encode: grow packet if vaMapBuffer returns multiple buffers
Max Dmitrichenko
maxim.d33 at gmail.com
Wed Nov 20 09:03:30 EET 2019
On Sun, Sep 29, 2019 at 3:19 AM Fu, Linjie <linjie.fu at intel.com> wrote:
> > -----Original Message-----
> > From: Li, Zhong <zhong.li at intel.com>
> > Sent: Friday, September 13, 2019 00:05
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel at ffmpeg.org>
> > Cc: Fu, Linjie <linjie.fu at intel.com>
> > Subject: RE: [FFmpeg-devel] [PATCH, v2] lavc/vaapi_encode: grow packet if
> > vaMapBuffer returns multiple buffers
> >
> > > From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of
> > Linjie Fu
> > > Sent: Friday, May 31, 2019 8:35 AM
> > > To: ffmpeg-devel at ffmpeg.org
> > > Cc: Fu, Linjie <linjie.fu at intel.com>
> > > Subject: [FFmpeg-devel] [PATCH, v2] lavc/vaapi_encode: grow packet if
> > > vaMapBuffer returns multiple buffers
> > >
> > > It seems that VA_CODED_BUF_STATUS_SINGLE_NALU allows driver to
> > map
> > > buffer for each slice.
> > >
> > > Currently, assigning new buffer for pkt when multiple buffer returns
> from
> > > vaMapBuffer will cover the previous encoded pkt data and lead to encode
> > issues.
> > >
> > > Iterate through the buf_list first to find out the total buffer size
> needed for
> > the
> > > pkt, allocate the whole pkt to avoid repeated reallocation and memcpy,
> > then copy
> > > data from each buf to pkt.
> > >
> > > Signed-off-by: Linjie Fu <linjie.fu at intel.com>
> > > ---
> > > [v2]: allocate the whole pkt to avoid repeated reallocation and memcpy
> > >
> > > libavcodec/vaapi_encode.c | 18 +++++++++++++-----
> > > 1 file changed, 13 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index
> > > 2dda451..9c9e5dd 100644
> > > --- a/libavcodec/vaapi_encode.c
> > > +++ b/libavcodec/vaapi_encode.c
> > > @@ -489,6 +489,8 @@ static int vaapi_encode_output(AVCodecContext
> > *avctx,
> > > VAAPIEncodeContext *ctx = avctx->priv_data;
> > > VACodedBufferSegment *buf_list, *buf;
> > > VAStatus vas;
> > > + int total_size = 0;
> > > + uint8_t *ptr;
> > > int err;
> > >
> > > err = vaapi_encode_wait(avctx, pic); @@ -505,15 +507,21 @@ static
> int
> > > vaapi_encode_output(AVCodecContext *avctx,
> > > goto fail;
> > > }
> > >
> > > + for (buf = buf_list; buf; buf = buf->next)
> > > + total_size += buf->size;
> > > +
> > > + err = av_new_packet(pkt, total_size);
> > > + ptr = pkt->data;
> > > +
> > > + if (err < 0)
> > > + goto fail_mapped;
> > > +
> > > for (buf = buf_list; buf; buf = buf->next) {
> > > av_log(avctx, AV_LOG_DEBUG, "Output buffer: %u bytes "
> > > "(status %08x).\n", buf->size, buf->status);
> > >
> > > - err = av_new_packet(pkt, buf->size);
> > > - if (err < 0)
> > > - goto fail_mapped;
> > > -
> > > - memcpy(pkt->data, buf->buf, buf->size);
> > > + memcpy(ptr, buf->buf, buf->size);
> > > + ptr += buf->size;
> > > }
> > >
> > > if (pic->type == PICTURE_TYPE_IDR)
> > > --
> > > 2.7.4
> >
> > LGTM
>
> Thanks for review.
> A kindly ping.
>
> - linjie
>
LGTM
regards
Max
More information about the ffmpeg-devel
mailing list