libcamera::CameraManager Class Reference

Provide access and manage all cameras in the system. More...

Inheritance diagram for libcamera::CameraManager:

## Classes

class | Private

## Public Member Functions

| CameraManager (const CameraManager &)=delete
CameraManager & | operator= (const CameraManager &)=delete
int | start ()
| Start the camera manager. More...
void | stop ()
| Stop the camera manager. More...
std::vector< std::shared_ptr< Camera > > | cameras () const
| Retrieve all available cameras. More...
std::shared_ptr< Camera > | get (const std::string &name)
| Get a camera based on name. More...
std::shared_ptr< Camera > | get (dev_t devnum)
| Retrieve a camera based on device number. More...
void | addCamera (std::shared_ptr< Camera > camera, const std::vector< dev_t > &devnums)
| Add a camera to the camera manager. More...
void | removeCamera (std::shared_ptr< Camera > camera)
| Remove a camera from the camera manager. More...
void | setEventDispatcher (std::unique_ptr< EventDispatcher > dispatcher)
| Set the event dispatcher. More...
EventDispatcher * | eventDispatcher ()
| Retrieve the event dispatcher. More...
Public Member Functions inherited from libcamera::Object
| Object (Object *parent=nullptr)
| Construct an Object instance. More...
virtual | ~Object ()
| Destroy an Object instance. More...
void | postMessage (std::unique_ptr< Message > msg)
| Post a message to the object's thread. More...
template<typename T , typename R , typename... FuncArgs, typename... Args, typename std::enable_if_t< std::is_base_of< Object, T >::value > * = nullptr>
R | invokeMethod (R(T::*func)(FuncArgs...), ConnectionType type, Args... args)
| Invoke a method asynchronously on an Object instance. More...
Thread * | thread () const
| Retrieve the thread the object is bound to. More...
void | moveToThread (Thread *thread)
| Move the object and all its children to a different thread. More...
Object * | parent () const
| Retrieve the object's parent. More...

## Static Public Member Functions

static const std::string & | version ()
| Retrieve the libcamera version string. More...

## Public Attributes

Signal< std::shared_ptr< Camera > > | cameraAdded
| Notify of a new camera added to the system. More...
Signal< std::shared_ptr< Camera > > | cameraRemoved
| Notify of a new camera removed from the system. More...

## Additional Inherited Members

Protected Member Functions inherited from libcamera::Object
virtual void | message (Message *msg)
| Message handler for the object. More...

## Detailed Description

Provide access and manage all cameras in the system.

The camera manager is the entry point to libcamera. It enumerates devices, associates them with pipeline managers, and provides access to the cameras in the system to applications. The manager owns all Camera objects and handles hot-plugging and hot-unplugging to manage the lifetime of cameras.

To interact with libcamera, an application starts by creating a camera manager instance. Only a single instance of the camera manager may exist at a time. Attempting to create a second instance without first deleting the existing instance results in undefined behaviour.

The manager is initially stopped, and shall be configured before being started. In particular a custom event dispatcher shall be installed if needed with CameraManager::setEventDispatcher().

Once the camera manager is configured, it shall be started with start(). This will enumerate all the cameras present in the system, which can then be listed with list() and retrieved with get().

Cameras are shared through std::shared_ptr<>, ensuring that a camera will stay valid until the last reference is released without requiring any special action from the application. Once the application has released all the references it held to cameras, the camera manager can be stopped with stop().

Todo:
  Add interface to register a notification callback to the user to be able to inform it new cameras have been hot-plugged or cameras have been removed due to hot-unplug.

## Member Function Documentation

## addCamera()

void libcamera::CameraManager::addCamera | ( | std::shared_ptr< Camera > | camera,
|  | const std::vector< dev_t > & | devnums
| ) |  |

Add a camera to the camera manager.

Parameters

  [in] | camera | The camera to be added
  [in] | devnums | The device numbers to associate with camera

This function is called by pipeline handlers to register the cameras they handle with the camera manager. Registered cameras are immediately made available to the system.

devnums are used by the V4L2 compatibility layer to map V4L2 device nodes to Camera instances.

Thread Safety:
  This function shall be called from the CameraManager thread.

## cameras()

std::vector< std::shared_ptr< Camera > > libcamera::CameraManager::cameras | ( |  | ) | const

Retrieve all available cameras.

Before calling this function the caller is responsible for ensuring that the camera manager is running.

Thread Safety:
  This function is thread-safe.

Returns
  List of all available cameras

## eventDispatcher()

EventDispatcher * libcamera::CameraManager::eventDispatcher | ( |  | ) |

Retrieve the event dispatcher.

This function retrieves the event dispatcher set with setEventDispatcher(). If no dispatcher has been set, a default poll-based implementation is created and returned, and no custom event dispatcher may be installed anymore.

The returned event dispatcher is valid until the camera manager is destroyed.

Returns
  Pointer to the event dispatcher

## get() [1/2]

std::shared_ptr< Camera > libcamera::CameraManager::get | ( | const std::string & | name | ) |

Get a camera based on name.

Parameters

  [in] | name | Name of camera to get

Before calling this function the caller is responsible for ensuring that the camera manager is running.

Thread Safety:
  This function is thread-safe.

Returns
  Shared pointer to Camera object or nullptr if camera not found

## get() [2/2]

std::shared_ptr< Camera > libcamera::CameraManager::get | ( | dev_t | devnum | ) |

Retrieve a camera based on device number.

Parameters

  [in] | devnum | Device number of camera to get

This method is meant solely for the use of the V4L2 compatibility layer, to map device nodes to Camera instances. Applications shall not use it and shall instead retrieve cameras by name.

Before calling this function the caller is responsible for ensuring that the camera manager is running.

Thread Safety:
  This function is thread-safe.

Returns
  Shared pointer to Camera object, which is empty if the camera is not found

## removeCamera()

void libcamera::CameraManager::removeCamera | ( | std::shared_ptr< Camera > | camera | ) |

Remove a camera from the camera manager.

Parameters

  [in] | camera | The camera to be removed

This function is called by pipeline handlers to unregister cameras from the camera manager. Unregistered cameras won't be reported anymore by the cameras() and get() calls, but references may still exist in applications.

Thread Safety:
  This function shall be called from the CameraManager thread.

## setEventDispatcher()

void libcamera::CameraManager::setEventDispatcher | ( | std::unique_ptr< EventDispatcher > | dispatcher | ) |

Set the event dispatcher.

Parameters

  [in] | dispatcher | Pointer to the event dispatcher

libcamera requires an event dispatcher to integrate event notification and timers with the application event loop. Applications that want to provide their own event dispatcher shall call this function once and only once before the camera manager is started with start(). If no event dispatcher is provided, a default poll-based implementation will be used.

The CameraManager takes ownership of the event dispatcher and will delete it when the application terminates.

## start()

int libcamera::CameraManager::start | ( |  | ) |

Start the camera manager.

Start the camera manager and enumerate all devices in the system. Once the start has been confirmed the user is free to list and otherwise interact with cameras in the system until either the camera manager is stopped or the camera is unplugged from the system.

Returns
  0 on success or a negative error code otherwise

## stop()

void libcamera::CameraManager::stop | ( |  | ) |

Stop the camera manager.

Before stopping the camera manager the caller is responsible for making sure all cameras provided by the manager are returned to the manager.

After the manager has been stopped no resource provided by the camera manager should be consider valid or functional even if they for one reason or another have yet to be deleted.

## version()

const std::string & libcamera::CameraManager::version | ( |  | ) |

inline static

Retrieve the libcamera version string.

Thread Safety:
  This function is threadsafe.

Returns
  The libcamera version string

## Member Data Documentation

## cameraAdded

libcamera::CameraManager::cameraAdded

Notify of a new camera added to the system.

This signal is emitted when a new camera is detected and successfully handled by the camera manager. The notification occurs alike for cameras detected when the manager is started with start() or when new cameras are later connected to the system. When the signal is emitted the new camera is already available from the list of cameras().

The signal is emitted from the CameraManager thread. Applications shall minimize the time spent in the signal handler and shall in particular not perform any blocking operation.

## cameraRemoved

libcamera::CameraManager::cameraRemoved

Notify of a new camera removed from the system.

This signal is emitted when a camera is removed from the system. When the signal is emitted the camera is not available from the list of cameras() anymore.

The signal is emitted from the CameraManager thread. Applications shall minimize the time spent in the signal handler and shall in particular not perform any blocking operation.

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

- include/libcamera/camera_manager.h
- src/libcamera/camera_manager.cpp
- obj-x86_64-linux-gnu/src/libcamera/version.cpp