Show a patch.

GET /api/1.1/patches/21244/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 21244,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21244/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21244/",
    "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": "<20240912045703.3446748-2-chenghaoyang@google.com>",
    "date": "2024-09-12T04:52:48",
    "name": "[1/1] libcamera: Camera: Add signals for completion of metadata as a partial result",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "46fb2e1b458c5e1caa14002b105a8c43d9c2e28d",
    "submitter": {
        "id": 117,
        "url": "https://patchwork.libcamera.org/api/1.1/people/117/?format=api",
        "name": "Cheng-Hao Yang",
        "email": "chenghaoyang@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21244/mbox/",
    "series": [
        {
            "id": 4583,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4583/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4583",
            "date": "2024-09-12T04:52:47",
            "name": "Add metadataCompleted Signal in Camera",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4583/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21244/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21244/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 CDBFBC324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Sep 2024 04:57:16 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6C4F7634FF;\n\tThu, 12 Sep 2024 06:57:16 +0200 (CEST)",
            "from mail-pl1-x629.google.com (mail-pl1-x629.google.com\n\t[IPv6:2607:f8b0:4864:20::629])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D5C8634FB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 12 Sep 2024 06:57:12 +0200 (CEST)",
            "by mail-pl1-x629.google.com with SMTP id\n\td9443c01a7336-205659dc63aso6515705ad.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Sep 2024 21:57:12 -0700 (PDT)",
            "from chenghaoyang-low.c.googlers.com.com\n\t(0.223.81.34.bc.googleusercontent.com. [34.81.223.0])\n\tby smtp.gmail.com with ESMTPSA id\n\td9443c01a7336-2076b01af1esm7048155ad.293.2024.09.11.21.57.08\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 11 Sep 2024 21:57:09 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"f6nt8X2z\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1726117030; x=1726721830;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=BJ0z8FK6KSwDQUsR4EdR1clLIHZLI81svcaWeS6aSpY=;\n\tb=f6nt8X2zfUHg+0QHbQgoD9Re8DkWtn2oZzYPRV1d6Mh1/hgSsKedZ8VRY9Jnu+wOFj\n\twdIWkch6y0It5ypbgkUZv1IskB1Ubnb3KP6gi1SbhKIRqwSKScGvAz54pSg3CyNqzVNM\n\tmNSGzJKv5e/eg8g4OQecH2EgNARjfa5TSZrqg=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1726117030; x=1726721830;\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\t:subject:date:message-id:reply-to;\n\tbh=BJ0z8FK6KSwDQUsR4EdR1clLIHZLI81svcaWeS6aSpY=;\n\tb=nmbQO3z43B6rHNDqpwL4Jb4etG/b3PH9JTvIVRpfFLyeXstmMAySqsMeDWJ3woebgq\n\tP40WVV9mLKQEW84qZ9bPTYMk2VP6L5BsTOpnIRYAq9uRjWj5VWaAkmZK3/OSVzzIKyNx\n\tHnjA9Aiv5QX3DqfmDs1L1fyg0qQhgg3MXiRHv4ImhMbR0mcep81sV2b/YkuR0iu9hvWX\n\t/AqygJVe//oGnlf/suTxxj2nOZfK1ksg4F3rnsUEiSc01ggRBdaAkh+CMuhy9Z3vgzfE\n\t8+mfVvBOkVw+yO1rZSL/QbR/zVUixV3MFe791xh7WWgwSwUONd2PeWIC7EFE0Ojve7hs\n\tVS7w==",
        "X-Gm-Message-State": "AOJu0Yy2xWT+j+zUAVa3SXuQ+6855BOk1d5q7AcF9jhIW1CsozleiHwy\n\t7jy5l7KlEf2kQVZLQ+tZ0DmFvsWLJ/iIItU6jsP7UvF9fgTOvL6VgGtJtCl/0bwMiOlAxBYaEAI\n\t=",
        "X-Google-Smtp-Source": "AGHT+IF93NYxFqCx/9qIsabJejnWEvCqc8M/NmR3sKwkALi2wEPViQabBVRNuhKTEpnS3HJ+H16dBQ==",
        "X-Received": "by 2002:a17:903:2281:b0:201:f8b4:3e3c with SMTP id\n\td9443c01a7336-2076e36c158mr28888005ad.12.1726117029686; \n\tWed, 11 Sep 2024 21:57:09 -0700 (PDT)",
        "From": "Harvey Yang <chenghaoyang@chromium.org>",
        "X-Google-Original-From": "Harvey Yang <chenghaoyang@google.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Han-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>",
        "Subject": "[PATCH 1/1] libcamera: Camera: Add signals for completion of\n\tmetadata as a partial result",
        "Date": "Thu, 12 Sep 2024 04:52:48 +0000",
        "Message-ID": "<20240912045703.3446748-2-chenghaoyang@google.com>",
        "X-Mailer": "git-send-email 2.46.0.598.g6f2099f65c-goog",
        "In-Reply-To": "<20240912045703.3446748-1-chenghaoyang@google.com>",
        "References": "<20240912045703.3446748-1-chenghaoyang@google.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": "From: Han-Lin Chen <hanlinchen@chromium.org>\n\nAllows pipeline handler to signal metadata completion by adding the\nfollowing signals to Camera:\n\nSignal<Request *, const ControlList &> metadataCompleted;\n\nTogether with the bufferCompleted signal, the pipeline handler is allowed to\nreturn buffers and partial metadata at any stage of processing.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\nCo-developed-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n include/libcamera/camera.h                    |  1 +\n include/libcamera/internal/pipeline_handler.h |  1 +\n include/libcamera/request.h                   |  5 +++\n src/libcamera/camera.cpp                      |  6 +++\n src/libcamera/pipeline_handler.cpp            | 37 +++++++++++++++++++\n src/libcamera/request.cpp                     | 20 ++++++++++\n 6 files changed, 70 insertions(+)",
    "diff": "diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex 94cee7bd..08c5c58c 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -122,6 +122,7 @@ public:\n \n \tconst std::string &id() const;\n \n+\tSignal<Request *, const ControlList &> metadataCompleted;\n \tSignal<Request *, FrameBuffer *> bufferCompleted;\n \tSignal<Request *> requestCompleted;\n \tSignal<> disconnected;\ndiff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex 0d380803..1af63a23 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -58,6 +58,7 @@ 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 completeRequest(Request *request);\n \ndiff --git a/include/libcamera/request.h b/include/libcamera/request.h\nindex e214a9d1..0200f4a1 100644\n--- a/include/libcamera/request.h\n+++ b/include/libcamera/request.h\n@@ -12,6 +12,7 @@\n #include <ostream>\n #include <stdint.h>\n #include <string>\n+#include <unordered_set>\n \n #include <libcamera/base/class.h>\n #include <libcamera/base/signal.h>\n@@ -64,6 +65,8 @@ public:\n \n \tstd::string toString() const;\n \n+\tControlList addCompletedMetadata(const ControlList &metadata);\n+\n private:\n \tLIBCAMERA_DISABLE_COPY(Request)\n \n@@ -73,6 +76,8 @@ private:\n \n \tconst uint64_t cookie_;\n \tStatus status_;\n+\n+\tstd::unordered_set<unsigned int> completedMetadata_;\n };\n \n std::ostream &operator<<(std::ostream &out, const Request &r);\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex a86f552a..5ffae23e 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -892,6 +892,12 @@ const std::string &Camera::id() const\n  * completed\n  */\n \n+/**\n+ * \\var Camera::metadataCompleted\n+ * \\brief Signal emitted when some metadata for a request is completed as a\n+ * partial result\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 e5940469..5d2999cb 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -535,6 +535,28 @@ bool PipelineHandler::completeBuffer(Request *request, FrameBuffer *buffer)\n \treturn request->_d()->completeBuffer(buffer);\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.\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ */\n+void PipelineHandler::completeMetadata(Request *request, const ControlList &metadata)\n+{\n+\tconst ControlList &validMetadata = request->addCompletedMetadata(metadata);\n+\tif (!validMetadata.empty()) {\n+\t\trequest->metadata().merge(validMetadata);\n+\n+\t\tCamera *camera = request->_d()->camera();\n+\t\tcamera->metadataCompleted.emit(request, validMetadata);\n+\t}\n+}\n+\n /**\n  * \\brief Signal request completion\n  * \\param[in] request The request that has completed\n@@ -557,6 +579,21 @@ 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() to report metadata.\n+\t */\n+\tconst ControlList &validMetadata = request->addCompletedMetadata(\n+\t\trequest->metadata());\n+\tif (!validMetadata.empty())\n+\t\tcamera->metadataCompleted.emit(request, validMetadata);\n+\n \twhile (!data->queuedRequests_.empty()) {\n \t\tRequest *req = data->queuedRequests_.front();\n \t\tif (req->status() == Request::RequestPending)\ndiff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp\nindex 8c56ed30..3ce23a8e 100644\n--- a/src/libcamera/request.cpp\n+++ b/src/libcamera/request.cpp\n@@ -598,6 +598,26 @@ std::string Request::toString() const\n \treturn ss.str();\n }\n \n+/**\n+ * \\brief Add completed metadata, as a partial result\n+ * \\param[in] metadata The metadata completed\n+ *\n+ * Request will record the entries that has been sent to the application, to\n+ * prevent duplicated controls.\n+ *\n+ * \\return ControlList that hasn't been completed before\n+ */\n+ControlList Request::addCompletedMetadata(const ControlList &metadata)\n+{\n+\tControlList resultMetadata;\n+\tfor (auto &[id, value] : metadata) {\n+\t\tif (!completedMetadata_.count(id))\n+\t\t\tresultMetadata.set(id, value);\n+\t}\n+\n+\treturn resultMetadata;\n+}\n+\n /**\n  * \\brief Insert a text representation of a Request into an output stream\n  * \\param[in] out The output stream\n",
    "prefixes": [
        "1/1"
    ]
}