From patchwork Sun Jun 30 23:38:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1545 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 77DFC61E16 for ; Mon, 1 Jul 2019 01:38:43 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 25D362F0 for ; Mon, 1 Jul 2019 01:38:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1561937923; bh=vj+T49ysYA1HwEPVQDmwtRPg3ZsFXfXS4CfKcv2ne+4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bkye0E497V3UR2IGCz7PmpTCXvqglzKN071mtNLmuPs2nGHLJME/Po0h747tERsn7 IFD524Jl6xZStLtTWwT7tDYyQXnj4UGO9rEW1Rd0c89y2r3WbQeK51e3ptu0F8nYui obNr9d4mbto3JxiQkedg68ZBJrYqvunczv+Qm38U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Jul 2019 02:38:06 +0300 Message-Id: <20190630233817.10130-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190630233817.10130-1-laurent.pinchart@ideasonboard.com> References: <20190630233817.10130-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 03/14] libcamera: v4l2_device: Add method to retrieve all supported controls 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: Sun, 30 Jun 2019 23:38:43 -0000 Add a new controls() method to the V4L2Device class to retrieve the map of all supported controls. This is needed in order to dynamically query the supported controls, for instance for drivers that support different sets of controls depending on the device model. To make the API easier to use, create a type alias for the control ID to ControlInfo and use it. Remove the getControlInfo() method that is not used externally, as it can now be replaced by accessing the full list of controls. Update the CameraSensor API accordingly. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 10 ++++------ src/libcamera/include/camera_sensor.h | 5 ++--- src/libcamera/include/v4l2_controls.h | 6 ++++-- src/libcamera/include/v4l2_device.h | 9 ++++----- src/libcamera/v4l2_controls.cpp | 5 +++++ src/libcamera/v4l2_device.cpp | 25 +++++++++---------------- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 471c3e2e6e47..14f631e8ecf7 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -248,14 +248,12 @@ int CameraSensor::setFormat(V4L2SubdeviceFormat *format) } /** - * \brief Retrieve information about a control - * \param[in] id The control ID - * \return A pointer to the V4L2ControlInfo for control \a id, or nullptr - * if the sensor doesn't have such a control + * \brief Retrieve the supported V4L2 controls + * \return A map of the V4L2 controls supported by the sensor */ -const V4L2ControlInfo *CameraSensor::getControlInfo(unsigned int id) const +const V4L2ControlInfoMap &CameraSensor::controls() const { - return subdev_->getControlInfo(id); + return subdev_->controls(); } /** diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index b42e7b8e1343..fe033fb374c1 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -13,12 +13,11 @@ #include #include "log.h" +#include "v4l2_controls.h" namespace libcamera { class MediaEntity; -class V4L2ControlInfo; -class V4L2ControlList; class V4L2Subdevice; struct V4L2SubdeviceFormat; @@ -43,7 +42,7 @@ public: const Size &size) const; int setFormat(V4L2SubdeviceFormat *format); - const V4L2ControlInfo *getControlInfo(unsigned int id) const; + const V4L2ControlInfoMap &controls() const; int getControls(V4L2ControlList *ctrls); int setControls(V4L2ControlList *ctrls); diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h index 0047efab11fa..10b726504951 100644 --- a/src/libcamera/include/v4l2_controls.h +++ b/src/libcamera/include/v4l2_controls.h @@ -8,11 +8,11 @@ #ifndef __LIBCAMERA_V4L2_CONTROLS_H__ #define __LIBCAMERA_V4L2_CONTROLS_H__ +#include +#include #include #include -#include - #include #include @@ -41,6 +41,8 @@ private: int64_t max_; }; +using V4L2ControlInfoMap = std::map; + class V4L2Control { public: diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 24a0134a2cba..e7e9829cb05f 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -13,19 +13,18 @@ #include #include "log.h" +#include "v4l2_controls.h" namespace libcamera { -class V4L2ControlInfo; -class V4L2ControlList; - class V4L2Device : protected Loggable { public: void close(); bool isOpen() const { return fd_ != -1; } - const V4L2ControlInfo *getControlInfo(unsigned int id) const; + const V4L2ControlInfoMap &controls() const { return controls_; } + int getControls(V4L2ControlList *ctrls); int setControls(V4L2ControlList *ctrls); @@ -48,7 +47,7 @@ private: const struct v4l2_ext_control *v4l2Ctrls, unsigned int count); - std::map controls_; + V4L2ControlInfoMap controls_; std::string deviceNode_; int fd_; }; diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index af017bce48ba..84258d9954d0 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -114,6 +114,11 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) * \return The V4L2 control maximum value */ +/** + * \typedef V4L2ControlInfoMap + * \brief A map of control ID to V4L2ControlInfo + */ + /** * \class V4L2Control * \brief A V4L2 control value diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 06939dead705..59fc98cefd4e 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -111,19 +111,10 @@ void V4L2Device::close() */ /** - * \brief Retrieve information about a control - * \param[in] id The control ID - * \return A pointer to the V4L2ControlInfo for control \a id, or nullptr - * if the device doesn't have such a control + * \fn V4L2Device::controls() + * \brief Retrieve the supported V4L2 controls + * \return A map of the V4L2 controls supported by the device */ -const V4L2ControlInfo *V4L2Device::getControlInfo(unsigned int id) const -{ - auto it = controls_.find(id); - if (it == controls_.end()) - return nullptr; - - return &it->second; -} /** * \brief Read controls from the device @@ -158,13 +149,14 @@ int V4L2Device::getControls(V4L2ControlList *ctrls) for (unsigned int i = 0; i < count; ++i) { const V4L2Control *ctrl = ctrls->getByIndex(i); - const V4L2ControlInfo *info = getControlInfo(ctrl->id()); - if (!info) { + const auto iter = controls_.find(ctrl->id()); + if (iter == controls_.end()) { LOG(V4L2, Error) << "Control '" << ctrl->id() << "' not found"; return -EINVAL; } + const V4L2ControlInfo *info = &iter->second; controlInfo[i] = info; v4l2Ctrls[i].id = info->id(); } @@ -232,13 +224,14 @@ int V4L2Device::setControls(V4L2ControlList *ctrls) for (unsigned int i = 0; i < count; ++i) { const V4L2Control *ctrl = ctrls->getByIndex(i); - const V4L2ControlInfo *info = getControlInfo(ctrl->id()); - if (!info) { + const auto iter = controls_.find(ctrl->id()); + if (iter == controls_.end()) { LOG(V4L2, Error) << "Control '" << ctrl->id() << "' not found"; return -EINVAL; } + const V4L2ControlInfo *info = &iter->second; controlInfo[i] = info; v4l2Ctrls[i].id = info->id();