diff mbox series

[FFmpeg-devel,18/46] avcodec/fitsenc: Avoid copying packet data, allow user-supplied buffers

Message ID HE1PR0301MB21543561F0C88F24B93AF82F8F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 6e2fe9958a96d14298151803e39203e2ab11332b
Headers show
Series [FFmpeg-devel,01/46] avcodec/a64multienc: Avoid intermediate buffer | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 29, 2021, 11:56 p.m. UTC
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>
---
 libavcodec/fitsenc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff mbox series

Patch

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,