summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2020-07-17 17:06:16 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-08-06 15:44:00 +0100
commitca6ae87af4c02e67ff876e3a354b4471d1b7592a (patch)
tree22475f76b36bdc9d1c1b7f5338095ac4f7e58273
parente5b829ee53103da16e5b775c5c5b4973bc50d56a (diff)
libcamera: buffer: Convert copyFrom to use MappedFrameBuffer
Utilise the new MappedFrameBuffer helper to handle all mapping and unmapping of the copyFrom helper function. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--src/libcamera/buffer.cpp37
1 files changed, 14 insertions, 23 deletions
diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp
index d040ac9a..a094737d 100644
--- a/src/libcamera/buffer.cpp
+++ b/src/libcamera/buffer.cpp
@@ -261,32 +261,23 @@ int FrameBuffer::copyFrom(const FrameBuffer *src)
}
}
- for (unsigned int i = 0; i < planes_.size(); i++) {
- void *dstmem = mmap(nullptr, planes_[i].length, PROT_WRITE,
- MAP_SHARED, planes_[i].fd.fd(), 0);
+ MappedFrameBuffer source(src, PROT_READ);
+ MappedFrameBuffer destination(this, PROT_WRITE);
- if (dstmem == MAP_FAILED) {
- LOG(Buffer, Error)
- << "Failed to map destination plane " << i;
- metadata_.status = FrameMetadata::FrameError;
- return -EINVAL;
- }
-
- void *srcmem = mmap(nullptr, src->planes_[i].length, PROT_READ,
- MAP_SHARED, src->planes_[i].fd.fd(), 0);
-
- if (srcmem == MAP_FAILED) {
- munmap(dstmem, planes_[i].length);
- LOG(Buffer, Error)
- << "Failed to map source plane " << i;
- metadata_.status = FrameMetadata::FrameError;
- return -EINVAL;
- }
+ if (!source.isValid()) {
+ LOG(Buffer, Error) << "Failed to map source planes";
+ return -EINVAL;
+ }
- memcpy(dstmem, srcmem, src->planes_[i].length);
+ if (!destination.isValid()) {
+ LOG(Buffer, Error) << "Failed to map destination planes";
+ return -EINVAL;
+ }
- munmap(srcmem, src->planes_[i].length);
- munmap(dstmem, planes_[i].length);
+ for (unsigned int i = 0; i < planes_.size(); i++) {
+ memcpy(destination.maps()[i].data(),
+ source.maps()[i].data(),
+ source.maps()[i].size());
}
metadata_ = src->metadata_;