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 <andreas.rheinhardt@outlook.com>
pull/362/head
Andreas Rheinhardt 4 years ago
parent a0b55e2adb
commit 259a762729
  1. 10
      libavcodec/a64multienc.c

@ -27,6 +27,7 @@
#include "a64colors.h" #include "a64colors.h"
#include "a64tables.h" #include "a64tables.h"
#include "elbg.h" #include "elbg.h"
#include "encode.h"
#include "internal.h" #include "internal.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/common.h" #include "libavutil/common.h"
@ -327,7 +328,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
/* any frames to encode? */ /* any frames to encode? */
if (c->mc_lifetime) { if (c->mc_lifetime) {
int alloc_size = charset_size + c->mc_lifetime*(screen_size + colram_size); 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; return ret;
buf = pkt->data; buf = pkt->data;
@ -383,8 +384,7 @@ static int a64multi_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
pkt->pts = pkt->dts = c->next_pts; pkt->pts = pkt->dts = c->next_pts;
c->next_pts = AV_NOPTS_VALUE; c->next_pts = AV_NOPTS_VALUE;
av_assert0(pkt->size >= req_size); av_assert0(pkt->size == req_size);
pkt->size = req_size;
pkt->flags |= AV_PKT_FLAG_KEY; pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = !!req_size; *got_packet = !!req_size;
} }
@ -397,12 +397,12 @@ const AVCodec ff_a64multi_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64"), .long_name = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64"),
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_A64_MULTI, .id = AV_CODEC_ID_A64_MULTI,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.priv_data_size = sizeof(A64Context), .priv_data_size = sizeof(A64Context),
.init = a64multi_encode_init, .init = a64multi_encode_init,
.encode2 = a64multi_encode_frame, .encode2 = a64multi_encode_frame,
.close = a64multi_close_encoder, .close = a64multi_close_encoder,
.pix_fmts = (const enum AVPixelFormat[]) {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}, .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, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
}; };
#endif #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)"), .long_name = NULL_IF_CONFIG_SMALL("Multicolor charset for Commodore 64, extended with 5th color (colram)"),
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_A64_MULTI5, .id = AV_CODEC_ID_A64_MULTI5,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.priv_data_size = sizeof(A64Context), .priv_data_size = sizeof(A64Context),
.init = a64multi_encode_init, .init = a64multi_encode_init,
.encode2 = a64multi_encode_frame, .encode2 = a64multi_encode_frame,
.close = a64multi_close_encoder, .close = a64multi_close_encoder,
.pix_fmts = (const enum AVPixelFormat[]) {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}, .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, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
}; };
#endif #endif

Loading…
Cancel
Save