rename device -> video capture

This commit is contained in:
2025-09-22 22:26:24 +02:00
parent 8bfcbfa128
commit 12565aab08
7 changed files with 192 additions and 174 deletions
+27 -25
View File
@@ -69,30 +69,31 @@ static void rebind_textures(ShaderProgram *program) {
}
}
static void link_video_to_texture(ShaderProgram *program, VideoDevice *device,
static void link_video_to_texture(ShaderProgram *program,
VideoCapture *video_capture,
unsigned int texture_index) {
device->dma_image = EGL_NO_IMAGE_KHR;
video_capture->dma_image = EGL_NO_IMAGE_KHR;
const EGLint attrib_list[] = {EGL_WIDTH,
device->width,
video_capture->width,
EGL_HEIGHT,
device->height,
video_capture->height,
EGL_LINUX_DRM_FOURCC_EXT,
device->pixelformat,
video_capture->pixelformat,
EGL_DMA_BUF_PLANE0_FD_EXT,
device->exp_fd,
video_capture->exp_fd,
EGL_DMA_BUF_PLANE0_OFFSET_EXT,
0,
EGL_DMA_BUF_PLANE0_PITCH_EXT,
device->bytesperline,
video_capture->bytesperline,
EGL_NONE};
device->dma_image = eglCreateImageKHR(program->egl_display, EGL_NO_CONTEXT,
EGL_LINUX_DMA_BUF_EXT,
(EGLClientBuffer)NULL, attrib_list);
video_capture->dma_image = eglCreateImageKHR(
program->egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
(EGLClientBuffer)NULL, attrib_list);
if (device->dma_image == EGL_NO_IMAGE_KHR) {
log_error("(%s) eglCreateImageKHR failed %04x", device->name,
if (video_capture->dma_image == EGL_NO_IMAGE_KHR) {
log_error("(%s) eglCreateImageKHR failed %04x", video_capture->name,
eglGetError());
return;
}
@@ -101,27 +102,28 @@ static void link_video_to_texture(ShaderProgram *program, VideoDevice *device,
glBindTexture(GL_TEXTURE_2D, program->textures[texture_index]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, device->width, device->height, 0,
GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, video_capture->width,
video_capture->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)device->dma_image, NULL);
(GLeglImageOES)video_capture->dma_image,
NULL);
log_info("Texture %d linked to %s", texture_index, device->name);
log_info("Texture %d linked to %s", texture_index, video_capture->name);
}
static void init_videos(ShaderProgram *program, ConfigFile shader_config,
VideoDevice *devices, unsigned int device_count) {
VideoCapture *video_captures, unsigned int count) {
unsigned int i;
unsigned tex_i;
char name[32];
for (i = 0; i < program->in_count; i++) {
if (i < device_count && !devices[i].error) {
if (i < count && !video_captures[i].error) {
sprintf(name, "IN_%d_OUT", i + 1);
tex_i = config_file_get_int(shader_config, name, 0);
link_video_to_texture(program, &devices[i], tex_i);
link_video_to_texture(program, &video_captures[i], tex_i);
} else {
log_warn("Cannot link input %d", i + 1);
}
@@ -353,8 +355,8 @@ static void init_programs(ShaderProgram *program, ConfigFile shader_config) {
}
ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
Context context, VideoDevice *devices,
unsigned int device_count, ShaderProgram *previous) {
Context context, VideoCapture *video_captures,
unsigned int count, ShaderProgram *previous) {
ShaderProgram program;
if (previous == NULL) {
@@ -383,7 +385,7 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile shader_config,
init_textures(&program, context);
init_videos(&program, shader_config, devices, device_count);
init_videos(&program, shader_config, video_captures, count);
init_framebuffers(&program, shader_config);
@@ -548,8 +550,8 @@ void shaders_free_window(ShaderProgram program, bool secondary) {
glDeleteVertexArrays(1, &program.vertex_array[secondary ? 1 : 0]);
}
void shaders_free_video(ShaderProgram program, VideoDevice device) {
if (!device.error && device.dma_image != EGL_NO_IMAGE_KHR) {
eglDestroyImageKHR(program.egl_display, device.dma_image);
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);
}
}