1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avcodec/libxavs2: Allow user-supplied buffers

Here the packet size is known before allocating the packet,
so that supporting user-supplied buffers is trivial.

Reviewed-by: James Almer <jamrial@gmail.com>
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 7a3613696d
commit 3abdf0efac

View File

@ -23,6 +23,7 @@
*/
#include "xavs2.h"
#include "encode.h"
#include "mpeg12.h"
#include "libavutil/avstring.h"
@ -214,10 +215,9 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
if ((cae->packet.len) && (cae->packet.state != XAVS2_STATE_FLUSH_END)) {
if (av_new_packet(pkt, cae->packet.len) < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to alloc xavs2 packet.\n");
if ((ret = ff_get_encode_buffer(avctx, pkt, cae->packet.len, 0)) < 0) {
cae->api->encoder_packet_unref(cae->encoder, &cae->packet);
return AVERROR(ENOMEM);
return ret;
}
pkt->pts = cae->packet.pts;
@ -230,7 +230,6 @@ static int xavs2_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
memcpy(pkt->data, cae->packet.stream, cae->packet.len);
pkt->size = cae->packet.len;
cae->api->encoder_packet_unref(cae->encoder, &cae->packet);
@ -290,11 +289,12 @@ const AVCodec ff_libxavs2_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("libxavs2 AVS2-P2/IEEE1857.4"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_AVS2,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
AV_CODEC_CAP_OTHER_THREADS,
.priv_data_size = sizeof(XAVS2EContext),
.init = xavs2_init,
.encode2 = xavs2_encode_frame,
.close = xavs2_close,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS,
.caps_internal = FF_CODEC_CAP_AUTO_THREADS,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE },