{"id":15508,"url":"https://patchwork.libcamera.org/api/patches/15508/?format=json","web_url":"https://patchwork.libcamera.org/patch/15508/","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":"<20220322131635.2869526-3-naush@raspberrypi.com>","date":"2022-03-22T13:16:34","name":"[libcamera-devel,v1,2/3] libcamera: v4l2_videodevice: Add a dequeue timer","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"18689a70dc697a4cfc8bb6d6534900b986f1eee3","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/15508/mbox/","series":[{"id":2983,"url":"https://patchwork.libcamera.org/api/series/2983/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2983","date":"2022-03-22T13:16:32","name":"V4L2 dequeue timeout","version":1,"mbox":"https://patchwork.libcamera.org/series/2983/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15508/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15508/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 D1AADC3264\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Mar 2022 13:16:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 136E9604DC;\n\tTue, 22 Mar 2022 14:16:44 +0100 (CET)","from mail-wm1-x334.google.com (mail-wm1-x334.google.com\n\t[IPv6:2a00:1450:4864:20::334])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9A62D604C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Mar 2022 14:16:40 +0100 (CET)","by mail-wm1-x334.google.com with SMTP id\n\tp184-20020a1c29c1000000b0037f76d8b484so1680191wmp.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Mar 2022 06:16:40 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:9e9a:99af:e5a6:319b])\n\tby smtp.gmail.com with ESMTPSA id\n\tn14-20020a7bcbce000000b0038c7776a300sm2293478wmi.0.2022.03.22.06.16.39\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 22 Mar 2022 06:16:39 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1647955004;\n\tbh=qTM4qmAxdbtRT4BQtkJcg/pXc5jc8EJQPvPqtB864us=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Tl7Be3oVhD2JHT451X5yImb7h+aeZum9xnTwIqe7WcWSYar576yyzf5dPsQ0n7Ksf\n\tyb5pXwuwzMR6H0d6briLdKFyH+7W1KeI4kFL2D+dSizbOISm5qN4nnhbajWyNkn56Z\n\tQ+Dl0d9raGzr2yr/+Z+hqxvC37TQxGHGOd60uYfLIR3djwGNE2BCCWNvygQ3Ug4H+A\n\tcsuKnPEzZvqXVjf2jFwkhy3ciXRyByvxMUF5pumjLSRCVAPsbxsquMk5AgYLBd2NOX\n\tBYcUeSKPlMoxpXb1oG4fb4RFWTOfCWMjpZtpCVBoBvabwYcQZLl+bMsN7ZSNOPbHBA\n\txKMxySiBQf65g==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=TT/6DZd4OaL1YskByu42Q+/sSbt1hoBuWG14c19MMoY=;\n\tb=nyi2HF3FLpebjyGmHH3C/xmapimFHvzToHawPoENaDcI7vk8eoIHSeB6iyPGBjJ3Tn\n\tvIul1762snKCtwaSHUtpMbvh5zusSTG/OJZise7ZVYF1YsS6vDxGqAAg1ZZohH6WU2ZV\n\ttlRZvxbGd0JBrRTjX573zXghFJPeu3e3GHtX0a7MS3fCldMlEwz+7yeonCHZHeusSSZn\n\tvxqAOTCNE76bq8ZFLDg4Qzr0uLCDWuX4WsK2l4DtnI83CZA9UhanuJVzbUi5IVa2PdZ0\n\tGXMq4KiYN15cBtOtAQ2WYmlYfflZJ5/BzEWqSo+nuGICfTj0TtWvrXpGfNoluQX46pyY\n\tSk4A=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"nyi2HF3F\"; 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:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=TT/6DZd4OaL1YskByu42Q+/sSbt1hoBuWG14c19MMoY=;\n\tb=NONWXONyQ4jAj5fDRd1Kwbbxm/kq2vYSkclo26CGRCuC1G61MGdB89vZzS6FuWhHQX\n\tqlzQPcTx2o9+vxQLRFruS5yfTBETNv+5wBItMpInrWV7hkW2KGD9KLILo+rjeSXuQZtk\n\t2dBS8V0oK9npEMXg+t/vXz4KXFpHh/Ugw1bqRI0/g7ZC5xYTxIvQx1oQWY1YPglHNGF3\n\t5eZ2oZJGkMDkCbTKspAr/PgnB0w/7N8zmHnAA4KseLja1Y/RX5GAGXkh4Y05TebX6IZI\n\tLnwvlRoxEZibcVOIybYk59dVYyBMPLaqQQhomZVwjVzRYL91vBNPrr6phDboU0KmRUqB\n\tiPbA==","X-Gm-Message-State":"AOAM533knc+HIR2NGPYM8Q1HzYb57H+LGU2I6poJ64JHc6fLXQvlaTiq\n\tM/aNoknTV1NngaqlRYCZE7s+Lem3hEv6Jg==","X-Google-Smtp-Source":"ABdhPJwTT+AqQH5Qs5N3l/Av9AF7xuNc2/RlRNz61QrmCPgoO7v6Pq50+kdGMpEjdGE2AEBDJZv/eQ==","X-Received":"by 2002:a05:6000:154c:b0:203:d46b:ede4 with SMTP id\n\t12-20020a056000154c00b00203d46bede4mr22458424wry.501.1647955000105; \n\tTue, 22 Mar 2022 06:16:40 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 22 Mar 2022 13:16:34 +0000","Message-Id":"<20220322131635.2869526-3-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20220322131635.2869526-1-naush@raspberrypi.com>","References":"<20220322131635.2869526-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v1 2/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 |  9 ++++\n src/libcamera/v4l2_videodevice.cpp            | 47 +++++++++++++++++++\n 2 files changed, 56 insertions(+)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 2d2ccc477c91..dd6e96438637 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -20,6 +20,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@@ -216,6 +217,9 @@ public:\n \tint streamOn();\n \tint streamOff();\n \n+\tvoid setDequeueTimeout(utils::Duration duration);\n+\tSignal<V4L2VideoDevice *> dequeueTimeout;\n+\n \tstatic std::unique_ptr<V4L2VideoDevice>\n \tfromEntityName(const MediaDevice *media, const std::string &entity);\n \n@@ -246,6 +250,8 @@ private:\n \tvoid bufferAvailable();\n \tFrameBuffer *dequeueBuffer();\n \n+\tvoid timerExpired();\n+\n \tV4L2Capability caps_;\n \tV4L2DeviceFormat format_;\n \tconst PixelFormatInfo *formatInfo_;\n@@ -259,6 +265,9 @@ private:\n \tEventNotifier *fdBufferNotifier_;\n \n \tbool streaming_;\n+\n+\tTimer timer_;\n+\tutils::Duration timerDuration_;\n };\n \n class V4L2M2MDevice\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 5f36ee20710d..25bce5475e07 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -600,6 +600,8 @@ int V4L2VideoDevice::open()\n \tfdBufferNotifier_->activated.connect(this, &V4L2VideoDevice::bufferAvailable);\n \tfdBufferNotifier_->setEnabled(false);\n \n+\ttimer_.timeout.connect(this, &V4L2VideoDevice::timerExpired);\n+\n \tLOG(V4L2, Debug)\n \t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n \t\t<< caps_.driver() << \": \" << caps_.card();\n@@ -1695,6 +1697,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \t\treturn nullptr;\n \t}\n \n+\tif (timerDuration_.count())\n+\t\ttimer_.start(timerDuration_);\n+\n \tcache_->put(buf.index);\n \n \tFrameBuffer *buffer = it->second;\n@@ -1797,6 +1802,8 @@ int V4L2VideoDevice::streamOn()\n \t}\n \n \tstreaming_ = true;\n+\tif (timerDuration_.count())\n+\t\ttimer_.start(timerDuration_);\n \n \treturn 0;\n }\n@@ -1821,6 +1828,9 @@ int V4L2VideoDevice::streamOff()\n \tif (!streaming_ && queuedBuffers_.empty())\n \t\treturn 0;\n \n+\tif (timerDuration_.count())\n+\t\ttimer_.stop();\n+\n \tret = ioctl(VIDIOC_STREAMOFF, &bufferType_);\n \tif (ret < 0) {\n \t\tLOG(V4L2, Error)\n@@ -1843,6 +1853,43 @@ int V4L2VideoDevice::streamOff()\n \treturn 0;\n }\n \n+/**\n+ * \\brief Set the dequeue timeout value\n+ * \\param[in] duration The timeout value to be used\n+ *\n+ * Sets a timeout value, given by \\a duration, that will be used by a timer to\n+ * ensure buffer dequeue events are periodically occurring. If the timer\n+ * expires, a slot in the pipeline handler may be optionally called to handle\n+ * this condition through the \\a dequeueTimeout signal.\n+ *\n+ * Set \\a duration to 0 to disable the timeout.\n+ *\n+ */\n+void V4L2VideoDevice::setDequeueTimeout(utils::Duration duration)\n+{\n+\ttimerDuration_ = duration;\n+\n+\ttimer_.stop();\n+\tif (duration.count() && streaming_)\n+\t\ttimer_.start(duration);\n+}\n+\n+/**\n+ * \\brief Slot to handle an expired dequeue timer.\n+ *\n+ * When this slot is called, the the time between successive dequeue events\n+ * is over the required timeout. Optionally call a slot in the pipeline handler\n+ * given by the \\a dequeueTimeout signal.\n+ */\n+void V4L2VideoDevice::timerExpired()\n+{\n+\tLOG(V4L2, Info)\n+\t\t<< \"Dequeue timer of \" << timerDuration_\n+\t\t<< \" has expired!\";\n+\n+\tdequeueTimeout.emit(this);\n+}\n+\n /**\n  * \\brief Create a new video device instance from \\a entity in media device\n  * \\a media\n","prefixes":["libcamera-devel","v1","2/3"]}