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

Andreas Rheinhardt git at videolan.org
Wed May 5 15:38:06 EEST 2021


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

avcodec/g722enc: 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=63218fc2d09c37b20b17d82a2e565dbb0d2c34b5
---

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

diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 8c4327b5f6..bb011fb81b 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -29,6 +29,7 @@
 
 #include "libavutil/avassert.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "g722.h"
 #include "libavutil/common.h"
@@ -346,7 +347,7 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     int nb_samples, out_size, ret;
 
     out_size = (frame->nb_samples + 1) / 2;
-    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;
 
     nb_samples = frame->nb_samples - (frame->nb_samples & 1);
@@ -373,11 +374,11 @@ const AVCodec ff_adpcm_g722_encoder = {
     .long_name       = NULL_IF_CONFIG_SMALL("G.722 ADPCM"),
     .type            = AVMEDIA_TYPE_AUDIO,
     .id              = AV_CODEC_ID_ADPCM_G722,
+    .capabilities    = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME,
     .priv_data_size  = sizeof(G722Context),
     .init            = g722_encode_init,
     .close           = g722_encode_close,
     .encode2         = g722_encode_frame,
-    .capabilities    = AV_CODEC_CAP_SMALL_LAST_FRAME,
     .sample_fmts     = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
     .channel_layouts = (const uint64_t[]){ AV_CH_LAYOUT_MONO, 0 },
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,



More information about the ffmpeg-cvslog mailing list