diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-03-23 01:25:20 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-03-24 10:34:02 +0200 |
commit | 275fd5bd33107a10b1e47a0d36d834b390831af0 (patch) | |
tree | 3fff6cc018c1cdc2068f6465cb422b755e2b0a60 /src/qcam/main_window.cpp | |
parent | 494da4467ddf091d457863cd363067979552d67e (diff) |
qcam: viewfinder: Add MappedBuffer to store memory mapping information
The new MappedBuffer structure replaces the std::pair<> used in the
mapped buffers map, and allows passing data to the ViewFinder::display()
function in a more structured way.
Signed-off-by: Laurent Pinchart <laurent.pinchart@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 | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index cb8f769e..d10c542c 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -27,8 +27,6 @@ #include <libcamera/camera_manager.h> #include <libcamera/version.h> -#include "viewfinder.h" - using namespace libcamera; /** @@ -354,8 +352,7 @@ 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_[plane.fd.fd()] = - std::make_pair(memory, plane.length); + mappedBuffers_[buffer.get()] = { memory, plane.length }; } /* Start the title timer and the camera. */ @@ -395,9 +392,8 @@ error: delete request; for (auto &iter : mappedBuffers_) { - void *memory = iter.second.first; - unsigned int length = iter.second.second; - munmap(memory, length); + const MappedBuffer &buffer = iter.second; + munmap(buffer.memory, buffer.size); } mappedBuffers_.clear(); @@ -425,9 +421,8 @@ void MainWindow::stopCapture() camera_->requestCompleted.disconnect(this, &MainWindow::requestComplete); for (auto &iter : mappedBuffers_) { - void *memory = iter.second.first; - unsigned int length = iter.second.second; - munmap(memory, length); + const MappedBuffer &buffer = iter.second; + munmap(buffer.memory, buffer.size); } mappedBuffers_.clear(); @@ -534,10 +529,7 @@ int MainWindow::display(FrameBuffer *buffer) if (buffer->planes().size() != 1) return -EINVAL; - const FrameBuffer::Plane &plane = buffer->planes().front(); - void *memory = mappedBuffers_[plane.fd.fd()].first; - unsigned char *raw = static_cast<unsigned char *>(memory); - viewfinder_->display(raw, buffer->metadata().planes[0].bytesused); + viewfinder_->display(buffer, &mappedBuffers_[buffer]); return 0; } |