From 3735e57fb2733d7d0937b9142f84e71f61a84fab Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 13 Jul 2018 15:58:36 -0400 Subject: [PATCH] v4l2: Add a macro to check for M2M https://bugzilla.gnome.org/show_bug.cgi?id=794842 --- sys/v4l2/gstv4l2.c | 7 +------ sys/v4l2/v4l2-utils.h | 18 ++++++++++++++++++ sys/v4l2/v4l2_calls.c | 9 +-------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/sys/v4l2/gstv4l2.c b/sys/v4l2/gstv4l2.c index 07a2873b58..2674d9cd34 100644 --- a/sys/v4l2/gstv4l2.c +++ b/sys/v4l2/gstv4l2.c @@ -153,12 +153,7 @@ gst_v4l2_probe_and_register (GstPlugin * plugin) 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 1bc0062f15..fbf1d45366 100644 --- a/sys/v4l2/v4l2-utils.h +++ b/sys/v4l2/v4l2-utils.h @@ -41,6 +41,24 @@ G_BEGIN_DECLS } \ } +/** + * 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 6303b17476..d3dbd422a5 100644 --- a/sys/v4l2/v4l2_calls.c +++ b/sys/v4l2/v4l2_calls.c @@ -575,14 +575,7 @@ gst_v4l2_open (GstV4l2Object * v4l2object) 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);