From patchwork Fri Apr 29 19:34:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15751 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 74EDAC0F2A for ; Fri, 29 Apr 2022 19:34:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7C78365647; Fri, 29 Apr 2022 21:34:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651260865; bh=XpMx92d9ohZG71rvFQnype5rF2q57xwiF6S5Lz/tXvk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Jp5wTw3/+c6da9A+P0jpJu2uxYVCUrn4LiwZhI7vVNXD/V36rmJY+6NBSQEz2BSKB hjBbsmOha1ujY1jMB2BOX8KSrRo4jECOUyfNdoYZbmxK1Mk6fQIjtF4qLaKxLbodaR i0RdrlOb8WH5SeQg/aB5cpf58ecdavcZncDXq1LdYf+R0V5b6RmqgxEi77VnH1ZXN6 ErDMI3OILZKhDx9xOG7godeu03NmQyhraG09ayyVdAzadpybnHlwkYB0ADTTG1E7Ik iy4Q6+LJii520TjOQr0oD7zpQAfHWMBI7PadK+0E4uKZh1PiuJQltatFJWh0HytHnQ XNyOzAzNvydbw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D8F2604A5 for ; Fri, 29 Apr 2022 21:34:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P8b9AvCJ"; dkim-atps=neutral Received: from Q.ksquared.org.uk.beta.tailscale.net (unknown [178.237.134.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 859AA475; Fri, 29 Apr 2022 21:34:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651260862; bh=XpMx92d9ohZG71rvFQnype5rF2q57xwiF6S5Lz/tXvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8b9AvCJcPqw3l+hx0mFe5B5YvHZhpRKirNY90RD/cZEJqq2jJQ+qDNIHYWrpjKhz Br0PMLrqBt/aHl4yq85GpXy/KyzbcjP0oUiPbd50r3EYu19iBEx4nU/Ap2nO75P7l8 dac4RDUELRlbsWgSwhGdXy4PdCCOG4cbJNfYfe1M= To: libcamera devel Date: Fri, 29 Apr 2022 21:34:32 +0200 Message-Id: <20220429193434.167990-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429193434.167990-1-kieran.bingham@ideasonboard.com> References: <20220429193434.167990-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: Add sequence value observer 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: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Components will often need to track and store a sequence number. Sequence numbers should be monotonically incrementing, but may require features such as validating that an external source matches this one, or ensuring that there are no gaps. Support the operations needed on sequence numbers in a dedicated class to reduce code duplication across components. Signed-off-by: Kieran Bingham Reviewed-by: Umang Jain --- include/libcamera/meson.build | 1 + include/libcamera/sequence.h | 20 +++++++++++ src/libcamera/meson.build | 1 + src/libcamera/sequence.cpp | 66 +++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 include/libcamera/sequence.h create mode 100644 src/libcamera/sequence.cpp diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 408b7acf152c..2911d4bf4ec7 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -14,6 +14,7 @@ libcamera_public_headers = files([ 'logging.h', 'pixel_format.h', 'request.h', + 'sequence.h', 'stream.h', 'transform.h', ]) diff --git a/include/libcamera/sequence.h b/include/libcamera/sequence.h new file mode 100644 index 000000000000..ad6e99726a4e --- /dev/null +++ b/include/libcamera/sequence.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include + +namespace libcamera { + +class Sequence +{ +public: + __nodiscard int update(unsigned int seq); + void reset() { sequence_.reset(); } + +private: + std::optional sequence_; +}; + +}; // namespace libcamera + diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 26912ca17819..ffdffeb4bfdc 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -38,6 +38,7 @@ libcamera_sources = files([ 'process.cpp', 'pub_key.cpp', 'request.cpp', + 'sequence.cpp', 'source_paths.cpp', 'stream.cpp', 'sysfs.cpp', diff --git a/src/libcamera/sequence.cpp b/src/libcamera/sequence.cpp new file mode 100644 index 000000000000..374b4f04d0a3 --- /dev/null +++ b/src/libcamera/sequence.cpp @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Ideas on Board Oy. + * + * sequence.cpp Sequence Number Observer + */ + +#include + +#include + +/** + * \file sequence.h + * \brief Sequence number observer + */ + +namespace libcamera { + +/** + * \class Sequence + * \brief Sequence number tracking which expects monotonically incrementing + * numbers + * + * The Sequence number observer is initialised with the first value it is given. + * It will return a difference of the expected update value, against the newly + * provided value - allowing the consumer to identify if a break in a sequence + * has occured. + */ + +/** + * \brief Update the sequence observer with the latest value + * \param seq The latest value for the sequence + * + * This function will update the state of the Sequence observer and identify any + * non-monotonic increment or change that may occur and return the difference + * from the expected update value. + * + * The sequence is initialised to the first value passed into \a update. + * + * \return The number of drops in the sequence that were detected + */ +__nodiscard int Sequence::update(unsigned int seq) +{ + if (!sequence_) + sequence_ = seq - 1; + + /* + * Any update expects a single integer difference from + * the previous value. + */ + int diff = seq - sequence_.value() - 1; + + sequence_ = seq; + + return diff; +}; + +/** + * \fn Sequence::reset + * \brief Resets the sequence observer + * + * Re-initialises the sequence observer so that any known break in the monotonic + * sequence is not reported. + */ + +} /* namespace libcamera */