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 | 8fb25961b94c6b8306c62f239352a111fbfcf788 (patch) | |
tree | 50705ae8121f9eff341b630ee9069948366866c8 | |
parent | f471caaf90526eb6177c9c91591010c04f64a0c3 (diff) | |
download | ffmpeg-8fb25961b94c6b8306c62f239352a111fbfcf788.tar.gz |
avcodec/g726: 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/g726.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/libavcodec/g726.c b/libavcodec/g726.c index 8c5c0940b8..2e053bc5e3 100644 --- a/libavcodec/g726.c +++ b/libavcodec/g726.c @@ -26,6 +26,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/opt.h" #include "avcodec.h" +#include "encode.h" #include "internal.h" #include "get_bits.h" #include "put_bits.h" @@ -353,7 +354,7 @@ static int g726_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int i, ret, out_size; out_size = (frame->nb_samples * c->code_size + 7) / 8; - 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; init_put_bits(&pb, avpkt->data, avpkt->size); @@ -370,7 +371,6 @@ static int g726_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, flush_put_bits(&pb); } - avpkt->size = out_size; *got_packet_ptr = 1; return 0; } @@ -401,10 +401,10 @@ const AVCodec ff_adpcm_g726_encoder = { .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_ADPCM_G726, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME, .priv_data_size = sizeof(G726Context), .init = g726_encode_init, .encode2 = g726_encode_frame, - .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, .priv_class = &g726_class, @@ -426,10 +426,10 @@ const AVCodec ff_adpcm_g726le_encoder = { .long_name = NULL_IF_CONFIG_SMALL("G.726 little endian ADPCM (\"right-justified\")"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_ADPCM_G726LE, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME, .priv_data_size = sizeof(G726Context), .init = g726_encode_init, .encode2 = g726_encode_frame, - .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, .priv_class = &g726le_class, |