From patchwork Wed Mar 25 15:13:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 26346 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 417EFC32F6 for ; Wed, 25 Mar 2026 15:14:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 80C7F627D7; Wed, 25 Mar 2026 16:14:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="j43NuIxs"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 96724627D7 for ; Wed, 25 Mar 2026 16:14:52 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b16a:5ed9:4ada:a95a]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 954E51992; Wed, 25 Mar 2026 16:13:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1774451614; bh=EbhtE94aXfZc4txsZOEuCZh+VEJl4RDHgjpWhMcla5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j43NuIxsyCbrc+yWLvf6DAZEzXAPI8R6NsQMUeakTz8t//6e8QdOuHRlI3Rgoq927 WpJPFgSoifRblUlMa/yRB75kroE7HoUynaBIBvtN7JdTUlkzkt0mYL1NNs7XpdO3MH XOaj7kapWgjif5/s9rs6g1syzA/Hh9Y4tWeqNgXc= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 04/32] libcamera: delayed_controls: Queue noop when needed, not before Date: Wed, 25 Mar 2026 16:13:36 +0100 Message-ID: <20260325151416.2114564-5-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260325151416.2114564-1-stefan.klug@ideasonboard.com> References: <20260325151416.2114564-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A no-op is queued when DelayedControls runs out of controls at the end of applyControls(). But these controls are only needed on the next call to applyControls(), so there is still time for a proper push. To fix that, move the no-op push to the beginning of applyContols(). Drop writeCount_ as it is no longer needed. Signed-off-by: Stefan Klug --- Changes in v2: - Improved a log message - Improved commit message - dropped writeCount_ member --- include/libcamera/internal/delayed_controls.h | 1 - src/libcamera/delayed_controls.cpp | 18 ++++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h index c650e672d964..2af572606d0f 100644 --- a/include/libcamera/internal/delayed_controls.h +++ b/include/libcamera/internal/delayed_controls.h @@ -76,7 +76,6 @@ private: unsigned int maxDelay_; uint32_t queueCount_; - uint32_t writeCount_; /* \todo Evaluate if we should index on ControlId * or unsigned int */ std::unordered_map values_; }; diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp index 2854016c6170..123a37bdc887 100644 --- a/src/libcamera/delayed_controls.cpp +++ b/src/libcamera/delayed_controls.cpp @@ -116,7 +116,6 @@ DelayedControls::DelayedControls(V4L2Device *device, void DelayedControls::reset() { queueCount_ = 1; - writeCount_ = 0; /* Retrieve control as reported by the device. */ std::vector ids; @@ -272,6 +271,13 @@ void DelayedControls::applyControls(uint32_t sequence) { LOG(DelayedControls, Debug) << "frame " << sequence << " started"; + while (queueCount_ - 1 < sequence) { + LOG(DelayedControls, Warning) + << "Queue is empty, auto queue no-op for sequence " + << queueCount_; + push(queueCount_, {}); + } + /* * Create control list peeking ahead in the value queue to ensure * values are set in time to satisfy the sensor delay. @@ -280,7 +286,7 @@ void DelayedControls::applyControls(uint32_t sequence) for (auto &ctrl : values_) { const ControlId *id = ctrl.first; unsigned int delayDiff = maxDelay_ - controlParams_[id].delay; - unsigned int index = std::max(0, writeCount_ - delayDiff); + unsigned int index = std::max(0, sequence - delayDiff); Info &info = ctrl.second[index]; if (info.updated) { @@ -310,14 +316,6 @@ void DelayedControls::applyControls(uint32_t sequence) } } - writeCount_ = sequence + 1; - - while (writeCount_ > queueCount_) { - LOG(DelayedControls, Warning) - << "Queue is empty, auto queue no-op."; - push(queueCount_, {}); - } - device_->setControls(&out); }