[vlc-devel] [PATCH 2/3] Android utils, OpenGL: implement wrapper for ASurfaceTexture API

Louis Regnier louis.videolabs at gmail.com
Mon Apr 6 11:52:00 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 | 60 ++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 4 deletions(-)

diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 7158ec6658..4527977ac5 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -792,8 +792,33 @@ AWindowHandler_setVideoLayout(AWindowHandler *p_awh,
     return VLC_SUCCESS;
 }
 
-int
-SurfaceTexture_attachToGLContext(AWindowHandler *p_awh, int tex_name)
+static jobject
+SurfaceTexture_getSurfaceTexture(JNIEnv *p_env, AWindowHandler *p_awh)
+{
+    jobject p_st = JNI_STEXCALL(CallObjectMethod, getSurfaceTexture);
+    return p_st;
+}
+
+static int
+ASurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t texName)
+{
+    JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "SurfaceTexture");
+    if (!p_env)
+        return VLC_EGENERIC;
+
+    JNI_STEXCALL(CallVoidMethod, removeFrameAvailableListener);
+    p_awh->ast_api.surfacetexture = SurfaceTexture_getSurfaceTexture(p_env, p_awh);
+
+    p_awh->ast_api.p_ast = p_awh->ast_api.pf_astFromst(p_env,
+                                                    p_awh->ast_api.surfacetexture);
+    if (p_awh->ast_api.p_ast == NULL)
+        return (VLC_EGENERIC);
+
+    return p_awh->ast_api.pf_attachToGL(p_awh->ast_api.p_ast, texName);
+}
+
+static int
+JNISurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t tex_name)
 {
     JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "SurfaceTexture");
     if (!p_env)
@@ -803,8 +828,16 @@ SurfaceTexture_attachToGLContext(AWindowHandler *p_awh, int tex_name)
            VLC_SUCCESS : VLC_EGENERIC;
 }
 
-void
-SurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
+static void
+ASurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
+{
+    p_awh->ast_api.pf_detachFromGL(p_awh->ast_api.p_ast);
+    if (p_awh->ast_api.p_ast != NULL)
+        p_awh->ast_api.pf_releaseAst(p_awh->ast_api.p_ast);
+}
+
+static void
+JNISurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
 {
     JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "SurfaceTexture");
     if (!p_env)
@@ -826,6 +859,25 @@ SurfaceTexture_detachFromGLContext(AWindowHandler *p_awh)
 int
 SurfaceTexture_waitAndUpdateTexImage(AWindowHandler *p_awh,
                                      const float **pp_transform_mtx)
+static int
+ASurfaceTexture_updateTexImage(AWindowHandler *p_awh, const float **pp_transform_mtx)
+{
+    JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "ASurfaceTexture");
+
+    if (!p_env)
+        return VLC_EGENERIC;
+
+    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;
+}
+
+static int
+JNISurfaceTexture_waitAndUpdateTexImage(AWindowHandler *p_awh,
+                                            const float **pp_transform_mtx)
 {
     JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "SurfaceTexture");
     if (!p_env)
-- 
2.26.0



More information about the vlc-devel mailing list