{"id":15751,"url":"https://patchwork.libcamera.org/api/patches/15751/?format=json","web_url":"https://patchwork.libcamera.org/patch/15751/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220429193434.167990-2-kieran.bingham@ideasonboard.com>","date":"2022-04-29T19:34:32","name":"[libcamera-devel,1/3] libcamera: Add sequence value observer","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"9316012334641248e8826b72b00591e106bc9cfa","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":{"id":11,"url":"https://patchwork.libcamera.org/api/users/11/?format=json","username":"kbingham","first_name":"Kieran","last_name":"Bingham","email":"kieran.bingham@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/15751/mbox/","series":[{"id":3083,"url":"https://patchwork.libcamera.org/api/series/3083/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3083","date":"2022-04-29T19:34:31","name":"Sequence Observer","version":1,"mbox":"https://patchwork.libcamera.org/series/3083/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15751/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15751/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 74EDAC0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 29 Apr 2022 19:34:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7C78365647;\n\tFri, 29 Apr 2022 21:34:25 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D8F2604A5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Apr 2022 21:34:23 +0200 (CEST)","from Q.ksquared.org.uk.beta.tailscale.net (unknown\n\t[178.237.134.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 859AA475;\n\tFri, 29 Apr 2022 21:34:22 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1651260865;\n\tbh=XpMx92d9ohZG71rvFQnype5rF2q57xwiF6S5Lz/tXvk=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Jp5wTw3/+c6da9A+P0jpJu2uxYVCUrn4LiwZhI7vVNXD/V36rmJY+6NBSQEz2BSKB\n\thjBbsmOha1ujY1jMB2BOX8KSrRo4jECOUyfNdoYZbmxK1Mk6fQIjtF4qLaKxLbodaR\n\ti0RdrlOb8WH5SeQg/aB5cpf58ecdavcZncDXq1LdYf+R0V5b6RmqgxEi77VnH1ZXN6\n\tErDMI3OILZKhDx9xOG7godeu03NmQyhraG09ayyVdAzadpybnHlwkYB0ADTTG1E7Ik\n\tiy4Q6+LJii520TjOQr0oD7zpQAfHWMBI7PadK+0E4uKZh1PiuJQltatFJWh0HytHnQ\n\tXNyOzAzNvydbw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1651260862;\n\tbh=XpMx92d9ohZG71rvFQnype5rF2q57xwiF6S5Lz/tXvk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=P8b9AvCJcPqw3l+hx0mFe5B5YvHZhpRKirNY90RD/cZEJqq2jJQ+qDNIHYWrpjKhz\n\tBr0PMLrqBt/aHl4yq85GpXy/KyzbcjP0oUiPbd50r3EYu19iBEx4nU/Ap2nO75P7l8\n\tdac4RDUELRlbsWgSwhGdXy4PdCCOG4cbJNfYfe1M="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"P8b9AvCJ\"; dkim-atps=neutral","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","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","Content-Transfer-Encoding":"8bit","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":"<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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Components will often need to track and store a sequence number.\nSequence numbers should be monotonically incrementing, but may require\nfeatures such as validating that an external source matches this one, or\nensuring that there are no gaps.\n\nSupport the operations needed on sequence numbers in a dedicated class\nto reduce code duplication across components.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/meson.build |  1 +\n include/libcamera/sequence.h  | 20 +++++++++++\n src/libcamera/meson.build     |  1 +\n src/libcamera/sequence.cpp    | 66 +++++++++++++++++++++++++++++++++++\n 4 files changed, 88 insertions(+)\n create mode 100644 include/libcamera/sequence.h\n create mode 100644 src/libcamera/sequence.cpp","diff":"diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 408b7acf152c..2911d4bf4ec7 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -14,6 +14,7 @@ libcamera_public_headers = files([\n     'logging.h',\n     'pixel_format.h',\n     'request.h',\n+    'sequence.h',\n     'stream.h',\n     'transform.h',\n ])\ndiff --git a/include/libcamera/sequence.h b/include/libcamera/sequence.h\nnew file mode 100644\nindex 000000000000..ad6e99726a4e\n--- /dev/null\n+++ b/include/libcamera/sequence.h\n@@ -0,0 +1,20 @@\n+#pragma once\n+\n+#include <optional>\n+\n+#include <libcamera/base/compiler.h>\n+\n+namespace libcamera {\n+\n+class Sequence\n+{\n+public:\n+\t__nodiscard int update(unsigned int seq);\n+\tvoid reset() { sequence_.reset(); }\n+\n+private:\n+\tstd::optional<unsigned int> sequence_;\n+};\n+\n+}; // namespace libcamera\n+\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 26912ca17819..ffdffeb4bfdc 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -38,6 +38,7 @@ libcamera_sources = files([\n     'process.cpp',\n     'pub_key.cpp',\n     'request.cpp',\n+    'sequence.cpp',\n     'source_paths.cpp',\n     'stream.cpp',\n     'sysfs.cpp',\ndiff --git a/src/libcamera/sequence.cpp b/src/libcamera/sequence.cpp\nnew file mode 100644\nindex 000000000000..374b4f04d0a3\n--- /dev/null\n+++ b/src/libcamera/sequence.cpp\n@@ -0,0 +1,66 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy.\n+ *\n+ * sequence.cpp Sequence Number Observer\n+ */\n+\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/sequence.h>\n+\n+/**\n+ * \\file sequence.h\n+ * \\brief Sequence number observer\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class Sequence\n+ * \\brief Sequence number tracking which expects monotonically incrementing\n+ *\t  numbers\n+ *\n+ * The Sequence number observer is initialised with the first value it is given.\n+ * It will return a difference of the expected update value, against the newly\n+ * provided value - allowing the consumer to identify if a break in a sequence\n+ * has occured.\n+ */\n+\n+/**\n+ * \\brief Update the sequence observer with the latest value\n+ * \\param seq The latest value for the sequence\n+ *\n+ * This function will update the state of the Sequence observer and identify any\n+ * non-monotonic increment or change that may occur and return the difference\n+ * from the expected update value.\n+ *\n+ * The sequence is initialised to the first value passed into \\a update.\n+ *\n+ * \\return The number of drops in the sequence that were detected\n+ */\n+__nodiscard int Sequence::update(unsigned int seq)\n+{\n+\tif (!sequence_)\n+\t\tsequence_ = seq - 1;\n+\n+\t/*\n+\t * Any update expects a single integer difference from\n+\t * the previous value.\n+\t */\n+\tint diff = seq - sequence_.value() - 1;\n+\n+\tsequence_ = seq;\n+\n+\treturn diff;\n+};\n+\n+/**\n+ * \\fn Sequence::reset\n+ * \\brief Resets the sequence observer\n+ *\n+ * Re-initialises the sequence observer so that any known break in the monotonic\n+ * sequence is not reported.\n+ */\n+\n+} /* namespace libcamera */\n","prefixes":["libcamera-devel","1/3"]}