From patchwork Wed Jun 19 11:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1475 Return-Path: Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5824E6194F for ; Wed, 19 Jun 2019 13:07:50 +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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id EC0C9FF806; Wed, 19 Jun 2019 11:07:49 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Jun 2019 13:08:54 +0200 Message-Id: <20190619110858.20980-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190619110858.20980-1-jacopo@jmondi.org> References: <20190619110858.20980-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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: Wed, 19 Jun 2019 11:07:50 -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 | 30 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 2c26f3eae2b4..563be151c257 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -7,12 +7,15 @@ #ifndef __LIBCAMERA_V4L2_DEVICE_H__ #define __LIBCAMERA_V4L2_DEVICE_H__ +#include #include #include "log.h" namespace libcamera { +class V4L2ControlInfo; + class V4L2Device : protected Loggable { public: @@ -22,7 +25,7 @@ public: protected: V4L2Device(const std::string &deviceNode, const std::string &logTag); - ~V4L2Device() {} + ~V4L2Device(); int fd() { return fd_; } @@ -33,6 +36,9 @@ protected: std::string logPrefix() const { return "'" + logTag_ + "'"; } private: + void listControls(); + + std::map controls_; std::string deviceNode_; std::string logTag_; int fd_; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index eeed0a70fb0e..58dd94836686 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 @@ -82,6 +83,12 @@ V4L2Device::V4L2Device(const std::string &deviceNode, const std::string &logTag) { } +V4L2Device::~V4L2Device() +{ + for (auto &pair : controls_) + delete pair.second; +} + /** * \fn V4L2Device::fd() * \brief Retrieve the V4L2 device file descriptor @@ -114,6 +121,8 @@ int V4L2Device::open(unsigned int flags) fd_ = ret; + listControls(); + return 0; } @@ -141,4 +150,25 @@ int V4L2Device::ioctl(unsigned long request, void *argp) * \return The tag to prefix log messages with */ +/* + * \brief List and store all controls supported by the V4L2 device + */ +void 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; + } +} + } /* namespace libcamera */