[{"id":38447,"web_url":"https://patchwork.libcamera.org/comment/38447/","msgid":"<CAEmqJPq6aDSFGy=qFvK3YJFNgp3MJQAHBS4R08b4cakQUC-WEg@mail.gmail.com>","date":"2026-03-30T07:38:21","subject":"Re: [PATCH v2 1/3] pipeline: rpi: Simplify delayed controls","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\nThank you for the update.\n\nOn Fri, 27 Mar 2026 at 14:47, David Plowman\n<david.plowman@raspberrypi.com> wrote:\n>\n> The queueCount field in the DelayedControls is actually\n> redundant. Remove it.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n> ---\n>  .../pipeline/rpi/common/delayed_controls.cpp  | 32 +++++++++++--------\n>  .../pipeline/rpi/common/delayed_controls.h    |  1 -\n>  2 files changed, 18 insertions(+), 15 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> index 19c71946..93145d30 100644\n> --- a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> @@ -119,7 +119,6 @@ DelayedControls::DelayedControls(V4L2Device *device,\n>   */\n>  void DelayedControls::reset(unsigned int cookie)\n>  {\n> -       queueCount_ = 1;\n>         writeCount_ = 0;\n>         cookies_[0] = cookie;\n>\n> @@ -154,10 +153,16 @@ void DelayedControls::reset(unsigned int cookie)\n>  bool DelayedControls::push(const ControlList &controls, const unsigned int cookie)\n>  {\n>         /* Copy state from previous frame. */\n> -       for (auto &ctrl : values_) {\n> -               Info &info = ctrl.second[queueCount_];\n> -               info = values_[ctrl.first][queueCount_ - 1];\n> -               info.updated = false;\n> +       if (writeCount_ > 0) {\n> +               for (auto &ctrl : values_) {\n> +                       Info &info = ctrl.second[writeCount_];\n> +                       info = values_[ctrl.first][writeCount_ - 1];\n> +                       info.updated = false;\n> +               }\n> +       } else {\n> +               /* Although it works, we don't expect this. */\n> +               LOG(RPiDelayedControls, Warning)\n> +                       << \"push called before applyControls\";\n>         }\n>\n>         /* Update with new controls. */\n> @@ -175,18 +180,17 @@ bool DelayedControls::push(const ControlList &controls, const unsigned int cooki\n>                 if (controlParams_.find(id) == controlParams_.end())\n>                         return false;\n>\n> -               Info &info = values_[id][queueCount_];\n> +               Info &info = values_[id][writeCount_];\n>\n>                 info = Info(control.second);\n>\n>                 LOG(RPiDelayedControls, Debug)\n>                         << \"Queuing \" << id->name()\n>                         << \" to \" << info.toString()\n> -                       << \" at index \" << queueCount_;\n> +                       << \" at index \" << writeCount_;\n>         }\n>\n> -       cookies_[queueCount_] = cookie;\n> -       queueCount_++;\n> +       cookies_[writeCount_] = cookie;\n>\n>         return true;\n>  }\n> @@ -277,12 +281,12 @@ void DelayedControls::applyControls(uint32_t sequence)\n>                 }\n>         }\n>\n> -       writeCount_ = sequence + 1;\n> -\n> -       while (writeCount_ > queueCount_) {\n> +       while (writeCount_ < sequence + 1) {\n> +               writeCount_++;\n>                 LOG(RPiDelayedControls, Debug)\n> -                       << \"Queue is empty, auto queue no-op.\";\n> -               push({}, cookies_[queueCount_ - 1]);\n> +                       << \"Pushing noop with for index \" << writeCount_\n> +                       << \" with cookie \" << cookies_[writeCount_ - 1];\n> +               push({}, cookies_[writeCount_ - 1]);\n>         }\n>\n>         device_->setControls(&out);\n> diff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.h b/src/libcamera/pipeline/rpi/common/delayed_controls.h\n> index 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>         std::unordered_map<const ControlId *, ControlParams> controlParams_;\n>         unsigned int maxDelay_;\n>\n> -       uint32_t queueCount_;\n>         uint32_t writeCount_;\n>         std::unordered_map<const ControlId *, RingBuffer<Info>> values_;\n>         RingBuffer<unsigned int> cookies_;\n> --\n> 2.47.3\n>","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 0CD3CBE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 30 Mar 2026 07:39:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9661862CF7;\n\tMon, 30 Mar 2026 09:39:01 +0200 (CEST)","from mail-ua1-x936.google.com (mail-ua1-x936.google.com\n\t[IPv6:2607:f8b0:4864:20::936])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A18862CC7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Mar 2026 09:38:59 +0200 (CEST)","by mail-ua1-x936.google.com with SMTP id\n\ta1e0cc1a2514c-9519b2e681dso82250241.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Mar 2026 00:38:59 -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=\"LyIwjh/Y\"; dkim-atps=neutral","ARC-Seal":"i=1; a=rsa-sha256; t=1774856338; cv=none;\n\td=google.com; s=arc-20240605;\n\tb=Uq5vyJPS0RHjwyVtFnRdS4etYsx8qPgrq5bwqBWDsMrqAW29jOwXMuP6LawgkX/i8v\n\tnP+qnbB7rajE+JSnTtV+5mhQIpOC7rPUK5FJ3KgcjrdOm1463UlUocLO4Sr64Vin7nvp\n\tX33TwYJDk8jRr2af29TZjfMJ3dwb6aag8hBdZWjq+Z4+5PHzdMjz2gwuM1KJIVg+6ASi\n\ttruUGIE5HU4rQB8/rzWAlEQXWJurvAXtssE80AR2wCwvNghM0MWjgBq/JqlDGq4LLX0+\n\ttZo7wcVQiMvJh8dRpB81gq5Fu1gbv3DRzdjkaBrHx/0JvPjh7jKLOuLV79Ej7OsAVKCz\n\tMKaQ==","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=arc-20240605; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:dkim-signature;\n\tbh=eKqCm+hsvY3J6zvo9NDrfJuonpmCBGgVGVJ0guLt6jM=;\n\tfh=raf7gMhxwhTsDETG3li6wpOfdJf6YyDg/c7aYJ8coN8=;\n\tb=fQomDFKWzypIv/3aUbjWhtSVQbRMXKF0oxRph0Qmdu41pAqPlNEfWlp1q06cw1UDOx\n\tXj7kr7RC0VdazERURp4qhESHYQglWw2dxiEaEviZOPOlAaVkDqQHfilZWdwm7+jpjYxz\n\t66kRfSFOWT4k35riR3LnEVGyqYrSwE+5Cz/bXGk28Geje0LmqHuQsGyWbq3uyiV53azj\n\ts5HVvH0ryb6GS8mrQIa8eGGSGe4Zgz20vQlZwokHNU+j9rxqjcgBaszFjjZXeuanDX5C\n\tHn2jPFhKngAftuQtCaaxv2cssYrPlz89gwRdsLjugKFiT0Vu2wfW6vmwI0LwBb1DnJqi\n\tvEkQ==; darn=lists.libcamera.org","ARC-Authentication-Results":"i=1; mx.google.com; arc=none","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1774856338; x=1775461138;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=eKqCm+hsvY3J6zvo9NDrfJuonpmCBGgVGVJ0guLt6jM=;\n\tb=LyIwjh/Y1Dkof50LTbpbF//y452MD+y3xUUUEKToQkVTeRfZOuAsyFrfmMgqD3xRCt\n\tQ/5wSMhM9Vz2sqh3IZOf7KfaZ+yJihS3B/PfRCWIldz+7cGAzQTbcgeVfkZiRXZZ30CB\n\t4cZq9CvNVVSvcf9cOEhjnd5aesxWTIvRm6uc49yC90t1HFHjO5TXv5zZd6/fgwc92Nny\n\tlXIabH2rqi6MeE1EFfm3Uifc/Va+6sP9uynSXKU2ouDM/TrC1UFDFMTu7bSF9/LpGzec\n\tTnEVjY/vRRwEgrC0LnK8QdpQ6wgCPc9W4z+1r/SOBDf5AoSH0mMdmg9HPumBly5q1XFC\n\t/+Og==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1774856338; x=1775461138;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=eKqCm+hsvY3J6zvo9NDrfJuonpmCBGgVGVJ0guLt6jM=;\n\tb=nsy0aHjtSOtD2hBaVNfxZ9nwRQ8U3qH+XkXDEQCTjQerOMldZSX/wpJjmLbDvMh0XL\n\treiVhIYsDZgMvk7moj6YTMIiZ2u90QGZE94VSJE/W5pElmHx2od5XdJG9xCCVJBQ+LHx\n\t6h8IoLL96bpALpdgIRsEyKf7dfo1rSMnM38lOA2/BZRei9SupKuKbjeAV0+1IM8aSKpQ\n\tl1gqLwJni+mTZH6xjwZM69aFX+96DnrKPEsYZesVYJsQPpdgXd9LoigCe9nfgGR395AH\n\t1ywkvVRvIb2SaQGAhpeHLwnj+jObkBx78XCtMX10jpklZ0s/AtYNiCrw0ze7mqHgj7Nn\n\ts4GA==","X-Gm-Message-State":"AOJu0Yy5JPYXM6Dt7aWZZYzq27E9R4Iop2EUS1hJVTLX3ZSaSeDkb2+6\n\t7HjF8Wd4CtJUOsiHrq0maRBFlrCV+tktDAuYQXKlCwIv1TS8Mw1+WE5Xk4jFp7KNcoOuRECHbl6\n\t0pnmPdB5x+p250rN37KIR0vfufT/wqF+I+jXhIPDI5ucPBelF3Cgl","X-Gm-Gg":"ATEYQzzJyyZMQQDnDV3fweQ8EzcwRb8gxRyFtxK1LCJFkCdreOxNCZ+/3lHkM14puUC\n\tQov4aMJXZsM07QNkBvDHy5w/KQYQ19MVgyGQrBi3XiYFbN6wChgEHKHNH+nhSVn/UFpgeWOKBLg\n\tH5czDl80S/PhDxrSFRhnTFzHJ1+oyNVY8s6qtRp5OiY7mycYnj80HzPLduqAi1V7Rr/sAvQkiUA\n\t2KXnuPy/pgw5qbgy7cbk0M0Z9V4d+7gW72IlYSg7DTUJctWs6RYTIUTvbhPXdx0y04iJhAHBckh\n\tygDSygBUBLBL4lA8P7CDTrO8ia4nLa3my1A3O/anjeRlmOe+nZ13H/6wy+0Vf1W+e8TsQFfQJWk\n\tYbTg/EuRXiIeoRa3LzMdM1oMy","X-Received":"by 2002:a67:e88b:0:b0:5ff:1d91:a4bd with SMTP id\n\tada2fe7eead31-604f932f2e6mr1299218137.8.1774856337777;\n\tMon, 30 Mar 2026 00:38:57 -0700 (PDT)","MIME-Version":"1.0","References":"<20260327144726.7983-1-david.plowman@raspberrypi.com>\n\t<20260327144726.7983-2-david.plowman@raspberrypi.com>","In-Reply-To":"<20260327144726.7983-2-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Mon, 30 Mar 2026 08:38:21 +0100","X-Gm-Features":"AQROBzA6755UrWp6sTZJbj1O4zlMh_2Ka6zk3OR7yrfOh-RQkQJfCXqYadVmFeA","Message-ID":"<CAEmqJPq6aDSFGy=qFvK3YJFNgp3MJQAHBS4R08b4cakQUC-WEg@mail.gmail.com>","Subject":"Re: [PATCH v2 1/3] pipeline: rpi: Simplify delayed controls","To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","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>"}},{"id":38654,"web_url":"https://patchwork.libcamera.org/comment/38654/","msgid":"<20260427003315.GA3733363@killaraus.ideasonboard.com>","date":"2026-04-27T00:33:15","subject":"Re: [PATCH v2 1/3] pipeline: rpi: Simplify delayed controls","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nThank you for the patch.\n\nOn Fri, Mar 27, 2026 at 02:42:34PM +0000, David Plowman wrote:\n> The queueCount field in the DelayedControls is actually\n> redundant. Remove it.\n\nThis patch changes the behaviour of the class significantly. Calling\npush() twice with applyControls() in-between will not result in both\npush() calls writing to the same entry in the ring buffer. The commit\nmessage should explain why this is desired, and why it's not an issue.\nThe documentation of the push() function should also be updated, and\npossibly other pieces of documentation as well.\n\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  .../pipeline/rpi/common/delayed_controls.cpp  | 32 +++++++++++--------\n>  .../pipeline/rpi/common/delayed_controls.h    |  1 -\n>  2 files changed, 18 insertions(+), 15 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> index 19c71946..93145d30 100644\n> --- a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> @@ -119,7 +119,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> @@ -154,10 +153,16 @@ void DelayedControls::reset(unsigned int cookie)\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 +180,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> @@ -277,12 +281,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);\n> diff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.h b/src/libcamera/pipeline/rpi/common/delayed_controls.h\n> index 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_;","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 BB4C2BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Apr 2026 00:33:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BBF0E62FC3;\n\tMon, 27 Apr 2026 02:33:19 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A5B6462E9D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Apr 2026 02:33:17 +0200 (CEST)","from killaraus.ideasonboard.com\n\t(2001-14ba-703d-e500--2a1.rev.dnainternet.fi\n\t[IPv6:2001:14ba:703d:e500::2a1])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1772E667;\n\tMon, 27 Apr 2026 02:31:35 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tC3I6dfk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1777249895;\n\tbh=bGhYl0J/lCW0vYlJ3EHJKfOIAKWZ4PeJ38F3GBmveds=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tC3I6dfkuOvI+TPrllT4juFsvmdKwIeg4EIogcOAL4kqNy/uMYew4cZwHQf8/doPb\n\thAxBm2yDx2iHebGsmXdnI9aHu36RkBa8goG4KelbbpBJxps0QuhWkZrS6QJCHHnz8e\n\t/Fq/omM02ajhdykroIdGiYwUZQNf9RmOh8jl+w/g=","Date":"Mon, 27 Apr 2026 03:33:15 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 1/3] pipeline: rpi: Simplify delayed controls","Message-ID":"<20260427003315.GA3733363@killaraus.ideasonboard.com>","References":"<20260327144726.7983-1-david.plowman@raspberrypi.com>\n\t<20260327144726.7983-2-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20260327144726.7983-2-david.plowman@raspberrypi.com>","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>"}},{"id":38662,"web_url":"https://patchwork.libcamera.org/comment/38662/","msgid":"<CAHW6GYJAK=5vhGjFZ8YK=0wEjBUxUsZ5GDYjY3OBZmcSNmS5Kg@mail.gmail.com>","date":"2026-04-27T10:04:14","subject":"Re: [PATCH v2 1/3] pipeline: rpi: Simplify delayed controls","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Laurent\n\nOn Mon, 27 Apr 2026 at 01:33, Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> Hi David,\n>\n> Thank you for the patch.\n>\n> On Fri, Mar 27, 2026 at 02:42:34PM +0000, David Plowman wrote:\n> > The queueCount field in the DelayedControls is actually\n> > redundant. Remove it.\n>\n> This patch changes the behaviour of the class significantly. Calling\n> push() twice with applyControls() in-between will not result in both\n> push() calls writing to the same entry in the ring buffer. The commit\n> message should explain why this is desired, and why it's not an issue.\n> The documentation of the push() function should also be updated, and\n> possibly other pieces of documentation as well.\n\nYes, thanks for the question. The critical thing is that\npush/applyControls calls are always interleaved by our PH, so\nqueueCount and writeCount are basically always the same (or different\nby one or something). But I'll add a little more explanation around\nthat and amend some documentation.\n\nNaush reminds me that there's a bit of history around this code, so\nit's actually a slight case of \"Back to the Future\" for us!\n\nThanks\n\nDavid\n\n>\n> > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> > ---\n> >  .../pipeline/rpi/common/delayed_controls.cpp  | 32 +++++++++++--------\n> >  .../pipeline/rpi/common/delayed_controls.h    |  1 -\n> >  2 files changed, 18 insertions(+), 15 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> > index 19c71946..93145d30 100644\n> > --- a/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> > +++ b/src/libcamera/pipeline/rpi/common/delayed_controls.cpp\n> > @@ -119,7 +119,6 @@ DelayedControls::DelayedControls(V4L2Device *device,\n> >   */\n> >  void DelayedControls::reset(unsigned int cookie)\n> >  {\n> > -     queueCount_ = 1;\n> >       writeCount_ = 0;\n> >       cookies_[0] = cookie;\n> >\n> > @@ -154,10 +153,16 @@ void DelayedControls::reset(unsigned int cookie)\n> >  bool DelayedControls::push(const ControlList &controls, const unsigned int cookie)\n> >  {\n> >       /* Copy state from previous frame. */\n> > -     for (auto &ctrl : values_) {\n> > -             Info &info = ctrl.second[queueCount_];\n> > -             info = values_[ctrl.first][queueCount_ - 1];\n> > -             info.updated = false;\n> > +     if (writeCount_ > 0) {\n> > +             for (auto &ctrl : values_) {\n> > +                     Info &info = ctrl.second[writeCount_];\n> > +                     info = values_[ctrl.first][writeCount_ - 1];\n> > +                     info.updated = false;\n> > +             }\n> > +     } else {\n> > +             /* Although it works, we don't expect this. */\n> > +             LOG(RPiDelayedControls, Warning)\n> > +                     << \"push called before applyControls\";\n> >       }\n> >\n> >       /* Update with new controls. */\n> > @@ -175,18 +180,17 @@ bool DelayedControls::push(const ControlList &controls, const unsigned int cooki\n> >               if (controlParams_.find(id) == controlParams_.end())\n> >                       return false;\n> >\n> > -             Info &info = values_[id][queueCount_];\n> > +             Info &info = values_[id][writeCount_];\n> >\n> >               info = Info(control.second);\n> >\n> >               LOG(RPiDelayedControls, Debug)\n> >                       << \"Queuing \" << id->name()\n> >                       << \" to \" << info.toString()\n> > -                     << \" at index \" << queueCount_;\n> > +                     << \" at index \" << writeCount_;\n> >       }\n> >\n> > -     cookies_[queueCount_] = cookie;\n> > -     queueCount_++;\n> > +     cookies_[writeCount_] = cookie;\n> >\n> >       return true;\n> >  }\n> > @@ -277,12 +281,12 @@ void DelayedControls::applyControls(uint32_t sequence)\n> >               }\n> >       }\n> >\n> > -     writeCount_ = sequence + 1;\n> > -\n> > -     while (writeCount_ > queueCount_) {\n> > +     while (writeCount_ < sequence + 1) {\n> > +             writeCount_++;\n> >               LOG(RPiDelayedControls, Debug)\n> > -                     << \"Queue is empty, auto queue no-op.\";\n> > -             push({}, cookies_[queueCount_ - 1]);\n> > +                     << \"Pushing noop with for index \" << writeCount_\n> > +                     << \" with cookie \" << cookies_[writeCount_ - 1];\n> > +             push({}, cookies_[writeCount_ - 1]);\n> >       }\n> >\n> >       device_->setControls(&out);\n> > diff --git a/src/libcamera/pipeline/rpi/common/delayed_controls.h b/src/libcamera/pipeline/rpi/common/delayed_controls.h\n> > index 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> >       std::unordered_map<const ControlId *, ControlParams> controlParams_;\n> >       unsigned int maxDelay_;\n> >\n> > -     uint32_t queueCount_;\n> >       uint32_t writeCount_;\n> >       std::unordered_map<const ControlId *, RingBuffer<Info>> values_;\n> >       RingBuffer<unsigned int> cookies_;\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 1DEDEBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Apr 2026 10:04:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 16D8D62FC6;\n\tMon, 27 Apr 2026 12:04:28 +0200 (CEST)","from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com\n\t[IPv6:2a00:1450:4864:20::52b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C7B76271A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Apr 2026 12:04:26 +0200 (CEST)","by mail-ed1-x52b.google.com with SMTP id\n\t4fb4d7f45d1cf-676a89de629so10018032a12.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Apr 2026 03:04:26 -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=\"pyDGPnZ3\"; dkim-atps=neutral","ARC-Seal":"i=1; a=rsa-sha256; t=1777284265; cv=none;\n\td=google.com; s=arc-20240605;\n\tb=dK7MfQO8817Gk6CFo2h0SLH7HmxRmhT1hEpC8xU2A+/8B10ySn+bbI8aoRkGG9IqKK\n\t/385WwHh2a5xTkoMQAxYyHfKgJCFGlGVucOfx6FXrMmrMNd61CxXamzjLFmnMD2OjSVy\n\ta9JE8dKTnF3oC+66MmgqTmdrgvOaodHd2F/+OmfA4CFCC1pG6FgN3OHDThgwfT3+7PZ2\n\tQ9TnDlJt9YnW4FuTox6yYOFr6DThUAZ3HOdrcOKOgbmEmKslHv1Vc5YkzvPU+sJ0RQVS\n\tegYL1RypJAGV6hIGcSI/2mlZlXlCyFp7kPv9BqcWMuFK1RFOtK7yO+64YiQnam01xDW3\n\tqk8Q==","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=arc-20240605; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:dkim-signature;\n\tbh=QrcSx0zQD3hXLZf+8z2GwR6BmShpVdOlG9A4auvf2t8=;\n\tfh=kAwbguIY0wmqf1QQypnTiLH20ruRu7+JSSp6fzxLlN4=;\n\tb=ZD5xcJ0sKd2l5WtnUaYhFsSl9v9Dn7/8s+zIOpLxa4UR6jP0ajBt9cm5rDWiDZ4vwV\n\tL0gOhOKJqT1SrKUqdGdzli5JDQgs++VCXSxPQJoGi7gu6DqguBIOl+0O7dk6K+giSvje\n\tXZX27YBDCyWCsOqOWdij+/gb1cKIDnZ8jfPfULkbEhDWE84oL1FRpvLOJ3corxTZI36A\n\tyKUZDrtAPKZwh3dltglqTrObSq4mLNXo7ioiWo+ggJMBiTeq8N7kFQRHDH/dfhj22u9i\n\tQtEnMYqaORx28HVQNaU6DexjSVuwNNQB6RR6M2bo/TRFTSat5KFRiE2s66WiRF4Lw6I1\n\tni3w==; darn=lists.libcamera.org","ARC-Authentication-Results":"i=1; mx.google.com; arc=none","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1777284265; x=1777889065;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=QrcSx0zQD3hXLZf+8z2GwR6BmShpVdOlG9A4auvf2t8=;\n\tb=pyDGPnZ3nTWOjAD2lOGecmciMxRTtmX+e197VGkpRfz5suOL2P+2YiYmQAaVf6tsXg\n\t04jiknQmyW1nlW6mAENpWYDBLr15itNlbkc99AeBUsmluEJ67mU6x540Ur1ZHK4U5fSt\n\tkwhwta2fP/CYvgwI0RlR3EpkUcEXbD7+TN8RdRrsMT0iwj9FroE+axBKPg0XJR03jc6p\n\tde1gT38sYfsZuTr7fTPyWHiGXfuYr6LOdAs65JcBrVKb1/l1KEwiBY6HSByMwlP5diwz\n\ttTM6QSkKqAgs20XQ17jDkU87g8G5EoBaVsOCiROcGiWwIeTkDrbZ5be9wx2LEjf2lko6\n\tb/+g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1777284265; x=1777889065;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=QrcSx0zQD3hXLZf+8z2GwR6BmShpVdOlG9A4auvf2t8=;\n\tb=sYUHpvKFAsXd7qKOfhAJx1tALv9sLuUuqMpkylUnLQbuXc+0CJJcWas8wjgWXbRQYg\n\tLaLHK0HS1MWb7EI+EDcGE43YS2R2nKMoDdP2RkgQBBH/M0TMB1QG4pxaRfc7GYOBvZjz\n\t0IwWzpMbb9xFmTNAUXSOqyeWnUjxaiyefFmFJfyQpFYsbkHLfDTP9U0Aoy0hXzUPgp+w\n\tJE11Zl4XQBbx9bmQZJ7hXO+qUYk1K03nBGYYRINp2A7axU8jHMagkyKAOXdd9kDqqkrZ\n\tCMl6wwQivu3Ck09XjuZt0MIqwos2wNnZW/4+PNkPs7KjrO+DQxxAX3+OK1CaAfnoLZT9\n\tgvoA==","X-Gm-Message-State":"AOJu0YznPRrAOrVSzMT820KxbaTD6jSLMNJSqcQQ8WewaWFCh5Msx4vN\n\ttNYjgi/qE/dP2p3g9PMis1M320IuBViv4opPhYP3PtEx7tEUYr1jqzhgjmHgwCeFdYTthVGZFcf\n\ta4pPi3uEY34iJTM32auyw0287m+yCyEWBzSm96xxYlA==","X-Gm-Gg":"AeBDievlcVBneKv2QT8uFAEaH+K/ERvsSv6LF7TvdUNrbhAmmA0B/d+H3Jlux8ia3Nm\n\tNP/twfRHA7U6mKCfEVxsYs8fkpVD3LDH0aFVjRS0JDG7zuxz1q3qmdUG7q+i4LYAWp3uX1QCDB7\n\thtLDLqRQ+vPcdsFCCwTPBLaQLAIDKdB0Y1ocOKwvdGuDAoWBMcjd2j42tEqh7qSKeBVTHxdcuEl\n\teLvboa8GF5W4HVpT2qihuDI1gqqvqPqZGwhZk3xSG6+//leSeianj+GNLsR9CK58O+dCBoL+cCQ\n\twXb6epZac45u/xr9t//jwApILHXMtt2cTTeGI3dsjZ+bG7SfPmYxEAg1jY9nZQAYURcHgwcfv5J\n\tbeDLqWmlm32NCYwtB/0L/2caaVapxz74nKOg=","X-Received":"by 2002:a17:906:599c:b0:ba2:5354:95dd with SMTP id\n\ta640c23a62f3a-ba41828ccacmr1467082466b.5.1777284265246;\n\tMon, 27 Apr 2026 03:04:25 -0700 (PDT)","MIME-Version":"1.0","References":"<20260327144726.7983-1-david.plowman@raspberrypi.com>\n\t<20260327144726.7983-2-david.plowman@raspberrypi.com>\n\t<20260427003315.GA3733363@killaraus.ideasonboard.com>","In-Reply-To":"<20260427003315.GA3733363@killaraus.ideasonboard.com>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Mon, 27 Apr 2026 11:04:14 +0100","X-Gm-Features":"AVHnY4JHcPTMCRO9dg9bVWNq1GQG4szDGNUThVktquyNlJnq44OmoNC2KYNkc2o","Message-ID":"<CAHW6GYJAK=5vhGjFZ8YK=0wEjBUxUsZ5GDYjY3OBZmcSNmS5Kg@mail.gmail.com>","Subject":"Re: [PATCH v2 1/3] pipeline: rpi: Simplify delayed controls","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","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>"}}]