summaryrefslogtreecommitdiff
path: root/src/v4l2/v4l2_camera_proxy.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-01-09 15:20:44 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-01-12 16:10:37 +0100
commit3c4b87244352552cce8d7a9c7b97ff85b39b3d58 (patch)
treee59a72b49992ac75b612e60bff14986c588c4d9a /src/v4l2/v4l2_camera_proxy.cpp
parent35ac23dca19ea31f17a526679a697e3e327e6af1 (diff)
v4l2: camera: Handle memory mapping of buffers directly
In the upcoming FrameBuffer API the memory mapping of buffers will be left to the user of the FrameBuffer objects. Prepare the V4L2 compatibility layer to this upcoming change to ease conversion to the new API. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/v4l2/v4l2_camera_proxy.cpp')
-rw-r--r--src/v4l2/v4l2_camera_proxy.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index 52f8468c..d38500a3 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -75,7 +75,8 @@ void V4L2CameraProxy::close()
vcam_->invokeMethod(&V4L2Camera::close, ConnectionTypeBlocking);
}
-void *V4L2CameraProxy::mmap(size_t length, int prot, int flags, off_t offset)
+void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,
+ off_t offset)
{
LOG(V4L2Compat, Debug) << "Servicing mmap";
@@ -91,13 +92,22 @@ void *V4L2CameraProxy::mmap(size_t length, int prot, int flags, off_t offset)
return MAP_FAILED;
}
- void *val = vcam_->invokeMethod(&V4L2Camera::mmap,
- ConnectionTypeBlocking, index);
+ FileDescriptor fd = vcam_->invokeMethod(&V4L2Camera::getBufferFd,
+ ConnectionTypeBlocking, index);
+ if (!fd.isValid()) {
+ errno = EINVAL;
+ return MAP_FAILED;
+ }
+
+ void *map = V4L2CompatManager::instance()->fops().mmap(addr, length, prot,
+ flags, fd.fd(), 0);
+ if (map == MAP_FAILED)
+ return map;
buffers_[index].flags |= V4L2_BUF_FLAG_MAPPED;
- mmaps_[val] = index;
+ mmaps_[map] = index;
- return val;
+ return map;
}
int V4L2CameraProxy::munmap(void *addr, size_t length)
@@ -110,6 +120,10 @@ int V4L2CameraProxy::munmap(void *addr, size_t length)
return -1;
}
+ if (V4L2CompatManager::instance()->fops().munmap(addr, length))
+ LOG(V4L2Compat, Error) << "Failed to unmap " << addr
+ << " with length " << length;
+
buffers_[iter->second].flags &= ~V4L2_BUF_FLAG_MAPPED;
mmaps_.erase(iter);