feat: video reconnect (wip egl error 3003)
This commit is contained in:
+16
-14
@@ -1,6 +1,5 @@
|
||||
#ifdef VIDEO_IN
|
||||
|
||||
#include <bsd/string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
@@ -286,22 +285,25 @@ 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, bool swap) {
|
||||
int result;
|
||||
static unsigned int read_video(VideoCapture *video_capture) {
|
||||
unsigned int result;
|
||||
struct v4l2_capability cap;
|
||||
|
||||
result = 0;
|
||||
|
||||
if ((swap || !video_capture->with_swap) &&
|
||||
if ((video_capture->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 (!swap && video_capture->with_swap &&
|
||||
} else if (!video_capture->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);
|
||||
|
||||
result = 2;
|
||||
} else if (ioctl(video_capture->fd, VIDIOC_QUERYCAP, &cap) == -1) {
|
||||
video_capture->error = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -361,18 +363,18 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
pid);
|
||||
timer_init(&timer, 30);
|
||||
|
||||
while (!context->stop) {
|
||||
video_result = read_video(video_capture, context->input_swap[input_index]);
|
||||
while (!context->stop && !video_capture->error) {
|
||||
video_result = read_video(video_capture);
|
||||
if (video_result > 0 && timer_inc(&timer)) {
|
||||
fps = timer_reset(&timer);
|
||||
|
||||
context->input_fps[input_index] = (unsigned int)round(fps);
|
||||
context->inputs.values[input_index].fps = (unsigned int)round(fps);
|
||||
if (trace_fps) {
|
||||
log_trace("(%s) %.2ffps", video_capture->name, fps);
|
||||
}
|
||||
}
|
||||
if (video_result > 0) {
|
||||
context->input_swap[input_index] = video_result == 2;
|
||||
video_capture->swap = video_result == 2;
|
||||
}
|
||||
}
|
||||
if (context->stop) {
|
||||
@@ -381,15 +383,15 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
} else {
|
||||
log_info("(%s) background acquisition stopped after error (pid: %d)",
|
||||
video_capture->name, pid);
|
||||
video_capture->disconnected = true;
|
||||
video_capture->pixelformat = 0;
|
||||
video_free(video_capture);
|
||||
}
|
||||
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
return false;
|
||||
}
|
||||
|
||||
void video_free(const VideoCapture *video_capture) {
|
||||
if (!video_capture->error) {
|
||||
close_stream(video_capture);
|
||||
}
|
||||
close_stream(video_capture);
|
||||
if (video_capture->exp_fd != -1) {
|
||||
close(video_capture->exp_fd);
|
||||
}
|
||||
@@ -401,4 +403,4 @@ void video_free(const VideoCapture *video_capture) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* VIDEO_IN */
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
Reference in New Issue
Block a user