mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-25 01:25:08 +03:00
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>
This commit is contained in:
parent
e5b829ee53
commit
ca6ae87af4
1 changed files with 16 additions and 25 deletions
|
@ -261,32 +261,23 @@ int FrameBuffer::copyFrom(const FrameBuffer *src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MappedFrameBuffer source(src, PROT_READ);
|
||||||
|
MappedFrameBuffer destination(this, PROT_WRITE);
|
||||||
|
|
||||||
|
if (!source.isValid()) {
|
||||||
|
LOG(Buffer, Error) << "Failed to map source planes";
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!destination.isValid()) {
|
||||||
|
LOG(Buffer, Error) << "Failed to map destination planes";
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < planes_.size(); i++) {
|
for (unsigned int i = 0; i < planes_.size(); i++) {
|
||||||
void *dstmem = mmap(nullptr, planes_[i].length, PROT_WRITE,
|
memcpy(destination.maps()[i].data(),
|
||||||
MAP_SHARED, planes_[i].fd.fd(), 0);
|
source.maps()[i].data(),
|
||||||
|
source.maps()[i].size());
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(dstmem, srcmem, src->planes_[i].length);
|
|
||||||
|
|
||||||
munmap(srcmem, src->planes_[i].length);
|
|
||||||
munmap(dstmem, planes_[i].length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata_ = src->metadata_;
|
metadata_ = src->metadata_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue