[libcamera-devel,v5,6/8] libcamera: v4l2_videodevice: Do not allow buffer queueing in stopping state
diff mbox series

Message ID 20220325090903.880311-7-naush@raspberrypi.com
State Accepted
Headers show
Series
  • Raspberry Pi: Efficient start/stop/start sequences
Related show

Commit Message

Naushir Patuck March 25, 2022, 9:09 a.m. UTC
If the device is in the process of being stopped (i.e. Stopping state), any
call to queueBuffer() must fail. This is to ensure the integrity of the buffer
queue, as it gets cleared at the end of streamOff.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/v4l2_videodevice.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Laurent Pinchart March 27, 2022, 11:09 p.m. UTC | #1
Hi Naush,

Thank you for the patch.

On Fri, Mar 25, 2022 at 09:09:01AM +0000, Naushir Patuck via libcamera-devel wrote:
> If the device is in the process of being stopped (i.e. Stopping state), any
> call to queueBuffer() must fail. This is to ensure the integrity of the buffer
> queue, as it gets cleared at the end of streamOff.
> 
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

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

> ---
>  src/libcamera/v4l2_videodevice.cpp | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 9cea6a608660..28f336086b49 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1491,6 +1491,9 @@ int V4L2VideoDevice::releaseBuffers()
>   * The best available V4L2 buffer is picked for \a buffer using the V4L2 buffer
>   * cache.
>   *
> + * Note that queueBuffer() will fail if the device is in the process of being
> + * stopped from a streaming state through streamOff().
> + *
>   * \return 0 on success or a negative error code otherwise
>   */
>  int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
> @@ -1499,6 +1502,11 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
>  	struct v4l2_buffer buf = {};
>  	int ret;
>  
> +	if (state_ == State::Stopping) {
> +		LOG(V4L2, Error) << "Device is in a stopping state.";
> +		return -ESHUTDOWN;
> +	}
> +
>  	/*
>  	 * Pipeline handlers should not requeue buffers after releasing the
>  	 * buffers on the device. Any occurence of this error should be fixed

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 9cea6a608660..28f336086b49 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1491,6 +1491,9 @@  int V4L2VideoDevice::releaseBuffers()
  * The best available V4L2 buffer is picked for \a buffer using the V4L2 buffer
  * cache.
  *
+ * Note that queueBuffer() will fail if the device is in the process of being
+ * stopped from a streaming state through streamOff().
+ *
  * \return 0 on success or a negative error code otherwise
  */
 int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
@@ -1499,6 +1502,11 @@  int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
 	struct v4l2_buffer buf = {};
 	int ret;
 
+	if (state_ == State::Stopping) {
+		LOG(V4L2, Error) << "Device is in a stopping state.";
+		return -ESHUTDOWN;
+	}
+
 	/*
 	 * Pipeline handlers should not requeue buffers after releasing the
 	 * buffers on the device. Any occurence of this error should be fixed