rename device -> video capture and inputs when used
This commit is contained in:
+2
-2
@@ -96,7 +96,7 @@ Parameters args_parse(int argc, char **argv) {
|
||||
params.base_tempo = 60.0f;
|
||||
params.demo = false;
|
||||
params.windowed = false;
|
||||
params.video_count = 0;
|
||||
params.video_in_count = 0;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
arg = argv[i];
|
||||
@@ -115,7 +115,7 @@ Parameters args_parse(int argc, char **argv) {
|
||||
} else if (is_arg(arg, "-fc") || is_arg(arg, "--frag-config")) {
|
||||
params.frag_config_path = value;
|
||||
} else if (is_arg(arg, "-v") || is_arg(arg, "--video-in")) {
|
||||
params.video_in[params.video_count++] = value;
|
||||
params.video_in[params.video_in_count++] = value;
|
||||
} else if (is_arg(arg, "-t") || is_arg(arg, "--tempo")) {
|
||||
params.base_tempo = (float)parse_uint(arg, value);
|
||||
} else if (is_arg(arg, "-is") || is_arg(arg, "--internal-size")) {
|
||||
|
||||
+18
-20
@@ -19,7 +19,7 @@ static Context context;
|
||||
static ShaderProgram program;
|
||||
static Window *window_output;
|
||||
static Window *window_monitor;
|
||||
static VideoCapture *video_captures;
|
||||
static VideoCapture *inputs;
|
||||
static File *fragment_shaders;
|
||||
static File common_shader_code;
|
||||
static Timer timer;
|
||||
@@ -145,15 +145,14 @@ static void free_files(unsigned int frag_count) {
|
||||
file_free(&common_shader_code, true);
|
||||
}
|
||||
|
||||
static void init_video_captures(char *video_in[MAX_VIDEO],
|
||||
unsigned int video_count,
|
||||
unsigned int internal_size) {
|
||||
static void init_inputs(char *video_in[MAX_VIDEO], unsigned int input_count,
|
||||
unsigned int internal_size) {
|
||||
unsigned int i;
|
||||
|
||||
video_captures = malloc(video_count * sizeof(VideoCapture));
|
||||
inputs = malloc(input_count * sizeof(VideoCapture));
|
||||
|
||||
for (i = 0; i < video_count; i++) {
|
||||
video_captures[i] = video_init(video_in[i], internal_size);
|
||||
for (i = 0; i < input_count; i++) {
|
||||
inputs[i] = video_init(video_in[i], internal_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,8 +160,8 @@ static void start_video_captures(unsigned int video_count) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < video_count; i++) {
|
||||
if (!video_captures[i].error) {
|
||||
video_background_read(&video_captures[i], &stop);
|
||||
if (!inputs[i].error) {
|
||||
video_background_read(&inputs[i], &stop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,12 +170,12 @@ static void free_video_captures(unsigned int video_count) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < video_count; i++) {
|
||||
shaders_free_video(program, video_captures[i]);
|
||||
shaders_free_input(program, inputs[i]);
|
||||
|
||||
video_free(video_captures[i]);
|
||||
video_free(inputs[i]);
|
||||
}
|
||||
|
||||
free(video_captures);
|
||||
free(inputs);
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char *description) {
|
||||
@@ -244,8 +243,7 @@ void forge_run(Parameters params) {
|
||||
|
||||
context.internal_height = params.internal_size;
|
||||
|
||||
init_video_captures(params.video_in, params.video_count,
|
||||
params.internal_size);
|
||||
init_inputs(params.video_in, params.video_in_count, params.internal_size);
|
||||
|
||||
if (params.output) {
|
||||
window_output = window_init(PACKAGE " " VERSION, params.output_screen,
|
||||
@@ -253,8 +251,8 @@ void forge_run(Parameters params) {
|
||||
|
||||
window_use(window_output, &context);
|
||||
|
||||
program = shaders_init(fragment_shaders, shader_config, context,
|
||||
video_captures, params.video_count, NULL);
|
||||
program = shaders_init(fragment_shaders, shader_config, context, inputs,
|
||||
params.video_in_count, NULL);
|
||||
} else {
|
||||
window_output = NULL;
|
||||
}
|
||||
@@ -266,8 +264,8 @@ void forge_run(Parameters params) {
|
||||
|
||||
window_use(window_monitor, &context);
|
||||
|
||||
program = shaders_init(fragment_shaders, shader_config, context,
|
||||
video_captures, params.video_count,
|
||||
program = shaders_init(fragment_shaders, shader_config, context, inputs,
|
||||
params.video_in_count,
|
||||
window_output != NULL ? &program : NULL);
|
||||
} else {
|
||||
window_monitor = NULL;
|
||||
@@ -282,7 +280,7 @@ void forge_run(Parameters params) {
|
||||
|
||||
timer = timer_init(30);
|
||||
|
||||
start_video_captures(params.video_count);
|
||||
start_video_captures(params.video_in_count);
|
||||
|
||||
log_info("Initialized");
|
||||
|
||||
@@ -309,7 +307,7 @@ void forge_run(Parameters params) {
|
||||
shaders_free_window(program, params.output);
|
||||
}
|
||||
|
||||
free_video_captures(params.video_count);
|
||||
free_video_captures(params.video_in_count);
|
||||
|
||||
free_context();
|
||||
|
||||
|
||||
+26
-29
@@ -69,32 +69,30 @@ static void rebind_textures(ShaderProgram *program) {
|
||||
}
|
||||
}
|
||||
|
||||
static void link_video_to_texture(ShaderProgram *program,
|
||||
VideoCapture *video_capture,
|
||||
static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
unsigned int texture_index) {
|
||||
video_capture->dma_image = EGL_NO_IMAGE_KHR;
|
||||
input->dma_image = EGL_NO_IMAGE_KHR;
|
||||
|
||||
const EGLint attrib_list[] = {EGL_WIDTH,
|
||||
video_capture->width,
|
||||
input->width,
|
||||
EGL_HEIGHT,
|
||||
video_capture->height,
|
||||
input->height,
|
||||
EGL_LINUX_DRM_FOURCC_EXT,
|
||||
video_capture->pixelformat,
|
||||
input->pixelformat,
|
||||
EGL_DMA_BUF_PLANE0_FD_EXT,
|
||||
video_capture->exp_fd,
|
||||
input->exp_fd,
|
||||
EGL_DMA_BUF_PLANE0_OFFSET_EXT,
|
||||
0,
|
||||
EGL_DMA_BUF_PLANE0_PITCH_EXT,
|
||||
video_capture->bytesperline,
|
||||
input->bytesperline,
|
||||
EGL_NONE};
|
||||
|
||||
video_capture->dma_image = eglCreateImageKHR(
|
||||
program->egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
|
||||
(EGLClientBuffer)NULL, attrib_list);
|
||||
input->dma_image = eglCreateImageKHR(program->egl_display, EGL_NO_CONTEXT,
|
||||
EGL_LINUX_DMA_BUF_EXT,
|
||||
(EGLClientBuffer)NULL, attrib_list);
|
||||
|
||||
if (video_capture->dma_image == EGL_NO_IMAGE_KHR) {
|
||||
log_error("(%s) eglCreateImageKHR failed %04x", video_capture->name,
|
||||
eglGetError());
|
||||
if (input->dma_image == EGL_NO_IMAGE_KHR) {
|
||||
log_error("(%s) eglCreateImageKHR failed %04x", input->name, eglGetError());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,28 +100,27 @@ static void link_video_to_texture(ShaderProgram *program,
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, program->textures[texture_index]);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, video_capture->width,
|
||||
video_capture->height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, input->width, input->height, 0, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_EGL_image_storage.txt
|
||||
glEGLImageTargetTextureStorageEXT(program->textures[texture_index],
|
||||
(GLeglImageOES)video_capture->dma_image,
|
||||
NULL);
|
||||
(GLeglImageOES)input->dma_image, NULL);
|
||||
|
||||
log_info("Texture %d linked to %s", texture_index, video_capture->name);
|
||||
log_info("Texture %d linked to %s", texture_index, input->name);
|
||||
}
|
||||
|
||||
static void init_videos(ShaderProgram *program, ConfigFile shader_config,
|
||||
VideoCapture *video_captures, unsigned int count) {
|
||||
static void init_input(ShaderProgram *program, ConfigFile shader_config,
|
||||
VideoCapture *inputs, unsigned int input_count) {
|
||||
unsigned int i;
|
||||
unsigned tex_i;
|
||||
char name[32];
|
||||
|
||||
for (i = 0; i < program->in_count; i++) {
|
||||
if (i < count && !video_captures[i].error) {
|
||||
if (i < input_count && !inputs[i].error) {
|
||||
sprintf(name, "IN_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(shader_config, name, 0);
|
||||
link_video_to_texture(program, &video_captures[i], tex_i);
|
||||
link_input_to_texture(program, &inputs[i], tex_i);
|
||||
} else {
|
||||
log_warn("Cannot link input %d", i + 1);
|
||||
}
|
||||
@@ -355,8 +352,8 @@ static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
|
||||
}
|
||||
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
||||
Context context, VideoCapture *video_captures,
|
||||
unsigned int count, ShaderProgram *previous) {
|
||||
Context context, VideoCapture *inputs,
|
||||
unsigned int input_count, ShaderProgram *previous) {
|
||||
ShaderProgram program;
|
||||
|
||||
if (previous == NULL) {
|
||||
@@ -385,7 +382,7 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
||||
|
||||
init_textures(&program, context);
|
||||
|
||||
init_videos(&program, shader_config, video_captures, count);
|
||||
init_input(&program, shader_config, inputs, input_count);
|
||||
|
||||
init_framebuffers(&program, shader_config);
|
||||
|
||||
@@ -550,8 +547,8 @@ void shaders_free_window(ShaderProgram program, bool secondary) {
|
||||
glDeleteVertexArrays(1, &program.vertex_array[secondary ? 1 : 0]);
|
||||
}
|
||||
|
||||
void shaders_free_video(ShaderProgram program, VideoCapture video_capture) {
|
||||
if (!video_capture.error && video_capture.dma_image != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program.egl_display, video_capture.dma_image);
|
||||
void shaders_free_input(ShaderProgram program, VideoCapture input) {
|
||||
if (!input.error && input.dma_image != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program.egl_display, input.dma_image);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -4,8 +4,8 @@
|
||||
#define SHADERS_H
|
||||
|
||||
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
|
||||
Context context, VideoCapture *video_captures,
|
||||
unsigned int count, ShaderProgram *previous);
|
||||
Context context, VideoCapture *inputs,
|
||||
unsigned int input_count, ShaderProgram *previous);
|
||||
|
||||
void shaders_update(ShaderProgram program, File *fragment_shaders,
|
||||
unsigned int i);
|
||||
@@ -17,6 +17,6 @@ void shaders_free(ShaderProgram program);
|
||||
|
||||
void shaders_free_window(ShaderProgram program, bool secondary);
|
||||
|
||||
void shaders_free_video(ShaderProgram program, VideoCapture video_capture);
|
||||
void shaders_free_input(ShaderProgram program, VideoCapture input);
|
||||
|
||||
#endif /* SHADERS_H */
|
||||
+3
-1
@@ -26,7 +26,7 @@ typedef struct Parameters {
|
||||
bool demo;
|
||||
bool windowed;
|
||||
char *video_in[MAX_VIDEO];
|
||||
unsigned int video_count;
|
||||
unsigned int video_in_count;
|
||||
} Parameters;
|
||||
|
||||
typedef struct Vertex {
|
||||
@@ -113,6 +113,8 @@ typedef struct Context {
|
||||
bool demo;
|
||||
unsigned int *seeds;
|
||||
bool monitor;
|
||||
unsigned int *input_widths;
|
||||
unsigned int *input_heights;
|
||||
} Context;
|
||||
|
||||
typedef struct Timer {
|
||||
|
||||
Reference in New Issue
Block a user