diff mbox series

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

Message ID HE1PR0301MB2154E6B299D691A71ADF01868F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
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/adxenc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

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 },
 };