[FFmpeg-devel] [PATCH] avfilter/vf_libplacebo: whitelist properties on linear blend tex (PR #20164)

Niklas Haas code at ffmpeg.org
Thu Aug 7 22:22:28 EEST 2025


PR #20164 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20164
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20164.patch

Instead of copying over the entire target and changing a few fields,
set the entire struct to a whitelist of safe properties that we want to
persist on the intermediate texture.

In particular, this avoids leaking irrelevant state related to the
acquire/release callbacks, e.g., which can otherwise cause deadlocks
when the same vulkan frame is attempted to be acquired twice.


From 16ec009d13e8dc53343c833cf1677d1e710b900c Mon Sep 17 00:00:00 2001
From: Niklas Haas <git at haasn.dev>
Date: Thu, 7 Aug 2025 21:18:45 +0200
Subject: [PATCH 1/2] avfilter/vf_libplacebo: whitelist properties on linear
 blend tex

Instead of copying over the entire target and changing a few fields,
set the entire struct to a whitelist of safe properties that we want to
persist on the intermediate texture.

In particular, this avoids leaking irrelevant state related to the
acquire/release callbacks, e.g., which can otherwise cause deadlocks
when the same vulkan frame is attempted to be acquired twice.
---
 libavfilter/vf_libplacebo.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index aecf28c40c..40f9ec2bba 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -990,15 +990,19 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
     struct pl_frame orig_target = target;
     bool use_linear_compositor = false;
     if (s->linear_tex && target.color.transfer != PL_COLOR_TRC_LINEAR && !s->disable_linear) {
-        use_linear_compositor = true;
-        target.color.transfer = PL_COLOR_TRC_LINEAR;
-        target.repr = pl_color_repr_rgb;
-        target.num_planes = 1;
-        target.planes[0] = (struct pl_plane) {
-            .components = 4,
-            .component_mapping = {0, 1, 2, 3},
-            .texture = s->linear_tex,
+        target = (struct pl_frame) {
+            .num_planes = 1,
+            .planes[0] = {
+                .components = 4,
+                .component_mapping = {0, 1, 2, 3},
+                .texture = s->linear_tex,
+            },
+            .repr = pl_color_repr_rgb,
+            .color = orig_target.color,
+            .rotation = orig_target.rotation,
         };
+        target.color.transfer = PL_COLOR_TRC_LINEAR;
+        use_linear_compositor = true;
     }
 
     /* Draw first frame opaque, others with blending */
-- 
2.49.1


From 2e64f0fc258eed90f4cc5da4e9b11549d9a59fe7 Mon Sep 17 00:00:00 2001
From: Niklas Haas <git at haasn.dev>
Date: Thu, 7 Aug 2025 21:21:28 +0200
Subject: [PATCH 2/2] avfilter/vf_libplacebo: simplify unnecessary indirection

in->idx is equal to the array index by definition, so just use the loop
index directly.
---
 libavfilter/vf_libplacebo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 40f9ec2bba..7e30524455 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1014,7 +1014,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
 #endif
     for (int i = 0; i < s->nb_inputs; i++) {
         LibplaceboInput *in = &s->inputs[i];
-        FilterLink *il = ff_filter_link(ctx->inputs[in->idx]);
+        FilterLink *il = ff_filter_link(ctx->inputs[i]);
         FilterLink *ol = ff_filter_link(outlink);
         int high_fps = av_cmp_q(il->frame_rate, ol->frame_rate) >= 0;
         if (in->qstatus != PL_QUEUE_OK)
@@ -1175,7 +1175,7 @@ static int libplacebo_activate(AVFilterContext *ctx)
                 if (av_fifo_peek(in->out_pts, &pts, 1, 0) >= 0) {
                     out_pts = FFMIN(out_pts, pts);
                 } else if (!in->status) {
-                    ff_inlink_request_frame(ctx->inputs[in->idx]);
+                    ff_inlink_request_frame(ctx->inputs[i]);
                     retry = true;
                 }
             }
@@ -1201,7 +1201,7 @@ static int libplacebo_activate(AVFilterContext *ctx)
 
             switch (in->qstatus) {
             case PL_QUEUE_MORE:
-                ff_inlink_request_frame(ctx->inputs[in->idx]);
+                ff_inlink_request_frame(ctx->inputs[i]);
                 retry = true;
                 break;
             case PL_QUEUE_OK:
-- 
2.49.1



More information about the ffmpeg-devel mailing list