Show a patch.

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

{
    "id": 24468,
    "url": "https://patchwork.libcamera.org/api/patches/24468/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24468/",
    "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": "<20250925221708.7471-7-hansg@kernel.org>",
    "date": "2025-09-25T22:17:08",
    "name": "[v2,6/6] libcamera: software_isp: Run sw-statistics once every 4th frame",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b94c880b315f47e67bba75170d200a84f38e666d",
    "submitter": {
        "id": 239,
        "url": "https://patchwork.libcamera.org/api/people/239/?format=api",
        "name": "Hans de Goede",
        "email": "hansg@kernel.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24468/mbox/",
    "series": [
        {
            "id": 5459,
            "url": "https://patchwork.libcamera.org/api/series/5459/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5459",
            "date": "2025-09-25T22:17:02",
            "name": "ipa: software_isp: AGC: Fox AGC oscillation bug",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5459/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24468/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24468/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 C502DC3333\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Sep 2025 22:17:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F145F6B60E;\n\tFri, 26 Sep 2025 00:17:32 +0200 (CEST)",
            "from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 007EF6B60F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Sep 2025 00:17:20 +0200 (CEST)",
            "from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby sea.source.kernel.org (Postfix) with ESMTP id DD8264561F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Sep 2025 22:17:19 +0000 (UTC)",
            "by smtp.kernel.org (Postfix) with ESMTPSA id 12A01C4CEF7;\n\tThu, 25 Sep 2025 22:17:18 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=kernel.org header.i=@kernel.org\n\theader.b=\"uRc9mwiv\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1758838639;\n\tbh=RH0Hcg13gyC2TYAJCCRxUwCSNWWjHlPrrMNTnoh9sgQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=uRc9mwivHLDvzHvjUesUfLu6s1RjT0ZHWsGxRvjyH8KLFrmDqZWXuWXnecwGzXw5I\n\tev8hvSRH0iBhGfyR7OJQVS7XJUaXUo3E5GW93cywTc52ZX02fWJGestegIE53qQWpg\n\t7i60zURpp2cg4N2ChgeYczGzqLBI0xg47F5mQZVtGsJbFidPmvy6jwQWNepnDzNbY1\n\txzFl+oFuGoLdm8AyI16OLfaEyS/lpWeMCbdKkqXq+YzOIS9gOqJpeXL62w7RR9h2kX\n\tI9NI48ReGgXKDsyT4nCe+ZjIvntbTbMN8VzD4TLvCrffD5vW4Bh/K4094Mz2X/ZRt+\n\thAnvPSmMOwrqA==",
        "From": "Hans de Goede <hansg@kernel.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Hans de Goede <hansg@kernel.org>",
        "Subject": "[PATCH v2 6/6] libcamera: software_isp: Run sw-statistics once every\n\t4th frame",
        "Date": "Fri, 26 Sep 2025 00:17:08 +0200",
        "Message-ID": "<20250925221708.7471-7-hansg@kernel.org>",
        "X-Mailer": "git-send-email 2.51.0",
        "In-Reply-To": "<20250925221708.7471-1-hansg@kernel.org>",
        "References": "<20250925221708.7471-1-hansg@kernel.org>",
        "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": "Run sw-statistics once every 4th frame, instead of every frame. There are\n2 reasons for this:\n\n1. There really is no need to have statistics for every frame and only\ndoing this every 4th frame helps save some CPU time.\n\n2. The generic nature of the simple pipeline-handler, so no information\nabout possible CSI receiver frame-delays. In combination with the software\nISP often being used with sensors without sensor info in the sensor-helper\ncode, so no reliable control-delay information means that the software ISP\nis prone to AGC oscillation. Skipping statistics gathering also means\nskipping running the AGC algorithm slowing it down, avoiding this\noscillation.\n\nNote ideally the AGC oscillation problem would be fixed by adding sensor\nmetadata support all through the stack so that the exact gain and exposure\nused for a specific frame are reliably provided by the sensor metadata.\n\nSigned-off-by: Hans de Goede <hansg@kernel.org>\n---\n src/libcamera/software_isp/debayer_cpu.cpp | 25 +++++++++++++---------\n src/libcamera/software_isp/debayer_cpu.h   |  4 ++--\n src/libcamera/software_isp/swstats_cpu.cpp |  5 +++++\n src/libcamera/software_isp/swstats_cpu.h   |  3 +++\n 4 files changed, 25 insertions(+), 12 deletions(-)",
    "diff": "diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex bfa60888..9010333e 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -655,7 +655,7 @@ void DebayerCpu::memcpyNextLine(const uint8_t *linePointers[])\n \tlineBufferIndex_ = (lineBufferIndex_ + 1) % (patternHeight + 1);\n }\n \n-void DebayerCpu::process2(const uint8_t *src, uint8_t *dst)\n+void DebayerCpu::process2(uint32_t frame, const uint8_t *src, uint8_t *dst)\n {\n \tunsigned int yEnd = window_.y + window_.height;\n \t/* Holds [0] previous- [1] current- [2] next-line */\n@@ -681,7 +681,8 @@ void DebayerCpu::process2(const uint8_t *src, uint8_t *dst)\n \tfor (unsigned int y = window_.y; y < yEnd; y += 2) {\n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine0(y, linePointers);\n+\t\tif (frame % SwStatsCpu::kStatPerNumFrames == 0)\n+\t\t\tstats_->processLine0(y, linePointers);\n \t\t(this->*debayer0_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n@@ -696,7 +697,8 @@ void DebayerCpu::process2(const uint8_t *src, uint8_t *dst)\n \tif (window_.y == 0) {\n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine0(yEnd, linePointers);\n+\t\tif (frame % SwStatsCpu::kStatPerNumFrames == 0)\n+\t\t\tstats_->processLine0(yEnd, linePointers);\n \t\t(this->*debayer0_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n@@ -710,7 +712,7 @@ void DebayerCpu::process2(const uint8_t *src, uint8_t *dst)\n \t}\n }\n \n-void DebayerCpu::process4(const uint8_t *src, uint8_t *dst)\n+void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst)\n {\n \tconst unsigned int yEnd = window_.y + window_.height;\n \t/*\n@@ -733,7 +735,8 @@ void DebayerCpu::process4(const uint8_t *src, uint8_t *dst)\n \tfor (unsigned int y = window_.y; y < yEnd; y += 4) {\n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine0(y, linePointers);\n+\t\tif (frame % SwStatsCpu::kStatPerNumFrames == 0)\n+\t\t\tstats_->processLine0(y, linePointers);\n \t\t(this->*debayer0_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n@@ -746,7 +749,8 @@ void DebayerCpu::process4(const uint8_t *src, uint8_t *dst)\n \n \t\tshiftLinePointers(linePointers, src);\n \t\tmemcpyNextLine(linePointers);\n-\t\tstats_->processLine2(y, linePointers);\n+\t\tif (frame % SwStatsCpu::kStatPerNumFrames == 0)\n+\t\t\tstats_->processLine2(y, linePointers);\n \t\t(this->*debayer2_)(dst, linePointers);\n \t\tsrc += inputConfig_.stride;\n \t\tdst += outputConfig_.stride;\n@@ -821,12 +825,13 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \t\treturn;\n \t}\n \n-\tstats_->startFrame();\n+\tif (frame % SwStatsCpu::kStatPerNumFrames == 0)\n+\t\tstats_->startFrame();\n \n \tif (inputConfig_.patternSize.height == 2)\n-\t\tprocess2(in.planes()[0].data(), out.planes()[0].data());\n+\t\tprocess2(frame, in.planes()[0].data(), out.planes()[0].data());\n \telse\n-\t\tprocess4(in.planes()[0].data(), out.planes()[0].data());\n+\t\tprocess4(frame, in.planes()[0].data(), out.planes()[0].data());\n \n \tmetadata.planes()[0].bytesused = out.planes()[0].size();\n \n@@ -851,7 +856,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \t *\n \t * \\todo Pass real bufferId once stats buffer passing is changed.\n \t */\n-\tstats_->finishFrame(frame, 0, true);\n+\tstats_->finishFrame(frame, 0, frame % SwStatsCpu::kStatPerNumFrames == 0);\n \toutputBufferReady.emit(output);\n \tinputBufferReady.emit(input);\n }\ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 9d343e46..03e0d784 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -133,8 +133,8 @@ private:\n \tvoid setupInputMemcpy(const uint8_t *linePointers[]);\n \tvoid shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src);\n \tvoid memcpyNextLine(const uint8_t *linePointers[]);\n-\tvoid process2(const uint8_t *src, uint8_t *dst);\n-\tvoid process4(const uint8_t *src, uint8_t *dst);\n+\tvoid process2(uint32_t frame, const uint8_t *src, uint8_t *dst);\n+\tvoid process4(uint32_t frame, const uint8_t *src, uint8_t *dst);\n \n \t/* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */\n \tstatic constexpr unsigned int kMaxLineBuffers = 5;\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex da91f912..35ba0a46 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -89,6 +89,11 @@ namespace libcamera {\n  * \\brief Signals that the statistics are ready\n  */\n \n+/**\n+ * \\var SwStatsCpu::kStatPerNumFrames\n+ * \\brief Run stats once every kStatPerNumFrames frames\n+ */\n+\n /**\n  * \\typedef SwStatsCpu::statsProcessFn\n  * \\brief Called when there is data to get statistics from\ndiff --git a/src/libcamera/software_isp/swstats_cpu.h b/src/libcamera/software_isp/swstats_cpu.h\nindex 6ac3c4de..ea0e6d5a 100644\n--- a/src/libcamera/software_isp/swstats_cpu.h\n+++ b/src/libcamera/software_isp/swstats_cpu.h\n@@ -32,6 +32,9 @@ public:\n \tSwStatsCpu();\n \t~SwStatsCpu() = default;\n \n+\t/* Run stats once every 4 frames */\n+\tstatic constexpr uint32_t kStatPerNumFrames = 4;\n+\n \tbool isValid() const { return sharedStats_.fd().isValid(); }\n \n \tconst SharedFD &getStatsFD() { return sharedStats_.fd(); }\n",
    "prefixes": [
        "v2",
        "6/6"
    ]
}