From patchwork Wed Apr 6 12:35:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15631 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 BD0EDC3260 for ; Wed, 6 Apr 2022 12:36:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72A8C6564B; Wed, 6 Apr 2022 14:36:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649248563; bh=kKNc5Avk2FwJqil3H/Ajhco1kcD2GEiIOR6YERdfC3w=; 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=ACtARnAiQamw9OrgsXnyS/xwL7s+maSKnYrg2odyj3Yn98jrdnvnE794XvGP2Ugab 61T/+jL+oo2ATvqvRmfG6NZscIu12W4HEsbdD5WGB1yj0mZt22d60ckZMjnBPGa/gS cbuMPnOTwbcnMpWFJ+Vch4SuisrZQhpdpauEBGlBc0GdCmmm7A4wMzJuQiCIfjnv2i VPLRh0owEjUfvLf5vDd8Aq2DDIYKRvJGtWTiPH1oneF0lDK0vIoZ4TcWlt08jEs0n0 s38UUjKaM/3igay+XFCeZlXA1ijKjfu6iSUTThYpznxpqCExKXeG3wFhE0rsePCnaJ d/tPzJia8E0Xw== 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 D18806563F for ; Wed, 6 Apr 2022 14:36:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="FwG4CY0x"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id h4so2951855wrc.13 for ; Wed, 06 Apr 2022 05:36:01 -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=aUJNEmkQe0GZ1+awdCYosUGZvagdGaLqZ5bpdZXMy/A=; b=FwG4CY0xbNhpGMIAdY+csElcjE44wRQSnc3mXeCWvtZC7LoJbVaAppyHVfc1xMe95A BpYUqq6j5juv88DdrVvxwbfxOtU7MwgpjaiAz5e1K5g9hS6X8pfI+Fd6nd0Aci7LRt9v TM/Qrt19RUR+zy4tIGuLlgVPi1ny8apB3GgiduNZ3OurJjMwO+aQ3N90PTx3td4f+ALG mv18JcyIIqtfrgH5gQzgqyB5HNogCQgbKPQK50u7oHS9m7USw2jmbONDC1FnNmazWueS 75JXYUFkjqS4ht9z3QYOL2YbAvuLYuBROGnS7ddgEYmMSzFF/N54WdHqvOhVKTP+8sUS 7SXw== 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=aUJNEmkQe0GZ1+awdCYosUGZvagdGaLqZ5bpdZXMy/A=; b=TC3kcEyHTFZqrxsnc7Iyy9HlaOX4VhIYLicBFL94DDF15lj9t+Z2/0+lHYPX6qbYfs BfTbxi0vSmrv4Ssty0IVQxXDEexg9w9nHtBIQaW+O8Jew+ysn7ORcIBzAAuQe2AmWF/H ErWU6Nj1hMHiRaznkcsMORRDIQR52PgM5ab1jNkW4++ITzUcg+/XqPSackG/EXtv9M+Q Lw33T+DJvMCbwrjP0UiXoDxyGAbcxcUdBjar5cWidg5Cb71mvVHXwpcet4oLz3YmepP3 a1aGmwEkM/hcd0OVQVufzs4fDWwTkGfPa8vgaKO44fO+T9XY5liYVmBEZvAH7kg+enj3 4D5Q== X-Gm-Message-State: AOAM531MFyEhMeAEV3BaaouCc16z9KzjfT9UYbBzJVFcLNU7ssCNr7Y0 uVGQvIehtRGiNULF+oz1qw3HnDV6IsHWTA== X-Google-Smtp-Source: ABdhPJyrIM6tMur4XOLwlsA+DBms++eBgHtNPEAmligcVWCrS+TSBtdcfGWEq4xDBZK7NGDsMc9sAw== X-Received: by 2002:a5d:44ca:0:b0:206:893:6b5c with SMTP id z10-20020a5d44ca000000b0020608936b5cmr6528487wrr.145.1649248561095; Wed, 06 Apr 2022 05:36:01 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:8464:e7f5:f44c:ee9f]) by smtp.gmail.com with ESMTPSA id p8-20020a5d59a8000000b00204178688d3sm16712490wrr.100.2022.04.06.05.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:36:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 13:35:52 +0100 Message-Id: <20220406123554.4042163-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406123554.4042163-1-naush@raspberrypi.com> References: <20220406123554.4042163-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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" 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 | 53 +++++++++++++++++++ 2 files changed, 63 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..c3a1b6c42e19 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,50 @@ 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 12:35:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15632 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 26A38C0F1B for ; Wed, 6 Apr 2022 12:36:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 632576564C; Wed, 6 Apr 2022 14:36:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649248564; bh=Z37E5czrIxS96iACdLcn9YE3Yf7nsd/gVZv1kceH06E=; 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=zG5PbzLIcSog+kbsclKnq4naIq2eiayWLmnuUhLEMrRl+prNUnLN8+9YWjkhaFNAf 5sqkQBnB0Io+88pF1JzVYnjMLu5+OpqAXLNxw6xCm8YZWqkRNiHnJ+0vc1/KuaKiVh HfdppLT3Mo+x2b6ZYnyMdGdnRjEQmW8Lw3l4FHk1H+GZZ85cyG5jjSkgxuFSngRRLe mP8d7dYfH7t6wbQLjaJy4h/cuLNgIl2nhAdfIaP7zMogyt+56hrTDiCWWokSxxjP/w 3Po52ryCgsXbghocMbjc4C1hUe6xlM1LVW0CJOCd0w2ZJacjmdOQgpgaSxlqDEW0sz p52jnOHF23iQw== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D7126563F for ; Wed, 6 Apr 2022 14:36:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="d/w9tiHw"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id m30so3036114wrb.1 for ; Wed, 06 Apr 2022 05:36:03 -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=SfEznbmp787RA8aq2UHbqCWXXr1yMkSr3uFtkGUjOHE=; b=d/w9tiHwgP2fJ0pxkZkA31T/RT2X5NciOfmc/uhek1pr9MAB47qPyFCss2lQl5wJD4 xPYXdHaA63edTwbC2nhiwv2xEGjXeaALi9VPA0PxWMwAG5SG3/jvX2uTzxQEixm0QWiZ gKvhY3/RYfgNPDDJ+OBOk/DfSTOoRSCLsB5CoB/3EGT8z50oAOgIuAym9+IwrT5dvq6B GBU6+wBfRG1YvbfDppjnuS1si0kAzDQgv0i+jD8YqfB3kyO8CQh1tG5KF3ccz8cV4cFt n1wEgaLHxvsZijOe2bJiUF/vX6Y/DDdnVcVMkvqPgq94vMPVcNV9OXh6mxTXRdKTyUps eL1g== 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=SfEznbmp787RA8aq2UHbqCWXXr1yMkSr3uFtkGUjOHE=; b=7AchjltM/y8QrdTN73hxK3GjBUQQcVmoz5jPTXcEgUp41WC6o4+yFkRPmVOLc6rxpb Um03xBB/k/w23jIvtE3b8qr04rzNOd+4P7aLrefnksS5M3/i8gZKIoltFrpqqeAuIZhq lYvWmA/JxUYswSGAT4PhB4CH73PLchwbH8oQmXUVsbAsGl7KDV1DTaSehxWEqkmUvs2f ACtMkV4ffUg0IR68smC5tiF1a+D89I0ZMYKroYJpVch5i5oSsk5X/4vAyrKWB2K5wnP1 TfLKo8AI3+XqI9qqw0nExYnMzd4KviMH3h0POELU8cbHuDr0vMSMkmWvdqGMhGsbpNY9 ugxA== X-Gm-Message-State: AOAM533rk7i9U9E4QfQ2Kl1WxP8WfrcxpzRax8O61uQ0kxh0WltXeQ1W 6YIeaTjhyQ0faYCU1JXw26UeeoNJTrXscw== X-Google-Smtp-Source: ABdhPJwf/Qn01fMIcwmZCLZbzf/umDyeb6QidGgFctauHT0x37lFblji5SYXrpdTyLwLzj1JbNbWjA== X-Received: by 2002:adf:f74a:0:b0:206:1767:129 with SMTP id z10-20020adff74a000000b0020617670129mr3852440wrp.87.1649248562545; Wed, 06 Apr 2022 05:36:02 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:8464:e7f5:f44c:ee9f]) by smtp.gmail.com with ESMTPSA id p8-20020a5d59a8000000b00204178688d3sm16712490wrr.100.2022.04.06.05.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:36:01 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 13:35:53 +0100 Message-Id: <20220406123554.4042163-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406123554.4042163-1-naush@raspberrypi.com> References: <20220406123554.4042163-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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" 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 | 19 +++++++++++++++++++ 3 files changed, 22 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..d6148724bdd5 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,14 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) } } + /* + * Set the dequeue timeout to the larger of 2x the maximum possible + * frame duration or 1 second. + */ + utils::Duration timeout = + std::max(1s, 2 * startConfig.maxSensorFrameLengthMs * 1ms); + data->unicam_[Unicam::Image].dev()->setDequeueTimeout(timeout); + return 0; } @@ -1192,6 +1203,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 +1785,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 12:35:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15633 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 6887CC0F1B for ; Wed, 6 Apr 2022 12:36:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1A0F46564E; Wed, 6 Apr 2022 14:36:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1649248567; 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=xqZt00pT7ejWTK3I+97oeT68qMK8H/6LVxAJLmxtdivz4H7KtSkYPR0wv6Cpds+k3 sCfiZVC0xIkJ6ji+JS3Q+dCV9oLyeRWlnDC2//IQ+/iwRWAXDrz3UdAfDoInqFpSd2 /Cqtf5RH2mUTnjM1Y/UTckmFlTAXa611ByYdmpC6mfBn5ydIC6O9L/66xIBUURZ9SY SkqpjzbyIUrh/s17NTsL6/t6acYqhstpJXZqukfpbUvhGpAp9I2Em03qIZ2jTz+qrg S63HyMgBoz8GZ1wcu2ukTnOcnqicE/L8Jmu8YYV/j/BFDDPYBCwneQAvO4QODwCi/V tIChoBZ+QHDmw== Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 81B3065651 for ; Wed, 6 Apr 2022 14:36:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="M/yRwrFb"; dkim-atps=neutral Received: by mail-wm1-x32c.google.com with SMTP id n38-20020a05600c502600b0038e4a0fc5easo1535121wmr.3 for ; Wed, 06 Apr 2022 05:36:04 -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=M/yRwrFbX7sjNbJ/SbribQDUohCF4JIJ0kpAH1ZXWqt4jwYdZeEeUpBu4HxqVshRzp Rdnjear8rc0LbIFNvgDavHKgsf3WoH/V5T3kLdIv493DsgkxS3pJK1fcuoPpCG+uPkAE QTAD2i6o/eP1BVFq+WbAFFAUzY6fPRs3uvgMIJUK2hE8XLITRe3cjrWhgJhGqZCujwms Q55tkUd7AFeqvAL9gW25Y5H+ceA6R1ds5oPeq/0DS1uX59zbDEolfHRAXiRRn71MBZHs mAbCUI71DEb9C0hG6EeKNoNf5gBaQxh+hAxDdAXtGxBUxMTWVCbxy8lDrx6srQmfqAc8 Z4JQ== 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=8Ck8AdwTlDDEotu8YM5lRg9hJjO0waujmWTtogyml7IROsv/1U7P9ProJqM3yCFcHr 0QZl1EHmF/Zr60qthalm/7lIfCQbh7Va8bckKc0I/uwJnWaOfl2Jj9P7N1DHtlYNUsWp Q4Kq/MY1HrJM8yh4+xCxpmmetfZ4JYENXhulKh0kwOMx+IcLkIBqiVk+KuA5THgdx/3V D9NAXQ7hlEPHmBNhGLxJkSouJppkAiCWc8No6fdrJ0cbZ4QwXDk/2c+gFfc/sZ+HYGE3 l2D81vKz/3WB0QgF8gp0b2q0uoOxrhfj1zTJDSFW+SQVcZfP8KT6k40IHK2ZN1c4UJ2l 27Cw== X-Gm-Message-State: AOAM533ovVuYHFpNdb3Fvhw+D/8fLntz/Cc1SU0ffrcDuSLQ4kwQqVJj mdRGapPZWYphzn3Qd4n6Dyl2CyMBMX4bmw== X-Google-Smtp-Source: ABdhPJz5Pg6aOiap8zaQryEZxnbe8xY5AamC7Ilc3b5LU14PUM8Ogc+TCs0QI29jXseiADXG1nyvTA== X-Received: by 2002:a05:600c:4f86:b0:38c:bd13:e074 with SMTP id n6-20020a05600c4f8600b0038cbd13e074mr7411880wmq.97.1649248563839; Wed, 06 Apr 2022 05:36:03 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:8464:e7f5:f44c:ee9f]) by smtp.gmail.com with ESMTPSA id p8-20020a5d59a8000000b00204178688d3sm16712490wrr.100.2022.04.06.05.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:36:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Apr 2022 13:35:54 +0100 Message-Id: <20220406123554.4042163-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220406123554.4042163-1-naush@raspberrypi.com> References: <20220406123554.4042163-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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'],