[libcamera-devel,v2,4/8] libcamera: v4l2_device: Support queueing buffers to an output device

Message ID 20190213151027.6376-5-kieran.bingham@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: v4l2_device buffer sharing
Related show

Commit Message

Kieran Bingham Feb. 13, 2019, 3:10 p.m. UTC
To queue a buffer to an output device, we must set the buffer properties.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/v4l2_device.cpp | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart Feb. 13, 2019, 3:44 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Wed, Feb 13, 2019 at 03:10:23PM +0000, Kieran Bingham wrote:
> To queue a buffer to an output device, we must set the buffer properties.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/libcamera/v4l2_device.cpp | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 83073c28b817..8c038239cf24 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -299,7 +299,15 @@ int V4L2Device::open()
>  			    ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
>  			    : V4L2_BUF_TYPE_VIDEO_OUTPUT;
>  
> -	fdEvent_ = new EventNotifier(fd_, EventNotifier::Read);
> +	/*
> +	 *  We wait for Read notifications on CAPTURE devices (POLLIN), and
> +	 *  Write notifications for OUTPUT devices (POLLOUT).
> +	 */
> +	if (caps_.isCapture())
> +		fdEvent_ = new EventNotifier(fd_, EventNotifier::Read);
> +	else
> +		fdEvent_ = new EventNotifier(fd_, EventNotifier::Write);
> +
>  	fdEvent_->activated.connect(this, &V4L2Device::bufferAvailable);
>  	fdEvent_->setEnabled(false);
>  
> @@ -679,6 +687,15 @@ int V4L2Device::queueBuffer(Buffer *buffer)
>  		buf.m.planes = planes;
>  	}
>  
> +	if (V4L2_TYPE_IS_OUTPUT(bufferType_)) {
> +		buf.bytesused = buffer->bytesused_;
> +		buf.sequence = buffer->sequence_;
> +		/**
> +		 * \todo: Timestamp should be converted back to a struct
> +		 * timeval for passing back into V4L2.
> +		 */
		buf.timestamp.tv_sec = buffer->timestamp / 1000000000;
		buf.timestamp.tv_usec = (buffer->timestamp / 1000) % 1000000;

With this,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +	}
> +
>  	LOG(V4L2, Debug) << "Queueing buffer " << buf.index;
>  
>  	ret = ioctl(fd_, VIDIOC_QBUF, &buf);

Patch

diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 83073c28b817..8c038239cf24 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -299,7 +299,15 @@  int V4L2Device::open()
 			    ? V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
 			    : V4L2_BUF_TYPE_VIDEO_OUTPUT;
 
-	fdEvent_ = new EventNotifier(fd_, EventNotifier::Read);
+	/*
+	 *  We wait for Read notifications on CAPTURE devices (POLLIN), and
+	 *  Write notifications for OUTPUT devices (POLLOUT).
+	 */
+	if (caps_.isCapture())
+		fdEvent_ = new EventNotifier(fd_, EventNotifier::Read);
+	else
+		fdEvent_ = new EventNotifier(fd_, EventNotifier::Write);
+
 	fdEvent_->activated.connect(this, &V4L2Device::bufferAvailable);
 	fdEvent_->setEnabled(false);
 
@@ -679,6 +687,15 @@  int V4L2Device::queueBuffer(Buffer *buffer)
 		buf.m.planes = planes;
 	}
 
+	if (V4L2_TYPE_IS_OUTPUT(bufferType_)) {
+		buf.bytesused = buffer->bytesused_;
+		buf.sequence = buffer->sequence_;
+		/**
+		 * \todo: Timestamp should be converted back to a struct
+		 * timeval for passing back into V4L2.
+		 */
+	}
+
 	LOG(V4L2, Debug) << "Queueing buffer " << buf.index;
 
 	ret = ioctl(fd_, VIDIOC_QBUF, &buf);