From f8a9890ddf213f6c9f4c2ea15ed84c53f8ff43a4 Mon Sep 17 00:00:00 2001 From: Michael Tretter Date: Tue, 18 Jul 2023 17:34:54 +0200 Subject: [PATCH] uvcsink: set cur_caps to upstream selected caps If the UVC gadget announces multiple formats in the descriptors the uvcsink doesn't select the actual format but let's the UVC hosts select the format. If the GStreamer pipeline is started before a UVC host selected the format, upstream decides on a format until the UVC host has decided. In this case, the current format needs to be set based on the caps from the caps event to be able to detect if the format selection by the UVC host requires a format change on the GStreamer pipeline. Part-of: --- .../gst-plugins-bad/sys/uvcgadget/gstuvcsink.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/subprojects/gst-plugins-bad/sys/uvcgadget/gstuvcsink.c b/subprojects/gst-plugins-bad/sys/uvcgadget/gstuvcsink.c index 2047d4fedc..e5b88fd2ec 100644 --- a/subprojects/gst-plugins-bad/sys/uvcgadget/gstuvcsink.c +++ b/subprojects/gst-plugins-bad/sys/uvcgadget/gstuvcsink.c @@ -248,6 +248,22 @@ gst_uvc_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) case GST_EVENT_CAPS: GST_DEBUG_OBJECT (self, "Handling %" GST_PTR_FORMAT, event); + /* If the UVC host did not yet commit a format, the cur_caps may contain + * all probed caps. In this case, the element is not able to detect, if + * the caps have changed when the stream is enabled. Take the caps from + * upstream to be able to detect a change. + */ + if (!GST_CAPS_IS_SIMPLE (self->cur_caps)) { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + gst_caps_replace (&self->cur_caps, caps); + + GST_DEBUG_OBJECT (self, + "UVC host didn't select a format, yet. Using upstream %" + GST_PTR_FORMAT, self->cur_caps); + } + /* EVENT CAPS signals that the buffers after the event will use new caps. * If the UVC host requested a new format, we now must start the stream. */