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 <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Hirokazu Honda 2021-08-26 20:25:35 +09:00 committed by Laurent Pinchart
parent 73994ec6bc
commit 1d2263dd3d
2 changed files with 12 additions and 4 deletions

View file

@ -10,6 +10,7 @@
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h>
#include <QComboBox> #include <QComboBox>
#include <QCoreApplication> #include <QCoreApplication>
@ -472,10 +473,14 @@ int MainWindow::startCapture()
for (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) { for (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) {
/* Map memory buffers and cache the mappings. */ /* Map memory buffers and cache the mappings. */
const FrameBuffer::Plane &plane = buffer->planes().front(); 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); plane.fd.fd(), 0);
mappedBuffers_[buffer.get()] = { static_cast<uint8_t *>(memory), mappedBuffers_[buffer.get()] = { static_cast<uint8_t *>(memory),
plane.length }; plane.length };
planeData_[buffer.get()] = { static_cast<uint8_t *>(memory) + plane.offset,
plane.length };
/* Store buffers on the free list. */ /* Store buffers on the free list. */
freeBuffers_[stream].enqueue(buffer.get()); freeBuffers_[stream].enqueue(buffer.get());
@ -542,6 +547,7 @@ error:
munmap(buffer.data(), buffer.size()); munmap(buffer.data(), buffer.size());
} }
mappedBuffers_.clear(); mappedBuffers_.clear();
planeData_.clear();
freeBuffers_.clear(); freeBuffers_.clear();
@ -578,6 +584,7 @@ void MainWindow::stopCapture()
munmap(buffer.data(), buffer.size()); munmap(buffer.data(), buffer.size());
} }
mappedBuffers_.clear(); mappedBuffers_.clear();
planeData_.clear();
requests_.clear(); requests_.clear();
freeQueue_.clear(); freeQueue_.clear();
@ -674,10 +681,10 @@ void MainWindow::processRaw(FrameBuffer *buffer,
"DNG Files (*.dng)"); "DNG Files (*.dng)");
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
const Span<uint8_t> &mapped = mappedBuffers_[buffer]; uint8_t *memory = planeData_[buffer].data();
DNGWriter::write(filename.toStdString().c_str(), camera_.get(), DNGWriter::write(filename.toStdString().c_str(), camera_.get(),
rawStream_->configuration(), metadata, buffer, rawStream_->configuration(), metadata, buffer,
mapped.data()); memory);
} }
#endif #endif
@ -754,7 +761,7 @@ void MainWindow::processViewfinder(FrameBuffer *buffer)
<< "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps; << "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps;
/* Render the frame on the viewfinder. */ /* Render the frame on the viewfinder. */
viewfinder_->render(buffer, mappedBuffers_[buffer]); viewfinder_->render(buffer, planeData_[buffer]);
} }
void MainWindow::queueRequest(FrameBuffer *buffer) void MainWindow::queueRequest(FrameBuffer *buffer)

View file

@ -107,6 +107,7 @@ private:
std::unique_ptr<CameraConfiguration> config_; std::unique_ptr<CameraConfiguration> config_;
std::map<FrameBuffer *, Span<uint8_t>> mappedBuffers_; std::map<FrameBuffer *, Span<uint8_t>> mappedBuffers_;
std::map<FrameBuffer *, Span<uint8_t>> planeData_;
/* Capture state, buffers queue and statistics */ /* Capture state, buffers queue and statistics */
bool isCapturing_; bool isCapturing_;