Patch Detail
Show a patch.
GET /api/patches/2612/?format=api
{ "id": 2612, "url": "https://patchwork.libcamera.org/api/patches/2612/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2612/", "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": "<20200112010212.2609025-31-niklas.soderlund@ragnatech.se>", "date": "2020-01-12T01:02:10", "name": "[libcamera-devel,v4,30/32] qcam: Cache buffer memory mapping", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "984179994729d22cf9d1f1ee0954e205792c8ea1", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/2612/mbox/", "series": [ { "id": 617, "url": "https://patchwork.libcamera.org/api/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/2612/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2612/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 179AE606FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 12 Jan 2020 02:03:30 +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 56806cbd-34d7-11ea-b6d8-005056917f90;\n\tSun, 12 Jan 2020 02:03:26 +0100 (CET)" ], "X-Halon-ID": "56806cbd-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:10 +0100", "Message-Id": "<20200112010212.2609025-31-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 30/32] qcam: 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:30 -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/qcam/main_window.cpp | 28 ++++++++++++++++++++++------\n src/qcam/main_window.h | 1 +\n 2 files changed, 23 insertions(+), 6 deletions(-)", "diff": "diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 701a2b9a73d53d96..047bf15ea7c188f7 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -201,6 +201,13 @@ int MainWindow::startCapture()\n \t\t}\n \n \t\trequests.push_back(request);\n+\n+\t\t/* Map memory buffers and cache the mappings. */\n+\t\tconst FrameBuffer::Plane &plane = buffer->planes().front();\n+\t\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n+\t\t\t\t plane.fd.fd(), 0);\n+\t\tmappedBuffers_[plane.fd.fd()] =\n+\t\t\tstd::make_pair(memory, plane.length);\n \t}\n \n \ttitleTimer_.start(2000);\n@@ -230,6 +237,13 @@ error:\n \tfor (Request *request : requests)\n \t\tdelete request;\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 \tcamera_->freeBuffers();\n \treturn ret;\n }\n@@ -243,6 +257,13 @@ void MainWindow::stopCapture()\n \tif (ret)\n \t\tstd::cout << \"Failed to stop capture\" << std::endl;\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 \tcamera_->freeBuffers();\n \tisCapturing_ = false;\n \n@@ -297,15 +318,10 @@ int MainWindow::display(FrameBuffer *buffer)\n \tif (buffer->planes().size() != 1)\n \t\treturn -EINVAL;\n \n-\t/* \\todo Once the FrameBuffer is done cache mapped memory. */\n \tconst FrameBuffer::Plane &plane = buffer->planes().front();\n-\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n-\t\t\t plane.fd.fd(), 0);\n-\n+\tvoid *memory = mappedBuffers_[plane.fd.fd()].first;\n \tunsigned char *raw = static_cast<unsigned char *>(memory);\n \tviewfinder_->display(raw, buffer->metadata().planes[0].bytesused);\n \n-\tmunmap(memory, plane.length);\n-\n \treturn 0;\n }\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 05cde4ceab5f7ea1..04fb9e3ea869c3fb 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -71,6 +71,7 @@ private:\n \tuint32_t framesCaptured_;\n \n \tViewFinder *viewfinder_;\n+\tstd::map<int, std::pair<void *, unsigned int>> mappedBuffers_;\n };\n \n #endif /* __QCAM_MAIN_WINDOW__ */\n", "prefixes": [ "libcamera-devel", "v4", "30/32" ] }