libcamera
v0.3.1+12-19bbca3c
Supporting cameras in Linux since 2019
|
Hot cache of associations between V4L2 buffer indexes and FrameBuffer. More...
Public Member Functions | |
V4L2BufferCache (unsigned int numEntries) | |
Create an empty cache with numEntries entries. More... | |
V4L2BufferCache (const std::vector< std::unique_ptr< FrameBuffer >> &buffers) | |
Create a pre-populated cache. More... | |
bool | isEmpty () const |
Check if all the entries in the cache are unused. | |
int | get (const FrameBuffer &buffer) |
Find the best V4L2 buffer for a FrameBuffer. More... | |
void | put (unsigned int index) |
Mark buffer index as free in the cache. More... | |
Hot cache of associations between V4L2 buffer indexes and FrameBuffer.
When importing buffers, V4L2 performs lazy mapping of dmabuf instances at VIDIOC_QBUF (or VIDIOC_PREPARE_BUF) time and keeps the mapping associated with the V4L2 buffer, as identified by its index. If the same V4L2 buffer is then reused and queued with different dmabufs, the old dmabufs will be unmapped and the new ones mapped. To keep this process efficient, it is crucial to consistently use the same V4L2 buffer for given dmabufs through the whole duration of a capture cycle.
The V4L2BufferCache class keeps a map of previous dmabufs to V4L2 buffer index associations to help selecting V4L2 buffers. It tracks, for every entry, if the V4L2 buffer is in use, and offers lookup of the best free V4L2 buffer for a set of dmabufs.
libcamera::V4L2BufferCache::V4L2BufferCache | ( | unsigned int | numEntries | ) |
Create an empty cache with numEntries entries.
[in] | numEntries | Number of entries to reserve in the cache |
Create a cache with numEntries entries all marked as unused. The entries will be populated as the cache is used. This is typically used to implement buffer import, with buffers added to the cache as they are queued.
libcamera::V4L2BufferCache::V4L2BufferCache | ( | const std::vector< std::unique_ptr< FrameBuffer >> & | buffers | ) |
Create a pre-populated cache.
[in] | buffers | Array of buffers to pre-populated with |
Create a cache pre-populated with buffers. This is typically used to implement buffer export, with all buffers added to the cache when they are allocated.
int libcamera::V4L2BufferCache::get | ( | const FrameBuffer & | buffer | ) |
Find the best V4L2 buffer for a FrameBuffer.
[in] | buffer | The FrameBuffer |
Find the best V4L2 buffer index to be used for the FrameBuffer buffer based on previous mappings of frame buffers to V4L2 buffers. If a free V4L2 buffer previously used with the same dmabufs as buffer is found in the cache, return its index. Otherwise return the index of the first free V4L2 buffer and record its association with the dmabufs of buffer.
void libcamera::V4L2BufferCache::put | ( | unsigned int | index | ) |
Mark buffer index as free in the cache.
[in] | index | The V4L2 buffer index |