Patch Detail
Show a patch.
GET /api/patches/3909/?format=api
{ "id": 3909, "url": "https://patchwork.libcamera.org/api/patches/3909/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3909/", "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": "<20200603141609.18584-6-paul.elder@ideasonboard.com>", "date": "2020-06-03T14:16:09", "name": "[libcamera-devel,5/5] v4l2: v4l2_compat: Add sockets to support polling", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "f7b3eb702647b0d9c0f2074ecf31d09fb5f2b6bd", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3909/mbox/", "series": [ { "id": 946, "url": "https://patchwork.libcamera.org/api/series/946/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=946", "date": "2020-06-03T14:16:04", "name": "Support qv4l2 with v4l2-compat", "version": 1, "mbox": "https://patchwork.libcamera.org/series/946/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3909/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3909/checks/", "tags": {}, "headers": { "Return-Path": "<paul.elder@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 2F9996116F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 3 Jun 2020 16:16:30 +0200 (CEST)", "from emerald.amanokami.net (fs76eef344.knge213.ap.nuro.jp\n\t[118.238.243.68])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 093B027C;\n\tWed, 3 Jun 2020 16:16:28 +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=\"iLSk7tfQ\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1591193789;\n\tbh=R0WJ9U03iK+gB9VcUQHl5r54uddRL1IDSrncqefwfms=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=iLSk7tfQ3WRXePchZlLXpIDhncKJxg3y+mvLrKMFIGJU5e/ow6mDZiLM832IMMJbo\n\t5J6hwAwoC8C/emrdOl2g0grMC6O3RzqKJ5JCIQwy6ZesI3sFmMZz6ZmKkA5N7FU1Ys\n\tg4B/VUz+SBRcQ/Qsr77xgMfrcIPOZNF5V+IVqojs=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 3 Jun 2020 23:16:09 +0900", "Message-Id": "<20200603141609.18584-6-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20200603141609.18584-1-paul.elder@ideasonboard.com>", "References": "<20200603141609.18584-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 5/5] v4l2: v4l2_compat: Add sockets to\n\tsupport polling", "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": "Wed, 03 Jun 2020 14:16:30 -0000" }, "content": "To support polling, we need to be able to signal when data is available\nto be read (POLLIN), as well as events (POLLPRI). To allow signaling\nPOLLPRI specifically, change eventfd to a pair of sockets.\n\nAfter adding the socketpair, use the socketpair to signal POLLIN by\nwriting a byte to the socket, and read the byte away upon VIDIOC_DQBUF\nto clear the handled POLLIN.\n\nAlthough POLLPRI is not actually implemented, since we don't support\nevents, the facilities are in place. The implementation for signaling\nand clearing POLLPRI is the same as for POLLIN, except that we would\nsend and receive an out-of-band byte through the socket.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/v4l2/v4l2_camera.cpp | 13 +++++++++++++\n src/v4l2/v4l2_camera.h | 3 +++\n src/v4l2/v4l2_camera_proxy.cpp | 14 ++++++++++++++\n src/v4l2/v4l2_camera_proxy.h | 4 ++++\n src/v4l2/v4l2_compat_manager.cpp | 22 ++++++++++++++++------\n 5 files changed, 50 insertions(+), 6 deletions(-)", "diff": "diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp\nindex 4da01a45..ecbc87ec 100644\n--- a/src/v4l2/v4l2_camera.cpp\n+++ b/src/v4l2/v4l2_camera.cpp\n@@ -8,6 +8,9 @@\n #include \"v4l2_camera.h\"\n \n #include <errno.h>\n+#include <sys/socket.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n \n #include \"libcamera/internal/log.h\"\n \n@@ -51,6 +54,13 @@ void V4L2Camera::close()\n \tbufferAllocator_ = nullptr;\n \n \tcamera_->release();\n+\n+\t::close(sockfd_);\n+}\n+\n+void V4L2Camera::bind(int sockfd)\n+{\n+\tsockfd_ = sockfd;\n }\n \n void V4L2Camera::getStreamConfig(StreamConfiguration *streamConfig)\n@@ -85,6 +95,9 @@ void V4L2Camera::requestComplete(Request *request)\n \tbufferLock_.unlock();\n \n \tbufferSema_.release();\n+\n+\tchar tmp = 0;\n+\t::send(sockfd_, &tmp, 1, 0);\n }\n \n int V4L2Camera::configure(StreamConfiguration *streamConfigOut,\ndiff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h\nindex 303eda44..1ad040c1 100644\n--- a/src/v4l2/v4l2_camera.h\n+++ b/src/v4l2/v4l2_camera.h\n@@ -39,6 +39,7 @@ public:\n \n \tint open();\n \tvoid close();\n+\tvoid bind(int sockfd);\n \tvoid getStreamConfig(StreamConfiguration *streamConfig);\n \tstd::vector<Buffer> completedBuffers();\n \n@@ -70,6 +71,8 @@ private:\n \n \tstd::deque<std::unique_ptr<Request>> pendingRequests_;\n \tstd::deque<std::unique_ptr<Buffer>> completedBuffers_;\n+\n+\tint sockfd_;\n };\n \n #endif /* __V4L2_CAMERA_H__ */\ndiff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex f84982a2..c9d7945a 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -13,6 +13,9 @@\n #include <linux/videodev2.h>\n #include <string.h>\n #include <sys/mman.h>\n+#include <sys/socket.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n \n #include <libcamera/camera.h>\n #include <libcamera/object.h>\n@@ -451,6 +454,11 @@ int V4L2CameraProxy::vidioc_dqbuf(struct v4l2_buffer *arg)\n \n \tcurrentBuf_ = (currentBuf_ + 1) % bufferCount_;\n \n+\tchar tmp;\n+\tint ret = ::recv(sockfd_, &tmp, 1, 0);\n+\tif (ret < 1)\n+\t\treturn -EBUSY;\n+\n \treturn 0;\n }\n \n@@ -529,6 +537,12 @@ int V4L2CameraProxy::ioctl(unsigned long request, void *arg)\n \treturn ret;\n }\n \n+void V4L2CameraProxy::bind(int sockfds[2])\n+{\n+\tsockfd_ = sockfds[0];\n+\tvcam_->bind(sockfds[1]);\n+}\n+\n struct PixelFormatPlaneInfo {\n \tunsigned int bitsPerPixel;\n \tunsigned int hSubSampling;\ndiff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\nindex af9f9bbe..251b14a8 100644\n--- a/src/v4l2/v4l2_camera_proxy.h\n+++ b/src/v4l2/v4l2_camera_proxy.h\n@@ -33,6 +33,8 @@ public:\n \n \tint ioctl(unsigned long request, void *arg);\n \n+\tvoid bind(int sockfds[2]);\n+\n private:\n \tbool validateBufferType(uint32_t type);\n \tbool validateMemoryType(uint32_t memory);\n@@ -77,6 +79,8 @@ private:\n \tstd::map<void *, unsigned int> mmaps_;\n \n \tstd::unique_ptr<V4L2Camera> vcam_;\n+\n+\tint sockfd_;\n };\n \n #endif /* __V4L2_CAMERA_PROXY_H__ */\ndiff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp\nindex 2338a0ee..b6e84866 100644\n--- a/src/v4l2/v4l2_compat_manager.cpp\n+++ b/src/v4l2/v4l2_compat_manager.cpp\n@@ -12,8 +12,8 @@\n #include <map>\n #include <stdarg.h>\n #include <string.h>\n-#include <sys/eventfd.h>\n #include <sys/mman.h>\n+#include <sys/socket.h>\n #include <sys/stat.h>\n #include <sys/sysmacros.h>\n #include <sys/types.h>\n@@ -155,15 +155,25 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod\n \tif (ret < 0)\n \t\treturn ret;\n \n-\tint efd = eventfd(0, oflag & (O_CLOEXEC | O_NONBLOCK));\n-\tif (efd < 0) {\n+\tint sockets[2];\n+\tret = socketpair(AF_UNIX,\n+\t\t\t SOCK_STREAM\n+\t\t\t | ((oflag & O_CLOEXEC) ? SOCK_CLOEXEC : 0)\n+\t\t\t | ((oflag & O_NONBLOCK) ? SOCK_NONBLOCK : 0),\n+\t\t\t 0, sockets);\n+\tif (ret) {\n+\t\tint err = errno;\n \t\tproxy->close();\n-\t\treturn efd;\n+\t\terrno = err;\n+\n+\t\treturn ret;\n \t}\n \n-\tdevices_.emplace(efd, proxy);\n+\tproxy->bind(sockets);\n+\n+\tdevices_.emplace(sockets[0], proxy);\n \n-\treturn efd;\n+\treturn sockets[0];\n }\n \n int V4L2CompatManager::dup(int oldfd)\n", "prefixes": [ "libcamera-devel", "5/5" ] }