Patch Detail
Show a patch.
GET /api/patches/9664/?format=api
{ "id": 9664, "url": "https://patchwork.libcamera.org/api/patches/9664/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9664/", "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": "<20200918135041.91492-7-jacopo@jmondi.org>", "date": "2020-09-18T13:50:39", "name": "[libcamera-devel,v2,6/8] android: camera_device: Add methods to get and return buffers", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "573dab89ff4265c6993dcaec046301d7558826ed", "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/9664/mbox/", "series": [ { "id": 1296, "url": "https://patchwork.libcamera.org/api/series/1296/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1296", "date": "2020-09-18T13:50:33", "name": "android: camera_device: Add support for internal buffers", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1296/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9664/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9664/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 031F7C3B5D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Sep 2020 13:47:25 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CE21262FD3;\n\tFri, 18 Sep 2020 15:47:24 +0200 (CEST)", "from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 750A462F4F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Sep 2020 15:47: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 relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 73B6B40009;\n\tFri, 18 Sep 2020 13:47:22 +0000 (UTC)" ], "X-Originating-IP": "93.34.118.233", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 18 Sep 2020 15:50:39 +0200", "Message-Id": "<20200918135041.91492-7-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.28.0", "In-Reply-To": "<20200918135041.91492-1-jacopo@jmondi.org>", "References": "<20200918135041.91492-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v2 6/8] android: camera_device: Add\n\tmethods to get and 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 two methods to the CameraDevice class to retrieve and return\nframe buffers associated to a stream from the memory pool reserved\nin libcamera.\n\nProtect accessing the vector of FrameBufer pointers with a\nper-pool mutex in the get and return buffer methods.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp | 34 +++++++++++++++++++++++++++++++++-\n src/android/camera_device.h | 11 +++++++++--\n 2 files changed, 42 insertions(+), 3 deletions(-)", "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex f96ea7321a67..6ed56ff57dab 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -8,6 +8,7 @@\n #include \"camera_device.h\"\n #include \"camera_ops.h\"\n \n+#include <mutex>\n #include <sys/mman.h>\n #include <tuple>\n #include <vector>\n@@ -1400,11 +1401,42 @@ int CameraDevice::allocateBuffersPool(Stream *stream)\n \t * the HAL.\n \t */\n \tfor (const auto &frameBuffer : allocator_.buffers(stream))\n-\t\tbufferPool_[stream].push_back(frameBuffer.get());\n+\t\tbufferPool_[stream].buffers.push_back(frameBuffer.get());\n \n \treturn 0;\n }\n \n+libcamera::FrameBuffer *CameraDevice::getBuffer(libcamera::Stream *stream)\n+{\n+\tif (bufferPool_.find(stream) == bufferPool_.end())\n+\t\treturn nullptr;\n+\n+\tBufferPool *pool = &bufferPool_[stream];\n+\tstd::lock_guard<std::mutex> locker(pool->mutex);\n+\n+\tif (pool->buffers.empty()) {\n+\t\tLOG(HAL, Error) << \"Buffer underrun\";\n+\t\treturn nullptr;\n+\t}\n+\n+\tFrameBuffer *buffer = pool->buffers.front();\n+\tpool->buffers.erase(pool->buffers.begin());\n+\n+\treturn buffer;\n+}\n+\n+void CameraDevice::returnBuffer(libcamera::Stream *stream,\n+\t\t\t\tlibcamera::FrameBuffer *buffer)\n+{\n+\tif (bufferPool_.find(stream) == bufferPool_.end())\n+\t\treturn;\n+\n+\tBufferPool *pool = &bufferPool_[stream];\n+\tstd::lock_guard<std::mutex> locker(pool->mutex);\n+\n+\tpool->buffers.push_back(buffer);\n+}\n+\n int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request)\n {\n \tif (!camera3Request->num_output_buffers) {\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 4cef34c01a49..5addffdc070a 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -9,6 +9,7 @@\n \n #include <map>\n #include <memory>\n+#include <mutex>\n #include <tuple>\n #include <vector>\n \n@@ -166,8 +167,11 @@ protected:\n \tstd::string logPrefix() const override;\n \n private:\n-\tusing FrameBufferPool = std::map<libcamera::Stream *,\n-\t\t\t\t\t std::vector<libcamera::FrameBuffer *>>;\n+\tstruct BufferPool {\n+\t\tstd::mutex mutex;\n+\t\tstd::vector<libcamera::FrameBuffer *> buffers;\n+\t};\n+\tusing FrameBufferPool = std::map<libcamera::Stream *, BufferPool>;\n \n \tCameraDevice(unsigned int id, const std::shared_ptr<libcamera::Camera> &camera);\n \n@@ -198,6 +202,9 @@ private:\n \tstd::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();\n \tlibcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);\n \tint allocateBuffersPool(libcamera::Stream *stream);\n+\tlibcamera::FrameBuffer *getBuffer(libcamera::Stream *stream);\n+\tvoid returnBuffer(libcamera::Stream *stream,\n+\t\t\t libcamera::FrameBuffer *buffer);\n \n \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);\n \tvoid notifyError(uint32_t frameNumber, camera3_stream_t *stream);\n", "prefixes": [ "libcamera-devel", "v2", "6/8" ] }