fix(video): alternate read for double buffering
This commit is contained in:
+5
-4
@@ -286,16 +286,17 @@ static void close_stream(const VideoCapture *video_capture) {
|
|||||||
ioctl(video_capture->fd, VIDIOC_STREAMOFF, &buf_type);
|
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;
|
int result;
|
||||||
|
|
||||||
result = 0;
|
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);
|
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf);
|
||||||
|
|
||||||
result = 1;
|
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) !=
|
ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf_swap) !=
|
||||||
-1) {
|
-1) {
|
||||||
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf_swap);
|
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);
|
timer_init(&timer, 30);
|
||||||
|
|
||||||
while (!context->stop) {
|
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)) {
|
if (video_result > 0 && timer_inc(&timer)) {
|
||||||
fps = timer_reset(&timer);
|
fps = timer_reset(&timer);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user