Loading...
Searching...
No Matches
libcamera::V4L2BufferCache Class Reference

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.
| V4L2BufferCache (const std::vector< std::unique_ptr< FrameBuffer > > &buffers)
| Create a pre-populated cache.
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.
void | put (unsigned int index)
| Mark buffer index as free in the cache.

## Detailed Description

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.

## Constructor & Destructor Documentation

## V4L2BufferCache() [1/2]

libcamera::V4L2BufferCache::V4L2BufferCache | ( | unsigned int | numEntries | ) |

Create an empty cache with numEntries entries.

Parameters

  [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.

## V4L2BufferCache() [2/2]

libcamera::V4L2BufferCache::V4L2BufferCache | ( | const std::vector< std::unique_ptr< FrameBuffer > > & | buffers | ) |

Create a pre-populated cache.

Parameters

  [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.

## Member Function Documentation

## get()

int libcamera::V4L2BufferCache::get | ( | const FrameBuffer & | buffer | ) |

Find the best V4L2 buffer for a FrameBuffer.

Parameters

  [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.

Returns
  The index of the best V4L2 buffer, or -ENOENT if no free V4L2 buffer is available

## put()

void libcamera::V4L2BufferCache::put | ( | unsigned int | index | ) |

Mark buffer index as free in the cache.

Parameters

  [in] | index | The V4L2 buffer index

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

- include/libcamera/internal/v4l2_videodevice.h
- src/libcamera/v4l2_videodevice.cpp