[Android] jni: fix thread attached twice in case of hw error

Thomas Guillem git at videolan.org
Wed Nov 19 13:15:48 CET 2014


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Nov 18 17:28:07 2014 +0100| [3ce0dc9c8ab24627096034887a2083ca73073352] | committer: Thomas Guillem

jni: fix thread attached twice in case of hw error

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

 libvlc/jni/vout.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libvlc/jni/vout.c b/libvlc/jni/vout.c
index 6b2c3a7..06dc605 100644
--- a/libvlc/jni/vout.c
+++ b/libvlc/jni/vout.c
@@ -55,18 +55,25 @@ void jni_UnlockAndroidSurface() {
 
 void jni_EventHardwareAccelerationError()
 {
+    JNIEnv *env;
+    bool isAttached = false;
+
     if (vout_android_gui == NULL)
         return;
 
-    JNIEnv *env;
-    jni_attach_thread(&env, THREAD_NAME);
+    if (jni_get_env(&env) < 0) {
+        if (jni_attach_thread(&env, THREAD_NAME) < 0)
+            return;
+        isAttached = true;
+    }
 
     jclass cls = (*env)->GetObjectClass(env, vout_android_gui);
     jmethodID methodId = (*env)->GetMethodID(env, cls, "eventHardwareAccelerationError", "()V");
     (*env)->CallVoidMethod(env, vout_android_gui, methodId);
 
     (*env)->DeleteLocalRef(env, cls);
-    jni_detach_thread();
+    if (isAttached)
+        jni_detach_thread();
 }
 
 static void jni_SetSurfaceLayoutEnv(JNIEnv *p_env, int width, int height, int visible_width, int visible_height, int sar_num, int sar_den)



More information about the Android mailing list