qcam: Cache buffer memory mapping

With the buffer allocator in use it's possible to cache the dmabuf
memory mappings when starting the camera instead of mapping and
unmapping them each time.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Niklas Söderlund
2019-12-17 01:27:11 +01:00
parent c89cfa534b
commit 07156a2713
2 changed files with 23 additions and 6 deletions
+22 -6
View File
@@ -201,6 +201,13 @@ int MainWindow::startCapture()
}
requests.push_back(request);
/* Map memory buffers and cache the mappings. */
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);
}
titleTimer_.start(2000);
@@ -230,6 +237,13 @@ error:
for (Request *request : requests)
delete request;
for (auto &iter : mappedBuffers_) {
void *memory = iter.second.first;
unsigned int length = iter.second.second;
munmap(memory, length);
}
mappedBuffers_.clear();
camera_->freeBuffers();
return ret;
}
@@ -243,6 +257,13 @@ void MainWindow::stopCapture()
if (ret)
std::cout << "Failed to stop capture" << std::endl;
for (auto &iter : mappedBuffers_) {
void *memory = iter.second.first;
unsigned int length = iter.second.second;
munmap(memory, length);
}
mappedBuffers_.clear();
camera_->freeBuffers();
isCapturing_ = false;
@@ -297,15 +318,10 @@ int MainWindow::display(FrameBuffer *buffer)
if (buffer->planes().size() != 1)
return -EINVAL;
/* \todo Once the FrameBuffer is done cache mapped memory. */
const FrameBuffer::Plane &plane = buffer->planes().front();
void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,
plane.fd.fd(), 0);
void *memory = mappedBuffers_[plane.fd.fd()].first;
unsigned char *raw = static_cast<unsigned char *>(memory);
viewfinder_->display(raw, buffer->metadata().planes[0].bytesused);
munmap(memory, plane.length);
return 0;
}
+1
View File
@@ -71,6 +71,7 @@ private:
uint32_t framesCaptured_;
ViewFinder *viewfinder_;
std::map<int, std::pair<void *, unsigned int>> mappedBuffers_;
};
#endif /* __QCAM_MAIN_WINDOW__ */