From patchwork Sat Feb 29 16:42:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2944 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 D8634627B1 for ; Sat, 29 Feb 2020 17:43:31 +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 650C8A28; Sat, 29 Feb 2020 17:43:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994611; bh=5WMaq6ShjVpoElkukTSQMf+J1iplhPR/Tv+cYIKDfbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/dNHW3RDrjPUXUTLVRjFd/6hPI7DIUQF4B3f2CU/j8QvwVxNagdyPFArKhBwWkbI uobE6iQ+eS5kSH3vzSdUZUqQ8qNX1d8q17N3ese/tTsGbZO8DWp0deVlf1HTbJVTzN e2hg8bDLClMatSu7/WkxJmgw9xx/G1kR8OztGToc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:50 +0200 Message-Id: <20200229164254.23604-28-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 27/31] libcamera: control_serializer: Add support for 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, 29 Feb 2020 16:43:36 -0000 From: Jacopo Mondi Add support for serializing and deserializing control values that store arrays of values. The serialized format is extended to explicitly handle arrays. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/control_serializer.cpp | 80 ++++++++++++---------- src/libcamera/include/control_serializer.h | 6 +- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index 6cac70739468..31b03e6e6d7c 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "byte_stream_buffer.h" #include "log.h" @@ -279,8 +280,9 @@ int ControlSerializer::serialize(const ControlList &list, struct ipa_control_value_entry entry; entry.id = id; - entry.count = 1; entry.type = value.type(); + entry.is_array = value.isArray(); + entry.count = value.numElements(); entry.offset = values.offset(); entries.write(&entry); @@ -293,52 +295,56 @@ int ControlSerializer::serialize(const ControlList &list, return 0; } -template<> -ControlValue ControlSerializer::load(ControlType type, - ByteStreamBuffer &b) +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; +} + +ControlValue ControlSerializer::loadControlValue(ControlType type, + ByteStreamBuffer &buffer, + bool isArray, + unsigned int count) { switch (type) { - case ControlTypeBool: { - bool value; - b.read(&value); - return ControlValue(value); - } + case ControlTypeBool: + return loadControlValue(buffer, isArray, count); - case ControlTypeInteger8: { - int8_t value; - b.read(&value); - return ControlValue(value); - } + case ControlTypeInteger8: + return loadControlValue(buffer, isArray, count); - case ControlTypeInteger32: { - int32_t value; - b.read(&value); - return ControlValue(value); - } + case ControlTypeInteger32: + return loadControlValue(buffer, isArray, count); - case ControlTypeInteger64: { - int64_t value; - b.read(&value); - return ControlValue(value); - } + case ControlTypeInteger64: + return loadControlValue(buffer, isArray, count); - case ControlTypeFloat: { - float value; - b.read(&value); - return ControlValue(value); - } + case ControlTypeFloat: + return loadControlValue(buffer, isArray, count); default: return ControlValue(); } } -template<> -ControlRange ControlSerializer::load(ControlType type, - ByteStreamBuffer &b) +ControlRange ControlSerializer::loadControlRange(ControlType type, + ByteStreamBuffer &b) { - ControlValue min = load(type, b); - ControlValue max = load(type, b); + ControlValue min = loadControlValue(type, b); + ControlValue max = loadControlValue(type, b); return ControlRange(min, max); } @@ -412,7 +418,7 @@ ControlInfoMap ControlSerializer::deserialize(ByteStreamBuffer & /* Create and store the ControlRange. */ ctrls.emplace(controlIds_.back().get(), - load(type, values)); + loadControlRange(type, values)); } /* @@ -500,7 +506,9 @@ ControlList ControlSerializer::deserialize(ByteStreamBuffer &buffer } ControlType type = static_cast(entry->type); - ctrls.set(entry->id, load(type, values)); + ctrls.set(entry->id, + loadControlValue(type, values, entry->is_array, + entry->count)); } return ctrls; diff --git a/src/libcamera/include/control_serializer.h b/src/libcamera/include/control_serializer.h index 55259913a2ca..b91d13155f5e 100644 --- a/src/libcamera/include/control_serializer.h +++ b/src/libcamera/include/control_serializer.h @@ -41,7 +41,11 @@ private: static void store(const ControlRange &range, ByteStreamBuffer &buffer); template - T load(ControlType type, ByteStreamBuffer &b); + ControlValue loadControlValue(ByteStreamBuffer &buffer, bool isArray, + unsigned int count); + ControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer, + bool isArray = false, unsigned int count = 1); + ControlRange loadControlRange(ControlType type, ByteStreamBuffer &buffer); unsigned int serial_; std::vector> controlIds_;