libcamera
v0.3.2+116-83c5ad0f
Supporting cameras in Linux since 2019
|
Classes | |
class | Private |
Base class for camera private data. More... | |
Public Member Functions | |
const std::string & | id () const |
Retrieve the ID 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 () const |
Retrieve the list of controls supported by the camera. More... | |
const ControlList & | properties () const |
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 (Span< const StreamRole > roles={}) |
Generate a default camera configuration according to stream roles. More... | |
std::unique_ptr< CameraConfiguration > | generateConfiguration (std::initializer_list< StreamRole > roles) |
int | configure (CameraConfiguration *config) |
Configure the camera prior to capture. More... | |
std::unique_ptr< 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 (const ControlList *controls=nullptr) |
Start capture from camera. More... | |
int | stop () |
Stop capture from camera. 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 | deleteLater () |
Schedule deletion of the instance in the thread it belongs to. 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, 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... | |
Public Member Functions inherited from libcamera::Extensible | |
Extensible (std::unique_ptr< Private > d) | |
Construct an instance of an Extensible class. More... | |
Static Public Member Functions | |
static std::shared_ptr< Camera > | create (std::unique_ptr< Private > d, const std::string &id, 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 | disconnected |
Signal emitted when the camera is disconnected from the system. More... | |
Friends | |
class | PipelineHandler |
class | FrameBufferAllocator |
Additional Inherited Members | |
Protected Member Functions inherited from libcamera::Object | |
virtual void | message (Message *msg) |
Message handler for the object. More... | |
bool | assertThreadBound (const char *message) |
Check if the caller complies with thread-bound constraints. More... | |
Protected Member Functions inherited from libcamera::Extensible | |
template<typename T > | |
const T * | _d () const |
Retrieve the private data instance. More... | |
template<typename T > | |
T * | _d () |
Retrieve the private data instance. More... | |
Camera device.
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.
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.
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.
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.
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.
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.
The camera has been asked to stop. Pending requests are being completed or cancelled, and no new requests are permitted to be queued. The camera will transition to the Configured state when all queued requests have been returned to the application.
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.
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 may 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.
-ENODEV | The camera has been disconnected from the system |
-EBUSY | The camera is not free and can't be acquired by the caller |
int libcamera::Camera::configure | ( | CameraConfiguration * | config | ) |
Configure the camera prior to capture.
[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 function 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.
Upon return the StreamConfiguration entries in config are associated with Stream instances which can be retrieved with StreamConfiguration::stream().
-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 |
const ControlInfoMap & libcamera::Camera::controls | ( | ) | const |
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.
|
static |
Create a camera instance.
[in] | d | Camera private data |
[in] | id | The ID of the camera device |
[in] | streams | Array of streams the camera provides |
The caller is responsible for guaranteeing a stable and unique camera ID matching the constraints described by Camera::id(). Parameters that are allocated dynamically at system startup, such as bus numbers that may be enumerated differently, are therefore not suitable to use in the ID.
Pipeline handlers that use a CameraSensor may use the CameraSensor::id() to generate an ID that satisfies the criteria of a stable and unique camera ID.
std::unique_ptr< Request > libcamera::Camera::createRequest | ( | uint64_t | cookie = 0 | ) |
Create a request object for the camera.
[in] | cookie | Opaque cookie for application use |
This function 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() function 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 deleting it. The request may be deleted in the completion handler, or reused after resetting its state with Request::reuse().
std::unique_ptr< CameraConfiguration > libcamera::Camera::generateConfiguration | ( | Span< const StreamRole > | roles = {} | ) |
Generate a default camera configuration according to stream roles.
[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.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
const std::string & libcamera::Camera::id | ( | ) | const |
Retrieve the ID of the camera.
The camera ID is a free-form string that identifies a camera in the system. IDs are guaranteed to be unique and stable: the same camera, when connected to the system in the same way (e.g. in the same USB port), will have the same ID across both unplug/replug and system reboots.
Applications may store the camera ID and use it later to acquire the same camera. They shall treat the ID as an opaque identifier, without interpreting its value.
Camera IDs may change when the system hardware or firmware is modified, for instance when replacing a PCI USB controller or moving it to another PCI slot, or updating the ACPI tables or Device Tree.
const ControlList & libcamera::Camera::properties | ( | ) | const |
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.
int libcamera::Camera::queueRequest | ( | Request * | request | ) |
Queue a request to the camera.
[in] | request | The request to queue to the camera |
This function 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.
-ENODEV | The camera has been disconnected from the system |
-EACCES | The camera is not running so requests can't be queued |
-EXDEV | The request does not belong to this camera |
-EINVAL | The request is invalid |
-ENOMEM | No buffer memory was available to handle the request |
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.
-EBUSY | The camera is running and can't be released |
int libcamera::Camera::start | ( | const ControlList * | controls = nullptr | ) |
Start capture from camera.
[in] | controls | Controls to be applied before starting the Camera |
Start the camera capture session, optionally providing a list of controls to apply before starting. 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().
-ENODEV | The camera has been disconnected from the system |
-EACCES | The camera is not in a state where it can be started |
int libcamera::Camera::stop | ( | ) |
Stop capture from camera.
This function stops capturing and processing requests immediately. All pending requests are cancelled and complete synchronously in an error state.
-ENODEV | The camera has been disconnected from the system |
-EACCES | The camera is not running so can't be stopped |
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.
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.