From 1d2263dd3d7dc68d8d1920682952e17d0a22ed95 Mon Sep 17 00:00:00 2001 From: Hirokazu Honda Date: Thu, 26 Aug 2021 20:25:35 +0900 Subject: qcam: main_window: Use offset mapping FrameBuffer FrameBuffer::Plane has offset info now. This uses the offset in mapping FrameBuffer in MainWindow. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/qcam/main_window.cpp | 15 +++++++++++---- src/qcam/main_window.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 1adaae60..3669c0b9 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -472,10 +473,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, + 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(memory), plane.length }; + planeData_[buffer.get()] = { static_cast(memory) + plane.offset, + plane.length }; /* Store buffers on the free list. */ freeBuffers_[stream].enqueue(buffer.get()); @@ -542,6 +547,7 @@ error: munmap(buffer.data(), buffer.size()); } mappedBuffers_.clear(); + planeData_.clear(); freeBuffers_.clear(); @@ -578,6 +584,7 @@ void MainWindow::stopCapture() munmap(buffer.data(), buffer.size()); } mappedBuffers_.clear(); + planeData_.clear(); requests_.clear(); freeQueue_.clear(); @@ -674,10 +681,10 @@ void MainWindow::processRaw(FrameBuffer *buffer, "DNG Files (*.dng)"); if (!filename.isEmpty()) { - const Span &mapped = mappedBuffers_[buffer]; + uint8_t *memory = planeData_[buffer].data(); DNGWriter::write(filename.toStdString().c_str(), camera_.get(), rawStream_->configuration(), metadata, buffer, - mapped.data()); + memory); } #endif @@ -754,7 +761,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, planeData_[buffer]); } void MainWindow::queueRequest(FrameBuffer *buffer) diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 6788de8d..28244bca 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -107,6 +107,7 @@ private: std::unique_ptr config_; std::map> mappedBuffers_; + std::map> planeData_; /* Capture state, buffers queue and statistics */ bool isCapturing_; -- cgit v1.2.1