[vlc-commits] opengl: make interop a vlc_object_t

Romain Vimont git at videolan.org
Mon Jan 13 11:44:21 CET 2020


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Thu Dec  5 11:20:39 2019 +0100| [6577b56f43a3a34aeded483ddf3e1803679e105a] | committer: Thomas Guillem

opengl: make interop a vlc_object_t

In order to pass interop instance to "glconv" modules, they must
"inherit" vlc_object_t.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6577b56f43a3a34aeded483ddf3e1803679e105a
---

 modules/hw/nvdec/nvdec_gl.c                     |  4 +--
 modules/video_output/opengl/converter.h         |  2 +-
 modules/video_output/opengl/converter_android.c |  4 +--
 modules/video_output/opengl/converter_cvpx.c    |  4 +--
 modules/video_output/opengl/converter_vaapi.c   |  6 ++--
 modules/video_output/opengl/converter_vdpau.c   |  4 +--
 modules/video_output/opengl/fragment_shaders.c  |  8 ++---
 modules/video_output/opengl/interop.h           |  1 +
 modules/video_output/opengl/vout_helper.c       | 43 ++++++++++++++++---------
 modules/video_output/win32/direct3d9.c          |  4 +--
 10 files changed, 46 insertions(+), 34 deletions(-)

diff --git a/modules/hw/nvdec/nvdec_gl.c b/modules/hw/nvdec/nvdec_gl.c
index a6ff6ccf69..f6b808a477 100644
--- a/modules/hw/nvdec/nvdec_gl.c
+++ b/modules/hw/nvdec/nvdec_gl.c
@@ -147,14 +147,14 @@ error:
 static void Close(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *)obj;
-    converter_sys_t *p_sys = tc->interop.priv;
+    converter_sys_t *p_sys = tc->interop->priv;
     vlc_decoder_device_Release(p_sys->device);
 }
 
 static int Open(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *) obj;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
     if (!is_nvdec_opaque(interop->fmt.i_chroma))
         return VLC_EGENERIC;
 
diff --git a/modules/video_output/opengl/converter.h b/modules/video_output/opengl/converter.h
index 7692f269c6..417e7dfc58 100644
--- a/modules/video_output/opengl/converter.h
+++ b/modules/video_output/opengl/converter.h
@@ -87,7 +87,7 @@ struct opengl_tex_converter_t
     struct pl_shader *pl_sh;
     const struct pl_shader_res *pl_sh_res;
 
-    struct vlc_gl_interop interop;
+    struct vlc_gl_interop *interop;
 
     /**
      * Callback to fetch locations of uniform or attributes variables
diff --git a/modules/video_output/opengl/converter_android.c b/modules/video_output/opengl/converter_android.c
index 0bdca07c2c..36e8f2b6da 100644
--- a/modules/video_output/opengl/converter_android.c
+++ b/modules/video_output/opengl/converter_android.c
@@ -94,7 +94,7 @@ static void
 Close(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *)obj;
-    struct priv *priv = tc->interop.priv;
+    struct priv *priv = tc->interop->priv;
 
     if (priv->stex_attached)
         SurfaceTexture_detachFromGLContext(priv->awh);
@@ -106,7 +106,7 @@ static int
 Open(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *) obj;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     if (interop->fmt.i_chroma != VLC_CODEC_ANDROID_OPAQUE
      || !interop->gl->surface->handle.anativewindow
diff --git a/modules/video_output/opengl/converter_cvpx.c b/modules/video_output/opengl/converter_cvpx.c
index c5978a23b2..68047d2eae 100644
--- a/modules/video_output/opengl/converter_cvpx.c
+++ b/modules/video_output/opengl/converter_cvpx.c
@@ -144,7 +144,7 @@ static void
 Close(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *)obj;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
     struct priv *priv = interop->priv;
 
 #if TARGET_OS_IPHONE
@@ -165,7 +165,7 @@ static int
 Open(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *) obj;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     if (interop->fmt.i_chroma != VLC_CODEC_CVPX_UYVY
      && interop->fmt.i_chroma != VLC_CODEC_CVPX_NV12
diff --git a/modules/video_output/opengl/converter_vaapi.c b/modules/video_output/opengl/converter_vaapi.c
index e33e882aee..c99a04239b 100644
--- a/modules/video_output/opengl/converter_vaapi.c
+++ b/modules/video_output/opengl/converter_vaapi.c
@@ -229,10 +229,10 @@ static void
 Close(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *)obj;
-    struct priv *priv = tc->interop.priv;
+    struct priv *priv = tc->interop->priv;
 
     if (priv->last.pic != NULL)
-        vaegl_release_last_pic(&tc->interop, priv);
+        vaegl_release_last_pic(tc->interop, priv);
 
     free(priv);
 }
@@ -339,7 +339,7 @@ static int
 Open(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *) obj;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     if (interop->vctx == NULL)
         return VLC_EGENERIC;
diff --git a/modules/video_output/opengl/converter_vdpau.c b/modules/video_output/opengl/converter_vdpau.c
index bf5461ddd4..c813a21243 100644
--- a/modules/video_output/opengl/converter_vdpau.c
+++ b/modules/video_output/opengl/converter_vdpau.c
@@ -107,7 +107,7 @@ Close(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *)obj;
     _glVDPAUFiniNV(); assert(tc->vt->GetError() == GL_NO_ERROR);
-    converter_sys_t *sys = tc->interop.priv;
+    converter_sys_t *sys = tc->interop->priv;
     vlc_decoder_device *dec_device = sys->dec_device;
     vlc_decoder_device_Release(dec_device);
 }
@@ -116,7 +116,7 @@ static int
 Open(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *) obj;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     if (interop->vctx == NULL)
         return VLC_EGENERIC;
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 9d73088509..d8a3d965fc 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -303,7 +303,7 @@ interop_rgb_base_init(struct vlc_gl_interop *interop, GLenum tex_target,
 static int
 tc_base_fetch_locations(opengl_tex_converter_t *tc, GLuint program)
 {
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     if (tc->yuv_color)
     {
@@ -350,7 +350,7 @@ tc_base_prepare_shader(const opengl_tex_converter_t *tc,
                        float alpha)
 {
     (void) tex_width; (void) tex_height;
-    const struct vlc_gl_interop *interop = &tc->interop;
+    const struct vlc_gl_interop *interop = tc->interop;
 
     if (tc->yuv_color)
         tc->vt->Uniform4fv(tc->uloc.Coefficients, 4, tc->yuv_coefficients);
@@ -567,7 +567,7 @@ GLuint
 opengl_fragment_shader_init_impl(opengl_tex_converter_t *tc, GLenum tex_target,
                                  vlc_fourcc_t chroma, video_color_space_t yuv_space)
 {
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     const char *swizzle_per_tex[PICTURE_PLANE_MAX] = { NULL, };
     const bool is_yuv = vlc_fourcc_IsYUV(chroma);
@@ -586,7 +586,7 @@ opengl_fragment_shader_init_impl(opengl_tex_converter_t *tc, GLenum tex_target,
         ret = tc_yuv_base_init(tc, chroma, desc, yuv_space, &yuv_swap_uv);
         if (ret != VLC_SUCCESS)
             return 0;
-        ret = opengl_init_swizzle(&tc->interop, swizzle_per_tex, chroma, desc);
+        ret = opengl_init_swizzle(tc->interop, swizzle_per_tex, chroma, desc);
         if (ret != VLC_SUCCESS)
             return 0;
     }
diff --git a/modules/video_output/opengl/interop.h b/modules/video_output/opengl/interop.h
index 069bc623ef..32bdf3cfd9 100644
--- a/modules/video_output/opengl/interop.h
+++ b/modules/video_output/opengl/interop.h
@@ -95,6 +95,7 @@ struct vlc_gl_interop_ops {
 };
 
 struct vlc_gl_interop {
+    vlc_object_t obj;
     vlc_gl_t *gl;
     const opengl_vtable_t *vt;
     GLenum tex_target;
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index ad082983e7..d74e8fefc7 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -346,7 +346,7 @@ static GLuint BuildVertexShader(const opengl_tex_converter_t *tc,
     tc->vt->ShaderSource(shader, 1, (const char **) &code, NULL);
     if (tc->b_dump_shaders)
         msg_Dbg(tc->gl, "\n=== Vertex shader for fourcc: %4.4s ===\n%s\n",
-                (const char *)&tc->interop.fmt.i_chroma, code);
+                (const char *)&tc->interop->fmt.i_chroma, code);
     tc->vt->CompileShader(shader);
     free(code);
     return shader;
@@ -399,7 +399,7 @@ static int
 opengl_link_program(struct prgm *prgm)
 {
     opengl_tex_converter_t *tc = prgm->tc;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     GLuint vertex_shader = BuildVertexShader(tc, interop->tex_count);
     GLuint shaders[] = { tc->fshader, vertex_shader };
@@ -506,11 +506,12 @@ static void
 opengl_deinit_program(vout_display_opengl_t *vgl, struct prgm *prgm)
 {
     opengl_tex_converter_t *tc = prgm->tc;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
     if (tc->p_module != NULL)
         module_unneed(tc, tc->p_module);
     else if (interop->priv != NULL)
         opengl_interop_generic_deinit(interop);
+    vlc_object_delete(tc->interop);
     if (prgm->id != 0)
         vgl->vt.DeleteProgram(prgm->id);
 
@@ -534,7 +535,14 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
     if (tc == NULL)
         return VLC_ENOMEM;
 
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = vlc_object_create(tc, sizeof(*interop));
+    if (!interop)
+    {
+        vlc_object_delete(tc);
+        return VLC_ENOMEM;
+    }
+
+    tc->interop = interop;
 
     tc->gl = vgl->gl;
     tc->vt = &vgl->vt;
@@ -597,6 +605,7 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
 
         if (desc == NULL)
         {
+            vlc_object_delete(interop);
             vlc_object_delete(tc);
             return VLC_EGENERIC;
         }
@@ -619,6 +628,7 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
 
     if (ret != VLC_SUCCESS)
     {
+        vlc_object_delete(interop);
         vlc_object_delete(tc);
         return VLC_EGENERIC;
     }
@@ -629,6 +639,7 @@ opengl_init_program(vout_display_opengl_t *vgl, vlc_video_context *context,
                                          interop->sw_fmt.space);
     if (!fragment_shader)
     {
+        vlc_object_delete(interop);
         vlc_object_delete(tc);
         return VLC_EGENERIC;
     }
@@ -865,7 +876,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
     }
     GL_ASSERT_NOERROR();
 
-    const struct vlc_gl_interop *interop = &vgl->prgm->tc->interop;
+    const struct vlc_gl_interop *interop = vgl->prgm->tc->interop;
     /* Update the fmt to main program one */
     vgl->fmt = interop->fmt;
     /* The orientation is handled by the orientation matrix */
@@ -887,11 +898,11 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
     }
 
     /* Allocates our textures */
-    assert(!vgl->sub_prgm->tc->interop.handle_texs_gen);
+    assert(!vgl->sub_prgm->tc->interop->handle_texs_gen);
 
     if (!interop->handle_texs_gen)
     {
-        ret = GenTextures(&vgl->prgm->tc->interop, vgl->tex_width, vgl->tex_height,
+        ret = GenTextures(vgl->prgm->tc->interop, vgl->tex_width, vgl->tex_height,
                           vgl->texture);
         if (ret != VLC_SUCCESS)
         {
@@ -951,7 +962,7 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
     vgl->vt.Finish();
     vgl->vt.Flush();
 
-    const struct vlc_gl_interop *interop = &vgl->prgm->tc->interop;
+    const struct vlc_gl_interop *interop = vgl->prgm->tc->interop;
     const size_t main_tex_count = interop->tex_count;
     const bool main_del_texs = !interop->handle_texs_gen;
 
@@ -1062,7 +1073,7 @@ int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
     GL_ASSERT_NOERROR();
 
     opengl_tex_converter_t *tc = vgl->prgm->tc;
-    const struct vlc_gl_interop *interop = &tc->interop;
+    const struct vlc_gl_interop *interop = tc->interop;
 
     /* Update the texture */
     int ret = interop->ops->update_textures(interop, vgl->texture, vgl->tex_width, vgl->tex_height,
@@ -1077,7 +1088,7 @@ int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
     vgl->region       = NULL;
 
     tc = vgl->sub_prgm->tc;
-    interop = &tc->interop;
+    interop = tc->interop;
     if (subpicture) {
 
         int count = 0;
@@ -1424,7 +1435,7 @@ static int SetupCoords(vout_display_opengl_t *vgl,
                        const float *left, const float *top,
                        const float *right, const float *bottom)
 {
-    const struct vlc_gl_interop *interop = &vgl->prgm->tc->interop;
+    const struct vlc_gl_interop *interop = vgl->prgm->tc->interop;
 
     GLfloat *vertexCoord, *textureCoord;
     GLushort *indices;
@@ -1488,7 +1499,7 @@ static int SetupCoords(vout_display_opengl_t *vgl,
 static void DrawWithShaders(vout_display_opengl_t *vgl, struct prgm *prgm)
 {
     opengl_tex_converter_t *tc = prgm->tc;
-    const struct vlc_gl_interop *interop = &tc->interop;
+    const struct vlc_gl_interop *interop = tc->interop;
     tc->pf_prepare_shader(tc, vgl->tex_width, vgl->tex_height, 1.0f);
 
     for (unsigned j = 0; j < interop->tex_count; j++) {
@@ -1552,7 +1563,7 @@ static void TextureCropForStereo(vout_display_opengl_t *vgl,
                                  float *left, float *top,
                                  float *right, float *bottom)
 {
-    const struct vlc_gl_interop *interop = &vgl->prgm->tc->interop;
+    const struct vlc_gl_interop *interop = vgl->prgm->tc->interop;
 
     float stereoCoefs[2];
     float stereoOffsets[2];
@@ -1602,8 +1613,8 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
         float right[PICTURE_PLANE_MAX];
         float bottom[PICTURE_PLANE_MAX];
         const opengl_tex_converter_t *tc = vgl->prgm->tc;
-        const struct vlc_gl_interop *interop = &tc->interop;
-        for (unsigned j = 0; j < tc->interop.tex_count; j++)
+        const struct vlc_gl_interop *interop = tc->interop;
+        for (unsigned j = 0; j < interop->tex_count; j++)
         {
             float scale_w = (float)interop->texs[j].w.num / interop->texs[j].w.den
                           / vgl->tex_width[j];
@@ -1644,7 +1655,7 @@ int vout_display_opengl_Display(vout_display_opengl_t *vgl,
     struct prgm *prgm = vgl->sub_prgm;
     GLuint program = prgm->id;
     opengl_tex_converter_t *tc = prgm->tc;
-    const struct vlc_gl_interop *interop = &tc->interop;
+    const struct vlc_gl_interop *interop = tc->interop;
     vgl->vt.UseProgram(program);
 
     vgl->vt.Enable(GL_BLEND);
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 3d8fca052b..01727c1f4f 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -1763,7 +1763,7 @@ static void
 GLConvClose(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *)obj;
-    struct glpriv *priv = tc->interop.priv;
+    struct glpriv *priv = tc->interop->priv;
 
     if (priv->gl_handle_d3d)
     {
@@ -1786,7 +1786,7 @@ static int
 GLConvOpen(vlc_object_t *obj)
 {
     opengl_tex_converter_t *tc = (void *) obj;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = tc->interop;
 
     if (interop->fmt.i_chroma != VLC_CODEC_D3D9_OPAQUE
      && interop->fmt.i_chroma != VLC_CODEC_D3D9_OPAQUE_10B)



More information about the vlc-commits mailing list