From 33ba8ede1cb0c48e9e105fb5d1680119b8b24fd0 Mon Sep 17 00:00:00 2001 From: klemek Date: Mon, 22 Sep 2025 23:48:55 +0200 Subject: [PATCH] debugging why video is 4fps --- src/forge.c | 3 +-- src/video.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/forge.c b/src/forge.c index cb4a5a3..de4a75d 100644 --- a/src/forge.c +++ b/src/forge.c @@ -27,7 +27,7 @@ static ConfigFile shader_config; static bool stop; static unsigned int compute_fps() { - static double fps; + double fps; char title[100]; if (timer_inc(&timer)) { @@ -85,7 +85,6 @@ static void init_context(Parameters params) { context.input_widths[i] = inputs[i].width; context.input_heights[i] = inputs[i].height; context.input_formats[i] = inputs[i].pixelformat; - log_debug("%d %x", inputs[i].pixelformat, inputs[i].pixelformat); } } } diff --git a/src/video.c b/src/video.c index ed2ab3a..9ff07d5 100644 --- a/src/video.c +++ b/src/video.c @@ -7,6 +7,7 @@ #include #include +#include "timer.h" #include "types.h" #include "video.h" #include "window.h" @@ -307,8 +308,27 @@ VideoCapture video_init(char *name, unsigned int preferred_height) { return video_capture; } +static bool read_video(VideoCapture *video_capture) { + if (ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf) == -1) { + ioctl_error(video_capture, "VIDIOC_DQBUF", + "buffer type not supported or no buffer allocated or the index " + "is out of bounds"); + return false; + } + + if (ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf) == -1) { + ioctl_error(video_capture, "VIDIOC_QBUF", + "buffer type not supported or no buffer allocated or the index " + "is out of bounds"); + return false; + } + + return true; +} + void video_background_read(VideoCapture *video_capture, bool *stop) { pid_t pid; + Timer timer; pid = fork(); if (pid < 0) { log_error("Could not create subprocess"); @@ -319,9 +339,13 @@ void video_background_read(VideoCapture *video_capture, bool *stop) { } log_info("%s background acquisition started (pid: %d)", video_capture->name, pid); - while (!*stop) { - ioctl(video_capture->fd, VIDIOC_DQBUF, &video_capture->buf); - ioctl(video_capture->fd, VIDIOC_QBUF, &video_capture->buf); + timer = timer_init(30); + + while (!*stop && read_video(video_capture)) { + // repeat infinitely + if (timer_inc(&timer)) { + log_trace("(%s) %.2ffps", video_capture->name, timer_reset(&timer)); + } } log_info("%s background acquisition stopped (pid: %d)", video_capture->name, pid);