From patchwork Tue Mar 19 12:05:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 19747 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 9BF7DC32C5 for ; Tue, 19 Mar 2024 12:05:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3C84A62CA7; Tue, 19 Mar 2024 13:05:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TkK93nuG"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D21862973 for ; Tue, 19 Mar 2024 13:05:29 +0100 (CET) Received: from jasper.fritz.box (unknown [IPv6:2a00:6020:448c:6c00:1478:344b:8fcb:baf5]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D640480; Tue, 19 Mar 2024 13:05:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1710849902; bh=CY+7rwNcPmr9tbggrYi5pB0eqv6maFoX762dCfO5dT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TkK93nuG8AJ8wb1Sh3KZ9hoKK2eQJgqRisE+hjt2hRXNB5aoXAF/+pJJu4P2JvA2T GDbxxQ1twQHLaqQZ86iGjLZB5n0gcaSDm63h/UU9iWFUfSHHIaNjwz/Pt9nRFGqQUw OCg4DltFH5/1dJnm/wPvzpj0lX9kcKLNw/KiWLLE= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v3 07/16] libcamera: delayed_controls: Add controlsAreQueued() helper Date: Tue, 19 Mar 2024 13:05:08 +0100 Message-Id: <20240319120517.362082-8-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240319120517.362082-1-stefan.klug@ideasonboard.com> References: <20240319120517.362082-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" This gets used in the upcoming patches to decide if controls need to be queued for a later frame, or if the controls can be skipped because they are already queued. Signed-off-by: Stefan Klug --- include/libcamera/internal/delayed_controls.h | 2 ++ src/libcamera/delayed_controls.cpp | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h index 0e28106a..ccbe7239 100644 --- a/include/libcamera/internal/delayed_controls.h +++ b/include/libcamera/internal/delayed_controls.h @@ -67,6 +67,8 @@ private: } }; + bool controlsAreQueued(unsigned int frame, const ControlList &controls); + V4L2Device *device_; /* \todo Evaluate if we should index on ControlId * or unsigned int */ std::unordered_map controlParams_; diff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp index 86571cd4..6c766ede 100644 --- a/src/libcamera/delayed_controls.cpp +++ b/src/libcamera/delayed_controls.cpp @@ -137,6 +137,40 @@ void DelayedControls::reset() } } +/** + * \brief Helper function to check if controls are already queued + * \param[in] sequence Sequence number to check + * \param[in] controls List of controls to compare against + * + * This function checks if the controls queued for frame \a sequence + * are equal to \a controls. This is helpful in cases where a control algorithm + * unconditionally queues controls for every frame, but always too late. + * In that case this can be used to check if incoming controls are already + * queued or need to be queued for a later frame. + * + * \returns true if \a controls are queued for the given sequence + */ +bool DelayedControls::controlsAreQueued(unsigned int sequence, + const ControlList &controls) +{ + const ControlIdMap &idmap = device_->controls().idmap(); + for (const auto &[id, value] : controls) { + const auto &it = idmap.find(id); + if (it == idmap.end()) { + LOG(DelayedControls, Warning) + << "Unknown control " << id; + return false; + } + + const ControlId *ctrlId = it->second; + + if (values_[ctrlId][sequence] != value) + return false; + } + + return true; +} + /** * \brief Push a set of controls on the queue * \param[in] controls List of controls to add to the device queue