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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4500>
This commit is contained in:
Haihua Hu 2023-04-27 22:12:15 +08:00 committed by GStreamer Marge Bot
parent ceb0aca906
commit 1c488626da

View file

@ -585,6 +585,14 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps,
* enumerate the possibilities */ * enumerate the possibilities */
caps = gst_caps_normalize (caps); 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) { for (i = 0; i < gst_caps_get_size (caps); ++i) {
gst_v4l2_clear_error (&error); gst_v4l2_clear_error (&error);
if (fcaps) if (fcaps)
@ -592,14 +600,6 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps,
fcaps = gst_caps_copy_nth (caps, i); 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 /* Just check if the format is acceptable, once we know
* no buffers should be outstanding we try S_FMT. * no buffers should be outstanding we try S_FMT.
* *
@ -633,6 +633,7 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps,
return NULL; return NULL;
} }
out:
gst_caps_unref (caps); gst_caps_unref (caps);
GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, fcaps); GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, fcaps);