Show a patch.

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

{
    "id": 15530,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/15530/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15530/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20220324093409.29247-1-naush@raspberrypi.com>",
    "date": "2022-03-24T09:34:08",
    "name": "[libcamera-devel,v2,1/2] libcamera: v4l2_videodevice: Add a dequeue timer",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "163d237d58b79f03bff93f20ecce8e45efca0c52",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/15530/mbox/",
    "series": [
        {
            "id": 2992,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2992/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2992",
            "date": "2022-03-24T09:34:08",
            "name": "[libcamera-devel,v2,1/2] libcamera: v4l2_videodevice: Add a dequeue timer",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2992/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15530/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15530/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 A464ABD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Mar 2022 09:34:14 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BFB77604DA;\n\tThu, 24 Mar 2022 10:34:13 +0100 (CET)",
            "from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com\n\t[IPv6:2a00:1450:4864:20::42f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D3DE601F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Mar 2022 10:34:12 +0100 (CET)",
            "by mail-wr1-x42f.google.com with SMTP id t11so5732917wrm.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Mar 2022 02:34:12 -0700 (PDT)",
            "from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:18f1:1b78:a3ab:7eda])\n\tby smtp.gmail.com with ESMTPSA id\n\tv15-20020a056000144f00b002057eac999fsm2243889wrx.76.2022.03.24.02.34.11\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 24 Mar 2022 02:34:11 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648114453;\n\tbh=zILa/s1ntW+kghEdxq25c2IT3/MqXufb22HdwyIDlaQ=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=P7zzfEmtnu+Hd8BQ7zeqqVw4k5UH91to50N4DYwCNCeLpHpq/tLzOhK5xM+iWMmVp\n\tWqrbmYTe2fVetyi0lv7+GjxONINxg5unKqsJ40jXTe0bAoyen/APlW7eZy/kgKUc93\n\tYhC3aT2LSra2FtXHmxpNXRGsf05tppHgFoS+PrfFuxz4xptweTyxJcJLpC+VEuIIfd\n\tlv9RSzYTRQOhGLz0CsR72nPGdK+7FW1ncwtbwSXCWX6bQtBzmjPLKWhDIJ5PSv5Ptk\n\tShou/3yGgPtOaYyS9+uFwwmkq273XymhEjgSEC6uAk6DjYgCLeK1IMM9a7wJqPVngm\n\to+rI/s4I9r+Fw==",
            "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=ipNazOf+GDYpo5NVgHVuDTgMHP3J4Xmz8ZP+fnMDeXE=;\n\tb=qwYDpSJMyAXbuY1joW4PyF3BnGNsdTElGIsm6q18AEttLO/Ug8fy7wDBKpQCZsqBVy\n\tCS++ALMYed0kVfj5ZOyUWwZ3ys0Dylve/1eqGBnzrOThF+2Rga9+ha11bHu5OZAOu/wh\n\tJ5OFgfKk0VNsRLIKd4h5db4fKPRu50vXOX1nlHcnfOyudGy36ow+qxddunV3y/1RNTff\n\tuahhOuG//O6oTxTyYumt+Iv3amfQi+CMYHISrLMv80wNtMuprYdhQcPAGGiSTfZbZc25\n\t/807wbuan4FOw+2cZ5XqaYSl1WfEbcq9tHlawaqYWBgRNkLGkAhIdvoxX3SXhtwZIbMo\n\tWU4g=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"qwYDpSJM\"; 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=ipNazOf+GDYpo5NVgHVuDTgMHP3J4Xmz8ZP+fnMDeXE=;\n\tb=kag4zuaWMD9xsDUIbYq7KeMGBzryNcjnSkf4i1jTPtiP7Fv+vFEDZa8Eo80ycpsD/K\n\tZtONkdbN0FvqpWJ2+ooHcguVgHM1gE60gMORe7ZmzFVI5GM8kBBoIT0tjUjOwbjNPmxf\n\tPvb7PTZCr0EqURFrFcWLy6hCCpqdTsTo0V1Cw28axCt37HmHVhxlFEaVXgfEM9fYVNMa\n\tWERdjhCNAwLEGVA34bPAaeKbDStS9GDArxdniFOMtWdxznymQzfhmwA4kG6XGcS/WCbv\n\tQxMuWsp4DWqUnVtFiq8Ure1nJI5Eqix4uOMi/WH3HDjIStsztApAhZ0yS20dXdbMi9if\n\tXEhQ==",
        "X-Gm-Message-State": "AOAM531DmNtpOzEY5IeB+fwWta5etUDwhr25+s/518x9iimswnrxyyn6\n\tm29Zlcee35SMTuxXltkyJWDSwOblt0SyjA==",
        "X-Google-Smtp-Source": "ABdhPJy1VftVIwWyw3CjFXxCudIlqlkZH5ydjFQTvSViF+IM6XE3hO5ggI4iiyiXMb2ngjgSTtd9PA==",
        "X-Received": "by 2002:adf:dfc2:0:b0:1f0:262a:d831 with SMTP id\n\tq2-20020adfdfc2000000b001f0262ad831mr3715271wrn.589.1648114451724; \n\tThu, 24 Mar 2022 02:34:11 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 24 Mar 2022 09:34:08 +0000",
        "Message-Id": "<20220324093409.29247-1-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 1/2] 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            | 49 +++++++++++++++++++\n 2 files changed, 59 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 2d2ccc477c91..c34cc6585612 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@@ -216,6 +218,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@@ -246,6 +251,8 @@ private:\n \tvoid bufferAvailable();\n \tFrameBuffer *dequeueBuffer();\n \n+\tvoid watchdogExpired();\n+\n \tV4L2Capability caps_;\n \tV4L2DeviceFormat format_;\n \tconst PixelFormatInfo *formatInfo_;\n@@ -259,6 +266,9 @@ private:\n \tEventNotifier *fdBufferNotifier_;\n \n \tbool streaming_;\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 5f36ee20710d..29225f3058b0 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -526,6 +526,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@@ -1695,6 +1696,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@@ -1797,6 +1801,8 @@ int V4L2VideoDevice::streamOn()\n \t}\n \n \tstreaming_ = true;\n+\tif (watchdogDuration_.count())\n+\t\twatchdog_.start(watchdogDuration_);\n \n \treturn 0;\n }\n@@ -1821,6 +1827,9 @@ int V4L2VideoDevice::streamOff()\n \tif (!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@@ -1843,6 +1852,46 @@ 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() && streaming_)\n+\t\twatchdog_.start(msec);\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",
        "v2",
        "1/2"
    ]
}