Patch Detail
Show a patch.
GET /api/1.1/patches/2454/?format=api
{ "id": 2454, "url": "https://patchwork.libcamera.org/api/1.1/patches/2454/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2454/", "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-5-niklas.soderlund@ragnatech.se>", "date": "2019-12-30T12:04:49", "name": "[libcamera-devel,v2,04/25] libcamera: buffer: Switch from Plane to FrameBuffer::Plane", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "8feaa50b16d231a67327a88cc70143d323349efe", "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/2454/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/2454/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2454/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CB17E6046B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Dec 2019 13:05:52 +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 b9353e40-2afc-11ea-a00b-005056917a89;\n\tMon, 30 Dec 2019 13:05:51 +0100 (CET)" ], "X-Halon-ID": "b9353e40-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:04:49 +0100", "Message-Id": "<20191230120510.938333-5-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 04/25] libcamera: buffer: Switch from\n\tPlane to FrameBuffer::Plane", "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:05:53 -0000" }, "content": "It is not libcameras responsibility to handle memory mappings. Switch\nfrom the soon to be removed Plane class which deals with memory\nmappings to FrameBuffer::Plane which just describes it. This makes the\ntransition to the full FrameBuffer easier.\n\nAs the full FrameBuffer interface have not yet spread to all parts of\nlibcamera core it is hard to create efficient caching of memory mappings\nin the qcam application. This will be fixed in a later patch, for now\nthe dmabuf is mapped and unmapped each time it is seen by the\napplication.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/buffer.h | 6 +++---\n src/cam/buffer_writer.cpp | 10 +++++++---\n src/libcamera/buffer.cpp | 4 ++--\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 8 ++++----\n src/libcamera/stream.cpp | 6 ++++--\n src/libcamera/v4l2_videodevice.cpp | 13 +++++++------\n src/qcam/main_window.cpp | 14 ++++++++++----\n test/camera/buffer_import.cpp | 2 +-\n 8 files changed, 38 insertions(+), 25 deletions(-)", "diff": "diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h\nindex 862031123b4b510c..71633492e4752efb 100644\n--- a/include/libcamera/buffer.h\n+++ b/include/libcamera/buffer.h\n@@ -89,11 +89,11 @@ private:\n class BufferMemory final\n {\n public:\n-\tconst std::vector<Plane> &planes() const { return planes_; }\n-\tstd::vector<Plane> &planes() { return planes_; }\n+\tconst std::vector<FrameBuffer::Plane> &planes() const { return planes_; }\n+\tstd::vector<FrameBuffer::Plane> &planes() { return planes_; }\n \n private:\n-\tstd::vector<Plane> planes_;\n+\tstd::vector<FrameBuffer::Plane> planes_;\n };\n \n class BufferPool final\ndiff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp\nindex c33e99c5f8173db8..3e84068e66bb4dd7 100644\n--- a/src/cam/buffer_writer.cpp\n+++ b/src/cam/buffer_writer.cpp\n@@ -10,6 +10,7 @@\n #include <iostream>\n #include <sstream>\n #include <string.h>\n+#include <sys/mman.h>\n #include <unistd.h>\n \n #include \"buffer_writer.h\"\n@@ -43,9 +44,10 @@ int BufferWriter::write(Buffer *buffer, const std::string &streamName)\n \t\treturn -errno;\n \n \tBufferMemory *mem = buffer->mem();\n-\tfor (Plane &plane : mem->planes()) {\n-\t\tvoid *data = plane.mem();\n-\t\tunsigned int length = plane.length();\n+\tfor (const FrameBuffer::Plane &plane : mem->planes()) {\n+\t\tvoid *data = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n+\t\t\t\t plane.fd.fd(), 0);\n+\t\tunsigned int length = plane.length;\n \n \t\tret = ::write(fd, data, length);\n \t\tif (ret < 0) {\n@@ -59,6 +61,8 @@ int BufferWriter::write(Buffer *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/libcamera/buffer.cpp b/src/libcamera/buffer.cpp\nindex 7c78b9b8f1e90aa5..fde0b33511c64c9e 100644\n--- a/src/libcamera/buffer.cpp\n+++ b/src/libcamera/buffer.cpp\n@@ -246,13 +246,13 @@ void *Plane::mem()\n /**\n * \\fn BufferMemory::planes() const\n * \\brief Retrieve the planes within the buffer\n- * \\return A const reference to a vector holding all Planes within the buffer\n+ * \\return A const reference to a vector holding all planes within the buffer\n */\n \n /**\n * \\fn BufferMemory::planes()\n * \\brief Retrieve the planes within the buffer\n- * \\return A reference to a vector holding all Planes within the buffer\n+ * \\return A reference to a vector holding all planes within the buffer\n */\n \n /**\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex d7ee95ded0f76027..bb652d0da9c6df52 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -688,8 +688,8 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera,\n \n \tfor (unsigned int i = 0; i < stream->configuration().bufferCount + 1; i++) {\n \t\tFrameBuffer::Plane plane;\n-\t\tplane.fd = FileDescriptor(paramPool_.buffers()[i].planes()[0].dmabuf());\n-\t\tplane.length = paramPool_.buffers()[i].planes()[0].length();\n+\t\tplane.fd = FileDescriptor(paramPool_.buffers()[i].planes()[0].fd.fd());\n+\t\tplane.length = paramPool_.buffers()[i].planes()[0].length;\n \n \t\tdata->ipaBuffers_.push_back({ .id = RKISP1_PARAM_BASE | i,\n \t\t\t\t\t .planes = { plane } });\n@@ -698,8 +698,8 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera,\n \n \tfor (unsigned int i = 0; i < stream->configuration().bufferCount + 1; i++) {\n \t\tFrameBuffer::Plane plane;\n-\t\tplane.fd = FileDescriptor(statPool_.buffers()[i].planes()[0].dmabuf());\n-\t\tplane.length = statPool_.buffers()[i].planes()[0].length();\n+\t\tplane.fd = FileDescriptor(statPool_.buffers()[i].planes()[0].fd.fd());\n+\t\tplane.length = statPool_.buffers()[i].planes()[0].length;\n \n \t\tdata->ipaBuffers_.push_back({ .id = RKISP1_STAT_BASE | i,\n \t\t\t\t\t .planes = { plane } });\ndiff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\nindex 45f31ae1e2daeb53..a6adc0de5da40063 100644\n--- a/src/libcamera/stream.cpp\n+++ b/src/libcamera/stream.cpp\n@@ -577,8 +577,10 @@ int Stream::mapBuffer(const Buffer *buffer)\n \t\tif (dmabufs[i] == -1)\n \t\t\tbreak;\n \n-\t\tmem->planes().emplace_back();\n-\t\tmem->planes().back().setDmabuf(dmabufs[i], 0);\n+\t\tFrameBuffer::Plane plane;\n+\t\tplane.fd = FileDescriptor(dmabufs[i]);\n+\t\tplane.length = 0;\n+\t\tmem->planes().emplace_back(plane);\n \t}\n \n \t/* Remove the buffer from the cache and return its index. */\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 13e023237dab0daf..f3f5303b7f470f63 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -921,9 +921,10 @@ int V4L2VideoDevice::createPlane(BufferMemory *buffer, unsigned int index,\n \t\treturn ret;\n \t}\n \n-\tbuffer->planes().emplace_back();\n-\tPlane &plane = buffer->planes().back();\n-\tplane.setDmabuf(expbuf.fd, length);\n+\tFrameBuffer::Plane plane;\n+\tplane.fd = FileDescriptor(expbuf.fd);\n+\tplane.length = length;\n+\tbuffer->planes().emplace_back(plane);\n \t::close(expbuf.fd);\n \n \treturn 0;\n@@ -986,14 +987,14 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer)\n \n \tbool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type);\n \tBufferMemory *mem = &bufferPool_->buffers()[buf.index];\n-\tconst std::vector<Plane> &planes = mem->planes();\n+\tconst std::vector<FrameBuffer::Plane> &planes = mem->planes();\n \n \tif (buf.memory == V4L2_MEMORY_DMABUF) {\n \t\tif (multiPlanar) {\n \t\t\tfor (unsigned int p = 0; p < planes.size(); ++p)\n-\t\t\t\tv4l2Planes[p].m.fd = planes[p].dmabuf();\n+\t\t\t\tv4l2Planes[p].m.fd = planes[p].fd.fd();\n \t\t} else {\n-\t\t\tbuf.m.fd = planes[0].dmabuf();\n+\t\t\tbuf.m.fd = planes[0].fd.fd();\n \t\t}\n \t}\n \ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 0c7ca61ac12ec41c..11fb67a509e973f5 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -8,6 +8,7 @@\n #include <iomanip>\n #include <iostream>\n #include <string>\n+#include <sys/mman.h>\n \n #include <QCoreApplication>\n #include <QInputDialog>\n@@ -296,13 +297,18 @@ void MainWindow::requestComplete(Request *request)\n \n int MainWindow::display(Buffer *buffer)\n {\n-\tBufferMemory *mem = buffer->mem();\n-\tif (mem->planes().size() != 1)\n+\tif (buffer->mem()->planes().size() != 1)\n \t\treturn -EINVAL;\n \n-\tPlane &plane = mem->planes().front();\n-\tunsigned char *raw = static_cast<unsigned char *>(plane.mem());\n+\t/* \\todo: Once the FrameBuffer is done cache mapped memory. */\n+\tconst FrameBuffer::Plane &plane = buffer->mem()->planes().front();\n+\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n+\t\t\t plane.fd.fd(), 0);\n+\n+\tunsigned char *raw = static_cast<unsigned char *>(memory);\n \tviewfinder_->display(raw, buffer->bytesused());\n \n+\tmunmap(memory, plane.length);\n+\n \treturn 0;\n }\ndiff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp\nindex 3efe02704c02f691..171540edd96f9fca 100644\n--- a/test/camera/buffer_import.cpp\n+++ b/test/camera/buffer_import.cpp\n@@ -178,7 +178,7 @@ private:\n \n \t\tuint64_t cookie = index;\n \t\tBufferMemory &mem = pool_.buffers()[index];\n-\t\tint dmabuf = mem.planes()[0].dmabuf();\n+\t\tint dmabuf = mem.planes()[0].fd.fd();\n \n \t\trequestReady.emit(cookie, dmabuf);\n \n", "prefixes": [ "libcamera-devel", "v2", "04/25" ] }