[{"id":24969,"web_url":"https://patchwork.libcamera.org/comment/24969/","msgid":"<bb5cfc51-61a5-0f5e-7ed5-52f6f51cebd6@ideasonboard.com>","date":"2022-09-12T09:25:27","subject":"Re: [libcamera-devel] [PATCH v4 1/2] libcamera: control_serializer:\n\tstore/load all ControlValue types","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Christian\n\nThank you for the patch,\n\nOn 9/4/22 3:03 AM, 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 their type but\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> Fixes: https://bugs.libcamera.org/show_bug.cgi?id=137\n>\n> Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>\n> Tested-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\nAdding a unit test for this in \ntest/serialization/control_serialization.cpp might be good idea,\n\nbut for this patch,\n\nReviewed-by: Umang Jain <umang.jain@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 C752CC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Sep 2022 09:25:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2D52461F8C;\n\tMon, 12 Sep 2022 11:25:35 +0200 (CEST)","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 409846099F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Sep 2022 11:25:33 +0200 (CEST)","from [IPV6:2401:4900:1f3e:50f3:a89c:93ec:bcd7:8b90] (unknown\n\t[IPv6:2401:4900:1f3e:50f3:a89c:93ec:bcd7:8b90])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EE73759D;\n\tMon, 12 Sep 2022 11:25:31 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1662974735;\n\tbh=A8yuid9Qqq3re2xjLhe6RTREHfxJSOKs4D/YvrudldU=;\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:\n\tFrom;\n\tb=gt6WcjK9O/yWduxzBAiKdD18rQlk/2IGOfktR/SQk56adjng9JumUtR2bojSo1pXm\n\tiy4owfxC0UUIGaFhZ/ev5geZyV5MVnwVGvIseajfezVLKnB0oD6kubLSIwINCWWlnn\n\teETWPPW7Gj9Z4/KOl9MnS8Qj1YpM60Md4wuLIDKL6cuD8+EnlNATGI6oHB2iUMe76I\n\t0aPlYvHSHHq0Qm9eTXXsBAdaX9b57B1MN7rnb9wOpMN+8oWdiEVqcQxFgPUnjafSXm\n\tQjUBgONvIDFTN24ZQNowtkrI9QUaG3WsyDRwGR0T5mmQJ050g40Kra7gJv0sRPmCEa\n\t+ArxsZV8Usuxg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1662974732;\n\tbh=A8yuid9Qqq3re2xjLhe6RTREHfxJSOKs4D/YvrudldU=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=FCAvm0w7diRmfTBX31H2R6ej8JDfX9h0S85c4GGriuAFT8JmRvmmJorHZ++nflr6U\n\tz4L+cJu9Vo6AaGn1T01uaGcNY9q34jgH8eJ2cHapVOybYbrBQBAQRJJzJ836HifPm2\n\tHGmP1mepzJAz+a6sxsB8WKcQomTwyJjiGMKzweIY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"FCAvm0w7\"; dkim-atps=neutral","Message-ID":"<bb5cfc51-61a5-0f5e-7ed5-52f6f51cebd6@ideasonboard.com>","Date":"Mon, 12 Sep 2022 14:55:27 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.12.0","Content-Language":"en-US","To":"libcamera-devel@lists.libcamera.org,\n\tChristian Rauch <Rauch.Christian@gmx.de>","References":"<20220903213330.213117-1-Rauch.Christian@gmx.de>","In-Reply-To":"<20220903213330.213117-1-Rauch.Christian@gmx.de>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v4 1/2] libcamera: control_serializer:\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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]