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

Andreas Rheinhardt git at videolan.org
Wed May 5 15:38:28 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 25 01:43:26 2021 +0200| [fbfae5eb36db0b0be1a8b9c715388e9fcfea0c0f] | committer: Andreas Rheinhardt

avcodec/s302menc: 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 at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fbfae5eb36db0b0be1a8b9c715388e9fcfea0c0f
---

 libavcodec/s302menc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/s302menc.c b/libavcodec/s302menc.c
index b9f35fb0cb..33633627f6 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,



More information about the ffmpeg-cvslog mailing list