Show a patch.

GET /api/1.1/patches/21473/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 21473,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21473/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21473/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20241002161933.247091-3-stefan.klug@ideasonboard.com>",
    "date": "2024-10-02T16:19:20",
    "name": "[v1,2/8] libcamera: Add a DebugMetadata helper",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f75f7749a6d0fbc7de7a5da010b14da2415576c7",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21473/mbox/",
    "series": [
        {
            "id": 4648,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4648/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4648",
            "date": "2024-10-02T16:19:18",
            "name": "Add support for IPA debugging metadata",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4648/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21473/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21473/checks/",
    "tags": {},
    "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 1AEF2BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  2 Oct 2024 16:20:19 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B485363527;\n\tWed,  2 Oct 2024 18:20:18 +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 EB1A663522\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  2 Oct 2024 18:20:16 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:b246:b33f:c662:8ae1])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5FC661011;\n\tWed,  2 Oct 2024 18:18:43 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"CfQxDIek\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727885924;\n\tbh=y3BgbDK0QT8E2RlKsd2t4gyUlEbvDDc5/P43dhofsNU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=CfQxDIekzXp3wtqlACvenAiC9LE5b27ZCAY0jiRqKRrCfFaAmWCfxo7gqgQseI0Lv\n\tKbPq/6B4vaOdz9nzyB18lzCvSAfnUD9ccr4dPfoXEJnjOGFtrFRfgd01XWZbYzRKpT\n\tMrWVEvYJ3XtEpLolDsE/Z7BpXS9YsZxQOQXZVg+c=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v1 2/8] libcamera: Add a DebugMetadata helper",
        "Date": "Wed,  2 Oct 2024 18:19:20 +0200",
        "Message-ID": "<20241002161933.247091-3-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20241002161933.247091-1-stefan.klug@ideasonboard.com>",
        "References": "<20241002161933.247091-1-stefan.klug@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Debug metadata often occurs in places where the metadata control list is\nnot available e.g. in queueRequest() or processStatsBuffer() or even in\na class far away from the metadata handling code. It is therefore\ndifficult to add debug metadata without adding lot's of boilerplate\ncode. This can be mitigated by recording the metadata and forwarding it\nto an upstream helper or the metadata control list when they become\navailable. Add such a helper.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n include/libcamera/internal/debug_controls.h |  52 +++++++\n include/libcamera/internal/meson.build      |   1 +\n src/libcamera/control_ids_core.yaml         |   6 +\n src/libcamera/debug_controls.cpp            | 144 ++++++++++++++++++++\n src/libcamera/meson.build                   |   1 +\n 5 files changed, 204 insertions(+)\n create mode 100644 include/libcamera/internal/debug_controls.h\n create mode 100644 src/libcamera/debug_controls.cpp",
    "diff": "diff --git a/include/libcamera/internal/debug_controls.h b/include/libcamera/internal/debug_controls.h\nnew file mode 100644\nindex 000000000000..d95c03e1db1f\n--- /dev/null\n+++ b/include/libcamera/internal/debug_controls.h\n@@ -0,0 +1,52 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas on Board Oy\n+ *\n+ * Debug metadata helpers\n+ */\n+\n+#pragma once\n+\n+#include <libcamera/control_ids.h>\n+\n+namespace libcamera {\n+\n+class DebugMetadata\n+{\n+public:\n+\tDebugMetadata() = default;\n+\n+\tvoid checkForEnable(const ControlList &controls);\n+\tvoid enable(bool enable = true);\n+\tvoid assignUpstream(DebugMetadata *upstream);\n+\tvoid assignControlList(ControlList *list);\n+\n+\ttemplate<typename T, typename V>\n+\tvoid set(const Control<T> &ctrl, const V &value)\n+\t{\n+\t\tif (upstream_) {\n+\t\t\tupstream_->set<T, V>(ctrl, value);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tif (!enabled_)\n+\t\t\treturn;\n+\n+\t\tif (list_) {\n+\t\t\tlist_->set<T, V>(ctrl, value);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tcache_.set<T, V>(ctrl, value);\n+\t}\n+\n+\tvoid set(unsigned int id, const ControlValue &value);\n+\n+private:\n+\tbool enabled_ = false;\n+\tControlList *list_ = nullptr;\n+\tDebugMetadata *upstream_ = nullptr;\n+\tControlList cache_;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 1c5eef9cab80..1dddcd50c90b 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -14,6 +14,7 @@ libcamera_internal_headers = files([\n     'control_serializer.h',\n     'control_validator.h',\n     'converter.h',\n+    'debug_controls.h',\n     'delayed_controls.h',\n     'device_enumerator.h',\n     'device_enumerator_sysfs.h',\ndiff --git a/src/libcamera/control_ids_core.yaml b/src/libcamera/control_ids_core.yaml\nindex 1b1bd9507d25..103bcb593c4a 100644\n--- a/src/libcamera/control_ids_core.yaml\n+++ b/src/libcamera/control_ids_core.yaml\n@@ -967,5 +967,11 @@ controls:\n \n         The default gamma value must be 2.2 which closely mimics sRGB gamma.\n         Note that this is camera gamma, so it is applied as 1.0/gamma.\n+        \n+  - DebugMetadataEnable:\n+      type: bool\n+      description: |\n+        Enable or disable the debug metadata.\n+\n \n ...\ndiff --git a/src/libcamera/debug_controls.cpp b/src/libcamera/debug_controls.cpp\nnew file mode 100644\nindex 000000000000..11a92a6b5871\n--- /dev/null\n+++ b/src/libcamera/debug_controls.cpp\n@@ -0,0 +1,144 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas on Board Oy.\n+ *\n+ * Helper to easily record debug metadata inside libcamera.\n+ */\n+\n+#include \"libcamera/internal/debug_controls.h\"\n+\n+namespace libcamera {\n+\n+/**\n+ * \\file debug_controls.h\n+ * \\brief Helper to easily record debug metadata inside libcamera\n+ */\n+\n+/**\n+ * \\class DebugMetadata\n+ * \\brief Helper to record metadata for later use\n+ *\n+ * When one wants to record debug metadata, the metadata list is often not\n+ * directly available (either because we are inside process() of an IPA or\n+ * because we are in a closed module). This class allows to record the data and\n+ * at a later point in time forward it either to another DebugMetadata instance\n+ * or to a ControlList.\n+ */\n+\n+/**\n+ * \\fn DebugMetadata::checkForEnable\n+ * \\brief Check for DebugMetadataEnable in the supplied ControlList\n+ * \\param[in] controls The supplied ControlList\n+ *\n+ * Looks for controls::DebugMetadataEnable and enables or disables debug\n+ * metadata handling accordingly.\n+ */\n+void DebugMetadata::checkForEnable(const ControlList &controls)\n+{\n+\tconst auto &ctrl = controls.get(controls::DebugMetadataEnable);\n+\tif (ctrl)\n+\t\tenable(*ctrl);\n+}\n+\n+/**\n+ * \\fn DebugMetadata::enable\n+ * \\brief Enables or disabled metadata handling\n+ * \\param[in] enable The enable state\n+ *\n+ * Enables or disables metadata handling according to \\a enable. When enable is\n+ * false, the cache gets cleared and no further metadata is recorded.\n+ */\n+void DebugMetadata::enable(bool enable)\n+{\n+\tenabled_ = enable;\n+\tif (!enabled_)\n+\t\tcache_.clear();\n+}\n+\n+/**\n+ * \\fn DebugMetadata::assignUpstream\n+ * \\brief Assign an upstream metadata handler\n+ * \\param[in] upstream Pointer to the upstream handler\n+ *\n+ * When a upstream gets set, the cache is copies to that list and all further\n+ * calls to DebugMetadata::set are forwarded to that list.\n+ *\n+ * The upstream can be reset by passing a nullptr.\n+ */\n+void DebugMetadata::assignUpstream(DebugMetadata *upstream)\n+{\n+\tupstream_ = upstream;\n+\n+\tif (!upstream_)\n+\t\treturn;\n+\n+\tfor (const auto &ctrl : cache_)\n+\t\tupstream_->set(ctrl.first, ctrl.second);\n+\n+\tcache_.clear();\n+}\n+\n+/**\n+ * \\fn DebugMetadata::assignControlList\n+ * \\brief Assign a control list\n+ * \\param[in] list Pointer to the list\n+ *\n+ * When a list gets set, the cache is copies to that list and all further calls\n+ * to DebugMetadata::set are forwarded to that list.\n+ *\n+ * The upstream can be reset by passing a nullptr.\n+ */\n+void DebugMetadata::assignControlList(ControlList *list)\n+{\n+\tlist_ = list;\n+\n+\tif (list_) {\n+\t\tlist_->merge(cache_);\n+\t\tcache_.clear();\n+\t}\n+}\n+\n+/**\n+ * \\fn DebugMetadata::set(const Control<T> &ctrl, const V &value)\n+ * \\brief Set a value\n+ * \\param[in] ctrl The ctrl to set\n+ * \\param[in] value The control value\n+ *\n+ * Sets the debug metadata for ctrl to value \\a value. If an upstream or a\n+ * control list is set, the value gets passed there (upstream takes precedence).\n+ * Otherwise the value is cached until one of them gets assigned.\n+ *\n+ * When the instance is disabled and upstream is not set, the value gets dropped.\n+ */\n+\n+/**\n+ * \\fn DebugMetadata::set(unsigned int id, const ControlValue &value)\n+ * \\brief Set a value\n+ * \\param[in] id The id of the control\n+ * \\param[in] value The control value\n+ *\n+ * Sets the debug metadata to value \\a value. If an upstream or a control list\n+ * is set, the value gets passed there (upstream takes precedence).\n+ * Otherwise the value is cached until one of them gets assigned.\n+ *\n+ * When the instance is disabled and upstream is not set, the value gets dropped.\n+ */\n+void DebugMetadata::set(unsigned int id, const ControlValue &value)\n+{\n+\tif (upstream_) {\n+\t\tupstream_->set(id, value);\n+\t\treturn;\n+\t}\n+\n+\tif (!enabled_)\n+\t\treturn;\n+\n+\tif (list_) {\n+\t\tlist_->set(id, value);\n+\t\treturn;\n+\t}\n+\n+\tcache_.set(id, value);\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex aa9ab0291854..f7b5ee8dcc34 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -25,6 +25,7 @@ libcamera_internal_sources = files([\n     'control_validator.cpp',\n     'converter.cpp',\n     'delayed_controls.cpp',\n+    'debug_controls.cpp',\n     'device_enumerator.cpp',\n     'device_enumerator_sysfs.cpp',\n     'dma_buf_allocator.cpp',\n",
    "prefixes": [
        "v1",
        "2/8"
    ]
}