[FFmpeg-devel] [PATCH 25/39] avcodec/libxavs2: Allow user-supplied buffers
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Fri May 21 12:17:28 EEST 2021
Here the packet size is known before allocating the packet,
so that supporting user-supplied buffers is trivial.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
libavcodec/libxavs2.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
index 99fe0e3286..9c5a576e90 100644
--- a/libavcodec/libxavs2.c
+++ b/libavcodec/libxavs2.c
@@ -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 },
--
2.27.0
More information about the ffmpeg-devel
mailing list