diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-04-25 01:43:26 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-05-05 14:17:03 +0200 |
commit | 6e2fe9958a96d14298151803e39203e2ab11332b (patch) | |
tree | 218d37c43c854c1e38a6f946626c032a37e3f2e7 | |
parent | ae7a7dc458113e62add7c559c555efccab4f8eee (diff) | |
download | ffmpeg-6e2fe9958a96d14298151803e39203e2ab11332b.tar.gz |
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 <andreas.rheinhardt@outlook.com>
-rw-r--r-- | libavcodec/fitsenc.c | 9 |
1 files changed, 4 insertions, 5 deletions
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, |