diff mbox series

[FFmpeg-devel,08/34] avcodec/fitsenc: Avoid copying packet data

Message ID HE1PR0301MB2154973273B4645AF156FD888F439@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Superseded
Headers show
Series [FFmpeg-devel,01/34] avcodec/adpcmenc: Avoid copying packet data | expand

Checks

Context Check Description
andriy/x86_make_warn warning New warnings during build
andriy/x86_make success Make finished
andriy/x86_make_fate fail Make fate failed
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate warning Make fate failed

Commit Message

Andreas Rheinhardt April 25, 2021, 10:34 p.m. UTC
When the packet size is known in advance like here, one can avoid
an intermediate buffer for the packet data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/fitsenc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/fitsenc.c b/libavcodec/fitsenc.c
index b44507e436..201604aa59 100644
--- a/libavcodec/fitsenc.c
+++ b/libavcodec/fitsenc.c
@@ -80,7 +80,8 @@  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_alloc_packet2(avctx, pkt, padded_data_size,
+                                            padded_data_size)) < 0)
         return ret;
 
     bytestream_start =
@@ -104,9 +105,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;