From patchwork Fri Oct 10 11:33:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 24579 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 9915CBE080 for ; Fri, 10 Oct 2025 11:33:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C77EB6B60E; Fri, 10 Oct 2025 13:33:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eD3PojqB"; dkim-atps=neutral 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 877E66B599 for ; Fri, 10 Oct 2025 13:33:49 +0200 (CEST) Received: from neptunite.hamster-moth.ts.net (unknown [IPv6:2404:7a81:160:2100:fa2a:8f34:95fc:6e6b]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CE8C9EFE; Fri, 10 Oct 2025 13:32:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1760095934; bh=sehZUsouTiEImz9m/s8rG0Jl2JMH2HMmnQHTPis7UHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eD3PojqBp38YVIsni4nyWcKm2Zdipv4lz6Eoqc05LaD58Q3ICalEUdTr+BP9rTbiR rWOlC1bX8lZ58PCOOgJWL6wS04etmB6N49fS0nLUTtmZvFdIcxE2iJdPGqMg3pCG6C qoK7O9unXYzhKLGvECHQKhePxbzJ5petCGx4pTuE= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , barnabas.pocze@ideasonboard.com Subject: [PATCH v3 1/2] libcamera: control_serializer: Add array info to serialized ControlValue Date: Fri, 10 Oct 2025 20:33:29 +0900 Message-ID: <20251010113332.3030598-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20251010113332.3030598-1-paul.elder@ideasonboard.com> References: <20251010113332.3030598-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Array controls (eg. ColourCorrectionMatrix, FrameDurationLimits, ColourGains) are serialized properly by the ControlSerializer, but are not deserialized properly. This is because their arrayness and size are not considered during deserialization. Fix this by adding arrayness and size to the serialized form of all ControlValues. This is achieved by adding the already-existing struct ipa_control_value_entry to the serialized form of ControlInfoMap to contain all the metadata associated with each ControlValue in the min/max/def of each ControlInfo. The issue was not noticed before as the default value of the ControlInfo of other array controls had been set to scalar values similar to min/max, and ColourCorrectionMatrix was the first control to properly define a non-scalar default value. Other array controls that define a scalar default value need to be fixed to define a properly sized default ControlInfo value. Bug: https://bugs.libcamera.org/show_bug.cgi?id=285 Signed-off-by: Paul Elder --- Changes in v3: - instead of adding an extra header to store isArray and numElements like in v2, just reuse struct ipa_control_value_entry, and add these entries to the serialized form of ControlInfoMap to store information for each of the three ControlValues that make of min and max and def in ControlInfoMap Changes in v2: - make it so that the *serialized form* of ControlValue includes arrayness and size instead - Compared to v1, this ties the arrayness and size information to ControlValue instead of ControlId, which as a side effect allows us to support scalar and array min/max values, not just def values. This also gives us support for variable-length arrays --- .../libcamera/internal/control_serializer.h | 6 +- src/libcamera/control_serializer.cpp | 76 +++++++++++++------ 2 files changed, 58 insertions(+), 24 deletions(-) diff --git a/include/libcamera/internal/control_serializer.h b/include/libcamera/internal/control_serializer.h index 8a63ae44a13e..755ee68e1efe 100644 --- a/include/libcamera/internal/control_serializer.h +++ b/include/libcamera/internal/control_serializer.h @@ -47,9 +47,13 @@ private: static void store(const ControlValue &value, ByteStreamBuffer &buffer); static void store(const ControlInfo &info, ByteStreamBuffer &buffer); + void populateControlValueEntry(struct ipa_control_value_entry &entry, + unsigned int id, + const ControlValue &value, + uint32_t offset); + ControlValue loadControlValue(ByteStreamBuffer &buffer, bool isArray = false, unsigned int count = 1); - 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 050f8512bd52..f15050901412 100644 --- a/src/libcamera/control_serializer.cpp +++ b/src/libcamera/control_serializer.cpp @@ -164,7 +164,8 @@ size_t ControlSerializer::binarySize(const ControlInfo &info) size_t ControlSerializer::binarySize(const ControlInfoMap &infoMap) { size_t size = sizeof(struct ipa_controls_header) - + infoMap.size() * sizeof(struct ipa_control_info_entry); + + infoMap.size() * (sizeof(struct ipa_control_info_entry) + + 3 * sizeof(struct ipa_control_value_entry)); for (const auto &ctrl : infoMap) size += binarySize(ctrl.second); @@ -197,14 +198,20 @@ void ControlSerializer::store(const ControlValue &value, { const ControlType type = value.type(); buffer.write(&type); + buffer.write(value.data()); } -void ControlSerializer::store(const ControlInfo &info, ByteStreamBuffer &buffer) +void ControlSerializer::populateControlValueEntry(struct ipa_control_value_entry &entry, + unsigned int id, + const ControlValue &value, + uint32_t offset) { - store(info.min(), buffer); - store(info.max(), buffer); - store(info.def(), buffer); + entry.id = id; + entry.type = value.type(); + entry.is_array = value.isArray(); + entry.count = value.numElements(); + entry.offset = offset; } /** @@ -232,7 +239,8 @@ int ControlSerializer::serialize(const ControlInfoMap &infoMap, /* Compute entries and data required sizes. */ size_t entriesSize = infoMap.size() - * sizeof(struct ipa_control_info_entry); + * (sizeof(struct ipa_control_info_entry) + + 3 * sizeof(struct ipa_control_value_entry)); size_t valuesSize = 0; for (const auto &ctrl : infoMap) valuesSize += binarySize(ctrl.second); @@ -284,7 +292,29 @@ int ControlSerializer::serialize(const ControlInfoMap &infoMap, entry.direction = static_cast(id->direction()); entries.write(&entry); - store(info, values); + /* + * Write the metadata for the ControlValue entries as well, + * since we need type, isArray, and numElements information for + * min/max/def of the ControlInfo. Doing it this way is the + * least intrusive in terms of changing the structs in + * ipa_controls.h + */ + struct ipa_control_value_entry valueEntry; + + populateControlValueEntry(valueEntry, id->id(), info.min(), + values.offset()); + entries.write(&valueEntry); + store(info.min(), values); + + populateControlValueEntry(valueEntry, id->id(), info.max(), + values.offset()); + entries.write(&valueEntry); + store(info.max(), values); + + populateControlValueEntry(valueEntry, id->id(), info.def(), + values.offset()); + entries.write(&valueEntry); + store(info.def(), values); } if (buffer.overflow()) @@ -366,11 +396,7 @@ int ControlSerializer::serialize(const ControlList &list, const ControlValue &value = ctrl.second; struct ipa_control_value_entry entry; - entry.id = id; - entry.type = value.type(); - entry.is_array = value.isArray(); - entry.count = value.numElements(); - entry.offset = values.offset(); + populateControlValueEntry(entry, id, value, values.offset()); entries.write(&entry); store(value, values); @@ -397,15 +423,6 @@ ControlValue ControlSerializer::loadControlValue(ByteStreamBuffer &buffer, return value; } -ControlInfo ControlSerializer::loadControlInfo(ByteStreamBuffer &b) -{ - ControlValue min = loadControlValue(b); - ControlValue max = loadControlValue(b); - ControlValue def = loadControlValue(b); - - return ControlInfo(min, max, def); -} - /** * \fn template T ControlSerializer::deserialize(ByteStreamBuffer &buffer) * \brief Deserialize an object from a binary buffer @@ -485,7 +502,13 @@ ControlInfoMap ControlSerializer::deserialize(ByteStreamBuffer & for (unsigned int i = 0; i < hdr->entries; ++i) { const struct ipa_control_info_entry *entry = entries.read(); - if (!entry) { + const struct ipa_control_value_entry *min_entry = + entries.read(); + const struct ipa_control_value_entry *max_entry = + entries.read(); + const struct ipa_control_value_entry *def_entry = + entries.read(); + if (!entry || !min_entry || !max_entry || !def_entry) { LOG(Serializer, Error) << "Out of data"; return {}; } @@ -518,8 +541,15 @@ ControlInfoMap ControlSerializer::deserialize(ByteStreamBuffer & return {}; } + ControlValue min = loadControlValue(values, min_entry->is_array, + min_entry->count); + ControlValue max = loadControlValue(values, max_entry->is_array, + max_entry->count); + ControlValue def = loadControlValue(values, def_entry->is_array, + def_entry->count); + /* Create and store the ControlInfo. */ - ctrls.emplace(controlId, loadControlInfo(values)); + ctrls.emplace(controlId, ControlInfo(min, max, def)); } /*