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