[FFmpeg-devel] [PATCH 29/46] avcodec/pcm: Allow user-supplied buffers

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Apr 30 02:57:00 EEST 2021


Trivial for encoders that know the size of the output packet in advance.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/pcm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 79b33b935c..e9b8eab484 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -30,6 +30,7 @@
 #include "libavutil/thread.h"
 #include "avcodec.h"
 #include "bytestream.h"
+#include "encode.h"
 #include "internal.h"
 #include "mathops.h"
 #include "pcm_tablegen.h"
@@ -106,7 +107,7 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     n           = frame->nb_samples * avctx->channels;
     samples     = (const short *)frame->data[0];
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size, n * sample_size)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, avpkt, n * sample_size, 0)) < 0)
         return ret;
     dst = avpkt->data;
 
@@ -555,9 +556,9 @@ const AVCodec ff_ ## name_ ## _encoder = {                                  \
     .long_name    = NULL_IF_CONFIG_SMALL(long_name_),                       \
     .type         = AVMEDIA_TYPE_AUDIO,                                     \
     .id           = AV_CODEC_ID_ ## id_,                                    \
+    .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE,    \
     .init         = pcm_encode_init,                                        \
     .encode2      = pcm_encode_frame,                                       \
-    .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE,                       \
     .sample_fmts  = (const enum AVSampleFormat[]){ sample_fmt_,             \
                                                    AV_SAMPLE_FMT_NONE },    \
     .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,                          \
-- 
2.27.0



More information about the ffmpeg-devel mailing list