Show a patch.

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

{
    "id": 2611,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2611/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2611/",
    "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": "<20200112010212.2609025-30-niklas.soderlund@ragnatech.se>",
    "date": "2020-01-12T01:02:09",
    "name": "[libcamera-devel,v4,29/32] cam: Cache buffer memory mapping",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "54d6021a5297035d346cf75f2ddb014e71d76d75",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2611/mbox/",
    "series": [
        {
            "id": 617,
            "url": "https://patchwork.libcamera.org/api/1.1/series/617/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=617",
            "date": "2020-01-12T01:01:40",
            "name": "libcamera: Rework buffer API",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/617/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2611/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2611/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<niklas.soderlund@ragnatech.se>",
        "Received": [
            "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 733FF606FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 12 Jan 2020 02:03:29 +0100 (CET)",
            "from bismarck.berto.se (p54ac5d7b.dip0.t-ipconnect.de\n\t[84.172.93.123]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 557afff6-34d7-11ea-b6d8-005056917f90;\n\tSun, 12 Jan 2020 02:03:25 +0100 (CET)"
        ],
        "X-Halon-ID": "557afff6-34d7-11ea-b6d8-005056917f90",
        "Authorized-sender": "niklas@soderlund.pp.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sun, 12 Jan 2020 02:02:09 +0100",
        "Message-Id": "<20200112010212.2609025-30-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200112010212.2609025-1-niklas.soderlund@ragnatech.se>",
        "References": "<20200112010212.2609025-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 29/32] cam: Cache buffer memory mapping",
        "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>",
        "X-List-Received-Date": "Sun, 12 Jan 2020 01:03:29 -0000"
    },
    "content": "With the buffer allocator in use it's possible to cache the dmabuf\nmemory mappings when starting the camera instead of mapping and\nunmapping them each time.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/cam/buffer_writer.cpp | 27 ++++++++++++++++++++++-----\n src/cam/buffer_writer.h   |  5 +++++\n src/cam/capture.cpp       |  3 +++\n 3 files changed, 30 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp\nindex 1d7366c87714cd91..c5a5eb46224ac3eb 100644\n--- a/src/cam/buffer_writer.cpp\n+++ b/src/cam/buffer_writer.cpp\n@@ -22,6 +22,27 @@ BufferWriter::BufferWriter(const std::string &pattern)\n {\n }\n \n+BufferWriter::~BufferWriter()\n+{\n+\tfor (auto &iter : mappedBuffers_) {\n+\t\tvoid *memory = iter.second.first;\n+\t\tunsigned int length = iter.second.second;\n+\t\tmunmap(memory, length);\n+\t}\n+\tmappedBuffers_.clear();\n+}\n+\n+void BufferWriter::mapBuffer(FrameBuffer *buffer)\n+{\n+\tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n+\t\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n+\t\t\t\t    plane.fd.fd(), 0);\n+\n+\t\tmappedBuffers_[plane.fd.fd()] =\n+\t\t\tstd::make_pair(memory, plane.length);\n+\t}\n+}\n+\n int BufferWriter::write(FrameBuffer *buffer, const std::string &streamName)\n {\n \tstd::string filename;\n@@ -44,9 +65,7 @@ int BufferWriter::write(FrameBuffer *buffer, const std::string &streamName)\n \t\treturn -errno;\n \n \tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n-\t\t/* \\todo Once the FrameBuffer is done cache mapped memory. */\n-\t\tvoid *data = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n-\t\t\t\t  plane.fd.fd(), 0);\n+\t\tvoid *data = mappedBuffers_[plane.fd.fd()].first;\n \t\tunsigned int length = plane.length;\n \n \t\tret = ::write(fd, data, length);\n@@ -61,8 +80,6 @@ int BufferWriter::write(FrameBuffer *buffer, const std::string &streamName)\n \t\t\t\t  << length << std::endl;\n \t\t\tbreak;\n \t\t}\n-\n-\t\tmunmap(data, length);\n \t}\n \n \tclose(fd);\ndiff --git a/src/cam/buffer_writer.h b/src/cam/buffer_writer.h\nindex 5917a7dfb5e28106..8c9b2436fdae4fc3 100644\n--- a/src/cam/buffer_writer.h\n+++ b/src/cam/buffer_writer.h\n@@ -7,6 +7,7 @@\n #ifndef __LIBCAMERA_BUFFER_WRITER_H__\n #define __LIBCAMERA_BUFFER_WRITER_H__\n \n+#include <map>\n #include <string>\n \n #include <libcamera/buffer.h>\n@@ -15,12 +16,16 @@ class BufferWriter\n {\n public:\n \tBufferWriter(const std::string &pattern = \"frame-#.bin\");\n+\t~BufferWriter();\n+\n+\tvoid mapBuffer(libcamera::FrameBuffer *buffer);\n \n \tint write(libcamera::FrameBuffer *buffer,\n \t\t  const std::string &streamName);\n \n private:\n \tstd::string pattern_;\n+\tstd::map<int, std::pair<void *, unsigned int>> mappedBuffers_;\n };\n \n #endif /* __LIBCAMERA_BUFFER_WRITER_H__ */\ndiff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\nindex dd078eb0ae4a2c62..738fa1c267eb6e36 100644\n--- a/src/cam/capture.cpp\n+++ b/src/cam/capture.cpp\n@@ -116,6 +116,9 @@ int Capture::capture(EventLoop *loop, FrameBufferAllocator *allocator)\n \t\t\t\t\t  << std::endl;\n \t\t\t\treturn ret;\n \t\t\t}\n+\n+\t\t\tif (writer_)\n+\t\t\t\twriter_->mapBuffer(buffer.get());\n \t\t}\n \n \t\trequests.push_back(request);\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "29/32"
    ]
}