[vlc-devel] [PATCH 4/5] android: util: implement wrapper for ASurfaceTexture API

Louis Regnier louis.videolabs at gmail.com
Mon Apr 27 23:28:54 CEST 2020


To use new native functions, we wrap ASurfaceTextureAPI structure pointers
inside a new set of native functions, it allow to describe some specifics
behaviors for the NDK API.
---
 modules/video_output/android/utils.c | 50 +++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 62d5ba16b0..cb190a3c53 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -30,6 +30,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)
@@ -76,6 +89,7 @@ struct AWindowHandler
     ptr_ANativeWindow_release pf_winRelease;
     native_window_api_t anw_api;
 
+    struct SurfaceTextureHandler st;
     struct ASurfaceTextureAPI ast_api;
     bool b_has_ast_api;
 
@@ -311,6 +325,13 @@ static int JNI_getSurfaceTexture(JNIEnv *env)
     return 0;
 }
 
+static int
+ASurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t texName);
+static int
+ASurfaceTexture_updateTexImage(AWindowHandler *p_awh, const float **pp_transform_mtx);
+static void
+ASurfaceTexture_detachFromGLContext(AWindowHandler *p_awh);
+
 static int
 LoadSurfaceTextureAPI(AWindowHandler *p_awh, void *p_library)
 {
@@ -373,9 +394,13 @@ LoadNativeWindowAPI(AWindowHandler *p_awh, JNIEnv *p_env)
      && p_awh->anw_api.winLock && p_awh->anw_api.unlockAndPost
      && p_awh->anw_api.setBuffersGeometry)
     {
-        if (LoadSurfaceTextureAPI(p_awh, p_library) == VLC_SUCCESS)
+        if (!LoadSurfaceTextureAPI(p_awh, p_library))
             JNI_getSurfaceTexture(p_env);
         p_awh->b_has_ast_api = false;
+        p_awh->st.pf_attachToGL = ASurfaceTexture_attachToGLContext;
+        p_awh->st.pf_updateTexImage = ASurfaceTexture_updateTexImage;
+        p_awh->st.pf_detachFromGL = ASurfaceTexture_detachFromGLContext;
+
         p_awh->p_anw_dl = p_library;
     }
     else
@@ -869,6 +894,12 @@ AWindowHandler_setVideoLayout(AWindowHandler *p_awh,
     return VLC_SUCCESS;
 }
 
+static int
+ASurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t texName)
+{
+    return p_awh->ast_api.pf_attachToGL(p_awh->ast_api.p_ast, texName);
+}
+
 int
 SurfaceTexture_attachToGLContext(AWindowHandler *p_awh, int tex_name)
 {
@@ -880,6 +911,12 @@ SurfaceTexture_attachToGLContext(AWindowHandler *p_awh, int tex_name)
            VLC_SUCCESS : VLC_EGENERIC;
 }
 
+static void
+ASurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
+{
+    p_awh->ast_api.pf_detachFromGL(p_awh->ast_api.p_ast);
+}
+
 void
 SurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
 {
@@ -900,6 +937,17 @@ SurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
     }
 }
 
+static int
+ASurfaceTexture_updateTexImage(AWindowHandler *p_awh, const float **pp_transform_mtx)
+{
+    if (p_awh->ast_api.pf_updateTexImage(p_awh->ast_api.p_ast))
+        return VLC_EGENERIC;
+
+    p_awh->ast_api.pf_getTransMatrix(p_awh->ast_api.p_ast, p_awh->ast_api.transMat);
+    *pp_transform_mtx = p_awh->ast_api.transMat;
+    return VLC_SUCCESS;
+}
+
 int
 SurfaceTexture_waitAndUpdateTexImage(AWindowHandler *p_awh,
                                      const float **pp_transform_mtx)
-- 
2.26.2



More information about the vlc-devel mailing list