[{"id":22908,"web_url":"https://patchwork.libcamera.org/comment/22908/","msgid":"<37633d34-5110-98b7-4439-0b4e7dbdb557@ideasonboard.com>","date":"2022-05-09T12:45:19","subject":"Re: [libcamera-devel] [PATCH 3/3] libcamera: v4l2: Detect frame\n\tdrops on V4L2VideoDevice","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> Pipelines with ISPs will report the output sequence number of the\n> V4L2VideoDevice of the ISP as the sequence number of the request buffer\n> completion. These have been seen to provide their own monotonic sequence\n> number, which means that any frame drop from the CSI2 receiver is\n> silently ignored and can easily go unnoticed. (except for frame rate\n> changes).\n>\n> Add an internal tracking of the sequence number on V4L2VideoDevice\n> instances to identify if there is ever a break in the stream.\n>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> ---\n>   include/libcamera/internal/v4l2_videodevice.h |  2 ++\n>   src/libcamera/v4l2_videodevice.cpp            | 10 ++++++++++\n>   2 files changed, 12 insertions(+)\n>\n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 9c9493cc16ed..ab4c4c56436d 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -28,6 +28,7 @@\n>   #include <libcamera/framebuffer.h>\n>   #include <libcamera/geometry.h>\n>   #include <libcamera/pixel_format.h>\n> +#include <libcamera/sequence.h>\n>   \n>   #include \"libcamera/internal/formats.h\"\n>   #include \"libcamera/internal/v4l2_device.h\"\n> @@ -273,6 +274,7 @@ private:\n>   \tEventNotifier *fdBufferNotifier_;\n>   \n>   \tState state_;\n> +\tSequence monotonicObserver_;\n>   \n>   \tTimer watchdog_;\n>   \tutils::Duration watchdogDuration_;\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 05d3273ebb58..4cef5d40e0c6 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1749,6 +1749,14 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n>   \tif (V4L2_TYPE_IS_OUTPUT(buf.type))\n>   \t\treturn buffer;\n>   \n> +\t/*\n> +\t * Observe the buffer sequence number on capture devices to check for\n> +\t * frame drops.\n> +\t */\n> +\tint drops = monotonicObserver_.update(buf.sequence);\n> +\tif (drops)\n> +\t\tLOG(V4L2, Warning) << \"Dropped \" << drops << \" frames\";\n> +\n>   \tunsigned int numV4l2Planes = multiPlanar ? buf.length : 1;\n>   \tFrameMetadata &metadata = buffer->metadata_;\n>   \n> @@ -1832,6 +1840,8 @@ int V4L2VideoDevice::streamOn()\n>   \t\treturn ret;\n>   \t}\n>   \n> +\tmonotonicObserver_.reset();\n> +\n>   \tstate_ = State::Streaming;\n>   \tif (watchdogDuration_.count())\n>   \t\twatchdog_.start(std::chrono::duration_cast<std::chrono::milliseconds>(watchdogDuration_));","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 6F074C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  9 May 2022 12:45:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CAB8D65641;\n\tMon,  9 May 2022 14:45:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 17FC3604A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 May 2022 14:45:25 +0200 (CEST)","from [192.168.1.106] (unknown [103.251.226.202])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0880755A;\n\tMon,  9 May 2022 14:45:23 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652100326;\n\tbh=jklXEYFCv4+VbzRG9HhKJ4pJMbV7MHTwB7ygnwQtk+I=;\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=M1CE2DQ/1rKsIAd4NTsBi/+d8L32ZJU1TnaMu/Td8Z9qfH3ogfCA4qdlQ1qAIkaMS\n\tXDsAiAu/RWxzBwEoRP89UzVyYwKwKgwDZcDEFU5o0zW0WTPK4bCGV3n3Dq9k/Og/7y\n\tpgknU+SbTd9GrqV4fjuUGFSYQmtU1v+EPParXc/BfNxafMvAxEH14HBuL/DRKUW7bX\n\tOK+PZRCwHAE083t6ASoZo/SP+i4Qpy1d8mQWNul6JjgsPEegohcn0UkziBO3/rnmXz\n\tQs5WDeNXu42C7XP1tp6crwDaH84vt9+jmpQtr/CFG6PFTsK4MR2GdEbbjYeh0BMmWV\n\tJ+Ecy2YuP5T4g==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652100324;\n\tbh=jklXEYFCv4+VbzRG9HhKJ4pJMbV7MHTwB7ygnwQtk+I=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=GkEbKwgwU6ScCiC86BbhtKwmDlDzyENSWLCZ10+I6BDMVf1fIMWC44hrrmMnkH7YG\n\tMkxNUIsEJliFDKaHF1ob8xE4jG/jWAtw/jgKzhe7kuS/JjPafA3ktF/07K02K0PjPj\n\tCc3Kg5CLeaarcltRIn9F7jlW3Z9O8XH5ES5FiW5s="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"GkEbKwgw\"; dkim-atps=neutral","Message-ID":"<37633d34-5110-98b7-4439-0b4e7dbdb557@ideasonboard.com>","Date":"Mon, 9 May 2022 18:15:19 +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-4-kieran.bingham@ideasonboard.com>","In-Reply-To":"<20220429193434.167990-4-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 3/3] libcamera: v4l2: Detect frame\n\tdrops on V4L2VideoDevice","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>"}}]