libcamera::Camera Class Referencefinal

Camera device. More...

Inheritance diagram for libcamera::Camera:

## Classes

class | Private

## Public Member Functions

| Camera (const Camera &)=delete
Camera & | operator= (const Camera &)=delete
const std::string & | name () const
| Retrieve the name of the camera. More...
int | acquire ()
| Acquire the camera device for exclusive access. More...
int | release ()
| Release exclusive access to the camera device. More...
const ControlInfoMap & | controls ()
| Retrieve the list of controls supported by the camera. More...
const ControlList & | properties ()
| Retrieve the list of properties of the camera. More...
const std::set< Stream * > & | streams () const
| Retrieve all the camera's stream information. More...
std::unique_ptr< CameraConfiguration > | generateConfiguration (const StreamRoles &roles)
| Generate a default camera configuration according to stream roles. More...
int | configure (CameraConfiguration *config)
| Configure the camera prior to capture. More...
Request * | createRequest (uint64_t cookie=0)
| Create a request object for the camera. More...
int | queueRequest (Request *request)
| Queue a request to the camera. More...
int | start ()
| Start capture from camera. More...
int | stop ()
| Stop capture from camera. More...

## Static Public Member Functions

static std::shared_ptr< Camera > | create (PipelineHandler *pipe, const std::string &name, const std::set< Stream * > &streams)
| Create a camera instance. More...

## Public Attributes

Signal< Request *, FrameBuffer * > | bufferCompleted
| Signal emitted when a buffer for a request queued to the camera has completed.
Signal< Request * > | requestCompleted
| Signal emitted when a request queued to the camera has completed.
Signal< Camera * > | disconnected
| Signal emitted when the camera is disconnected from the system. More...

## Friends

class | PipelineHandler
class | FrameBufferAllocator

## Detailed Description

Camera device.

Todo:
  Add documentation for camera start timings. What exactly does the camera expect the pipeline handler to do when start() is called?

The Camera class models a camera capable of producing one or more image streams from a single image source. It provides the main interface to configuring and controlling the device, and capturing image streams. It is the central object exposed by libcamera.

To support the central nature of Camera objects, libcamera manages the lifetime of camera instances with std::shared_ptr<>. Instances shall be created with the create() function which returns a shared pointer. The Camera constructors and destructor are private, to prevent instances from being constructed and destroyed manually.

# Operating the Camera

An application needs to perform a sequence of operations on a camera before it is ready to process requests. The camera needs to be acquired and configured to prepare the camera for capture. Once started the camera can process requests until it is stopped. When an application is done with a camera, the camera needs to be released.

An application may start and stop a camera multiple times as long as it is not released. The camera may also be reconfigured.

Functions that affect the camera state as defined below are generally not synchronized with each other by the Camera class. The caller is responsible for ensuring their synchronization if necessary.

## States

To help manage the sequence of operations needed to control the camera a set of states are defined. Each state describes which operations may be performed on the camera. Performing an operation not allowed in the camera state results in undefined behaviour. Operations not listed at all in the state diagram are allowed in all states.

### Available

The base state of a camera, an application can inspect the properties of the camera to determine if it wishes to use it. If an application wishes to use a camera it should acquire() it to proceed to the Acquired state.

### Acquired

In the acquired state an application has exclusive access to the camera and may modify the camera's parameters to configure it and proceed to the Configured state.

### Configured

The camera is configured and ready to be started. The application may release() the camera and to get back to the Available state or start() it to progress to the Running state.

### Running

The camera is running and ready to process requests queued by the application. The camera remains in this state until it is stopped and moved to the Configured state.

## Member Function Documentation

## acquire()

int libcamera::Camera::acquire | ( |  | ) |

Acquire the camera device for exclusive access.

After opening the device with open(), exclusive access must be obtained before performing operations that change the device state. This function is not blocking, if the device has already been acquired (by the same or another process) the -EBUSY error code is returned.

Acquiring a camera will limit usage of any other camera(s) provided by the same pipeline handler to the same instance of libcamera. The limit is in effect until all cameras from the pipeline handler are released. Other instances of libcamera can still list and examine the cameras but will fail if they attempt to acquire() any of them.

Once exclusive access isn't needed anymore, the device should be released with a call to the release() function.

Thread Safety:
  This function is thread-safe. It may only be called when the camera is in the Available state as defined in Operating the Camera.

Returns
  0 on success or a negative error code otherwise

Return values

  -ENODEV | The camera has been disconnected from the system
  -EBUSY | The camera is not free and can't be acquired by the caller

## configure()

int libcamera::Camera::configure | ( | CameraConfiguration * | config | ) |

Configure the camera prior to capture.

Parameters

  [in] | config | The camera configurations to setup

Prior to starting capture, the camera must be configured to select a group of streams to be involved in the capture and their configuration. The caller specifies which streams are to be involved and their configuration by populating config.

The configuration is created by generateConfiguration(), and adjusted by the caller with CameraConfiguration::validate(). This method only accepts fully valid configurations and returns an error if config is not valid.

Exclusive access to the camera shall be ensured by a call to acquire() prior to calling this function, otherwise an -EACCES error will be returned.

Thread Safety:
  This function may only be called when the camera is in the Acquired or Configured state as defined in Operating the Camera, and shall be synchronized by the caller with other functions that affect the camera state.

Upon return the StreamConfiguration entries in config are associated with Stream instances which can be retrieved with StreamConfiguration::stream().

Returns
  0 on success or a negative error code otherwise

Return values

  -ENODEV | The camera has been disconnected from the system
  -EACCES | The camera is not in a state where it can be configured
  -EINVAL | The configuration is not valid

## controls()

const ControlInfoMap & libcamera::Camera::controls | ( |  | ) |

Retrieve the list of controls supported by the camera.

The list of controls supported by the camera and their associated constraints remain constant through the lifetime of the Camera object.

Thread Safety:
  This function is thread-safe.

Returns
  A ControlInfoMap listing the controls supported by the camera

## create()

std::shared_ptr< Camera > libcamera::Camera::create | ( | PipelineHandler * | pipe,
|  | const std::string & | name,
|  | const std::set< Stream * > & | streams
| ) |  |

static

Create a camera instance.

Parameters

  [in] | pipe | The pipeline handler responsible for the camera device
  [in] | name | The name of the camera device
  [in] | streams | Array of streams the camera provides

The caller is responsible for guaranteeing unicity of the camera name.

Returns
  A shared pointer to the newly created camera object

## createRequest()

Request * libcamera::Camera::createRequest | ( | uint64_t | cookie = `0` | ) |

Create a request object for the camera.

Parameters

  [in] | cookie | Opaque cookie for application use

This method creates an empty request for the application to fill with buffers and parameters, and queue for capture.

The cookie is stored in the request and is accessible through the Request::cookie() method at any time. It is typically used by applications to map the request to an external resource in the request completion handler, and is completely opaque to libcamera.

The ownership of the returned request is passed to the caller, which is responsible for either queueing the request or deleting it.

Thread Safety:
  This function is thread-safe. It may only be called when the camera is in the Configured or Running state as defined in Operating the Camera.

Returns
  A pointer to the newly created request, or nullptr on error

## generateConfiguration()

std::unique_ptr< CameraConfiguration > libcamera::Camera::generateConfiguration | ( | const StreamRoles & | roles | ) |

Generate a default camera configuration according to stream roles.

Parameters

  [in] | roles | A list of stream roles

Generate a camera configuration for a set of desired stream roles. The caller specifies a list of stream roles and the camera returns a configuration containing suitable streams and their suggested default configurations. An empty list of roles is valid, and will generate an empty configuration that can be filled by the caller.

Thread Safety:
  This function is thread-safe.

Returns
  A CameraConfiguration if the requested roles can be satisfied, or a null pointer otherwise. The ownership of the returned configuration is passed to the caller.

## name()

const std::string & libcamera::Camera::name | ( |  | ) | const

Retrieve the name of the camera.

Thread Safety:
  This function is thread-safe.

Returns
  Name of the camera device

## properties()

const ControlList & libcamera::Camera::properties | ( |  | ) |

Retrieve the list of properties of the camera.

Camera properties are static information that describe the capabilities of the camera. They remain constant through the lifetime of the Camera object.

Returns
  A ControlList of properties supported by the camera

## queueRequest()

int libcamera::Camera::queueRequest | ( | Request * | request | ) |

Queue a request to the camera.

Parameters

  [in] | request | The request to queue to the camera

This method queues a request to the camera for capture.

After allocating the request with createRequest(), the application shall fill it with at least one capture buffer before queuing it. Requests that contain no buffers are invalid and are rejected without being queued.

Once the request has been queued, the camera will notify its completion through the requestCompleted signal.

Ownership of the request is transferred to the camera. It will be deleted automatically after it completes.

Thread Safety:
  This function is thread-safe. It may only be called when the camera is in the Running state as defined in Operating the Camera.

Returns
  0 on success or a negative error code otherwise

Return values

  -ENODEV | The camera has been disconnected from the system
  -EACCES | The camera is not running so requests can't be queued
  -EINVAL | The request is invalid
  -ENOMEM | No buffer memory was available to handle the request

## release()

int libcamera::Camera::release | ( |  | ) |

Release exclusive access to the camera device.

Releasing the camera device allows other users to acquire exclusive access with the acquire() function.

Thread Safety:
  This function may only be called when the camera is in the Available or Configured state as defined in Operating the Camera, and shall be synchronized by the caller with other functions that affect the camera state.

Returns
  0 on success or a negative error code otherwise

Return values

  -EBUSY | The camera is running and can't be released

## start()

int libcamera::Camera::start | ( |  | ) |

Start capture from camera.

Start the camera capture session. Once the camera is started the application can queue requests to the camera to process and return to the application until the capture session is terminated with stop().

Thread Safety:
  This function may only be called when the camera is in the Configured state as defined in Operating the Camera, and shall be synchronized by the caller with other functions that affect the camera state.

Returns
  0 on success or a negative error code otherwise

Return values

  -ENODEV | The camera has been disconnected from the system
  -EACCES | The camera is not in a state where it can be started

## stop()

int libcamera::Camera::stop | ( |  | ) |

Stop capture from camera.

This method stops capturing and processing requests immediately. All pending requests are cancelled and complete synchronously in an error state.

Thread Safety:
  This function may only be called when the camera is in the Running state as defined in Operating the Camera, and shall be synchronized by the caller with other functions that affect the camera state.

Returns
  0 on success or a negative error code otherwise

Return values

  -ENODEV | The camera has been disconnected from the system
  -EACCES | The camera is not running so can't be stopped

## streams()

const std::set< Stream * > & libcamera::Camera::streams | ( |  | ) | const

Retrieve all the camera's stream information.

Retrieve all of the camera's static stream information. The static information describes among other things how many streams the camera supports and the capabilities of each stream.

Thread Safety:
  This function is thread-safe.

Returns
  An array of all the camera's streams

## Member Data Documentation

## disconnected

libcamera::Camera::disconnected

Signal emitted when the camera is disconnected from the system.

This signal is emitted when libcamera detects that the camera has been removed from the system. For hot-pluggable devices this is usually caused by physical device disconnection. The media device is passed as a parameter.

As soon as this signal is emitted the camera instance will refuse all new application API calls by returning errors immediately.

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

- include/libcamera/camera.h
- src/libcamera/camera.cpp