summaryrefslogtreecommitdiff
path: root/src/libcamera/v4l2_device.cpp
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2019-08-08 14:30:03 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2019-08-13 10:23:21 +0100
commite0f35d6f57465a54ac03eed62ff23833ec051029 (patch)
treeb6cf4e25d0b6a340cc8d3e3d285960d741dbf894 /src/libcamera/v4l2_device.cpp
parenta6799dc5b9ded442152b3430e321d9b147b9d7fd (diff)
libcamera: v4l2_device: Add setFd()
Provide a means for V4L2 device instances to set the fd_ explicitly. This allows for V4L2Devices to operate when they must use an external open() call. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/libcamera/v4l2_device.cpp')
-rw-r--r--src/libcamera/v4l2_device.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 9a00566a..f8954661 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -89,6 +89,32 @@ int V4L2Device::open(unsigned int flags)
}
/**
+ * \brief Set the file descriptor of a V4L2 device
+ * \param[in] fd The file descriptor handle
+ *
+ * This method allows a device to provide an already opened file descriptor
+ * referring to the V4L2 device node, instead of opening it with open(). This
+ * can be used for V4L2 M2M devices where a single video device node is used for
+ * both the output and capture devices, or when receiving an open file
+ * descriptor in a context that doesn't have permission to open the device node
+ * itself.
+ *
+ * This method and the open() method are mutually exclusive, only one of the two
+ * shall be used for a V4L2Device instance.
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int V4L2Device::setFd(int fd)
+{
+ if (isOpen())
+ return -EBUSY;
+
+ fd_ = fd;
+
+ return 0;
+}
+
+/**
* \brief Close the device node
*
* Reset the file descriptor to -1