[vlc-devel] [PATCH v4 08/20] opengl: pass output size to filters
Romain Vimont
rom1v at videolabs.io
Tue Jul 7 12:33:51 CEST 2020
A filter may need to specify a different output size.
The input size is accessible via the sampler.
Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>
---
modules/video_output/opengl/filter.c | 9 +++++++--
modules/video_output/opengl/filter.h | 6 ++++++
modules/video_output/opengl/filter_priv.h | 6 ++++--
modules/video_output/opengl/filters.c | 23 +++++++++++++++++++----
modules/video_output/opengl/renderer.c | 2 ++
5 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/modules/video_output/opengl/filter.c b/modules/video_output/opengl/filter.c
index c4ba0bfb71..80a0459be9 100644
--- a/modules/video_output/opengl/filter.c
+++ b/modules/video_output/opengl/filter.c
@@ -41,6 +41,8 @@ vlc_gl_filter_New(vlc_object_t *parent, const struct vlc_gl_api *api)
return NULL;
priv->sampler = NULL;
+ priv->size_out.width = 0;
+ priv->size_out.height = 0;
struct vlc_gl_filter *filter = &priv->filter;
filter->api = api;
@@ -58,9 +60,10 @@ ActivateGLFilter(void *func, bool forced, va_list args)
vlc_gl_filter_open_fn *activate = func;
struct vlc_gl_filter *filter = va_arg(args, struct vlc_gl_filter *);
const config_chain_t *config = va_arg(args, config_chain_t *);
+ struct vlc_gl_tex_size *size_out = va_arg(args, struct vlc_gl_tex_size *);
struct vlc_gl_sampler *sampler = va_arg(args, struct vlc_gl_sampler *);
- return activate(filter, config, sampler);
+ return activate(filter, config, size_out, sampler);
}
#undef vlc_gl_filter_LoadModule
@@ -68,10 +71,12 @@ int
vlc_gl_filter_LoadModule(vlc_object_t *parent, const char *name,
struct vlc_gl_filter *filter,
const config_chain_t *config,
+ struct vlc_gl_tex_size *size_out,
struct vlc_gl_sampler *sampler)
{
filter->module = vlc_module_load(parent, "opengl filter", name, true,
- ActivateGLFilter, filter, config, sampler);
+ ActivateGLFilter, filter, config, size_out,
+ sampler);
if (!filter->module)
return VLC_EGENERIC;
diff --git a/modules/video_output/opengl/filter.h b/modules/video_output/opengl/filter.h
index 8d10002aaa..f6dbd3db23 100644
--- a/modules/video_output/opengl/filter.h
+++ b/modules/video_output/opengl/filter.h
@@ -26,9 +26,15 @@
struct vlc_gl_filter;
+struct vlc_gl_tex_size {
+ unsigned width;
+ unsigned height;
+};
+
typedef int
vlc_gl_filter_open_fn(struct vlc_gl_filter *filter,
const config_chain_t *config,
+ struct vlc_gl_tex_size *size_out,
struct vlc_gl_sampler *sampler);
struct vlc_gl_filter_ops {
diff --git a/modules/video_output/opengl/filter_priv.h b/modules/video_output/opengl/filter_priv.h
index 365ebd0fa9..50134faf50 100644
--- a/modules/video_output/opengl/filter_priv.h
+++ b/modules/video_output/opengl/filter_priv.h
@@ -30,6 +30,7 @@
struct vlc_gl_filter_priv {
struct vlc_gl_filter filter;
+ struct vlc_gl_tex_size size_out;
struct vlc_gl_sampler *sampler; /* owned */
struct vlc_list node; /**< node of vlc_gl_filters.list */
@@ -46,9 +47,10 @@ int
vlc_gl_filter_LoadModule(vlc_object_t *parent, const char *name,
struct vlc_gl_filter *filter,
const config_chain_t *config,
+ struct vlc_gl_tex_size *size_out,
struct vlc_gl_sampler *sampler);
-#define vlc_gl_filter_LoadModule(o, a, b, c, d) \
- vlc_gl_filter_LoadModule(VLC_OBJECT(o), a, b, c, d)
+#define vlc_gl_filter_LoadModule(o, a, b, c, d, e) \
+ vlc_gl_filter_LoadModule(VLC_OBJECT(o), a, b, c, d, e)
void
vlc_gl_filter_Delete(struct vlc_gl_filter *filter);
diff --git a/modules/video_output/opengl/filters.c b/modules/video_output/opengl/filters.c
index 02a2a076ac..47c222f533 100644
--- a/modules/video_output/opengl/filters.c
+++ b/modules/video_output/opengl/filters.c
@@ -83,14 +83,25 @@ vlc_gl_filters_Append(struct vlc_gl_filters *filters, const char *name,
struct vlc_gl_filter_priv *priv = vlc_gl_filter_PRIV(filter);
- bool first_filter = vlc_list_is_empty(&filters->list);
- if (first_filter)
+ struct vlc_gl_tex_size size_in;
+
+ struct vlc_gl_filter_priv *prev_filter =
+ vlc_list_last_entry_or_null(&filters->list, struct vlc_gl_filter_priv,
+ node);
+ if (!prev_filter)
+ {
+ size_in.width = filters->interop->fmt_out.i_visible_width;
+ size_in.height = filters->interop->fmt_out.i_visible_height;
priv->sampler = vlc_gl_sampler_NewFromInterop(filters->interop);
+ }
else
{
+ size_in = prev_filter->size_out;
+
video_format_t fmt;
video_format_Init(&fmt, VLC_CODEC_RGBA);
- // TODO set format width/height
+ fmt.i_width = fmt.i_visible_width = size_in.width;
+ fmt.i_height = fmt.i_visible_height = size_in.height;
priv->sampler =
vlc_gl_sampler_NewFromTexture2D(filters->gl, filters->api, &fmt);
@@ -102,8 +113,12 @@ vlc_gl_filters_Append(struct vlc_gl_filters *filters, const char *name,
return NULL;
}
+ /* By default, the output size is the same as the input size. The filter
+ * may change it during its Open(). */
+ priv->size_out = size_in;
+
int ret = vlc_gl_filter_LoadModule(filters->gl, name, filter, config,
- priv->sampler);
+ &priv->size_out, priv->sampler);
if (ret != VLC_SUCCESS)
{
/* Creation failed, do not call close() */
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 2d8cf56e29..a579163779 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -333,9 +333,11 @@ Draw(struct vlc_gl_filter *filter);
int
vlc_gl_renderer_Open(struct vlc_gl_filter *filter,
const config_chain_t *config,
+ struct vlc_gl_tex_size *size_out,
struct vlc_gl_sampler *sampler)
{
(void) config;
+ (void) size_out;
const opengl_vtable_t *vt = &filter->api->vt;
const video_format_t *fmt = &sampler->fmt;
--
2.27.0
More information about the vlc-devel
mailing list