Show a patch.

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

{
    "id": 9879,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/9879/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/9879/",
    "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": "<20200930132707.19367-8-jacopo@jmondi.org>",
    "date": "2020-09-30T13:27:05",
    "name": "[libcamera-devel,v4,7/9] android: camera_device: Add methods to get and return buffers",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2804e1d796519ce4fca3a35f62f30d468d08c27f",
    "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/9879/mbox/",
    "series": [
        {
            "id": 1340,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1340/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1340",
            "date": "2020-09-30T13:26:58",
            "name": "android: camera_device: Add support for internal buffers",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/1340/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/9879/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/9879/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 72767C3B5B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 30 Sep 2020 13:23:30 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4CEB2623B0;\n\tWed, 30 Sep 2020 15:23:30 +0200 (CEST)",
            "from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 34879622B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 30 Sep 2020 15:23:27 +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 relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 1D189C0007;\n\tWed, 30 Sep 2020 13:23:25 +0000 (UTC)"
        ],
        "X-Originating-IP": "93.34.118.233",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 30 Sep 2020 15:27:05 +0200",
        "Message-Id": "<20200930132707.19367-8-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.28.0",
        "In-Reply-To": "<20200930132707.19367-1-jacopo@jmondi.org>",
        "References": "<20200930132707.19367-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v4 7/9] 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 FrameBuffer 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 07041dd916d5..2ebc3fcc336e 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@@ -1402,11 +1403,42 @@ int CameraDevice::allocateBufferPool(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 c46610725e12..c91de367d7bd 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 allocateBufferPool(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",
        "v4",
        "7/9"
    ]
}