summaryrefslogtreecommitdiff
path: root/src/libcamera/include
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-10-28 00:21:48 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-01-12 16:10:37 +0100
commit9e71540ebbde3592805aff0e2e26803406b2e15c (patch)
tree56e70619cb6f0157ef15276325259a91c42cae07 /src/libcamera/include
parent5967363c0b99a59f3526c51917572b807324e389 (diff)
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>
Diffstat (limited to 'src/libcamera/include')
-rw-r--r--src/libcamera/include/v4l2_videodevice.h45
1 files changed, 42 insertions, 3 deletions
diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h
index 27ec77cd..9d22754a 100644
--- a/src/libcamera/include/v4l2_videodevice.h
+++ b/src/libcamera/include/v4l2_videodevice.h
@@ -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: