From patchwork Fri Apr 29 19:34:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15753 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 031C9C0F2A for ; Fri, 29 Apr 2022 19:34:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 95F5465649; Fri, 29 Apr 2022 21:34:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651260867; bh=oRF/c0525Cus9kCvVz/f8Vi+n7Gq6xMrXq8wK4Dt6hw=; 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=ws/Vw9TEz8hg8f5WC8jSns5WqRTWYzEeNe01QMaZ/D8fIhwPhk1pC6Xkl3qU5nmX6 EQrCdXga9VQtxOvwOORdS8s88pNZRVa3loHfATolebm/IxZDo5mOubjFroZjcr3BYY pBTNVg57xEbSF1sR2U6pWzN5J8QgwuHW7NPFPVxl7zNzrvzdpKsG/l73N47YSFX1B1 NnSnBk0O0ApFR+rQstQA+pRArvoIS0b2j8k7s+NB7k2MRjMkwG/YwZ+JTnnnfeC5J7 cf1/8pLQk69rUPZuucAUAbLMBDlLVu1Y+takMknj0qlk37K4C2TgxfPmEL3Q7Rwv+S QwuzQBmTIO0EQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B52D65640 for ; Fri, 29 Apr 2022 21:34:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IqKNT10U"; 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 A0C84475; Fri, 29 Apr 2022 21:34:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651260863; bh=oRF/c0525Cus9kCvVz/f8Vi+n7Gq6xMrXq8wK4Dt6hw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IqKNT10UJm6iwr69UlSK1zzTEmrjOt98v7ixajLFv0i/p1DG5aEPA3Kz51rsiKlRR OWaAfvOdvZirPswTFZ2UT3+GeCYIJxYICI3QWkAJ7tE12VY3XJ2Ei+609jdfJroPTY iT9Pra2+iKNXFK/UfgRmj06zd9RUwQmCj/WmJymY= To: libcamera devel 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 Subject: [libcamera-devel] [PATCH 3/3] libcamera: v4l2: Detect frame drops on V4L2VideoDevice 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" Pipelines with ISPs will report the output sequence number of the V4L2VideoDevice of the ISP as the sequence number of the request buffer completion. These have been seen to provide their own monotonic sequence number, which means that any frame drop from the CSI2 receiver is silently ignored and can easily go unnoticed. (except for frame rate changes). Add an internal tracking of the sequence number on V4L2VideoDevice instances to identify if there is ever a break in the stream. Signed-off-by: Kieran Bingham Reviewed-by: Umang Jain --- include/libcamera/internal/v4l2_videodevice.h | 2 ++ src/libcamera/v4l2_videodevice.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 9c9493cc16ed..ab4c4c56436d 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "libcamera/internal/formats.h" #include "libcamera/internal/v4l2_device.h" @@ -273,6 +274,7 @@ private: EventNotifier *fdBufferNotifier_; State state_; + Sequence monotonicObserver_; Timer watchdog_; utils::Duration watchdogDuration_; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 05d3273ebb58..4cef5d40e0c6 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1749,6 +1749,14 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() if (V4L2_TYPE_IS_OUTPUT(buf.type)) return buffer; + /* + * Observe the buffer sequence number on capture devices to check for + * frame drops. + */ + int drops = monotonicObserver_.update(buf.sequence); + if (drops) + LOG(V4L2, Warning) << "Dropped " << drops << " frames"; + unsigned int numV4l2Planes = multiPlanar ? buf.length : 1; FrameMetadata &metadata = buffer->metadata_; @@ -1832,6 +1840,8 @@ int V4L2VideoDevice::streamOn() return ret; } + monotonicObserver_.reset(); + state_ = State::Streaming; if (watchdogDuration_.count()) watchdog_.start(std::chrono::duration_cast(watchdogDuration_));