From patchwork Sat Mar 21 00:36:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3229 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06A9662BA9 for ; Sat, 21 Mar 2020 01:36:51 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8B5B31265; Sat, 21 Mar 2020 01:36:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584751010; bh=Rx24ezjq6uZEMrSny/+gAL7tGn9NMgYHXjSoiZdj9VE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GmjI+T/K/d4DwAEDbH+AVSNWm3J16GepE3ThjJPuCWBAuv5YyMCZcu5L3ygoONgtH tnprOMuNK2EVITMVF6FOzoL9/yjVTpOYdzEE3+QdvPpvVJkgRSzmssx52NuEiYd+eO UkiuD/AkxULdSp2i5eTEEUCcq6T7d1RPYJEHucE8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 21 Mar 2020 02:36:34 +0200 Message-Id: <20200321003640.2156-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> References: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/7] libcamera: controls: Add zero-copy set API for ControlValue 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: Sat, 21 Mar 2020 00:36:51 -0000 Extend the ControlValue class with a reserve() function to set the value without actually copying data, and a non-const data() function that allows writing data directly to the ControlValue storage. This allows allocating memory directly in ControlValue, potentially removing a data copy. Note that this change was implemented before ByteStreamBuffer gained the zero-copy read() variant, and doesn't actually save a copy in the control serializer. It however still simplifies ControlSerializer::loadControlValue(). Signed-off-by: Laurent Pinchart --- include/libcamera/controls.h | 4 ++ src/libcamera/control_serializer.cpp | 61 ++-------------------- src/libcamera/controls.cpp | 54 ++++++++++++++----- src/libcamera/include/control_serializer.h | 3 -- 4 files changed, 50 insertions(+), 72 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 2a6657128f17..4b2e7e9cdd6c 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -115,6 +115,7 @@ public: bool isArray() const { return isArray_; } std::size_t numElements() const { return numElements_; } Span data() const; + Span data(); std::string toString() const; @@ -174,6 +175,9 @@ public: value.data(), value.size(), sizeof(typename T::value_type)); } + void reserve(ControlType type, bool isArray = false, + std::size_t numElements = 1); + private: ControlType type_ : 8; bool isArray_; diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index 808419f246c0..fcff5e56fbf7 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -295,70 +295,17 @@ int ControlSerializer::serialize(const ControlList &list, return 0; } -template -ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, - bool isArray, - unsigned int count) -{ - ControlValue value; - - const T *data = buffer.read(count); - if (!data) - return value; - - if (isArray) - value.set(Span{ data, count }); - else - value.set(*data); - - return value; -} - -template<> -ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, - bool isArray, - unsigned int count) -{ - ControlValue value; - - const char *data = buffer.read(count); - if (!data) - return value; - - value.set(std::string{ data, count }); - - return value; -} - ControlValue ControlSerializer::loadControlValue(ControlType type, ByteStreamBuffer &buffer, bool isArray, unsigned int count) { - switch (type) { - case ControlTypeBool: - return loadControlValue(buffer, isArray, count); - - case ControlTypeByte: - return loadControlValue(buffer, isArray, count); - - case ControlTypeInteger32: - return loadControlValue(buffer, isArray, count); - - case ControlTypeInteger64: - return loadControlValue(buffer, isArray, count); - - case ControlTypeFloat: - return loadControlValue(buffer, isArray, count); - - case ControlTypeString: - return loadControlValue(buffer, isArray, count); + ControlValue value; - case ControlTypeNone: - return ControlValue(); - } + value.reserve(type, isArray, count); + buffer.read(value.data()); - return ControlValue(); + return value; } ControlInfo ControlSerializer::loadControlInfo(ControlType type, diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 2568447478d5..540cc026417a 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -189,6 +189,15 @@ Span ControlValue::data() const return { data, size }; } +/** + * \copydoc ControlValue::data() const + */ +Span ControlValue::data() +{ + Span data = const_cast(this)->data(); + return { const_cast(data.data()), data.size() }; +} + /** * \brief Assemble and return a string describing the value * \return A string describing the ControlValue @@ -312,23 +321,44 @@ void ControlValue::set(ControlType type, bool isArray, const void *data, { ASSERT(elementSize == ControlValueSize[type]); - release(); + reserve(type, isArray, numElements); + + Span storage = ControlValue::data(); + memcpy(storage.data(), data, storage.size()); +} + +/** + * \brief Set the control type and reserve memory + * \param[in] type The control type + * \param[in] isArray True to make the value an array + * \param[in] numElements The number of elements + * + * This function sets the type of the control value to \a type, and reserves + * memory to store the control value. If \a isArray is true, the instance + * becomes an array control and storage for \a numElements is reserved. + * Otherwise the instance becomes a simple control, numElements is ignored, and + * storage for the single element is reserved. + */ +void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElements) +{ + if (!isArray) + numElements = 1; + + std::size_t oldSize = numElements_ * ControlValueSize[type_]; + std::size_t newSize = numElements * ControlValueSize[type]; + + if (oldSize != newSize) + release(); type_ = type; - numElements_ = numElements; isArray_ = isArray; + numElements_ = numElements; - std::size_t size = elementSize * numElements; - void *storage; - - if (size > sizeof(value_)) { - storage_ = reinterpret_cast(new uint8_t[size]); - storage = storage_; - } else { - storage = reinterpret_cast(&value_); - } + if (oldSize == newSize) + return; - memcpy(storage, data, size); + if (newSize > sizeof(value_)) + storage_ = reinterpret_cast(new uint8_t[newSize]); } /** diff --git a/src/libcamera/include/control_serializer.h b/src/libcamera/include/control_serializer.h index 70aa28fd5f58..99bacd920fce 100644 --- a/src/libcamera/include/control_serializer.h +++ b/src/libcamera/include/control_serializer.h @@ -40,9 +40,6 @@ private: static void store(const ControlValue &value, ByteStreamBuffer &buffer); static void store(const ControlInfo &info, ByteStreamBuffer &buffer); - template - ControlValue loadControlValue(ByteStreamBuffer &buffer, bool isArray, - unsigned int count); ControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer, bool isArray = false, unsigned int count = 1); ControlInfo loadControlInfo(ControlType type, ByteStreamBuffer &buffer); From patchwork Sat Mar 21 00:36:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3230 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 6936D62BA9 for ; Sat, 21 Mar 2020 01:36:51 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EA960A54; Sat, 21 Mar 2020 01:36:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584751011; bh=+gpWLOTwj2hkj3rLy7bRt3VSRI+ILclZJ2h8Dx9BPF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HvtG1c2ypB3h+WMTs/vXx/aIIgIpfmvIYu06hsPDybiqUobxdDJW/ihJGV9Pp2lS6 O0r2wYljM8P1p9hnsoy5PCbcWyYg1O6FOoF9VZSFOWaJRwL+lS9YJlXqvaGxBPhqe6 y+h3rtoN3703MxKn9AU6YtnHtpGO1OgF6aJbV+gI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 21 Mar 2020 02:36:35 +0200 Message-Id: <20200321003640.2156-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> References: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/7] libcamera: v4l2_controls: Cache query control information 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: Sat, 21 Mar 2020 00:36:52 -0000 From: Jacopo Mondi Cache the V4L2 control info retrieved with VIDIOC_QUERY_EXT_CTRL at control listing time for later use. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- Changes since v1: - Rename ctrlsInfo_ to controlInfo_ - Add entry in controlInfo_ with emplace --- src/libcamera/include/v4l2_device.h | 1 + src/libcamera/v4l2_device.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 6bfddefe336c..ce8edd98a01d 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -48,6 +48,7 @@ private: const struct v4l2_ext_control *v4l2Ctrls, unsigned int count); + std::map controlInfo_; std::vector> controlIds_; ControlInfoMap controls_; std::string deviceNode_; diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 179476e9afad..7eded67cb47e 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -381,6 +381,8 @@ void V4L2Device::listControls() } controlIds_.emplace_back(std::make_unique(ctrl)); + controlInfo_.emplace(ctrl.id, ctrl); + ctrls.emplace(controlIds_.back().get(), V4L2ControlInfo(ctrl)); } From patchwork Sat Mar 21 00:36:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3231 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C4DBC629AC for ; Sat, 21 Mar 2020 01:36:51 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 54E981265; Sat, 21 Mar 2020 01:36:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584751011; bh=jZBPg1dufv7uT5Rc6od88PpVb6kEWFLbu0m+gYgRZOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cKkDbQlwyta9509axDiB3zq4NirmZgb7NEY/ytcgCqGvN1XBkLJfQiUgPuxFiQP7D QtCaX3G3sNoi8wuHmRwofqn04QwQ24m3vJ5z1C9Dd9VKvqy2biouetIehXX8MVyclC Hr4PBT6x5rywGMWs5jvzFZ992WzzD7vf8jpk/OHo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 21 Mar 2020 02:36:36 +0200 Message-Id: <20200321003640.2156-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> References: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/7] libcamera: v4l2_device: Support writing array U8 controls 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: Sat, 21 Mar 2020 00:36:52 -0000 From: Jacopo Mondi Add support to write array controls of type V4L2_CTRL_TYPE_U8. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- Changes since v1: - Avoid copy of data in updateControls() - Use writable ControlValue storage directly for arrays in setControls() - Return an error when setting a control with a non-array value --- src/libcamera/v4l2_device.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 7eded67cb47e..2139e98bc9b8 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -250,7 +250,7 @@ int V4L2Device::setControls(ControlList *ctrls) memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); unsigned int i = 0; - for (const auto &ctrl : *ctrls) { + for (auto &ctrl : *ctrls) { unsigned int id = ctrl.first; const auto iter = controls_.find(id); if (iter == controls_.end()) { @@ -262,16 +262,29 @@ int V4L2Device::setControls(ControlList *ctrls) v4l2Ctrls[i].id = id; /* Set the v4l2_ext_control value for the write operation. */ - const ControlValue &value = ctrl.second; + ControlValue &value = ctrl.second; switch (iter->first->type()) { case ControlTypeInteger64: v4l2Ctrls[i].value64 = value.get(); break; + + case ControlTypeByte: { + if (!value.isArray()) { + LOG(V4L2, Error) + << "Control " << utils::hex(id) + << " requires an array value"; + return -EINVAL; + } + + Span data = value.data(); + v4l2Ctrls[i].p_u8 = data.data(); + v4l2Ctrls[i].size = data.size(); + + break; + } + default: - /* - * \todo To be changed when support for string and - * compound controls will be added. - */ + /* \todo To be changed to support strings. */ v4l2Ctrls[i].value = value.get(); break; } @@ -414,6 +427,14 @@ void V4L2Device::updateControls(ControlList *ctrls, case ControlTypeInteger64: value.set(v4l2Ctrl->value64); break; + + case ControlTypeByte: + /* + * No action required, the VIDIOC_[GS]_EXT_CTRLS ioctl + * accessed the ControlValue storage directly. + */ + break; + default: /* * \todo To be changed when support for string and From patchwork Sat Mar 21 00:36:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3232 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 33E4C62BBA for ; Sat, 21 Mar 2020 01:36:52 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B4655A54; Sat, 21 Mar 2020 01:36:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584751011; bh=WkVhICCZLGxluzQQoI6YYP/MJbEJ6X5+ql3oFelp9qs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rfG70g7ltmePkCRu6LAoesrioP2+z/N4THAU0o1rUJkmrn6/iaiBGMNu9MuDx0dQ8 4TJ8SlmsSvDQ7Ef16SQ/9Io+YcOGTl8P/ZCYBiRwQbgma8MM5imm+2uMPul9fEjRvp GMqUQzeBW4DHvbJHVoniUnCpXE1DytiPN5qm2i/A= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 21 Mar 2020 02:36:37 +0200 Message-Id: <20200321003640.2156-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> References: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/7] libcamera: v4l2_device: Support reading U8 array controls 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: Sat, 21 Mar 2020 00:36:52 -0000 From: Jacopo Mondi Add support to retrieve the value of array controls of type V4L2_CTRL_TYPE_U8. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- Changes since v1: - Use writable ControlValue storage directly for arrays in getControls() - Handle the control type more generically - Improve error message for unsupported types - Rename ctrlsInfo_ to controlInfo_ --- src/libcamera/v4l2_device.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 2139e98bc9b8..3c91eb3f9f97 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -176,7 +176,7 @@ int V4L2Device::getControls(ControlList *ctrls) memset(v4l2Ctrls, 0, sizeof(v4l2Ctrls)); unsigned int i = 0; - for (const auto &ctrl : *ctrls) { + for (auto &ctrl : *ctrls) { unsigned int id = ctrl.first; const auto iter = controls_.find(id); if (iter == controls_.end()) { @@ -185,6 +185,31 @@ int V4L2Device::getControls(ControlList *ctrls) return -EINVAL; } + const struct v4l2_query_ext_ctrl &info = controlInfo_[id]; + ControlValue &value = ctrl.second; + + if (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) { + ControlType type; + + switch (info.type) { + case V4L2_CTRL_TYPE_U8: + type = ControlTypeByte; + break; + + default: + LOG(V4L2, Error) + << "Unsupported payload control type " + << info.type; + return -EINVAL; + } + + value.reserve(type, true, info.elems); + Span data = value.data(); + + v4l2Ctrls[i].p_u8 = data.data(); + v4l2Ctrls[i].size = data.size(); + } + v4l2Ctrls[i].id = id; i++; } From patchwork Sat Mar 21 00:36:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3233 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 8A42060417 for ; Sat, 21 Mar 2020 01:36:52 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1EE1613C2; Sat, 21 Mar 2020 01:36:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584751012; bh=pBp1/PYh/igJaChzKg9zuLWL2Jc6myjZrMYMLO/Z5Pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EEDZFzgOU6dmv5pINKTGg65tWWZquVz+8B+OSoLkdas0F1M0UPFAwMw+9iPI1qgtI Dbt2PnmENGdiLmY9a6LuPkzx8pEPPBVVtL071YVzv0nu7cWN1bucVV6faCBuoSlNiP lCAdOWuHNIZFA0Sf1o1vEFxOc6yv5GWzRX2hA4iU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 21 Mar 2020 02:36:38 +0200 Message-Id: <20200321003640.2156-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> References: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/7] libcamera: v4l2_controls: Support U8 array controls 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: Sat, 21 Mar 2020 00:36:52 -0000 From: Jacopo Mondi Add support for array controls of type V4L2_CTRL_TYPE_U8. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_controls.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index 4861f9778df3..8e2415f2a6df 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -60,6 +60,9 @@ std::string v4l2_ctrl_name(const struct v4l2_query_ext_ctrl &ctrl) ControlType v4l2_ctrl_type(const struct v4l2_query_ext_ctrl &ctrl) { switch (ctrl.type) { + case V4L2_CTRL_TYPE_U8: + return ControlTypeByte; + case V4L2_CTRL_TYPE_BOOLEAN: return ControlTypeBool; @@ -119,6 +122,12 @@ V4L2ControlId::V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl) V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) { switch (ctrl.type) { + case V4L2_CTRL_TYPE_U8: + ControlInfo::operator=(ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value))); + break; + case V4L2_CTRL_TYPE_BOOLEAN: ControlInfo::operator=(ControlInfo(static_cast(ctrl.minimum), static_cast(ctrl.maximum), From patchwork Sat Mar 21 00:36:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3234 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EEE7C60417 for ; Sat, 21 Mar 2020 01:36:52 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7FAEBA54; Sat, 21 Mar 2020 01:36:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584751012; bh=wHcC7cWqXvwgldOyvO5EGAqqYYZ0qOeXWPOK7SkEouM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ETU7wEVNwqV65fOIup7FYnoPceC5tHI1gpk6jvg6N/4dovKzAh5aTVo+Jm12Yjc8u +XfqvP5NJwH/oQHAUayoToDBZobESVnX4AVmqpAVRuq+XImWpmTmEq63gK4+rzbI2q p8dFMI6w8zStY0uFrfPOKJTDFVoxJlj9PBywpnyA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 21 Mar 2020 02:36:39 +0200 Message-Id: <20200321003640.2156-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> References: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/7] libcamera: v4l2_device: Enable enumeration of U8 controls 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: Sat, 21 Mar 2020 00:36:53 -0000 From: Jacopo Mondi Enable the enumeration of V4L2 array controls with V4L2_CTRL_TYPE_U8 type. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/v4l2_device.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 3c91eb3f9f97..03e305165096 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -386,7 +386,8 @@ void V4L2Device::listControls() /* \todo Add support for menu and compound controls. */ while (1) { - ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; + ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL | + V4L2_CTRL_FLAG_NEXT_COMPOUND; if (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl)) break; @@ -394,13 +395,6 @@ void V4L2Device::listControls() ctrl.flags & V4L2_CTRL_FLAG_DISABLED) continue; - if (ctrl.elems != 1 || ctrl.nr_of_dims) { - LOG(V4L2, Debug) - << "Array control " << utils::hex(ctrl.id) - << " not supported"; - continue; - } - switch (ctrl.type) { case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_BOOLEAN: @@ -409,8 +403,9 @@ void V4L2Device::listControls() case V4L2_CTRL_TYPE_INTEGER64: case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_INTEGER_MENU: + case V4L2_CTRL_TYPE_U8: break; - /* \todo Support compound controls. */ + /* \todo Support other control types. */ default: LOG(V4L2, Debug) << "Control " << utils::hex(ctrl.id) From patchwork Sat Mar 21 00:36:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3235 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 5161460417 for ; Sat, 21 Mar 2020 01:36:53 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E058813C2; Sat, 21 Mar 2020 01:36:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584751013; bh=u6GRWgZptZJUm8GwP2bbv31pja9xaDi8JNeyq9Bohnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o8trWShn7b5gXUUEbjwUU32cZxDh+zpZ1FxhH1+7ikTaBsLZ20UkV+aF4+AN6ivnV 7iPD8weptEPSMCJ06bzgh135/oOvf5I/Y3LyS5bj32+HbSe3ynN23modtLHI/ntNGB ZzD18RV//EoTL0ZBL7lW7XLJ7bohadD1vyiXEqyg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 21 Mar 2020 02:36:40 +0200 Message-Id: <20200321003640.2156-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> References: <20200321003640.2156-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/7] test: v4l2_videodevice: Test U8 array controls 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: Sat, 21 Mar 2020 00:36:53 -0000 From: Jacopo Mondi Test V4L2 array control using vivid control VIVID_CID_U8_4D_ARRAY. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- Changes since v1: - Add missing period in comment - Use - Don't set array value for VIVID_CID_U8_4D_ARRAY before getControls() --- test/v4l2_videodevice/controls.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp index 478de3707a3c..da9e0111e221 100644 --- a/test/v4l2_videodevice/controls.cpp +++ b/test/v4l2_videodevice/controls.cpp @@ -5,6 +5,8 @@ * controls.cpp - V4L2 device controls handling test */ +#include +#include #include #include @@ -12,6 +14,13 @@ #include "v4l2_videodevice_test.h" +/* These come from the vivid driver. */ +#define VIVID_CID_CUSTOM_BASE (V4L2_CID_USER_BASE | 0xf000) +#define VIVID_CID_U8_4D_ARRAY (VIVID_CID_CUSTOM_BASE + 10) + +/* Helper for VIVID_CID_U8_4D_ARRAY control array size: not from kernel. */ +#define VIVID_CID_U8_ARRAY_SIZE (2 * 3 * 4 * 5) + using namespace std; using namespace libcamera; @@ -36,7 +45,8 @@ protected: if (infoMap.find(V4L2_CID_BRIGHTNESS) == infoMap.end() || infoMap.find(V4L2_CID_CONTRAST) == infoMap.end() || - infoMap.find(V4L2_CID_SATURATION) == infoMap.end()) { + infoMap.find(V4L2_CID_SATURATION) == infoMap.end() || + infoMap.find(VIVID_CID_U8_4D_ARRAY) == infoMap.end()) { cerr << "Missing controls" << endl; return TestFail; } @@ -44,12 +54,14 @@ protected: const ControlInfo &brightness = infoMap.find(V4L2_CID_BRIGHTNESS)->second; const ControlInfo &contrast = infoMap.find(V4L2_CID_CONTRAST)->second; const ControlInfo &saturation = infoMap.find(V4L2_CID_SATURATION)->second; + const ControlInfo &u8 = infoMap.find(VIVID_CID_U8_4D_ARRAY)->second; /* Test getting controls. */ ControlList ctrls(infoMap); ctrls.set(V4L2_CID_BRIGHTNESS, -1); ctrls.set(V4L2_CID_CONTRAST, -1); ctrls.set(V4L2_CID_SATURATION, -1); + ctrls.set(VIVID_CID_U8_4D_ARRAY, 0); int ret = capture_->getControls(&ctrls); if (ret) { @@ -64,11 +76,27 @@ protected: return TestFail; } + uint8_t u8Min = u8.min().get(); + uint8_t u8Max = u8.max().get(); + + Span u8Span = ctrls.get(VIVID_CID_U8_4D_ARRAY).get>(); + bool valid = std::all_of(u8Span.begin(), u8Span.end(), + [&](uint8_t v) { return v >= u8Min && v <= u8Max; }); + if (!valid) { + cerr << "Incorrect value for retrieved array control" + << endl; + return TestFail; + } + /* Test setting controls. */ ctrls.set(V4L2_CID_BRIGHTNESS, brightness.min()); ctrls.set(V4L2_CID_CONTRAST, contrast.max()); ctrls.set(V4L2_CID_SATURATION, saturation.min()); + std::array u8Values; + std::fill(u8Values.begin(), u8Values.end(), u8.min().get()); + ctrls.set(VIVID_CID_U8_4D_ARRAY, Span(u8Values)); + ret = capture_->setControls(&ctrls); if (ret) { cerr << "Failed to set controls" << endl;