{"id":2944,"url":"https://patchwork.libcamera.org/api/1.1/patches/2944/?format=json","web_url":"https://patchwork.libcamera.org/patch/2944/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200229164254.23604-28-laurent.pinchart@ideasonboard.com>","date":"2020-02-29T16:42:50","name":"[libcamera-devel,27/31] libcamera: control_serializer: Add support for array controls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"23619aa081dfbba484deb4c4d164ff3cd0f9a6cd","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2944/mbox/","series":[{"id":696,"url":"https://patchwork.libcamera.org/api/1.1/series/696/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=696","date":"2020-02-29T16:42:23","name":"libcamera: Add support for array controls","version":1,"mbox":"https://patchwork.libcamera.org/series/696/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2944/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2944/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D8634627B1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Feb 2020 17:43:31 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 650C8A28;\n\tSat, 29 Feb 2020 17:43:31 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1582994611;\n\tbh=5WMaq6ShjVpoElkukTSQMf+J1iplhPR/Tv+cYIKDfbQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=n/dNHW3RDrjPUXUTLVRjFd/6hPI7DIUQF4B3f2CU/j8QvwVxNagdyPFArKhBwWkbI\n\tuobE6iQ+eS5kSH3vzSdUZUqQ8qNX1d8q17N3ese/tTsGbZO8DWp0deVlf1HTbJVTzN\n\te2hg8bDLClMatSu7/WkxJmgw9xx/G1kR8OztGToc=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 27/31] libcamera: control_serializer: Add\n\tsupport for array controls","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 29 Feb 2020 16:43:36 -0000"},"content":"From: Jacopo Mondi <jacopo@jmondi.org>\n\nAdd support for serializing and deserializing control values that store\narrays of values. The serialized format is extended to explicitly handle\narrays.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/control_serializer.cpp       | 80 ++++++++++++----------\n src/libcamera/include/control_serializer.h |  6 +-\n 2 files changed, 49 insertions(+), 37 deletions(-)","diff":"diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp\nindex 6cac70739468..31b03e6e6d7c 100644\n--- a/src/libcamera/control_serializer.cpp\n+++ b/src/libcamera/control_serializer.cpp\n@@ -14,6 +14,7 @@\n #include <ipa/ipa_controls.h>\n #include <libcamera/control_ids.h>\n #include <libcamera/controls.h>\n+#include <libcamera/span.h>\n \n #include \"byte_stream_buffer.h\"\n #include \"log.h\"\n@@ -279,8 +280,9 @@ int ControlSerializer::serialize(const ControlList &list,\n \n \t\tstruct ipa_control_value_entry entry;\n \t\tentry.id = id;\n-\t\tentry.count = 1;\n \t\tentry.type = value.type();\n+\t\tentry.is_array = value.isArray();\n+\t\tentry.count = value.numElements();\n \t\tentry.offset = values.offset();\n \t\tentries.write(&entry);\n \n@@ -293,52 +295,56 @@ int ControlSerializer::serialize(const ControlList &list,\n \treturn 0;\n }\n \n-template<>\n-ControlValue ControlSerializer::load<ControlValue>(ControlType type,\n-\t\t\t\t\t\t   ByteStreamBuffer &b)\n+template<typename T>\n+ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer,\n+\t\t\t\t\t\t bool isArray,\n+\t\t\t\t\t\t unsigned int count)\n+{\n+\tControlValue value;\n+\n+\tconst T *data = buffer.read<T>(count);\n+\tif (!data)\n+\t\treturn value;\n+\n+\tif (isArray)\n+\t\tvalue.set(Span<const T>{ data, count });\n+\telse\n+\t\tvalue.set(*data);\n+\n+\treturn value;\n+}\n+\n+ControlValue ControlSerializer::loadControlValue(ControlType type,\n+\t\t\t\t\t\t ByteStreamBuffer &buffer,\n+\t\t\t\t\t\t bool isArray,\n+\t\t\t\t\t\t unsigned int count)\n {\n \tswitch (type) {\n-\tcase ControlTypeBool: {\n-\t\tbool value;\n-\t\tb.read(&value);\n-\t\treturn ControlValue(value);\n-\t}\n+\tcase ControlTypeBool:\n+\t\treturn loadControlValue<bool>(buffer, isArray, count);\n \n-\tcase ControlTypeInteger8: {\n-\t\tint8_t value;\n-\t\tb.read(&value);\n-\t\treturn ControlValue(value);\n-\t}\n+\tcase ControlTypeInteger8:\n+\t\treturn loadControlValue<int8_t>(buffer, isArray, count);\n \n-\tcase ControlTypeInteger32: {\n-\t\tint32_t value;\n-\t\tb.read(&value);\n-\t\treturn ControlValue(value);\n-\t}\n+\tcase ControlTypeInteger32:\n+\t\treturn loadControlValue<int32_t>(buffer, isArray, count);\n \n-\tcase ControlTypeInteger64: {\n-\t\tint64_t value;\n-\t\tb.read(&value);\n-\t\treturn ControlValue(value);\n-\t}\n+\tcase ControlTypeInteger64:\n+\t\treturn loadControlValue<int64_t>(buffer, isArray, count);\n \n-\tcase ControlTypeFloat: {\n-\t\tfloat value;\n-\t\tb.read(&value);\n-\t\treturn ControlValue(value);\n-\t}\n+\tcase ControlTypeFloat:\n+\t\treturn loadControlValue<float>(buffer, isArray, count);\n \n \tdefault:\n \t\treturn ControlValue();\n \t}\n }\n \n-template<>\n-ControlRange ControlSerializer::load<ControlRange>(ControlType type,\n-\t\t\t\t\t\t   ByteStreamBuffer &b)\n+ControlRange ControlSerializer::loadControlRange(ControlType type,\n+\t\t\t\t\t\t ByteStreamBuffer &b)\n {\n-\tControlValue min = load<ControlValue>(type, b);\n-\tControlValue max = load<ControlValue>(type, b);\n+\tControlValue min = loadControlValue(type, b);\n+\tControlValue max = loadControlValue(type, b);\n \n \treturn ControlRange(min, max);\n }\n@@ -412,7 +418,7 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n \n \t\t/* Create and store the ControlRange. */\n \t\tctrls.emplace(controlIds_.back().get(),\n-\t\t\t      load<ControlRange>(type, values));\n+\t\t\t      loadControlRange(type, values));\n \t}\n \n \t/*\n@@ -500,7 +506,9 @@ ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer\n \t\t}\n \n \t\tControlType type = static_cast<ControlType>(entry->type);\n-\t\tctrls.set(entry->id, load<ControlValue>(type, values));\n+\t\tctrls.set(entry->id,\n+\t\t\t  loadControlValue(type, values, entry->is_array,\n+\t\t\t\t\t   entry->count));\n \t}\n \n \treturn ctrls;\ndiff --git a/src/libcamera/include/control_serializer.h b/src/libcamera/include/control_serializer.h\nindex 55259913a2ca..b91d13155f5e 100644\n--- a/src/libcamera/include/control_serializer.h\n+++ b/src/libcamera/include/control_serializer.h\n@@ -41,7 +41,11 @@ private:\n \tstatic void store(const ControlRange &range, ByteStreamBuffer &buffer);\n \n \ttemplate<typename T>\n-\tT load(ControlType type, ByteStreamBuffer &b);\n+\tControlValue loadControlValue(ByteStreamBuffer &buffer, bool isArray,\n+\t\t\t\t      unsigned int count);\n+\tControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer,\n+\t\t\t\t      bool isArray = false, unsigned int count = 1);\n+\tControlRange loadControlRange(ControlType type, ByteStreamBuffer &buffer);\n \n \tunsigned int serial_;\n \tstd::vector<std::unique_ptr<ControlId>> controlIds_;\n","prefixes":["libcamera-devel","27/31"]}