[libcamera-devel] [PATCH 09/15] v4l2: v4l2_cammera_proxy: Reset buffer flags on streamoff when already off

Paul Elder paul.elder at ideasonboard.com
Tue Jun 16 15:12:38 CEST 2020


If VIDIOC_STREAMOFF is called when the stream is already off, just reset
the buffer status flags and return. Add a streaming flag to
V4L2CameraProxy to track the streaming status.

Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
 src/v4l2/v4l2_camera_proxy.cpp | 18 +++++++++++++++++-
 src/v4l2/v4l2_camera_proxy.h   |  1 +
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index fd2785f..63b4124 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -34,7 +34,8 @@ V4L2CameraProxy::V4L2CameraProxy(unsigned int index,
 				 std::shared_ptr<Camera> camera)
 	: refcount_(0), index_(index), bufferCount_(0), currentBuf_(0),
 	  vcam_(std::make_unique<V4L2Camera>(camera)), efd_(-1),
-	  v4l2RecordPriorityFd_(-1), acquiredFd_(-1), initialized_(false)
+	  v4l2RecordPriorityFd_(-1), acquiredFd_(-1), initialized_(false),
+	  streaming_(false)
 {
 	querycap(camera);
 }
@@ -628,6 +629,9 @@ int V4L2CameraProxy::vidioc_dqbuf(int fd, struct v4l2_buffer *arg)
 	if (arg == nullptr)
 		return -EFAULT;
 
+	if (!streaming_)
+		return -EINVAL;
+
 	int ret = lock(fd);
 	if (ret < 0)
 		return ret;
@@ -666,6 +670,9 @@ int V4L2CameraProxy::vidioc_streamon(int fd, int *arg)
 	if (arg == nullptr)
 		return -EFAULT;
 
+	if (streaming_)
+		return 0;
+
 	int ret = lock(fd);
 	if (ret < 0)
 		return ret;
@@ -674,6 +681,7 @@ int V4L2CameraProxy::vidioc_streamon(int fd, int *arg)
 		return -EINVAL;
 
 	currentBuf_ = 0;
+	streaming_ = true;
 
 	return vcam_->streamOn();
 }
@@ -685,6 +693,12 @@ int V4L2CameraProxy::vidioc_streamoff(int fd, int *arg)
 	if (arg == nullptr)
 		return -EFAULT;
 
+	if (!streaming_) {
+		for (unsigned int i = 0; i < bufferCount_; i++)
+			buffers_[i].flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE);
+		return 0;
+	}
+
 	int ret = lock(fd);
 	if (ret < 0)
 		return ret;
@@ -697,6 +711,8 @@ int V4L2CameraProxy::vidioc_streamoff(int fd, int *arg)
 	for (struct v4l2_buffer &buf : buffers_)
 		buf.flags &= ~(V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE);
 
+	streaming_ = false;
+
 	return ret;
 }
 
diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h
index 2ff9571..28b2fa0 100644
--- a/src/v4l2/v4l2_camera_proxy.h
+++ b/src/v4l2/v4l2_camera_proxy.h
@@ -103,6 +103,7 @@ private:
 	int acquiredFd_;
 
 	bool initialized_;
+	bool streaming_;
 };
 
 #endif /* __V4L2_CAMERA_PROXY_H__ */
-- 
2.27.0



More information about the libcamera-devel mailing list