Show a patch.

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

{
    "id": 16361,
    "url": "https://patchwork.libcamera.org/api/patches/16361/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16361/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20220624003004.31600-1-laurent.pinchart@ideasonboard.com>",
    "date": "2022-06-24T00:30:04",
    "name": "[libcamera-devel,v4.1,03/12] ipa: libipa: algorithm: Add an algorithm registration mechanism",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "e2cabf98d02508b7ca5d16c583b7cbfa63ff2a6d",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16361/mbox/",
    "series": [
        {
            "id": 3216,
            "url": "https://patchwork.libcamera.org/api/series/3216/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3216",
            "date": "2022-06-24T00:30:04",
            "name": null,
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3216/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16361/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16361/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 3BB29BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Jun 2022 00:30:26 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4208E65635;\n\tFri, 24 Jun 2022 02:30:25 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D832261FB2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jun 2022 02:30:23 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F256CDD;\n\tFri, 24 Jun 2022 02:30:22 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656030625;\n\tbh=40pLfsGo7v+rc0VPtPFVqcUAaJsnI0nprqpJGSG5WKM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=aaDgYZURuQcTWZaSV821R3ylzac96nnVvzQUEZ2a5f8OX9TFkEjm5rhrO2kMyD2G9\n\t4akySgY7ytMuqMILGsEz5/T2nr38oc2TwCaI/xDbSDxlwMljvr4bjiK4YIYjad+XeM\n\tZql7MwIZkiIyw+0BwIPqNVdHv8UA0WItdQRXG0fo5z8HuFQit95Juz4XKCRc2mglBf\n\tDuefDnsAOYTCHJptBkcsDS5qExe4XD1YmmMrcd/bhh2r/5i2Xl7PE5fP3pGAJWC5qC\n\tyFB+NH6mWj0YYtT7sdKZNXwtKtUQ6LJ9JjQSHP/5Xvyo+xe7w5Oc7B0dK7rWMlyXtu\n\tIMrQao/DPppLQ==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1656030623;\n\tbh=40pLfsGo7v+rc0VPtPFVqcUAaJsnI0nprqpJGSG5WKM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=b8G15sk8Kw2eX3fRAhZfLZSL5b+LYaavOidBxTTKXcmnYMRWUPRAhvDq8ak8qrg7I\n\tiWvT+Qov/SbbXu+SAKkEDuE78V4U0EqDIiIpcyIUQGjHfvDNwpyTQkPepuLLzop4kO\n\t7PvclfQixMES/TPHtEZVOeRbCPcSkWx/++Xa0ucw="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"b8G15sk8\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 24 Jun 2022 03:30:04 +0300",
        "Message-Id": "<20220624003004.31600-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220620014305.26778-4-laurent.pinchart@ideasonboard.com>",
        "References": "<20220620014305.26778-4-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4.1 03/12] ipa: libipa: algorithm: Add an\n\talgorithm registration mechanism",
        "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": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "In order to allow dynamic instantiation of algorithms based on tuning\ndata files, add a mechanism to register algorithms with the IPA module.\nThe implementation relies on an AlgorithmFactory class and a\nregistration macro, similar to the pipeline handler registration\nmechanism. The main difference is that the algorithm registration and\ninstantiation are implemented in the Module class instead of the\nAlgorithmFactory class, making the factory an internal implementation\ndetail.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nChanges since v4:\n\n- Simplify the REGISTER_IPA_ALGORITHM() macro by making more use of\n  templates\n- Add name argument to the REGISTER_IPA_ALGORITHM() macro\n---\n\nThe first changed compared to v4 is an implementation detail, and the\nsecond change is significant. It decouples the algorithm name from the\nclass name, allowing identifications of algorithms with strings that\nwouldn't be valid C++ symbol names. For instance, the Raspberry Pi IPA\nnaming scheme (\"rpi.${algo}\") can now be supported.\n\n Documentation/Doxyfile.in    |  1 +\n src/ipa/libipa/algorithm.cpp | 48 ++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/algorithm.h   | 47 ++++++++++++++++++++++++++++++++++-\n src/ipa/libipa/module.cpp    | 24 ++++++++++++++++++\n src/ipa/libipa/module.h      | 33 +++++++++++++++++++++++++\n 5 files changed, 152 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\nindex 3d20e3ca460f..4bb83d50c6c9 100644\n--- a/Documentation/Doxyfile.in\n+++ b/Documentation/Doxyfile.in\n@@ -886,6 +886,7 @@ EXCLUDE_SYMBOLS        = libcamera::BoundMethodArgs \\\n                          libcamera::BoundMethodStatic \\\n                          libcamera::CameraManager::Private \\\n                          libcamera::SignalBase \\\n+                         libcamera::ipa::AlgorithmFactoryBase \\\n                          *::details \\\n                          std::*\n \ndiff --git a/src/ipa/libipa/algorithm.cpp b/src/ipa/libipa/algorithm.cpp\nindex 2df91e5d8fed..1d0998089044 100644\n--- a/src/ipa/libipa/algorithm.cpp\n+++ b/src/ipa/libipa/algorithm.cpp\n@@ -32,6 +32,11 @@ namespace ipa {\n  * argument.\n  */\n \n+/**\n+ * \\typedef Algorithm::Module\n+ * \\brief The IPA module type for this class of algorithms\n+ */\n+\n /**\n  * \\fn Algorithm::configure()\n  * \\brief Configure the Algorithm given an IPAConfigInfo\n@@ -94,6 +99,49 @@ namespace ipa {\n  * such that the algorithms use up to date state as required.\n  */\n \n+/**\n+ * \\class AlgorithmFactory\n+ * \\brief Registration of Algorithm classes and creation of instances\n+ * \\tparam _Algorithm The algorithm class type for this factory\n+ *\n+ * To facilitate instantiation of Algorithm classes, the AlgorithmFactory class\n+ * implements auto-registration of algorithms with the IPA Module class. Each\n+ * Algorithm subclass shall register itself using the REGISTER_IPA_ALGORITHM()\n+ * macro, which will create a corresponding instance of an AlgorithmFactory and\n+ * register it with the IPA Module.\n+ */\n+\n+/**\n+ * \\fn AlgorithmFactory::AlgorithmFactory()\n+ * \\brief Construct an algorithm factory\n+ * \\param[in] name Name of the algorithm class\n+ *\n+ * Creating an instance of the factory automatically registers is with the IPA\n+ * Module class, enabling creation of algorithm instances through\n+ * Module::createAlgorithm().\n+ *\n+ * The factory \\a name identifies the algorithm and shall be unique.\n+ */\n+\n+/**\n+ * \\fn AlgorithmFactory::create()\n+ * \\brief Create an instance of the Algorithm corresponding to the factory\n+ * \\return A pointer to a newly constructed instance of the Algorithm subclass\n+ * corresponding to the factory\n+ */\n+\n+/**\n+ * \\def REGISTER_IPA_ALGORITHM\n+ * \\brief Register an algorithm with the IPA module\n+ * \\param[in] algorithm Class name of Algorithm derived class to register\n+ * \\param[in] name Name of the algorithm\n+ *\n+ * Register an Algorithm subclass with the IPA module to make it available for\n+ * instantiation through Module::createAlgorithm(). The \\a name identifies the\n+ * algorithm and must be unique across all algorithms registered for the IPA\n+ * module.\n+ */\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/libipa/algorithm.h b/src/ipa/libipa/algorithm.h\nindex fd2ffcfbc900..cfbe4ed8efac 100644\n--- a/src/ipa/libipa/algorithm.h\n+++ b/src/ipa/libipa/algorithm.h\n@@ -6,14 +6,19 @@\n  */\n #pragma once\n \n+#include <memory>\n+#include <string>\n+\n namespace libcamera {\n \n namespace ipa {\n \n-template<typename Module>\n+template<typename _Module>\n class Algorithm\n {\n public:\n+\tusing Module = _Module;\n+\n \tvirtual ~Algorithm() {}\n \n \tvirtual int configure([[maybe_unused]] typename Module::Context &context,\n@@ -34,6 +39,46 @@ public:\n \t}\n };\n \n+template<typename _Module>\n+class AlgorithmFactoryBase\n+{\n+public:\n+\tAlgorithmFactoryBase(const char *name)\n+\t\t: name_(name)\n+\t{\n+\t\t_Module::registerAlgorithm(this);\n+\t}\n+\n+\tvirtual ~AlgorithmFactoryBase() = default;\n+\n+\tconst std::string &name() const { return name_; }\n+\n+\tvirtual std::unique_ptr<Algorithm<_Module>> create() const = 0;\n+\n+private:\n+\tstd::string name_;\n+};\n+\n+template<typename _Algorithm>\n+class AlgorithmFactory : public AlgorithmFactoryBase<typename _Algorithm::Module>\n+{\n+public:\n+\tAlgorithmFactory(const char *name)\n+\t\t: AlgorithmFactoryBase<typename _Algorithm::Module>(name)\n+\t{\n+\t}\n+\n+\t~AlgorithmFactory() = default;\n+\n+\tstd::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override\n+\t{\n+\t\treturn std::make_unique<_Algorithm>();\n+\t}\n+};\n+\n+#define REGISTER_IPA_ALGORITHM(algorithm, name) \\\n+static AlgorithmFactory<algorithm> global_##algorithm##Factory(name);\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp\nindex d03cc8ef03ed..451614fd04da 100644\n--- a/src/ipa/libipa/module.cpp\n+++ b/src/ipa/libipa/module.cpp\n@@ -75,6 +75,30 @@ namespace ipa {\n  * \\brief The type of the IPA statistics and ISP results\n  */\n \n+/**\n+ * \\fn Module::createAlgorithm()\n+ * \\brief Create an instance of an Algorithm by name\n+ * \\param[in] name The algorithm name\n+ *\n+ * This function is the entry point to algorithm instantiation for the IPA\n+ * module. It creates and returns an instance of an algorithm identified by its\n+ * \\a name. If no such algorithm exists, the function returns nullptr.\n+ *\n+ * To make an algorithm available to the IPA module, it shall be registered with\n+ * the REGISTER_IPA_ALGORITHM() macro.\n+ *\n+ * \\return A new instance of the Algorithm subclass corresponding to the \\a name\n+ */\n+\n+/**\n+ * \\fn Module::registerAlgorithm()\n+ * \\brief Add an algorithm factory class to the list of available algorithms\n+ * \\param[in] factory Factory to use to construct the algorithm\n+ *\n+ * This function registers an algorithm factory. It is meant to be called by the\n+ * AlgorithmFactory constructor only.\n+ */\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h\nindex c4d778120408..05f39801db47 100644\n--- a/src/ipa/libipa/module.h\n+++ b/src/ipa/libipa/module.h\n@@ -7,6 +7,12 @@\n \n #pragma once\n \n+#include <memory>\n+#include <string>\n+#include <vector>\n+\n+#include \"algorithm.h\"\n+\n namespace libcamera {\n \n namespace ipa {\n@@ -23,6 +29,33 @@ public:\n \tusing Stats = _Stats;\n \n \tvirtual ~Module() {}\n+\n+\tstatic std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name)\n+\t{\n+\t\tfor (const AlgorithmFactoryBase<Module> *factory : factories()) {\n+\t\t\tif (factory->name() == name)\n+\t\t\t\treturn factory->create();\n+\t\t}\n+\n+\t\treturn nullptr;\n+\t}\n+\n+\tstatic void registerAlgorithm(AlgorithmFactoryBase<Module> *factory)\n+\t{\n+\t\tfactories().push_back(factory);\n+\t}\n+\n+private:\n+\tstatic std::vector<AlgorithmFactoryBase<Module> *> &factories()\n+\t{\n+\t\t/*\n+\t\t * The static factories map is defined inside the function to ensure\n+\t\t * it gets initialized on first use, without any dependency on\n+\t\t * link order.\n+\t\t */\n+\t\tstatic std::vector<AlgorithmFactoryBase<Module> *> factories;\n+\t\treturn factories;\n+\t}\n };\n \n } /* namespace ipa */\n",
    "prefixes": [
        "libcamera-devel",
        "v4.1",
        "03/12"
    ]
}