Show a patch.

GET /api/patches/15623/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 15623,
    "url": "https://patchwork.libcamera.org/api/patches/15623/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15623/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20220406075859.3857121-2-naush@raspberrypi.com>",
    "date": "2022-04-06T07:58:57",
    "name": "[libcamera-devel,v4,1/3] libcamera: v4l2_videodevice: Add a dequeue timer",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "55def340e178738b12070e1e2026f3986f4064e1",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/15623/mbox/",
    "series": [
        {
            "id": 3031,
            "url": "https://patchwork.libcamera.org/api/series/3031/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3031",
            "date": "2022-04-06T07:58:56",
            "name": "Dequeue timeout",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3031/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15623/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15623/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 AE8F3C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 Apr 2022 07:59:08 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3DDCF65649;\n\tWed,  6 Apr 2022 09:59:07 +0200 (CEST)",
            "from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com\n\t[IPv6:2a00:1450:4864:20::32e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7ABBA6563F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 Apr 2022 09:59:05 +0200 (CEST)",
            "by mail-wm1-x32e.google.com with SMTP id\n\tl7-20020a05600c1d0700b0038c99618859so3084123wms.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 06 Apr 2022 00:59:05 -0700 (PDT)",
            "from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:eedb:32e2:e3d4:3bfa])\n\tby smtp.gmail.com with ESMTPSA id\n\t14-20020a056000154e00b00203f8adde0csm17235503wry.32.2022.04.06.00.59.03\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 06 Apr 2022 00:59:03 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1649231947;\n\tbh=rYcmruh35Pg+MdVWCwJV+IR5WnvTsKJr/Jx6h2VPJGk=;\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=3SyYtLkz7myab0hT8uElonBbE3l5BnEFpYePkjgaWSAclx89IP/rI84uVtN4wCFus\n\tj9OGQgwdgAzKw/ndynqOZqYZA3AvXJbEav1SszT89V7YbF2MG8P5A+r0xJYxyMVkrR\n\tA5W9VEGLMWF8Gouy7laIGHusHfwqYAW2SyZ01/xy2hTZGd9SqxJbZA3f1pWvto0RNT\n\tSmH5Lv8xnC+OkMvSPBSEWNylDFSlrHCd25upB11ZMVWVeF9RnLVUZxh0d8SJpJXAmh\n\t1TjdXjx1xmmvw77X4bwxmR1CU4dTP6nYQRD2hox4tkWKtEywouEeI8ydHZm5nYtL7U\n\tsl8GHhxAOqldQ==",
            "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=ZYCgnUfigpETSTFDrFlUETziIrYy1O0tzrpB8f0Bg/A=;\n\tb=orwOb8y1nU3pIRKc7SpZ5lpOuGnD3L6eLfBj5IcM7eBtL21XQtCmHQqyBP/znlDfMI\n\tz79aUg/3jVm8bySpvM+Hv4hzRfd9NOEfOuOansX5KOgDWrkDxbjtN+xFMmlCB6r6OdtL\n\t46cH3Xd2XDYr1OydfX7g4UBRMGHPfDWmRJwsTsDMg75+jwJIrax/XlrdOb4VlZCPDVJg\n\tquUElZjvPoPxjX6jSnueMO2bOGg+YEURlVWMBunvO1R5cFw6GyhWkODs0V+0WnrL6Ef1\n\tm7/qQ/n1CrPWkKMYVHjjyfg4ltw/Z5YTN9hG95hJvUlOIz/W8uw+2ZYtNVURKaLtxTRU\n\tpeOA=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"orwOb8y1\"; 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=ZYCgnUfigpETSTFDrFlUETziIrYy1O0tzrpB8f0Bg/A=;\n\tb=tuwBB0Fn3dkY8spvUUE2F37kKLKNBX9mw1pbFe5eI9cbXIdlLESRgUEbKj9BSWXSL4\n\t13UZUVmDsQOIqhQbDnqqHkOdcpn0U6I3mN5lFrxsxd8rAtsSB/P8vxCHjF11VHqhfBVC\n\tQ3h4OgM9NGFworl/3NCGN2nYIR6FirVnfI7XXlpiSj/X8rmwelVK0STBa6vyKfD8C022\n\ttWYs8tiQnequB7fMDz9sxA8cHt7T95OjypjJYACcBVeYb6RAab90ntZd4w/nIUYEHPxG\n\tIgU8xEOaK+JCuYNJa5ZqoeZEmHKvJ5B5pxB9+gExehrFTjr/TTY9rnLa94UAZJmSdUBp\n\tFcxA==",
        "X-Gm-Message-State": "AOAM531UOauKL7TvxT/bmV8rdwE4JCwIXqPhy8a76Vy6QEwkRIj3JPDD\n\t1c335xY1UEJ9fq3FntfwcuNaNKnBnNQIrQ==",
        "X-Google-Smtp-Source": "ABdhPJzBUHJviF339eL35Hh7FgEfRyWvNeagD1uTZ8ChtIEBYEBSfL7oWdHd7UdgF25OYtj4alvMLw==",
        "X-Received": "by 2002:a05:600c:4fd4:b0:38c:cc3f:ac01 with SMTP id\n\to20-20020a05600c4fd400b0038ccc3fac01mr6386109wmq.206.1649231944843; \n\tWed, 06 Apr 2022 00:59:04 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed,  6 Apr 2022 08:58:57 +0100",
        "Message-Id": "<20220406075859.3857121-2-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20220406075859.3857121-1-naush@raspberrypi.com>",
        "References": "<20220406075859.3857121-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 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": "From: Naushir Patuck via libcamera-devel <libcamera-devel@lists.libcamera.org>\n\nAdd 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>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_videodevice.h | 10 ++++\n src/libcamera/v4l2_videodevice.cpp            | 55 +++++++++++++++++++\n 2 files changed, 65 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex cfeae7bd6c52..9c9493cc16ed 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -20,7 +20,9 @@\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+#include <libcamera/base/utils.h>\n \n #include <libcamera/color_space.h>\n #include <libcamera/framebuffer.h>\n@@ -217,6 +219,9 @@ public:\n \tint streamOn();\n \tint streamOff();\n \n+\tvoid setDequeueTimeout(utils::Duration timeout);\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+\tutils::Duration watchdogDuration_;\n };\n \n class V4L2M2MDevice\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 0830be80c553..dc5020df5c5c 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@@ -1726,6 +1727,9 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \t\treturn nullptr;\n \t}\n \n+\tif (watchdogDuration_.count())\n+\t\twatchdog_.start(std::chrono::duration_cast<std::chrono::milliseconds>(watchdogDuration_));\n+\n \tcache_->put(buf.index);\n \n \tFrameBuffer *buffer = it->second;\n@@ -1828,6 +1832,8 @@ int V4L2VideoDevice::streamOn()\n \t}\n \n \tstate_ = State::Streaming;\n+\tif (watchdogDuration_.count())\n+\t\twatchdog_.start(std::chrono::duration_cast<std::chrono::milliseconds>(watchdogDuration_));\n \n \treturn 0;\n }\n@@ -1852,6 +1858,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@@ -1879,6 +1888,52 @@ int V4L2VideoDevice::streamOff()\n \treturn 0;\n }\n \n+/**\n+ * \\brief Set the dequeue timeout value\n+ * \\param[in] timeout The timeout value to be used\n+ *\n+ * Sets a timeout value, given by \\a timeout, 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 timeout to 0 to disable the watchdog timer.\n+ */\n+void V4L2VideoDevice::setDequeueTimeout(utils::Duration timeout)\n+{\n+\twatchdogDuration_ = timeout;\n+\n+\twatchdog_.stop();\n+\tif (watchdogDuration_.count() && state_ == State::Streaming) {\n+\t\twatchdog_.start(std::chrono::duration_cast<std::chrono::milliseconds>(timeout));\n+\t}\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_\n+\t\t<< \" 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",
        "v4",
        "1/3"
    ]
}