Show a patch.

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

{
    "id": 10274,
    "url": "https://patchwork.libcamera.org/api/patches/10274/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10274/",
    "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": "<20201028010051.3830668-2-niklas.soderlund@ragnatech.se>",
    "date": "2020-10-28T01:00:43",
    "name": "[libcamera-devel,1/9] libcamera: v4l2_device: Move start of frame detection to V4L2Device",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "fc0d97d06ddf1d7113dc244b9ce8ddcd52fefd99",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/10274/mbox/",
    "series": [
        {
            "id": 1423,
            "url": "https://patchwork.libcamera.org/api/series/1423/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1423",
            "date": "2020-10-28T01:00:42",
            "name": "libcamera: Add helper for controls that take effect with a delay",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1423/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10274/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10274/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 D8B5BC3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Oct 2020 01:01:12 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B76B362244;\n\tWed, 28 Oct 2020 02:01:12 +0100 (CET)",
            "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D57B56220D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Oct 2020 02:01:10 +0100 (CET)",
            "from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de\n\t[79.202.36.88])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 106f6308-18b9-11eb-954c-0050569116f7;\n\tWed, 28 Oct 2020 02:01:09 +0100 (CET)"
        ],
        "X-Halon-ID": "106f6308-18b9-11eb-954c-0050569116f7",
        "Authorized-sender": "niklas.soderlund@fsdn.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org, david.plowman@raspberrypi.com,\n\tnaush@raspberrypi.com",
        "Date": "Wed, 28 Oct 2020 02:00:43 +0100",
        "Message-Id": "<20201028010051.3830668-2-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.29.1",
        "In-Reply-To": "<20201028010051.3830668-1-niklas.soderlund@ragnatech.se>",
        "References": "<20201028010051.3830668-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH 1/9] libcamera: v4l2_device: Move start of\n\tframe detection to V4L2Device",
        "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>",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "base64",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The V4L2_EVENT_FRAME_SYNC event may occur on both V4L2 video-devices\n(V4L2VideoDevice) and sub-devices (V4L2Subdevice). Move the start of\nframe detection to the common base class of the two, V4L2Device.\n\nThere is no functional change.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n* Changes since v1\n- Mark eventAvailable() private instead of protected.\n- Remove a blank line.\n- Call setFd() instead of duplicating it.\n---\n include/libcamera/internal/v4l2_device.h      | 13 +++-\n include/libcamera/internal/v4l2_videodevice.h |  8 --\n src/libcamera/v4l2_device.cpp                 | 76 ++++++++++++++++++-\n src/libcamera/v4l2_videodevice.cpp            | 75 +-----------------\n 4 files changed, 87 insertions(+), 85 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex 722fb72207d74111..295f08f0be6f1980 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -13,11 +13,15 @@\n \n #include <linux/videodev2.h>\n \n+#include <libcamera/signal.h>\n+\n #include \"libcamera/internal/log.h\"\n #include \"libcamera/internal/v4l2_controls.h\"\n \n namespace libcamera {\n \n+class EventNotifier;\n+\n class V4L2Device : protected Loggable\n {\n public:\n@@ -34,6 +38,9 @@ public:\n \tconst std::string &deviceNode() const { return deviceNode_; }\n \tstd::string devicePath() const;\n \n+\tint setFrameStartEnabled(bool enable);\n+\tSignal<uint32_t> frameStart;\n+\n protected:\n \tV4L2Device(const std::string &deviceNode);\n \t~V4L2Device();\n@@ -44,18 +51,22 @@ protected:\n \tint ioctl(unsigned long request, void *argp);\n \n \tint fd() { return fd_; }\n-\n private:\n \tvoid listControls();\n \tvoid updateControls(ControlList *ctrls,\n \t\t\t    const struct v4l2_ext_control *v4l2Ctrls,\n \t\t\t    unsigned int count);\n \n+\tvoid eventAvailable(EventNotifier *notifier);\n+\n \tstd::map<unsigned int, struct v4l2_query_ext_ctrl> controlInfo_;\n \tstd::vector<std::unique_ptr<V4L2ControlId>> controlIds_;\n \tControlInfoMap controls_;\n \tstd::string deviceNode_;\n \tint fd_;\n+\n+\tEventNotifier *fdEventNotifier_;\n+\tbool frameStartEnabled_;\n };\n \n } /* namespace libcamera */\ndiff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 53f6a2d5515b9bb3..cf705ec9cd6ad118 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -204,9 +204,6 @@ public:\n \tint queueBuffer(FrameBuffer *buffer);\n \tSignal<FrameBuffer *> bufferReady;\n \n-\tint setFrameStartEnabled(bool enable);\n-\tSignal<uint32_t> frameStart;\n-\n \tint streamOn();\n \tint streamOff();\n \n@@ -240,8 +237,6 @@ private:\n \tvoid bufferAvailable(EventNotifier *notifier);\n \tFrameBuffer *dequeueBuffer();\n \n-\tvoid eventAvailable(EventNotifier *notifier);\n-\n \tV4L2Capability caps_;\n \n \tenum v4l2_buf_type bufferType_;\n@@ -251,9 +246,6 @@ private:\n \tstd::map<unsigned int, FrameBuffer *> queuedBuffers_;\n \n \tEventNotifier *fdBufferNotifier_;\n-\tEventNotifier *fdEventNotifier_;\n-\n-\tbool frameStartEnabled_;\n };\n \n class V4L2M2MDevice\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 31d4dad0ee47b734..36fe62b04003551e 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -16,6 +16,8 @@\n #include <sys/syscall.h>\n #include <unistd.h>\n \n+#include <libcamera/event_notifier.h>\n+\n #include \"libcamera/internal/log.h\"\n #include \"libcamera/internal/sysfs.h\"\n #include \"libcamera/internal/utils.h\"\n@@ -52,7 +54,8 @@ LOG_DEFINE_CATEGORY(V4L2)\n  * at open() time, and the \\a logTag to prefix log messages with.\n  */\n V4L2Device::V4L2Device(const std::string &deviceNode)\n-\t: deviceNode_(deviceNode), fd_(-1)\n+\t: deviceNode_(deviceNode), fd_(-1), fdEventNotifier_(nullptr),\n+\t  frameStartEnabled_(false)\n {\n }\n \n@@ -87,7 +90,7 @@ int V4L2Device::open(unsigned int flags)\n \t\treturn ret;\n \t}\n \n-\tfd_ = ret;\n+\tsetFd(ret);\n \n \tlistControls();\n \n@@ -117,6 +120,10 @@ int V4L2Device::setFd(int fd)\n \n \tfd_ = fd;\n \n+\tfdEventNotifier_ = new EventNotifier(fd_, EventNotifier::Exception);\n+\tfdEventNotifier_->activated.connect(this, &V4L2Device::eventAvailable);\n+\tfdEventNotifier_->setEnabled(false);\n+\n \treturn 0;\n }\n \n@@ -130,6 +137,8 @@ void V4L2Device::close()\n \tif (!isOpen())\n \t\treturn;\n \n+\tdelete fdEventNotifier_;\n+\n \tif (::close(fd_) < 0)\n \t\tLOG(V4L2, Error) << \"Failed to close V4L2 device: \"\n \t\t\t\t << strerror(errno);\n@@ -396,6 +405,40 @@ std::string V4L2Device::devicePath() const\n \treturn path;\n }\n \n+/**\n+ * \\brief Enable or disable frame start event notification\n+ * \\param[in] enable True to enable frame start events, false to disable them\n+ *\n+ * This function enables or disables generation of frame start events. Once\n+ * enabled, the events are signalled through the frameStart signal.\n+ *\n+ * \\return 0 on success, a negative error code otherwise\n+ */\n+int V4L2Device::setFrameStartEnabled(bool enable)\n+{\n+\tif (frameStartEnabled_ == enable)\n+\t\treturn 0;\n+\n+\tstruct v4l2_event_subscription event{};\n+\tevent.type = V4L2_EVENT_FRAME_SYNC;\n+\n+\tunsigned long request = enable ? VIDIOC_SUBSCRIBE_EVENT\n+\t\t\t      : VIDIOC_UNSUBSCRIBE_EVENT;\n+\tint ret = ioctl(request, &event);\n+\tif (enable && ret)\n+\t\treturn ret;\n+\n+\tfdEventNotifier_->setEnabled(enable);\n+\tframeStartEnabled_ = enable;\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * \\var V4L2Device::frameStart\n+ * \\brief A Signal emitted when capture of a frame has started\n+ */\n+\n /**\n  * \\brief Perform an IOCTL system call on the device node\n  * \\param[in] request The IOCTL request code\n@@ -519,4 +562,33 @@ void V4L2Device::updateControls(ControlList *ctrls,\n \t}\n }\n \n+/**\n+ * \\brief Slot to handle V4L2 events from the V4L2 device\n+ * \\param[in] notifier The event notifier\n+ *\n+ * When this slot is called, a V4L2 event is available to be dequeued from the\n+ * device.\n+ */\n+void V4L2Device::eventAvailable([[maybe_unused]] EventNotifier *notifier)\n+{\n+\tstruct v4l2_event event{};\n+\tint ret = ioctl(VIDIOC_DQEVENT, &event);\n+\tif (ret < 0) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Failed to dequeue event, disabling event notifier\";\n+\t\tfdEventNotifier_->setEnabled(false);\n+\t\treturn;\n+\t}\n+\n+\tif (event.type != V4L2_EVENT_FRAME_SYNC) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Spurious event (\" << event.type\n+\t\t\t<< \"), disabling event notifier\";\n+\t\tfdEventNotifier_->setEnabled(false);\n+\t\treturn;\n+\t}\n+\n+\tframeStart.emit(event.u.frame_sync.frame_sequence);\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 36d7d9a0f27a103f..012d9bc73f30ad09 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -472,8 +472,7 @@ const std::string V4L2DeviceFormat::toString() const\n  * \\param[in] deviceNode The file-system path to the video device node\n  */\n V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n-\t: V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr),\n-\t  fdEventNotifier_(nullptr), frameStartEnabled_(false)\n+\t: V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr)\n {\n \t/*\n \t * We default to an MMAP based CAPTURE video device, however this will\n@@ -566,10 +565,6 @@ int V4L2VideoDevice::open()\n \tfdBufferNotifier_->activated.connect(this, &V4L2VideoDevice::bufferAvailable);\n \tfdBufferNotifier_->setEnabled(false);\n \n-\tfdEventNotifier_ = new EventNotifier(fd(), EventNotifier::Exception);\n-\tfdEventNotifier_->activated.connect(this, &V4L2VideoDevice::eventAvailable);\n-\tfdEventNotifier_->setEnabled(false);\n-\n \tLOG(V4L2, Debug)\n \t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n \t\t<< caps_.driver() << \": \" << caps_.card();\n@@ -659,10 +654,6 @@ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type)\n \tfdBufferNotifier_->activated.connect(this, &V4L2VideoDevice::bufferAvailable);\n \tfdBufferNotifier_->setEnabled(false);\n \n-\tfdEventNotifier_ = new EventNotifier(fd(), EventNotifier::Exception);\n-\tfdEventNotifier_->activated.connect(this, &V4L2VideoDevice::eventAvailable);\n-\tfdEventNotifier_->setEnabled(false);\n-\n \tLOG(V4L2, Debug)\n \t\t<< \"Opened device \" << caps_.bus_info() << \": \"\n \t\t<< caps_.driver() << \": \" << caps_.card();\n@@ -680,7 +671,6 @@ void V4L2VideoDevice::close()\n \n \treleaseBuffers();\n \tdelete fdBufferNotifier_;\n-\tdelete fdEventNotifier_;\n \n \tV4L2Device::close();\n }\n@@ -1533,74 +1523,11 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()\n \treturn buffer;\n }\n \n-/**\n- * \\brief Slot to handle V4L2 events from the V4L2 video device\n- * \\param[in] notifier The event notifier\n- *\n- * When this slot is called, a V4L2 event is available to be dequeued from the\n- * device.\n- */\n-void V4L2VideoDevice::eventAvailable([[maybe_unused]] EventNotifier *notifier)\n-{\n-\tstruct v4l2_event event{};\n-\tint ret = ioctl(VIDIOC_DQEVENT, &event);\n-\tif (ret < 0) {\n-\t\tLOG(V4L2, Error)\n-\t\t\t<< \"Failed to dequeue event, disabling event notifier\";\n-\t\tfdEventNotifier_->setEnabled(false);\n-\t\treturn;\n-\t}\n-\n-\tif (event.type != V4L2_EVENT_FRAME_SYNC) {\n-\t\tLOG(V4L2, Error)\n-\t\t\t<< \"Spurious event (\" << event.type\n-\t\t\t<< \"), disabling event notifier\";\n-\t\tfdEventNotifier_->setEnabled(false);\n-\t\treturn;\n-\t}\n-\n-\tframeStart.emit(event.u.frame_sync.frame_sequence);\n-}\n-\n /**\n  * \\var V4L2VideoDevice::bufferReady\n  * \\brief A Signal emitted when a framebuffer completes\n  */\n \n-/**\n- * \\brief Enable or disable frame start event notification\n- * \\param[in] enable True to enable frame start events, false to disable them\n- *\n- * This function enables or disables generation of frame start events. Once\n- * enabled, the events are signalled through the frameStart signal.\n- *\n- * \\return 0 on success, a negative error code otherwise\n- */\n-int V4L2VideoDevice::setFrameStartEnabled(bool enable)\n-{\n-\tif (frameStartEnabled_ == enable)\n-\t\treturn 0;\n-\n-\tstruct v4l2_event_subscription event{};\n-\tevent.type = V4L2_EVENT_FRAME_SYNC;\n-\n-\tunsigned long request = enable ? VIDIOC_SUBSCRIBE_EVENT\n-\t\t\t      : VIDIOC_UNSUBSCRIBE_EVENT;\n-\tint ret = ioctl(request, &event);\n-\tif (enable && ret)\n-\t\treturn ret;\n-\n-\tfdEventNotifier_->setEnabled(enable);\n-\tframeStartEnabled_ = enable;\n-\n-\treturn ret;\n-}\n-\n-/**\n- * \\var V4L2VideoDevice::frameStart\n- * \\brief A Signal emitted when capture of a frame has started\n- */\n-\n /**\n  * \\brief Start the video stream\n  * \\return 0 on success or a negative error code otherwise\n",
    "prefixes": [
        "libcamera-devel",
        "1/9"
    ]
}