From patchwork Thu Oct 30 16:58:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 24924 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 2E8D0C3336 for ; Thu, 30 Oct 2025 16:58:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A44ED609B3; Thu, 30 Oct 2025 17:58:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P+MLy6S9"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A2EF6097B for ; Thu, 30 Oct 2025 17:58:27 +0100 (CET) Received: from pb-laptop.local (185.221.140.239.nat.pool.zt.hu [185.221.140.239]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6957F4E5B; Thu, 30 Oct 2025 17:56:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761843397; bh=9QB9kHA1zUZ+FIzDCzw0hB32seKsXL9zKorcZNi8fBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P+MLy6S9al4FoM80e5QVxRlUYvFbjqP8I7jWKfpttBnyr8wHPvGZ7wc/EUgxP/VXY L5ucpf6oUlyI1/8IuD6pXDO+lFicYldtIvSlGTp53XcM7JzJJy/k4XzjYSKhHmfsm0 DLghoA8C7CSjwrPaFU/7AA2ztpnGMpNO/LfXEv/I= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Paul Elder Subject: [RFC PATCH v3 19/22] libcamera: pipeline_handler: Inject "debug" metadata Date: Thu, 30 Oct 2025 17:58:13 +0100 Message-ID: <20251030165816.1095180-20-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251030165816.1095180-1-barnabas.pocze@ideasonboard.com> References: <20251030165816.1095180-1-barnabas.pocze@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" Inject all metadata controls in the "debug" namespace into the metadata plan of each camera so that they can be used seamlessly. Dynamically sized array-like controls have a hard-coded size of 32 elements. Additionally, a new type is added for inspecting properties of a control type at runtime since that was not available previously. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- include/libcamera/internal/controls.h | 39 +++++++++++++++++++++++ src/libcamera/controls.cpp | 2 +- src/libcamera/pipeline_handler.cpp | 45 +++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 include/libcamera/internal/controls.h diff --git a/include/libcamera/internal/controls.h b/include/libcamera/internal/controls.h new file mode 100644 index 0000000000..be3f93e43c --- /dev/null +++ b/include/libcamera/internal/controls.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2025, Ideas on Board Oy + */ + +#pragma once + +#include + +namespace libcamera::controls::details { + +struct TypeInfo { + std::size_t size = 0; + std::size_t alignment = 0; + + explicit operator bool() const { return alignment != 0; } + + static constexpr TypeInfo get(ControlType t) + { + switch (t) { + case ControlTypeNone: return {}; + case ControlTypeBool: return { sizeof(bool), alignof(bool) }; + case ControlTypeByte: return { sizeof(uint8_t), alignof(uint8_t) }; + case ControlTypeUnsigned16: return { sizeof(uint16_t), alignof(uint16_t) }; + case ControlTypeUnsigned32: return { sizeof(uint32_t), alignof(uint32_t) }; + case ControlTypeInteger32: return { sizeof(int32_t), alignof(int32_t) }; + case ControlTypeInteger64: return { sizeof(int64_t), alignof(int64_t) }; + case ControlTypeFloat: return { sizeof(float), alignof(float) }; + case ControlTypeString: return { sizeof(char), alignof(char) }; + case ControlTypeRectangle: return { sizeof(Rectangle), alignof(Rectangle) }; + case ControlTypeSize: return { sizeof(Size), alignof(Size) }; + case ControlTypePoint: return { sizeof(Point), alignof(Point) }; + } + + return {}; + } +}; + +} /* libcamera::controls::details */ diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 222030c434..d51e6c882f 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -17,7 +17,7 @@ #include "libcamera/internal/control_validator.h" /** - * \file controls.h + * \file libcamera/controls.h * \brief Framework to manage controls related to an object * * A control is a mean to govern or influence the operation of an object, and in diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index de98a93306..a3a37de873 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -16,11 +16,13 @@ #include #include +#include #include #include #include "libcamera/internal/camera.h" #include "libcamera/internal/camera_manager.h" +#include "libcamera/internal/controls.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/request.h" @@ -755,6 +757,47 @@ std::string PipelineHandler::configurationFile(const std::string &subdir, return std::string(); } +namespace { + +/* + * This is kind of hack. The metadata controls in the "debug" namespace + * are forcefully injected into each Camera's MetadataListPlan so that + * they work seamlessly without any additional setup. + * + * The dynamically-sized array-like controls have a maximum capacity + * determined by the magic number below. + */ +void extendMetadataPlanWithDebugMetadata(MetadataListPlan& mlp) +{ + constexpr std::size_t kDynamicArrayCapacity = 32; + + for (const auto &[id, ctrl] : controls::controls) { + if (!ctrl->isOutput()) + continue; + if (ctrl->vendor() != "debug") + continue; + if (mlp.get(id)) + continue; + + std::size_t count = ctrl->size(); + if (count == 0) /* Non-array controls have a static size of 0. */ + count = 1; + else if (ctrl->size() == libcamera::dynamic_extent) + count = kDynamicArrayCapacity; + + const auto info = controls::details::TypeInfo::get(ctrl->type()); + if (!info) + continue; + + [[maybe_unused]] bool ok = mlp.set(id, + info.size, info.alignment, + count, ctrl->type(), ctrl->isArray()); + ASSERT(ok); + } +} + +} /* namespace */ + /** * \brief Register a camera to the camera manager and pipeline handler * \param[in] camera The camera to be added @@ -800,6 +843,8 @@ void PipelineHandler::registerCamera(std::shared_ptr camera) Camera::Private *data = camera->_d(); data->properties_.set(properties::SystemDevices, devnums); + extendMetadataPlanWithDebugMetadata(data->metadataPlan_); + manager_->_d()->addCamera(std::move(camera)); }