diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-04-25 01:43:26 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-05-05 14:17:03 +0200 |
commit | 63218fc2d09c37b20b17d82a2e565dbb0d2c34b5 (patch) | |
tree | 2387d1836f01c12388682743eafde9140422827a | |
parent | 6e2fe9958a96d14298151803e39203e2ab11332b (diff) | |
download | ffmpeg-63218fc2d09c37b20b17d82a2e565dbb0d2c34b5.tar.gz |
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@outlook.com>
-rw-r--r-- | libavcodec/g722enc.c | 5 |
1 files 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, |