Patch Detail
Show a patch.
GET /api/1.1/patches/17088/?format=api
{ "id": 17088, "url": "https://patchwork.libcamera.org/api/1.1/patches/17088/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17088/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20220812090838.1784703-3-hanlinchen@chromium.org>", "date": "2022-08-12T09:08:33", "name": "[libcamera-devel,v2,2/7] libcamera: Camera: Add signals for completion of metadata and partial result", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "3335c6ca093df200da1b60d64e32225114db32b4", "submitter": { "id": 98, "url": "https://patchwork.libcamera.org/api/1.1/people/98/?format=api", "name": "Hanlin Chen", "email": "hanlinchen@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17088/mbox/", "series": [ { "id": 3408, "url": "https://patchwork.libcamera.org/api/1.1/series/3408/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3408", "date": "2022-08-12T09:08:31", "name": "Implement Android Partial Result Featrue", "version": 2, "mbox": "https://patchwork.libcamera.org/series/3408/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17088/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17088/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 0D0EBC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 12 Aug 2022 09:08:53 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C469863331;\n\tFri, 12 Aug 2022 11:08:52 +0200 (CEST)", "from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com\n\t[IPv6:2607:f8b0:4864:20::52c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D32E16332D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Aug 2022 11:08:51 +0200 (CEST)", "by mail-pg1-x52c.google.com with SMTP id bh13so328666pgb.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Aug 2022 02:08:51 -0700 (PDT)", "from localhost ([2401:fa00:1:17:1705:d284:d114:2e24])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\tij1-20020a170902ab4100b0016f1ef2cd44sm1164281plb.154.2022.08.12.02.08.49\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 12 Aug 2022 02:08:49 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660295332;\n\tbh=VO/fxVcJWGHYLOdEQrn7s1ICjuFYL6BRUvHx/cqFiwg=;\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=rc7tUzTywQPgrRt0wAJ3U5LP0tP6udR1518NrQMemJF3yMm2dsji43JUjoXAk4Ynq\n\tZNzaXJb5nPV3JTWb42p9o9YE/RiEViyQ6SooyCu7nQ9wcxOpMLlNI8mRP9flO+7X5Z\n\ttQClMydIzpq3XPhQjW3B0LVpsq2pUicLIMUi5VScpli27XakAoERxP+CrP/mWGDHB7\n\tqdF/z/piY82EV0UIvCfe78m/ltHpxMTdmAuUlBEQVhdnRnReoJQOf9uLtwS+cnTFfq\n\toQIFy82nweVtj4LS+rn9IHG1e0hMO55koIOJ117PV8mbhhwiF7jmIFM71oc4H1XD+v\n\tJpmizUV0HwYmw==", "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc;\n\tbh=R85XYqoVWEGvT6M8Agx+9ORKuOA7agTT19FBIQSY1xk=;\n\tb=QbzabP55WJiV6FkPPgUG7F7cMEBgxRX9eFeHUNN3Hi54veBHzdDrwyPPqWynhz9dvK\n\tMNPoq7YQWBDeRX25VmJAQNR/0mQPHd3KSoel3y4I+tx/7MaCHUEjsibHvHjuQgltAA4m\n\t3K2jJBuesxZBdOSR7C9CQ6vbmj5q4IF1QIZZ0=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"QbzabP55\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc;\n\tbh=R85XYqoVWEGvT6M8Agx+9ORKuOA7agTT19FBIQSY1xk=;\n\tb=MGv8+W89dek0NfwS+P6qMwaHzaNoN5d9epF1mhkEHphnCgV0r3rGrRTzSAARZu4deW\n\tJwxyeocNQQCPU+AUzHlFdWShuY3o58M3ZdPUfw2OOA0CGvXvasiDnBC/c6ZPAzptxlCj\n\t3EQ/ebR6uN0F6XG+nGFjR3gsSwq5sJArKJqyoRhI246ZYciuoCsEB2D26t2KT2OiUKMQ\n\tPXrJSSQGIRiRQd7QthYHp3RBTsXoud+eR8lif7pNtjKVMNmTld6Y3ioWa4QzDKnFxBjc\n\tBnnryAub0Yzg5AETNrc3frunzDJ8F+mhd2gFNs0g8I9YXGhbwaV0uBE4ODU5cq+45oDd\n\t62eA==", "X-Gm-Message-State": "ACgBeo0FUinRCvMi+ncLsInjQ5AVMJlx47IaV8PXNk4VCjshYHEuLadi\n\tTM/OMSu4MBAg6Jq+Ng7c3x2D+cvimE99rA==", "X-Google-Smtp-Source": "AA6agR7i74sDED9cbQYg5vIMwnuQNf/QGGblGRtgjX5G85nWe5hGrBt6VQ1eDHwSGLch/OHfwDqE/A==", "X-Received": "by 2002:a05:6a00:88f:b0:530:dec:81fd with SMTP id\n\tq15-20020a056a00088f00b005300dec81fdmr3081455pfj.64.1660295330122; \n\tFri, 12 Aug 2022 02:08:50 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 12 Aug 2022 17:08:33 +0800", "Message-Id": "<20220812090838.1784703-3-hanlinchen@chromium.org>", "X-Mailer": "git-send-email 2.37.1.595.g718a3a8f04-goog", "In-Reply-To": "<20220812090838.1784703-1-hanlinchen@chromium.org>", "References": "<20220812090838.1784703-1-hanlinchen@chromium.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 2/7] libcamera: Camera: Add signals for\n\tcompletion of metadata and partial result", "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": "Han-Lin Chen via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Han-Lin Chen <hanlinchen@chromium.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Allows pipelien handler to signal partial result completion by adding the\nfollowing signals to Camera:\n\nSignal<Request *, ControlList *> metadataCompleted;\nSignal<Request *, Result *> partialResultCompleted;\n\nTogether with the bufferCompleted signal, the pipeline handler is allowed to\nreturn buffers, partial metadata and combination of both at any stage of\nprocessing.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n---\n include/libcamera/camera.h | 2 +\n include/libcamera/internal/pipeline_handler.h | 4 +\n include/libcamera/request.h | 40 +++++\n src/libcamera/camera.cpp | 10 ++\n src/libcamera/pipeline_handler.cpp | 121 ++++++++++++-\n src/libcamera/request.cpp | 170 +++++++++++++++++-\n 6 files changed, 332 insertions(+), 15 deletions(-)", "diff": "diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex 5aa4bf69..187e01d8 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -99,7 +99,9 @@ public:\n \n \tconst std::string &id() const;\n \n+\tSignal<Request *, Result *> partialResultCompleted;\n \tSignal<Request *, FrameBuffer *> bufferCompleted;\n+\tSignal<Request *, ControlList *> metadataCompleted;\n \tSignal<Request *> requestCompleted;\n \tSignal<> disconnected;\n \ndiff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex c3e4c258..08519fb3 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -33,6 +33,7 @@ class FrameBuffer;\n class MediaDevice;\n class PipelineHandler;\n class Request;\n+class Result;\n \n class PipelineHandler : public std::enable_shared_from_this<PipelineHandler>,\n \t\t\tpublic Object\n@@ -62,7 +63,9 @@ public:\n \tvoid registerRequest(Request *request);\n \tvoid queueRequest(Request *request);\n \n+\tvoid completeMetadata(Request *request, const ControlList &metadata);\n \tbool completeBuffer(Request *request, FrameBuffer *buffer);\n+\tvoid completePartialResult(Request *request, Result &&result);\n \tvoid completeRequest(Request *request);\n \n \tconst char *name() const { return name_; }\n@@ -80,6 +83,7 @@ private:\n \tvoid mediaDeviceDisconnected(MediaDevice *media);\n \tvirtual void disconnect();\n \n+\tvoid cancelRequest(Request *request);\n \tvoid doQueueRequest(Request *request);\n \tvoid doQueueRequests();\n \ndiff --git a/include/libcamera/request.h b/include/libcamera/request.h\nindex dffde153..ac520226 100644\n--- a/include/libcamera/request.h\n+++ b/include/libcamera/request.h\n@@ -25,8 +25,43 @@ namespace libcamera {\n class Camera;\n class CameraControlValidator;\n class FrameBuffer;\n+class Request;\n class Stream;\n \n+class Result\n+{\n+public:\n+\tResult(Request *request);\n+\tResult(Result &&result);\n+\t~Result();\n+\n+\tRequest *request() const { return request_; }\n+\tconst ControlList &metadata() const { return metadata_; }\n+\n+\tconst std::vector<FrameBuffer *> &buffers() const { return buffers_; }\n+\tint addBuffer(FrameBuffer *buffer);\n+\n+\ttemplate<typename T, typename V>\n+\tvoid set(const Control<T> &ctrl, const V &value)\n+\t{\n+\t\treturn metadata_.set(ctrl, value);\n+\t}\n+\n+\tvoid set(unsigned int id, const ControlValue &value);\n+\tvoid merge(const ControlList &source);\n+\n+\tstd::string toString() const;\n+\n+private:\n+\tLIBCAMERA_DISABLE_COPY(Result)\n+\n+\tRequest *request_;\n+\tControlList metadata_;\n+\tstd::vector<FrameBuffer *> buffers_;\n+};\n+\n+std::ostream &operator<<(std::ostream &out, const Result &r);\n+\n class Request : public Extensible\n {\n \tLIBCAMERA_DECLARE_PRIVATE()\n@@ -44,6 +79,7 @@ public:\n \t};\n \n \tusing BufferMap = std::map<const Stream *, FrameBuffer *>;\n+\tusing ResultList = std::vector<Result>;\n \n \tRequest(Camera *camera, uint64_t cookie = 0);\n \t~Request();\n@@ -53,9 +89,12 @@ public:\n \tControlList &controls() { return *controls_; }\n \tControlList &metadata() { return *metadata_; }\n \tconst BufferMap &buffers() const { return bufferMap_; }\n+\tResultList &resultList() { return results_; }\n+\tResult *addResult(Result &&result);\n \tint addBuffer(const Stream *stream, FrameBuffer *buffer,\n \t\t std::unique_ptr<Fence> fence = nullptr);\n \tFrameBuffer *findBuffer(const Stream *stream) const;\n+\tconst Stream *findStream(const FrameBuffer *buffer) const;\n \n \tuint32_t sequence() const;\n \tuint64_t cookie() const { return cookie_; }\n@@ -71,6 +110,7 @@ private:\n \tControlList *controls_;\n \tControlList *metadata_;\n \tBufferMap bufferMap_;\n+\tResultList results_;\n \n \tconst uint64_t cookie_;\n \tStatus status_;\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 4d3523e2..a5fb9b33 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -765,6 +765,16 @@ const std::string &Camera::id() const\n * completed\n */\n \n+/**\n+ * \\var Camera::metadataCompleted\n+ * \\brief Signal emitted when a partial metadata for a request is completed\n+ */\n+\n+/**\n+ * \\var Camera::partialResultCompleted\n+ * \\brief Signal emitted when a partial result for a request is completed\n+ */\n+\n /**\n * \\var Camera::requestCompleted\n * \\brief Signal emitted when a request queued to the camera has completed\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 7c180a8e..6608c210 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -305,8 +305,9 @@ void PipelineHandler::stop(Camera *camera)\n \t\tRequest *request = waitingRequests_.front();\n \t\twaitingRequests_.pop();\n \n-\t\trequest->_d()->cancel();\n-\t\tcompleteRequest(request);\n+\t\tcancelRequest(request);\n+\t\trequest->_d()->complete();\n+\t\tcamera->requestCompleted.emit(request);\n \t}\n \n \t/* Make sure no requests are pending. */\n@@ -402,17 +403,30 @@ void PipelineHandler::doQueueRequest(Request *request)\n \trequest->_d()->sequence_ = data->requestSequence_++;\n \n \tif (request->_d()->cancelled_) {\n+\t\tcancelRequest(request);\n \t\tcompleteRequest(request);\n \t\treturn;\n \t}\n \n \tint ret = queueRequestDevice(camera, request);\n \tif (ret) {\n-\t\trequest->_d()->cancel();\n+\t\tcancelRequest(request);\n \t\tcompleteRequest(request);\n \t}\n }\n \n+/**\n+ * \\brief Cancel buffers of a request and complete the all buffers\n+ */\n+void PipelineHandler::cancelRequest(Request *request)\n+{\n+\trequest->_d()->cancel();\n+\tfor (auto it : request->buffers()) {\n+\t\tFrameBuffer *buffer = it.second;\n+\t\tcompleteBuffer(request, buffer);\n+\t}\n+}\n+\n /**\n * \\brief Queue prepared requests to the device\n *\n@@ -453,9 +467,10 @@ void PipelineHandler::doQueueRequests()\n * \\param[in] request The request the buffer belongs to\n * \\param[in] buffer The buffer that has completed\n *\n- * This function shall be called by pipeline handlers to signal completion of\n+ * This function could be called by pipeline handlers to signal completion of\n * the \\a buffer part of the \\a request. It notifies applications of buffer\n- * completion and updates the request's internal buffer tracking. The request\n+ * completion and updates the request's internal buffer tracking. The function\n+ * notify completion of a partial result including the buffer. The request\n * is not completed automatically when the last buffer completes to give\n * pipeline handlers a chance to perform any operation that may still be\n * needed. They shall complete requests explicitly with completeRequest().\n@@ -466,10 +481,75 @@ void PipelineHandler::doQueueRequests()\n * otherwise\n */\n bool PipelineHandler::completeBuffer(Request *request, FrameBuffer *buffer)\n+{\n+\tResult result(request);\n+\tresult.addBuffer(buffer);\n+\tcompletePartialResult(request, std::move(result));\n+\n+\treturn request->_d()->hasPendingBuffers();\n+}\n+\n+/**\n+ * \\brief Complete part of metadata for a request\n+ * \\param[in] request The request the buffer belongs to\n+ * \\param[in] metadata The partial metadata that has completed\n+ *\n+ * This function could be called by pipeline handlers to signal completion of\n+ * the \\a metadata part of the \\a request. It notifies applications of metadata\n+ * completion. The function notify completion of a partial result including the\n+ * metadata. The request is not completed automatically when the last metadata\n+ * completes to give pipeline handlers a chance to perform any operation that\n+ * may still be needed. They shall complete requests explicitly with\n+ * completeRequest().\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ */\n+void PipelineHandler::completeMetadata(Request *request, const ControlList &metadata)\n+{\n+\tResult result = Result(request);\n+\tresult.merge(metadata);\n+\tcompletePartialResult(request, std::move(result));\n+}\n+\n+/**\n+ * \\brief Complete part of metadata and buffer for a request\n+ * \\param[in] request The request the buffer belongs to\n+ * \\param[in] result The partial result that has completed\n+ *\n+ * This function could be called by pipeline handlers to signal completion of\n+ * the \\a result part of the \\a request. It notifies applications of partial\n+ * completion. The function notify completion of buffers and metadata included\n+ * in the result. The request is not completed automatically when the last\n+ * result completes to give pipeline handlers a chance to perform any operation\n+ * that may still be needed. They shall complete requests explicitly with\n+ * completeRequest(). The function only accepts rvalue of a Result type and\n+ * its interval content will be moved to the internal store to avoid copying\n+ * big metadata.\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ */\n+void PipelineHandler::completePartialResult(Request *request, Result &&result)\n {\n \tCamera *camera = request->_d()->camera();\n-\tcamera->bufferCompleted.emit(request, buffer);\n-\treturn request->_d()->completeBuffer(buffer);\n+\tResult *movedResult = request->addResult(std::move(result));\n+\n+\tASSERT(movedResult->request() == request);\n+\tASSERT(!movedResult->buffers().empty() ||\n+\t !movedResult->metadata().empty());\n+\n+\tfor (auto buffer : movedResult->buffers()) {\n+\t\trequest->_d()->completeBuffer(buffer);\n+\t\tcamera->bufferCompleted.emit(request, buffer);\n+\t}\n+\n+\tif (!movedResult->metadata().empty()) {\n+\t\trequest->metadata().merge(movedResult->metadata());\n+\t\tcamera->metadataCompleted.emit(\n+\t\t\trequest,\n+\t\t\t&const_cast<ControlList &>(movedResult->metadata()));\n+\t}\n+\n+\tcamera->partialResultCompleted.emit(request, movedResult);\n }\n \n /**\n@@ -494,6 +574,33 @@ void PipelineHandler::completeRequest(Request *request)\n \n \tCamera::Private *data = camera->_d();\n \n+\t/*\n+\t * Collect metadata which is not yet completed by the Camera, and\n+\t * create one partial result to cover the missing metadata before\n+\t * completing the whole request. This guarantees the aggregation of\n+\t * metadata in completed partial results equals to the global metadata\n+\t * in the request.\n+\t *\n+\t * \\todo: Forbid merging metadata into request.metadata() directly and\n+\t * force calling completeMetadata() and completePartialResult() to\n+\t * report metadata.\n+\t */\n+\tstd::unordered_set<unsigned int> completedMetadata;\n+\tfor (auto &result : request->resultList()) {\n+\t\tfor (auto &[id, _] : result.metadata())\n+\t\t\tcompletedMetadata.insert(id);\n+\t}\n+\n+\tControlList &requestMetadata = request->metadata();\n+\tif (requestMetadata.size() > completedMetadata.size()) {\n+\t\tResult result(request);\n+\t\tfor (auto &[id, value] : requestMetadata)\n+\t\t\tif (!completedMetadata.count(id))\n+\t\t\t\tresult.set(id, value);\n+\n+\t\tcompletePartialResult(request, std::move(result));\n+\t}\n+\n \tauto iter = data->queuedRequests_.begin();\n \twhile (iter != data->queuedRequests_.end()) {\n \t\tif ((*iter)->status() != Request::RequestPending) {\ndiff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\nindex d2af1d22..239c29cf 100644\n--- a/src/libcamera/request.cpp\n+++ b/src/libcamera/request.cpp\n@@ -126,15 +126,10 @@ void Request::Private::complete()\n \n void Request::Private::doCancelRequest()\n {\n-\tRequest *request = _o<Request>();\n-\n-\tfor (FrameBuffer *buffer : pending_) {\n+\tfor (FrameBuffer *buffer : pending_)\n \t\tbuffer->_d()->cancel();\n-\t\tcamera_->bufferCompleted.emit(request, buffer);\n-\t}\n \n \tcancelled_ = true;\n-\tpending_.clear();\n \tnotifiers_.clear();\n \ttimer_.reset();\n }\n@@ -144,8 +139,8 @@ void Request::Private::doCancelRequest()\n *\n * Mark the request and its associated buffers as cancelled and complete it.\n *\n- * Set each pending buffer in error state and emit the buffer completion signal\n- * before completing the Request.\n+ * Set each pending buffer in error state. The pipeline handler shall complete\n+ * the cancelled buffers to notice the application.\n */\n void Request::Private::cancel()\n {\n@@ -323,6 +318,11 @@ void Request::Private::timeout()\n * \\brief A map of Stream to FrameBuffer pointers\n */\n \n+/**\n+ * \\typedef Request::ResultList\n+ * \\brief A list partial results associated with a request\n+ */\n+\n /**\n * \\class Request\n * \\brief A frame capture request\n@@ -394,6 +394,7 @@ void Request::reuse(ReuseFlag flags)\n \n \tstatus_ = RequestPending;\n \n+\tresults_.clear();\n \tcontrols_->clear();\n \tmetadata_->clear();\n }\n@@ -424,6 +425,12 @@ void Request::reuse(ReuseFlag flags)\n * \\return The map of Stream to FrameBuffer\n */\n \n+/**\n+ * \\fn Request::resultList()\n+ * \\brief Retrieve the request's partial results\n+ * \\return A reference to the list of results that associates with the request\n+ */\n+\n /**\n * \\brief Add a FrameBuffer with its associated Stream to the Request\n * \\param[in] stream The stream the buffer belongs to\n@@ -489,6 +496,20 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer,\n \treturn 0;\n }\n \n+/**\n+ * \\brief Add result into the internal result list\n+ * \\param[in] result The result to add into the request\n+ *\n+ * The function only accepts rvalue and moves its content into the request\n+ *\n+ * \\return The result moved into the request\n+ */\n+Result *Request::addResult(Result &&result)\n+{\n+\tresults_.emplace_back(std::move(result));\n+\treturn &results_.back();\n+}\n+\n /**\n * \\var Request::bufferMap_\n * \\brief Mapping of streams to buffers for this request\n@@ -513,6 +534,21 @@ FrameBuffer *Request::findBuffer(const Stream *stream) const\n \treturn it->second;\n }\n \n+/**\n+ * \\brief Return the stream associated with a buffer\n+ * \\param[in] buffer The buffer the stream is associated to\n+ * \\return The stream associated with the buffer, or nullptr if the buffer is\n+ * not part of this request\n+ */\n+const Stream *Request::findStream(const FrameBuffer *buffer) const\n+{\n+\tfor (auto &[key, value] : bufferMap_)\n+\t\tif (buffer == value)\n+\t\t\treturn key;\n+\n+\treturn nullptr;\n+}\n+\n /**\n * \\fn Request::metadata()\n * \\brief Retrieve the request's metadata\n@@ -606,4 +642,122 @@ std::ostream &operator<<(std::ostream &out, const Request &r)\n \treturn out;\n }\n \n+/**\n+ * \\class Result\n+ * \\brief A partial result of a frame capture request\n+ *\n+ * A Result allows pipeline handler to report partial results to the application\n+ */\n+\n+/**\n+ * \\brief Create a partial result for a capture request\n+ * \\param[in] request The request the result associated to\n+ */\n+Result::Result(Request *request)\n+\t: request_(request)\n+{\n+}\n+\n+/**\n+ * \\brief Move constructor of a Result\n+ * \\param[in] result The other result\n+ */\n+Result::Result(Result &&result) = default;\n+\n+Result::~Result() = default;\n+\n+/**\n+ * \\fn Result::request()\n+ * \\brief Retrieve the result's associated request\n+ * \\return The Request pointer associated with the result\n+ */\n+\n+/**\n+ * \\fn Result::metadata()\n+ * \\brief Retrieve the result's metadata\n+ * \\return The metadata contained in the result\n+ */\n+\n+/**\n+ * \\fn Result::buffers()\n+ * \\brief Retrieve the result's buffers\n+ * \\return The buffers contained in the result\n+ */\n+\n+/**\n+ * \\fn Result::set(const Control<T> &ctrl, const V &value)\n+ * \\brief Set the control \\a ctrl value to \\a value into metadata\n+ * \\param[in] ctrl The control\n+ * \\param[in] value The control value\n+ */\n+\n+/**\n+ * \\brief Add a FrameBuffer with its associated Stream to the Result\n+ * \\param[in] buffer The FrameBuffer to add to the result\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -EINVAL The buffer does not reference a valid Stream in the request\n+ */\n+int Result::addBuffer(FrameBuffer *buffer)\n+{\n+\tif (!buffer || !request_->findStream(buffer)) {\n+\t\tLOG(Request, Error) << \"Invalid buffer reference\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tbuffers_.emplace_back(buffer);\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Set the control \\a id to \\a value\n+ * \\param[in] id The control id\n+ * \\param[in] value The control value\n+ */\n+void Result::set(unsigned int id, const ControlValue &value)\n+{\n+\tmetadata_.set(id, value);\n+}\n+\n+/**\n+ * \\brief Merge the \\a source into the metadata of the result\n+ * \\param[in] source The ControlList to merge into this metadata\n+ */\n+void Result::merge(const ControlList &source)\n+{\n+\tmetadata_.merge(source);\n+}\n+\n+/**\n+ * \\brief Generate a string representation of the Result internals\n+ *\n+ * This function facilitates debugging of Result state while it is used\n+ * internally within libcamera.\n+ *\n+ * \\return A string representing the current state of the result\n+ */\n+std::string Result::toString() const\n+{\n+\tstd::stringstream ss;\n+\tss << *this;\n+\n+\treturn ss.str();\n+}\n+\n+/**\n+ * \\brief Insert a text representation of a Result into an output stream\n+ * \\param[in] out The output stream\n+ * \\param[in] r The Result\n+ * \\return The output stream \\a out\n+ */\n+std::ostream &operator<<(std::ostream &out, const Result &r)\n+{\n+\t/* Example Output: Result(55:1/2) */\n+\tout << \"Result(\" << r.request()->sequence() << \":\"\n+\t << r.buffers().size() << \"/\"\n+\t << const_cast<Result &>(r).metadata().size() << \")\";\n+\n+\treturn out;\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v2", "2/7" ] }