diff mbox series

[FFmpeg-devel,04/46] avcodec/adpcmenc: Avoid copying packet data, allow direct rendering

Message ID HE1PR0301MB215416F7ED7B0AEEC11409C98F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 32b20a274a8a628b5f255ca6641aef1c9c3b5713
Headers show
Series [FFmpeg-devel,01/46] avcodec/a64multienc: Avoid intermediate buffer
Related show

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; and one can also use
user-supplied buffers.

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

Patch

diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 1c62ca5a83..2b5a606699 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -29,6 +29,7 @@ 
 #include "bytestream.h"
 #include "adpcm.h"
 #include "adpcm_data.h"
+#include "encode.h"
 #include "internal.h"
 
 /**
@@ -605,7 +606,7 @@  static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         pkt_size = (frame->nb_samples * avctx->channels) / 2;
     else
         pkt_size = avctx->block_align;
-    if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0)
         return ret;
     dst = avpkt->data;
 
@@ -960,7 +961,6 @@  static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         return AVERROR(EINVAL);
     }
 
-    avpkt->size = pkt_size;
     *got_packet_ptr = 1;
     return 0;
 }
@@ -1005,7 +1005,7 @@  const AVCodec ff_ ## name_ ## _encoder = {                                 \
     .encode2        = adpcm_encode_frame,                                  \
     .close          = adpcm_encode_close,                                  \
     .sample_fmts    = sample_fmts_,                                        \
-    .capabilities   = capabilities_,                                       \
+    .capabilities   = capabilities_ | AV_CODEC_CAP_DR1,                    \
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, \
     .priv_class     = &name_ ## _encoder_class,                            \
 }