From patchwork Wed Aug 18 00:22:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13381 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 45FF1BD87D for ; Wed, 18 Aug 2021 00:22:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A61CF6025D; Wed, 18 Aug 2021 02:22:20 +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="rVDKKH0+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 447C86025D for ; Wed, 18 Aug 2021 02:22:19 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C62B5499 for ; Wed, 18 Aug 2021 02:22:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1629246138; bh=KR97woK/c+mtO4HHNAxOIlNk+fHe+8S2FCc5guFi148=; h=From:To:Subject:Date:From; b=rVDKKH0+YrqmC2Q1V2EVKUroI84o1hXN7os0YVW24tYvXU+hCUstjyKaY7RI/IxRP Rqi7JfID4mJfjD++1YMphMTty4mP/Qtbv3KsOxo7tN0+BRahAs78h7kFT3/fKMstvJ lypRob3r+jvhAcVb1974efk8HCXvDXYgIbke2NjM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 18 Aug 2021 03:22:08 +0300 Message-Id: <20210818002208.13631-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] qcam: Replace MappedBuffer with Span 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" The MappedBuffer structure is a custom container that binds a data pointer with a length. This is exactly what Span is. Use it instead. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Hirokazu Honda --- src/qcam/main_window.cpp | 17 +++++++++-------- src/qcam/main_window.h | 2 +- src/qcam/viewfinder.h | 9 +++------ src/qcam/viewfinder_gl.cpp | 5 +++-- src/qcam/viewfinder_gl.h | 2 +- src/qcam/viewfinder_qt.cpp | 5 +++-- src/qcam/viewfinder_qt.h | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 39d034de6bb2..1adaae60d83b 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -474,7 +474,8 @@ int MainWindow::startCapture() 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 }; + mappedBuffers_[buffer.get()] = { static_cast(memory), + plane.length }; /* Store buffers on the free list. */ freeBuffers_[stream].enqueue(buffer.get()); @@ -537,8 +538,8 @@ error: requests_.clear(); for (auto &iter : mappedBuffers_) { - const MappedBuffer &buffer = iter.second; - munmap(buffer.memory, buffer.size); + const Span &buffer = iter.second; + munmap(buffer.data(), buffer.size()); } mappedBuffers_.clear(); @@ -573,8 +574,8 @@ void MainWindow::stopCapture() camera_->requestCompleted.disconnect(this, &MainWindow::requestComplete); for (auto &iter : mappedBuffers_) { - const MappedBuffer &buffer = iter.second; - munmap(buffer.memory, buffer.size); + const Span &buffer = iter.second; + munmap(buffer.data(), buffer.size()); } mappedBuffers_.clear(); @@ -673,10 +674,10 @@ void MainWindow::processRaw(FrameBuffer *buffer, "DNG Files (*.dng)"); if (!filename.isEmpty()) { - const MappedBuffer &mapped = mappedBuffers_[buffer]; + const Span &mapped = mappedBuffers_[buffer]; DNGWriter::write(filename.toStdString().c_str(), camera_.get(), rawStream_->configuration(), metadata, buffer, - mapped.memory); + mapped.data()); } #endif @@ -753,7 +754,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_[buffer]); } void MainWindow::queueRequest(FrameBuffer *buffer) diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 85d56ce49abe..6788de8ddde9 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -106,7 +106,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.h b/src/qcam/viewfinder.h index 46747c227d0c..42d40f1f33f0 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -11,14 +11,11 @@ #include #include +#include + #include #include -struct MappedBuffer { - void *memory; - size_t size; -}; - class ViewFinder { public: @@ -27,7 +24,7 @@ public: virtual const QList &nativeFormats() const = 0; virtual int setFormat(const libcamera::PixelFormat &format, const QSize &size) = 0; - virtual void render(libcamera::FrameBuffer *buffer, MappedBuffer *map) = 0; + virtual void render(libcamera::FrameBuffer *buffer, libcamera::Span mem) = 0; virtual void stop() = 0; virtual QImage getCurrentImage() = 0; diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index add87db88207..40226601f9fd 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -110,7 +110,8 @@ QImage ViewFinderGL::getCurrentImage() return grabFramebuffer(); } -void ViewFinderGL::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) +void ViewFinderGL::render(libcamera::FrameBuffer *buffer, + libcamera::Span mem) { if (buffer->planes().size() != 1) { qWarning() << "Multi-planar buffers are not supported"; @@ -120,7 +121,7 @@ void ViewFinderGL::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) if (buffer_) renderComplete(buffer_); - data_ = static_cast(map->memory); + data_ = mem.data(); /* * \todo Get the stride from the buffer instead of computing it naively */ diff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h index 4a0f8ca58f29..3334549e0be4 100644 --- a/src/qcam/viewfinder_gl.h +++ b/src/qcam/viewfinder_gl.h @@ -39,7 +39,7 @@ public: const QList &nativeFormats() const override; int setFormat(const libcamera::PixelFormat &format, const QSize &size) override; - void render(libcamera::FrameBuffer *buffer, MappedBuffer *map) override; + void render(libcamera::FrameBuffer *buffer, libcamera::Span mem) override; void stop() override; QImage getCurrentImage() override; diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp index e436714c6bdb..efa1d412584b 100644 --- a/src/qcam/viewfinder_qt.cpp +++ b/src/qcam/viewfinder_qt.cpp @@ -78,14 +78,15 @@ int ViewFinderQt::setFormat(const libcamera::PixelFormat &format, return 0; } -void ViewFinderQt::render(libcamera::FrameBuffer *buffer, MappedBuffer *map) +void ViewFinderQt::render(libcamera::FrameBuffer *buffer, + libcamera::Span mem) { if (buffer->planes().size() != 1) { qWarning() << "Multi-planar buffers are not supported"; return; } - unsigned char *memory = static_cast(map->memory); + unsigned char *memory = mem.data(); size_t size = buffer->metadata().planes[0].bytesused; { diff --git a/src/qcam/viewfinder_qt.h b/src/qcam/viewfinder_qt.h index 501c72a70dec..1a569b9cee6e 100644 --- a/src/qcam/viewfinder_qt.h +++ b/src/qcam/viewfinder_qt.h @@ -32,7 +32,7 @@ public: const QList &nativeFormats() const override; int setFormat(const libcamera::PixelFormat &format, const QSize &size) override; - void render(libcamera::FrameBuffer *buffer, MappedBuffer *map) override; + void render(libcamera::FrameBuffer *buffer, libcamera::Span mem) override; void stop() override; QImage getCurrentImage() override;