[vlc-devel] [PATCH v2 13/21] opengl: make interop a vlc_object_t

Romain Vimont rom1v at videolabs.io
Tue Jan 7 12:41:49 CET 2020


In order to pass interop instance to "glconv" modules, they must
"inherit" vlc_object_t.
---
 modules/video_output/opengl/converter.h       |  2 +-
 .../video_output/opengl/converter_android.c   |  2 +-
 modules/video_output/opengl/converter_cvpx.c  |  4 +-
 modules/video_output/opengl/converter_vaapi.c |  6 +--
 modules/video_output/opengl/converter_vdpau.c |  4 +-
 .../video_output/opengl/fragment_shaders.c    |  8 +--
 modules/video_output/opengl/interop.h         |  1 +
 modules/video_output/opengl/vout_helper.c     | 49 +++++++++++--------
 8 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/modules/video_output/opengl/converter.h b/modules/video_output/opengl/converter.h
index a7780ef8db..d835b6a184 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..d0722e486c 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);
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 bea2164d05..46c652fbf6 100644
--- a/modules/video_output/opengl/converter_vaapi.c
+++ b/modules/video_output/opengl/converter_vaapi.c
@@ -289,10 +289,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);
 }
@@ -356,7 +356,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 78441cb469..f499332414 100644
--- a/modules/video_output/opengl/converter_vdpau.c
+++ b/modules/video_output/opengl/converter_vdpau.c
@@ -118,7 +118,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);
 }
@@ -127,7 +127,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 373811cafc..35db79f59a 100644
--- a/modules/video_output/opengl/interop.h
+++ b/modules/video_output/opengl/interop.h
@@ -109,6 +109,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 0cd32183d4..ad9585d13a 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;
 
@@ -1058,8 +1069,7 @@ void vout_display_opengl_Viewport(vout_display_opengl_t *vgl, int x, int y,
 
 bool vout_display_opengl_HasPool(const vout_display_opengl_t *vgl)
 {
-    opengl_tex_converter_t *tc = vgl->prgm->tc;
-    struct vlc_gl_interop *interop = &tc->interop;
+    struct vlc_gl_interop *interop = vgl->prgm->tc->interop;
     return interop->ops->get_pool != NULL;
 }
 
@@ -1070,8 +1080,7 @@ picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned
     if (vgl->pool)
         return vgl->pool;
 
-    opengl_tex_converter_t *tc = vgl->prgm->tc;
-    const struct vlc_gl_interop *interop = &tc->interop;
+    const struct vlc_gl_interop *interop = vgl->prgm->tc->interop;
     requested_count = __MIN(VLCGL_PICTURE_MAX, requested_count);
     /* Allocate with tex converter pool callback if it exists */
     assert(interop->ops->get_pool != NULL);
@@ -1091,7 +1100,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,
@@ -1106,7 +1115,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;
@@ -1453,7 +1462,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;
@@ -1517,7 +1526,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++) {
@@ -1581,7 +1590,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];
@@ -1631,8 +1640,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];
@@ -1673,7 +1682,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);
-- 
2.25.0.rc0



More information about the vlc-devel mailing list