[FFmpeg-devel] [PATCH 4/5] avfilter/libplacebo: move hwctx init to init()

Niklas Haas ffmpeg at haasn.xyz
Fri Feb 9 16:53:48 EET 2024


From: Niklas Haas <git at haasn.dev>

---
 libavfilter/vf_libplacebo.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index a9a3d884ce..f41d8be0c0 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -544,6 +544,7 @@ static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len)
 
 static void libplacebo_uninit(AVFilterContext *avctx);
 static int libplacebo_config_input(AVFilterLink *inlink);
+static int init_vulkan(AVFilterContext *avctx);
 
 static int libplacebo_init(AVFilterContext *avctx)
 {
@@ -610,8 +611,7 @@ static int libplacebo_init(AVFilterContext *avctx)
     if (strcmp(s->fps_string, "none") != 0)
         RET(av_parse_video_rate(&s->fps, s->fps_string));
 
-    /* Note: s->vulkan etc. are initialized later, when hwctx is available */
-    return 0;
+    return init_vulkan(avctx);
 
 fail:
     return err;
@@ -656,13 +656,20 @@ static void input_uninit(LibplaceboInput *input)
     av_fifo_freep2(&input->out_pts);
 }
 
-static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwctx)
+static int init_vulkan(AVFilterContext *avctx)
 {
     int err = 0;
     LibplaceboContext *s = avctx->priv;
+    const AVVulkanDeviceContext *hwctx = NULL;
     uint8_t *buf = NULL;
     size_t buf_len;
 
+    if (avctx->hw_device_ctx) {
+        const AVHWDeviceContext *avhwctx = (void *) avctx->hw_device_ctx->data;
+        if (avhwctx->type == AV_HWDEVICE_TYPE_VULKAN)
+            hwctx = s->vkctx.hwctx = avhwctx->hwctx;
+    }
+
     if (hwctx) {
 #if PL_API_VER >= 278
         /* Import libavfilter vulkan context into libplacebo */
@@ -1127,18 +1134,9 @@ static int libplacebo_query_format(AVFilterContext *ctx)
 {
     int err;
     LibplaceboContext *s = ctx->priv;
-    const AVVulkanDeviceContext *vkhwctx = NULL;
     const AVPixFmtDescriptor *desc = NULL;
     AVFilterFormats *infmts = NULL, *outfmts = NULL;
 
-    if (ctx->hw_device_ctx) {
-        const AVHWDeviceContext *avhwctx = (void *) ctx->hw_device_ctx->data;
-        if (avhwctx->type == AV_HWDEVICE_TYPE_VULKAN)
-            vkhwctx = avhwctx->hwctx;
-    }
-
-    RET(init_vulkan(ctx, vkhwctx));
-
     while ((desc = av_pix_fmt_desc_next(desc))) {
         enum AVPixelFormat pixfmt = av_pix_fmt_desc_get_id(desc);
 
@@ -1150,7 +1148,7 @@ static int libplacebo_query_format(AVFilterContext *ctx)
 #endif
 
         if (pixfmt == AV_PIX_FMT_VULKAN) {
-            if (!vkhwctx || vkhwctx->act_dev != s->vulkan->device)
+            if (!s->vkctx.hwctx || s->vkctx.hwctx->act_dev != s->vulkan->device)
                 continue;
         }
 
-- 
2.43.0



More information about the ffmpeg-devel mailing list