diff mbox series

[FFmpeg-devel,07/46] avcodec/aptxenc: Avoid copying packet data, allow user-supplied buffers

Message ID HE1PR0301MB21547AC05D0E1C71351AA91E8F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 9e9836424b63ee096fd715a2479066daff8dfa01
Headers show
Series [FFmpeg-devel,01/46] avcodec/a64multienc: Avoid intermediate buffer
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 29, 2021, 11:56 p.m. UTC
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>
---
 libavcodec/aptxenc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

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,