{"id":24918,"url":"https://patchwork.libcamera.org/api/patches/24918/?format=json","web_url":"https://patchwork.libcamera.org/patch/24918/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20251030165816.1095180-17-barnabas.pocze@ideasonboard.com>","date":"2025-10-30T16:58:10","name":"[RFC,v3,16/22] libcamera: pipeline_handler: Add metadataAvailable() function","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"7330fed32f69cd180f06c580982af2304323ce98","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24918/mbox/","series":[{"id":5545,"url":"https://patchwork.libcamera.org/api/series/5545/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5545","date":"2025-10-30T16:57:54","name":"libcamera: Add `MetadataList`","version":3,"mbox":"https://patchwork.libcamera.org/series/5545/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24918/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24918/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 D538BC32DB\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Oct 2025 16:58:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 64F0D609C0;\n\tThu, 30 Oct 2025 17:58:45 +0100 (CET)","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 881B460970\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Oct 2025 17:58:25 +0100 (CET)","from pb-laptop.local (185.221.140.239.nat.pool.zt.hu\n\t[185.221.140.239])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6911015D2;\n\tThu, 30 Oct 2025 17:56:35 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"XJLaR8LW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761843395;\n\tbh=nU41733PuEdREmE7GxQzkvJHHKYKMBoH+TFSi17v33c=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=XJLaR8LWsn5JkWdIBRWjvtzi3LXu89ZU6yMh2LBRRfYSkIfmnwDmOcLZ12RyrMpR6\n\tNvhfSAyltMTy6T0r6a0jbOZSM/NDPiPL+aaKLvAwbK8ux6GRhfr1zXwJXz/ayIQfP+\n\tn7T6rv8MK2x8VzWD9dx+4QwGqkayqrP8ZWK2rnN0=","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>,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"[RFC PATCH v3 16/22] libcamera: pipeline_handler: Add\n\tmetadataAvailable() function","Date":"Thu, 30 Oct 2025 17:58:10 +0100","Message-ID":"<20251030165816.1095180-17-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","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 report metadata for a Request is\nby accessing the Request::metadata_ list directly, and either merging\na ControlList or seting 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 an intermediate 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>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nOriginal: https://patchwork.libcamera.org/patch/22229/\n\nchanges in v3:\n  * abort if merging ControlList into metadata fails\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            | 90 +++++++++++++++++++\n 2 files changed, 139 insertions(+)","diff":"diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex e89d6a33e3..6c0e546e67 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/internal/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 internal::cxx20::type_identity_t<T> &value)\n+\t{\n+\t\tauto &m = request->metadata2();\n+\t\tconst auto c = m.checkpoint();\n+\n+\t\tstd::ignore = m.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 internal::cxx20::type_identity_t<T> &value) const\n+\t\t{\n+\t\t\trequest->metadata().set(ctrl, value);\n+\t\t\tstd::ignore = request->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 e5f9e55c97..de98a93306 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -532,6 +532,96 @@ 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 internal::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\tLOG(Pipeline, Fatal) << \"Tried to add incompatible metadata items\";\n+\n+\tif (!d->empty())\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 internal::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\n+ * 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\n+ * 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 (...) // controls::X is available and ready to be reported\n+\t\t\tset(controls::X, ...);\n+\t\tif (...) // controls::Y is available and ready to be reported\n+\t\t\tset(controls::Y, ...);\n+\t\t// ...\n+\t});\n+ * \\endcode\n+ *\n+ * The advantage of the above over two calls to\n+ * PipelineHandler::metadataAvailable(Request *request, const Control<T> &ctrl, const internal::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","v3","16/22"]}