Show a patch.

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

{
    "id": 26691,
    "url": "https://patchwork.libcamera.org/api/patches/26691/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/26691/",
    "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": "<20260508130804.8238-2-david.plowman@raspberrypi.com>",
    "date": "2026-05-08T12:57:41",
    "name": "[v5,1/3] pipeline: rpi: Simplify delayed controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "118d6df606795b38292c25a09b55b1d06020b47c",
    "submitter": {
        "id": 42,
        "url": "https://patchwork.libcamera.org/api/people/42/?format=api",
        "name": "David Plowman",
        "email": "david.plowman@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/26691/mbox/",
    "series": [
        {
            "id": 5924,
            "url": "https://patchwork.libcamera.org/api/series/5924/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5924",
            "date": "2026-05-08T12:57:40",
            "name": "Atomic control lists on Raspberry Pi",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/5924/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/26691/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/26691/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 D5796BDCBD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  8 May 2026 13:08:11 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1D26F6301A;\n\tFri,  8 May 2026 15:08:10 +0200 (CEST)",
            "from mail-wm1-x334.google.com (mail-wm1-x334.google.com\n\t[IPv6:2a00:1450:4864:20::334])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B67DD62FE1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 May 2026 15:08:07 +0200 (CEST)",
            "by mail-wm1-x334.google.com with SMTP id\n\t5b1f17b1804b1-48a7fe4f40bso21547685e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 08 May 2026 06:08:07 -0700 (PDT)",
            "from localhost.localdomain ([2a06:61c0:f337:0:9c1f:b517:931a:3b19])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-48e68f5d9b5sm34044905e9.15.2026.05.08.06.08.06\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 08 May 2026 06:08:06 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"J/06+Mj+\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1778245687; x=1778850487;\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=B/6c4x6aPmSj4hSBbdqWEJNfL9gt9CXnVpTwIUpnx7A=;\n\tb=J/06+Mj+lT+FyhgOldADVQqllQW+b3fxVGBvhhfRtMOxm91OOUILYWcMNmG7Y/2vDG\n\tNAHizb8RmlXY0k8GALU2ZWiskh2n5/CxAYqxQlY6sPr5n7WDjxfwYhSBuaLi33ih48Zi\n\tCHmgV8rJnhWuKRW41Jb0kUdP3/gFbIoKOFTydHj5HrWM7j6T3QM2SPK5JzYJUdTT3km7\n\tTqH/icAW+348EiIu2kaZD3UiXcjYtxQDLA+IAYkSzG72hQ8Up62107jqxxrLcbR+/0pJ\n\tQyXqReCD1mrACbDgCalOwBAWVPCS4HRX39UVeBCTHkJOY2BZv5xnCnqWd2I2jS1s1r02\n\tvW7Q==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1778245687; x=1778850487;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=B/6c4x6aPmSj4hSBbdqWEJNfL9gt9CXnVpTwIUpnx7A=;\n\tb=QNoBzCAXToqvVCrxoKQwlACRhpRNv17s2elMXfokRtBj03kCvJ+CSGE5FYuc3hCeKO\n\tjDVtbm9H0FIladqGICrFsh9nor13cAz4oRc3tDaYIMx3EP5qSrBZCc2Wlk1iy1jKt+k4\n\tc49KbVcKNZ16QnWaEuz/uU+JQtA9uREzxTNZjxL98thNxfR0ocPSdkByFV0ZLS3M77QM\n\tXWq5Z8NKxwdPFK+xLGYrzkOKBbee0CSAYHlL+yEhQl62KdFXwgp79lieAIUbecrnyzeG\n\tX6ITJ/Eorvt04GE3Yt/0p8LsX4ZeVFJi6eb3lCRfX3PoKtsTTlFCJgsqT1ziVczBI++7\n\tjklw==",
        "X-Gm-Message-State": "AOJu0YxVR9XKLkbXlrgYK+hT+NJUOIIzTmxF26o6re672lIQVPsAqkJa\n\ttQUHZU5LFyiMwA2JBlU0F+My2muUYQNqLNgZZTk6faRWPX2N0S0mIxLpyPTRjikVRJwnThMmKjk\n\tlCafR",
        "X-Gm-Gg": "AeBDiets+FT0lpg2L3U8ukt4bkyNEuWip+9bYdvlRH1YLAOuG0yAPcat8IwaeLfNDTL\n\tk99WdDUJnh9eIb1XVxNCSw/Xbup86XVR3wY20KnFgji4zr+GtnlIcMs306SRjY+6llFjy6xFIdq\n\trxUsaoS0m04nrU6u2T8nqDQA0f2px0X+9BO1//P1ayQ52gsHsd9tKG2JKUoYFXN7LnfXJI8/Dxz\n\t21kEJ3qM8LT/lK4yoIJ9ATuNyVzwoW1BEJE816iUmXJd8b0lEM7AvqJYKmBJHw54h9p+52EKQsf\n\ttDPMCk3I0gD4MNnWnXNr2cgkeB+K4IcUeHYTl+SX7NYZGlTRCVk1F0+wUrUH7nCmzQdFBYEC/1O\n\tUoOmyURzY1M+bo+l1Mm8QyKaMc3IJ2ZBZ0ZUsFAs4WXQeqMGzeH9DXhZcAGZ8jYTAVHFHzzqG28\n\tZ70NqzQLUiU0anNg901b9CFhI3L1nFleEJ9XSiSZKBvfDuxthI9PPLi3CD0hiV1IZOdwMLjEEnr\n\tjkpsClSQg9diroKA9oIT661m2HTgbHo/vRjAw==",
        "X-Received": "by 2002:a05:600d:d:b0:489:1ff5:edda with SMTP id\n\t5b1f17b1804b1-48e51e08240mr169742525e9.6.1778245686903; \n\tFri, 08 May 2026 06:08:06 -0700 (PDT)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "David Plowman <david.plowman@raspberrypi.com>,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Subject": "[PATCH v5 1/3] pipeline: rpi: Simplify delayed controls",
        "Date": "Fri,  8 May 2026 13:57:41 +0100",
        "Message-ID": "<20260508130804.8238-2-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.47.3",
        "In-Reply-To": "<20260508130804.8238-1-david.plowman@raspberrypi.com>",
        "References": "<20260508130804.8238-1-david.plowman@raspberrypi.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": "The queueCount_ value is redundant and can be removed.\n\nThe pipeline handler calls the push and applyControls functions in a\nan interleaved manner, so queueCount_ was merely tracking writeCount_,\nand is therefore unnecessary.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n .../pipeline/rpi/common/delayed_controls.cpp  | 62 +++++++++++--------\n .../pipeline/rpi/common/delayed_controls.h    |  1 -\n 2 files changed, 36 insertions(+), 27 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\nindex 19c71946..b647174f 100644\n--- a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n+++ b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n@@ -32,14 +32,15 @@ namespace RPi {\n  *\n  * Some sensor controls take effect with a delay as the sensor needs time to\n  * adjust, for example exposure and analog gain. This is a helper class to deal\n- * with such controls and the intended users are pipeline handlers.\n+ * with such controls.\n  *\n- * The idea is to extend the concept of the buffer depth of a pipeline the\n- * application needs to maintain to also cover controls. Just as with buffer\n- * depth if the application keeps the number of requests queued above the\n- * control depth the controls are guaranteed to take effect for the correct\n- * request. The control depth is determined by the control with the greatest\n- * delay.\n+ * The idea is to maintain a queue of controls that have been submitted.\n+ * Whenever a new frame starts, we can \"peak back\" into this queue to send\n+ * controls at the correct number of frames in advance to account for each\n+ * control's delay.\n+ *\n+ * The overall delay for controls becomes the maximum delay of any of the\n+ * controls.\n  */\n \n /**\n@@ -119,7 +120,6 @@ DelayedControls::DelayedControls(V4L2Device *device,\n  */\n void DelayedControls::reset(unsigned int cookie)\n {\n-\tqueueCount_ = 1;\n \twriteCount_ = 0;\n \tcookies_[0] = cookie;\n \n@@ -146,18 +146,25 @@ void DelayedControls::reset(unsigned int cookie)\n  * \\brief Push a set of controls on the queue\n  * \\param[in] controls List of controls to add to the device queue\n  *\n- * Push a set of controls to the control queue. This increases the control queue\n- * depth by one.\n+ * Push a set of controls to the control queue. The next call to applyControls\n+ * will advance the slot in the queue where the next call to push will write\n+ * controls.\n  *\n  * \\returns true if \\a controls are accepted, or false otherwise\n  */\n bool DelayedControls::push(const ControlList &controls, const unsigned int cookie)\n {\n \t/* Copy state from previous frame. */\n-\tfor (auto &ctrl : values_) {\n-\t\tInfo &info = ctrl.second[queueCount_];\n-\t\tinfo = values_[ctrl.first][queueCount_ - 1];\n-\t\tinfo.updated = false;\n+\tif (writeCount_ > 0) {\n+\t\tfor (auto &ctrl : values_) {\n+\t\t\tInfo &info = ctrl.second[writeCount_];\n+\t\t\tinfo = values_[ctrl.first][writeCount_ - 1];\n+\t\t\tinfo.updated = false;\n+\t\t}\n+\t} else {\n+\t\t/* Although it works, we don't expect this. */\n+\t\tLOG(RPiDelayedControls, Warning)\n+\t\t\t<< \"push called before applyControls\";\n \t}\n \n \t/* Update with new controls. */\n@@ -175,18 +182,17 @@ bool DelayedControls::push(const ControlList &controls, const unsigned int cooki\n \t\tif (controlParams_.find(id) == controlParams_.end())\n \t\t\treturn false;\n \n-\t\tInfo &info = values_[id][queueCount_];\n+\t\tInfo &info = values_[id][writeCount_];\n \n \t\tinfo = Info(control.second);\n \n \t\tLOG(RPiDelayedControls, Debug)\n \t\t\t<< \"Queuing \" << id->name()\n \t\t\t<< \" to \" << info.toString()\n-\t\t\t<< \" at index \" << queueCount_;\n+\t\t\t<< \" at index \" << writeCount_;\n \t}\n \n-\tcookies_[queueCount_] = cookie;\n-\tqueueCount_++;\n+\tcookies_[writeCount_] = cookie;\n \n \treturn true;\n }\n@@ -200,9 +206,9 @@ bool DelayedControls::push(const ControlList &controls, const unsigned int cooki\n  * the callers responsibility to not read too old sequence numbers that have been\n  * pushed out of the history.\n  *\n- * Historic values are evicted by pushing new values onto the queue using\n- * push(). The max history from the current sequence number that yields valid\n- * values are thus 16 minus number of controls pushed.\n+ * Historic values are evicted by new frames arriving and applyControls\n+ * advancing the head of the queue in the ring buffer. The valid history in\n+ * the queue consists of 16 entries from this head of the queue.\n  *\n  * \\return The controls at \\a sequence number\n  */\n@@ -234,6 +240,10 @@ std::pair<ControlList, unsigned int> DelayedControls::get(uint32_t sequence)\n  * number. Any user of these helpers is responsible to inform the helper about\n  * the start of any frame. This can be connected with ease to the start of a\n  * exposure (SOE) V4L2 event.\n+ *\n+ * Controls will be sent to the device, each staggered by the appropriate\n+ * number of frames for that control, so that they are applied at the same\n+ * time.\n  */\n void DelayedControls::applyControls(uint32_t sequence)\n {\n@@ -277,12 +287,12 @@ void DelayedControls::applyControls(uint32_t sequence)\n \t\t}\n \t}\n \n-\twriteCount_ = sequence + 1;\n-\n-\twhile (writeCount_ > queueCount_) {\n+\twhile (writeCount_ < sequence + 1) {\n+\t\twriteCount_++;\n \t\tLOG(RPiDelayedControls, Debug)\n-\t\t\t<< \"Queue is empty, auto queue no-op.\";\n-\t\tpush({}, cookies_[queueCount_ - 1]);\n+\t\t\t<< \"Pushing noop with for index \" << writeCount_\n+\t\t\t<< \" with cookie \" << cookies_[writeCount_ - 1];\n+\t\tpush({}, cookies_[writeCount_ - 1]);\n \t}\n \n \tdevice_->setControls(&out);\ndiff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.h b/src/libcamera/pipeline/rpi/common/delayed_controls.h\nindex 487b0057..48ad5a0f 100644\n--- a/src/libcamera/pipeline/rpi/common/delayed_controls.h\n+++ b/src/libcamera/pipeline/rpi/common/delayed_controls.h\n@@ -76,7 +76,6 @@ private:\n \tstd::unordered_map<const ControlId *, ControlParams> controlParams_;\n \tunsigned int maxDelay_;\n \n-\tuint32_t queueCount_;\n \tuint32_t writeCount_;\n \tstd::unordered_map<const ControlId *, RingBuffer<Info>> values_;\n \tRingBuffer<unsigned int> cookies_;\n",
    "prefixes": [
        "v5",
        "1/3"
    ]
}