shared context and rename config filer

This commit is contained in:
2025-09-28 16:26:53 +02:00
parent b12fb43654
commit 6eaba98fff
14 changed files with 145 additions and 195 deletions
+6 -19
View File
@@ -3,13 +3,10 @@
#include <linux/videodev2.h>
#include <log.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "config.h"
#include "rand.h"
#include "shared.h"
#include "timer.h"
#include "types.h"
@@ -270,14 +267,6 @@ static void create_image_buffer(VideoCapture *video_capture) {
ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf);
}
static void create_shared_data(VideoCapture *video_capture) {
char name[256];
sprintf(name, "/" PACKAGE "_fps_%d", rand_uint(1000000));
video_capture->fps = shared_init_uint(name, 0);
}
static void close_stream(VideoCapture video_capture) {
ioctl(video_capture.fd, VIDIOC_STREAMOFF, &buf_type);
}
@@ -317,8 +306,6 @@ VideoCapture video_init(char *name, unsigned int preferred_height) {
create_image_buffer(&video_capture);
create_shared_data(&video_capture);
return video_capture;
}
@@ -340,7 +327,8 @@ static bool read_video(VideoCapture *video_capture) {
return true;
}
void video_background_read(VideoCapture *video_capture, SharedBool *stop) {
void video_background_read(VideoCapture *video_capture, SharedContext *context,
int input_index) {
pid_t pid;
Timer timer;
double fps;
@@ -357,16 +345,16 @@ void video_background_read(VideoCapture *video_capture, SharedBool *stop) {
pid);
timer = timer_init(30);
while (!stop->value && read_video(video_capture)) {
while (!context->stop && read_video(video_capture)) {
// repeat infinitely
if (timer_inc(&timer)) {
fps = timer_reset(&timer);
video_capture->fps->value = (unsigned int)round(fps);
context->input_fps[input_index] = (unsigned int)round(fps);
log_trace("(%s) %.2ffps", video_capture->name, fps);
}
}
if (stop->value) {
if (context->stop) {
log_info("%s background acquisition stopped by main thread (pid: %d)",
video_capture->name, pid);
} else {
@@ -374,13 +362,12 @@ void video_background_read(VideoCapture *video_capture, SharedBool *stop) {
video_capture->name, pid);
}
window_terminate();
exit(stop->value ? EXIT_SUCCESS : EXIT_FAILURE);
exit(context->stop ? EXIT_SUCCESS : EXIT_FAILURE);
}
void video_free(VideoCapture video_capture) {
if (!video_capture.error) {
close_stream(video_capture);
shared_close_uint(video_capture.fps);
}
if (video_capture.exp_fd != -1) {
close(video_capture.exp_fd);