Patch Detail
Show a patch.
GET /api/patches/3549/?format=api
{ "id": 3549, "url": "https://patchwork.libcamera.org/api/patches/3549/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3549/", "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": "<20200426004309.2743-2-laurent.pinchart@ideasonboard.com>", "date": "2020-04-26T00:43:09", "name": "[libcamera-devel,2/2] libcamera: v4l2_videodevice: Add support for frame start events", "commit_ref": "205f1f13814018e3d0511c797b9399529efe9a59", "pull_url": null, "state": "accepted", "archived": false, "hash": "9e054024b29a9c57557a47fed0cb5d6ed098868f", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3549/mbox/", "series": [ { "id": 828, "url": "https://patchwork.libcamera.org/api/series/828/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=828", "date": "2020-04-26T00:43:08", "name": "[libcamera-devel,1/2] libcamera: v4l2_videodevice: Rename fdEvent_ to fdBufferNotifier_", "version": 1, "mbox": "https://patchwork.libcamera.org/series/828/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3549/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3549/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 31D8562E55\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 26 Apr 2020 02:43:28 +0200 (CEST)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BA983583\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 26 Apr 2020 02:43:27 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"KjjczxPV\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1587861807;\n\tbh=+pQZvmeJ3RUdi7AP82toKPoXIDjIZVJgI2GuEkRuJ9I=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=KjjczxPVJjaZm+jy3iCv+Bf20yFrhXHss19NQxhXZxtQNvMIx80TUoKuN5kDMnBsI\n\t13zjUJT3ncJVaVWlgPosEVi3io/9yGF8RBfvjs23zIy3BaLN2nS9J2SuqUIlkcOi3h\n\tyXqbMoamNOcYsVH0tHZWIce4Y5tapPn30qtKqjdQ=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 26 Apr 2020 03:43:09 +0300", "Message-Id": "<20200426004309.2743-2-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.25.3", "In-Reply-To": "<20200426004309.2743-1-laurent.pinchart@ideasonboard.com>", "References": "<20200426004309.2743-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 2/2] libcamera: v4l2_videodevice: Add\n\tsupport for frame start events", "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>", "X-List-Received-Date": "Sun, 26 Apr 2020 00:43:28 -0000" }, "content": "Extend the V4L2VideoDevice to support notifying of frame start events.\nThe events are received from the device through the V4L2 event API, and\npassed to users of the class through a signal.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/v4l2_videodevice.h | 8 +++\n src/libcamera/v4l2_videodevice.cpp | 75 +++++++++++++++++++++++-\n 2 files changed, 82 insertions(+), 1 deletion(-)", "diff": "diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex ee63d28da734..a0409e59c08f 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -224,6 +224,9 @@ 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@@ -262,6 +265,8 @@ 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@@ -271,6 +276,9 @@ 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_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 18a71e4f8a7f..45aedb1a9490 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -544,7 +544,8 @@ 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: V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr),\n+\t fdEventNotifier_(nullptr), frameStartEnabled_(false)\n {\n \t/*\n \t * We default to an MMAP based CAPTURE video device, however this will\n@@ -637,6 +638,10 @@ 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@@ -726,6 +731,10 @@ 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@@ -743,6 +752,7 @@ void V4L2VideoDevice::close()\n \n \treleaseBuffers();\n \tdelete fdBufferNotifier_;\n+\tdelete fdEventNotifier_;\n \n \tV4L2Device::close();\n }\n@@ -1570,11 +1580,74 @@ 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(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", "2/2" ] }