From 3de73f1262732a70f10e3d60a4f0951fd322fcfa Mon Sep 17 00:00:00 2001 From: Lynne Date: Fri, 30 Aug 2024 22:02:39 +0000 Subject: [PATCH] hw_base_encode: make recon_frames_ref optional Vulkan supports some stupidly odd hardware, that unfortunately, most modern GPUs happen to be. The DPB images for encoders may be required to be preallocated all at once, and rather than be individual frames, be layers of a single frame. As the hw_base_encode code is written with the thought that either the driver or the device itself supports sane image allocation, Vulkan does not leave us with this option. So, in the case that the hardware does not support individual frames to be used as DPBs, make the DBP frames context optional, and let the subsystem manage this. --- libavcodec/hw_base_encode.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c index 8411cc7582..7b6ec97d3b 100644 --- a/libavcodec/hw_base_encode.c +++ b/libavcodec/hw_base_encode.c @@ -440,16 +440,18 @@ static int hw_base_encode_send_frame(AVCodecContext *avctx, FFHWBaseEncodeContex goto fail; } - pic->recon_image = av_frame_alloc(); - if (!pic->recon_image) { - err = AVERROR(ENOMEM); - goto fail; - } + if (ctx->recon_frames_ref) { + pic->recon_image = av_frame_alloc(); + if (!pic->recon_image) { + err = AVERROR(ENOMEM); + goto fail; + } - err = av_hwframe_get_buffer(ctx->recon_frames_ref, pic->recon_image, 0); - if (err < 0) { - err = AVERROR(ENOMEM); - goto fail; + err = av_hwframe_get_buffer(ctx->recon_frames_ref, pic->recon_image, 0); + if (err < 0) { + err = AVERROR(ENOMEM); + goto fail; + } } pic->priv = av_mallocz(ctx->op->priv_size);