[{"id":22907,"web_url":"https://patchwork.libcamera.org/comment/22907/","msgid":"<611a8f5d-4669-116b-c449-6ebbe90afb30@ideasonboard.com>","date":"2022-05-09T12:42:30","subject":"Re: [libcamera-devel] [PATCH 1/3] libcamera: Add sequence value\n\tobserver","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch\n\nOn 4/30/22 01:04, Kieran Bingham via libcamera-devel wrote:\n> Components will often need to track and store a sequence number.\n> Sequence numbers should be monotonically incrementing, but may require\n> features such as validating that an external source matches this one, or\n> ensuring that there are no gaps.\n>\n> Support the operations needed on sequence numbers in a dedicated class\n> to reduce code duplication across components.\n>\n> Signed-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\n>\n> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\n> index 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>   ])\n> diff --git a/include/libcamera/sequence.h b/include/libcamera/sequence.h\n> new file mode 100644\n> index 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> +\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 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',\n> diff --git a/src/libcamera/sequence.cpp b/src/libcamera/sequence.cpp\n> new file mode 100644\n> index 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\nIndentation\n\n\nLooks good to me,\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\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 */","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 C9869C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  9 May 2022 12:42:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1913865646;\n\tMon,  9 May 2022 14:42:38 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 43DDA604A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 May 2022 14:42:36 +0200 (CEST)","from [192.168.1.106] (unknown [103.251.226.202])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 12EA055A;\n\tMon,  9 May 2022 14:42:34 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652100158;\n\tbh=s9wft/jpS6W8X42eW+2rH0tqL0/6ySxu0l3DsO/PB2o=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=V+D69+GlFta2KjyiYVi1Nl9bVJlKPmhmBP3GAlOdcwRRYiQwZ0oM9TG8VzxTAPkhm\n\tDoXtDZYLkQKtW+8x89dg6LGijg2qRiFTzaTyhW9Yen6n0eR0JA0zHqV7IPEtXlDw8R\n\tkDy6FTvlZKlcjhxMj5g65dmGfhaiIpAN8sr9XinR0VORH6z9erCvp2vgMVEzYQ84+E\n\tPpSRw1yioH6auVnMq/1tCXES9pLbLG3zJFSY2gAeuXKpibCe0wD5laPpuG5EoTrlo1\n\t90+YPPr9HTryzQDtvpc6tIrEm2hgTChROXot5XqF75eOi0wjEXgkAQ68Wr7vtcIMvw\n\taR8tKACVhv86g==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652100155;\n\tbh=s9wft/jpS6W8X42eW+2rH0tqL0/6ySxu0l3DsO/PB2o=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=vOBhrrSauFXt66h0m+8e0mTcnY1mSLhsHXazjwZKIX/14ojrxnIzduMjhP05L7IXX\n\tAk6+Wzk73SrSbUBkBTPpnOmXxTWQhr01EaqAREc6YYba8PlhHwVSabqkekP0ztnIdJ\n\t79SUKIAd1BthhINrhwjvWXpCCZLSPwEhPocr2mDs="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"vOBhrrSa\"; dkim-atps=neutral","Message-ID":"<611a8f5d-4669-116b-c449-6ebbe90afb30@ideasonboard.com>","Date":"Mon, 9 May 2022 18:12:30 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.4.1","Content-Language":"en-US","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","References":"<20220429193434.167990-1-kieran.bingham@ideasonboard.com>\n\t<20220429193434.167990-2-kieran.bingham@ideasonboard.com>","In-Reply-To":"<20220429193434.167990-2-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 1/3] libcamera: Add sequence value\n\tobserver","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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]