[vlc-devel] [PATCH 3/3] Android utils, OpenGL: implement switch NDK / JNI

Louis Regnier louis.videolabs at gmail.com
Mon Apr 6 11:52:01 CEST 2020


If the NDK API requierments are met, native functions (or if not possible JNI)
are saved as default behaviors inside SurfaceTextureHandler pointer structure.

Then, in all cases, wrap pointers of SurfaceTextureHandler in a common function
used by OpenGL to attach / update / detach textures.

fixes #20344
---
 modules/video_output/android/utils.c          | 48 +++++++++++++++++--
 modules/video_output/android/utils.h          |  4 +-
 modules/video_output/opengl/interop_android.c |  2 +-
 3 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 4527977ac5..3a4f139e19 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -32,6 +32,19 @@ typedef ANativeWindow* (*ptr_ANativeWindow_fromSurface)(JNIEnv*, jobject);
 typedef ANativeWindow* (*ptr_ANativeWindow_fromSurfaceTexture)(JNIEnv*, jobject);
 typedef void (*ptr_ANativeWindow_release)(ANativeWindow*);
 
+typedef int (*ptr_SurfaceTexture_attachToGLContext)
+                                        (AWindowHandler *p_awh, uint32_t tex_name);
+typedef int (*ptr_SurfaceTexture_updateTexImage)(AWindowHandler *p_awh,
+                                        const float **pp_transform_mtx);
+typedef void (*ptr_SurfaceTexture_detachFromGLContext)(AWindowHandler *p_awh);
+
+struct SurfaceTextureHandler
+{
+    ptr_SurfaceTexture_attachToGLContext pf_attachToGL;
+    ptr_SurfaceTexture_updateTexImage pf_updateTexImage;
+    ptr_SurfaceTexture_detachFromGLContext pf_detachFromGL;
+};
+
 typedef void (*ptr_ASurfaceTexture_getTransformMatrix)
                                         (ASurfaceTexture *st, float mtx[16]);
 typedef ASurfaceTexture* (*ptr_ASurfaceTexture_fromSurfaceTexture)
@@ -352,7 +365,18 @@ LoadNativeWindowAPI(AWindowHandler *p_awh)
      && p_awh->anw_api.winLock && p_awh->anw_api.unlockAndPost
      && p_awh->anw_api.setBuffersGeometry)
     {
-        LoadSurfaceTextureAPI(p_awh, p_library);
+        if (LoadSurfaceTextureAPI(p_awh, p_library))
+        {
+            p_awh->st.pf_attachToGL = ASurfaceTexture_attachToGLContext;
+            p_awh->st.pf_updateTexImage = ASurfaceTexture_updateTexImage;
+            p_awh->st.pf_detachFromGL = ASurfaceTexture_detachFromGLContext;
+        }
+        else
+        {
+            p_awh->st.pf_attachToGL = JNISurfaceTexture_attachToGLContext;
+            p_awh->st.pf_updateTexImage = JNISurfaceTexture_waitAndUpdateTexImage;
+            p_awh->st.pf_detachFromGL = JNISurfaceTexture_detachFromGLContext;
+        }
         p_awh->p_anw_dl = p_library;
     }
     else
@@ -828,6 +852,12 @@ JNISurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t tex_name)
            VLC_SUCCESS : VLC_EGENERIC;
 }
 
+int
+SurfaceTexture_attachToGLContext(AWindowHandler *p_awh, int tex_name)
+{
+    return p_awh->st.pf_attachToGL(p_awh, tex_name);
+}
+
 static void
 ASurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
 {
@@ -856,9 +886,12 @@ JNISurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
     }
 }
 
-int
-SurfaceTexture_waitAndUpdateTexImage(AWindowHandler *p_awh,
-                                     const float **pp_transform_mtx)
+void
+SurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
+{
+    p_awh->st.pf_detachFromGL(p_awh);
+}
+
 static int
 ASurfaceTexture_updateTexImage(AWindowHandler *p_awh, const float **pp_transform_mtx)
 {
@@ -903,3 +936,10 @@ JNISurfaceTexture_waitAndUpdateTexImage(AWindowHandler *p_awh,
         return VLC_EGENERIC;
     }
 }
+
+int
+SurfaceTexture_updateTexImage(AWindowHandler *p_awh, const float **pp_transform_mtx)
+{
+    return p_awh->st.pf_updateTexImage(p_awh, pp_transform_mtx);
+}
+
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 28aed6c6a1..c4f22cedf6 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -198,5 +198,5 @@ SurfaceTexture_getANativeWindow(AWindowHandler *p_awh)
  * \return VLC_SUCCESS or a VLC error
  */
 int
-SurfaceTexture_waitAndUpdateTexImage(AWindowHandler *p_awh,
-                                     const float **pp_transform_mtx);
+SurfaceTexture_updateTexImage(AWindowHandler *p_awh, const float **pp_transform_mtx);
+
diff --git a/modules/video_output/opengl/interop_android.c b/modules/video_output/opengl/interop_android.c
index f62043944a..29fef17fce 100644
--- a/modules/video_output/opengl/interop_android.c
+++ b/modules/video_output/opengl/interop_android.c
@@ -72,7 +72,7 @@ tc_anop_update(const struct vlc_gl_interop *interop, GLuint *textures,
     if (!priv->avctx->render(pic->context))
         return VLC_SUCCESS; /* already rendered */
 
-    if (SurfaceTexture_waitAndUpdateTexImage(priv->awh, &priv->transform_mtx)
+    if (SurfaceTexture_updateTexImage(priv->awh, &priv->transform_mtx)
         != VLC_SUCCESS)
     {
         priv->transform_mtx = NULL;
-- 
2.26.0



More information about the vlc-devel mailing list