From 259a76272911853e46e05e02e3718f4faed4745b Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sun, 25 Apr 2021 01:43:26 +0200 Subject: [PATCH] avcodec/a64multienc: Avoid copying packet data, allow user-supplied buffers When the packet size is known in advance like here, one can avoid an intermediate buffer for the packet data by using ff_get_encode_buffer() and also set AV_CODEC_CAP_DR1 at the same time. Signed-off-by: Andreas Rheinhardt --- libavcodec/a64multienc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c index ad2500e41a..e2dd85b756 100644 --- a/libavcodec/a64multienc.c +++ b/libavcodec/a64multienc.c @@ -27,6 +27,7 @@ #include "a64colors.h" #include "a64tables.h" #include "elbg.h" +#include "encode.h" #include "internal.h" #include "libavutil/avassert.h" #include "libavutil/common.h" @@ -327,7 +328,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt, /* any frames to encode? */ if (c->mc_lifetime) { int alloc_size = charset_size + c->mc_lifetime*(screen_size + colram_size); - if ((ret = ff_alloc_packet2(avctx, pkt, alloc_size, 0)) < 0) + if ((ret = ff_get_encode_buffer(avctx, pkt, alloc_size, 0)) < 0) return ret; buf = pkt->data; @@ -383,8 +384,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt, pkt->pts = pkt->dts = c->next_pts; c->next_pts = AV_NOPTS_VALUE; - av_assert0(pkt->size >= req_size); - pkt->size = req_size; + av_assert0(pkt->size == req_size); pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = !!req_size; } @@ -397,12 +397,12 @@ const AVCodec ff_a64multi_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_A64_MULTI, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, .priv_data_size = sizeof(A64Context), .init = a64multi_encode_init, .encode2 = a64multi_encode_frame, .close = a64multi_close_encoder, .pix_fmts = (const enum AVPixelFormat[]) {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}, - .capabilities = AV_CODEC_CAP_DELAY, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, }; #endif @@ -412,12 +412,12 @@ const AVCodec ff_a64multi5_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64, extended with 5th color (colram)"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_A64_MULTI5, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, .priv_data_size = sizeof(A64Context), .init = a64multi_encode_init, .encode2 = a64multi_encode_frame, .close = a64multi_close_encoder, .pix_fmts = (const enum AVPixelFormat[]) {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}, - .capabilities = AV_CODEC_CAP_DELAY, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, }; #endif