avcodec/s302menc: 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.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-04-25 01:43:26 +02:00
parent 7bb7161f86
commit fbfae5eb36
1 changed files with 4 additions and 2 deletions

View File

@ -21,6 +21,7 @@
*/
#include "avcodec.h"
#include "encode.h"
#include "internal.h"
#include "mathops.h"
#include "put_bits.h"
@ -83,7 +84,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt,
return AVERROR(EINVAL);
}
if ((ret = ff_alloc_packet2(avctx, avpkt, buf_size, 0)) < 0)
if ((ret = ff_get_encode_buffer(avctx, avpkt, buf_size, 0)) < 0)
return ret;
o = avpkt->data;
@ -172,13 +173,14 @@ const AVCodec ff_s302m_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("SMPTE 302M"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_S302M,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_EXPERIMENTAL |
AV_CODEC_CAP_VARIABLE_FRAME_SIZE,
.priv_data_size = sizeof(S302MEncContext),
.init = s302m_encode_init,
.encode2 = s302m_encode2_frame,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32,
AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_NONE },
.capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE | AV_CODEC_CAP_EXPERIMENTAL,
.supported_samplerates = (const int[]) { 48000, 0 },
/* .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_STEREO,
AV_CH_LAYOUT_QUAD,