Patch Detail
Show a patch.
GET /api/patches/25647/?format=api
{ "id": 25647, "url": "https://patchwork.libcamera.org/api/patches/25647/?format=api", "web_url": "https://patchwork.libcamera.org/patch/25647/", "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": "<20260106165754.1759831-17-barnabas.pocze@ideasonboard.com>", "date": "2026-01-06T16:57:48", "name": "[v4,16/22] libcamera: pipeline_handler: Add metadataAvailable() function", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "9bd52c5a1258b29a338c1396533c9119ed4032be", "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/25647/mbox/", "series": [ { "id": 5688, "url": "https://patchwork.libcamera.org/api/series/5688/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5688", "date": "2026-01-06T16:57:32", "name": "libcamera: Add `MetadataList`", "version": 4, "mbox": "https://patchwork.libcamera.org/series/5688/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/25647/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/25647/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 EE84EC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 6 Jan 2026 16:58:19 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B494461FC4;\n\tTue, 6 Jan 2026 17:58:16 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B2EC61FC2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 6 Jan 2026 17:58:02 +0100 (CET)", "from pb-laptop.local (185.221.143.114.nat.pool.zt.hu\n\t[185.221.143.114])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ECB1327FB;\n\tTue, 6 Jan 2026 17:57:40 +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=\"OiGdrGPk\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1767718661;\n\tbh=nPLvG5KkAcJaRNTUh6/zF8JDQ5kGoT7sXVLbXGriM70=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OiGdrGPk2pWedp97NbIq2lIEHPcS03tvTfB0y1A694mFsWwQNn+soD6REBIDW1YyR\n\tOAhO9PQuSv7cikIPQhIEVC2VFQ8xqibTCWwYaZfwENAkzNzI81dcd3knl0MjlJiSQR\n\tNMgC763xkZcWgkVYfAAipZtQrxDXeUQPt6OOCYfs=", "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>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH v4 16/22] libcamera: pipeline_handler: Add\n\tmetadataAvailable() function", "Date": "Tue, 6 Jan 2026 17:57:48 +0100", "Message-ID": "<20260106165754.1759831-17-barnabas.pocze@ideasonboard.com>", "X-Mailer": "git-send-email 2.52.0", "In-Reply-To": "<20260106165754.1759831-1-barnabas.pocze@ideasonboard.com>", "References": "<20260106165754.1759831-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>\nReviewed-by: Kieran Bingham <kieran.bingham@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 | 52 +++++++++++\n src/libcamera/pipeline_handler.cpp | 92 +++++++++++++++++++\n 2 files changed, 144 insertions(+)", "diff": "diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex b4f97477a..10206945d 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,53 @@ 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\tRequest::Private *d = request->_d();\n+\n+\t\tauto &m = d->metadata2();\n+\t\tconst auto c = m.checkpoint();\n+\n+\t\tstd::ignore = m.set(ctrl, value);\n+\t\td->metadata().set(ctrl, value);\n+\n+\t\tconst auto diff = c.diffSince();\n+\t\tif (diff)\n+\t\t\td->camera()->metadataAvailable.emit(request, diff);\n+\t}\n+\n+#ifndef __DOXYGEN__\n+\tstruct MetadataSetter {\n+\t\tRequest::Private *d;\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\td->metadata().set(ctrl, value);\n+\t\t\tstd::ignore = d->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\tRequest::Private *d = request->_d();\n+\t\tconst auto c = d->metadata2().checkpoint();\n+\n+\t\tstd::invoke(func, MetadataSetter{ d });\n+\n+\t\tif (const auto diff = c.diffSince())\n+\t\t\td->camera()->metadataAvailable.emit(request, diff);\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 5c469e5ba..26675104b 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -543,6 +543,98 @@ 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 each\n+ * metadata must only be set at most once. Afterwards the function notifies the\n+ * application by triggering the Camera::availableMetadata signal with the just\n+ * 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::Private *d = request->_d();\n+\n+\td->metadata().merge(metadata);\n+\n+\tconst auto diff = d->metadata2().merge(metadata);\n+\tif (!diff)\n+\t\tLOG(Pipeline, Fatal) << \"Tried to add incompatible metadata items\";\n+\n+\tif (!diff->empty())\n+\t\td->camera()->metadataAvailable.emit(request, *diff);\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 serves 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": [ "v4", "16/22" ] }