From patchwork Thu Jun 13 11:20:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1426 Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E5D4561BD1 for ; Thu, 13 Jun 2019 13:19:42 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 7866FC0014; Thu, 13 Jun 2019 11:19:42 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 13 Jun 2019 13:20:42 +0200 Message-Id: <20190613112046.25260-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190613112046.25260-1-jacopo@jmondi.org> References: <20190613112046.25260-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/6] libcamera: v4l2_device: List controls at device open X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jun 2019 11:19:43 -0000 Enumerate all the controls a device supports at open() time. Store the control informations in a map inside the device to save querying the control when setting or getting its value from the device. Signed-off-by: Jacopo Mondi --- src/libcamera/include/v4l2_device.h | 8 +++++++- src/libcamera/v4l2_device.cpp | 31 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index a73e1b600500..727b9d2e210a 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -7,14 +7,17 @@ #ifndef __LIBCAMERA_V4L2_DEVICE_H__ #define __LIBCAMERA_V4L2_DEVICE_H__ +#include #include namespace libcamera { +class V4L2ControlInfo; + class V4L2Device { public: - virtual ~V4L2Device() { close(); } + virtual ~V4L2Device(); protected: V4L2Device(); @@ -28,7 +31,10 @@ protected: int ioctl(unsigned long request, void *argp); private: + int listControls(); + int fd_; + std::map controls_; }; } /* namespace libcamera */ diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 6cbfc212a725..b60b446050e9 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -13,6 +13,7 @@ #include #include "log.h" +#include "v4l2_controls.h" /** * \file v4l2_device.h @@ -50,6 +51,14 @@ V4L2Device::V4L2Device() { } +V4L2Device::~V4L2Device() +{ + for (auto &pair : controls_) + delete pair.second; + + close(); +} + /** * \fn V4L2Device::fd() * \brief Retrieve the V4L2 device file descriptor @@ -82,6 +91,28 @@ int V4L2Device::open(const std::string &pathname, unsigned int flags) fd_ = ret; + listControls(); + + return 0; +} + +int V4L2Device::listControls() +{ + struct v4l2_query_ext_ctrl ctrl = {}; + + /* \todo: add support for menu and compound controls. */ + ctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL; + while (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl) == 0) { + if (ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS || + ctrl.flags & V4L2_CTRL_FLAG_DISABLED) { + ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; + continue; + } + + controls_[ctrl.id] = new V4L2ControlInfo(ctrl); + ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; + } + return 0; }