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 | f471caaf90526eb6177c9c91591010c04f64a0c3 (patch) | |
tree | e51e9d408736ec8329e9c3102b2e8d87493581ab /libavcodec/g723_1enc.c | |
parent | 63218fc2d09c37b20b17d82a2e565dbb0d2c34b5 (diff) | |
download | ffmpeg-f471caaf90526eb6177c9c91591010c04f64a0c3.tar.gz |
avcodec/g723_1enc: 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>
Diffstat (limited to 'libavcodec/g723_1enc.c')
-rw-r--r-- | libavcodec/g723_1enc.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c index 64899efc84..2b3cccee09 100644 --- a/libavcodec/g723_1enc.c +++ b/libavcodec/g723_1enc.c @@ -34,6 +34,7 @@ #include "avcodec.h" #include "celp_math.h" +#include "encode.h" #include "g723_1.h" #include "internal.h" @@ -1044,10 +1045,9 @@ static void fcb_search(G723_1_ChannelContext *p, int16_t *impulse_resp, * @param frame output buffer * @param size size of the buffer */ -static int pack_bitstream(G723_1_ChannelContext *p, AVPacket *avpkt) +static void pack_bitstream(G723_1_ChannelContext *p, AVPacket *avpkt, int info_bits) { PutBitContext pb; - int info_bits = 0; int i, temp; init_put_bits(&pb, avpkt->data, avpkt->size); @@ -1099,7 +1099,6 @@ static int pack_bitstream(G723_1_ChannelContext *p, AVPacket *avpkt) } flush_put_bits(&pb); - return frame_size[info_bits]; } static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, @@ -1112,7 +1111,7 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int16_t cur_lsp[LPC_ORDER]; int16_t weighted_lpc[LPC_ORDER * SUBFRAMES << 1]; int16_t vector[FRAME_LEN + PITCH_MAX]; - int offset, ret, i, j; + int offset, ret, i, j, info_bits = 0; int16_t *in, *start; HFParam hf[4]; @@ -1231,11 +1230,12 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_free(start); - if ((ret = ff_alloc_packet2(avctx, avpkt, 24, 0)) < 0) + ret = ff_get_encode_buffer(avctx, avpkt, frame_size[info_bits], 0); + if (ret < 0) return ret; *got_packet_ptr = 1; - avpkt->size = pack_bitstream(p, avpkt); + pack_bitstream(p, avpkt, info_bits); return 0; } @@ -1249,6 +1249,7 @@ const AVCodec ff_g723_1_encoder = { .long_name = NULL_IF_CONFIG_SMALL("G.723.1"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_G723_1, + .capabilities = AV_CODEC_CAP_DR1, .priv_data_size = sizeof(G723_1_Context), .init = g723_1_encode_init, .encode2 = g723_1_encode_frame, |