[FFmpeg-cvslog] avcodec/libshine: Avoid copying data, allow user-supplied buffer
Andreas Rheinhardt
git at videolan.org
Sun May 23 16:42:08 EEST 2021
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 25 01:43:26 2021 +0200| [6564ab0e01609c580c5f9ebd05c0a403b2a956b2] | committer: Andreas Rheinhardt
avcodec/libshine: Avoid copying data, allow user-supplied buffer
The libshine encoder already uses an internal buffer, so that the
packet size is already known before allocating the packet; therefore
one can avoid another (implicit) intermediate buffer by switching
to ff_get_encode_buffer(), thereby also supporting user-supplied
buffers.
Reviewed-by: James Almer <jamrial at gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6564ab0e01609c580c5f9ebd05c0a403b2a956b2
---
libavcodec/libshine.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/libshine.c b/libavcodec/libshine.c
index 4a9fc617f0..04d5914701 100644
--- a/libavcodec/libshine.c
+++ b/libavcodec/libshine.c
@@ -24,6 +24,7 @@
#include "libavutil/intreadwrite.h"
#include "audio_frame_queue.h"
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
#include "mpegaudio.h"
#include "mpegaudiodecheader.h"
@@ -102,7 +103,7 @@ static int libshine_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
len = hdr.frame_size;
if (len <= s->buffer_index) {
- if ((ret = ff_alloc_packet2(avctx, avpkt, len, 0)))
+ if ((ret = ff_get_encode_buffer(avctx, avpkt, len, 0)))
return ret;
memcpy(avpkt->data, s->buffer, len);
s->buffer_index -= len;
@@ -111,7 +112,6 @@ static int libshine_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,
&avpkt->duration);
- avpkt->size = len;
*got_packet_ptr = 1;
}
return 0;
@@ -135,11 +135,11 @@ const AVCodec ff_libshine_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("libshine MP3 (MPEG audio layer 3)"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_MP3,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
.priv_data_size = sizeof(SHINEContext),
.init = libshine_encode_init,
.encode2 = libshine_encode_frame,
.close = libshine_encode_close,
- .capabilities = AV_CODEC_CAP_DELAY,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16P,
AV_SAMPLE_FMT_NONE },
.supported_samplerates = libshine_sample_rates,
More information about the ffmpeg-cvslog
mailing list