Patch Detail
Show a patch.
GET /api/patches/9562/?format=api
{ "id": 9562, "url": "https://patchwork.libcamera.org/api/patches/9562/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9562/", "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": "<20200909155457.153907-6-jacopo@jmondi.org>", "date": "2020-09-09T15:54:54", "name": "[libcamera-devel,5/8] libcamera: framebuffer_allocator: Get and return buffers", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "d67e3fda3275d86e404e98cb4ac9acbca0a3c0fb", "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/9562/mbox/", "series": [ { "id": 1282, "url": "https://patchwork.libcamera.org/api/series/1282/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1282", "date": "2020-09-09T15:54:49", "name": "android: camera_device: Allocate internal buffers", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1282/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9562/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9562/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 78114BDB1E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 9 Sep 2020 15:51:24 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4821F62D68;\n\tWed, 9 Sep 2020 17:51:24 +0200 (CEST)", "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 1055262D04\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 9 Sep 2020 17:51:23 +0200 (CEST)", "from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 2FDFF1BF208;\n\tWed, 9 Sep 2020 15:51:22 +0000 (UTC)" ], "X-Originating-IP": "93.34.118.233", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 9 Sep 2020 17:54:54 +0200", "Message-Id": "<20200909155457.153907-6-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.28.0", "In-Reply-To": "<20200909155457.153907-1-jacopo@jmondi.org>", "References": "<20200909155457.153907-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 5/8] libcamera: framebuffer_allocator: Get\n\tand return 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>", "Cc": "hanlinchen@chromium.org", "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": "Add to the FrameBufferAllocator class two methods to get and\nreturn buffers from the pool of buffers allocated for a Stream.\n\nThe two methods return pointer to the allocated buffers without\ntransferring ownership to the caller.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/framebuffer_allocator.h | 5 ++\n src/libcamera/framebuffer_allocator.cpp | 60 +++++++++++++++++++++--\n 2 files changed, 62 insertions(+), 3 deletions(-)", "diff": "diff --git a/include/libcamera/framebuffer_allocator.h b/include/libcamera/framebuffer_allocator.h\nindex 2a4d538a0cb2..1f3f10d4ec03 100644\n--- a/include/libcamera/framebuffer_allocator.h\n+++ b/include/libcamera/framebuffer_allocator.h\n@@ -9,6 +9,7 @@\n \n #include <map>\n #include <memory>\n+#include <queue>\n #include <vector>\n \n namespace libcamera {\n@@ -33,9 +34,13 @@ public:\n \tbool allocated() const { return !buffers_.empty(); }\n \tconst std::vector<std::unique_ptr<FrameBuffer>> &buffers(Stream *stream) const;\n \n+\tFrameBuffer *getBuffer(Stream *stream);\n+\tvoid returnBuffer(Stream *stream, FrameBuffer *buffer);\n+\n private:\n \tstd::shared_ptr<Camera> camera_;\n \tstd::map<Stream *, std::vector<std::unique_ptr<FrameBuffer>>> buffers_;\n+\tstd::map<Stream *, std::queue<FrameBuffer *>> availableBuffers_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/framebuffer_allocator.cpp b/src/libcamera/framebuffer_allocator.cpp\nindex 7ed80011c845..7429d6b9edb7 100644\n--- a/src/libcamera/framebuffer_allocator.cpp\n+++ b/src/libcamera/framebuffer_allocator.cpp\n@@ -64,7 +64,7 @@ FrameBufferAllocator::FrameBufferAllocator(std::shared_ptr<Camera> camera)\n \n FrameBufferAllocator::~FrameBufferAllocator()\n {\n-\tbuffers_.clear();\n+\tclear();\n }\n \n /**\n@@ -93,11 +93,17 @@ int FrameBufferAllocator::allocate(Stream *stream)\n \t}\n \n \tint ret = camera_->exportFrameBuffers(stream, &buffers_[stream]);\n-\tif (ret == -EINVAL)\n+\tif (ret == -EINVAL) {\n \t\tLOG(Allocator, Error)\n \t\t\t<< \"Stream is not part of \" << camera_->id()\n \t\t\t<< \" active configuration\";\n-\treturn ret;\n+\t\treturn ret;\n+\t}\n+\n+\tfor (const auto &buffer : buffers_[stream])\n+\t\tavailableBuffers_[stream].push(buffer.get());\n+\n+\treturn 0;\n }\n \n /**\n@@ -122,6 +128,9 @@ int FrameBufferAllocator::free(Stream *stream)\n \tbuffers.clear();\n \tbuffers_.erase(iter);\n \n+\tavailableBuffers_[stream] = {};\n+\tavailableBuffers_.erase(availableBuffers_.find(stream));\n+\n \treturn 0;\n }\n \n@@ -131,6 +140,7 @@ int FrameBufferAllocator::free(Stream *stream)\n void FrameBufferAllocator::clear()\n {\n \tbuffers_.clear();\n+\tavailableBuffers_.clear();\n }\n \n /**\n@@ -162,4 +172,48 @@ FrameBufferAllocator::buffers(Stream *stream) const\n \treturn iter->second;\n }\n \n+/**\n+ * \\brief Get a pointer to a \\a buffer for the \\a stream\n+ * \\param[in] stream The stream to get a buffer for\n+ *\n+ * The method returns a pointer to a FrameBuffer but does transfer the buffer\n+ * ownership to the caller: the returned pointer remains valid until the\n+ * FrameBufferAllocator does not get deleted or the allocated buffers do not get\n+ * released with a call for free() or clear().\n+ *\n+ * \\return A FrameBuffer pointer or nullptr if the no buffers is available\n+ */\n+FrameBuffer *FrameBufferAllocator::getBuffer(Stream *stream)\n+{\n+\tif (!allocated() || buffers_[stream].empty())\n+\t\treturn nullptr;\n+\n+\tFrameBuffer *frameBuffer = availableBuffers_[stream].front();\n+\tavailableBuffers_[stream].pop();\n+\n+\treturn frameBuffer;\n+}\n+\n+/**\n+ * \\brief Return a \\a buffer to the list of buffers available for the a \\a stream\n+ * \\param[in] stream The stream to return buffer to\n+ * \\param[in] buffer The buffer to return\n+ */\n+void FrameBufferAllocator::returnBuffer(Stream *stream, FrameBuffer *buffer)\n+{\n+\tif (!allocated())\n+\t\treturn;\n+\n+\tfor (const auto &b : buffers_[stream]) {\n+\t\t/*\n+\t\t * Return the buffer to the available queue only if it was part\n+\t\t * of the vector of buffers allocated for the Stream.\n+\t\t */\n+\t\tif (b.get() != buffer)\n+\t\t\tcontinue;\n+\n+\t\tavailableBuffers_[stream].push(buffer);\n+\t}\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "5/8" ] }