[FFmpeg-devel] [PATCH 28/46] avcodec/pcm-dvdenc: Avoid copying packet data, allow user-supplied buffers
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Fri Apr 30 02:56:59 EEST 2021
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>
---
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,
--
2.27.0
More information about the ffmpeg-devel
mailing list