[{"id":24907,"web_url":"https://patchwork.libcamera.org/comment/24907/","msgid":"<20220903005109.GB113531@pyrite.rasen.tech>","date":"2022-09-03T00:51:09","subject":"Re: [libcamera-devel] [PATCH v3 1/2] libcamera: serialiser:\n\tstore/load all ControlValue types","submitter":{"id":97,"url":"https://patchwork.libcamera.org/api/people/97/","name":"Nicolas Dufresne via libcamera-devel","email":"libcamera-devel@lists.libcamera.org"},"content":"Hi Christian,\n\nThank you for the patch.\n\nIn the subject:\n\ns/serialiser/control_serializer/\n\nOn Sat, Sep 03, 2022 at 12:49:38AM +0200, Christian Rauch via libcamera-devel wrote:\n> The min/max/def ControlValue of a ControlInfo can take arbitrary types that\n> are different from each other and different from the ControlId type.\n> The serialiser serialises these ControlValue separately by there type but\n\ns/there/their/\n\n> does not store the type. The deserialiser assumes that ControlValue types\n> match the ControlId type. If this is not the case, deserialisation will try\n> to deserialise values of the wrong type.\n> \n> Fix this by serialising each of the min/max/def ControlValue's ControlType\n> and storing it just before the serialised ControlValue.\n> \n> Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>\n\nThis fixes bug 137 (not sure if there's a specific \"Fixes:\" tag for\nthis)\n\nTested-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  .../libcamera/internal/control_serializer.h   |  4 +--\n>  src/libcamera/control_serializer.cpp          | 28 +++++++++----------\n>  2 files changed, 15 insertions(+), 17 deletions(-)\n> \n> diff --git a/include/libcamera/internal/control_serializer.h b/include/libcamera/internal/control_serializer.h\n> index 99e57fee..a38ca6b0 100644\n> --- a/include/libcamera/internal/control_serializer.h\n> +++ b/include/libcamera/internal/control_serializer.h\n> @@ -47,9 +47,9 @@ private:\n>  \tstatic void store(const ControlValue &value, ByteStreamBuffer &buffer);\n>  \tstatic void store(const ControlInfo &info, ByteStreamBuffer &buffer);\n> \n> -\tControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer,\n> +\tControlValue loadControlValue(ByteStreamBuffer &buffer,\n>  \t\t\t\t      bool isArray = false, unsigned int count = 1);\n> -\tControlInfo loadControlInfo(ControlType type, ByteStreamBuffer &buffer);\n> +\tControlInfo loadControlInfo(ByteStreamBuffer &buffer);\n> \n>  \tunsigned int serial_;\n>  \tunsigned int serialSeed_;\n> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp\n> index e87d2362..0cf719bd 100644\n> --- a/src/libcamera/control_serializer.cpp\n> +++ b/src/libcamera/control_serializer.cpp\n> @@ -144,7 +144,7 @@ void ControlSerializer::reset()\n> \n>  size_t ControlSerializer::binarySize(const ControlValue &value)\n>  {\n> -\treturn value.data().size_bytes();\n> +\treturn sizeof(ControlType) + value.data().size_bytes();\n>  }\n> \n>  size_t ControlSerializer::binarySize(const ControlInfo &info)\n> @@ -195,6 +195,8 @@ size_t ControlSerializer::binarySize(const ControlList &list)\n>  void ControlSerializer::store(const ControlValue &value,\n>  \t\t\t      ByteStreamBuffer &buffer)\n>  {\n> +\tconst ControlType type = value.type();\n> +\tbuffer.write(&type);\n>  \tbuffer.write(value.data());\n>  }\n> \n> @@ -379,11 +381,13 @@ int ControlSerializer::serialize(const ControlList &list,\n>  \treturn 0;\n>  }\n> \n> -ControlValue ControlSerializer::loadControlValue(ControlType type,\n> -\t\t\t\t\t\t ByteStreamBuffer &buffer,\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> +\tControlType type;\n> +\tbuffer.read(&type);\n> +\n>  \tControlValue value;\n> \n>  \tvalue.reserve(type, isArray, count);\n> @@ -392,15 +396,11 @@ ControlValue ControlSerializer::loadControlValue(ControlType type,\n>  \treturn value;\n>  }\n> \n> -ControlInfo ControlSerializer::loadControlInfo(ControlType type,\n> -\t\t\t\t\t       ByteStreamBuffer &b)\n> +ControlInfo ControlSerializer::loadControlInfo(ByteStreamBuffer &b)\n>  {\n> -\tif (type == ControlTypeString)\n> -\t\ttype = ControlTypeInteger32;\n> -\n> -\tControlValue min = loadControlValue(type, b);\n> -\tControlValue max = loadControlValue(type, b);\n> -\tControlValue def = loadControlValue(type, b);\n> +\tControlValue min = loadControlValue(b);\n> +\tControlValue max = loadControlValue(b);\n> +\tControlValue def = loadControlValue(b);\n> \n>  \treturn ControlInfo(min, max, def);\n>  }\n> @@ -513,7 +513,7 @@ ControlInfoMap ControlSerializer::deserialize<ControlInfoMap>(ByteStreamBuffer &\n>  \t\t}\n> \n>  \t\t/* Create and store the ControlInfo. */\n> -\t\tctrls.emplace(controlId, loadControlInfo(type, values));\n> +\t\tctrls.emplace(controlId, loadControlInfo(values));\n>  \t}\n> \n>  \t/*\n> @@ -624,10 +624,8 @@ ControlList ControlSerializer::deserialize<ControlList>(ByteStreamBuffer &buffer\n>  \t\t\treturn {};\n>  \t\t}\n> \n> -\t\tControlType type = static_cast<ControlType>(entry->type);\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\t\t  loadControlValue(values, entry->is_array, entry->count));\n>  \t}\n> \n>  \treturn ctrls;\n> --\n> 2.34.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9D6DCC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  3 Sep 2022 00:51:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E300F62003;\n\tSat,  3 Sep 2022 02:51:20 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E9F7162003\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  3 Sep 2022 02:51:18 +0200 (CEST)","from pyrite.rasen.tech (unknown [50.228.9.220])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 30AA86DD;\n\tSat,  3 Sep 2022 02:51:18 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1662166280;\n\tbh=vc9XulkFHpwnTo6G9SqyicBxBP4AzNWloAMQ57eM7AY=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=lm7WKnfm3AYWSwsHIfGnzIU3lcDxs/8DKDjLcUw20WKEid3t3z2uWUO8TDI5f2Dtz\n\tVxO0Fal53SCYqMo/TE9xCXmaXAvN/Hhf4AcqlJkvu0z1Smc783Hn9ByOAnqpouALBw\n\tQBm1XsubrXEn9el/UqJI29IBiNnzPpfRll1eY3qY+GrKKDLWj7fT0lZ0vm0W76gZo6\n\taXyVboIYmRvZfhMLGjjUBHDRx5P14L9fMFvc2B1bM+98Fq+7kVwMBEMHzbbOuAJ3aw\n\tBBawHyzpeyBZzdw0AYIYo+KI3qAKjjvebcus9XhdiaMfWH0q/BZvhcel0YX4tI8Tjx\n\tjikLhTFFytxwA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1662166278;\n\tbh=vc9XulkFHpwnTo6G9SqyicBxBP4AzNWloAMQ57eM7AY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=RuzWmRd0SspuxfWWb22v2pUC5dGy8a9rGzdy+aSs5SgceNMigQ6nkvBPWUNIf5Blp\n\tlgcJNPe4aXYppBY9W/PZpqd2WTxs8gjwHvq8s1JVOsPzBrPCe2/MGR3EOns5D8GxzS\n\tU6pOx2SnOpfoKUS/ckgUWPwuBkWZXmGqtfLnqkv4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"RuzWmRd0\"; dkim-atps=neutral","Date":"Fri, 2 Sep 2022 20:51:09 -0400","To":"Christian Rauch <Rauch.Christian@gmx.de>","Message-ID":"<20220903005109.GB113531@pyrite.rasen.tech>","References":"<20220902224939.111640-1-Rauch.Christian@gmx.de>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20220902224939.111640-1-Rauch.Christian@gmx.de>","Subject":"Re: [libcamera-devel] [PATCH v3 1/2] libcamera: serialiser:\n\tstore/load all ControlValue types","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>","From":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"paul.elder@ideasonboard.com","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]