From 3c62d29a55740ab9152b67323a5091876cb63f9b Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Tue, 25 Mar 2025 16:24:48 +0530 Subject: [PATCH] gstpipewiresrc: Fix re-linking When using PW source, one might want to dynamically link PW source to a different source. Setting possible_caps to NULL prevents the caps intersect from returning a successful result on format change. Do not set possible_caps to NULL as we get that from peer caps which should stay the same ideally for the duration of pipeline run. That allows re-linking PW source any number of times with a pipeline like below. gst-launch-1.0 pipewiresrc autoconnect=false ! queue ! video/x-raw,format=YUY2 ! videoconvert ! xvimagesink The above pipeline can be made to switch between a camera source and a screen capture source like wf-recorder. Note that this fix only improves the status quo and won't work if the peer caps change due to a re-negotiation. --- src/gst/gstpipewiresrc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index 1570c83e9..f8e8669d6 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -990,7 +990,7 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc) GST_DEBUG_OBJECT (basesrc, "connect capture with path %s, target-object %s", pwsrc->stream->path, pwsrc->stream->target_object); - pwsrc->possible_caps = possible_caps; + pwsrc->possible_caps = gst_caps_ref (possible_caps); pwsrc->negotiated = FALSE; enum pw_stream_flags flags; @@ -1027,7 +1027,6 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc) } negotiated_caps = g_steal_pointer (&pwsrc->caps); - pwsrc->possible_caps = NULL; pw_thread_loop_unlock (pwsrc->stream->core->loop); if (negotiated_caps == NULL) @@ -1472,6 +1471,7 @@ gst_pipewire_src_stop (GstBaseSrc * basesrc) pwsrc->eos = false; gst_buffer_replace (&pwsrc->last_buffer, NULL); gst_caps_replace(&pwsrc->caps, NULL); + gst_caps_replace(&pwsrc->possible_caps, NULL); pwsrc->transform_value = UINT32_MAX; pw_thread_loop_unlock (pwsrc->stream->core->loop);