@@ -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,
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. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/libshine.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)