From patchwork Sat Sep 3 21:33:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Rauch X-Patchwork-Id: 17292 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id F2960C327D for ; Sat, 3 Sep 2022 21:33:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E9FB862046; Sat, 3 Sep 2022 23:33:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662240815; bh=3CL1St6IP9I3ecDiVWoYhncZQLbjo5vZVQCDu4LIk0I=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=I3Y6XyeRamgZhLnq++jD9AFKNVtapMK3R58cwUJe+9SdDmSvwSw8E8DNMmG0Wl8QX /iOfw/CEMxpTEW9HXOrf2P+fwOsTVfDrL2nLLKPxF5Lgc3L6xuFWS99lcCYMNgbLn1 OvlEyOqGg1vYQFbOTBPmzdWEVEcumcoLzAGX3CWOF3qxgGFbxQ78IHi69PK/ClVqlL BSJAJNTNBOoqEaLZFJJcNBnIXnwTBwGjDro5lEQAkxzf1FW9JSxeSBWJ60CP8LGH+C tVcQsNWpDn18RxcChTPF18Lh3eT/+LrU+cv0kjKP5rD47y7EGPe9ZykpkspSERqhCw OI++gtj4+yJtw== Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 632DD62033 for ; Sat, 3 Sep 2022 23:33:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=gmx.net header.i=@gmx.net header.b="YkvlKVxy"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662240812; bh=3CL1St6IP9I3ecDiVWoYhncZQLbjo5vZVQCDu4LIk0I=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=YkvlKVxy/2aChGC1sC4tvOfB35eu++qjmuTrSEEbUrXa5mxycmFKSljGGgH9huoWR eAGGvtJcqnXBvfaKfEYG79qSXKuGWanlh6VitCDGMnnXWAS5f9+ILuU4J4rk2tlW3X b/UI8GhwGgCBP4m+rqqWS5w2NKhrxJcgv3D+sOcM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from voyager ([88.152.184.103]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N3KTy-1pTT941eHi-010PJv; Sat, 03 Sep 2022 23:33:32 +0200 To: libcamera-devel@lists.libcamera.org Date: Sat, 3 Sep 2022 23:33:29 +0200 Message-Id: <20220903213330.213117-1-Rauch.Christian@gmx.de> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:8lGgn5vhXtyU7KdwHQV9YJPEcPJKtP5SWTT5VoemkCsfoKel7YA xoy0CFkIyzAeuZNLojI7NdhxQgALr0y89JQNWfe3mHIrq7B45MmGP0srdE1cmeGdIcXS5v3 T4moPxGaWXUNSwKNPiAjoWRBCbOLm96RWTjKrRW+HKFU/dzd9olb0ywWjmJvzjFyYelwkYU 6Q3hQidoxvWMhIT9t1Rww== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:lL6jft9njFg=:zrk8kW1poATsr5sOjHtwZT AOHyznCo1RLHYHk3LI8C50y/QrDZDsJtT8ca4L1HWfxrzdozpw6RSYxCJTjhAE8YsbtQWYy26 v/XTfoP9WPF3vnuyw3vwk0jiV6hi85aJ9mCbAxxwp6jPLjp1l2L7Jru8ZsGJjLjG/WI/tXH6P w8qwQgcLa05MkPVFuNpjKt3J12upW0kUc+et3zbfouzdtmFJ3Yp6pAkVdkJ3FCFkmTdkgQola p6kDIT1+3yBEXhLtynFRATmQ3NbTgrxkXMZ6d8ohKtMorlVkO147aZeAqXoEibS7kYCpPeecv fCaKjw2V4FMNJsAOiF5Q4gkp7n6cibefAXdIsg+pJCmKu49QkG4Cg2i5hN3G2d3VCO83UfP2o yLOGPw4bVAHLOkocImm/OzzMV32LPF5A//wMhUte9rwhhzvo6LDIGz4b2BtoBOiBTk8DgqXcw kgHWd1xC2zCTq68B2pbBQ1aH8oXdh++/sfOFbIsN/2HRIJRjeGo8pIXACp54u9mPGuFM2LMWi o9VeQ8Ab5Yfzr6rk0jhuESxuJ1uprlDG27joS/GK608a1s5q6xSz4kCzjg76JVa054cT3NTb8 M1eUmHlB/5cefpbGtijEnZMUPBUXMZ9LXTQ7qxAjjRXG+yEnaYAiQ//41hVxwAYC0F/pC9aSx efO4LzZAj6DBCNrmu8/wAFSy1RqDgX6L37xNf8fNQ1ptnIb6ntmUCSwypwyTqwNrLvUC85a7M lZ1zkV4r/+p2kIGPuKjyl1SBWSTWQxhw4C+m5Dts6HB0WZLV6WH5qsNMkPzQXGb2JoHTHKnZY SzAwzZKKU/i/pUmZZvAxG1dhDhFh0NeKvHFWLBruC5Zux2ik/CKFZHftlT+X843O6aXbDdiF3 kIkjUtAd8T+CZLhQc1V8y4eWYQwBsbS9AGb8cyvGBYTm9fvA44O0nOLQM1bgKhcHxZqFA7gIQ 4lajH7wCJM6xcVNktXmpOWy/l1u8SG4vwGQ31AHpJxvTh59jDaXEuOBTNzVmolrFZldoyNmeZ CAA7leUeMSZJ23McxBGNl6v4BKUzNGmEbj2eEb5QVMiEipgyrgg+zyZvQ5xYtUx7IHDama6dH uOX/lUcILUcaOkdsydQUOVokFGnBpXtijnged1bMazh7XJ8txzfnMXAnwYHq341Qmpoel+JG+ 1/F9/QO4LsiDjglbzVcFPPfLRp Subject: [libcamera-devel] [PATCH v4 1/2] libcamera: control_serializer: store/load all ControlValue types 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-Patchwork-Original-From: Christian Rauch via libcamera-devel From: Christian Rauch Reply-To: Christian Rauch Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The min/max/def ControlValue of a ControlInfo can take arbitrary types that are different from each other and different from the ControlId type. The serialiser serialises these ControlValue separately by their type but does not store the type. The deserialiser assumes that ControlValue types match the ControlId type. If this is not the case, deserialisation will try to deserialise values of the wrong type. Fix this by serialising each of the min/max/def ControlValue's ControlType and storing it just before the serialised ControlValue. Fixes: https://bugs.libcamera.org/show_bug.cgi?id=137 Signed-off-by: Christian Rauch Tested-by: Paul Elder Reviewed-by: Paul Elder Reviewed-by: Umang Jain --- .../libcamera/internal/control_serializer.h | 4 +-- src/libcamera/control_serializer.cpp | 28 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) -- 2.34.1 diff --git a/include/libcamera/internal/control_serializer.h b/include/libcamera/internal/control_serializer.h index 99e57fee..a38ca6b0 100644 --- a/include/libcamera/internal/control_serializer.h +++ b/include/libcamera/internal/control_serializer.h @@ -47,9 +47,9 @@ private: static void store(const ControlValue &value, ByteStreamBuffer &buffer); static void store(const ControlInfo &info, ByteStreamBuffer &buffer); - ControlValue loadControlValue(ControlType type, ByteStreamBuffer &buffer, + ControlValue loadControlValue(ByteStreamBuffer &buffer, bool isArray = false, unsigned int count = 1); - ControlInfo loadControlInfo(ControlType type, ByteStreamBuffer &buffer); + ControlInfo loadControlInfo(ByteStreamBuffer &buffer); unsigned int serial_; unsigned int serialSeed_; diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp index e87d2362..0cf719bd 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -144,7 +144,7 @@ void ControlSerializer::reset() size_t ControlSerializer::binarySize(const ControlValue &value) { - return value.data().size_bytes(); + return sizeof(ControlType) + value.data().size_bytes(); } size_t ControlSerializer::binarySize(const ControlInfo &info) @@ -195,6 +195,8 @@ size_t ControlSerializer::binarySize(const ControlList &list) void ControlSerializer::store(const ControlValue &value, ByteStreamBuffer &buffer) { + const ControlType type = value.type(); + buffer.write(&type); buffer.write(value.data()); } @@ -379,11 +381,13 @@ int ControlSerializer::serialize(const ControlList &list, return 0; } -ControlValue ControlSerializer::loadControlValue(ControlType type, - ByteStreamBuffer &buffer, +ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, bool isArray, unsigned int count) { + ControlType type; + buffer.read(&type); + ControlValue value; value.reserve(type, isArray, count); @@ -392,15 +396,11 @@ ControlValue ControlSerializer::loadControlValue(ControlType type, return value; } -ControlInfo ControlSerializer::loadControlInfo(ControlType type, - ByteStreamBuffer &b) +ControlInfo ControlSerializer::loadControlInfo(ByteStreamBuffer &b) { - if (type == ControlTypeString) - type = ControlTypeInteger32; - - ControlValue min = loadControlValue(type, b); - ControlValue max = loadControlValue(type, b); - ControlValue def = loadControlValue(type, b); + ControlValue min = loadControlValue(b); + ControlValue max = loadControlValue(b); + ControlValue def = loadControlValue(b); return ControlInfo(min, max, def); } @@ -513,7 +513,7 @@ ControlInfoMap ControlSerializer::deserialize(ByteStreamBuffer & } /* Create and store the ControlInfo. */ - ctrls.emplace(controlId, loadControlInfo(type, values)); + ctrls.emplace(controlId, loadControlInfo(values)); } /* @@ -624,10 +624,8 @@ ControlList ControlSerializer::deserialize(ByteStreamBuffer &buffer return {}; } - ControlType type = static_cast(entry->type); ctrls.set(entry->id, - loadControlValue(type, values, entry->is_array, - entry->count)); + loadControlValue(values, entry->is_array, entry->count)); } return ctrls;