Patch Detail
Show a patch.
GET /api/patches/8893/?format=api
{ "id": 8893, "url": "https://patchwork.libcamera.org/api/patches/8893/?format=api", "web_url": "https://patchwork.libcamera.org/patch/8893/", "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": "<20200720224232.153717-2-kieran.bingham@ideasonboard.com>", "date": "2020-07-20T22:42:25", "name": "[libcamera-devel,RFC,1/8] libcamera: buffer: Create a MappedFrameBuffer", "commit_ref": null, "pull_url": null, "state": "rfc", "archived": false, "hash": "d6a5224840f0e211fd4fda52aee48094e8e64a05", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/8893/mbox/", "series": [ { "id": 1119, "url": "https://patchwork.libcamera.org/api/series/1119/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1119", "date": "2020-07-20T22:42:24", "name": "RFC MappedBuffers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1119/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/8893/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/8893/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 1B6BDC2E67\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jul 2020 22:42:41 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 56A8A605C6;\n\tTue, 21 Jul 2020 00:42:39 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 633CD60554\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 21 Jul 2020 00:42:37 +0200 (CEST)", "from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D0B6F563;\n\tTue, 21 Jul 2020 00:42:36 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Plh3sJek\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1595284957;\n\tbh=d1o20GUpXdd+g4xj2BYIhLaUMX9Oe9GZzEWjnPvXOe0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Plh3sJekRKDwB3zh4HuVdiu6eRFWPMAIHzkHWkhkcCDREpbc2NAUJyYrVh9w2ru/O\n\tFCLolSZWV1KnR8S7eBklcAp56f+8XQuVjwP4HP96GC0XkVzV4MNL1mHObs0UOwT043\n\tk02c7OhC/XE9r57nsZf992R/PxdyftiSn5C6yTlk=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "libcamera devel <libcamera-devel@lists.libcamera.org>", "Date": "Mon, 20 Jul 2020 23:42:25 +0100", "Message-Id": "<20200720224232.153717-2-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20200720224232.153717-1-kieran.bingham@ideasonboard.com>", "References": "<20200720224232.153717-1-kieran.bingham@ideasonboard.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [RFC PATCH 1/8] libcamera: buffer: Create a\n\tMappedFrameBuffer", "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=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Provide a MappedFrameBuffer helper class which will map\nall of the Planes within a FrameBuffer and provide CPU addressable\npointers for those planes.\n\nMappings are removed upon destruction.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n\nThis introduces an automatically mapping/unmapping MappedFrameBuffer\nobject, with a move constructor (essential to prevent un-desirable\nunmapping).\n\n\n\n include/libcamera/buffer.h | 23 ++++++++++++++++++++\n src/libcamera/buffer.cpp | 43 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 66 insertions(+)", "diff": "diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\nindex 6bb2e4f8558f..881d736da2db 100644\n--- a/include/libcamera/buffer.h\n+++ b/include/libcamera/buffer.h\n@@ -71,6 +71,29 @@ private:\n \tunsigned int cookie_;\n };\n \n+class MappedFrameBuffer {\n+public:\n+\tMappedFrameBuffer(const FrameBuffer *buffer, int flags);\n+\t~MappedFrameBuffer();\n+\n+\t/* Move constructor only, copying is not permitted. */\n+\tMappedFrameBuffer(MappedFrameBuffer &&rhs);\n+\n+\tstruct MappedPlane {\n+\t\tvoid *address;\n+\t\tsize_t length;\n+\t};\n+\n+\tbool isValid() const { return valid_; }\n+\tint error() const { return error_; }\n+\tconst std::vector<MappedPlane> &maps() const { return maps_; }\n+\n+private:\n+\tint error_;\n+\tbool valid_;\n+\tstd::vector<MappedPlane> maps_;\n+};\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_BUFFER_H__ */\ndiff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\nindex 1a1d4bac7aed..28b43d937f57 100644\n--- a/src/libcamera/buffer.cpp\n+++ b/src/libcamera/buffer.cpp\n@@ -290,4 +290,47 @@ int FrameBuffer::copyFrom(const FrameBuffer *src)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Map all planes of a FrameBuffer\n+ * \\param[in] src Buffer to be mapped\n+ * \\param[in] flags Protection flags to apply to map\n+ *\n+ * Construct an object to map a frame buffer for CPU access.\n+ * The flags are passed directly to mmap and should be either PROT_READ,\n+ * PROT_WRITE, or a bitwise-or combination of both.\n+ */\n+MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, int flags)\n+\t: error_(0)\n+{\n+\tmaps_.reserve(buffer->planes().size());\n+\n+\tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n+\t\tvoid *address = mmap(nullptr, plane.length, flags,\n+\t\t\t\t MAP_SHARED, plane.fd.fd(), 0);\n+\n+\t\tif (address == MAP_FAILED) {\n+\t\t\terror_ = -errno;\n+\t\t\tLOG(Buffer, Error) << \"Failed to mmap plane\";\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tmaps_.push_back({address, plane.length});\n+\t}\n+\n+\tvalid_ = buffer->planes().size() == maps_.size();\n+}\n+\n+MappedFrameBuffer::~MappedFrameBuffer()\n+{\n+\tfor (MappedPlane map : maps_)\n+\t\tmunmap(map.address, map.length);\n+}\n+\n+MappedFrameBuffer::MappedFrameBuffer(MappedFrameBuffer &&rhs)\n+{\n+\terror_ = rhs.error_;\n+\tvalid_ = rhs.valid_;\n+\tmaps_ = std::move(rhs.maps_);\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "RFC", "1/8" ] }