Fix VIDIOC_S_FMT EBUSY error on video stream restart

V4L2 buffers were not explicitly freed before closing the device, causing VIDIOC_S_FMT to fail with EBUSY on restart. Added  VIDIOC_REQBUFS(count=0) call in cleanup to free buffer queue synchronously before close().

This ensures subsequent opens can set format immediately without EBUSY errors, eliminating 100ms+ retry delays.
This commit is contained in:
Adam Shiervani 2025-10-17 11:14:53 +00:00 committed by Siyuan
parent 38a987469f
commit 0f4e073a45
1 changed files with 20 additions and 8 deletions

View File

@ -606,6 +606,18 @@ void *run_video_stream(void *arg)
log_error("VIDIOC_STREAMOFF failed: %s", strerror(errno)); log_error("VIDIOC_STREAMOFF failed: %s", strerror(errno));
} }
// Explicitly free V4L2 buffer queue
struct v4l2_requestbuffers req_free;
memset(&req_free, 0, sizeof(req_free));
req_free.count = 0;
req_free.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
req_free.memory = V4L2_MEMORY_DMABUF;
if (ioctl(video_dev_fd, VIDIOC_REQBUFS, &req_free) < 0)
{
log_error("Failed to free V4L2 buffers: %s", strerror(errno));
}
venc_stop(); venc_stop();
for (int i = 0; i < input_buffer_count; i++) for (int i = 0; i < input_buffer_count; i++)