v4l2src: Simplify format handling
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 9 Jul 2018 19:33:02 +0000 (15:33 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 27 Aug 2018 17:41:30 +0000 (13:41 -0400)
Always initially use try_format(), delaying set_format() to when the
allocation is being negotiated. This avoid having two code paths, and
will be help adding support for properly importing buffers of specific
strides and offsets.

https://bugzilla.gnome.org/show_bug.cgi?id=583890

sys/v4l2/gstv4l2src.c

index 88c813f..a87bcdc 100644 (file)
@@ -446,33 +446,28 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps, GstStructure * pref_s)
 
     fcaps = gst_caps_copy_nth (caps, i);
 
-    if (GST_V4L2_IS_ACTIVE (obj)) {
-      /* 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;
-      }
+    /* 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.
-       *
-       * Basesrc will do an allocation query that
-       * should indirectly reclaim buffers, after that we can
-       * set the format and then configure our pool */
-      if (gst_v4l2_object_try_format (obj, fcaps, &error)) {
-        /* make sure the caps changed before doing anything */
-        if (gst_v4l2_object_caps_equal (obj, fcaps))
-          break;
-
-        v4l2src->renegotiation_adjust = v4l2src->offset + 1;
-        v4l2src->pending_set_fmt = TRUE;
-        break;
-      }
-    } else {
-      if (gst_v4l2src_set_format (v4l2src, fcaps, &error))
+    /* Just check if the format is acceptable, once we know
+     * no buffers should be outstanding we try S_FMT.
+     *
+     * Basesrc will do an allocation query that
+     * should indirectly reclaim buffers, after that we can
+     * set the format and then configure our pool */
+    if (gst_v4l2_object_try_format (obj, fcaps, &error)) {
+      /* make sure the caps changed before doing anything */
+      if (gst_v4l2_object_caps_equal (obj, fcaps))
         break;
+
+      v4l2src->renegotiation_adjust = v4l2src->offset + 1;
+      v4l2src->pending_set_fmt = TRUE;
+      break;
     }
 
     /* Only EIVAL make sense, report any other errors, this way we don't keep