diff mbox series

[FFmpeg-devel,04/10] hw_base_encode: make recon_frames_ref optional

Message ID 20240901000314.379276-3-dev@lynne.ee
State New
Headers show
Series None | expand

Commit Message

Lynne Sept. 1, 2024, 12:03 a.m. UTC
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 mbox series

Patch

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);