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

Andreas Rheinhardt git at videolan.org
Sun May 23 16:41:58 EEST 2021


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

avcodec/libcodec2: 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.

Reviewed-by: James Almer <jamrial at gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libavcodec/libcodec2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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



More information about the ffmpeg-cvslog mailing list