[vlc-devel] [PATCH 2/5] android: util: load ASurfaceTexture API
Louis Regnier
louis.videolabs at gmail.com
Mon Apr 27 23:28:52 CEST 2020
Load the new Android NDK API to manage SurfaceTexture, which
is available since Android API 28.
---
modules/video_output/android/utils.c | 75 ++++++++++++++++++++++++++++
modules/video_output/android/utils.h | 1 +
2 files changed, 76 insertions(+)
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index cdd2b97df4..8a300b05bb 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -30,6 +30,36 @@ typedef ANativeWindow* (*ptr_ANativeWindow_fromSurface)(JNIEnv*, jobject);
typedef ANativeWindow* (*ptr_ANativeWindow_fromSurfaceTexture)(JNIEnv*, jobject);
typedef void (*ptr_ANativeWindow_release)(ANativeWindow*);
+typedef void (*ptr_ASurfaceTexture_getTransformMatrix)
+ (ASurfaceTexture *st, float mtx[16]);
+typedef ASurfaceTexture* (*ptr_ASurfaceTexture_fromSurfaceTexture)
+ (JNIEnv* env, jobject surfacetexture);
+typedef int (*ptr_ASurfaceTexture_updateTexImage)(ASurfaceTexture* st);
+typedef int (*ptr_ASurfaceTexture_detachFromGLContext)
+ (ASurfaceTexture *st);
+typedef int (*ptr_ASurfaceTexture_attachToGLContext)
+ (ASurfaceTexture *st, uint32_t texName);
+typedef void (*ptr_ASurfaceTexture_release)(ASurfaceTexture *st);
+typedef ANativeWindow* (*ptr_ASurfaceTexture_acquireANativeWindow) (ASurfaceTexture *st);
+typedef jobject (*ptr_ANativeWindow_toSurface) (JNIEnv *env, ANativeWindow *window);
+
+struct ASurfaceTextureAPI
+{
+ float transMat[16];
+
+ jobject surfacetexture;
+ ASurfaceTexture *p_ast;
+
+ ptr_ASurfaceTexture_updateTexImage pf_updateTexImage;
+ ptr_ASurfaceTexture_fromSurfaceTexture pf_astFromst;
+ ptr_ASurfaceTexture_attachToGLContext pf_attachToGL;
+ ptr_ASurfaceTexture_detachFromGLContext pf_detachFromGL;
+ ptr_ASurfaceTexture_getTransformMatrix pf_getTransMatrix;
+ ptr_ASurfaceTexture_release pf_releaseAst;
+ ptr_ASurfaceTexture_acquireANativeWindow pf_acquireAnw;
+ ptr_ANativeWindow_toSurface pf_anwToSurface;
+};
+
struct AWindowHandler
{
JavaVM *p_jvm;
@@ -46,6 +76,8 @@ struct AWindowHandler
ptr_ANativeWindow_release pf_winRelease;
native_window_api_t anw_api;
+ struct ASurfaceTextureAPI ast_api;
+
struct {
awh_events_t cb;
} event;
@@ -248,6 +280,48 @@ LoadNativeSurfaceAPI(AWindowHandler *p_awh)
p_awh->anw_api.setBuffersGeometry = NULL;
}
+/*
+ * Android ASurfaceTexture Android NDK
+ */
+
+static int
+LoadSurfaceTextureAPI(AWindowHandler *p_awh, void *p_library)
+{
+ p_awh->ast_api.pf_astFromst = (ptr_ASurfaceTexture_fromSurfaceTexture)
+ dlsym(p_library, "ASurfaceTexture_fromSurfaceTexture");
+ if (p_awh->ast_api.pf_astFromst == NULL) return VLC_EGENERIC;
+
+ p_awh->ast_api.pf_updateTexImage = (ptr_ASurfaceTexture_updateTexImage)
+ dlsym(p_library, "ASurfaceTexture_updateTexImage");
+ if (p_awh->ast_api.pf_updateTexImage == NULL) return VLC_EGENERIC;
+
+ p_awh->ast_api.pf_attachToGL = (ptr_ASurfaceTexture_attachToGLContext)
+ dlsym(p_library, "ASurfaceTexture_attachToGLContext");
+ if (p_awh->ast_api.pf_attachToGL == NULL) return VLC_EGENERIC;
+
+ p_awh->ast_api.pf_detachFromGL = (ptr_ASurfaceTexture_detachFromGLContext)
+ dlsym(p_library, "ASurfaceTexture_detachFromGLContext");
+ if (p_awh->ast_api.pf_detachFromGL == NULL) return VLC_EGENERIC;
+
+ p_awh->ast_api.pf_getTransMatrix = (ptr_ASurfaceTexture_getTransformMatrix)
+ dlsym(p_library, "ASurfaceTexture_getTransformMatrix");
+ if (p_awh->ast_api.pf_getTransMatrix == NULL) return VLC_EGENERIC;
+
+ p_awh->ast_api.pf_releaseAst = (ptr_ASurfaceTexture_release)
+ dlsym(p_library, "ASurfaceTexture_release");
+ if (p_awh->ast_api.pf_releaseAst == NULL) return VLC_EGENERIC;
+
+ p_awh->ast_api.pf_acquireAnw = (ptr_ASurfaceTexture_acquireANativeWindow)
+ dlsym(p_library, "ASurfaceTexture_acquireANativeWindow");
+ if (p_awh->ast_api.pf_acquireAnw == NULL) return VLC_EGENERIC;
+
+ p_awh->ast_api.pf_anwToSurface = (ptr_ANativeWindow_toSurface)
+ dlsym(p_library, "ANativeWindow_toSurface");
+ if (p_awh->ast_api.pf_anwToSurface == NULL) return VLC_EGENERIC;
+
+ return VLC_SUCCESS;
+}
+
/*
* Android NativeWindow (post android 2.3)
*/
@@ -272,6 +346,7 @@ LoadNativeWindowAPI(AWindowHandler *p_awh)
&& p_awh->anw_api.winLock && p_awh->anw_api.unlockAndPost
&& p_awh->anw_api.setBuffersGeometry)
{
+ LoadSurfaceTextureAPI(p_awh, p_library);
p_awh->p_anw_dl = p_library;
}
else
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 35ccc41906..28aed6c6a1 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -34,6 +34,7 @@
#include <vlc_common.h>
typedef struct AWindowHandler AWindowHandler;
+typedef struct ASurfaceTexture ASurfaceTexture;
enum AWindow_ID {
AWindow_Video,
--
2.26.2
More information about the vlc-devel
mailing list