libcamera
v0.3.2+116-83c5ad0f
Supporting cameras in Linux since 2019
|
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... | |
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.
libcamera::FrameBufferAllocator::FrameBufferAllocator | ( | std::shared_ptr< Camera > | camera | ) |
Construct a FrameBufferAllocator serving a camera.
[in] | camera | The camera |
int libcamera::FrameBufferAllocator::allocate | ( | Stream * | stream | ) |
Allocate buffers for a configured stream.
[in] | stream | The 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.
-EACCES | The camera is not in a state where buffers can be allocated |
-EINVAL | The stream does not belong to the camera or the stream is not part of the active camera configuration |
-EBUSY | Buffers are already allocated for the stream |
|
inline |
Check if the allocator has allocated buffers for any stream.
const std::vector< std::unique_ptr< FrameBuffer > > & libcamera::FrameBufferAllocator::buffers | ( | Stream * | stream | ) | const |
Retrieve the buffers allocated for a stream.
[in] | stream | The 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.
int libcamera::FrameBufferAllocator::free | ( | Stream * | stream | ) |
Free buffers previously allocated for a stream.
[in] | stream | The stream |
Free buffers allocated with allocate().
This invalidates the buffers returned by buffers().
-EACCES | The camera is not in a state where buffers can be freed |
-EINVAL | The allocator do not handle the stream |