From patchwork Tue Mar 29 11:29:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15581 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 95D45C0F1B for ; Tue, 29 Mar 2022 11:29:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 120B7604C5; Tue, 29 Mar 2022 13:29:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648553377; bh=6uWnvqFM6z9TjkKaLaFdj+tJNLai4fy0JSyD6eLlNWs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BTcsWYw/Waf8WtnZJSY9b1z1tdsnStv0XQ590xn4FUF78adA9u3vqROVTsDgzNhp4 tDbpTS93rcKw9KTeKTeuiAYhAMYBw5D/mOTHAA3dergVmDf0F9wgwtepozsxj8oYIU NR6PABGEMLraEMyTnIcKccPU5VMyZHwwBuZBb2dKgN2C77ds8z6p9Br7/JF+BXnYd8 7rZmh5Vu30N+GNu7IhVbL1burf2170Snmex8/qeVYYqitWtcSSqTXy4OmpkB1cJa+P A3IGR+5mvE8GhvNk2TLFZemsOsKhlepYlzgE7iVO5S0VZgn6quWQJiKDDyQHuzXCaW mthQGoKTvwWYQ== 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 873B660135 for ; Tue, 29 Mar 2022 13:29:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lvx60xc/"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id a1so24319278wrh.10 for ; Tue, 29 Mar 2022 04:29:34 -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:mime-version :content-transfer-encoding; bh=jiUiaj6V+PO+r77ClBHn0L2Fm0x8rUqAAlSGuT11Qck=; b=lvx60xc/D6ynk0tsCFzbKvy1SYseQVjxj0NavCa1tFyAxxL48vp1W5SW/UxXI2+wJO D6VZEZhfJE8ZAvX4WvC4E+BeoTnEDN/kmWhyCiXm+s+uQHKe/eTHdItE9+OF8oR8azOQ k6WyEldBgo71BkX5fh0doa6ZvaBPkuBZ+dhn3Xm8yNNk8TN6TyrfzmWdVXKCZPJ98a77 FN72YaR3wUw6CBODxNkllyb40odx4dhywXFxN8ea//Mlx34S39J+hEFyMJt+RVj+7TgO ZqbHu/9nEJg8FSv5W4r70YyTjKCb+BZ7ags66bE6sC71knSaexSI+YUV2TDGlMqSS/Ww X5bg== 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:mime-version :content-transfer-encoding; bh=jiUiaj6V+PO+r77ClBHn0L2Fm0x8rUqAAlSGuT11Qck=; b=SPxkuVSVjzVXf4CIiqW5CI8ieivejqtJgZu9Xdc+aFPEgPXoNx6Wp0SwcwZPdMQZUQ +GeNAu8jlnBMsmVyVuXZsn59gMUFXEBiybRUW7g3gfeHMVkslkAB+AKYm5lXPgv3O1QK y5ooZgiHX/tHnt57aESVW1S2Bja8iyVjxgZMEV2fXeFSp6cALZACjEXghLiL5nNWa+v9 9JRP+NDEK2jeN64b6sNLT9HP50rzY1O7pM1IaRbucVhUUF8cUYKveXHqBEPAOnHwfQkk cJ50+VZyk9D0MAGeIAAQJ4yRNUgunLmHAFngNoQQ1khD3/lxLUucahUZ7G4nb6fwdrvb Z0nA== X-Gm-Message-State: AOAM533J2O1qb2U9RzIIUvNNa6D0Sup9DARerMaxR7B196yzjxOUs8tx jtF1Jk5TW8NYWcHlxd1OiIr3pw+TiFMLGQ== X-Google-Smtp-Source: ABdhPJzifXkajhG4BNv8VZ8l3LuXz5bWP3ixDtZ6fACGNXoaikyk/QR+TTJtwvNASAYqFKD+53EVKA== X-Received: by 2002:a5d:65c5:0:b0:203:dcc9:546c with SMTP id e5-20020a5d65c5000000b00203dcc9546cmr30525020wrw.130.1648553373913; Tue, 29 Mar 2022 04:29:33 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e34f:94fd:5684:9ead]) by smtp.gmail.com with ESMTPSA id bi20-20020a05600c3d9400b0038cfe80eeddsm1767436wmb.29.2022.03.29.04.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 04:29:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Mar 2022 12:29:27 +0100 Message-Id: <20220329112929.465434-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 54 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index cfeae7bd6c52..2a9ba1fe5c71 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -217,6 +219,9 @@ public: int streamOn(); int streamOff(); + void setDequeueTimeout(std::chrono::milliseconds msec); + 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_; + std::chrono::milliseconds watchdogDuration_; }; class V4L2M2MDevice diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 009f6d55610f..22191cb9de4d 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() @@ -1723,6 +1724,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer() return nullptr; } + if (watchdogDuration_.count()) + watchdog_.start(watchdogDuration_); + cache_->put(buf.index); FrameBuffer *buffer = it->second; @@ -1825,6 +1829,8 @@ int V4L2VideoDevice::streamOn() } state_ = State::Streaming; + if (watchdogDuration_.count()) + watchdog_.start(watchdogDuration_); return 0; } @@ -1849,6 +1855,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) @@ -1876,6 +1885,51 @@ int V4L2VideoDevice::streamOff() return 0; } +/** + * \brief Set the dequeue timeout value + * \param[in] msec The timeout value to be used + * + * Sets a timeout value, given by \a msec, 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 msec to 0 to disable the watchdog timer. + */ +void V4L2VideoDevice::setDequeueTimeout(std::chrono::milliseconds msec) +{ + watchdogDuration_ = msec; + + watchdog_.stop(); + if (watchdogDuration_.count() && state_ == State::Streaming) + watchdog_.start(msec); +} + +/** + * \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_.count() + << " ms has expired!"; + + dequeueTimeout.emit(); +} + /** * \brief Create a new video device instance from \a entity in media device * \a media From patchwork Tue Mar 29 11:29:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15582 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 BBC66C3265 for ; Tue, 29 Mar 2022 11:29:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 938F665631; Tue, 29 Mar 2022 13:29:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648553377; bh=mjbznzRxFUAL8z7yRVPduBNyO7b2NUX6pOgQk8ld8OU=; 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=13pi91tlXlKEge/MQgkRfNx+0cjpGtHWhNzZxMYnphcycEO0L6UwVwNYYIw33T7Og yyARuu2jz2iJbjuk9V9PFLAzMES6utGc5krg1zEJOE1P/+Ym4w5LWshDorha9BYqG2 r9CTlg7kN16Pe8yDEYZZS1gdTA8isqxCKPccrtQD3ppoQ45A7HTjU6KZ9Fj7fOfNLp MidXtReJsYdrJTgHMypklETv3IO1Hd1enXyU2ww+xJ4FCN7yDfiN4NL6Ksry2861qq lGRFv+SJAS56V3X/vXVpcoguaf5571zziXs/0FMVWDGHfmRpDa0Cj58R6/W1GO4Rdk A4DeKfHpAO7Dg== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B508460135 for ; Tue, 29 Mar 2022 13:29:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="r/s6RgHX"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id m30so24360592wrb.1 for ; Tue, 29 Mar 2022 04:29:35 -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=PMJdW2rucqrbrTu3le2vUiYbMO1fA9w3WTWdb1FkfOY=; b=r/s6RgHX1z4RBEmejda9XqRlzC95Ai63VYHEuFiTatG9ezXwYORE3u4HquTsZGBtDt I9ggDH/WiIE4Jb8ykdgfPRCNQcBXH4kuQeFQS1og8sWsZIW2eXX5SFhCr6deGdYEeuHm fZDRbN6o4vsMJ4jr/JcdS7l90WRIdDl8z7JmGUNDLdLpda/L9Z8CEBy3LUtJY3I2Ypds Zqh0uz4v8xS71dRr1eirBEJ8SO6OFXwVwzzcNnhKM56FjHk7Ro8raC3pHi1qUM+x0mqo KfRsxg8UJIxMZZ2EMpg5wNGYzoFyBLdFaT3mwiJeLA+S0+GUpgnRsqrJRnl8HGY2vxLe rbkQ== 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=PMJdW2rucqrbrTu3le2vUiYbMO1fA9w3WTWdb1FkfOY=; b=vEvOo8RHhYq0MRdQKp7kraxMeP4GUIscKvkty3VIMZhgDX+ao+NDRVd8xxX9YMpdwP iUZQ9LnUeERQKMDVSJlw1ILBsCLShKQzbYmkQIQPHNbFw/ZwEvlZqje8cZ/bx0di+GDL tGa7gn8Sq6vEkWbMxFLxVEC+hBEZ/E62GmhSnoZuqAuQ+2yhE0e2rYIzEZfu93M+vPcs Oso37Fp+968mF79wjUGam/IjuDTvNUIkiOdKcUOuSD6+myuqJ+UsZMbwsDOTC/SUWy5G e3bgfq9vRqDZD6WhGBG9zEmBuBfUXkf93ZVM1+1xk1FOw+M9OGXpCS7cV7TEKxGlU2ed rrOg== X-Gm-Message-State: AOAM530fVV4CZh38QbBA06q8U+6fH11akGC+K/gsL5EKlU5/YPZjjeK5 ufPktUjkeAoawBaSGdWKK6yeoP7HIfw+xQ== X-Google-Smtp-Source: ABdhPJycWBY8s48ViGs+xuPO0oCpSRjOwvn7TXz+Gg1TQZaYQH9/eSmDHgDZjN4O5ozEeP7fGhZScQ== X-Received: by 2002:a5d:6e0c:0:b0:1ef:7cbb:a5aa with SMTP id h12-20020a5d6e0c000000b001ef7cbba5aamr30300155wrz.5.1648553374832; Tue, 29 Mar 2022 04:29:34 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e34f:94fd:5684:9ead]) by smtp.gmail.com with ESMTPSA id bi20-20020a05600c3d9400b0038cfe80eeddsm1767436wmb.29.2022.03.29.04.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 04:29:34 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Mar 2022 12:29:28 +0100 Message-Id: <20220329112929.465434-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329112929.465434-1-naush@raspberrypi.com> References: <20220329112929.465434-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 a fatal 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..93931aaf3b55 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -208,6 +208,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 +1051,11 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) } } + /* Set the dequeue timeout to 2x the maximum possible frame duration. */ + std::chrono::milliseconds msec(startConfig.maxSensorFrameLengthMs * 2); + data->unicam_[Unicam::Image].dev()->setDequeueTimeout(msec); + LOG(RPI, Debug) << "Setting Unicam timeout to " << msec << " ms."; + return 0; } @@ -1192,6 +1198,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 +1780,14 @@ void RPiCameraData::setSensorControls(ControlList &controls) sensor_->setControls(&controls); } +void RPiCameraData::unicamTimeout() +{ + LOG(RPI, Error) + << "Unicam has timed out!\n" + "Please check that your camera sensor connector is attached securely.\n" + "Alternatively, try another cable and/or sensor."; +} + void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) { RPi::Stream *stream = nullptr; From patchwork Tue Mar 29 11:29:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15583 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 49FB7C0F1B for ; Tue, 29 Mar 2022 11:29:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E1BDF65635; Tue, 29 Mar 2022 13:29:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648553377; bh=uJkdLyKKi1CM7U78WY3/9v8M7LaHmqKbeWqVheZf5rM=; 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=DnDMFZs3e/P/eeYf2NI6mLHH/BuyBue1dqqpWeMxRWoFJ/x3lptVD5hDdNu+Ea6lQ B/i34hGXG5HC3f2RY9QLpk2wjysYuP5WeFlbdeiQz9OrzAtjrf5Ch24ZZBOyFXsUmU Y+unX9i3GZOj4h1F4E3cMLRjSbuA5+gv9dG4UvmQ2HKIja8MG6UE0k1E0t3QSyhFxe pz/lT0yR4wArH+5F0ZZUCFbVbVVltk8jg8Yxph9bAWRPAdZBxSPhcrRnKDuO5S+D/+ FdsNF0xab3ZnkDeY9N2ROmpA3AuFFolhNsJ87QsW8yCmTqCeQ4jgYB+VCFC4meKcQ2 vM1N2fHgX+evg== 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 74B1B604C5 for ; Tue, 29 Mar 2022 13:29:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="lBBgkEzB"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id m30so24360637wrb.1 for ; Tue, 29 Mar 2022 04:29:36 -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=YymQGyzOkJ/fWIcmhh9T0m5zlCZROtuZjEIX+kkvOFQ=; b=lBBgkEzBnAqXTMiLdHQCLcO9U/cP3po6VfvxyIO0WrE+wZ2WJpuR3lT5OP9XO7hZlR y/mpAXdahEFVGFFiIjWo5cXlihUXhKjnG4ooekOhYyUYgwy7A3bnWF+U481vVBdQ/5M1 6fgsPGQZfMB/ylVJ6o+w5kBzu31I3b/G0g/JgaxOKAFpsVRKFOgUBVPtab8zqAsvikd7 r3UnE6iDpVAjHxqp6kZQ68ghEiJWCfLAT1sSboKWXc8u1G0bk43iAz3YPESBtSXKM1tH k/esSC7WQsLkP3dGRu/EbtlnabiUxjRMuWkdkEIDEvHQW8uzCJWYCaLoxwuQ8zurac7R LC/Q== 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=YymQGyzOkJ/fWIcmhh9T0m5zlCZROtuZjEIX+kkvOFQ=; b=n8dVKZW6v7QQs2w8j69qvk2OwibvHI+rfuNTntoUrV2wRk7NEhPjpxArK2jsdcFwGW xPyZBgdhkFHIA/tI/eXQPLhp9vaiXuOfs0R2v9Hswa5FhWL7hygEAXYxQIOeGP7YUq/D jwPHLGipq/Vh2LRF/8QjdcYfruubEYJ4nG1wosdxxCvVph0LAOqa2jYfZ6rTbH2XJgvO 7S4j8/olXpDgOgg60fAk2osxhKJdSAlHN4dSXGmbY0huLstd5OTgo2wnE3CNgRkZmHX3 EGVWnFb0I6BUs1lt/80HAsKEIiS07Y9ZqetW+RepjOUuIGREWzYZitkQfNYj1UOUmth8 mxRw== X-Gm-Message-State: AOAM53104gQOjskTtZQtgoOrTkjOtgBMIX3f7W2MQ+tauRpc2xkA2eRe EhGgRMYwFxjWmDKPq0NRaOxyAPlFHG/Gow== X-Google-Smtp-Source: ABdhPJxnGfG5mtchbMFio84bRKIgVL/YZea2a7i9MmUg0Bmc81gkvVPhYyKOJuqhE4sZMbJ7SBhEUQ== X-Received: by 2002:adf:cc89:0:b0:203:f654:116a with SMTP id p9-20020adfcc89000000b00203f654116amr29848750wrj.320.1648553375986; Tue, 29 Mar 2022 04:29:35 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:e34f:94fd:5684:9ead]) by smtp.gmail.com with ESMTPSA id bi20-20020a05600c3d9400b0038cfe80eeddsm1767436wmb.29.2022.03.29.04.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 04:29:35 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Mar 2022 12:29:29 +0100 Message-Id: <20220329112929.465434-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329112929.465434-1-naush@raspberrypi.com> References: <20220329112929.465434-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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'],