Skip to content

Commit

Permalink
avcodec/libvorbisenc: Avoid copying data, allow user-supplied buffers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andreas Rheinhardt <[email protected]>
  • Loading branch information
mkver committed May 23, 2021
1 parent 6ba55e9 commit d8e66ec
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libavcodec/libvorbisenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d8e66ec

Please sign in to comment.