[vlc-commits] android: utils: refactor GET_METHOD usage

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


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

android: utils: refactor GET_METHOD usage

Instead of passing the full path in the jfields structure, pass the
jfields first-order structure and the method field within it
separately, allowing to use it for future additional other classes too.

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

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

 modules/video_output/android/utils.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 9fb37e5035..1d41aa0aa4 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -689,42 +689,45 @@ InitJNIFields(JNIEnv *env, vlc_object_t *p_obj, jobject *jobj)
         } \
     } \
 } while( 0 )
-#define GET_METHOD(id, str, args, critical) do { \
-    jfields.id = (*env)->GetMethodID(env, clazz, (str), (args)); \
+#define GET_METHOD(id_clazz, id, str, args, critical) do { \
+    jfields.id_clazz.id = (*env)->GetMethodID(\
+            env, jfields.id_clazz.clazz, (str), (args)); \
     CHECK_EXCEPTION("GetMethodID("str")", critical); \
 } while( 0 )
 
     clazz = (*env)->GetObjectClass(env, jobj);
     CHECK_EXCEPTION("AndroidNativeWindow clazz", true);
-    GET_METHOD(AWindow.getVideoSurface,
+
+    jfields.AWindow.clazz = (*env)->NewGlobalRef(env, clazz);
+    (*env)->DeleteLocalRef(env, clazz);
+
+    GET_METHOD(AWindow, getVideoSurface,
                "getVideoSurface", "()Landroid/view/Surface;", true);
-    GET_METHOD(AWindow.getSubtitlesSurface,
+    GET_METHOD(AWindow, getSubtitlesSurface,
                "getSubtitlesSurface", "()Landroid/view/Surface;", true);
-    GET_METHOD(AWindow.registerNative,
+    GET_METHOD(AWindow, registerNative,
                "registerNative", "(J)I", true);
-    GET_METHOD(AWindow.unregisterNative,
+    GET_METHOD(AWindow, unregisterNative,
                "unregisterNative", "()V", true);
-    GET_METHOD(AWindow.setVideoLayout,
+    GET_METHOD(AWindow, setVideoLayout,
                "setVideoLayout", "(IIIIII)V", true);
 
-    GET_METHOD(AWindow.attachToGLContext,
+    GET_METHOD(AWindow, attachToGLContext,
                "SurfaceTexture_attachToGLContext", "(I)Z", true);
-    GET_METHOD(AWindow.detachFromGLContext,
+    GET_METHOD(AWindow, detachFromGLContext,
                "SurfaceTexture_detachFromGLContext", "()V", true);
-    GET_METHOD(AWindow.waitAndUpdateTexImage,
+    GET_METHOD(AWindow, waitAndUpdateTexImage,
                "SurfaceTexture_waitAndUpdateTexImage", "([F)Z",
                true);
-    GET_METHOD(AWindow.getSurface,
+    GET_METHOD(AWindow, getSurface,
                "SurfaceTexture_getSurface", "()Landroid/view/Surface;", true);
 
-    if ((*env)->RegisterNatives(env, clazz, jni_callbacks, 2) < 0)
+    if ((*env)->RegisterNatives(env, jfields.AWindow.clazz, jni_callbacks, 2) < 0)
     {
         msg_Err(p_obj, "RegisterNatives failed");
         i_init_state = 0;
         goto end;
     }
-    jfields.AWindow.clazz = (*env)->NewGlobalRef(env, clazz);
-    (*env)->DeleteLocalRef(env, clazz);
 
 #undef GET_METHOD
 #undef CHECK_EXCEPTION



More information about the vlc-commits mailing list