From 97f768f65e75c2847d86a05f30009e008e8be396 Mon Sep 17 00:00:00 2001 From: klemek Date: Mon, 24 Nov 2025 19:11:59 +0100 Subject: [PATCH] fix(video): alternate read for double buffering --- src/video.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/video.c b/src/video.c index 3e7ada4..1aab9ba 100644 --- a/src/video.c +++ b/src/video.c @@ -286,16 +286,17 @@ static void close_stream(const VideoCapture *video_capture) { ioctl(video_capture->fd, VIDIOC_STREAMOFF, &buf_type); } -static unsigned int read_video(const VideoCapture *video_capture) { +static unsigned int read_video(const VideoCapture *video_capture, bool swap) { int result; result = 0; - if (ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) != -1) { + if ((swap || !video_capture->with_swap) && + ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) != -1) { ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf); result = 1; - } else if (video_capture->with_swap && + } else if (!swap && video_capture->with_swap && ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf_swap) != -1) { ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf_swap); @@ -361,7 +362,7 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context, timer_init(&timer, 30); while (!context->stop) { - video_result = read_video(video_capture); + video_result = read_video(video_capture, context->input_swap[input_index]); if (video_result > 0 && timer_inc(&timer)) { fps = timer_reset(&timer);