[Android] [PATCH 1/2] jni: fix thread attached twice in case of hw error

Thomas Guillem thomas at gllm.fr
Wed Nov 19 12:05:28 CET 2014


---
 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)
-- 
2.1.1



More information about the Android mailing list