{"id":3256,"url":"https://patchwork.libcamera.org/api/1.1/patches/3256/?format=json","web_url":"https://patchwork.libcamera.org/patch/3256/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200323142205.28342-14-laurent.pinchart@ideasonboard.com>","date":"2020-03-23T14:21:57","name":"[libcamera-devel,13/21] qcam: viewfinder: Add MappedBuffer to store memory mapping information","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6a07386f38cbac8c8b812be4d16de3eec0620209","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3256/mbox/","series":[{"id":760,"url":"https://patchwork.libcamera.org/api/1.1/series/760/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=760","date":"2020-03-23T14:21:44","name":"qcam: Bypass format conversion when not required","version":1,"mbox":"https://patchwork.libcamera.org/series/760/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3256/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3256/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CD05E62C81\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Mar 2020 15:22:22 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7475C11FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Mar 2020 15:22:22 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584973342;\n\tbh=B/vsZYfjryhoy/2Qt+BqsX/HD3nUquKpVeSN8UcJilY=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=kPhScnLH+2GRBInMlTEncdK7i0Ok7uWQZD6ZCmHwQLPqa/DwdCarWmgVwFXaBDEmI\n\tZ7+zpbkkOwUhAr0TKVII47vqfph+Rt8UWSyYuBV7qW/T0D+75gqLioV80yk3cwxeJ/\n\tIlhRbxATAHxtotGxJOmb/iwOBxuo8ydmyIRqhJ14=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 23 Mar 2020 16:21:57 +0200","Message-Id":"<20200323142205.28342-14-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200323142205.28342-1-laurent.pinchart@ideasonboard.com>","References":"<20200323142205.28342-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 13/21] qcam: viewfinder: Add MappedBuffer\n\tto store memory mapping information","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, 23 Mar 2020 14:22:28 -0000"},"content":"The new MappedBuffer structure replaces the std::pair<> used in the\nmapped buffers map, and allows passing data to the ViewFinder::display()\nfunction in a more structured way.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/qcam/main_window.cpp | 20 ++++++--------------\n src/qcam/main_window.h   |  4 ++--\n src/qcam/viewfinder.cpp  |  6 ++++--\n src/qcam/viewfinder.h    | 10 +++++++++-\n 4 files changed, 21 insertions(+), 19 deletions(-)","diff":"diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 184345b0e2a6..c0feb91a6fb1 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -28,8 +28,6 @@\n #include <libcamera/camera_manager.h>\n #include <libcamera/version.h>\n \n-#include \"viewfinder.h\"\n-\n using namespace libcamera;\n \n /**\n@@ -350,8 +348,7 @@ int MainWindow::startCapture()\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\tmappedBuffers_[buffer.get()] = { memory, plane.length };\n \t}\n \n \t/* Start the title timer and the camera. */\n@@ -391,9 +388,8 @@ error:\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\tconst MappedBuffer &buffer = iter.second;\n+\t\tmunmap(buffer.memory, buffer.size);\n \t}\n \tmappedBuffers_.clear();\n \n@@ -421,9 +417,8 @@ void MainWindow::stopCapture()\n \tcamera_->requestCompleted.disconnect(this, &MainWindow::requestComplete);\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\tconst MappedBuffer &buffer = iter.second;\n+\t\tmunmap(buffer.memory, buffer.size);\n \t}\n \tmappedBuffers_.clear();\n \n@@ -529,10 +524,7 @@ int MainWindow::display(FrameBuffer *buffer)\n \tif (buffer->planes().size() != 1)\n \t\treturn -EINVAL;\n \n-\tconst FrameBuffer::Plane &plane = buffer->planes().front();\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+\tviewfinder_->display(buffer, &mappedBuffers_[buffer]);\n \n \treturn 0;\n }\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex fcde88c14f77..0918ae5307d8 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -23,11 +23,11 @@\n #include <libcamera/stream.h>\n \n #include \"../cam/options.h\"\n+#include \"viewfinder.h\"\n \n using namespace libcamera;\n \n class QAction;\n-class ViewFinder;\n \n enum {\n \tOptCamera = 'c',\n@@ -85,7 +85,7 @@ private:\n \tFrameBufferAllocator *allocator_;\n \n \tstd::unique_ptr<CameraConfiguration> config_;\n-\tstd::map<int, std::pair<void *, unsigned int>> mappedBuffers_;\n+\tstd::map<FrameBuffer *, MappedBuffer> mappedBuffers_;\n \n \t/* Capture state, buffers queue and statistics */\n \tbool isCapturing_;\ndiff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp\nindex 066ac605e7b4..d00edc33dfb7 100644\n--- a/src/qcam/viewfinder.cpp\n+++ b/src/qcam/viewfinder.cpp\n@@ -24,7 +24,8 @@ ViewFinder::~ViewFinder()\n \tdelete image_;\n }\n \n-void ViewFinder::display(const unsigned char *raw, size_t size)\n+void ViewFinder::display(const libcamera::FrameBuffer *buffer,\n+\t\t\t MappedBuffer *map)\n {\n \tQMutexLocker locker(&mutex_);\n \n@@ -34,7 +35,8 @@ void ViewFinder::display(const unsigned char *raw, size_t size)\n \t * impacting performances.\n \t */\n \n-\tconverter_.convert(raw, size, image_);\n+\tconverter_.convert(static_cast<unsigned char *>(map->memory),\n+\t\t\t   buffer->metadata().planes[0].bytesused, image_);\n \tupdate();\n }\n \ndiff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h\nindex a019c3a470ea..735a6b67e91d 100644\n--- a/src/qcam/viewfinder.h\n+++ b/src/qcam/viewfinder.h\n@@ -7,16 +7,24 @@\n #ifndef __QCAM_VIEWFINDER_H__\n #define __QCAM_VIEWFINDER_H__\n \n+#include <stddef.h>\n+\n #include <QMutex>\n #include <QSize>\n #include <QWidget>\n \n+#include <libcamera/buffer.h>\n #include <libcamera/pixelformats.h>\n \n #include \"format_converter.h\"\n \n class QImage;\n \n+struct MappedBuffer {\n+\tvoid *memory;\n+\tsize_t size;\n+};\n+\n class ViewFinder : public QWidget\n {\n public:\n@@ -24,7 +32,7 @@ public:\n \t~ViewFinder();\n \n \tint setFormat(const libcamera::PixelFormat &format, const QSize &size);\n-\tvoid display(const unsigned char *rgb, size_t size);\n+\tvoid display(const libcamera::FrameBuffer *buffer, MappedBuffer *map);\n \n \tQImage getCurrentImage();\n \n","prefixes":["libcamera-devel","13/21"]}