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

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


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

avcodec/pcm-dvdenc: 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=3e6dcf0b1aff77d742520261c83ebdaa68d0e5cd
---

 libavcodec/pcm-dvdenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c
index e644f30f5d..ae7de65f1d 100644
--- a/libavcodec/pcm-dvdenc.c
+++ b/libavcodec/pcm-dvdenc.c
@@ -21,6 +21,7 @@
 
 #include "avcodec.h"
 #include "bytestream.h"
+#include "encode.h"
 #include "internal.h"
 
 typedef struct PCMDVDContext {
@@ -119,7 +120,7 @@ static int pcm_dvd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     PutByteContext pb;
     int ret;
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size, 0)) < 0)
+    if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0)
         return ret;
 
     memcpy(avpkt->data, s->header, 3);
@@ -163,7 +164,6 @@ static int pcm_dvd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     }
 
     avpkt->pts      = frame->pts;
-    avpkt->size     = pkt_size;
     avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
     *got_packet_ptr = 1;
 
@@ -175,10 +175,10 @@ const AVCodec ff_pcm_dvd_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for DVD media"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_PCM_DVD,
+    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME,
     .priv_data_size = sizeof(PCMDVDContext),
     .init           = pcm_dvd_encode_init,
     .encode2        = pcm_dvd_encode_frame,
-    .capabilities   = AV_CODEC_CAP_SMALL_LAST_FRAME,
     .supported_samplerates = (const int[]) { 48000, 96000, 0},
     .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                             AV_CH_LAYOUT_STEREO,



More information about the ffmpeg-cvslog mailing list