feat: video reconnect (wip egl error 3003)
This commit is contained in:
+82
-35
@@ -39,6 +39,20 @@ bool check_glerror(ShaderProgram *program) {
|
||||
return code > 0;
|
||||
}
|
||||
|
||||
bool check_eglerror(ShaderProgram *program, const char *context) {
|
||||
unsigned int code;
|
||||
|
||||
code = eglGetError();
|
||||
|
||||
if (code > 0 && code != EGL_SUCCESS) {
|
||||
log_warn("(%s) EGL Error: %04x", context, code);
|
||||
program->error = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void init_gl(ShaderProgram *program) {
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
@@ -88,7 +102,15 @@ static void rebind_textures(const ShaderProgram *program) {
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
unsigned int texture_index, bool swap) {
|
||||
unsigned int input_index,
|
||||
unsigned int texture_index, bool swap,
|
||||
bool reload) {
|
||||
if (reload) {
|
||||
glDeleteTextures(1, program->textures + texture_index);
|
||||
|
||||
glGenTextures(1, program->textures + texture_index);
|
||||
}
|
||||
|
||||
EGLImageKHR dma_image;
|
||||
|
||||
dma_image = EGL_NO_IMAGE_KHR;
|
||||
@@ -111,15 +133,14 @@ static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
dma_image = eglCreateImageKHR(program->egl_display, EGL_NO_CONTEXT,
|
||||
EGL_LINUX_DMA_BUF_EXT, NULL, attrib_list);
|
||||
|
||||
if (swap) {
|
||||
input->dma_image_swap = dma_image;
|
||||
} else {
|
||||
input->dma_image = dma_image;
|
||||
if (check_eglerror(program, "eglCreateImageKHR")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dma_image == EGL_NO_IMAGE_KHR) {
|
||||
log_error("(%s) eglCreateImageKHR failed %04x", input->name, eglGetError());
|
||||
return;
|
||||
if (swap) {
|
||||
program->dma_images_swap[input_index] = dma_image;
|
||||
} else {
|
||||
program->dma_images[input_index] = dma_image;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texture_index);
|
||||
@@ -130,30 +151,35 @@ static void link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_EGL_image_storage.txt
|
||||
glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D, input->dma_image, NULL);
|
||||
glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D, dma_image, NULL);
|
||||
|
||||
if (check_eglerror(program, "glEGLImageTargetTexStorageEXT")) {
|
||||
return;
|
||||
}
|
||||
|
||||
log_info("Texture %d linked to %s", texture_index, input->name);
|
||||
}
|
||||
|
||||
static void init_input(ShaderProgram *program, const ConfigFile *config,
|
||||
VideoCaptureArray *inputs) {
|
||||
VideoCaptureArray *inputs, unsigned int i, bool reload) {
|
||||
unsigned int tex_i;
|
||||
char name[STR_LEN];
|
||||
|
||||
for (unsigned int i = 0; i < program->in_count; i++) {
|
||||
if (i < inputs->length && !inputs->values[i].error) {
|
||||
snprintf(name, STR_LEN, "IN_%d_OUT", i + 1);
|
||||
if (i < inputs->length && !inputs->values[i].error) {
|
||||
snprintf(name, STR_LEN, "IN_%d_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
link_input_to_texture(program, &inputs->values[i], i, tex_i, false, reload);
|
||||
if (inputs->values[i].with_swap) {
|
||||
snprintf(name, STR_LEN, "IN_%d_SWAP_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
link_input_to_texture(program, &inputs->values[i], tex_i, false);
|
||||
if (inputs->values[i].with_swap) {
|
||||
snprintf(name, STR_LEN, "IN_%d_SWAP_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
link_input_to_texture(program, &inputs->values[i], tex_i, true);
|
||||
}
|
||||
} else {
|
||||
log_warn("Cannot link input %d", i + 1);
|
||||
link_input_to_texture(program, &inputs->values[i], i, tex_i, true,
|
||||
reload);
|
||||
}
|
||||
} else {
|
||||
log_warn("Cannot link input %d", i + 1);
|
||||
}
|
||||
|
||||
check_glerror(program);
|
||||
}
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
@@ -426,8 +452,10 @@ static void update_viewport(ShaderProgram *program,
|
||||
// clean and resize all textures
|
||||
for (unsigned int i = 0; i < program->tex_count; i++) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
// TODO dont remap input textures
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context->tex_resolution[0],
|
||||
context->tex_resolution[1], 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
check_glerror(program);
|
||||
}
|
||||
program->last_resolution[0] = context->resolution[0];
|
||||
program->last_resolution[1] = context->resolution[1];
|
||||
@@ -507,11 +535,11 @@ static void use_program(const ShaderProgram *program, int i, bool output,
|
||||
write_uniform_2f(program->iinres_locations[i * program->in_count + j],
|
||||
&context->input_resolutions[j]);
|
||||
write_uniform_1i(program->iinfmt_locations[i * program->in_count + j],
|
||||
context->input_formats[j]);
|
||||
context->inputs.values[j].pixelformat);
|
||||
write_uniform_1i(program->iinfps_locations[i * program->in_count + j],
|
||||
context->input_fps[j]);
|
||||
context->inputs.values[j].fps);
|
||||
write_uniform_1i(program->iinswap_locations[i * program->in_count + j],
|
||||
context->input_swap[j] ? 1 : 0);
|
||||
context->inputs.values[j].swap ? 1 : 0);
|
||||
}
|
||||
|
||||
// set seeds uniforms
|
||||
@@ -581,6 +609,11 @@ void shaders_init(ShaderProgram *program, const Project *project,
|
||||
program->active_count = project->state_config.midi_active_counts.length;
|
||||
program->midi_lengths.length = 0;
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
memset(program->dma_images, 0, sizeof(program->dma_images));
|
||||
memset(program->dma_images_swap, 0, sizeof(program->dma_images_swap));
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
init_gl(program);
|
||||
|
||||
if (check_glerror(program)) {
|
||||
@@ -625,13 +658,19 @@ void shaders_init(ShaderProgram *program, const Project *project,
|
||||
}
|
||||
}
|
||||
|
||||
void shaders_relink_input(ShaderProgram *program, const Project *project,
|
||||
VideoCaptureArray *inputs, unsigned int i) {
|
||||
#ifdef VIDEO_IN
|
||||
// shaders_free_input(program, i);
|
||||
init_input(program, &project->config, inputs, i, true);
|
||||
#endif /* VIDEO_IN */
|
||||
}
|
||||
|
||||
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;
|
||||
for (unsigned int i = 0; i < program->in_count; i++) {
|
||||
init_input(program, &project->config, inputs, i, false);
|
||||
}
|
||||
#endif /* VIDEO_IN */
|
||||
}
|
||||
@@ -688,14 +727,22 @@ void shaders_free_window(const ShaderProgram *program, bool secondary) {
|
||||
glDeleteVertexArrays(1, &program->vertex_array[secondary ? 1 : 0]);
|
||||
}
|
||||
|
||||
void shaders_free_input(const ShaderProgram *program,
|
||||
const VideoCapture *input) {
|
||||
void shaders_free_input(ShaderProgram *program, unsigned int input_index) {
|
||||
#ifdef VIDEO_IN
|
||||
if (!input->error && input->dma_image != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display, input->dma_image);
|
||||
if (program->dma_images[input_index] != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display, program->dma_images[input_index]);
|
||||
|
||||
program->dma_images[input_index] = EGL_NO_IMAGE_KHR;
|
||||
|
||||
check_eglerror(program, "eglDestroyImageKHR");
|
||||
}
|
||||
if (!input->error && input->dma_image_swap != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display, input->dma_image_swap);
|
||||
if (program->dma_images_swap[input_index] != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display,
|
||||
program->dma_images_swap[input_index]);
|
||||
|
||||
program->dma_images_swap[input_index] = EGL_NO_IMAGE_KHR;
|
||||
|
||||
check_eglerror(program, "eglDestroyImageKHR");
|
||||
}
|
||||
#endif /* VIDEO_IN */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user