From patchwork Mon Jul 20 22:42:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8895 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id F3369C2E67 for ; Mon, 20 Jul 2020 22:42:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 13CD86087E; Tue, 21 Jul 2020 00:42:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="eWz/qbnu"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EDEEF605BB for ; Tue, 21 Jul 2020 00:42:37 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C9BDA49; Tue, 21 Jul 2020 00:42:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1595284957; bh=0/d+NRPlOjBZEzfEZjvq9MzBQ4q/8ZbSbxzpg7wdSTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eWz/qbnu7/rgGjVIxadBd1eKMvQoUrRguPPnVmgY9sf9zO1+nu346mCo46Hsh7is3 Bg0OmrOMY5/dBPMcLLQ6ye/8sFroJ5TIb+4t/k/BXztbJn4WiC+r3zB0hVsL56JMxC 52DnCqjz98I9QL9epUU1W+vtD7mJ2rXK4ijWT0zQ= From: Kieran Bingham To: libcamera devel 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 MappedFrameBuffer X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Remove the local mapping code, and utilise the libcamera buffer map helper class. Signed-off-by: Kieran Bingham --- Working towards a more generic MappedBuffer base interface of the newly introduced MappedFrameBuffer hits a snag that the viewfinder in qcam already defines a type which conflicts. Remove it by converting qcam to use the new MappedFrameBuffer types. src/qcam/main_window.cpp | 27 +++++++++++---------------- src/qcam/main_window.h | 2 +- src/qcam/viewfinder.cpp | 4 ++-- src/qcam/viewfinder.h | 7 +------ 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7bc13603774e..b25260ba7b28 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -446,10 +446,14 @@ int MainWindow::startCapture() for (const std::unique_ptr &buffer : allocator_->buffers(stream)) { /* Map memory buffers and cache the mappings. */ - const FrameBuffer::Plane &plane = buffer->planes().front(); - void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED, - plane.fd.fd(), 0); - mappedBuffers_[buffer.get()] = { memory, plane.length }; + MappedFrameBuffer mapped(buffer.get(), PROT_READ); + if (!mapped.isValid()) { + qWarning() << "Failed to map buffer"; + ret = mapped.error(); + goto error; + } + + mappedBuffers_.insert({buffer.get(), std::move(mapped)}); /* Store buffers on the free list. */ freeBuffers_[stream].enqueue(buffer.get()); @@ -512,12 +516,7 @@ error: for (Request *request : requests) delete request; - for (auto &iter : mappedBuffers_) { - const MappedBuffer &buffer = iter.second; - munmap(buffer.memory, buffer.size); - } mappedBuffers_.clear(); - freeBuffers_.clear(); delete allocator_; @@ -548,10 +547,6 @@ void MainWindow::stopCapture() camera_->requestCompleted.disconnect(this, &MainWindow::requestComplete); - for (auto &iter : mappedBuffers_) { - const MappedBuffer &buffer = iter.second; - munmap(buffer.memory, buffer.size); - } mappedBuffers_.clear(); delete allocator_; @@ -643,10 +638,10 @@ void MainWindow::processRaw(FrameBuffer *buffer, const ControlList &metadata) "DNG Files (*.dng)"); if (!filename.isEmpty()) { - const MappedBuffer &mapped = mappedBuffers_[buffer]; + const MappedFrameBuffer &mapped = mappedBuffers_.at(buffer); DNGWriter::write(filename.toStdString().c_str(), camera_.get(), rawStream_->configuration(), metadata, buffer, - mapped.memory); + mapped.maps()[0].address); } #endif @@ -720,7 +715,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer) << "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps; /* Render the frame on the viewfinder. */ - viewfinder_->render(buffer, &mappedBuffers_[buffer]); + viewfinder_->render(buffer, &mappedBuffers_.at(buffer)); } void MainWindow::queueRequest(FrameBuffer *buffer) diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 4606fe487ad4..ddf51ca01111 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -119,7 +119,7 @@ private: FrameBufferAllocator *allocator_; std::unique_ptr config_; - std::map mappedBuffers_; + std::map mappedBuffers_; /* Capture state, buffers queue and statistics */ bool isCapturing_; diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index dcf8a15d2df6..591d26eae87c 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -78,14 +78,14 @@ int ViewFinder::setFormat(const libcamera::PixelFormat &format, return 0; } -void ViewFinder::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) +void ViewFinder::render(libcamera::FrameBuffer *buffer, libcamera::MappedFrameBuffer *map) { if (buffer->planes().size() != 1) { qWarning() << "Multi-planar buffers are not supported"; return; } - unsigned char *memory = static_cast(map->memory); + unsigned char *memory = static_cast(map->maps()[0].address); size_t size = buffer->metadata().planes[0].bytesused; { diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h index 26a1320537d2..c4cc51f14dda 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -23,11 +23,6 @@ class QImage; -struct MappedBuffer { - void *memory; - size_t size; -}; - class ViewFinder : public QWidget { Q_OBJECT @@ -39,7 +34,7 @@ public: const QList &nativeFormats() const; int setFormat(const libcamera::PixelFormat &format, const QSize &size); - void render(libcamera::FrameBuffer *buffer, MappedBuffer *map); + void render(libcamera::FrameBuffer *buffer, libcamera::MappedFrameBuffer *map); void stop(); QImage getCurrentImage();