[FFmpeg-cvslog] avcodec/adxenc: Avoid copying packet data, allow user-supplied buffers

Andreas Rheinhardt git at videolan.org
Wed May 5 15:37:41 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 25 01:43:26 2021 +0200| [ad232c6833d9f192324c9e99c19d1b4dd7852828] | committer: Andreas Rheinhardt

avcodec/adxenc: 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 at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ad232c6833d9f192324c9e99c19d1b4dd7852828
---

 libavcodec/adxenc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index fecc0ce384..c5849a40a1 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 },
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,



More information about the ffmpeg-cvslog mailing list