You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/libcodec2: Avoid copying packet data, allow user-supplied buffers
When the packet size is known in advance like here, one can avoid an intermediate buffer for the packet data by using ff_get_encode_buffer() and also set AV_CODEC_CAP_DR1 at the same time. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include <codec2/codec2.h>
|
#include <codec2/codec2.h>
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/opt.h"
|
||||||
|
#include "encode.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "codec2utils.h"
|
#include "codec2utils.h"
|
||||||
|
|
||||||
@@ -169,7 +170,7 @@ static int libcodec2_encode(AVCodecContext *avctx, AVPacket *avpkt,
|
|||||||
LibCodec2Context *c2 = avctx->priv_data;
|
LibCodec2Context *c2 = avctx->priv_data;
|
||||||
int16_t *samples = (int16_t *)frame->data[0];
|
int16_t *samples = (int16_t *)frame->data[0];
|
||||||
|
|
||||||
int ret = ff_alloc_packet2(avctx, avpkt, avctx->block_align, 0);
|
int ret = ff_get_encode_buffer(avctx, avpkt, avctx->block_align, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -201,11 +202,11 @@ const AVCodec ff_libcodec2_encoder = {
|
|||||||
.long_name = NULL_IF_CONFIG_SMALL("codec2 encoder using libcodec2"),
|
.long_name = NULL_IF_CONFIG_SMALL("codec2 encoder using libcodec2"),
|
||||||
.type = AVMEDIA_TYPE_AUDIO,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
.id = AV_CODEC_ID_CODEC2,
|
.id = AV_CODEC_ID_CODEC2,
|
||||||
|
.capabilities = AV_CODEC_CAP_DR1,
|
||||||
.priv_data_size = sizeof(LibCodec2Context),
|
.priv_data_size = sizeof(LibCodec2Context),
|
||||||
.init = libcodec2_init_encoder,
|
.init = libcodec2_init_encoder,
|
||||||
.close = libcodec2_close,
|
.close = libcodec2_close,
|
||||||
.encode2 = libcodec2_encode,
|
.encode2 = libcodec2_encode,
|
||||||
.capabilities = 0,
|
|
||||||
.supported_samplerates = (const int[]){ 8000, 0 },
|
.supported_samplerates = (const int[]){ 8000, 0 },
|
||||||
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
|
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
|
||||||
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO, 0 },
|
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO, 0 },
|
||||||
|
Reference in New Issue
Block a user