[vlc-commits] android: utils: load Surface JNI API

Alexandre Janniaux git at videolan.org
Wed Jul 8 17:52:49 CEST 2020


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Jun 24 15:14:30 2020 +0200| [60f21e5e1b6f65ea8a8a33b43af19c9039e05f4f] | committer: Alexandre Janniaux

android: utils: load Surface JNI API

When creating a SurfaceTexture JNI object, we can, with recent API,
transform the SurfaceTexture into an ASurfaceTexture NDK object.
However, with previous Android version, the only way is to create the
Surface JNI object directly from the SurfaceTexture JNI object, and then
convert the Surface into a ANativeWindow NDK object for the producer
side.

This patch loads the class and the constructor taking a reference to
SurfaceTexture.

Signed-off-by: Alexandre Janniaux <ajanni at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=60f21e5e1b6f65ea8a8a33b43af19c9039e05f4f
---

 modules/video_output/android/utils.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 92d3abdf88..5ec872f2e8 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -133,6 +133,10 @@ static struct
           jmethodID init_iz;
           jmethodID init_z;
     } SurfaceTexture;
+    struct {
+        jclass clazz;
+        jmethodID init_st;
+    } Surface;
 } jfields;
 
 #define JNI_CALL(what, obj, method, ...) \
@@ -713,6 +717,7 @@ InitJNIFields(JNIEnv *env, vlc_object_t *p_obj, jobject *jobj)
     }
 
     jfields.SurfaceTexture.clazz = NULL;
+    jfields.Surface.clazz = NULL;
 
     jclass surfacetexture_class =
         (*env)->FindClass(env, "android/graphics/SurfaceTexture");
@@ -734,6 +739,17 @@ InitJNIFields(JNIEnv *env, vlc_object_t *p_obj, jobject *jobj)
         !jfields.SurfaceTexture.init_z)
         goto error;
 
+    jclass surface_class = (*env)->FindClass(env, "android/view/Surface");
+    CHECK_EXCEPTION("android/view/Surface class", true);
+
+    jfields.Surface.clazz = (*env)->NewGlobalRef(env, surface_class);
+    (*env)->DeleteLocalRef(env, surface_class);
+    if (jfields.Surface.clazz == NULL)
+        goto error;
+
+    GET_METHOD(Surface, init_st, "<init>",
+               "(Landroid/graphics/SurfaceTexture;)V", true);
+
 #undef GET_METHOD
 #undef CHECK_EXCEPTION
 
@@ -751,6 +767,10 @@ error:
         (*env)->DeleteGlobalRef(env, jfields.SurfaceTexture.clazz);
     jfields.SurfaceTexture.clazz = NULL;
 
+    if (jfields.Surface.clazz)
+        (*env)->DeleteGlobalRef(env, jfields.Surface.clazz);
+    jfields.Surface.clazz = NULL;
+
     vlc_mutex_unlock(&lock);
     msg_Err(p_obj, "Failed to load jfields table");
     return VLC_EGENERIC;
@@ -879,6 +899,9 @@ AWindowHandler_destroy(AWindowHandler *p_awh)
         if (jfields.SurfaceTexture.clazz)
             (*p_env)->DeleteGlobalRef(p_env, jfields.SurfaceTexture.clazz);
 
+        if (jfields.Surface.clazz)
+            (*p_env)->DeleteGlobalRef(p_env, jfields.Surface.clazz);
+
         JNI_ANWCALL(CallVoidMethod, unregisterNative);
         AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Video);
         AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Subtitles);



More information about the vlc-commits mailing list