@@ -46,7 +46,7 @@ public:
unsigned int index() const { return index_; };
const std::vector<Plane *> &planes() { return planes_; };
-private:
+protected:
unsigned int index_;
unsigned int format_;
@@ -10,6 +10,8 @@
#include <sys/mman.h>
#include <unistd.h>
+#include <linux/videodev2.h>
+
#include <libcamera/buffer.h>
#include "log.h"
@@ -241,6 +243,31 @@ int Buffer::munmap()
* \brief Return a reference to the vector holding all Planes within the buffer
*/
+/**
+ * \enum Buffer::BufferType
+ * \brief Identify the type of buffer for derived types
+ *
+ * Buffers may be derived to support specific buffer type features on top of the
+ * generic interface. The BufferType is used internally to assert compatibility
+ * in the event of any generic Buffer object being upcast to a specific type.
+ */
+
+/**
+ * \var Buffer::BufferTypeGeneric
+ * \brief The Buffer can only be supported through the public Buffer API
+ */
+
+/**
+ * \var Buffer::BufferTypeV4L2
+ * \brief The Buffer can supported through both the public Buffer API and the
+ * internal V4L2 API.
+ */
+
+/**
+ * \var Buffer::type_
+ * \brief An internal BufferType to describe the construction of the Buffer.
+ */
+
/**
* \class BufferPool
* \brief A pool of buffers
@@ -11,6 +11,8 @@
#include <linux/videodev2.h>
+#include <libcamera/buffer.h>
+
namespace libcamera {
struct V4L2Capability final : v4l2_capability {
@@ -53,6 +55,12 @@ struct V4L2Capability final : v4l2_capability {
}
};
+class V4L2Buffer : public Buffer
+{
+public:
+ V4L2Buffer(struct v4l2_buffer &vb);
+};
+
class V4L2DeviceFormat
{
public:
@@ -80,6 +80,33 @@ LOG_DEFINE_CATEGORY(V4L2)
* \return True if the device provides Streaming I/O IOCTLs
*/
+/**
+ * \brief Construct a Buffer object from a v4l2_buffer description
+ *
+ * Buffers are abstracted in the same format regardless of using the single
+ * planar API or multi-planar API. The buffer object contains a Plane for each
+ * memory plane required to represent the buffer.
+ */
+V4L2Buffer::V4L2Buffer(struct v4l2_buffer &vb)
+ : Buffer()
+{
+ index_ = vb.index;
+
+ if (V4L2_TYPE_IS_MULTIPLANAR(vb.type)) {
+ unsigned int i;
+ for (i = 0; i < vb.length; ++i) {
+ /* TODO: dmaBuf should retrieve FD here */
+ Plane *plane = new Plane(vb.m.planes[i].length,
+ vb.m.planes[i].m.mem_offset);
+ planes_.push_back(plane);
+ }
+ } else {
+ /* TODO: dmaBuf should retrieve FD here */
+ Plane *plane = new Plane(vb.length, vb.m.offset);
+ planes_.push_back(plane);
+ }
+}
+
/**
* \class V4L2DeviceFormat
* \brief The V4L2 device image format and sizes
Provide a constructor to create a Buffer object directly from a v4l2_buffer as a V4L2Buffer type. This allows the Buffers to be created directly following a v4l2_reqbufs operation. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> --- include/libcamera/buffer.h | 2 +- src/libcamera/buffer.cpp | 27 +++++++++++++++++++++++++++ src/libcamera/include/v4l2_device.h | 8 ++++++++ src/libcamera/v4l2_device.cpp | 27 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-)