libcamera: v4l2_videodevice: Add V4L2BufferCache to deal with index mapping
In preparation for the FrameBuffer interface add a class that will deal with keeping the cache between dmabuf file descriptors and V4L2 video device buffer indexes. This initial implementation ensures that no hot association is lost while its eviction strategy could be improved in the future. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -11,7 +11,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
#include <memory>
|
||||
|
||||
#include <libcamera/buffer.h>
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/pixelformats.h>
|
||||
#include <libcamera/signal.h>
|
||||
@@ -22,9 +24,6 @@
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Buffer;
|
||||
class BufferMemory;
|
||||
class BufferPool;
|
||||
class EventNotifier;
|
||||
class FileDescriptor;
|
||||
class MediaDevice;
|
||||
@@ -106,6 +105,46 @@ struct V4L2Capability final : v4l2_capability {
|
||||
}
|
||||
};
|
||||
|
||||
class V4L2BufferCache
|
||||
{
|
||||
public:
|
||||
V4L2BufferCache(unsigned int numEntries);
|
||||
V4L2BufferCache(const std::vector<std::unique_ptr<FrameBuffer>> &buffers);
|
||||
~V4L2BufferCache();
|
||||
|
||||
int get(const FrameBuffer &buffer);
|
||||
void put(unsigned int index);
|
||||
|
||||
private:
|
||||
class Entry
|
||||
{
|
||||
public:
|
||||
Entry();
|
||||
Entry(bool free, const FrameBuffer &buffer);
|
||||
|
||||
bool operator==(const FrameBuffer &buffer);
|
||||
|
||||
bool free;
|
||||
|
||||
private:
|
||||
struct Plane {
|
||||
Plane(const FrameBuffer::Plane &plane)
|
||||
: fd(plane.fd.fd()), length(plane.length)
|
||||
{
|
||||
}
|
||||
|
||||
int fd;
|
||||
unsigned int length;
|
||||
};
|
||||
|
||||
std::vector<Plane> planes_;
|
||||
};
|
||||
|
||||
std::vector<Entry> cache_;
|
||||
/* \todo Expose the miss counter through an instrumentation API. */
|
||||
unsigned int missCounter_;
|
||||
};
|
||||
|
||||
class V4L2DeviceFormat
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user