[FFmpeg-devel] [PATCH] lavc/vaapi_encode: grow packet if vaMapBuffer returns multiple buffers

Linjie Fu linjie.fu at intel.com
Wed May 29 23:57:03 EEST 2019


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.

Using av_grow_packet to expand pkt if several buffers are returned.

Signed-off-by: Linjie Fu <linjie.fu at intel.com>
---
 libavcodec/vaapi_encode.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2dda451..2812237 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -490,6 +490,7 @@ static int vaapi_encode_output(AVCodecContext *avctx,
     VACodedBufferSegment *buf_list, *buf;
     VAStatus vas;
     int err;
+    uint8_t *ptr;
 
     err = vaapi_encode_wait(avctx, pic);
     if (err < 0)
@@ -509,11 +510,18 @@ static int vaapi_encode_output(AVCodecContext *avctx,
         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 (pkt->size)
+            err = av_grow_packet(pkt, buf->size);
+        else {
+            err = av_new_packet(pkt, buf->size);
+            ptr = pkt->data;
+        }
+
         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



More information about the ffmpeg-devel mailing list