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:
Kieran Bingham 2020-07-17 17:06:16 +01:00
parent e5b829ee53
commit ca6ae87af4

View file

@ -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++) {
void *dstmem = mmap(nullptr, planes_[i].length, PROT_WRITE,
MAP_SHARED, planes_[i].fd.fd(), 0);
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);
memcpy(destination.maps()[i].data(),
source.maps()[i].data(),
source.maps()[i].size());
}
metadata_ = src->metadata_;