summaryrefslogtreecommitdiff
path: root/libavcodec
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 14:44:13 +0200
commit6564ab0e01609c580c5f9ebd05c0a403b2a956b2 (patch)
tree84f0f1922b11ec9812454e0b391cbd35670ee46f /libavcodec
parent0812a60feeb5e49efa268fb50d5850b1ad84eb70 (diff)
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@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/libshine.c6
1 files 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,