Show a patch.

GET /api/1.1/patches/9690/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 9690,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/9690/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/9690/",
    "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": "<20200922094738.5327-7-jacopo@jmondi.org>",
    "date": "2020-09-22T09:47:36",
    "name": "[libcamera-devel,v3,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/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/9690/mbox/",
    "series": [
        {
            "id": 1306,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1306/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1306",
            "date": "2020-09-22T09:47:30",
            "name": "android: camera_device: Add support for internal buffers",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/1306/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/9690/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/9690/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 6C45ABF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 22 Sep 2020 09:44:35 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4955C62FD4;\n\tTue, 22 Sep 2020 11:44:35 +0200 (CEST)",
            "from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BE60D60364\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 22 Sep 2020 11:44:33 +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 relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 5BF86E0003;\n\tTue, 22 Sep 2020 09:44:26 +0000 (UTC)"
        ],
        "X-Originating-IP": "93.34.118.233",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 22 Sep 2020 11:47:36 +0200",
        "Message-Id": "<20200922094738.5327-7-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.28.0",
        "In-Reply-To": "<20200922094738.5327-1-jacopo@jmondi.org>",
        "References": "<20200922094738.5327-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v3 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=\"utf-8\"",
        "Content-Transfer-Encoding": "base64",
        "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\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\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",
        "v3",
        "6/8"
    ]
}