build: check build no video

This commit is contained in:
2025-11-24 00:28:30 +01:00
parent d19f5d2d81
commit 3dceb044aa
4 changed files with 43 additions and 31 deletions
+11
View File
@@ -18,6 +18,17 @@ jobs:
- name: gcc
run: mkdir -p build && gcc -v -Wall -Wextra -Werror -Wno-format-truncation src/*.c src/*.h -lglfw -lGL -lm -lasound -lbsd -Iinclude hashmap.c/hashmap.c log.c/src/log.c -DGLFW_INCLUDE_NONE -DGLFW_EXPOSE_NATIVE_EGL -DGLFW_NATIVE_INCLUDE_NONE -DVIDEO_IN
build-no-video:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: install libs
run: sudo apt install -y libglfw3-dev libgl-dev libasound2-dev libbsd-dev
- name: gcc
run: mkdir -p build && gcc -v -Werror src/*.c src/*.h -lglfw -lGL -lm -lasound -lbsd -Iinclude hashmap.c/hashmap.c log.c/src/log.c -DGLFW_INCLUDE_NONE -DGLFW_EXPOSE_NATIVE_EGL -DGLFW_NATIVE_INCLUDE_NONE
build-release:
needs: lint
runs-on: ubuntu-latest
+12
View File
@@ -14,11 +14,15 @@
#define GLAD_GL_IMPLEMENTATION
#include <glad/gl.h>
#ifdef VIDEO_IN
#define GLAD_EGL_IMPLEMENTATION
#include <glad/egl.h>
#endif /* VIDEO_IN */
#include <GLFW/glfw3.h>
#ifdef VIDEO_IN
#include <GLFW/glfw3native.h>
#endif /* VIDEO_IN */
static const GLuint unused_uniform = (GLuint)-1;
@@ -38,6 +42,7 @@ bool check_glerror(ShaderProgram *program) {
static void init_gl(ShaderProgram *program) {
gladLoadGL(glfwGetProcAddress);
#ifdef VIDEO_IN
program->egl_display = glfwGetEGLDisplay();
if (program->egl_display == EGL_NO_DISPLAY) {
log_error("error: glfwGetEGLDisplay no EGLDisplay returned");
@@ -46,6 +51,7 @@ static void init_gl(ShaderProgram *program) {
}
gladLoadEGL(program->egl_display, glfwGetProcAddress);
#endif /* VIDEO_IN */
}
static void init_textures(ShaderProgram *program,
@@ -80,6 +86,7 @@ static void rebind_textures(const ShaderProgram *program) {
}
}
#ifdef VIDEO_IN
static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
unsigned int texture_index) {
input->dma_image = EGL_NO_IMAGE_KHR;
@@ -136,6 +143,7 @@ static void init_input(ShaderProgram *program, const ConfigFile *config,
}
}
}
#endif /* VIDEO_IN */
static void init_framebuffers(ShaderProgram *program,
const ConfigFile *config) {
@@ -598,11 +606,13 @@ void shaders_init(ShaderProgram *program, const Project *project,
void shaders_link_inputs(ShaderProgram *program, const Project *project,
VideoCaptureArray *inputs) {
#ifdef VIDEO_IN
init_input(program, &project->config, inputs);
if (check_glerror(program)) {
return;
}
#endif /* VIDEO_IN */
}
void shaders_update(ShaderProgram *program, const File *fragment_shader,
@@ -659,7 +669,9 @@ void shaders_free_window(const ShaderProgram *program, bool secondary) {
void shaders_free_input(const ShaderProgram *program,
const VideoCapture *input) {
#ifdef VIDEO_IN
if (!input->error && input->dma_image != EGL_NO_IMAGE_KHR) {
eglDestroyImageKHR(program->egl_display, input->dma_image);
}
#endif /* VIDEO_IN */
}
+7 -8
View File
@@ -1,12 +1,12 @@
#include <GLFW/glfw3.h>
#include <alsa/asoundlib.h>
#ifdef VIDEO_IN
#include <glad/egl.h>
#include <linux/videodev2.h>
#endif /* VIDEO_IN */
#include <glad/gl.h>
#include <hashmap.h>
#include <linmath.h>
#ifdef VIDEO_IN
#include <linux/videodev2.h>
#endif /* VIDEO_IN */
#include <stdbool.h>
#include <sys/time.h>
#include <time.h>
@@ -127,15 +127,13 @@ typedef struct ShaderProgram {
unsigned int active_count;
unsigned int in_count;
#ifdef VIDEO_IN
EGLDisplay egl_display;
#endif /* VIDEO_IN */
} ShaderProgram;
// video.c
#ifndef VIDEO_IN
struct v4l2_buffer {};
#endif /* VIDEO_IN */
typedef struct VideoCapture {
char name[STR_LEN];
bool error;
@@ -145,9 +143,10 @@ typedef struct VideoCapture {
unsigned int height;
unsigned int pixelformat;
unsigned int bytesperline;
bool output;
#ifdef VIDEO_IN
struct v4l2_buffer buf;
EGLImageKHR dma_image;
#endif /* VIDEO_IN */
} VideoCapture;
typedef ARRAY(VideoCaptureArray, VideoCapture);
+13 -23
View File
@@ -17,6 +17,9 @@
#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,
const char *default_msg) {
if (errno == EINVAL) {
@@ -116,7 +119,7 @@ static bool get_available_sizes(VideoCapture *video_capture,
index = 0;
fmt_enum.index = index;
fmt_enum.pixel_format = V4L2_PIX_FMT_YUYV;
fmt_enum.pixel_format = pixel_format;
found = false;
video_capture->width = 0;
@@ -148,7 +151,7 @@ static bool get_available_sizes(VideoCapture *video_capture,
memset(&fmt_enum, 0, sizeof(fmt_enum));
fmt_enum.index = ++index;
fmt_enum.pixel_format = V4L2_PIX_FMT_YUYV;
fmt_enum.pixel_format = pixel_format;
}
if (video_capture->height == 0) {
@@ -163,26 +166,18 @@ static bool get_available_sizes(VideoCapture *video_capture,
static bool set_format(VideoCapture *video_capture) {
struct v4l2_format fmt;
video_capture->output = false;
memset(&fmt, 0, sizeof(fmt));
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.type = buf_type;
fmt.fmt.pix.width = video_capture->width;
fmt.fmt.pix.height = video_capture->height;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.pixelformat = pixel_format;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
if (ioctl(video_capture->fd, VIDIOC_S_FMT, &fmt) == -1) {
fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
video_capture->output = true;
if (ioctl(video_capture->fd, VIDIOC_S_FMT, &fmt) == -1) {
ioctl_error(video_capture, "VIDIOC_S_FMT",
"Requested buffer type not supported");
return false;
}
ioctl_error(video_capture, "VIDIOC_S_FMT",
"Requested buffer type not supported");
return false;
}
video_capture->width = fmt.fmt.pix.width;
@@ -204,8 +199,7 @@ static bool request_buffers(VideoCapture *video_capture) {
memset(&reqbuf, 0, sizeof(reqbuf));
reqbuf.type = video_capture->output ? V4L2_BUF_TYPE_VIDEO_OUTPUT
: V4L2_BUF_TYPE_VIDEO_CAPTURE;
reqbuf.type = buf_type;
reqbuf.memory = V4L2_MEMORY_MMAP;
reqbuf.count = 1;
@@ -227,8 +221,7 @@ static bool export_buffer(VideoCapture *video_capture) {
memset(&expbuf, 0, sizeof(expbuf));
expbuf.type = video_capture->output ? V4L2_BUF_TYPE_VIDEO_OUTPUT
: V4L2_BUF_TYPE_VIDEO_CAPTURE;
expbuf.type = buf_type;
expbuf.index = 0;
expbuf.flags = O_RDONLY;
@@ -244,8 +237,6 @@ static bool export_buffer(VideoCapture *video_capture) {
return true;
}
static const enum v4l2_buf_type buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
static bool open_stream(VideoCapture *video_capture) {
if (ioctl(video_capture->fd, VIDIOC_STREAMON, &buf_type) == -1) {
ioctl_error(
@@ -260,8 +251,7 @@ static bool open_stream(VideoCapture *video_capture) {
static void create_image_buffer(VideoCapture *video_capture) {
memset(&video_capture->buf, 0, sizeof(video_capture->buf));
video_capture->buf.type = video_capture->output ? V4L2_BUF_TYPE_VIDEO_OUTPUT
: V4L2_BUF_TYPE_VIDEO_CAPTURE;
video_capture->buf.type = buf_type;
video_capture->buf.memory = V4L2_MEMORY_MMAP;
video_capture->buf.index = 0;