diff mbox series

[FFmpeg-devel,24/39] avcodec/sbcenc: Avoid copying packet data, allow user-supplied buffers

Message ID HE1PR0301MB2154251C32F6BCD9FEDD64B18F299@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 7a3613696d9beb625c09c703723884eb18a58976
Headers show
Series [FFmpeg-devel,01/39] avcodec/audiotoolboxenc: Remove AV_CODEC_CAP_DR1 | expand

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 May 21, 2021, 9:17 a.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/sbcenc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/sbcenc.c b/libavcodec/sbcenc.c
index e87c623d4b..5f9a214a1a 100644
--- a/libavcodec/sbcenc.c
+++ b/libavcodec/sbcenc.c
@@ -32,6 +32,7 @@ 
 
 #include "libavutil/opt.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "profiles.h"
 #include "put_bits.h"
@@ -290,7 +291,7 @@  static int sbc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     if (av_frame->nb_samples * frame->channels * 2 < frame->codesize)
         return 0;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, frame_length, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, avpkt, frame_length, 0)) < 0)
         return ret;
 
     /* Select the needed input data processing function and call it */
@@ -346,10 +347,10 @@  const AVCodec ff_sbc_encoder = {
     .long_name             = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband codec)"),
     .type                  = AVMEDIA_TYPE_AUDIO,
     .id                    = AV_CODEC_ID_SBC,
+    .capabilities          = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME,
     .priv_data_size        = sizeof(SBCEncContext),
     .init                  = sbc_encode_init,
     .encode2               = sbc_encode_frame,
-    .capabilities          = AV_CODEC_CAP_SMALL_LAST_FRAME,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                                   AV_CH_LAYOUT_STEREO, 0},