diff mbox series

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

Message ID HE1PR0301MB2154CB477DFF70D9A0E00D908F5F9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 3e6dcf0b1aff77d742520261c83ebdaa68d0e5cd
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:56 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/pcm-dvdenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

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,