Show a patch.

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

{
    "id": 16139,
    "url": "https://patchwork.libcamera.org/api/patches/16139/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16139/",
    "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": "<20220603132259.188845-3-umang.jain@ideasonboard.com>",
    "date": "2022-06-03T13:22:57",
    "name": "[libcamera-devel,v1,2/4] ipa: ipu3: ipa_context: Extend FCQueue::get()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "3e41d667759a14ade3c361b5169f74877a047f92",
    "submitter": {
        "id": 86,
        "url": "https://patchwork.libcamera.org/api/people/86/?format=api",
        "name": "Umang Jain",
        "email": "umang.jain@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16139/mbox/",
    "series": [
        {
            "id": 3157,
            "url": "https://patchwork.libcamera.org/api/series/3157/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3157",
            "date": "2022-06-03T13:22:55",
            "name": "Move frame contexts queue to separate class",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3157/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16139/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16139/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 BC8FEC326D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Jun 2022 13:23:09 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8E05860105;\n\tFri,  3 Jun 2022 15:23:08 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FC8A6040E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Jun 2022 15:23:06 +0200 (CEST)",
            "from perceval.ideasonboard.com\n\t(static-127-186-62-95.ipcom.comunitel.net [95.62.186.127])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 08FDD10DD;\n\tFri,  3 Jun 2022 15:23:05 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1654262588;\n\tbh=+VLfXU/12xLb9bTzefRzNmnud605OTY0ljKOxSSuNbE=;\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=EfET7njHoLNEipLZ/47AGQICu9Wi6QTh974sxt3enJ68K4DM+R5gKxUHALZ+N1VWa\n\tEW3A7/v+a8cq7kRhb4H91/RLOEWsKDfaXK/ZKNgZPa5Sog0esUgYC5ht8U9BNlYNmY\n\taeFiBsdFTWy+G1AHFJgnh+fpOYUc9aQsKPW6Fu0kctiaoQbvHLMDDEE0I6oiT3tkWD\n\tavoc0TwSsnKCDlLqGRuTp1hKBQ+GErkWtNGZYx1aPiAPwjDoqCEhztKZ4UT2jD/sVz\n\tNKH14rjnCZr9ZzauS1Z8QZiq6ZsClYTlcgrBOJ3OQWl3mPeZUK0sTxV/oL9qPdpaNu\n\taa2diHnn+2P4Q==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1654262586;\n\tbh=+VLfXU/12xLb9bTzefRzNmnud605OTY0ljKOxSSuNbE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ozbrhxRgsnWfGRr0JDxUsuSXgj5u8afCxPAJQIcVNxRH0JWCXWUNA344UbVLsCvOv\n\tCG/2Dzz5P9KbeRwcK8JrAJbizhrH9VWroAEdIXsTMbihQuLAb3psSrzVDPCB3FBqrL\n\t4YIRmM2SDKyoCapFlimyzq379asW4b2ZNc8ZCeqI="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ozbrhxRg\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  3 Jun 2022 15:22:57 +0200",
        "Message-Id": "<20220603132259.188845-3-umang.jain@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.31.1",
        "In-Reply-To": "<20220603132259.188845-1-umang.jain@ideasonboard.com>",
        "References": "<20220603132259.188845-1-umang.jain@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v1 2/4] ipa: ipu3: ipa_context: Extend\n\tFCQueue::get()",
        "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": "Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Umang Jain <umang.jain@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Extend the FCQueue::get() to return a IPAFrameContext for a\nnon-existent frame. The .get() should be able to figure out if a\nexistent frame context is asked for, or to create a new frame context\nbased on the next available position. To keep track of next available\nposition in the queue, use of head and tail pointer are used.\n\nWe specifically want to have access to the queue through the\n.get() function hence operator[] is deleted for FCQueue as\npart of this patch as well.\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n src/ipa/ipu3/ipa_context.cpp | 95 +++++++++++++++++++++++++++++++++---\n src/ipa/ipu3/ipa_context.h   |  9 ++++\n src/ipa/ipu3/ipu3.cpp        |  4 +-\n 3 files changed, 100 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\nindex 9f95a61c..2438d68d 100644\n--- a/src/ipa/ipu3/ipa_context.cpp\n+++ b/src/ipa/ipu3/ipa_context.cpp\n@@ -222,13 +222,33 @@ IPAFrameContext::IPAFrameContext(uint32_t id, const ControlList &reqControls)\n  * \\brief A FIFO circular queue holding IPAFrameContext(s)\n  *\n  * FCQueue holds all the IPAFrameContext(s) related to frames required\n- * to be processed by the IPA at a given point.\n+ * to be processed by the IPA at a given point. An IPAFrameContext is created\n+ * on the first call FCQueue::get(frame) for that frame. Subsequent calls to\n+ * FCQueue::get() with the same frame number shall return the IPAFrameContext\n+ * previously created until the frame is marked as complete through\n+ * FCQueue::completeFrame(frame).\n+ */\n+\n+/**\n+ * \\var FCQueue::head_\n+ * \\brief A pointer to the a IPAFrameContext next expected to complete\n+ */\n+\n+/**\n+ * \\var FCQueue::tail_\n+ * \\brief A pointer to the latest IPAFrameContext created\n+ */\n+\n+/**\n+ * \\var FCQueue::isFull_\n+ * \\brief Flag set when the FCQueue is full\n  */\n \n /**\n  * \\brief FCQueue constructor\n  */\n FCQueue::FCQueue()\n+\t: head_(nullptr), tail_(nullptr), isFull_(false)\n {\n \tclear();\n }\n@@ -238,21 +258,75 @@ FCQueue::FCQueue()\n  * \\param[in] frame Frame number for which the IPAFrameContext needs to\n  * retrieved\n  *\n- * \\return Pointer to the IPAFrameContext\n+ * This function returns the IPAFrameContext for the desired frame. If the\n+ * frame context does not exist in the queue, the next available slot in the\n+ * queue is returned. It is the responsibility of the caller to fill the correct\n+ * IPAFrameContext parameters of newly returned IPAFrameContext.\n+ *\n+ * \\return Pointer to the IPAFrameContext or nullptr if frame context couldn't\n+ * be created\n  */\n IPAFrameContext *FCQueue::get(uint32_t frame)\n {\n-\tIPAFrameContext &frameContext = this->at(frame % kMaxFrameContexts);\n+\tif (frame <= tail_->frame) {\n+\t\tIPAFrameContext &frameContext = this->at(frame % kMaxFrameContexts);\n+\t\tif (frame != frameContext.frame)\n+\t\t\tLOG(IPAIPU3, Warning)\n+\t\t\t\t<< \"Got wrong frame context for frame \" << frame;\n+\n+\t\treturn &frameContext;\n+\t} else {\n+\t\tif (isFull_) {\n+\t\t\tLOG(IPAIPU3, Warning)\n+\t\t\t\t<< \"Cannot create frame context for frame \" << frame\n+\t\t\t\t<< \" since FCQueue is full\";\n+\n+\t\t\treturn nullptr;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Frame context doesn't exist yet so get the next available\n+\t\t * position in the queue.\n+\t\t */\n+\t\ttail_ = &this->at((tail_->frame + 1) % kMaxFrameContexts);\n+\t\ttail_->frame = frame;\n+\n+\t\t/* Check if the queue is full to avoid over-queueing later */\n+\t\tif (tail_->frame - head_->frame >= kMaxFrameContexts - 1)\n+\t\t\tisFull_ = true;\n \n-\tif (frame != frameContext.frame) {\n+\t\treturn tail_;\n+\t}\n+}\n+\n+/**\n+ * \\brief Notifies the FCQueue that a frame has been completed\n+ * \\param[in] frame The completed frame number\n+ */\n+void FCQueue::completeFrame(uint32_t frame)\n+{\n+\tif (head_->frame != frame)\n \t\tLOG(IPAIPU3, Warning)\n-\t\t\t<< \"Got wrong frame context for frame\" << frame\n-\t\t\t<< \" or frame context doesn't exist yet\";\n+\t\t\t<< \"Frame \" << frame << \" completed out-of-sync?\";\n+\n+\tif (frame > tail_->frame) {\n+\t\tLOG(IPAIPU3, Error)\n+\t\t\t<< \"Completing a frame \" << frame\n+\t\t\t<< \" not present in the queue is disallowed\";\n+\t\treturn;\n \t}\n \n-\treturn &frameContext;\n+\thead_ = this->get(frame + 1);\n+\n+\tif (isFull_)\n+\t\tisFull_ = false;\n }\n \n+/**\n+ * \\fn FCQueue::isFull()\n+ * \\brief Checks whether the frame context queue is full\n+ */\n+\n /**\n  * \\brief Clear the FCQueue by resetting all the entries in the ring-buffer\n  */\n@@ -260,6 +334,13 @@ void FCQueue::clear()\n {\n \tIPAFrameContext initFrameContext;\n \tthis->fill(initFrameContext);\n+\n+\tisFull_ = false;\n+\n+\t/* Intialise 0th index to frame 0 */\n+\tthis->at(0).frame = 0;\n+\ttail_ = &this->at(0);\n+\thead_ = tail_;\n }\n \n } /* namespace ipa::ipu3 */\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 56d281f6..475855da 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -93,9 +93,18 @@ class FCQueue : public std::array<IPAFrameContext, kMaxFrameContexts>\n {\n public:\n \tFCQueue();\n+\tFCQueue &operator[](const FCQueue &) = delete;\n \n \tvoid clear();\n+\tvoid completeFrame(uint32_t frame);\n \tIPAFrameContext *get(uint32_t frame);\n+\tbool isFull() { return isFull_; }\n+\n+private:\n+\tIPAFrameContext *head_;\n+\tIPAFrameContext *tail_;\n+\n+\tbool isFull_;\n };\n \n struct IPAContext {\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 0843d882..1d6ee515 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -605,6 +605,8 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame,\n \t */\n \n \tmetadataReady.emit(frame, ctrls);\n+\n+\tcontext_.frameContexts.completeFrame(frame);\n }\n \n /**\n@@ -618,7 +620,7 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame,\n void IPAIPU3::queueRequest(const uint32_t frame, const ControlList &controls)\n {\n \t/* \\todo Start processing for 'frame' based on 'controls'. */\n-\tcontext_.frameContexts[frame % kMaxFrameContexts] = { frame, controls };\n+\t*context_.frameContexts.get(frame) = { frame, controls };\n }\n \n /**\n",
    "prefixes": [
        "libcamera-devel",
        "v1",
        "2/4"
    ]
}