libcamera  v0.3.1+12-19bbca3c
Supporting cameras in Linux since 2019
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
libcamera::DeviceEnumerator Class Referenceabstract

Enumerate, store and search media devices. More...

Collaboration diagram for libcamera::DeviceEnumerator:
Collaboration graph
[legend]

Public Member Functions

virtual int init ()=0
 Initialize the enumerator. More...
 
virtual int enumerate ()=0
 Enumerate all media devices in the system. More...
 
std::shared_ptr< MediaDevicesearch (const DeviceMatch &dm)
 Search available media devices for a pattern match. More...
 

Static Public Member Functions

static std::unique_ptr< DeviceEnumeratorcreate ()
 Create a new device enumerator matching the systems capabilities. More...
 

Public Attributes

Signal devicesAdded
 Notify of new media devices being found. More...
 

Protected Member Functions

std::unique_ptr< MediaDevicecreateDevice (const std::string &deviceNode)
 Create a media device instance. More...
 
void addDevice (std::unique_ptr< MediaDevice > media)
 Add a media device to the enumerator. More...
 
void removeDevice (const std::string &deviceNode)
 Remove a media device from the enumerator. More...
 

Detailed Description

Enumerate, store and search media devices.

The DeviceEnumerator class is responsible for all interactions with the operating system related to media devices. It enumerates all media devices in the system, and for each device found creates an instance of the MediaDevice class and stores it internally. The list of media devices can then be searched using DeviceMatch search patterns.

The enumerator also associates media device entities with device node paths.

Member Function Documentation

◆ addDevice()

void libcamera::DeviceEnumerator::addDevice ( std::unique_ptr< MediaDevice media)
protected

Add a media device to the enumerator.

Parameters
[in]mediamedia device instance to add

Store the media device in the internal list for later matching with pipeline handlers. media shall be created with createDevice() first. This function shall be called after all members of the entities of the media graph have been confirmed to be initialized.

◆ create()

std::unique_ptr< DeviceEnumerator > libcamera::DeviceEnumerator::create ( )
static

Create a new device enumerator matching the systems capabilities.

Depending on how the operating system handles device detection, hot-plug notification and device node lookup, different device enumerator implementations may be needed. This function creates the best enumerator for the operating system based on the available resources. Not all different enumerator types are guaranteed to support all features.

Returns
A pointer to the newly created device enumerator on success, or nullptr if an error occurs

◆ createDevice()

std::unique_ptr< MediaDevice > libcamera::DeviceEnumerator::createDevice ( const std::string &  deviceNode)
protected

Create a media device instance.

Parameters
[in]deviceNodepath to the media device to create

Create a media device for the deviceNode, open it, and populate its media graph. The device enumerator shall then populate the media device by associating device nodes with entities using MediaEntity::setDeviceNode(). This process is specific to each device enumerator, and the device enumerator shall ensure that device nodes are ready to be used (for instance, if applicable, by waiting for device nodes to be created and access permissions to be set by the system). Once done, it shall add the media device to the system with addDevice().

Returns
Created media device instance on success, or nullptr otherwise

◆ enumerate()

libcamera::DeviceEnumerator::enumerate ( )
pure virtual

Enumerate all media devices in the system.

This function finds and add all media devices in the system to the enumerator. It shall be implemented by all subclasses of DeviceEnumerator using system-specific methods.

Individual media devices that can't be properly enumerated shall be skipped with a warning message logged, without returning an error. Only errors that prevent enumeration altogether shall be fatal.

Thread Safety:
This function is thread-bound.
Returns
0 on success or a negative error code otherwise

◆ init()

libcamera::DeviceEnumerator::init ( )
pure virtual

Initialize the enumerator.

Returns
0 on success or a negative error code otherwise
Return values
-EBUSYthe enumerator has already been initialized
-ENODEVthe enumerator can't enumerate devices

◆ removeDevice()

void libcamera::DeviceEnumerator::removeDevice ( const std::string &  deviceNode)
protected

Remove a media device from the enumerator.

Parameters
[in]deviceNodePath to the media device to remove

Remove the media device identified by deviceNode previously added to the enumerator with addDevice(). The media device's MediaDevice::disconnected signal is emitted.

◆ search()

std::shared_ptr< MediaDevice > libcamera::DeviceEnumerator::search ( const DeviceMatch dm)

Search available media devices for a pattern match.

Parameters
[in]dmSearch pattern

Search in the enumerated media devices that are not already in use for a match described in dm. If a match is found and the caller intends to use it the caller is responsible for acquiring the MediaDevice object and releasing it when done with it.

Returns
pointer to the matching MediaDevice, or nullptr if no match is found

Member Data Documentation

◆ devicesAdded

libcamera::DeviceEnumerator::devicesAdded

Notify of new media devices being found.

This signal is emitted when the device enumerator finds new media devices in the system. It may be emitted for every newly detected device, or once for multiple devices, at the discretion of the device enumerator. Not all device enumerator types may support dynamic detection of new devices.


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