[FFmpeg-devel] [PATCH 07/46] avcodec/aptxenc: Avoid copying packet data, allow user-supplied buffers
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Fri Apr 30 02:56:38 EEST 2021
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>
---
libavcodec/aptxenc.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libavcodec/aptxenc.c b/libavcodec/aptxenc.c
index f432a123d0..733ebc42c3 100644
--- a/libavcodec/aptxenc.c
+++ b/libavcodec/aptxenc.c
@@ -21,6 +21,7 @@
*/
#include "aptx.h"
+#include "encode.h"
/*
* Half-band QMF analysis filter realized with a polyphase FIR filter.
@@ -214,7 +215,7 @@ static int aptx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
return ret;
output_size = s->block_size * frame->nb_samples/4;
- if ((ret = ff_alloc_packet2(avctx, avpkt, output_size, 0)) < 0)
+ if ((ret = ff_get_encode_buffer(avctx, avpkt, output_size, 0)) < 0)
return ret;
for (pos = 0, ipos = 0; pos < output_size; pos += s->block_size, ipos += 4) {
@@ -245,11 +246,11 @@ const AVCodec ff_aptx_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("aptX (Audio Processing Technology for Bluetooth)"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_APTX,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME,
.priv_data_size = sizeof(AptXContext),
.init = ff_aptx_init,
.encode2 = aptx_encode_frame,
.close = aptx_close,
- .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P,
@@ -264,11 +265,11 @@ const AVCodec ff_aptx_hd_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("aptX HD (Audio Processing Technology for Bluetooth)"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_APTX_HD,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME,
.priv_data_size = sizeof(AptXContext),
.init = ff_aptx_init,
.encode2 = aptx_encode_frame,
.close = aptx_close,
- .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P,
--
2.27.0
More information about the ffmpeg-devel
mailing list