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