{"id":22229,"url":"https://patchwork.libcamera.org/api/patches/22229/?format=json","web_url":"https://patchwork.libcamera.org/patch/22229/","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":"<20241206160747.97176-4-jacopo.mondi@ideasonboard.com>","date":"2024-12-06T16:07:41","name":"[3/8] libcamera: pipeline_handler: Add metadataAvailable() function","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6ba2b996f199a1accb97f9e6f5159bb69db88bb0","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22229/mbox/","series":[{"id":4858,"url":"https://patchwork.libcamera.org/api/series/4858/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4858","date":"2024-12-06T16:07:38","name":"libcamera: Support partial metadata completion","version":1,"mbox":"https://patchwork.libcamera.org/series/4858/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22229/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22229/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 88546BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Dec 2024 16:08:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4BC6967E2D;\n\tFri,  6 Dec 2024 17:07:59 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EC06E618B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Dec 2024 17:07:55 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 475B2641;\n\tFri,  6 Dec 2024 17:07:26 +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=\"mjsCbx0N\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1733501246;\n\tbh=UtKmjupIEL60xV2zJbciiaJq0pJuJPdySw2ZplSqTxI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=mjsCbx0NsX2cevRuXiEnyiVYEeQHPHre18Wf35Sn8oRzvBSgYjpoZkEXg1J4oV8lb\n\ttrq85eHXQJCliHu/HEHbC8xEeCUv6aW1XnHh1YGluLuLUktFelRZ3IkRMDELIX/t8D\n\tJSSadDQfxYTqWh2OU6gwGetPwQX00NX6O9xupInM=","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tHarvey Yang <chenghaoyang@chromium.org>,\n\tHan-Lin Chen <hanlinchen@chromium.org>","Subject":"[PATCH 3/8] libcamera: pipeline_handler: Add metadataAvailable()\n\tfunction","Date":"Fri,  6 Dec 2024 17:07:41 +0100","Message-ID":"<20241206160747.97176-4-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.47.1","In-Reply-To":"<20241206160747.97176-1-jacopo.mondi@ideasonboard.com>","References":"<20241206160747.97176-1-jacopo.mondi@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":"Currently 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 two overloads, one that accepts a ControlList and merges it into\nRequest::metadata_ and one that allows to set a single metadata result\nthere without going through an intermediate copy.\n\nThe newly provided helpers trigger the Camera::availableMetadata signal\nfrom where applications can retrieve the list of ControlIds that have\njust been made available by the pipeline handler.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n include/libcamera/internal/pipeline_handler.h | 41 ++++++++++\n src/libcamera/pipeline_handler.cpp            | 74 +++++++++++++++++++\n 2 files changed, 115 insertions(+)","diff":"diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex fb28a18d0f46..3ca6a0290b2b 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -11,13 +11,17 @@\n #include <queue>\n #include <string>\n #include <sys/types.h>\n+#include <unordered_set>\n #include <vector>\n \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 +62,43 @@ 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 T &value)\n+\t{\n+\t\tif (request->metadata().contains(ctrl.id()))\n+\t\t\treturn;\n+\n+\t\tstd::unordered_set<const ControlId *> ids;\n+\t\tids.insert(&ctrl);\n+\n+\t\trequest->metadata().set<T, T>(ctrl, value);\n+\n+\t\tCamera *camera = request->_d()->camera();\n+\t\tcamera->metadataAvailable.emit(request, ids);\n+\t}\n+\n+#ifndef __DOXYGEN__\n+\ttemplate<typename T, std::size_t Size>\n+\tvoid metadataAvailable(Request *request,\n+\t\t\t       const Control<Span<const T, Size>> &ctrl,\n+\t\t\t       const Span<const T, Size> &value)\n+\t{\n+\t\tif (request->metadata().contains(ctrl.id()))\n+\t\t\treturn;\n+\n+\t\tstd::unordered_set<const ControlId *> ids;\n+\t\tids.insert(&ctrl);\n+\n+\t\trequest->metadata().set(ctrl, value);\n+\n+\t\tCamera *camera = request->_d()->camera();\n+\t\tcamera->metadataAvailable.emit(request, ids);\n+\t}\n+#endif\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 caa5c20e7483..a69d789116ad 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -507,6 +507,80 @@ void PipelineHandler::doQueueRequests()\n  * \\return 0 on success or a negative error code otherwise\n  */\n \n+/**\n+ * \\brief Notify the availability of a list of metadata for \\a request\n+ * \\param[in] request The request the metadata belongs to\n+ * \\param[in] metadata The metadata list\n+ *\n+ * This function should be called multiple times by pipeline handlers to signal\n+ * the availability of a list of metadata results. It notifies applications\n+ * by triggering the Camera::availableMetadata signal and accumulates the\n+ * metadata results in Request::metadata().\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+ * A metadata key is expected to be notified at most once. Metadata keys\n+ * notified multiple times are ignored.\n+ *\n+ * This overload allows to signal the availability of a list of metadata and\n+ * merges them in the Request::metadata() list. This operations is expensive\n+ * as controls are copied from \\a metadata to Request::metadata().\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ */\n+void PipelineHandler::metadataAvailable(Request *request, const ControlList &metadata)\n+{\n+\tstd::unordered_set<const ControlId *> ids;\n+\tconst ControlIdMap *idmap = request->metadata().idMap();\n+\n+\tfor (const auto &ctrl : metadata) {\n+\t\tif (request->metadata().contains(ctrl.first))\n+\t\t\tcontinue;\n+\n+\t\tASSERT(idmap->count(ctrl.first));\n+\n+\t\tids.insert(idmap->at(ctrl.first));\n+\t}\n+\n+\tif (ids.empty())\n+\t\treturn;\n+\n+\trequest->metadata().merge(metadata);\n+\n+\tCamera *camera = request->_d()->camera();\n+\tcamera->metadataAvailable.emit(request, ids);\n+}\n+\n+/**\n+ * \\fn void PipelineHandler::metadataAvailable(Request *request, const Control<T> &ctrl, const T &value)\n+ * \\brief Notify the availability of a metadata result for \\a request\n+ * \\param[in] request The request the metadata belongs to\n+ * \\param[in] ctrl The control id to notify\n+ * \\param[in] value the control value\n+ *\n+ * This function should be called multiple times by pipeline handlers to signal\n+ * the availability of a metadata result. It notifies applications\n+ * by triggering the Camera::availableMetadata signal and accumulates the\n+ * metadata result in Request::metadata().\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+ * A metadata key is expected to be notified at most once. Metadata keys\n+ * notified multiple times are ignored.\n+ *\n+ * This overload allows to signal the availability of a single metadata and\n+ * merge \\a value in the Request::metadata() list. This operations copies \\a\n+ * value in the Request::metadata() list without creating intermediate copies.\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ */\n+\n /**\n  * \\brief Complete a buffer for a request\n  * \\param[in] request The request the buffer belongs to\n","prefixes":["3/8"]}