{"id":8895,"url":"https://patchwork.libcamera.org/api/1.1/patches/8895/?format=json","web_url":"https://patchwork.libcamera.org/patch/8895/","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":"<20200720224232.153717-4-kieran.bingham@ideasonboard.com>","date":"2020-07-20T22:42:27","name":"[libcamera-devel,RFC,3/8] qcam: Convert to use MappedFrameBuffer","commit_ref":null,"pull_url":null,"state":"rfc","archived":false,"hash":"c663a1b2496712790d8263d7825f156259c61925","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8895/mbox/","series":[{"id":1119,"url":"https://patchwork.libcamera.org/api/1.1/series/1119/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1119","date":"2020-07-20T22:42:24","name":"RFC MappedBuffers","version":1,"mbox":"https://patchwork.libcamera.org/series/1119/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8895/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8895/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id F3369C2E67\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jul 2020 22:42:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 13CD86087E;\n\tTue, 21 Jul 2020 00:42:40 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EDEEF605BB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 21 Jul 2020 00:42:37 +0200 (CEST)","from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C9BDA49;\n\tTue, 21 Jul 2020 00:42:37 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"eWz/qbnu\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1595284957;\n\tbh=0/d+NRPlOjBZEzfEZjvq9MzBQ4q/8ZbSbxzpg7wdSTc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=eWz/qbnu7/rgGjVIxadBd1eKMvQoUrRguPPnVmgY9sf9zO1+nu346mCo46Hsh7is3\n\tBg0OmrOMY5/dBPMcLLQ6ye/8sFroJ5TIb+4t/k/BXztbJn4WiC+r3zB0hVsL56JMxC\n\t52DnCqjz98I9QL9epUU1W+vtD7mJ2rXK4ijWT0zQ=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Mon, 20 Jul 2020 23:42:27 +0100","Message-Id":"<20200720224232.153717-4-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20200720224232.153717-1-kieran.bingham@ideasonboard.com>","References":"<20200720224232.153717-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [RFC PATCH 3/8] qcam: Convert to use\n\tMappedFrameBuffer","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Remove the local mapping code, and utilise the libcamera buffer map\nhelper class.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n\nWorking towards a more generic MappedBuffer base interface of the newly\nintroduced MappedFrameBuffer hits a snag that the viewfinder in qcam\nalready defines a type which conflicts.\n\nRemove it by converting qcam to use the new MappedFrameBuffer types.\n\n\n src/qcam/main_window.cpp | 27 +++++++++++----------------\n src/qcam/main_window.h   |  2 +-\n src/qcam/viewfinder.cpp  |  4 ++--\n src/qcam/viewfinder.h    |  7 +------\n 4 files changed, 15 insertions(+), 25 deletions(-)","diff":"diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex 7bc13603774e..b25260ba7b28 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -446,10 +446,14 @@ int MainWindow::startCapture()\n \n \t\tfor (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) {\n \t\t\t/* Map memory buffers and cache the mappings. */\n-\t\t\tconst FrameBuffer::Plane &plane = buffer->planes().front();\n-\t\t\tvoid *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,\n-\t\t\t\t\t    plane.fd.fd(), 0);\n-\t\t\tmappedBuffers_[buffer.get()] = { memory, plane.length };\n+\t\t\tMappedFrameBuffer mapped(buffer.get(), PROT_READ);\n+\t\t\tif (!mapped.isValid()) {\n+\t\t\t\tqWarning() << \"Failed to map buffer\";\n+\t\t\t\tret = mapped.error();\n+\t\t\t\tgoto error;\n+\t\t\t}\n+\n+\t\t\tmappedBuffers_.insert({buffer.get(), std::move(mapped)});\n \n \t\t\t/* Store buffers on the free list. */\n \t\t\tfreeBuffers_[stream].enqueue(buffer.get());\n@@ -512,12 +516,7 @@ error:\n \tfor (Request *request : requests)\n \t\tdelete request;\n \n-\tfor (auto &iter : mappedBuffers_) {\n-\t\tconst MappedBuffer &buffer = iter.second;\n-\t\tmunmap(buffer.memory, buffer.size);\n-\t}\n \tmappedBuffers_.clear();\n-\n \tfreeBuffers_.clear();\n \n \tdelete allocator_;\n@@ -548,10 +547,6 @@ void MainWindow::stopCapture()\n \n \tcamera_->requestCompleted.disconnect(this, &MainWindow::requestComplete);\n \n-\tfor (auto &iter : mappedBuffers_) {\n-\t\tconst MappedBuffer &buffer = iter.second;\n-\t\tmunmap(buffer.memory, buffer.size);\n-\t}\n \tmappedBuffers_.clear();\n \n \tdelete allocator_;\n@@ -643,10 +638,10 @@ void MainWindow::processRaw(FrameBuffer *buffer, const ControlList &metadata)\n \t\t\t\t\t\t\t\"DNG Files (*.dng)\");\n \n \tif (!filename.isEmpty()) {\n-\t\tconst MappedBuffer &mapped = mappedBuffers_[buffer];\n+\t\tconst MappedFrameBuffer &mapped = mappedBuffers_.at(buffer);\n \t\tDNGWriter::write(filename.toStdString().c_str(), camera_.get(),\n \t\t\t\t rawStream_->configuration(), metadata, buffer,\n-\t\t\t\t mapped.memory);\n+\t\t\t\t mapped.maps()[0].address);\n \t}\n #endif\n \n@@ -720,7 +715,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer)\n \t\t<< \"fps:\" << Qt::fixed << qSetRealNumberPrecision(2) << fps;\n \n \t/* Render the frame on the viewfinder. */\n-\tviewfinder_->render(buffer, &mappedBuffers_[buffer]);\n+\tviewfinder_->render(buffer, &mappedBuffers_.at(buffer));\n }\n \n void MainWindow::queueRequest(FrameBuffer *buffer)\ndiff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\nindex 4606fe487ad4..ddf51ca01111 100644\n--- a/src/qcam/main_window.h\n+++ b/src/qcam/main_window.h\n@@ -119,7 +119,7 @@ private:\n \tFrameBufferAllocator *allocator_;\n \n \tstd::unique_ptr<CameraConfiguration> config_;\n-\tstd::map<FrameBuffer *, MappedBuffer> mappedBuffers_;\n+\tstd::map<FrameBuffer *, MappedFrameBuffer> 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 dcf8a15d2df6..591d26eae87c 100644\n--- a/src/qcam/viewfinder.cpp\n+++ b/src/qcam/viewfinder.cpp\n@@ -78,14 +78,14 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format,\n \treturn 0;\n }\n \n-void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)\n+void ViewFinder::render(libcamera::FrameBuffer *buffer, libcamera::MappedFrameBuffer *map)\n {\n \tif (buffer->planes().size() != 1) {\n \t\tqWarning() << \"Multi-planar buffers are not supported\";\n \t\treturn;\n \t}\n \n-\tunsigned char *memory = static_cast<unsigned char *>(map->memory);\n+\tunsigned char *memory = static_cast<unsigned char *>(map->maps()[0].address);\n \tsize_t size = buffer->metadata().planes[0].bytesused;\n \n \t{\ndiff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h\nindex 26a1320537d2..c4cc51f14dda 100644\n--- a/src/qcam/viewfinder.h\n+++ b/src/qcam/viewfinder.h\n@@ -23,11 +23,6 @@\n \n class QImage;\n \n-struct MappedBuffer {\n-\tvoid *memory;\n-\tsize_t size;\n-};\n-\n class ViewFinder : public QWidget\n {\n \tQ_OBJECT\n@@ -39,7 +34,7 @@ public:\n \tconst QList<libcamera::PixelFormat> &nativeFormats() const;\n \n \tint setFormat(const libcamera::PixelFormat &format, const QSize &size);\n-\tvoid render(libcamera::FrameBuffer *buffer, MappedBuffer *map);\n+\tvoid render(libcamera::FrameBuffer *buffer, libcamera::MappedFrameBuffer *map);\n \tvoid stop();\n \n \tQImage getCurrentImage();\n","prefixes":["libcamera-devel","RFC","3/8"]}