From 1c488626da9586efabb583145338084abfac72a3 Mon Sep 17 00:00:00 2001 From: Haihua Hu Date: Thu, 27 Apr 2023 22:12:15 +0800 Subject: [PATCH] v4l2src: fix cannot reuse current caps when fixate caps in negotiation when regotiation happens, v4l2src will check if it can reuse current caps, but we need check if current caps is subset of all query caps from downstream instead of check it with query caps one by one. Assuming that the current caps is not the subset of first caps from query caps, it will go to try fmt. when try fmt success, v4l2src will make pending_set_fmt to TRUE and going to reset. Part-of: --- .../gst-plugins-good/sys/v4l2/gstv4l2src.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2src.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2src.c index e33b71ec3c..cfea812e99 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2src.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2src.c @@ -585,6 +585,14 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps, * enumerate the possibilities */ caps = gst_caps_normalize (caps); + /* try hard to avoid TRY_FMT since some UVC camera just crash when this + * is called at run-time. */ + if (gst_v4l2_object_caps_is_subset (obj, caps)) { + fcaps = gst_v4l2_object_get_current_caps (obj); + GST_DEBUG_OBJECT (basesrc, "reuse current caps %" GST_PTR_FORMAT, fcaps); + goto out; + } + for (i = 0; i < gst_caps_get_size (caps); ++i) { gst_v4l2_clear_error (&error); if (fcaps) @@ -592,14 +600,6 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps, fcaps = gst_caps_copy_nth (caps, i); - /* try hard to avoid TRY_FMT since some UVC camera just crash when this - * is called at run-time. */ - if (gst_v4l2_object_caps_is_subset (obj, fcaps)) { - gst_caps_unref (fcaps); - fcaps = gst_v4l2_object_get_current_caps (obj); - break; - } - /* Just check if the format is acceptable, once we know * no buffers should be outstanding we try S_FMT. * @@ -633,6 +633,7 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps, return NULL; } +out: gst_caps_unref (caps); GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, fcaps);