[libcamera-devel,11/11] libcamera: v4l2device: update Buffer with information from v4l2_buffer when dequeueing

Message ID 20190203110102.5663-12-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: V4L2 Streams
Related show

Commit Message

Kieran Bingham Feb. 3, 2019, 11:01 a.m. UTC
From: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Copy the information from the struct v4l2_buffer when dequeueing the
buffer as applications need this information to make sens of the
captured data.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

[Kieran: Re-adapt to use the V4L2Buffer class casting]
---
 include/libcamera/buffer.h          | 12 ++++++++++++
 src/libcamera/include/v4l2_device.h |  2 ++
 src/libcamera/v4l2_device.cpp       | 17 ++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

Patch

diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
index 97fab5c65cce..b4dd0851bc7f 100644
--- a/include/libcamera/buffer.h
+++ b/include/libcamera/buffer.h
@@ -7,6 +7,7 @@ 
 #ifndef __LIBCAMERA_BUFFER_H__
 #define __LIBCAMERA_BUFFER_H__
 
+#include <sys/time.h>
 #include <vector>
 
 namespace libcamera {
@@ -46,8 +47,19 @@  public:
 	unsigned int index() const { return index_; };
 	const std::vector<Plane *> &planes() { return planes_; };
 
+	unsigned int bytesused() const { return bytesused_; };
+	unsigned int flags() const { return flags_; };
+	unsigned int field() const { return field_; };
+	struct timeval timestamp() const { return timestamp_; };
+	unsigned int sequence() const { return sequence_; };
+
 protected:
 	unsigned int index_;
+	unsigned int bytesused_;
+	unsigned int flags_;
+	unsigned int field_;
+	struct timeval timestamp_;
+	unsigned int sequence_;
 
 	unsigned int format_;
 	unsigned int width_;
diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h
index fbbddad68082..641362ff594c 100644
--- a/src/libcamera/include/v4l2_device.h
+++ b/src/libcamera/include/v4l2_device.h
@@ -61,6 +61,8 @@  class V4L2Buffer : public Buffer
 {
 public:
 	V4L2Buffer(struct v4l2_buffer &vb);
+
+	void update(struct v4l2_buffer &vb);
 };
 
 class V4L2DeviceFormat
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 630b43532c3e..7fafe2af393d 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -9,6 +9,7 @@ 
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <sys/time.h>
 #include <unistd.h>
 #include <vector>
 
@@ -111,6 +112,16 @@  V4L2Buffer::V4L2Buffer(struct v4l2_buffer &vb)
 	}
 }
 
+void V4L2Buffer::update(struct v4l2_buffer &vb)
+{
+	/* Update buffer information */
+	bytesused_ = vb.bytesused;
+	flags_ = vb.flags;
+	field_ = vb.field;
+	timestamp_ = vb.timestamp;
+	sequence_ = vb.sequence;
+}
+
 /**
  * \class V4L2DeviceFormat
  * \brief The V4L2 device image format and sizes
@@ -673,7 +684,11 @@  Buffer *V4L2Device::dequeueBuffer()
 		return nullptr;
 	}
 
-	return bufferPool_->buffers()[buf.index];
+	V4L2Buffer *b;
+	b = reinterpret_cast<V4L2Buffer *>(bufferPool_->buffers()[buf.index]);
+	b->update(buf);
+
+	return b;
 }
 
 /**