summaryrefslogtreecommitdiff
path: root/libavcodec/vaapi_encode.c
diff options
context:
space:
mode:
authorLinjie Fu <linjie.fu@intel.com>2019-05-30 20:34:31 -0400
committerRuiling Song <ruiling.song@intel.com>2019-12-17 07:57:03 +0800
commitefefba61f8513e9d909af041b17584fd82775c63 (patch)
tree78f67b1e49daaced24da7562aa27b301d19d47c4 /libavcodec/vaapi_encode.c
parent2e2dfe6673fa4a75f988cae5370e543357be7d99 (diff)
downloadffmpeg-efefba61f8513e9d909af041b17584fd82775c63.tar.gz
lavc/vaapi_encode: grow packet if vaMapBuffer returns multiple buffers
Currently, assigning new buffer for pkt when multiple buffers were returned from vaMapBuffer will overwrite 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@intel.com>
Diffstat (limited to 'libavcodec/vaapi_encode.c')
-rw-r--r--libavcodec/vaapi_encode.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 3be9159d37..b0235114df 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -579,6 +579,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);
@@ -595,15 +597,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)