From patchwork Wed Apr 6 07:58:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15623 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 AE8F3C0F1B for ; Wed, 6 Apr 2022 07:59:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DDCF65649; Wed, 6 Apr 2022 09:59:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649231947; bh=rYcmruh35Pg+MdVWCwJV+IR5WnvTsKJr/Jx6h2VPJGk=; 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=3SyYtLkz7myab0hT8uElonBbE3l5BnEFpYePkjgaWSAclx89IP/rI84uVtN4wCFus j9OGQgwdgAzKw/ndynqOZqYZA3AvXJbEav1SszT89V7YbF2MG8P5A+r0xJYxyMVkrR A5W9VEGLMWF8Gouy7laIGHusHfwqYAW2SyZ01/xy2hTZGd9SqxJbZA3f1pWvto0RNT SmH5Lv8xnC+OkMvSPBSEWNylDFSlrHCd25upB11ZMVWVeF9RnLVUZxh0d8SJpJXAmh 1TjdXjx1xmmvw77X4bwxmR1CU4dTP6nYQRD2hox4tkWKtEywouEeI8ydHZm5nYtL7U sl8GHhxAOqldQ== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7ABBA6563F for ; Wed, 6 Apr 2022 09:59:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="orwOb8y1"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id l7-20020a05600c1d0700b0038c99618859so3084123wms.2 for ; Wed, 06 Apr 2022 00:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZYCgnUfigpETSTFDrFlUETziIrYy1O0tzrpB8f0Bg/A=; b=orwOb8y1nU3pIRKc7SpZ5lpOuGnD3L6eLfBj5IcM7eBtL21XQtCmHQqyBP/znlDfMI z79aUg/3jVm8bySpvM+Hv4hzRfd9NOEfOuOansX5KOgDWrkDxbjtN+xFMmlCB6r6OdtL 46cH3Xd2XDYr1OydfX7g4UBRMGHPfDWmRJwsTsDMg75+jwJIrax/XlrdOb4VlZCPDVJg quUElZjvPoPxjX6jSnueMO2bOGg+YEURlVWMBunvO1R5cFw6GyhWkODs0V+0WnrL6Ef1 m7/qQ/n1CrPWkKMYVHjjyfg4ltw/Z5YTN9hG95hJvUlOIz/W8uw+2ZYtNVURKaLtxTRU peOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZYCgnUfigpETSTFDrFlUETziIrYy1O0tzrpB8f0Bg/A=; b=tuwBB0Fn3dkY8spvUUE2F37kKLKNBX9mw1pbFe5eI9cbXIdlLESRgUEbKj9BSWXSL4 13UZUVmDsQOIqhQbDnqqHkOdcpn0U6I3mN5lFrxsxd8rAtsSB/P8vxCHjF11VHqhfBVC Q3h4OgM9NGFworl/3NCGN2nYIR6FirVnfI7XXlpiSj/X8rmwelVK0STBa6vyKfD8C022 tWYs8tiQnequB7fMDz9sxA8cHt7T95OjypjJYACcBVeYb6RAab90ntZd4w/nIUYEHPxG IgU8xEOaK+JCuYNJa5ZqoeZEmHKvJ5B5pxB9+gExehrFTjr/TTY9rnLa94UAZJmSdUBp FcxA== X-Gm-Message-State: AOAM531UOauKL7TvxT/bmV8rdwE4JCwIXqPhy8a76Vy6QEwkRIj3JPDD 1c335xY1UEJ9fq3FntfwcuNaNKnBnNQIrQ== X-Google-Smtp-Source: ABdhPJzBUHJviF339eL35Hh7FgEfRyWvNeagD1uTZ8ChtIEBYEBSfL7oWdHd7UdgF25OYtj4alvMLw== X-Received: by 2002:a05:600c:4fd4:b0:38c:cc3f:ac01 with SMTP id o20-20020a05600c4fd400b0038ccc3fac01mr6386109wmq.206.1649231944843; Wed, 06 Apr 2022 00:59:04 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:eedb:32e2:e3d4:3bfa]) by smtp.gmail.com with ESMTPSA id 14-20020a056000154e00b00203f8adde0csm17235503wry.32.2022.04.06.00.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 00:59:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 08:58:57 +0100 Message-Id: <20220406075859.3857121-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406075859.3857121-1-naush@raspberrypi.com> References: <20220406075859.3857121-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/3] libcamera: v4l2_videodevice: Add a dequeue timer 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Naushir Patuck via libcamera-devel Add a timer that gets reset on every buffer dequeue event. If the timeout expires, optionally call a slot in the pipeline handler to handle this condition. This may be useful in detecting and handling stalls in either the hardware or device driver. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 10 ++++ src/libcamera/v4l2_videodevice.cpp | 55 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index cfeae7bd6c52..9c9493cc16ed 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include @@ -217,6 +219,9 @@ public: int streamOn(); int streamOff(); + void setDequeueTimeout(utils::Duration timeout); + Signal<> dequeueTimeout; + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -253,6 +258,8 @@ private: void bufferAvailable(); FrameBuffer *dequeueBuffer(); + void watchdogExpired(); + V4L2Capability caps_; V4L2DeviceFormat format_; const PixelFormatInfo *formatInfo_; @@ -266,6 +273,9 @@ private: EventNotifier *fdBufferNotifier_; State state_; + + Timer watchdog_; + utils::Duration watchdogDuration_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 0830be80c553..dc5020df5c5c 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -539,6 +539,7 @@ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) V4L2VideoDevice::V4L2VideoDevice(const MediaEntity *entity) : V4L2VideoDevice(entity->deviceNode()) { + watchdog_.timeout.connect(this, &V4L2VideoDevice::watchdogExpired); } V4L2VideoDevice::~V4L2VideoDevice() @@ -1726,6 +1727,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return nullptr; } + if (watchdogDuration_.count()) + watchdog_.start(std::chrono::duration_cast(watchdogDuration_)); + cache_->put(buf.index); FrameBuffer *buffer = it->second; @@ -1828,6 +1832,8 @@ int V4L2VideoDevice::streamOn() } state_ = State::Streaming; + if (watchdogDuration_.count()) + watchdog_.start(std::chrono::duration_cast(watchdogDuration_)); return 0; } @@ -1852,6 +1858,9 @@ int V4L2VideoDevice::streamOff() if (state_ != State::Streaming && queuedBuffers_.empty()) return 0; + if (watchdogDuration_.count()) + watchdog_.stop(); + ret = ioctl(VIDIOC_STREAMOFF, &bufferType_); if (ret < 0) { LOG(V4L2, Error) @@ -1879,6 +1888,52 @@ int V4L2VideoDevice::streamOff() return 0; } +/** + * \brief Set the dequeue timeout value + * \param[in] timeout The timeout value to be used + * + * Sets a timeout value, given by \a timeout, that will be used by a watchdog timer + * to ensure buffer dequeue events are periodically occurring when the device is + * streaming. The watchdog timer is only active when the device is streaming, so + * it is not necessary to disable it when the device stops streaming. The timeout + * value can be safely updated at any time. + * + * If the timer expires, the \ref V4L2VideoDevice::dequeueTimeout signal is + * emitted. This can typically be used by pipeline handlers to be notified of + * stalled devices. + * + * Set \a timeout to 0 to disable the watchdog timer. + */ +void V4L2VideoDevice::setDequeueTimeout(utils::Duration timeout) +{ + watchdogDuration_ = timeout; + + watchdog_.stop(); + if (watchdogDuration_.count() && state_ == State::Streaming) { + watchdog_.start(std::chrono::duration_cast(timeout)); + } +} + +/** + * \var V4L2VideoDevice::dequeueTimeout + * \brief A Signal emitted when the dequeue watchdog timer expires + */ + +/** + * \brief Slot to handle an expired dequeue timer + * + * When this slot is called, the time between successive dequeue events is over + * the required timeout. Emit the \ref V4L2VideoDevice::dequeueTimeout signal. + */ +void V4L2VideoDevice::watchdogExpired() +{ + LOG(V4L2, Warning) + << "Dequeue timer of " << watchdogDuration_ + << " has expired!"; + + dequeueTimeout.emit(); +} + /** * \brief Create a new video device instance from \a entity in media device * \a media From patchwork Wed Apr 6 07:58:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15624 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 15B80C3260 for ; Wed, 6 Apr 2022 07:59:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B97B76564D; Wed, 6 Apr 2022 09:59:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649231949; bh=YfHkyuISdtpEFUz72XKQw2qLvqSSTFQnKC1b5Clku8o=; 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=eNidMTe+2SurCyhRescJ3eOtlg/2WZR5FqNG4B/b9SpEYMFEkdS2JpJGs1vVLvwZr R8OIBwsapcNfhuM6wm2AASbizjJ6e3v0MsjO81xsw4urtPYHBVkwpSNKPxdAzhu9nZ P6R7UZeGlz7lZ9ZWEogBOyuDea8iNe5WY5COd63Hqq2kyScf0WfiH+RYUHLYSqes5E KZH+0LAu9X3+8tkwRWHoF19HvF8X04ufSJ2mDDxJMkQ4BzjereGkIaz+G2C0SU5L2t wkAHiYnRpSMp5agX2jh4+jT+ygzs3RJw2KCCI3WZKIiIesceM2uCmGmFMKwRKs9G8j fiVuHZ32EOiVw== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BCD6665643 for ; Wed, 6 Apr 2022 09:59:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="AdmdVrAq"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id d29so1892794wra.10 for ; Wed, 06 Apr 2022 00:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n+SfiTLIZkbs8xSe1U6Qik4cd6Yqni5HDX2QUf9j1F4=; b=AdmdVrAq5m/5p0SeTRTsF+MIRDLTZINN4j9966/ZzsBbzAPHRp9xFaqwZGUZ6fKsnh oknRVLDmvF4xtQMgeLvc7/UmJ35V1/GZccacKr0qcSTXpiPS9KrTan4oGyrN0YYJt+Wo Vcq6CGPvYru80pG1GPBeeBT41482R+N0t3HhexEixSdvWIGpkKe3iVRvZGfW+fcwIUSJ vNiwH/DFfBVkhHINABfiwYllHO9fXStiExwlrcapr7cX4lnymrkiAX1IjbLqaYMYQKOF ATo8MtPaPprk9eBtrHHfeGQR8h9ZnWUsw99EMJrDq094Z/4FaHYJ0KZSyro9WEQtkeq8 MjAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n+SfiTLIZkbs8xSe1U6Qik4cd6Yqni5HDX2QUf9j1F4=; b=4k/yxdiFO7D3VrrxqmuatO6iDI5H9VWmEWp+y+jzXMlWytpVeqTLQXGuVSHUJcJh8B t+XXe12zC3CmPuZj0xkdDj2uItwEyDlCfG6AtNRjdlS7dEJseH0Jt2XL4CIFoXfgOerk +mlGsyAesFbDxGmZMzm6USF4YBo92/8t+hT7JJtyGHZGQ5SqAvxK4sGS2GQeDbLz+9v/ BOGBlErErHno9AP61hIrP5NNi3eT6p3p9G3REvfkKaSKb/HRXhGXj0Y4YxdtBHse/ifg 0v5jHDBpUvCkeedtqEXsL7/57nBsxPMB08qB5XTgHnjL8kiXLyR8OOtOVD9CKdpJ5L20 gjjA== X-Gm-Message-State: AOAM532iu/LV90YpNbGrHH+N2hXMo58oRuhJtPiBRIfX23RPjp5kD/sl 5c7M9U4HiXmOvVFekBMjH272oLa7j1Oljw== X-Google-Smtp-Source: ABdhPJw7FXdXEMlMzYDUfZY9IlTY7x3dkz2KVE+kU+7j5OuIEXuarcN3THftm7+s86gTIukCjIVKtQ== X-Received: by 2002:adf:f60a:0:b0:206:1201:e223 with SMTP id t10-20020adff60a000000b002061201e223mr5580212wrp.712.1649231946069; Wed, 06 Apr 2022 00:59:06 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:eedb:32e2:e3d4:3bfa]) by smtp.gmail.com with ESMTPSA id 14-20020a056000154e00b00203f8adde0csm17235503wry.32.2022.04.06.00.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 00:59:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 08:58:58 +0100 Message-Id: <20220406075859.3857121-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406075859.3857121-1-naush@raspberrypi.com> References: <20220406075859.3857121-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/3] pipeline: raspberrypi: Add a Unicam dequeue timeout 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Naushir Patuck via libcamera-devel Enable the V4L2VideoDevice dequeue timeout for the Unicam Image node, and connect the timeout signal to a slot in the pipeline handler. This slot will log an error message informing the user of a possible hardware stall. The timeout is calculated as 2x the maximum frame length possible for a given mode, returned by the IPA. Signed-off-by: Naushir Patuck Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/ipa/raspberrypi.mojom | 1 + src/ipa/raspberrypi/raspberrypi.cpp | 2 ++ .../pipeline/raspberrypi/raspberrypi.cpp | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/libcamera/ipa/raspberrypi.mojom b/include/libcamera/ipa/raspberrypi.mojom index acd3cafe6c91..5a228b75cd2f 100644 --- a/include/libcamera/ipa/raspberrypi.mojom +++ b/include/libcamera/ipa/raspberrypi.mojom @@ -41,6 +41,7 @@ struct IPAConfig { struct StartConfig { libcamera.ControlList controls; int32 dropFrameCount; + uint32 maxSensorFrameLengthMs; }; interface IPARPiInterface { diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 1bf4e270b062..89767a9db471 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -280,6 +280,8 @@ void IPARPi::start(const ControlList &controls, ipa::RPi::StartConfig *startConf } startConfig->dropFrameCount = dropFrameCount_; + const Duration maxSensorFrameDuration = mode_.max_frame_length * mode_.line_length; + startConfig->maxSensorFrameLengthMs = maxSensorFrameDuration.get(); firstStart_ = false; lastRunTimestamp_ = 0; diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 8fd79be67988..98c463e39548 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -45,6 +45,8 @@ #include "dma_heaps.h" #include "rpi_stream.h" +using namespace std::chrono_literals; + namespace libcamera { LOG_DEFINE_CATEGORY(RPI) @@ -208,6 +210,7 @@ public: void setIspControls(const ControlList &controls); void setDelayedControls(const ControlList &controls); void setSensorControls(ControlList &controls); + void unicamTimeout(); /* bufferComplete signal handlers. */ void unicamBufferDequeue(FrameBuffer *buffer); @@ -1050,6 +1053,10 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) } } + /* Set the dequeue timeout to 2x the maximum possible frame duration. */ + utils::duration timeout(2 * startConfig.maxSensorFrameLengthMs * 1ms); + data->unicam_[Unicam::Image].dev()->setDequeueTimeout(timeout); + return 0; } @@ -1192,6 +1199,7 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, Me data->isp_[Isp::Stats] = RPi::Stream("ISP Stats", ispCapture3); /* Wire up all the buffer connections. */ + data->unicam_[Unicam::Image].dev()->dequeueTimeout.connect(data.get(), &RPiCameraData::unicamTimeout); data->unicam_[Unicam::Image].dev()->frameStart.connect(data.get(), &RPiCameraData::frameStarted); data->unicam_[Unicam::Image].dev()->bufferReady.connect(data.get(), &RPiCameraData::unicamBufferDequeue); data->isp_[Isp::Input].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispInputDequeue); @@ -1773,6 +1781,13 @@ void RPiCameraData::setSensorControls(ControlList &controls) sensor_->setControls(&controls); } +void RPiCameraData::unicamTimeout() +{ + LOG(RPI, Error) << "Unicam has timed out!"; + LOG(RPI, Error) << "Please check that your camera sensor connector is attached securely."; + LOG(RPI, Error) << "Alternatively, try another cable and/or sensor."; +} + void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) { RPi::Stream *stream = nullptr; From patchwork Wed Apr 6 07:58:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15625 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 DAB69C0F1B for ; Wed, 6 Apr 2022 07:59:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 67B3565644; Wed, 6 Apr 2022 09:59:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649231950; bh=8Ewq6FpKQZHfDJbvneE/YsIROH3JjdaudrsCD96DizA=; 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=Vqjk0wECMkoMwlJVR8jh5GzmLhfNW3slASjy2P+nJRaXACh91MGMQxnFTWnijQilK pO5OCRh52rGJtOcfORiSbE4RFShejZrEQY1d4EGKoKSfcKyCKsuOwarkq0HGhiId+N anDyhG7pzzjer8zNyDlSYCqPq7uHF3uVr4GEk2geprh+Dk0q5qA+sx+gTUg3FboCIX w8qHsXTyqJhesnvwKTCvSeZBsCKinI6foy2ZKrdSchGBcYJ6fmsxBytF6+8huNObbA LMsw+Pz6HOPauCDPFIv27UIjS7Gr91DNhydH/rxw1CQkFMn5F05mPvMqLvV8crvmOh EOYBDl5yGvpTQ== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A857965645 for ; Wed, 6 Apr 2022 09:59:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Gf3s6X9b"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id z1so1934607wrg.4 for ; Wed, 06 Apr 2022 00:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w2V02RKBfRqnzfen6tsvXrw2no3e3coAJ3zggKTkg3E=; b=Gf3s6X9bXF0k0h57ByXdC2oQe1Ek1ZsHSywtL5jKZtwzT/8SwlCZHTFPJXWRJTizCl qjyoB4YOxFi0k1hBYMbixYNrjTlbNOCtPrFC8VMtz1HxW//oqNEYL1i/jW5I/Blwo5qP iCbZyWDA7UFPCDd/gFs/Uikhsgjf5JfcwXaz4xAL14Sz09iJclRDj4f0dSjWEKqNqlYp ArUNtoZu2NXD987JFi2+jPvZvoL06b5lhOkNmZPZhRDslg2j7DGzDlZb+YoSLk0fJLK+ 7OWsnQnfEYEbIvWHFPqZT6dGIDPuqokkEN2qXObEZX80miWTGIF5mvYiWI0Th1O3vV6n 66eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w2V02RKBfRqnzfen6tsvXrw2no3e3coAJ3zggKTkg3E=; b=eclsEh1MLI8xNuLciE69hmNAl4pjCNa4/aP8Wq7SzHyw+GJHpdJ5DYnV3EVkrvw1KY +aBOslWsNlU3nCWQGYAQkKx4DioRO78xsfZCmS6xYhg7cXkCSgNeeVclGfE+4lhy7T7D T6jaJVNSS0JtMpU2dvZIHzfhhISQj1VCjTWAoZ4aiHOhOQSQuHbSg4J0FPWXW6KGPM1D qZQEYmKgGDbtMC6MdK1ZGORBTtM2ojucTZnKmLMOsZMS6hAyKZWndddY9lBMxMtkeRVq E/90/E0pZWY+ZqZOjVu9fpiZDhRRxFCNQjeOOK541truVIil5W8QSMXW0cNhvpAqGaDB DgBw== X-Gm-Message-State: AOAM530Ksf+BmUgmQwkt1FtgxcLxICg1jgqE0GVHdnPBHieSFS+w5UJh vcKSWhciornU1AOAC7pu5+4ZgcyyUx/XrA== X-Google-Smtp-Source: ABdhPJx1cGm/eb36D5y+DJsP7WoF8VJav4jlYZYXLI1bbpmWgdwI3vPqoT4zpFnYEeshegmzxM2oPA== X-Received: by 2002:a5d:6d8b:0:b0:203:f9b4:be1d with SMTP id l11-20020a5d6d8b000000b00203f9b4be1dmr5669066wrs.298.1649231947058; Wed, 06 Apr 2022 00:59:07 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:eedb:32e2:e3d4:3bfa]) by smtp.gmail.com with ESMTPSA id 14-20020a056000154e00b00203f8adde0csm17235503wry.32.2022.04.06.00.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 00:59:06 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 08:58:59 +0100 Message-Id: <20220406075859.3857121-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406075859.3857121-1-naush@raspberrypi.com> References: <20220406075859.3857121-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/3] test: v4l2_videodevice: Verify the Dequeue Watchdog 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Kieran Bingham Add a test that captures 5 frames, with a short (5ms) watchdog. The default framerate of the VIMC pipeline should ensure that we never meet this watchdog, and the timeout should activate. Signed-off-by: Kieran Bingham Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- test/v4l2_videodevice/dequeue_watchdog.cpp | 96 ++++++++++++++++++++++ test/v4l2_videodevice/meson.build | 1 + 2 files changed, 97 insertions(+) create mode 100644 test/v4l2_videodevice/dequeue_watchdog.cpp diff --git a/test/v4l2_videodevice/dequeue_watchdog.cpp b/test/v4l2_videodevice/dequeue_watchdog.cpp new file mode 100644 index 000000000000..0cb4de6f81a0 --- /dev/null +++ b/test/v4l2_videodevice/dequeue_watchdog.cpp @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Ideas on Board Oy. + * + * libcamera V4L2 dequeue watchdog test + */ + +#include + +#include +#include +#include + +#include + +#include "v4l2_videodevice_test.h" + +using namespace libcamera; +using namespace std::chrono_literals; + +class DequeueWatchdogTest : public V4L2VideoDeviceTest +{ +public: + DequeueWatchdogTest() + : V4L2VideoDeviceTest("vimc", "Raw Capture 0"), frames_(0), barks_(0) {} + +protected: + int run() + { + constexpr unsigned int bufferCount = 8; + + EventDispatcher *dispatcher = Thread::current()->eventDispatcher(); + Timer timeout; + + int ret = capture_->allocateBuffers(bufferCount, &buffers_); + if (ret < 0) + return TestFail; + + capture_->dequeueTimeout.connect(this, &DequeueWatchdogTest::barkCounter); + capture_->setDequeueTimeout(5ms); + + capture_->bufferReady.connect(this, &DequeueWatchdogTest::receiveBuffer); + + for (const std::unique_ptr &buffer : buffers_) { + if (capture_->queueBuffer(buffer.get())) { + std::cout << "Failed to queue buffer" << std::endl; + return TestFail; + } + } + + capture_->streamOn(); + + timeout.start(5s); + while (timeout.isRunning()) { + dispatcher->processEvents(); + if (frames_ > 5) + break; + } + + std::cout << "Processed " << frames_ << " frames_ and heard " + << barks_ << " barks_" << std::endl; + + if (!barks_) { + std::cout << "Failed to hear any barks_." << std::endl; + return TestFail; + } + + capture_->streamOff(); + + return TestPass; + } + +private: + void receiveBuffer(FrameBuffer *buffer) + { + if (buffer->metadata().status == FrameMetadata::FrameCancelled) + return; + + std::cout << "Buffer received" << std::endl; + frames_++; + + /* Requeue the buffer for further use. */ + capture_->queueBuffer(buffer); + } + + void barkCounter() + { + std::cout << "Watchdog is barking" << std::endl; + barks_++; + } + + unsigned int frames_; + unsigned int barks_; +}; + +TEST_REGISTER(DequeueWatchdogTest) diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build index 643f82edce5e..7a26f53d106a 100644 --- a/test/v4l2_videodevice/meson.build +++ b/test/v4l2_videodevice/meson.build @@ -6,6 +6,7 @@ v4l2_videodevice_tests = [ ['double_open', 'double_open.cpp'], ['controls', 'controls.cpp'], ['formats', 'formats.cpp'], + ['dequeue_watchdog', 'dequeue_watchdog.cpp'], ['request_buffers', 'request_buffers.cpp'], ['buffer_cache', 'buffer_cache.cpp'], ['stream_on_off', 'stream_on_off.cpp'],