summaryrefslogtreecommitdiff
path: root/src/v4l2/v4l2_camera.cpp
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2020-06-22 18:51:20 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2020-06-25 23:41:29 +0900
commit9076e88fc3ca3d3ffbd1b0d80542db96708614e7 (patch)
tree9c57889d22b6b868519b3cd5644a1df0001dcb8e /src/v4l2/v4l2_camera.cpp
parentedacd07c5e9a5080628e7cc4d057674f7f742ead (diff)
v4l2: v4l2_compat: Support multiple open
Previously, since we acquired the libcamera camera upon open(), it was impossible to support multiple open, as any subsequent opens would return error because the camera would already be acquired. To fix this, we first initialize the camera in the first call to V4L2CameraProxy::open(), just to heat up the stream format cache. We then add ownership by a V4L2CameraFile of a V4L2Camera via the V4L2CameraProxy. All vidioc ioctls prior to reqbufs > 0 (except for s_fmt) are able to access the camera without ownership. A call to reqbufs > 0 (and s_fmt) will take ownership, and the ownership will be released at reqbufs = 0. While ownership is assigned, the eventfd that should be signaled (and cleared) by V4L2Camera and V4L2CameraProxy is set to the V4L2CameraFile that has ownership, and is cleared when the ownership is released. In case close() is called without a reqbufs = 0 first, the ownership is also released on close(). We also use the V4L2CameraFile to contain all the information specific to an open instance of the file. This removes the need to keep track of such information within V4L2CameraProxy via multiple maps from int fd to info. Since V4L2 does not expect reqbufs 0 to ever return error, make V4L2CameraProxy::freeBuffers() return void. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/v4l2/v4l2_camera.cpp')
-rw-r--r--src/v4l2/v4l2_camera.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp
index 9a1ebc84..25573202 100644
--- a/src/v4l2/v4l2_camera.cpp
+++ b/src/v4l2/v4l2_camera.cpp
@@ -17,7 +17,8 @@ using namespace libcamera;
LOG_DECLARE_CATEGORY(V4L2Compat);
V4L2Camera::V4L2Camera(std::shared_ptr<Camera> camera)
- : camera_(camera), isRunning_(false), bufferAllocator_(nullptr)
+ : camera_(camera), isRunning_(false), bufferAllocator_(nullptr),
+ efd_(-1)
{
camera_->requestCompleted.connect(this, &V4L2Camera::requestComplete);
}
@@ -29,7 +30,6 @@ V4L2Camera::~V4L2Camera()
int V4L2Camera::open()
{
- /* \todo Support multiple open. */
if (camera_->acquire() < 0) {
LOG(V4L2Compat, Error) << "Failed to acquire camera";
return -EINVAL;
@@ -59,6 +59,11 @@ void V4L2Camera::bind(int efd)
efd_ = efd;
}
+void V4L2Camera::unbind()
+{
+ efd_ = -1;
+}
+
void V4L2Camera::getStreamConfig(StreamConfiguration *streamConfig)
{
*streamConfig = config_->at(0);