Patch Detail
Show a patch.
GET /api/patches/23884/?format=api
{ "id": 23884, "url": "https://patchwork.libcamera.org/api/patches/23884/?format=api", "web_url": "https://patchwork.libcamera.org/patch/23884/", "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": "<20250721104622.1550908-17-barnabas.pocze@ideasonboard.com>", "date": "2025-07-21T10:46:16", "name": "[RFC,v2,16/22] libcamera: pipeline_handler: Add metadataAvailable() function", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4ecbee1258041ceabb38786c73d6c503d59d958c", "submitter": { "id": 216, "url": "https://patchwork.libcamera.org/api/people/216/?format=api", "name": "Barnabás Pőcze", "email": "barnabas.pocze@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/23884/mbox/", "series": [ { "id": 5305, "url": "https://patchwork.libcamera.org/api/series/5305/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5305", "date": "2025-07-21T10:46:00", "name": "libcamera: Add `MetadataList`", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5305/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/23884/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/23884/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 D40ECC3323\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Jul 2025 10:46:58 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 533A569005;\n\tMon, 21 Jul 2025 12:46:58 +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 3921F68FE6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jul 2025 12:46:35 +0200 (CEST)", "from pb-laptop.local (185.221.140.39.nat.pool.zt.hu\n\t[185.221.140.39])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 451077972;\n\tMon, 21 Jul 2025 12:45:58 +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=\"kGGccKcn\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753094758;\n\tbh=yUD2aBtOpzzuNczp3uhMWgInss8zgNxEv8sH9JSEaYc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=kGGccKcn04NvUwGINH8YXkdIXgmMYfct4WsTy6mfXrkWd6NOXMVCXntH0rK97STwA\n\tC4OnCh1Zvn8efL+IDS0QEDHo+ESA6HSiN35jEi4AbqnorFf1bEr3WhPwlbaJ3vekgG\n\tuXW9EBVkEyiUOc/9V+1quR9N+YUU3uI8Vn3zcqeA=", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Subject": "[RFC PATCH v2 16/22] libcamera: pipeline_handler: Add\n\tmetadataAvailable() function", "Date": "Mon, 21 Jul 2025 12:46:16 +0200", "Message-ID": "<20250721104622.1550908-17-barnabas.pocze@ideasonboard.com>", "X-Mailer": "git-send-email 2.50.1", "In-Reply-To": "<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>", "References": "<20250721104622.1550908-1-barnabas.pocze@ideasonboard.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "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": "From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nCurrently the way pipeline handlers have to store metadata results\nfor a Request is to access the Request::metadata_ list directly and\neither merge a ControlList or set a single control value there.\n\nDirect access to Request::metadata_ is however problematic as even if\nmetadata would be available earlier, pipeline handlers can only\naccumulate the results in Request::metadata_ and they're only available\nfor applications at Request complete time.\n\nInstead of letting pipeline handlers access Request::metadata_ directly\nprovide two helper functions, similar in spirit to\nPipelineHandler::completeBuffer() and\nPipelineHandler::completeRequest(), to allow pipeline handlers to\nnotify early availability of metadata.\n\nProvide three overloads, one that accepts a ControlList and merges it into\nRequest::metadata_, one that allows to set a single metadata result there\nwithout going through an intermediate copy, and one that runs a callback\nfor conditional metadata reporting without intermediate an ControlList.\n\nThe newly provided helpers trigger the Camera::availableMetadata signal\nfrom where applications can retrieve the list of controls that have\njust been made available by the pipeline handler.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n[Fill both lists, use `type_identity`, new overload, adjust commit message.]\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\nOriginal: https://patchwork.libcamera.org/patch/22229/\n\nchanges in v2:\n * add new overload that takes an invocable object for more flexibility\n---\n include/libcamera/internal/pipeline_handler.h | 49 +++++++++++\n src/libcamera/pipeline_handler.cpp | 84 +++++++++++++++++++\n 2 files changed, 133 insertions(+)", "diff": "diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex e89d6a33e..49c907178 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -7,16 +7,21 @@\n \n #pragma once\n \n+#include <functional>\n #include <memory>\n #include <string>\n #include <sys/types.h>\n #include <vector>\n \n+#include <libcamera/base/details/cxx20.h>\n #include <libcamera/base/object.h>\n \n+#include <libcamera/camera.h>\n #include <libcamera/controls.h>\n #include <libcamera/stream.h>\n \n+#include \"libcamera/internal/request.h\"\n+\n namespace libcamera {\n \n class Camera;\n@@ -58,6 +63,50 @@ public:\n \tvoid registerRequest(Request *request);\n \tvoid queueRequest(Request *request);\n \n+\tvoid metadataAvailable(Request *request, const ControlList &metadata);\n+\n+\ttemplate<typename T>\n+\tvoid metadataAvailable(Request *request, const Control<T> &ctrl,\n+\t\t\t const details::cxx20::type_identity_t<T> &value)\n+\t{\n+\t\tauto &m = request->metadata2();\n+\t\tconst auto c = m.checkpoint();\n+\n+\t\tm.set(ctrl, value);\n+\t\trequest->metadata().set(ctrl, value);\n+\n+\t\tconst auto d = c.diffSince();\n+\t\tif (d)\n+\t\t\trequest->_d()->camera()->metadataAvailable.emit(request, d);\n+\t}\n+\n+#ifndef __DOXYGEN__\n+\tstruct MetadataSetter {\n+\t\tRequest *request;\n+\n+\t\ttemplate<typename T>\n+\t\tvoid operator()(const Control<T> &ctrl,\n+\t\t\t const details::cxx20::type_identity_t<T> &value) const\n+\t\t{\n+\t\t\trequest->metadata().set(ctrl, value);\n+\t\t\trequest->metadata2().set(ctrl, value);\n+\t\t}\n+\t};\n+\n+\ttemplate<typename Func, std::enable_if_t<std::is_invocable_v<Func&, MetadataSetter>> * = nullptr>\n+#else\n+\ttemplate<typename Func>\n+#endif\n+\tvoid metadataAvailable(Request *request, Func func)\n+\t{\n+\t\tconst auto c = request->metadata2().checkpoint();\n+\n+\t\tstd::invoke(func, MetadataSetter{ request });\n+\n+\t\tif (const auto d = c.diffSince())\n+\t\t\trequest->_d()->camera()->metadataAvailable.emit(request, d);\n+\t}\n+\n \tbool completeBuffer(Request *request, FrameBuffer *buffer);\n \tvoid completeRequest(Request *request);\n \tvoid cancelRequest(Request *request);\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex e5f9e55c9..edfa9cf58 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -532,6 +532,90 @@ void PipelineHandler::doQueueRequests(Camera *camera)\n * \\return 0 on success or a negative error code otherwise\n */\n \n+/**\n+ * \\brief Signal the availability of metadata for \\a request\n+ * \\param[in] request The request the metadata belongs to\n+ * \\param[in] metadata The collection of metadata items\n+ *\n+ * This function copies metadata items from \\a metadata to the cumulative metadata\n+ * collection of \\a request. This function may be called multiple times, but metadata\n+ * items already present in Request::metadata() are ignored. Afterwards the function\n+ * notifies the application by triggering the Camera::availableMetadata signal with\n+ * the just added metadata items.\n+ *\n+ * Early metadata completion allows pipeline handlers to fast track delivery of\n+ * metadata results as soon as they are available before the completion of \\a\n+ * request. The full list of metadata results of a Request is available at\n+ * Request completion time in Request::metadata().\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ *\n+ * \\sa PipelineHandler::metadataAvailable(Request *request, Func func)\n+ * \\sa PipelineHandler::metadataAvailable(Request *request,\n+ * const Control<T> &ctrl,\n+ * const details::cxx20::type_identity_t<T> &value)\n+ */\n+void PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+{\n+\trequest->metadata().merge(metadata);\n+\n+\tconst auto d = request->metadata2().merge(metadata);\n+\tif (d)\n+\t\trequest->_d()->camera()->metadataAvailable.emit(request, d);\n+}\n+\n+/**\n+ * \\fn void PipelineHandler::metadataAvailable(Request *request, const Control<T> &ctrl,\n+ *\t\t\t\t\t const details::cxx20::type_identity_t<T> &value)\n+ * \\copybrief PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+ * \\param[in] request The request the metadata belongs to\n+ * \\param[in] ctrl The control id of the metadata item\n+ * \\param[in] value The value of the metadata item\n+ *\n+ * This function servers the same purpose as PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+ * but it allows a single metadata item to be reported directly,\n+ * without creating a ControlList.\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ * \\sa PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+ */\n+\n+/**\n+ * \\fn void PipelineHandler::metadataAvailable(Request *request, Func func)\n+ * \\copybrief PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+ * \\param[in] request The request the metadata belongs to\n+ * \\param[in] func The callback to invoke\n+ *\n+ * This function serves the same purpose as PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+ * but it provides more flexibility for pipeline handlers. This function invokes\n+ * \\a func, which receives as its sole argument an object of unspecified type whose\n+ * operator() can be used to add metadata items.\n+ *\n+ * For example, a PipelineHandler might use this function to conditionally report two\n+ * metadata items without creating an intermediate ControlList:\n+ *\n+ * \\code\n+\tmetadataAvailable(request, [&](auto set) {\n+\t\tif (x)\n+\t\t\tset(controls::X, x);\n+\t\tif (y)\n+\t\t\tset(controls::Y, y);\n+\t\t// ...\n+\t});\n+ * \\endcode\n+ *\n+ * The advantage of the above over two calls to PipelineHandler::metadataAvailable(Request *request, const Control<T> &ctrl, const details::cxx20::type_identity_t<T> &value)\n+ * is that the application is only notified once, after \\a func has returned.\n+ *\n+ * \\note Calling any overload of metadataAvailable() inside \\a func is not allowed.\n+ * \\note The object passed to \\a func is only usable while \\a func runs, it must not\n+ * be saved or reused.\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ *\n+ * \\sa PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+ */\n+\n /**\n * \\brief Complete a buffer for a request\n * \\param[in] request The request the buffer belongs to\n", "prefixes": [ "RFC", "v2", "16/22" ] }