summaryrefslogtreecommitdiff
path: root/libavcodec/libvorbisenc.c
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:49:45 +0200
commitd8e66ec1d7233541fd84205cb10e8e6ff87167de (patch)
tree7c7a16632674aa69a3a637315178e2194e0da44e /libavcodec/libvorbisenc.c
parent6ba55e9652746382dddddadb9d91206e22e15939 (diff)
avcodec/libvorbisenc: Avoid copying data, allow user-supplied buffers
Here the packet size is known before allocating the packet because the encoder provides said information (and works with internal buffers itself), so one can use this information to avoid the implicit use of another intermediate buffer for the packet data; and by switching to ff_get_encode_buffer() one can also allow user-supplied buffers. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/libvorbisenc.c')
-rw-r--r--libavcodec/libvorbisenc.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index d0f4c65aac..ec674695d4 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -25,6 +25,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
#include "audio_frame_queue.h"
+#include "encode.h"
#include "internal.h"
#include "vorbis.h"
#include "vorbis_parser.h"
@@ -348,7 +349,7 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
- if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes, 0)) < 0)
+ if ((ret = ff_get_encode_buffer(avctx, avpkt, op.bytes, 0)) < 0)
return ret;
av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL);
@@ -378,11 +379,12 @@ const AVCodec ff_libvorbis_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("libvorbis"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_VORBIS,
+ .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+ AV_CODEC_CAP_SMALL_LAST_FRAME,
.priv_data_size = sizeof(LibvorbisEncContext),
.init = libvorbis_encode_init,
.encode2 = libvorbis_encode_frame,
.close = libvorbis_encode_close,
- .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SMALL_LAST_FRAME,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
.priv_class = &vorbis_class,