Patch Detail
Show a patch.
GET /api/1.1/patches/2473/?format=api
{ "id": 2473, "url": "https://patchwork.libcamera.org/api/1.1/patches/2473/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2473/", "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": "<20191230120510.938333-24-niklas.soderlund@ragnatech.se>", "date": "2019-12-30T12:05:08", "name": "[libcamera-devel,v2,23/25] qcam: Cache buffer memory mapping", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "925d8b78467714bacb3140538c4e068669cd5c86", "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/2473/mbox/", "series": [ { "id": 593, "url": "https://patchwork.libcamera.org/api/1.1/series/593/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=593", "date": "2019-12-30T12:04:45", "name": "libcamera: Rework buffer API", "version": 2, "mbox": "https://patchwork.libcamera.org/series/593/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2473/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2473/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 F00896046A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Dec 2019 13:06:12 +0100 (CET)", "from bismarck.berto.se (p4fca2fd0.dip0.t-ipconnect.de\n\t[79.202.47.208]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid c56016c4-2afc-11ea-a00b-005056917a89;\n\tMon, 30 Dec 2019 13:06:12 +0100 (CET)" ], "X-Halon-ID": "c56016c4-2afc-11ea-a00b-005056917a89", "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": "Mon, 30 Dec 2019 13:05:08 +0100", "Message-Id": "<20191230120510.938333-24-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20191230120510.938333-1-niklas.soderlund@ragnatech.se>", "References": "<20191230120510.938333-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 23/25] 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": "Mon, 30 Dec 2019 12:06:13 -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>\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 e53ed2801291f2c5..2008931075b96260 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/* Cache buffer memory mapping. */\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 &itr : mappedBuffers_) {\n+\t\tvoid *memory = itr.second.first;\n+\t\tunsigned int length = itr.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 &itr : mappedBuffers_) {\n+\t\tvoid *memory = itr.second.first;\n+\t\tunsigned int length = itr.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", "v2", "23/25" ] }