[vlc-devel] [PATCH 03/24] opengl: add interop close() callback
Alexandre Janniaux
ajanni at videolabs.io
Tue Jan 28 16:41:55 CET 2020
Hi,
Maybe you can add a small helper for calling interop->close
to ease reading and writing ? Not important for this
patchset though.
On Mon, Jan 27, 2020 at 09:19:53PM +0100, Romain Vimont wrote:
> Use a callback to close an interop instead of relying on closing the
> module.
>
> This allows to properly close interop_sw, which is not a module.
> ---
> modules/video_output/opengl/interop.h | 6 +++++
> modules/video_output/opengl/interop_android.c | 6 ++---
> modules/video_output/opengl/interop_cvpx.c | 6 ++---
> modules/video_output/opengl/interop_sw.c | 22 ++++++++++---------
> modules/video_output/opengl/interop_vaapi.c | 6 ++---
> modules/video_output/opengl/interop_vdpau.c | 8 +++----
> modules/video_output/opengl/vout_helper.c | 4 ++--
> 7 files changed, 33 insertions(+), 25 deletions(-)
>
> diff --git a/modules/video_output/opengl/interop.h b/modules/video_output/opengl/interop.h
> index 3aa19adf71..4d4667efa6 100644
> --- a/modules/video_output/opengl/interop.h
> +++ b/modules/video_output/opengl/interop.h
> @@ -92,6 +92,12 @@ struct vlc_gl_interop_ops {
> */
> const float *
> (*get_transform_matrix)(const struct vlc_gl_interop *interoporter);
> +
> + /**
> + * Called before the interop is destroyed
> + */
> + void
> + (*close)(struct vlc_gl_interop *interop);
> };
>
> struct vlc_gl_interop {
> diff --git a/modules/video_output/opengl/interop_android.c b/modules/video_output/opengl/interop_android.c
> index 47b4bab328..f62043944a 100644
> --- a/modules/video_output/opengl/interop_android.c
> +++ b/modules/video_output/opengl/interop_android.c
> @@ -93,9 +93,8 @@ tc_get_transform_matrix(const struct vlc_gl_interop *interop)
> }
>
> static void
> -Close(vlc_object_t *obj)
> +Close(struct vlc_gl_interop *interop)
> {
> - struct vlc_gl_interop *interop = (void *)obj;
> struct priv *priv = interop->priv;
>
> if (priv->stex_attached)
> @@ -134,6 +133,7 @@ Open(vlc_object_t *obj)
> .allocate_textures = tc_anop_allocate_textures,
> .update_textures = tc_anop_update,
> .get_transform_matrix = tc_get_transform_matrix,
> + .close = Close,
> };
> interop->ops = &ops;
>
> @@ -184,7 +184,7 @@ Open(vlc_object_t *obj)
> vlc_module_begin ()
> set_description("Android OpenGL SurfaceTexture converter")
> set_capability("glinterop", 1)
> - set_callbacks(Open, Close)
> + set_callback(Open)
> set_category(CAT_VIDEO)
> set_subcategory(SUBCAT_VIDEO_VOUT)
> vlc_module_end ()
> diff --git a/modules/video_output/opengl/interop_cvpx.c b/modules/video_output/opengl/interop_cvpx.c
> index 00171398e3..7c57455d78 100644
> --- a/modules/video_output/opengl/interop_cvpx.c
> +++ b/modules/video_output/opengl/interop_cvpx.c
> @@ -143,9 +143,8 @@ tc_cvpx_update(const struct vlc_gl_interop *interop, GLuint *textures,
> #endif
>
> static void
> -Close(vlc_object_t *obj)
> +Close(struct vlc_gl_interop *interop)
> {
> - struct vlc_gl_interop *interop = (void *) obj;
> struct priv *priv = interop->priv;
>
> #if TARGET_OS_IPHONE
> @@ -280,6 +279,7 @@ Open(vlc_object_t *obj)
> interop->priv = priv;
> static const struct vlc_gl_interop_ops ops = {
> .update_textures = tc_cvpx_update,
> + .close = Close,
> };
> interop->ops = &ops;
>
> @@ -293,7 +293,7 @@ error:
> vlc_module_begin ()
> set_description("Apple OpenGL CVPX converter")
> set_capability("glinterop", 1)
> - set_callbacks(Open, Close)
> + set_callback(Open)
> set_category(CAT_VIDEO)
> set_subcategory(SUBCAT_VIDEO_VOUT)
> vlc_module_end ()
> diff --git a/modules/video_output/opengl/interop_sw.c b/modules/video_output/opengl/interop_sw.c
> index 11c0946c5d..481ebd027e 100644
> --- a/modules/video_output/opengl/interop_sw.c
> +++ b/modules/video_output/opengl/interop_sw.c
> @@ -284,6 +284,16 @@ tc_common_update(const struct vlc_gl_interop *interop, GLuint *textures,
> return ret;
> }
>
> +void
> +opengl_interop_generic_deinit(struct vlc_gl_interop *interop)
> +{
> + struct priv *priv = interop->priv;
> + for (size_t i = 0; i < PBO_DISPLAY_COUNT && priv->pbo.display_pics[i]; ++i)
> + picture_Release(priv->pbo.display_pics[i]);
> + free(priv->texture_temp_buf);
> + free(priv);
> +}
> +
> int
> opengl_interop_generic_init(struct vlc_gl_interop *interop, bool allow_dr)
> {
> @@ -347,6 +357,7 @@ opengl_interop_generic_init(struct vlc_gl_interop *interop, bool allow_dr)
> static const struct vlc_gl_interop_ops ops = {
> .allocate_textures = tc_common_allocate_textures,
> .update_textures = tc_common_update,
> + .close = opengl_interop_generic_deinit,
> };
> interop->ops = &ops;
>
> @@ -371,6 +382,7 @@ opengl_interop_generic_init(struct vlc_gl_interop *interop, bool allow_dr)
> static const struct vlc_gl_interop_ops pbo_ops = {
> .allocate_textures = tc_common_allocate_textures,
> .update_textures = tc_pbo_update,
> + .close = opengl_interop_generic_deinit,
> };
> interop->ops = &pbo_ops;
> msg_Dbg(interop->gl, "PBO support enabled");
> @@ -379,13 +391,3 @@ opengl_interop_generic_init(struct vlc_gl_interop *interop, bool allow_dr)
>
> return VLC_SUCCESS;
> }
> -
> -void
> -opengl_interop_generic_deinit(struct vlc_gl_interop *interop)
> -{
> - struct priv *priv = interop->priv;
> - for (size_t i = 0; i < PBO_DISPLAY_COUNT && priv->pbo.display_pics[i]; ++i)
> - picture_Release(priv->pbo.display_pics[i]);
> - free(priv->texture_temp_buf);
> - free(priv);
> -}
> diff --git a/modules/video_output/opengl/interop_vaapi.c b/modules/video_output/opengl/interop_vaapi.c
> index 7dcbd52124..b11251135f 100644
> --- a/modules/video_output/opengl/interop_vaapi.c
> +++ b/modules/video_output/opengl/interop_vaapi.c
> @@ -227,9 +227,8 @@ error:
> }
>
> static void
> -Close(vlc_object_t *obj)
> +Close(struct vlc_gl_interop *interop)
> {
> - struct vlc_gl_interop *interop = (void *)obj;
> struct priv *priv = interop->priv;
>
> if (priv->last.pic != NULL)
> @@ -412,6 +411,7 @@ Open(vlc_object_t *obj)
>
> static const struct vlc_gl_interop_ops ops = {
> .update_textures = tc_vaegl_update,
> + .close = Close,
> };
> interop->ops = &ops;
>
> @@ -427,7 +427,7 @@ error:
> vlc_module_begin ()
> set_description("VA-API OpenGL surface converter")
> set_capability("glinterop", 1)
> - set_callbacks(Open, Close)
> + set_callback(Open)
> set_category(CAT_VIDEO)
> set_subcategory(SUBCAT_VIDEO_VOUT)
> add_shortcut("vaapi")
> diff --git a/modules/video_output/opengl/interop_vdpau.c b/modules/video_output/opengl/interop_vdpau.c
> index dbffe81926..6625f995a3 100644
> --- a/modules/video_output/opengl/interop_vdpau.c
> +++ b/modules/video_output/opengl/interop_vdpau.c
> @@ -105,9 +105,8 @@ tc_vdpau_gl_update(const struct vlc_gl_interop *interop, GLuint textures[],
> }
>
> static void
> -Close(vlc_object_t *obj)
> +Close(struct vlc_gl_interop *interop)
> {
> - struct vlc_gl_interop *interop = (void *)obj;
> _glVDPAUFiniNV(); assert(interop->vt->GetError() == GL_NO_ERROR);
> converter_sys_t *sys = interop->priv;
> vlc_decoder_device *dec_device = sys->dec_device;
> @@ -180,12 +179,13 @@ Open(vlc_object_t *obj)
> COLOR_SPACE_UNDEF);
> if (ret != VLC_SUCCESS)
> {
> - Close(obj);
> + Close(interop);
> return VLC_EGENERIC;
> }
>
> static const struct vlc_gl_interop_ops ops = {
> .update_textures = tc_vdpau_gl_update,
> + .close = Close,
> };
> interop->ops = &ops;
> interop->priv = sys;
> @@ -230,7 +230,7 @@ DecoderDeviceOpen(vlc_decoder_device *device, vout_window_t *window)
> vlc_module_begin ()
> set_description("VDPAU OpenGL surface converter")
> set_capability("glinterop", 2)
> - set_callbacks(Open, Close)
> + set_callback(Open)
> set_category(CAT_VIDEO)
> set_subcategory(SUBCAT_VIDEO_VOUT)
> add_shortcut("vdpau")
> diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
> index dec3be50c3..7e472f7b62 100644
> --- a/modules/video_output/opengl/vout_helper.c
> +++ b/modules/video_output/opengl/vout_helper.c
> @@ -518,8 +518,8 @@ opengl_deinit_program(vout_display_opengl_t *vgl, struct prgm *prgm)
> struct vlc_gl_interop *interop = tc->interop;
> if (interop->module != NULL)
> module_unneed(interop, interop->module);
> - else if (interop->priv != NULL)
> - opengl_interop_generic_deinit(interop);
> + if (interop->ops && interop->ops->close)
> + interop->ops->close(interop);
> vlc_object_delete(interop);
> if (prgm->id != 0)
> vgl->vt.DeleteProgram(prgm->id);
> --
> 2.25.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list