{"id":15753,"url":"https://patchwork.libcamera.org/api/1.1/patches/15753/?format=json","web_url":"https://patchwork.libcamera.org/patch/15753/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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-4-kieran.bingham@ideasonboard.com>","date":"2022-04-29T19:34:34","name":"[libcamera-devel,3/3] libcamera: v4l2: Detect frame drops on V4L2VideoDevice","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e32f1d4d2abf15539e7d798dd0d41348d115fd48","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":{"id":11,"url":"https://patchwork.libcamera.org/api/1.1/users/11/?format=json","username":"kbingham","first_name":"Kieran","last_name":"Bingham","email":"kieran.bingham@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/15753/mbox/","series":[{"id":3083,"url":"https://patchwork.libcamera.org/api/1.1/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/15753/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15753/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 031C9C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 29 Apr 2022 19:34:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 95F5465649;\n\tFri, 29 Apr 2022 21:34:27 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B52D65640\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 Apr 2022 21:34:24 +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 A0C84475;\n\tFri, 29 Apr 2022 21:34:23 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1651260867;\n\tbh=oRF/c0525Cus9kCvVz/f8Vi+n7Gq6xMrXq8wK4Dt6hw=;\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=ws/Vw9TEz8hg8f5WC8jSns5WqRTWYzEeNe01QMaZ/D8fIhwPhk1pC6Xkl3qU5nmX6\n\tEQrCdXga9VQtxOvwOORdS8s88pNZRVa3loHfATolebm/IxZDo5mOubjFroZjcr3BYY\n\tpBTNVg57xEbSF1sR2U6pWzN5J8QgwuHW7NPFPVxl7zNzrvzdpKsG/l73N47YSFX1B1\n\tNnSnBk0O0ApFR+rQstQA+pRArvoIS0b2j8k7s+NB7k2MRjMkwG/YwZ+JTnnnfeC5J7\n\tcf1/8pLQk69rUPZuucAUAbLMBDlLVu1Y+takMknj0qlk37K4C2TgxfPmEL3Q7Rwv+S\n\tQwuzQBmTIO0EQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1651260863;\n\tbh=oRF/c0525Cus9kCvVz/f8Vi+n7Gq6xMrXq8wK4Dt6hw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=IqKNT10UJm6iwr69UlSK1zzTEmrjOt98v7ixajLFv0i/p1DG5aEPA3Kz51rsiKlRR\n\tOWaAfvOdvZirPswTFZ2UT3+GeCYIJxYICI3QWkAJ7tE12VY3XJ2Ei+609jdfJroPTY\n\tiT9Pra2+iKNXFK/UfgRmj06zd9RUwQmCj/WmJymY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"IqKNT10U\"; dkim-atps=neutral","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Fri, 29 Apr 2022 21:34:34 +0200","Message-Id":"<20220429193434.167990-4-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 3/3] libcamera: v4l2: Detect frame drops\n\ton 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":"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":"Pipelines with ISPs will report the output sequence number of the\nV4L2VideoDevice of the ISP as the sequence number of the request buffer\ncompletion. These have been seen to provide their own monotonic sequence\nnumber, which means that any frame drop from the CSI2 receiver is\nsilently ignored and can easily go unnoticed. (except for frame rate\nchanges).\n\nAdd an internal tracking of the sequence number on V4L2VideoDevice\ninstances to identify if there is ever a break in the stream.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_videodevice.h |  2 ++\n src/libcamera/v4l2_videodevice.cpp            | 10 ++++++++++\n 2 files changed, 12 insertions(+)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 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_;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 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_));\n","prefixes":["libcamera-devel","3/3"]}