From e5163f54d47c4f2c167eba5e40f8df62229e8ad5 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Tue, 22 Jan 2019 18:51:15 +0000 Subject: libcamera: v4l2device: Obtain device capabilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The capabilities structure from the kernel can return capabilities of the driver, or potentially more specific device capabilities. Handle this with an inline function 'device_caps()' to return the device specific capabilities when available, or fall back to the driver capabilities otherwise. Reviewed-by: Niklas Söderlund Signed-off-by: Kieran Bingham --- src/libcamera/include/v4l2_device.h | 12 +++++++++--- src/libcamera/v4l2_device.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index b92e1f1c..cb3601ca 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -26,10 +26,16 @@ struct V4L2Capability final : v4l2_capability { { return reinterpret_cast(v4l2_capability::bus_info); } + unsigned int device_caps() const + { + return capabilities & V4L2_CAP_DEVICE_CAPS + ? v4l2_capability::device_caps + : v4l2_capability::capabilities; + } - bool isCapture() const { return capabilities & V4L2_CAP_VIDEO_CAPTURE; } - bool isOutput() const { return capabilities & V4L2_CAP_VIDEO_OUTPUT; } - bool hasStreaming() const { return capabilities & V4L2_CAP_STREAMING; } + bool isCapture() const { return device_caps() & V4L2_CAP_VIDEO_CAPTURE; } + bool isOutput() const { return device_caps() & V4L2_CAP_VIDEO_OUTPUT; } + bool hasStreaming() const { return device_caps() & V4L2_CAP_STREAMING; } }; class MediaEntity; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 2b17fa1e..0ce2b187 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -49,6 +49,13 @@ LOG_DEFINE_CATEGORY(V4L2) * \return The string containing the device location */ +/** + * \fn unsigned int V4L2Capability::device_caps() + * \brief Retrieve the capabilities of the device + * \return The device specific capabilities if V4L2_CAP_DEVICE_CAPS is set or + * driver capabilities otherwise + */ + /** * \fn bool V4L2Capability::isCapture() * \brief Identify if the device is capable of capturing video -- cgit v1.2.1