aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-04-25 01:43:26 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-23 15:12:57 +0200
commit5abb5c04155b536f26fc88311ac3132890111360 (patch)
treec2249ee58f14e4657f01affa6dd50fb627c483a7
parent314c086a859cffeb53ad4e227d77f42f6301a9b9 (diff)
downloadffmpeg-5abb5c04155b536f26fc88311ac3132890111360.tar.gz
avcodec/flacenc: Avoid copying packet data, allow user-supplied buffers
The FLAC encoder calculates the size in advance, so 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. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/flacenc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index 37ed1e4cce..de36d33333 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -27,6 +27,7 @@
#include "avcodec.h"
#include "bswapdsp.h"
+#include "encode.h"
#include "put_bits.h"
#include "golomb.h"
#include "internal.h"
@@ -1378,7 +1379,7 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
}
- if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes, 0)) < 0)
+ if ((ret = ff_get_encode_buffer(avctx, avpkt, frame_bytes, 0)) < 0)
return ret;
out_bytes = write_frame(s, avpkt);
@@ -1396,10 +1397,11 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
avpkt->pts = frame->pts;
avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
- avpkt->size = out_bytes;
s->next_pts = avpkt->pts + avpkt->duration;
+ av_shrink_packet(avpkt, out_bytes);
+
*got_packet_ptr = 1;
return 0;
}
@@ -1459,11 +1461,12 @@ const AVCodec ff_flac_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_FLAC,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+ AV_CODEC_CAP_SMALL_LAST_FRAME,
.priv_data_size = sizeof(FlacEncodeContext),
.init = flac_encode_init,
.encode2 = flac_encode_frame,
.close = flac_encode_close,
- .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_S32,
AV_SAMPLE_FMT_NONE },