[libcamera-devel] [PATCH 02/11] libcamera: buffer: Support v4l2_buffer construction
Kieran Bingham
kieran.bingham at ideasonboard.com
Sun Feb 3 12:00:53 CET 2019
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 at 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(-)
diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
index afe99d5c4ab0..e730fc0f84fd 100644
--- a/include/libcamera/buffer.h
+++ b/include/libcamera/buffer.h
@@ -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_;
diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp
index 887863b2af2e..c21994d7c035 100644
--- a/src/libcamera/buffer.cpp
+++ b/src/libcamera/buffer.cpp
@@ -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
diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index f68b2b1df525..9e9eada94130 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -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:
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 5c415d0bddbc..d507ea9700b3 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -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
--
2.19.1
More information about the libcamera-devel
mailing list