Patch Detail
Show a patch.
GET /api/patches/482/?format=api
{ "id": 482, "url": "https://patchwork.libcamera.org/api/patches/482/?format=api", "web_url": "https://patchwork.libcamera.org/patch/482/", "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": "<20190203105517.5355-2-kieran.bingham@ideasonboard.com>", "date": "2019-02-03T10:55:13", "name": "[libcamera-devel,v2,1/5] libcamera: Add Buffer and BufferPool classes", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "8aef8848ae11bae4df1907b0197117d0efe03e64", "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/482/mbox/", "series": [ { "id": 164, "url": "https://patchwork.libcamera.org/api/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/482/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/482/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 A66A560DB8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 3 Feb 2019 11:55:21 +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 165145AA;\n\tSun, 3 Feb 2019 11:55:21 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549191321;\n\tbh=bSL8a/jHoYJV+bzkEdKJN3UZTxmPQYH+CXnPiRKgpdw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=m0R621QVlzo7jTpl/NyGu8mgg3Na4v6cwkNSmBND0+6om2De03MzJqVtX2uToPN5D\n\tV8DkZRYb0nD+EUS73Gk6S0q0FV0bPJ08mzpB9At83hpi/i2AsiEW72xyDcDD8nygzx\n\ttwa64NBg4A1Dd1ZWKfkTY/AeOHu5zDy6Xs+t5K1g=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "To": "LibCamera Devel <libcamera-devel@lists.libcamera.org>", "Date": "Sun, 3 Feb 2019 11:55:13 +0100", "Message-Id": "<20190203105517.5355-2-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 1/5] libcamera: Add Buffer and\n\tBufferPool classes", "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": "From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nProvide classes that represent frame buffers and pools of frame buffers.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nKieran\n - Fix checkstyle.py diff\n---\n include/libcamera/buffer.h | 55 ++++++++++++++++++\n include/libcamera/libcamera.h | 1 +\n include/libcamera/meson.build | 1 +\n src/libcamera/buffer.cpp | 102 ++++++++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 5 files changed, 160 insertions(+)\n create mode 100644 include/libcamera/buffer.h\n create mode 100644 src/libcamera/buffer.cpp", "diff": "diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\nnew file mode 100644\nindex 000000000000..97c8025d9e77\n--- /dev/null\n+++ b/include/libcamera/buffer.h\n@@ -0,0 +1,55 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * buffer.h - Buffer handling\n+ */\n+#ifndef __LIBCAMERA_BUFFER_H__\n+#define __LIBCAMERA_BUFFER_H__\n+\n+#include <vector>\n+\n+namespace libcamera {\n+\n+class Buffer\n+{\n+public:\n+\tBuffer();\n+\t~Buffer();\n+\n+\tint dmabuf() const { return fd_; };\n+\tint setDmabuf(int fd);\n+\n+\tint mmap();\n+\tvoid munmap();\n+\n+private:\n+\tint fd_;\n+};\n+\n+class BufferPool\n+{\n+public:\n+\tenum Memory {\n+\t\tInternal,\n+\t\tExternal,\n+\t};\n+\n+\tBufferPool(Memory memory);\n+\tvirtual ~BufferPool();\n+\n+\tint allocate(unsigned int count);\n+\tvoid free();\n+\n+\tunsigned int count() const { return buffers_.size(); };\n+\n+private:\n+\tvirtual int allocateMemory() = 0;\n+\n+\tBufferPool::Memory memory_;\n+\tstd::vector<Buffer *> buffers_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_BUFFER_H__ */\ndiff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h\nindex 272dfd5e4a67..8167e8099ac0 100644\n--- a/include/libcamera/libcamera.h\n+++ b/include/libcamera/libcamera.h\n@@ -7,6 +7,7 @@\n #ifndef __LIBCAMERA_LIBCAMERA_H__\n #define __LIBCAMERA_LIBCAMERA_H__\n \n+#include <libcamera/buffer.h>\n #include <libcamera/camera.h>\n #include <libcamera/camera_manager.h>\n #include <libcamera/event_dispatcher.h>\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 54a680787e5c..8c14423bc444 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -1,4 +1,5 @@\n libcamera_api = files([\n+ 'buffer.h',\n 'camera.h',\n 'camera_manager.h',\n 'event_dispatcher.h',\ndiff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\nnew file mode 100644\nindex 000000000000..6dfebfc6bb28\n--- /dev/null\n+++ b/src/libcamera/buffer.cpp\n@@ -0,0 +1,102 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * buffer.cpp - Buffer handling\n+ */\n+\n+#include <errno.h>\n+#include <unistd.h>\n+\n+#include <libcamera/buffer.h>\n+\n+/**\n+ * \\file buffer.h\n+ * \\brief Buffer handling\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class Buffer\n+ * \\brief A memory buffer to store a frame\n+ *\n+ * The Buffer class represents a memory buffer used to store a frame.\n+ */\n+Buffer::Buffer()\n+\t: fd_(-1)\n+{\n+}\n+\n+Buffer::~Buffer()\n+{\n+\tif (fd_ != -1)\n+\t\tclose(fd_);\n+}\n+\n+/**\n+ * \\fn Buffer::dmabuf()\n+ * \\brief Get the dmabuf file handle backing the buffer\n+ */\n+\n+/**\n+ * \\brief Set the dmabuf file handle backing the buffer\n+ *\n+ * The \\a fd dmabuf file handle is duplicated and stored.\n+ */\n+int Buffer::setDmabuf(int fd)\n+{\n+\tif (fd_ != -1) {\n+\t\tclose(fd_);\n+\t\tfd_ = -1;\n+\t}\n+\n+\tif (fd != -1)\n+\t\treturn 0;\n+\n+\tfd_ = dup(fd);\n+\tif (fd_ == -1)\n+\t\treturn -errno;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\class BufferPool\n+ * \\brief A pool of buffers\n+ */\n+BufferPool::BufferPool(BufferPool::Memory memory)\n+\t: memory_(memory)\n+{\n+}\n+\n+BufferPool::~BufferPool()\n+{\n+\tfree();\n+}\n+\n+int BufferPool::allocate(unsigned int count)\n+{\n+\tfor (unsigned int i = 0; i < count; ++i) {\n+\t\tBuffer *buffer = new Buffer();\n+\t\tbuffers_.push_back(buffer);\n+\t}\n+\n+\tif (memory_ == Memory::Internal) {\n+\t\tint ret = allocateMemory();\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void BufferPool::free()\n+{\n+\tfor (Buffer *buffer : buffers_)\n+\t\tdelete buffer;\n+\n+\tbuffers_.clear();\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 9f6ff99eebe2..a4e9cc8f936c 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -1,4 +1,5 @@\n libcamera_sources = files([\n+ 'buffer.cpp',\n 'camera.cpp',\n 'camera_manager.cpp',\n 'device_enumerator.cpp',\n", "prefixes": [ "libcamera-devel", "v2", "1/5" ] }