libcamera  v0.0.0+3174-88a90ba2
Supporting cameras in Linux since 2019
Public Member Functions | List of all members
libcamera::FrameBufferAllocator Class Reference

FrameBuffer allocator for applications. More...

Public Member Functions

 FrameBufferAllocator (std::shared_ptr< Camera > camera)
 Construct a FrameBufferAllocator serving a camera. More...
 
int allocate (Stream *stream)
 Allocate buffers for a configured stream. More...
 
int free (Stream *stream)
 Free buffers previously allocated for a stream. More...
 
bool allocated () const
 Check if the allocator has allocated buffers for any stream. More...
 
const std::vector< std::unique_ptr< FrameBuffer > > & buffers (Stream *stream) const
 Retrieve the buffers allocated for a stream. More...
 

Detailed Description

FrameBuffer allocator for applications.

The libcamera API is designed to consume buffers provided by applications as FrameBuffer instances. This makes libcamera a user of buffers exported by other devices (such as displays or video encoders), or allocated from an external allocator (such as ION on Android platforms). In some situations, applications do not have any means to allocate or get hold of suitable buffers, for instance when no other device is involved, on Linux platforms that lack a centralized allocator. The FrameBufferAllocator class provides a buffer allocator that can be used in these situations.

Applications create a framebuffer allocator for a Camera, and use it to allocate buffers for streams of a CameraConfiguration with allocate(). They control which streams to allocate buffers for, and can thus use external buffers for a subset of the streams if desired.

Buffers are deleted for a stream with free(), and destroying the allocator automatically deletes all allocated buffers. Applications own the buffers allocated by the FrameBufferAllocator and are responsible for ensuring the buffers are not deleted while they are in use (part of a Request that has been queued and hasn't completed yet).

Usage of the FrameBufferAllocator is optional, if all buffers for a camera are provided externally applications shall not use this class.

Constructor & Destructor Documentation

◆ FrameBufferAllocator()

libcamera::FrameBufferAllocator::FrameBufferAllocator ( std::shared_ptr< Camera camera)

Construct a FrameBufferAllocator serving a camera.

Parameters
[in]cameraThe camera

Member Function Documentation

◆ allocate()

int libcamera::FrameBufferAllocator::allocate ( Stream stream)

Allocate buffers for a configured stream.

Parameters
[in]streamThe stream to allocate buffers for

Allocate buffers suitable for capturing frames from the stream. The Camera shall have been previously configured with Camera::configure() and shall be stopped, and the stream shall be part of the active camera configuration.

Upon successful allocation, the allocated buffers can be retrieved with the buffers() function.

Returns
The number of allocated buffers on success or a negative error code otherwise
Return values
-EACCESThe camera is not in a state where buffers can be allocated
-EINVALThe stream does not belong to the camera or the stream is not part of the active camera configuration
-EBUSYBuffers are already allocated for the stream

◆ allocated()

libcamera::FrameBufferAllocator::allocated ( ) const
inline

Check if the allocator has allocated buffers for any stream.

Returns
True if the allocator has allocated buffers for one or more streams, false otherwise

◆ buffers()

const std::vector< std::unique_ptr< FrameBuffer > > & libcamera::FrameBufferAllocator::buffers ( Stream stream) const

Retrieve the buffers allocated for a stream.

Parameters
[in]streamThe stream to retrieve buffers for

This function shall only be called after successfully allocating buffers for stream with allocate(). The returned buffers are valid until free() is called for the same stream or the FrameBufferAllocator instance is destroyed.

Returns
The buffers allocated for the stream

◆ free()

int libcamera::FrameBufferAllocator::free ( Stream stream)

Free buffers previously allocated for a stream.

Parameters
[in]streamThe stream

Free buffers allocated with allocate().

This invalidates the buffers returned by buffers().

Returns
0 on success or a negative error code otherwise
Return values
-EACCESThe camera is not in a state where buffers can be freed
-EINVALThe allocator do not handle the stream

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