feat: video auto reconnect
Clang Lint CI / lint-no-video (push) Successful in 56s
Clang Build CI / run-no-video (push) Successful in 59s
Clang Build CI / run-video (push) Successful in 1m15s
Clang Build CI / build-release (push) Successful in 2m23s
Clang Lint CI / lint-video (push) Successful in 2m14s
Clang Lint CI / lint-no-video (push) Successful in 56s
Clang Build CI / run-no-video (push) Successful in 59s
Clang Build CI / run-video (push) Successful in 1m15s
Clang Build CI / build-release (push) Successful in 2m23s
Clang Lint CI / lint-video (push) Successful in 2m14s
This commit is contained in:
+18
-24
@@ -4,8 +4,8 @@
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include <log.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
@@ -344,23 +344,17 @@ void video_init(VideoCapture *video_capture, const char *name,
|
||||
create_image_buffers(video_capture);
|
||||
}
|
||||
|
||||
bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
int input_index, bool trace_fps) {
|
||||
pid_t pid;
|
||||
void *video_background_read(void *args) {
|
||||
VideoBackgroundReadArgs *process_args = (VideoBackgroundReadArgs *)args;
|
||||
VideoCapture *video_capture = process_args->capture;
|
||||
Context *context = process_args->context;
|
||||
int input_index = process_args->input_index;
|
||||
bool trace_fps = process_args->trace_fps;
|
||||
Timer timer;
|
||||
double fps;
|
||||
unsigned int video_result;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
log_error("Could not create subprocess");
|
||||
return false;
|
||||
}
|
||||
if (pid == 0) {
|
||||
return true;
|
||||
}
|
||||
log_info("(%s) background acquisition started (pid: %d)", video_capture->name,
|
||||
pid);
|
||||
log_info("(%s) background acquisition started", video_capture->name);
|
||||
timer_init(&timer, 30);
|
||||
|
||||
while (!context->stop && !video_capture->error) {
|
||||
@@ -368,26 +362,26 @@ bool video_background_read(VideoCapture *video_capture, SharedContext *context,
|
||||
if (video_result > 0 && timer_inc(&timer)) {
|
||||
fps = timer_reset(&timer);
|
||||
|
||||
context->inputs.values[input_index].fps = (unsigned int)round(fps);
|
||||
context->input_fps[input_index] = (unsigned int)round(fps);
|
||||
if (trace_fps) {
|
||||
log_trace("(%s) %.2ffps", video_capture->name, fps);
|
||||
}
|
||||
}
|
||||
if (video_result > 0) {
|
||||
video_capture->swap = video_result == 2;
|
||||
context->input_swap[input_index] = video_capture->swap =
|
||||
video_result == 2;
|
||||
}
|
||||
}
|
||||
if (context->stop) {
|
||||
log_info("(%s) background acquisition stopped by main thread (pid: %d)",
|
||||
video_capture->name, pid);
|
||||
log_info("(%s) background acquisition stopped by main thread",
|
||||
video_capture->name);
|
||||
} else {
|
||||
log_info("(%s) background acquisition stopped after error (pid: %d)",
|
||||
video_capture->name, pid);
|
||||
log_info("(%s) background acquisition stopped after error",
|
||||
video_capture->name);
|
||||
video_capture->disconnected = true;
|
||||
video_capture->pixelformat = 0;
|
||||
video_free(video_capture);
|
||||
context->input_formats[input_index] = 0;
|
||||
}
|
||||
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
void video_free(const VideoCapture *video_capture) {
|
||||
@@ -396,7 +390,7 @@ void video_free(const VideoCapture *video_capture) {
|
||||
close(video_capture->exp_fd);
|
||||
}
|
||||
if (video_capture->exp_fd_swap != -1) {
|
||||
close(video_capture->exp_fd);
|
||||
close(video_capture->exp_fd_swap);
|
||||
}
|
||||
if (video_capture->fd != -1) {
|
||||
close(video_capture->fd);
|
||||
|
||||
Reference in New Issue
Block a user