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
+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;