Patch Detail
Show a patch.
GET /api/patches/14917/?format=api
{ "id": 14917, "url": "https://patchwork.libcamera.org/api/patches/14917/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14917/", "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": "<20211130233634.34173-4-jacopo@jmondi.org>", "date": "2021-11-30T23:36:26", "name": "[libcamera-devel,v3,03/11] libcamera: fence: Introduce Fence", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4eb447187d30c3f098ba9e821184863e3e9452d2", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14917/mbox/", "series": [ { "id": 2788, "url": "https://patchwork.libcamera.org/api/series/2788/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2788", "date": "2021-11-30T23:36:23", "name": "libcamera: Add support for Fence", "version": 3, "mbox": "https://patchwork.libcamera.org/series/2788/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14917/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14917/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 12B96C324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 23:35:53 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8976060732;\n\tWed, 1 Dec 2021 00:35:52 +0100 (CET)", "from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF62160710\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 1 Dec 2021 00:35:50 +0100 (CET)", "(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 1AA821BF207;\n\tTue, 30 Nov 2021 23:35:49 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 1 Dec 2021 00:36:26 +0100", "Message-Id": "<20211130233634.34173-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.33.1", "In-Reply-To": "<20211130233634.34173-1-jacopo@jmondi.org>", "References": "<20211130233634.34173-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 03/11] libcamera: fence: Introduce Fence", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Introduce a Fence class which models a synchronization primitive that\nallows to notify the availability of a resource.\n\nThe Fence is modeled as a wrapper of a UniqueFD instance where\nread events are used to signal the Fence. The class can be later\nextended to support additional signalling mechanisms.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/fence.h | 31 ++++++++++\n include/libcamera/meson.build | 1 +\n src/libcamera/fence.cpp | 108 ++++++++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 141 insertions(+)\n create mode 100644 include/libcamera/fence.h\n create mode 100644 src/libcamera/fence.cpp", "diff": "diff --git a/include/libcamera/fence.h b/include/libcamera/fence.h\nnew file mode 100644\nindex 000000000000..95f2dd07f10b\n--- /dev/null\n+++ b/include/libcamera/fence.h\n@@ -0,0 +1,31 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * internal/fence.h - Synchronization fence\n+ */\n+\n+#pragma once\n+\n+#include <libcamera/base/class.h>\n+#include <libcamera/base/unique_fd.h>\n+\n+namespace libcamera {\n+\n+class Fence\n+{\n+public:\n+\tFence(UniqueFD fd);\n+\n+\tbool isValid() const { return fd_.isValid(); }\n+\tconst UniqueFD *fd() const { return &fd_; }\n+\n+\tUniqueFD reset() { return std::move(fd_); }\n+\n+private:\n+\tLIBCAMERA_DISABLE_COPY_AND_MOVE(Fence)\n+\n+\tUniqueFD fd_;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 5f42977c034b..8c2cae00d877 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -6,6 +6,7 @@ libcamera_public_headers = files([\n 'camera.h',\n 'camera_manager.h',\n 'controls.h',\n+ 'fence.h',\n 'framebuffer.h',\n 'framebuffer_allocator.h',\n 'geometry.h',\ndiff --git a/src/libcamera/fence.cpp b/src/libcamera/fence.cpp\nnew file mode 100644\nindex 000000000000..2bab8d7de76a\n--- /dev/null\n+++ b/src/libcamera/fence.cpp\n@@ -0,0 +1,108 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * fence.cpp - Synchronization fence\n+ */\n+\n+#include \"libcamera/fence.h\"\n+\n+namespace libcamera {\n+\n+/**\n+ *\n+ * \\file libcamera/fence.h\n+ * \\brief Synchronization fence\n+ */\n+\n+/**\n+ * \\class Fence\n+ * \\brief Synchronization fence class\n+ *\n+ * The Fence class is a thin abstraction around a UniqueFD which simply allows\n+ * to access it as a const pointer or to move its ownership to the caller.\n+ *\n+ * Synchronization fences are most commonly used in association with frame\n+ * buffers. A FrameBuffer can be associated with a Fence (\\sa\n+ * Request::addBuffer()) so that the library can wait for the Fence to be\n+ * signalled before allowing the camera device to actually access the memory\n+ * area described by the FrameBuffer.\n+ *\n+ * By using synchronization fences, application can then synchronize between\n+ * frame buffer consumers and produces, as in example a video output device and\n+ * camera, to gurantee that new data transfers only happen once the existing\n+ * frames have been displayed.\n+ *\n+ * The Fence class only abstracts the underlying mechanism used by libcamera to\n+ * implement synchronization primitives and allow to wait until an event is\n+ * signalled, but does not implement event notification itself which is instead\n+ * implemented by the core library.\n+ *\n+ * \\sa Request::prepare()\n+ *\n+ * A Fence can be realized by different event notification primitives, the most\n+ * common of which is represented by waiting for read events to happen on a\n+ * file descriptor. This is currently the only mechanism supported by libcamera,\n+ * but others can be implemented by extending or subclassing this class and\n+ * implementing opportune handling in the core library.\n+ *\n+ * The usage of the Fence class allows to abstract the underlying\n+ * synchronization mechanism in use and implement an interface towards other\n+ * library components that will not change when new synchronization primitives\n+ * will be added as fences.\n+ *\n+ * A Fence is contructed with a UniqueFD whose ownship is moved in the Fence. A\n+ * FrameBuffer can be associated with a Fence by passing it to the\n+ * Request::addBuffer() function, which will move the Fence into the FrameBuffer\n+ * itself. Once a Request is queued to the Camera, a preparation phase gurantees\n+ * that before actually applying the Request to the hardware, all the valid\n+ * fences of the frame buffers in a Request are correctly signalled. Once a\n+ * Fence has completed, the library will reset the FrameBuffer fence so that\n+ * application won't be allowed to access it.\n+ *\n+ * An optional timeout can be started while waiting for a fence to complete. If\n+ * waiting on a Fence fails for whatever reason, the FrameBuffer's fence is not\n+ * reset and is made available to application for them to handle it, by\n+ * resetting the Fence to correctly close the underlying UniqueFD.\n+ *\n+ * A failure in waiting for a Fence to complete will result in the Request to\n+ * complete in failed state.\n+ */\n+\n+/**\n+ * \\brief Create a synchronization fence\n+ * \\param[in] fd The synchronization fence unique file descriptor\n+ *\n+ * The unique file descriptor ownership is moved to the Fence.\n+ */\n+Fence::Fence(UniqueFD fd)\n+\t: fd_(std::move(fd))\n+{\n+}\n+\n+/**\n+ * \\fn Fence::isValid()\n+ * \\brief Retrieve if a Fence is valid\n+ *\n+ * A Fence is valid if the UniqueFD it wraps is valid\n+ *\n+ * \\return True if the Fence is valid, false otherwise\n+ */\n+\n+/**\n+ * \\fn Fence::fd()\n+ * \\brief Retrieve a constant pointer to the UniqueFD\n+ * \\return A const pointer to the UniqueFD\n+ */\n+\n+/**\n+ * \\fn Fence::reset()\n+ * \\brief Reset the Fence by moving the UniqueFD ownership to the caller\n+ *\n+ * Reset the Fence by releasing the wrapped UniqueFD. Ownership of the UniqueFD\n+ * is moved to the caller.\n+ *\n+ * \\return The UniqueFD\n+ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex b763110e74a6..b4882a2577f5 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -14,6 +14,7 @@ libcamera_sources = files([\n 'delayed_controls.cpp',\n 'device_enumerator.cpp',\n 'device_enumerator_sysfs.cpp',\n+ 'fence.cpp',\n 'formats.cpp',\n 'framebuffer.cpp',\n 'framebuffer_allocator.cpp',\n", "prefixes": [ "libcamera-devel", "v3", "03/11" ] }