Patch Detail
Show a patch.
GET /api/1.1/patches/486/?format=api
{ "id": 486, "url": "https://patchwork.libcamera.org/api/1.1/patches/486/?format=api", "web_url": "https://patchwork.libcamera.org/patch/486/", "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": "<20190203105517.5355-6-kieran.bingham@ideasonboard.com>", "date": "2019-02-03T10:55:17", "name": "[libcamera-devel,v2,5/5] libcamera: buffer: Provide Buffer Planes", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "74305a9fac33b0edbc9d4fa335bd0b6338bc4c48", "submitter": { "id": 4, "url": "https://patchwork.libcamera.org/api/1.1/people/4/?format=api", "name": "Kieran Bingham", "email": "kieran.bingham@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/486/mbox/", "series": [ { "id": 164, "url": "https://patchwork.libcamera.org/api/1.1/series/164/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=164", "date": "2019-02-03T10:55:12", "name": "libcamera: Buffer Objects", "version": 2, "mbox": "https://patchwork.libcamera.org/series/164/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/486/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/486/checks/", "tags": {}, "headers": { "Return-Path": "<kieran.bingham@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 6440D60DB5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 3 Feb 2019 11:55:22 +0100 (CET)", "from localhost.localdomain\n\t(218.182-78-194.adsl-static.isp.belgacom.be [194.78.182.218])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1118A41;\n\tSun, 3 Feb 2019 11:55:22 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549191322;\n\tbh=ucXzhou69UrroknYx5pOV3IP4jtEFpQzVog2HmdzNFk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qxXEyG4/0sg0qWLjBvRB6Pbe0dYnSZ+3l906m2jicvV4JPr0RcwXR/nqbzG4Xcx8z\n\tRFSOnMIIrSoRFAqk3XFbn3f2qyKpLX+6xubzwCFM3lXHbs4eYejFX5O5UZHPN3ByHB\n\t3dOMCkPVoih1LF97qcCcIZgmxJ/dNN9zq/SQdH5Y=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>", "Date": "Sun, 3 Feb 2019 11:55:17 +0100", "Message-Id": "<20190203105517.5355-6-kieran.bingham@ideasonboard.com>", "X-Mailer": "git-send-email 2.19.1", "In-Reply-To": "<20190203105517.5355-1-kieran.bingham@ideasonboard.com>", "References": "<20190203105517.5355-1-kieran.bingham@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 5/5] libcamera: buffer: Provide Buffer\n\tPlanes", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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, 03 Feb 2019 10:55:22 -0000" }, "content": "Extend the Buffer management to support multi-planar formats.\n\nAn image within the system may use one or more Plane objects to track each\nplane in the case of multi-planar image formats. The Buffer class manages all\nof the data required to render or interpret the raw image data.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/buffer.h | 37 +++++++-\n src/libcamera/buffer.cpp | 187 +++++++++++++++++++++++++++++++++++--\n 2 files changed, 212 insertions(+), 12 deletions(-)", "diff": "diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\nindex dda5075f2879..afe99d5c4ab0 100644\n--- a/include/libcamera/buffer.h\n+++ b/include/libcamera/buffer.h\n@@ -11,20 +11,49 @@\n \n namespace libcamera {\n \n-class Buffer\n+class Plane\n {\n public:\n-\tBuffer();\n-\t~Buffer();\n+\tPlane();\n+\tPlane(unsigned int length, unsigned int offset);\n+\t~Plane();\n \n \tint dmabuf() const { return fd_; };\n \tint setDmabuf(int fd);\n \n \tint mmap();\n-\tvoid munmap();\n+\tint munmap();\n+\n+\tunsigned int length() const { return length_; };\n+\tvoid *mem() const { return mem_; };\n \n private:\n \tint fd_;\n+\tunsigned int length_;\n+\tunsigned int offset_;\n+\tvoid *mem_;\n+};\n+\n+class Buffer\n+{\n+public:\n+\tBuffer();\n+\tvirtual ~Buffer();\n+\n+\tint mmap();\n+\tint munmap();\n+\n+\tunsigned int index() const { return index_; };\n+\tconst std::vector<Plane *> &planes() { return planes_; };\n+\n+private:\n+\tunsigned int index_;\n+\n+\tunsigned int format_;\n+\tunsigned int width_;\n+\tunsigned int height_;\n+\n+\tstd::vector<Plane *> planes_;\n };\n \n class BufferPool\ndiff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\nindex 08deaa97e4af..887863b2af2e 100644\n--- a/src/libcamera/buffer.cpp\n+++ b/src/libcamera/buffer.cpp\n@@ -6,10 +6,14 @@\n */\n \n #include <errno.h>\n+#include <string.h>\n+#include <sys/mman.h>\n #include <unistd.h>\n \n #include <libcamera/buffer.h>\n \n+#include \"log.h\"\n+\n /**\n * \\file buffer.h\n * \\brief Buffer handling\n@@ -17,25 +21,52 @@\n \n namespace libcamera {\n \n+LOG_DEFINE_CATEGORY(Buffer)\n+\n /**\n- * \\class Buffer\n- * \\brief A memory buffer to store a frame\n+ * \\class Plane\n+ * \\brief A memory region to store a single plane of a frame\n+ *\n+ * Image pixel formats may require more than one memory region to store separate\n+ * planar data. These memory regions may be different sizes depending upon the\n+ * pixel formats, and may be backed against different dmabuf handles when\n+ * working with the V4L2 MPLANE api.\n *\n- * The Buffer class represents a memory buffer used to store a frame.\n+ * The Plane class tracks the specific details of a memory region used to store\n+ * a single plane for a given image and provides the means to map and access the\n+ * data from an application.\n+ *\n+ * A Buffer may contain multiple Plane instances for multi-planar image formats.\n */\n-Buffer::Buffer()\n-\t: fd_(-1)\n+\n+Plane::Plane()\n+\t: fd_(-1), length_(0), offset_(0), mem_(0)\n {\n }\n \n-Buffer::~Buffer()\n+/**\n+ * \\brief Construct a Plane memory region for CPU mappings\n+ * \\param[in] length The size of the memory region which should be mapped\n+ * \\param[in] offset The offset into the file descriptor base at which the\n+ * buffer commences\n+ *\n+ * \\sa mmap()\n+ */\n+Plane::Plane(unsigned int length, unsigned int offset)\n+\t: fd_(-1), length_(length), offset_(offset), mem_(0)\n {\n+}\n+\n+Plane::~Plane()\n+{\n+\tmunmap();\n+\n \tif (fd_ != -1)\n \t\tclose(fd_);\n }\n \n /**\n- * \\fn Buffer::dmabuf()\n+ * \\fn Plane::dmabuf()\n * \\brief Get the dmabuf file handle backing the buffer\n */\n \n@@ -46,7 +77,7 @@ Buffer::~Buffer()\n *\n * \\return 0 on success or a negative error value otherwise.\n */\n-int Buffer::setDmabuf(int fd)\n+int Plane::setDmabuf(int fd)\n {\n \tif (fd_ != -1) {\n \t\tclose(fd_);\n@@ -70,6 +101,146 @@ int Buffer::setDmabuf(int fd)\n \treturn 0;\n }\n \n+\n+/**\n+ * \\brief Map the plane memory data to a CPU accessible address\n+ *\n+ * The file descriptor to map the memory from must be set by a call to\n+ * setDmaBuf before calling this function.\n+ *\n+ * \\sa setDmaBuf\n+ *\n+ * \\return 0 on success or a negative error value otherwise.\n+ */\n+int Plane::mmap()\n+{\n+\tvoid *map;\n+\n+\tif (mem_)\n+\t\treturn 0;\n+\n+\tmap = ::mmap(NULL, length_, PROT_READ | PROT_WRITE, MAP_SHARED, fd_,\n+\t\t offset_);\n+\tif (map == reinterpret_cast<void *>(-1)) {\n+\t\tint ret = -errno;\n+\t\tLOG(Buffer, Error)\n+\t\t\t<< \"Failed to mmap buffer: \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tmem_ = map;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Unmap any existing CPU accessible mapping\n+ *\n+ * Unmap the memory mapped by an earlier call to mmap.\n+ *\n+ * \\return 0 on success or a negative error value otherwise.\n+ */\n+int Plane::munmap()\n+{\n+\tint ret = 0;\n+\n+\tif (mem_)\n+\t\tret = ::munmap(mem_, length_);\n+\n+\tif (ret) {\n+\t\tret = -errno;\n+\t\tLOG(Buffer, Warning)\n+\t\t\t<< \"Failed to unmap buffer: \" << strerror(ret);\n+\t} else {\n+\t\tmem_ = 0;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * \\fn Plane::length()\n+ * \\brief Get the length of the memory buffer\n+ */\n+\n+/**\n+ * \\fn Plane::mem()\n+ * \\brief Get the CPU accessible memory address if mapped\n+ */\n+\n+/**\n+ * \\class Buffer\n+ * \\brief A memory buffer to store an image\n+ *\n+ * The Buffer class represents the memory buffers used to store a\n+ * full frame image, which may contain multiple separate memory Plane\n+ * objects if the image format is multi-planar.\n+ */\n+\n+Buffer::Buffer()\n+\t: index_(-1), format_(0), width_(0), height_(0)\n+{\n+}\n+\n+Buffer::~Buffer()\n+{\n+\tfor (Plane *plane : planes_)\n+\t\tdelete plane;\n+\n+\tplanes_.clear();\n+}\n+\n+/**\n+ * \\brief Map each buffer plane to a CPU accessible address\n+ *\n+ * Each buffer plane must have had it's dmabuf handle set before attempting to\n+ * mmap.\n+ *\n+ * \\return 0 on success or a negative error value otherwise.\n+ */\n+int Buffer::mmap()\n+{\n+\tint ret;\n+\n+\tfor (Plane *plane : planes_) {\n+\t\tret = plane->mmap();\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Unmap any existing CPU accessible mapping for each plane\n+ *\n+ * Unmap the memory mapped by an earlier call to mmap.\n+ *\n+ * \\return 0 on success or a negative error value otherwise.\n+ */\n+int Buffer::munmap()\n+{\n+\tint ret;\n+\n+\tfor (Plane *plane : planes_) {\n+\t\tret = plane->munmap();\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\fn Buffer::index()\n+ * \\brief Get the Buffer index value\n+ */\n+\n+/**\n+ * \\fn Buffer::planes()\n+ * \\brief Return a reference to the vector holding all Planes within the buffer\n+ */\n+\n /**\n * \\class BufferPool\n * \\brief A pool of buffers\n", "prefixes": [ "libcamera-devel", "v2", "5/5" ] }