From patchwork Sat Feb 29 16:42: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: 2933 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 8D987627AB for ; Sat, 29 Feb 2020 17:43:27 +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 0672FA49 for ; Sat, 29 Feb 2020 17:43:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994607; bh=Jr+UsjTu+IpR948LvDC61E8yrlBuGmxw5fm5LwXPVT4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BPhPuXgoKDXIBPRlADGlaJKCDrNiZyypkK4UCkNLhAcn40AeZ2o4Kd7HdxhR5PFXi +xH5+ablleNHy1m66XXawEJAyoVLvOpCEtIgQIFM91DfJvvjFQUbgbOe8toQSgYEmh Bc/I7wB00UhIpa4vt2btBLKudXOtoGvw2nzPQBzQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:38 +0200 Message-Id: <20200229164254.23604-16-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> References: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 15/31] libcamera: controls: Expose raw data in 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, 29 Feb 2020 16:43:31 -0000 Add a data() function to the ControlValue class to expose the raw data stored by the class as a Span. This will be useful to simplify the serialization of ControlValue instances. The size computation for the raw data is moved from the ControlSerializer, which is updated accordingly to use the data() function in order to access the size. Simplification of the ControlSerializer will happen in a subsequent change. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/controls.h | 3 +++ src/libcamera/control_serializer.cpp | 13 +------------ src/libcamera/controls.cpp | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 6f0ebf4f3ca5..4538be06af93 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -12,6 +12,8 @@ #include #include +#include + namespace libcamera { class ControlValidator; @@ -65,6 +67,7 @@ public: ControlType type() const { return type_; } bool isNone() const { return type_ == ControlTypeNone; } + Span data() const; std::string toString() const; diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index 803ac16c2456..2b66ab978f81 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -27,17 +27,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Serializer) -namespace { - -static constexpr size_t ControlValueSize[] = { - [ControlTypeNone] = 1, - [ControlTypeBool] = sizeof(bool), - [ControlTypeInteger32] = sizeof(int32_t), - [ControlTypeInteger64] = sizeof(int64_t), -}; - -} /* namespace */ - /** * \class ControlSerializer * \brief Serializer and deserializer for control-related classes @@ -106,7 +95,7 @@ void ControlSerializer::reset() size_t ControlSerializer::binarySize(const ControlValue &value) { - return ControlValueSize[value.type()]; + return value.data().size_bytes(); } size_t ControlSerializer::binarySize(const ControlRange &range) diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 76230a052de1..b2331ab7540d 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -47,6 +47,17 @@ namespace libcamera { LOG_DEFINE_CATEGORY(Controls) +namespace { + +static constexpr size_t ControlValueSize[] = { + [ControlTypeNone] = 1, + [ControlTypeBool] = sizeof(bool), + [ControlTypeInteger32] = sizeof(int32_t), + [ControlTypeInteger64] = sizeof(int64_t), +}; + +} /* namespace */ + /** * \enum ControlType * \brief Define the data type of a Control @@ -91,6 +102,18 @@ ControlValue::ControlValue() * \return True if the value type is ControlTypeNone, false otherwise */ +/** + * \brief Retrieve the raw of a control value + * \return The raw data of the control value as a span of uint8_t + */ +Span ControlValue::data() const +{ + return { + reinterpret_cast(&bool_), + ControlValueSize[type_] + }; +} + /** * \brief Assemble and return a string describing the value * \return A string describing the ControlValue