From patchwork Tue Sep 24 17:14:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1996 Return-Path: Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EAD860BCF for ; Tue, 24 Sep 2019 19:13:08 +0200 (CEST) X-Originating-IP: 213.45.248.89 Received: from uno.homenet.telecomitalia.it (host89-248-dynamic.45-213-r.retail.telecomitalia.it [213.45.248.89]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 890E120004 for ; Tue, 24 Sep 2019 17:13:07 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 24 Sep 2019 19:14:38 +0200 Message-Id: <20190924171440.29758-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190924171440.29758-1-jacopo@jmondi.org> References: <20190924171440.29758-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/5] libcamera: v4l2_controls: Use DataValue and DataInfo X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Sep 2019 17:13:08 -0000 Use DataValue and DataInfo in the V4L2 control handling classes to maximize code reuse with the libcamera controls classes. The control type is now represented by the DataType from the DataValue rather than the V4L2_CTRL_TYPE_* previously stored in the V4L2ControlInfo. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/libcamera/include/v4l2_controls.h | 22 ++++-------- src/libcamera/include/v4l2_device.h | 1 - src/libcamera/v4l2_controls.cpp | 49 +++++++-------------------- src/libcamera/v4l2_device.cpp | 29 ++++++---------- 4 files changed, 30 insertions(+), 71 deletions(-) diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h index 10b726504951..27b855f3407f 100644 --- a/src/libcamera/include/v4l2_controls.h +++ b/src/libcamera/include/v4l2_controls.h @@ -16,29 +16,18 @@ #include #include +#include + namespace libcamera { -class V4L2ControlInfo +class V4L2ControlInfo : public DataInfo { public: V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl); - unsigned int id() const { return id_; } - unsigned int type() const { return type_; } - size_t size() const { return size_; } - const std::string &name() const { return name_; } - - int64_t min() const { return min_; } - int64_t max() const { return max_; } private: unsigned int id_; - unsigned int type_; - size_t size_; - std::string name_; - - int64_t min_; - int64_t max_; }; using V4L2ControlInfoMap = std::map; @@ -49,14 +38,15 @@ public: V4L2Control(unsigned int id, int value = 0) : id_(id), value_(value) {} - int64_t value() const { return value_; } + DataType type() const { return value_.type(); } + int64_t value() const { return value_.getInt64(); } void setValue(int64_t value) { value_ = value; } unsigned int id() const { return id_; } private: unsigned int id_; - int64_t value_; + DataValue value_; }; class V4L2ControlList diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 75a52c33d821..3144adc26e36 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -44,7 +44,6 @@ protected: private: void listControls(); void updateControls(V4L2ControlList *ctrls, - const V4L2ControlInfo **controlInfo, const struct v4l2_ext_control *v4l2Ctrls, unsigned int count); diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index 84258d9954d0..9bc4929cbd76 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -69,13 +69,10 @@ namespace libcamera { * \param ctrl The struct v4l2_query_ext_ctrl as returned by the kernel */ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) + : DataInfo(DataValue(static_cast(ctrl.minimum)), + DataValue(static_cast(ctrl.maximum))), + id_(ctrl.id) { - id_ = ctrl.id; - type_ = ctrl.type; - name_ = static_cast(ctrl.name); - size_ = ctrl.elem_size * ctrl.elems; - min_ = ctrl.minimum; - max_ = ctrl.maximum; } /** @@ -84,36 +81,6 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) * \return The V4L2 control ID */ -/** - * \fn V4L2ControlInfo::type() - * \brief Retrieve the control type as defined by V4L2_CTRL_TYPE_* - * \return The V4L2 control type - */ - -/** - * \fn V4L2ControlInfo::size() - * \brief Retrieve the control value data size (in bytes) - * \return The V4L2 control value data size - */ - -/** - * \fn V4L2ControlInfo::name() - * \brief Retrieve the control user readable name - * \return The V4L2 control user readable name - */ - -/** - * \fn V4L2ControlInfo::min() - * \brief Retrieve the control minimum value - * \return The V4L2 control minimum value - */ - -/** - * \fn V4L2ControlInfo::max() - * \brief Retrieve the control maximum value - * \return The V4L2 control maximum value - */ - /** * \typedef V4L2ControlInfoMap * \brief A map of control ID to V4L2ControlInfo @@ -134,6 +101,10 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) * to be directly used but are instead intended to be grouped in * V4L2ControlList instances, which are then passed as parameters to * V4L2Device::setControls() and V4L2Device::getControls() operations. + * + * \todo Currently all V4L2Controls are integers. For the sake of keeping the + * implementation as simpler as possible treat all values as int64. The value() + * and setValue() operations use that single data type for now. */ /** @@ -143,6 +114,12 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) * \param value The control value */ +/** + * \fn V4L2Control::type() + * \brief Retrieve the type of the control + * \return The control type + */ + /** * \fn V4L2Control::value() * \brief Retrieve the value of the control diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 349bf2d29704..e87863af6a66 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -169,7 +169,6 @@ int V4L2Device::getControls(V4L2ControlList *ctrls) if (count == 0) return 0; - const V4L2ControlInfo *controlInfo[count]; struct v4l2_ext_control v4l2Ctrls[count]; memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); @@ -183,7 +182,6 @@ int V4L2Device::getControls(V4L2ControlList *ctrls) } const V4L2ControlInfo *info = &iter->second; - controlInfo[i] = info; v4l2Ctrls[i].id = info->id(); } @@ -210,7 +208,7 @@ int V4L2Device::getControls(V4L2ControlList *ctrls) ret = errorIdx; } - updateControls(ctrls, controlInfo, v4l2Ctrls, count); + updateControls(ctrls, v4l2Ctrls, count); return ret; } @@ -244,7 +242,6 @@ int V4L2Device::setControls(V4L2ControlList *ctrls) if (count == 0) return 0; - const V4L2ControlInfo *controlInfo[count]; struct v4l2_ext_control v4l2Ctrls[count]; memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); @@ -258,12 +255,11 @@ int V4L2Device::setControls(V4L2ControlList *ctrls) } const V4L2ControlInfo *info = &iter->second; - controlInfo[i] = info; v4l2Ctrls[i].id = info->id(); /* Set the v4l2_ext_control value for the write operation. */ - switch (info->type()) { - case V4L2_CTRL_TYPE_INTEGER64: + switch (ctrl->type()) { + case DataTypeInteger64: v4l2Ctrls[i].value64 = ctrl->value(); break; default: @@ -299,7 +295,7 @@ int V4L2Device::setControls(V4L2ControlList *ctrls) ret = errorIdx; } - updateControls(ctrls, controlInfo, v4l2Ctrls, count); + updateControls(ctrls, v4l2Ctrls, count); return ret; } @@ -352,8 +348,7 @@ void V4L2Device::listControls() ctrl.flags & V4L2_CTRL_FLAG_DISABLED) continue; - V4L2ControlInfo info(ctrl); - switch (info.type()) { + switch (ctrl.type) { case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_BOOLEAN: case V4L2_CTRL_TYPE_MENU: @@ -364,11 +359,12 @@ void V4L2Device::listControls() break; /* \todo Support compound controls. */ default: - LOG(V4L2, Debug) << "Control type '" << info.type() + LOG(V4L2, Debug) << "Control type '" << ctrl.type << "' not supported"; continue; } + V4L2ControlInfo info(ctrl); controls_.emplace(ctrl.id, info); } } @@ -382,25 +378,22 @@ void V4L2Device::listControls() * \param[in] count The number of controls to update */ void V4L2Device::updateControls(V4L2ControlList *ctrls, - const V4L2ControlInfo **controlInfo, const struct v4l2_ext_control *v4l2Ctrls, unsigned int count) { for (unsigned int i = 0; i < count; ++i) { - const struct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i]; - const V4L2ControlInfo *info = controlInfo[i]; V4L2Control *ctrl = ctrls->getByIndex(i); - switch (info->type()) { - case V4L2_CTRL_TYPE_INTEGER64: - ctrl->setValue(v4l2Ctrl->value64); + switch (ctrl->type()) { + case DataTypeInteger64: + ctrl->setValue(v4l2Ctrls[i].value64); break; default: /* * \todo To be changed when support for string and * compound controls will be added. */ - ctrl->setValue(v4l2Ctrl->value); + ctrl->setValue(v4l2Ctrls[i].value); break; } }