[Android] jni: version check before using private structures

Edward Wang git at videolan.org
Thu Nov 7 13:03:56 CET 2013


vlc-ports/android | branch: 0.1.x-bugfix | Edward Wang <edward.c.wang at compdigitec.com> | Sun Sep  1 17:52:36 2013 +0200| [ea2fa670d560dbdcac299ff4fe7226c0da1b5f81] | committer: Edward Wang

jni: version check before using private structures

Close #9300

(cherry picked from commit d0f34ad811467bae4494769448a70bd474d23508)
Signed-off-by: Edward Wang <edward.c.wang at compdigitec.com>

Conflicts:
	vlc-android/jni/vout.c

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ea2fa670d560dbdcac299ff4fe7226c0da1b5f81
---

 vlc-android/jni/libvlcjni.c |   29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 4f06641..c79930c 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -338,23 +338,26 @@ void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jo
     jclass clz;
     jfieldID fid;
 
-    pthread_mutex_lock(&vout_android_lock);
-    clz = (*env)->GetObjectClass(env, surf);
-    fid = (*env)->GetFieldID(env, clz, "mSurface", "I");
-    if (fid == NULL) {
-        jthrowable exp = (*env)->ExceptionOccurred(env);
-        if (exp) {
-            (*env)->DeleteLocalRef(env, exp);
-            (*env)->ExceptionClear(env);
+    clz = (*env)->FindClass(env, "org/videolan/libvlc/LibVlcUtil");
+    jmethodID methodId = (*env)->GetStaticMethodID(env, clz, "isGingerbreadOrLater", "()Z");
+    jboolean gingerbreadOrLater = (*env)->CallStaticBooleanMethod(env, clz, methodId);
+    // Android 2.2 and under don't have ANativeWindow_fromSurface
+    if(unlikely(!gingerbreadOrLater)) {
+        clz = (*env)->GetObjectClass(env, surf);
+        fid = (*env)->GetFieldID(env, clz, "mSurface", "I");
+        if (fid == NULL) {
+            jthrowable exp = (*env)->ExceptionOccurred(env);
+            if (exp) {
+                (*env)->DeleteLocalRef(env, exp);
+                (*env)->ExceptionClear(env);
+            }
+            fid = (*env)->GetFieldID(env, clz, "mNativeSurface", "I");
         }
-        fid = (*env)->GetFieldID(env, clz, "mNativeSurface", "I");
+        vout_android_surf = (void*)(*env)->GetIntField(env, surf, fid);
+        (*env)->DeleteLocalRef(env, clz);
     }
-    vout_android_surf = (void*)(*env)->GetIntField(env, surf, fid);
-    (*env)->DeleteLocalRef(env, clz);
-
     vout_android_gui = (*env)->NewGlobalRef(env, gui);
     vout_android_java_surf = (*env)->NewGlobalRef(env, surf);
-    pthread_mutex_unlock(&vout_android_lock);
 }
 
 void Java_org_videolan_libvlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {



More information about the Android mailing list