[FFmpeg-devel] [PATCH 06/46] avcodec/adxenc: Avoid copying packet data, allow user-supplied buffers

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Apr 30 02:56:37 EEST 2021


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 at outlook.com>
---
 libavcodec/adxenc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index f507840a1a..fc31351330 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -22,6 +22,7 @@
 #include "avcodec.h"
 #include "adx.h"
 #include "bytestream.h"
+#include "encode.h"
 #include "internal.h"
 #include "put_bits.h"
 
@@ -148,7 +149,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     if (!samples) {
         if (c->eof)
             return 0;
-        if ((ret = ff_alloc_packet2(avctx, avpkt, 18, 0)) < 0)
+        if ((ret = ff_get_encode_buffer(avctx, avpkt, 18, 0)) < 0)
             return ret;
         c->eof = 1;
         dst = avpkt->data;
@@ -162,7 +163,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     }
 
     out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE;
-    if ((ret = ff_alloc_packet2(avctx, avpkt, out_size, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0)
         return ret;
     dst = avpkt->data;
 
@@ -192,10 +193,10 @@ const AVCodec ff_adpcm_adx_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_ADPCM_ADX,
+    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
     .priv_data_size = sizeof(ADXContext),
     .init           = adx_encode_init,
     .encode2        = adx_encode_frame,
-    .capabilities   = AV_CODEC_CAP_DELAY,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16,
                                                       AV_SAMPLE_FMT_NONE },
 };
-- 
2.27.0



More information about the ffmpeg-devel mailing list