libcamera::V4L2Device Class Reference

Base class for V4L2VideoDevice and V4L2Subdevice. More...

Inheritance diagram for libcamera::V4L2Device:

## Public Member Functions

void | close ()
| Close the device node. More...
bool | isOpen () const
| Check if the V4L2 device node is open. More...
const ControlInfoMap & | controls () const
| Retrieve the supported V4L2 controls and their information. More...
ControlList | getControls (const std::vector< uint32_t > &ids)
| Read controls from the device. More...
int | setControls (ControlList *ctrls)
| Write controls to the device. More...
const std::string & | deviceNode () const
| Retrieve the device node path. More...

## Protected Member Functions

| V4L2Device (const std::string &deviceNode)
| Construct a V4L2Device. More...
| ~V4L2Device ()
| Destroy a V4L2Device.
int | open (unsigned int flags)
| Open a V4L2 device node. More...
int | setFd (int fd)
| Set the file descriptor of a V4L2 device. More...
int | ioctl (unsigned long request, void *argp)
| Perform an IOCTL system call on the device node. More...
int | fd ()
| Retrieve the V4L2 device file descriptor. More...
Protected Member Functions inherited from libcamera::Loggable
virtual std::string | logPrefix () const =0
| Retrieve a string to be prefixed to the log message. More...
LogMessage | _log (const char *file, unsigned int line, LogSeverity severity) const
| Create a temporary LogMessage object to log a message. More...
LogMessage | _log (const char *file, unsigned int line, const LogCategory &category, LogSeverity severity) const
| Create a temporary LogMessage object to log a message. More...

## Detailed Description

Base class for V4L2VideoDevice and V4L2Subdevice.

The V4L2Device class groups together the methods and fields common to both the V4L2VideoDevice and V4L2Subdevice classes, and provides a base class with methods to open and close the device node associated with the device and to perform IOCTL system calls on it.

The V4L2Device class cannot be instantiated directly, as its constructor is protected. Users should instead create instances of one the derived classes to model either a V4L2 video device or a V4L2 subdevice.

## Constructor & Destructor Documentation

## V4L2Device()

libcamera::V4L2Device::V4L2Device | ( | const std::string & | deviceNode | ) |

protected

Construct a V4L2Device.

Parameters

  [in] | deviceNode | The device node filesystem path

Initialize the file descriptor to -1 and store the deviceNode to be used at open() time, and the logTag to prefix log messages with.

## Member Function Documentation

## close()

void libcamera::V4L2Device::close | ( |  | ) |

Close the device node.

Reset the file descriptor to -1

## controls()

libcamera::V4L2Device::controls | ( |  | ) | const

inline

Retrieve the supported V4L2 controls and their information.

Returns
  A map of the V4L2 controls supported by the device

## deviceNode()

libcamera::V4L2Device::deviceNode | ( |  | ) | const

inline

Retrieve the device node path.

Returns
  The device node path

## fd()

libcamera::V4L2Device::fd | ( |  | ) |

inline protected

Retrieve the V4L2 device file descriptor.

Returns
  The V4L2 device file descriptor, -1 if the device node is not open

## getControls()

ControlList libcamera::V4L2Device::getControls | ( | const std::vector< uint32_t > & | ids | ) |

Read controls from the device.

Parameters

  [in] | ids | The list of controls to read, specified by their ID

This method reads the value of all controls contained in ids, and returns their values as a ControlList.

If any control in ids is not supported by the device, is disabled (i.e. has the V4L2_CTRL_FLAG_DISABLED flag set), or if any other error occurs during validation of the requested controls, no control is read and this method returns an empty control list.

Returns
  The control values in a ControlList on success, or an empty list on error

## ioctl()

int libcamera::V4L2Device::ioctl | ( | unsigned long | request,
|  | void * | argp
| ) |  |

protected

Perform an IOCTL system call on the device node.

Parameters

  [in] | request | The IOCTL request code
  [in] | argp | A pointer to the IOCTL argument

Returns
  0 on success or a negative error code otherwise

## isOpen()

libcamera::V4L2Device::isOpen | ( |  | ) | const

inline

Check if the V4L2 device node is open.

Returns
  True if the V4L2 device node is open, false otherwise

## open()

int libcamera::V4L2Device::open | ( | unsigned int | flags | ) |

protected

Open a V4L2 device node.

Parameters

  [in] | flags | Access mode flags

Open the device node path with the provided access mode flags and initialize the file descriptor, which was initially set to -1.

Returns
  0 on success or a negative error code otherwise

## setControls()

int libcamera::V4L2Device::setControls | ( | ControlList * | ctrls | ) |

Write controls to the device.

Parameters

  [in] | ctrls | The list of controls to write

This method writes the value of all controls contained in ctrls, and stores the values actually applied to the device in the corresponding ctrls entry.

If any control in ctrls is not supported by the device, is disabled (i.e. has the V4L2_CTRL_FLAG_DISABLED flag set), is read-only, if any other error occurs during validation of the requested controls, no control is written and this method returns -EINVAL.

If an error occurs while writing the controls, the index of the first control that couldn't be written is returned. All controls below that index are written and their values are updated in ctrls, while all other controls are not written and their values are not changed.

Returns
  0 on success or an error code otherwise

Return values

  -EINVAL | One of the control is not supported or not accessible
  i | The index of the control that failed

## setFd()

int libcamera::V4L2Device::setFd | ( | int | fd | ) |

protected

Set the file descriptor of a V4L2 device.

Parameters

  [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.

Returns
  0 on success or a negative error code otherwise

The documentation for this class was generated from the following files:

- include/libcamera/internal/v4l2_device.h
- src/libcamera/v4l2_device.cpp