Patch Detail
Show a patch.
GET /api/1.1/patches/8414/?format=api
{ "id": 8414, "url": "https://patchwork.libcamera.org/api/1.1/patches/8414/?format=api", "web_url": "https://patchwork.libcamera.org/patch/8414/", "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": "<20200624145256.48266-17-paul.elder@ideasonboard.com>", "date": "2020-06-24T14:52:50", "name": "[libcamera-devel,v4,16/22] v4l2: v4l2_camera: Don't use libcamera::Semaphore for available buffers", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "493a0a581f1e185471b39bdce30da3b5f5daa26c", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/8414/mbox/", "series": [ { "id": 1041, "url": "https://patchwork.libcamera.org/api/1.1/series/1041/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1041", "date": "2020-06-24T14:52:34", "name": "Support v4l2-compliance", "version": 4, "mbox": "https://patchwork.libcamera.org/series/1041/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/8414/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/8414/checks/", "tags": {}, "headers": { "Return-Path": "<paul.elder@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 16EBB609B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Jun 2020 16:53:54 +0200 (CEST)", "from jade.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:8147:f2a2:a8c6:9087])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 625C3595;\n\tWed, 24 Jun 2020 16:53:51 +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=\"ItgpG+UP\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593010433;\n\tbh=hULpYTBQvTYKOONtsF/mqy2j5E3JHOwx6xyxrWlZ+RQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ItgpG+UPdITIuIoa7TfrGRMwHfwjrk3OP69or5vWzAM3YDcdUPZWntcazOk3JWu7N\n\tmLpRzDu3+RxeBhPpf4OopAPu61DBFVBOdFacHzNb542HilUJkrl6RtT0xu/MtjT60H\n\t2n/iRMaTy/a//RrM/jSE4w3cWrTSoLRHl6F2s2FA=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 24 Jun 2020 23:52:50 +0900", "Message-Id": "<20200624145256.48266-17-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20200624145256.48266-1-paul.elder@ideasonboard.com>", "References": "<20200624145256.48266-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 16/22] v4l2: v4l2_camera: Don't use\n\tlibcamera::Semaphore for available buffers", "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, 24 Jun 2020 14:53:54 -0000" }, "content": "In V4L2, a blocked dqbuf should not not also block a streamoff. This\nmeans that on streamoff, the blocked dqbuf must return (with error). We\ncannot do this with the libcamera semaphore, so pull out the necessary\ncomponents of a semaphore, and put them into V4L2Camera, so that dqbuf\nfrom V4L2CameraProxy can wait on a disjunct condition of the\navailability of the semaphore or the stopping of the stream.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v4:\n- cosmetic changes\n\nChanges in v3:\n- don't notify all with the lock held\n\nChanges in v2:\n- remove mutex for isRunning_\n- use V4L2Camera::isRunning() instead of V4L2CameraProxy::streaming_ in\n the dqbuf ioctl handler\n---\n src/v4l2/v4l2_camera.cpp | 34 +++++++++++++++++++++++++++++++---\n src/v4l2/v4l2_camera.h | 9 +++++++--\n src/v4l2/v4l2_camera_proxy.cpp | 11 +++++++++--\n 3 files changed, 47 insertions(+), 7 deletions(-)", "diff": "diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp\nindex 177b1ea..f7df9b8 100644\n--- a/src/v4l2/v4l2_camera.cpp\n+++ b/src/v4l2/v4l2_camera.cpp\n@@ -18,7 +18,7 @@ LOG_DECLARE_CATEGORY(V4L2Compat);\n \n V4L2Camera::V4L2Camera(std::shared_ptr<Camera> camera)\n \t: camera_(camera), isRunning_(false), bufferAllocator_(nullptr),\n-\t efd_(-1)\n+\t efd_(-1), bufferAvailableCount_(0)\n {\n \tcamera_->requestCompleted.connect(this, &V4L2Camera::requestComplete);\n }\n@@ -100,7 +100,11 @@ void V4L2Camera::requestComplete(Request *request)\n \tif (ret != sizeof(data))\n \t\tLOG(V4L2Compat, Error) << \"Failed to signal eventfd POLLIN\";\n \n-\tbufferSema_.release();\n+\t{\n+\t\tMutexLocker locker(bufferMutex_);\n+\t\tbufferAvailableCount_++;\n+\t}\n+\tbufferCV_.notify_all();\n }\n \n int V4L2Camera::configure(StreamConfiguration *streamConfigOut,\n@@ -192,7 +196,11 @@ int V4L2Camera::streamOff()\n \tif (ret < 0)\n \t\treturn ret == -EACCES ? -EBUSY : ret;\n \n-\tisRunning_ = false;\n+\t{\n+\t\tMutexLocker locker(bufferMutex_);\n+\t\tisRunning_ = false;\n+\t}\n+\tbufferCV_.notify_all();\n \n \treturn 0;\n }\n@@ -228,6 +236,26 @@ int V4L2Camera::qbuf(unsigned int index)\n \treturn 0;\n }\n \n+void V4L2Camera::waitForBufferAvailable()\n+{\n+\tMutexLocker locker(bufferMutex_);\n+\tbufferCV_.wait(locker, [&] {\n+\t\t\t return bufferAvailableCount_ >= 1 || !isRunning_;\n+\t\t });\n+\tif (isRunning_)\n+\t\tbufferAvailableCount_--;\n+}\n+\n+bool V4L2Camera::isBufferAvailable()\n+{\n+\tMutexLocker locker(bufferMutex_);\n+\tif (bufferAvailableCount_ < 1)\n+\t\treturn false;\n+\n+\tbufferAvailableCount_--;\n+\treturn true;\n+}\n+\n bool V4L2Camera::isRunning()\n {\n \treturn isRunning_;\ndiff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h\nindex ee53c2b..515e906 100644\n--- a/src/v4l2/v4l2_camera.h\n+++ b/src/v4l2/v4l2_camera.h\n@@ -57,9 +57,10 @@ public:\n \n \tint qbuf(unsigned int index);\n \n-\tbool isRunning();\n+\tvoid waitForBufferAvailable();\n+\tbool isBufferAvailable();\n \n-\tSemaphore bufferSema_;\n+\tbool isRunning();\n \n private:\n \tvoid requestComplete(Request *request);\n@@ -76,6 +77,10 @@ private:\n \tstd::deque<std::unique_ptr<Buffer>> completedBuffers_;\n \n \tint efd_;\n+\n+\tMutex bufferMutex_;\n+\tstd::condition_variable bufferCV_;\n+\tunsigned int bufferAvailableCount_;\n };\n \n #endif /* __V4L2_CAMERA_H__ */\ndiff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex 9965a53..4c140eb 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -590,10 +590,17 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg)\n \t\treturn -EINVAL;\n \n \tif (!file->nonBlocking())\n-\t\tvcam_->bufferSema_.acquire();\n-\telse if (!vcam_->bufferSema_.tryAcquire())\n+\t\tvcam_->waitForBufferAvailable();\n+\telse if (!vcam_->isBufferAvailable())\n \t\treturn -EAGAIN;\n \n+\t/*\n+\t * We need to check here again in case stream was turned off while we\n+\t * were blocked on waitForBufferAvailable().\n+\t */\n+\tif (!vcam_->isRunning())\n+\t\treturn -EINVAL;\n+\n \tupdateBuffers();\n \n \tstruct v4l2_buffer &buf = buffers_[currentBuf_];\n", "prefixes": [ "libcamera-devel", "v4", "16/22" ] }