From e2e8cf7944493f3d2de6627c0991e348bb23d113 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Sat, 30 Mar 2024 20:44:07 +0100 Subject: [PATCH] gst/src: Avoid unnecessary renegotiations during streaming Some clients like many camera apps, including Cheese or Snapshot, trigger a lot of unnessecary renegotiations. While arguably that should be solved on a Gstreamer level, we can help out by checking if the preferred new caps are the same that are already in use and skip the renegotiation in this case. This allows several apps to e.g. take pictures without a slow and heavy stream restart. --- src/gst/gstpipewiresrc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index 1357aae6a..4ae881106 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -864,6 +864,21 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc) GST_DEBUG_OBJECT (basesrc, "have common caps (sanitized): %" GST_PTR_FORMAT, possible_caps); + if (pw_stream_get_state(pwsrc->stream, NULL) == PW_STREAM_STATE_STREAMING) { + g_autoptr (GstCaps) current_caps = NULL; + g_autoptr (GstCaps) preferred_new_caps = NULL; + + current_caps = gst_pad_get_current_caps (GST_BASE_SRC_PAD (pwsrc)); + preferred_new_caps = gst_caps_copy_nth (possible_caps, 0); + + if (gst_caps_is_equal (current_caps, preferred_new_caps)) { + GST_DEBUG_OBJECT (pwsrc, + "Stream running and new caps equal current ones. " + "Skipping renegotiation."); + goto no_nego_needed; + } + } + /* open a connection with these caps */ possible = gst_caps_to_format_all (possible_caps);