From 6e2fe9958a96d14298151803e39203e2ab11332b Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sun, 25 Apr 2021 01:43:26 +0200 Subject: avcodec/fitsenc: 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/fitsenc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/fitsenc.c b/libavcodec/fitsenc.c index 80d0d71d1d..d96baad986 100644 --- a/libavcodec/fitsenc.c +++ b/libavcodec/fitsenc.c @@ -32,13 +32,14 @@ #include "libavutil/intreadwrite.h" #include "avcodec.h" #include "bytestream.h" +#include "encode.h" #include "internal.h" static int fits_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { AVFrame * const p = (AVFrame *)pict; - uint8_t *bytestream, *bytestream_start, *ptr; + uint8_t *bytestream, *ptr; const uint16_t flip = (1 << 15); uint64_t data_size = 0, padded_data_size = 0; int ret, bitpix, naxis3 = 1, i, j, k, bytes_left; @@ -80,10 +81,9 @@ static int fits_encode_frame(AVCodecContext *avctx, AVPacket *pkt, data_size = (bitpix >> 3) * avctx->height * avctx->width * naxis3; padded_data_size = ((data_size + 2879) / 2880 ) * 2880; - if ((ret = ff_alloc_packet2(avctx, pkt, padded_data_size, 0)) < 0) + if ((ret = ff_get_encode_buffer(avctx, pkt, padded_data_size, 0)) < 0) return ret; - bytestream_start = bytestream = pkt->data; for (k = 0; k < naxis3; k++) { @@ -104,9 +104,7 @@ static int fits_encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytes_left = padded_data_size - data_size; memset(bytestream, 0, bytes_left); - bytestream += bytes_left; - pkt->size = bytestream - bytestream_start; pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = 1; @@ -118,6 +116,7 @@ const AVCodec ff_fits_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Flexible Image Transport System"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_FITS, + .capabilities = AV_CODEC_CAP_DR1, .encode2 = fits_encode_frame, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_GBRAP16BE, AV_PIX_FMT_GBRP16BE, -- cgit v1.2.3