diff mbox series

[FFmpeg-devel,03/39] avcodec/libcodec2: Avoid copying packet data, allow user-supplied buffers

Message ID HE1PR0301MB21541AD8DB330FFE0E2CABF78F299@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 398822a70edf860cd47514e34e15c80c2dfca584
Headers show
Series [FFmpeg-devel,01/39] avcodec/audiotoolboxenc: Remove AV_CODEC_CAP_DR1 | 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 May 21, 2021, 9:17 a.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/libcodec2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/libcodec2.c b/libavcodec/libcodec2.c
index 562a616f59..2996dc42f5 100644
--- a/libavcodec/libcodec2.c
+++ b/libavcodec/libcodec2.c
@@ -22,6 +22,7 @@ 
 #include <codec2/codec2.h>
 #include "avcodec.h"
 #include "libavutil/opt.h"
+#include "encode.h"
 #include "internal.h"
 #include "codec2utils.h"
 
@@ -169,7 +170,7 @@  static int libcodec2_encode(AVCodecContext *avctx, AVPacket *avpkt,
     LibCodec2Context *c2 = avctx->priv_data;
     int16_t *samples = (int16_t *)frame->data[0];
 
-    int ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align, 0);
+    int ret = ff_get_encode_buffer(avctx, avpkt, avctx->block_align, 0);
     if (ret < 0) {
         return ret;
     }
@@ -201,11 +202,11 @@  const AVCodec ff_libcodec2_encoder = {
     .long_name              = NULL_IF_CONFIG_SMALL("codec2 encoder using libcodec2"),
     .type                   = AVMEDIA_TYPE_AUDIO,
     .id                     = AV_CODEC_ID_CODEC2,
+    .capabilities           = AV_CODEC_CAP_DR1,
     .priv_data_size         = sizeof(LibCodec2Context),
     .init                   = libcodec2_init_encoder,
     .close                  = libcodec2_close,
     .encode2                = libcodec2_encode,
-    .capabilities           = 0,
     .supported_samplerates  = (const int[]){ 8000, 0 },
     .sample_fmts            = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
     .channel_layouts        = (const uint64_t[]) { AV_CH_LAYOUT_MONO, 0 },