v4l2: Add a macro to check for M2M

https://bugzilla.gnome.org/show_bug.cgi?id=794842
diff --git a/sys/v4l2/gstv4l2.c b/sys/v4l2/gstv4l2.c
index 07a2873..2674d9c 100644
--- a/sys/v4l2/gstv4l2.c
+++ b/sys/v4l2/gstv4l2.c
@@ -153,12 +153,7 @@
     else
       device_caps = vcap.capabilities;
 
-    if (!((device_caps & (V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE)) ||
-            /* But legacy driver may expose both CAPTURE and OUTPUT */
-            ((device_caps &
-                    (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE)) &&
-                (device_caps &
-                    (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE)))))
+    if (!GST_V4L2_IS_M2M (device_caps))
       continue;
 
     GST_DEBUG ("Probing '%s' located at '%s'",
diff --git a/sys/v4l2/v4l2-utils.h b/sys/v4l2/v4l2-utils.h
index 1bc0062..fbf1d45 100644
--- a/sys/v4l2/v4l2-utils.h
+++ b/sys/v4l2/v4l2-utils.h
@@ -41,6 +41,24 @@
   } \
 }
 
+/**
+ * GST_V4L2_IS_M2M:
+ * @_dcaps: The device capabilities
+ *
+ * Checks if the device caps represent an M2M device. Note that modern M2M
+ * devices uses V4L2_CAP_VIDEO_M2M* flag, but legacy uses to set both CAPTURE
+ * and OUTPUT flags instead.
+ *
+ * Returns: %TRUE if this is a M2M device.
+ */
+#define GST_V4L2_IS_M2M(_dcaps) \
+  (((_dcaps) & (V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE)) ||\
+            (((_dcaps) & \
+                    (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE)) && \
+                ((_dcaps) & \
+                    (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE))))
+
+
 typedef struct _GstV4l2Iterator GstV4l2Iterator;
 typedef struct _GstV4l2Error GstV4l2Error;
 
diff --git a/sys/v4l2/v4l2_calls.c b/sys/v4l2/v4l2_calls.c
index 6303b17..d3dbd42 100644
--- a/sys/v4l2/v4l2_calls.c
+++ b/sys/v4l2/v4l2_calls.c
@@ -575,14 +575,7 @@
     goto not_output;
 
   if (GST_IS_V4L2_VIDEO_DEC (v4l2object->element) &&
-      /* Today's M2M device only expose M2M */
-      !((v4l2object->device_caps & (V4L2_CAP_VIDEO_M2M |
-                  V4L2_CAP_VIDEO_M2M_MPLANE)) ||
-          /* But legacy driver may expose both CAPTURE and OUTPUT */
-          ((v4l2object->device_caps &
-                  (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE)) &&
-              (v4l2object->device_caps &
-                  (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE)))))
+      !GST_V4L2_IS_M2M (v4l2object->device_caps))
     goto not_m2m;
 
   gst_v4l2_adjust_buf_type (v4l2object);