feat: select fourcc and handle hw decoded
Clang Build CI / build-release (push) Failing after 54s
Clang Build CI / run-video (push) Successful in 1m12s
Clang Lint CI / lint-no-video (push) Successful in 1m12s
Clang Build CI / run-no-video (push) Successful in 1m17s
Clang Lint CI / lint-video (push) Successful in 4m33s

This commit is contained in:
2026-05-17 00:40:22 +02:00
parent e667c6b869
commit e38f57af46
11 changed files with 74 additions and 31 deletions
+8
View File
@@ -34,6 +34,7 @@ static void print_help(int status_code) {
"[-vs=SIZE] "
"[-vb=COUNT] "
"[-vr / -nvr] "
"[-vf=FOURCC] "
#endif /* VIDEO_IN */
"[-is=SIZE] "
"[-ls / -nls] "
@@ -70,6 +71,7 @@ static void print_help(int status_code) {
"internal texture height)\n"
" -vr, --video-reconnect auto-reconnect video (default)\n"
" -nvr, --no-video-reconnect do not auto-reconnect video\n"
" -vf, --video-fourcc video codec fourcc (default: YUYV)\n"
#endif /* VIDEO_IN */
" -is, --internal-size internal texture height (default: 720)\n"
" -ls, --load-state load saved state (default)\n"
@@ -142,6 +144,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
params->video_buffers = 2;
params->video_size = 0;
params->video_reconnect = true;
strlcpy(params->video_fourcc, "YUYV", 5);
#endif /* VIDEO_IN */
params->internal_size = 720;
params->load_state = true;
@@ -243,6 +246,11 @@ void args_parse(Parameters *params, int argc, char **argv) {
params->video_reconnect = true;
} else if (is_arg(arg, "-nvr") || is_arg(arg, "--no-video-reconnect")) {
params->video_reconnect = false;
} else if (is_arg(arg, "-vf") || is_arg(arg, "--video-fourcc")) {
if (strlen(value) == 0) {
invalid_value(arg, value);
}
strlcpy(params->video_fourcc, value, 5);
} else {
invalid_arg(arg);
}
+4 -2
View File
@@ -85,7 +85,8 @@ static void init_inputs() {
for (unsigned int i = 0; i < init_params.video_in.length; i++) {
video_init(&video_captures.values[i], init_params.video_in.values[i],
init_params.video_size, init_params.video_buffers, true);
init_params.video_size, init_params.video_buffers,
init_params.video_fourcc, true);
if (!video_captures.values[i].error) {
context.input_resolutions[i][0] = video_captures.values[i].width;
@@ -125,7 +126,8 @@ background_reconnect_video_captures(__attribute__((unused)) void *args) {
if (video_captures.values[i].disconnected) {
video_free(&video_captures.values[i]);
video_init(&video_captures.values[i], init_params.video_in.values[i],
init_params.video_size, init_params.video_buffers, false);
init_params.video_size, init_params.video_buffers,
init_params.video_fourcc, false);
if (!video_captures.values[i].error) {
context.input_resolutions[i][0] = video_captures.values[i].width;
-6
View File
@@ -245,12 +245,6 @@ static bool link_input_to_texture(ShaderProgram *program, VideoCapture *input,
return false;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, input->width, input->height, 0, GL_RGB,
GL_UNSIGNED_BYTE, 0);
if (check_glerror(program, "link_input_to_texture/glTexImage2D")) {
return false;
}
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_EGL_image_storage.txt
glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D, dma_image, NULL);
if (check_eglerror(program,
+1
View File
@@ -50,6 +50,7 @@ typedef struct Parameters {
unsigned int video_buffers;
unsigned int video_size;
bool video_reconnect;
char video_fourcc[5];
#endif /* VIDEO_IN */
unsigned int internal_size;
bool load_state;
+24 -9
View File
@@ -16,7 +16,6 @@
#include "timer.h"
#include "video.h"
static const unsigned int pixel_format = V4L2_PIX_FMT_YUYV;
static const enum v4l2_buf_type buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
static void ioctl_error(VideoCapture *video_capture, const char *operation,
@@ -70,6 +69,19 @@ static void ioctl_error(VideoCapture *video_capture, const char *operation,
video_capture->error = true;
}
static void fourcc_to_string(unsigned int fourcc, char *str) {
str[0] = (char)(fourcc & 0xFF);
str[1] = (char)((fourcc >> 8) & 0xFF);
str[2] = (char)((fourcc >> 16) & 0xFF);
str[3] = (char)((fourcc >> 24) & 0xFF);
str[4] = '\0';
}
static int string_to_fourcc(const char *str) {
return (unsigned int)str[0] | ((unsigned int)str[1] << 8) |
((unsigned int)str[2] << 16) | ((unsigned int)str[3] << 24);
}
static void open_device(VideoCapture *video_capture, const char *name,
bool log_error) {
strlcpy(video_capture->name, name, STR_LEN);
@@ -112,7 +124,8 @@ static bool check_caps(VideoCapture *video_capture) {
}
static bool get_available_sizes(VideoCapture *video_capture,
unsigned int preferred_height) {
unsigned int preferred_height,
unsigned int pixel_format) {
struct v4l2_frmsizeenum fmt_enum;
unsigned int index;
bool found = false;
@@ -165,8 +178,9 @@ static bool get_available_sizes(VideoCapture *video_capture,
return true;
}
static bool set_format(VideoCapture *video_capture) {
static bool set_format(VideoCapture *video_capture, unsigned int pixel_format) {
struct v4l2_format fmt;
char fourcc[STR_LEN];
memset(&fmt, 0, sizeof(fmt));
@@ -187,9 +201,9 @@ static bool set_format(VideoCapture *video_capture) {
video_capture->pixelformat = fmt.fmt.pix.pixelformat;
video_capture->bytesperline = fmt.fmt.pix.bytesperline;
log_info("(%s) Format fourcc: %c%c%c%c", video_capture->name,
fmt.fmt.pix.pixelformat, fmt.fmt.pix.pixelformat >> 8,
fmt.fmt.pix.pixelformat >> 16, fmt.fmt.pix.pixelformat >> 24);
fourcc_to_string(fmt.fmt.pix.pixelformat, fourcc);
log_info("(%s) Format fourcc: %s", video_capture->name, fourcc);
log_info("(%s) Resolution: %dx%d", video_capture->name, fmt.fmt.pix.width,
fmt.fmt.pix.height);
@@ -326,7 +340,7 @@ static unsigned int read_video(VideoCapture *video_capture) {
void video_init(VideoCapture *video_capture, const char *name,
unsigned int preferred_height, unsigned int buffer_count,
bool log_error) {
const char *video_fourcc, bool log_error) {
open_device(video_capture, name, log_error);
if (video_capture->error) {
@@ -339,13 +353,14 @@ void video_init(VideoCapture *video_capture, const char *name,
return;
}
if (!get_available_sizes(video_capture, preferred_height)) {
if (!get_available_sizes(video_capture, preferred_height,
string_to_fourcc(video_fourcc))) {
video_capture->error = true;
video_free(video_capture);
return;
}
if (!set_format(video_capture)) {
if (!set_format(video_capture, string_to_fourcc(video_fourcc))) {
video_capture->error = true;
video_free(video_capture);
return;
+1 -1
View File
@@ -7,7 +7,7 @@
void video_init(VideoCapture *video_capture, const char *name,
unsigned int preferred_height, unsigned int buffer_count,
bool log_error);
const char *video_fourcc, bool log_error);
void *video_background_read(void *args);