diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-09-06 01:35:22 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-09-07 19:18:51 +0300 |
commit | a13676f2bb9a86ced75ed640f571512cf1a76afe (patch) | |
tree | da0bfea97abec2b03c4feca663dd1f0304230055 /src/qcam/main_window.cpp | |
parent | 013084310836519b57883176d65fb5e9f6c00f8d (diff) |
qcam: Use Image class to access pixel data
Replace the manual implementation of frame buffer mapping with the Image
class to improve code sharing. The ViewFinder API is updated to take an
Image pointer in the render() function to prepare for multi-planar
buffer support.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/qcam/main_window.cpp')
-rw-r--r-- | src/qcam/main_window.cpp | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 129aeb0b..b933ab21 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -7,10 +7,9 @@ #include "main_window.h" +#include <assert.h> #include <iomanip> #include <string> -#include <sys/mman.h> -#include <unistd.h> #include <QComboBox> #include <QCoreApplication> @@ -29,6 +28,7 @@ #include <libcamera/camera_manager.h> #include <libcamera/version.h> +#include "../cam/image.h" #include "dng_writer.h" #ifndef QT_NO_OPENGL #include "viewfinder_gl.h" @@ -473,15 +473,10 @@ int MainWindow::startCapture() for (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) { /* Map memory buffers and cache the mappings. */ - const FrameBuffer::Plane &plane = buffer->planes().front(); - size_t length = lseek(plane.fd.fd(), 0, SEEK_END); - void *memory = mmap(NULL, length, PROT_READ, MAP_SHARED, - plane.fd.fd(), 0); - - mappedBuffers_[buffer.get()] = { static_cast<uint8_t *>(memory), - plane.length }; - planeData_[buffer.get()] = { static_cast<uint8_t *>(memory) + plane.offset, - plane.length }; + std::unique_ptr<Image> image = + Image::fromFrameBuffer(buffer.get(), Image::MapMode::ReadOnly); + assert(image != nullptr); + mappedBuffers_[buffer.get()] = std::move(image); /* Store buffers on the free list. */ freeBuffers_[stream].enqueue(buffer.get()); @@ -543,12 +538,7 @@ error_disconnect: error: requests_.clear(); - for (auto &iter : mappedBuffers_) { - const Span<uint8_t> &buffer = iter.second; - munmap(buffer.data(), buffer.size()); - } mappedBuffers_.clear(); - planeData_.clear(); freeBuffers_.clear(); @@ -580,12 +570,7 @@ void MainWindow::stopCapture() camera_->requestCompleted.disconnect(this); - for (auto &iter : mappedBuffers_) { - const Span<uint8_t> &buffer = iter.second; - munmap(buffer.data(), buffer.size()); - } mappedBuffers_.clear(); - planeData_.clear(); requests_.clear(); freeQueue_.clear(); @@ -682,7 +667,7 @@ void MainWindow::processRaw(FrameBuffer *buffer, "DNG Files (*.dng)"); if (!filename.isEmpty()) { - uint8_t *memory = planeData_[buffer].data(); + uint8_t *memory = mappedBuffers_[buffer]->data(0).data(); DNGWriter::write(filename.toStdString().c_str(), camera_.get(), rawStream_->configuration(), metadata, buffer, memory); @@ -766,7 +751,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer) << "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps; /* Render the frame on the viewfinder. */ - viewfinder_->render(buffer, planeData_[buffer]); + viewfinder_->render(buffer, mappedBuffers_[buffer].get()); } void MainWindow::queueRequest(FrameBuffer *buffer) |