v4l2provider: Fix device type detection
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 11 Jul 2016 22:30:18 +0000 (18:30 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 11 Jul 2016 23:17:49 +0000 (19:17 -0400)
The type detection would lead to assertion as it would try
to create a device without having found any type for it. It
also didn't detect MPLANE devices properly.

sys/v4l2/gstv4l2deviceprovider.c

index 68e0657..4142f1a 100644 (file)
@@ -136,22 +136,30 @@ gst_v4l2_device_provider_probe_device (GstV4l2DeviceProvider * provider,
   gst_structure_set (props, "v4l2.device.device_caps", G_TYPE_UINT,
       v4l2obj->vcap.device_caps, NULL);
 
-  if (v4l2obj->device_caps & V4L2_CAP_VIDEO_CAPTURE)
+  if (v4l2obj->device_caps &
+      (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE))
     type = GST_V4L2_DEVICE_TYPE_SOURCE;
 
-  if (v4l2obj->device_caps & V4L2_CAP_VIDEO_OUTPUT) {
-    /* Morph it in case our initial guess was wrong */
-    v4l2obj->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+  if (v4l2obj->device_caps &
+      (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE)) {
+    /* We ignore M2M devices that are both capture and output for now
+     * The provider is not for them */
+    if (type != GST_V4L2_DEVICE_TYPE_INVALID)
+      goto close;
+
+    type = GST_V4L2_DEVICE_TYPE_SINK;
 
-    if (type == GST_V4L2_DEVICE_TYPE_INVALID)
-      type = GST_V4L2_DEVICE_TYPE_SINK;
+    /* We have opened as a capture as we didn't know, now that know,
+     * let's fixed it */
+    if (v4l2obj->device_caps & V4L2_CAP_VIDEO_OUTPUT_MPLANE)
+      v4l2obj->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
     else
-      /* We ignore M2M devices that are both capture and output for now
-       * The provider is not for them
-       */
-      goto close;
+      v4l2obj->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
   }
 
+  if (type == GST_V4L2_DEVICE_TYPE_INVALID)
+    goto close;
+
   caps = gst_v4l2_object_get_caps (v4l2obj, NULL);
 
   if (caps == NULL)