From 071e3698f56522726f2ba1aeeade44d6c6c4f7f8 Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Thu, 4 Jun 2020 22:33:24 +0900 Subject: v4l2: v4l2_camera_proxy: Fix segfault on restarting streams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The V4L2 compatibility layer keeps track of the index of the next buffer to be dequeued, to handle VIDIOC_DQBUF. This index is set to 0 on startup and incremented (modulo #frames), and is otherwise never reset. This means that if the last handled frame index is not #frames-1, and the stream is restarted without restarting libcamera and the V4L2 compatilibity layer, the buffer index number won't match with the libcamera buffer index number, causing a segfault. Fix this by resetting the current buffer index to zero on VIDIOC_STREAMON. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/v4l2/v4l2_camera_proxy.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/v4l2') diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 7ee4c0cb..059f3cbe 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -465,6 +465,8 @@ int V4L2CameraProxy::vidioc_streamon(int *arg) if (!validateBufferType(*arg)) return -EINVAL; + currentBuf_ = 0; + return vcam_->streamOn(); } -- cgit v1.2.1