[Android] jni: version check before using private structures

Edward Wang git at videolan.org
Sun Sep 1 17:53:06 CEST 2013


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

jni: version check before using private structures

Close #9300

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

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

diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
index f2765db..777d7d4 100644
--- a/vlc-android/jni/vout.c
+++ b/vlc-android/jni/vout.c
@@ -66,23 +66,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