{"id":15581,"url":"https://patchwork.libcamera.org/api/patches/15581/?format=json","web_url":"https://patchwork.libcamera.org/patch/15581/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220329112929.465434-1-naush@raspberrypi.com>","date":"2022-03-29T11:29:27","name":"[libcamera-devel,v3,1/3] libcamera: v4l2_videodevice: Add a dequeue timer","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f32c0b9787c668c16947a49bad7839c149b8ce1e","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15581/mbox/","series":[{"id":3012,"url":"https://patchwork.libcamera.org/api/series/3012/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3012","date":"2022-03-29T11:29:27","name":"[libcamera-devel,v3,1/3] libcamera: v4l2_videodevice: Add a dequeue timer","version":3,"mbox":"https://patchwork.libcamera.org/series/3012/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15581/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15581/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 95D45C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Mar 2022 11:29:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 120B7604C5;\n\tTue, 29 Mar 2022 13:29:37 +0200 (CEST)","from mail-wr1-x430.google.com (mail-wr1-x430.google.com\n\t[IPv6:2a00:1450:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 873B660135\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Mar 2022 13:29:34 +0200 (CEST)","by mail-wr1-x430.google.com with SMTP id a1so24319278wrh.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Mar 2022 04:29:34 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:e34f:94fd:5684:9ead])\n\tby smtp.gmail.com with ESMTPSA id\n\tbi20-20020a05600c3d9400b0038cfe80eeddsm1767436wmb.29.2022.03.29.04.29.33\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 29 Mar 2022 04:29:33 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648553377;\n\tbh=6uWnvqFM6z9TjkKaLaFdj+tJNLai4fy0JSyD6eLlNWs=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=BTcsWYw/Waf8WtnZJSY9b1z1tdsnStv0XQ590xn4FUF78adA9u3vqROVTsDgzNhp4\n\ttDbpTS93rcKw9KTeKTeuiAYhAMYBw5D/mOTHAA3dergVmDf0F9wgwtepozsxj8oYIU\n\tNR6PABGEMLraEMyTnIcKccPU5VMyZHwwBuZBb2dKgN2C77ds8z6p9Br7/JF+BXnYd8\n\t7rZmh5Vu30N+GNu7IhVbL1burf2170Snmex8/qeVYYqitWtcSSqTXy4OmpkB1cJa+P\n\tA3IGR+5mvE8GhvNk2TLFZemsOsKhlepYlzgE7iVO5S0VZgn6quWQJiKDDyQHuzXCaW\n\tmthQGoKTvwWYQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=jiUiaj6V+PO+r77ClBHn0L2Fm0x8rUqAAlSGuT11Qck=;\n\tb=lvx60xc/D6ynk0tsCFzbKvy1SYseQVjxj0NavCa1tFyAxxL48vp1W5SW/UxXI2+wJO\n\tD6VZEZhfJE8ZAvX4WvC4E+BeoTnEDN/kmWhyCiXm+s+uQHKe/eTHdItE9+OF8oR8azOQ\n\tk6WyEldBgo71BkX5fh0doa6ZvaBPkuBZ+dhn3Xm8yNNk8TN6TyrfzmWdVXKCZPJ98a77\n\tFN72YaR3wUw6CBODxNkllyb40odx4dhywXFxN8ea//Mlx34S39J+hEFyMJt+RVj+7TgO\n\tZqbHu/9nEJg8FSv5W4r70YyTjKCb+BZ7ags66bE6sC71knSaexSI+YUV2TDGlMqSS/Ww\n\tX5bg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"lvx60xc/\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=jiUiaj6V+PO+r77ClBHn0L2Fm0x8rUqAAlSGuT11Qck=;\n\tb=SPxkuVSVjzVXf4CIiqW5CI8ieivejqtJgZu9Xdc+aFPEgPXoNx6Wp0SwcwZPdMQZUQ\n\t+GeNAu8jlnBMsmVyVuXZsn59gMUFXEBiybRUW7g3gfeHMVkslkAB+AKYm5lXPgv3O1QK\n\ty5ooZgiHX/tHnt57aESVW1S2Bja8iyVjxgZMEV2fXeFSp6cALZACjEXghLiL5nNWa+v9\n\t9JRP+NDEK2jeN64b6sNLT9HP50rzY1O7pM1IaRbucVhUUF8cUYKveXHqBEPAOnHwfQkk\n\tcJ50+VZyk9D0MAGeIAAQJ4yRNUgunLmHAFngNoQQ1khD3/lxLUucahUZ7G4nb6fwdrvb\n\tZ0nA==","X-Gm-Message-State":"AOAM533J2O1qb2U9RzIIUvNNa6D0Sup9DARerMaxR7B196yzjxOUs8tx\n\tjtF1Jk5TW8NYWcHlxd1OiIr3pw+TiFMLGQ==","X-Google-Smtp-Source":"ABdhPJzifXkajhG4BNv8VZ8l3LuXz5bWP3ixDtZ6fACGNXoaikyk/QR+TTJtwvNASAYqFKD+53EVKA==","X-Received":"by 2002:a5d:65c5:0:b0:203:dcc9:546c with SMTP id\n\te5-20020a5d65c5000000b00203dcc9546cmr30525020wrw.130.1648553373913; \n\tTue, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 1/3] libcamera: v4l2_videodevice: Add a\n\tdequeue timer","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a timer that gets reset on every buffer dequeue event. If the timeout\nexpires, optionally call a slot in the pipeline handler to handle this\ncondition. This may be useful in detecting and handling stalls in either the\nhardware or device driver.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n include/libcamera/internal/v4l2_videodevice.h | 10 ++++\n src/libcamera/v4l2_videodevice.cpp            | 54 +++++++++++++++++++\n 2 files changed, 64 insertions(+)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex cfeae7bd6c52..2a9ba1fe5c71 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -9,6 +9,7 @@\n \n #include <array>\n #include <atomic>\n+#include <chrono>\n #include <memory>\n #include <optional>\n #include <stdint.h>\n@@ -20,6 +21,7 @@\n #include <libcamera/base/class.h>\n #include <libcamera/base/log.h>\n #include <libcamera/base/signal.h>\n+#include <libcamera/base/timer.h>\n #include <libcamera/base/unique_fd.h>\n \n #include <libcamera/color_space.h>\n@@ -217,6 +219,9 @@ public:\n \tint streamOn();\n \tint streamOff();\n \n+\tvoid setDequeueTimeout(std::chrono::milliseconds msec);\n+\tSignal<> dequeueTimeout;\n+\n \tstatic std::unique_ptr<V4L2VideoDevice>\n \tfromEntityName(const MediaDevice *media, const std::string &entity);\n \n@@ -253,6 +258,8 @@ private:\n \tvoid bufferAvailable();\n \tFrameBuffer *dequeueBuffer();\n \n+\tvoid watchdogExpired();\n+\n \tV4L2Capability caps_;\n \tV4L2DeviceFormat format_;\n \tconst PixelFormatInfo *formatInfo_;\n@@ -266,6 +273,9 @@ private:\n \tEventNotifier *fdBufferNotifier_;\n \n \tState state_;\n+\n+\tTimer watchdog_;\n+\tstd::chrono::milliseconds watchdogDuration_;\n };\n \n class V4L2M2MDevice\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 009f6d55610f..22191cb9de4d 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -539,6 +539,7 @@ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n V4L2VideoDevice::V4L2VideoDevice(const MediaEntity *entity)\n \t: V4L2VideoDevice(entity->deviceNode())\n {\n+\twatchdog_.timeout.connect(this, &V4L2VideoDevice::watchdogExpired);\n }\n \n V4L2VideoDevice::~V4L2VideoDevice()\n@@ -1723,6 +1724,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \t\treturn nullptr;\n \t}\n \n+\tif (watchdogDuration_.count())\n+\t\twatchdog_.start(watchdogDuration_);\n+\n \tcache_->put(buf.index);\n \n \tFrameBuffer *buffer = it->second;\n@@ -1825,6 +1829,8 @@ int V4L2VideoDevice::streamOn()\n \t}\n \n \tstate_ = State::Streaming;\n+\tif (watchdogDuration_.count())\n+\t\twatchdog_.start(watchdogDuration_);\n \n \treturn 0;\n }\n@@ -1849,6 +1855,9 @@ int V4L2VideoDevice::streamOff()\n \tif (state_ != State::Streaming && queuedBuffers_.empty())\n \t\treturn 0;\n \n+\tif (watchdogDuration_.count())\n+\t\twatchdog_.stop();\n+\n \tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n \tif (ret < 0) {\n \t\tLOG(V4L2, Error)\n@@ -1876,6 +1885,51 @@ int V4L2VideoDevice::streamOff()\n \treturn 0;\n }\n \n+/**\n+ * \\brief Set the dequeue timeout value\n+ * \\param[in] msec The timeout value to be used\n+ *\n+ * Sets a timeout value, given by \\a msec, that will be used by a watchdog timer\n+ * to ensure buffer dequeue events are periodically occurring when the device is\n+ * streaming. The watchdog timer is only active when the device is streaming, so\n+ * it is not necessary to disable it when the device stops streaming. The timeout\n+ * value can be safely updated at any time.\n+ *\n+ * If the timer expires, the \\ref V4L2VideoDevice::dequeueTimeout signal is\n+ * emitted. This can typically be used by pipeline handlers to be notified of\n+ * stalled devices.\n+ *\n+ * Set \\a msec to 0 to disable the watchdog timer.\n+ */\n+void V4L2VideoDevice::setDequeueTimeout(std::chrono::milliseconds msec)\n+{\n+\twatchdogDuration_ = msec;\n+\n+\twatchdog_.stop();\n+\tif (watchdogDuration_.count() && state_ == State::Streaming)\n+\t\twatchdog_.start(msec);\n+}\n+\n+/**\n+ * \\var V4L2VideoDevice::dequeueTimeout\n+ * \\brief A Signal emitted when the dequeue watchdog timer expires\n+ */\n+\n+/**\n+ * \\brief Slot to handle an expired dequeue timer.\n+ *\n+ * When this slot is called, the time between successive dequeue events is over\n+ * the required timeout. Emit the \\ref V4L2VideoDevice::dequeueTimeout signal.\n+ */\n+void V4L2VideoDevice::watchdogExpired()\n+{\n+\tLOG(V4L2, Warning)\n+\t\t<< \"Dequeue timer of \" << watchdogDuration_.count()\n+\t\t<< \" ms has expired!\";\n+\n+\tdequeueTimeout.emit();\n+}\n+\n /**\n  * \\brief Create a new video device instance from \\a entity in media device\n  * \\a media\n","prefixes":["libcamera-devel","v3","1/3"]}