[FFmpeg-cvslog] avcodec/pcm: Allow user-supplied buffers

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


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue Apr 27 16:58:16 2021 +0200| [0788069cb1cf95b8858f9315ffe9cd4e1916eef1] | committer: Andreas Rheinhardt

avcodec/pcm: Allow user-supplied buffers

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

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 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,                          \



More information about the ffmpeg-cvslog mailing list