diff mbox series

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

Message ID HE1PR0301MB215400454F8C55260FFE6F4A8F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit fbfae5eb36db0b0be1a8b9c715388e9fcfea0c0f
Headers show
Series [FFmpeg-devel,01/46] avcodec/a64multienc: Avoid intermediate buffer | 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 April 29, 2021, 11:57 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/s302menc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/s302menc.c b/libavcodec/s302menc.c
index 2d0615bb2c..f145fd5f4f 100644
--- a/libavcodec/s302menc.c
+++ b/libavcodec/s302menc.c
@@ -21,6 +21,7 @@ 
  */
 
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 #include "mathops.h"
 #include "put_bits.h"
@@ -83,7 +84,7 @@  static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt,
         return AVERROR(EINVAL);
     }
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, avpkt, buf_size, 0)) < 0)
         return ret;
 
     o = avpkt->data;
@@ -172,13 +173,14 @@  const AVCodec ff_s302m_encoder = {
     .long_name             = NULL_IF_CONFIG_SMALL("SMPTE 302M"),
     .type                  = AVMEDIA_TYPE_AUDIO,
     .id                    = AV_CODEC_ID_S302M,
+    .capabilities          = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_EXPERIMENTAL |
+                             AV_CODEC_CAP_VARIABLE_FRAME_SIZE,
     .priv_data_size        = sizeof(S302MEncContext),
     .init                  = s302m_encode_init,
     .encode2               = s302m_encode2_frame,
     .sample_fmts           = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32,
                                                             AV_SAMPLE_FMT_S16,
                                                             AV_SAMPLE_FMT_NONE },
-    .capabilities          = AV_CODEC_CAP_VARIABLE_FRAME_SIZE | AV_CODEC_CAP_EXPERIMENTAL,
     .supported_samplerates = (const int[]) { 48000, 0 },
  /* .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_STEREO,
                                                   AV_CH_LAYOUT_QUAD,