[vlc-devel] [PATCH 08/27] opengl: load filters from command-line arguments
Romain Vimont
rom1v at videolabs.io
Thu Jun 25 14:22:55 CEST 2020
Enable OpenGL filters via the --gl-filters command-line option:
vlc file.mkv --gl-filters=filter1:filter2
Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>
---
modules/video_output/caopengllayer.m | 6 +-
modules/video_output/ios.m | 9 ++-
modules/video_output/macosx.m | 6 +-
modules/video_output/opengl/display.c | 8 ++-
modules/video_output/opengl/vout_helper.c | 76 +++++++++++++++++++----
modules/video_output/opengl/vout_helper.h | 6 +-
modules/video_output/win32/glwin32.c | 6 +-
7 files changed, 97 insertions(+), 20 deletions(-)
diff --git a/modules/video_output/caopengllayer.m b/modules/video_output/caopengllayer.m
index 16e8de1c36..c9772bd62a 100644
--- a/modules/video_output/caopengllayer.m
+++ b/modules/video_output/caopengllayer.m
@@ -57,6 +57,7 @@ vlc_module_begin()
set_category(CAT_VIDEO)
set_subcategory(SUBCAT_VIDEO_VOUT)
set_callback_display(Open, 0)
+ add_opengl_param_gl_filters()
add_opengl_submodule_renderer()
vlc_module_end()
@@ -183,8 +184,11 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
const vlc_fourcc_t *subpicture_chromas;
if (!OpenglLock(sys->gl)) {
+ char *glfilters_config = var_InheritString(vd, "gl-filters");
sys->vgl = vout_display_opengl_New(fmt, &subpicture_chromas,
- sys->gl, &cfg->viewpoint, context);
+ sys->gl, &cfg->viewpoint,
+ context, glfilters_config);
+ free(glfilters_config);
OpenglUnlock(sys->gl);
} else
sys->vgl = NULL;
diff --git a/modules/video_output/ios.m b/modules/video_output/ios.m
index 637a140146..1236bd7111 100644
--- a/modules/video_output/ios.m
+++ b/modules/video_output/ios.m
@@ -77,6 +77,7 @@ vlc_module_begin ()
add_shortcut("vout_ios2", "vout_ios")
add_glopts()
+ add_opengl_param_gl_filters()
add_opengl_submodule_renderer()
vlc_module_end ()
@@ -196,9 +197,11 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
if (vlc_gl_MakeCurrent(sys->gl) != VLC_SUCCESS)
goto bailout;
- vout_display_opengl_t *vgl = vout_display_opengl_New(fmt, &subpicture_chromas,
- sys->gl, &cfg->viewpoint,
- context);
+ char *glfilters_config = var_InheritString(vd, "gl-filters");
+ vout_display_opengl_t *vgl =
+ vout_display_opengl_New(fmt, &subpicture_chromas, sys->gl,
+ &cfg->viewpoint, context, glfilters_config);
+ free(glfilters_config);
vlc_gl_ReleaseCurrent(sys->gl);
if (!vgl)
goto bailout;
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index a714b59f6e..7a9fedd650 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -79,6 +79,7 @@ vlc_module_begin ()
set_callback_display(Open, 300)
add_shortcut ("macosx", "vout_macosx")
add_glopts ()
+ add_opengl_param_gl_filters()
add_opengl_submodule_renderer()
vlc_module_end ()
@@ -228,8 +229,11 @@ static int Open (vout_display_t *vd, const vout_display_cfg_t *cfg,
msg_Err(vd, "Can't attach gl context");
goto error;
}
+ char *glfilters_config = var_InheritString(vd, "gl-filters");
sys->vgl = vout_display_opengl_New (fmt, &subpicture_chromas, sys->gl,
- &cfg->viewpoint, context);
+ &cfg->viewpoint, context,
+ glfilters_config);
+ free(glfilters_config);
vlc_gl_ReleaseCurrent(sys->gl);
if (!sys->vgl) {
msg_Err(vd, "Error while initializing opengl display.");
diff --git a/modules/video_output/opengl/display.c b/modules/video_output/opengl/display.c
index b7f6b44f15..4e7346f764 100644
--- a/modules/video_output/opengl/display.c
+++ b/modules/video_output/opengl/display.c
@@ -68,6 +68,7 @@ vlc_module_begin ()
add_module("gl", "opengl", NULL, GL_TEXT, PROVIDER_LONGTEXT)
#endif
add_glopts ()
+ add_opengl_param_gl_filters()
add_opengl_submodule_renderer()
vlc_module_end ()
@@ -138,8 +139,11 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
if (vlc_gl_MakeCurrent (sys->gl))
goto error;
- sys->vgl = vout_display_opengl_New (fmt, &spu_chromas, sys->gl,
- &cfg->viewpoint, context);
+ char *glfilters_config = var_InheritString(vd, "gl-filters");
+ sys->vgl = vout_display_opengl_New(fmt, &spu_chromas, sys->gl,
+ &cfg->viewpoint, context,
+ glfilters_config);
+ free(glfilters_config);
vlc_gl_ReleaseCurrent (sys->gl);
if (sys->vgl == NULL)
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 22ca7350ea..47e078e532 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -98,11 +98,72 @@ ResizeFormatToGLMaxTexSize(video_format_t *fmt, unsigned int max_tex_size)
}
}
+static int
+LoadFilters(vlc_gl_t *gl, struct vlc_gl_filters *filters,
+ const char *glfilters_config, struct vlc_gl_renderer **out_renderer)
+{
+ struct vlc_gl_filter *renderer_filter = NULL;
+
+ if (glfilters_config)
+ {
+ const char *string = glfilters_config;
+ char *next_module = NULL;
+ do
+ {
+ char *name;
+ config_chain_t *config = NULL;
+ char *leftover = config_ChainCreate(&name, &config, string);
+
+ free(next_module);
+ next_module = leftover;
+ string = next_module; /* const view of next_module */
+
+ if (name)
+ {
+ struct vlc_gl_filter *filter =
+ vlc_gl_filters_Append(filters, name, config);
+ config_ChainDestroy(config);
+ if (!filter)
+ {
+ msg_Err(gl, "Could not load GL filter: %s", name);
+ free(name);
+ return VLC_EGENERIC;
+ }
+
+ if (!strcmp("renderer", name))
+ renderer_filter = filter;
+
+ free(name);
+ }
+ } while (string);
+ }
+
+ if (!renderer_filter)
+ {
+ /* Append a renderer at the end if it was not provided in the glfilters
+ * list */
+ renderer_filter =
+ vlc_gl_filters_Append(filters, "renderer", NULL);
+ if (!renderer_filter)
+ {
+ msg_Err(gl, "Could not load GL renderer");
+ return VLC_EGENERIC;
+ }
+ }
+
+ /* The renderer is a special filter: we need its concrete instance to
+ * forward SetViewpoint() */
+ *out_renderer = renderer_filter->sys;
+
+ return VLC_SUCCESS;
+}
+
vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
const vlc_fourcc_t **subpicture_chromas,
vlc_gl_t *gl,
const vlc_viewpoint_t *viewpoint,
- vlc_video_context *context)
+ vlc_video_context *context,
+ const char *glfilters_config)
{
vout_display_opengl_t *vgl = calloc(1, sizeof(*vgl));
if (!vgl)
@@ -150,20 +211,13 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
goto delete_interop;
}
- /* The renderer is the only filter, for now */
- struct vlc_gl_filter *renderer_filter =
- vlc_gl_filters_Append(vgl->filters, "renderer", NULL);
- if (!renderer_filter)
+ ret = LoadFilters(gl, vgl->filters, glfilters_config, &vgl->renderer);
+ if (ret != VLC_SUCCESS)
{
- msg_Warn(gl, "Could not create renderer for %4.4s",
- (const char *) &fmt->i_chroma);
+ msg_Err(gl, "Could not load filters: %s", glfilters_config);
goto delete_filters;
}
- /* The renderer is a special filter: we need its concrete instance to
- * forward SetViewpoint() */
- vgl->renderer = renderer_filter->sys;
-
vgl->sub_interop = vlc_gl_interop_NewForSubpictures(gl, api);
if (!vgl->sub_interop)
{
diff --git a/modules/video_output/opengl/vout_helper.h b/modules/video_output/opengl/vout_helper.h
index 482eabb554..1d84201d94 100644
--- a/modules/video_output/opengl/vout_helper.h
+++ b/modules/video_output/opengl/vout_helper.h
@@ -84,13 +84,17 @@
add_module("glinterop", "glinterop", NULL, GLINTEROP_TEXT, GLINTEROP_LONGTEXT) \
add_glopts_placebo ()
+#define add_opengl_param_gl_filters() \
+ add_module_list("gl-filters", "opengl filter", NULL, "GL filters", "GL filters")
+
typedef struct vout_display_opengl_t vout_display_opengl_t;
vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
const vlc_fourcc_t **subpicture_chromas,
vlc_gl_t *gl,
const vlc_viewpoint_t *viewpoint,
- vlc_video_context *context);
+ vlc_video_context *context,
+ const char *glfilters_config);
void vout_display_opengl_Delete(vout_display_opengl_t *vgl);
int vout_display_opengl_SetViewpoint(vout_display_opengl_t *vgl, const vlc_viewpoint_t*);
diff --git a/modules/video_output/win32/glwin32.c b/modules/video_output/win32/glwin32.c
index c09f543d84..3aebe25180 100644
--- a/modules/video_output/win32/glwin32.c
+++ b/modules/video_output/win32/glwin32.c
@@ -54,6 +54,7 @@ vlc_module_begin()
add_shortcut("glwin32", "opengl")
set_callback_display(Open, 275)
add_glopts()
+ add_opengl_param_gl_filters()
add_opengl_submodule_renderer()
vlc_module_end()
@@ -153,8 +154,11 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
const vlc_fourcc_t *subpicture_chromas;
if (vlc_gl_MakeCurrent (sys->gl))
goto error;
+ char *glfilters_config = var_InheritString(vd, "gl-filters");
sys->vgl = vout_display_opengl_New(&fmt, &subpicture_chromas, sys->gl,
- &cfg->viewpoint, context);
+ &cfg->viewpoint, context,
+ glfilters_config);
+ free(glfilters_config);
vlc_gl_ReleaseCurrent (sys->gl);
if (!sys->vgl)
goto error;
--
2.27.0
More information about the vlc-devel
mailing list