[Android] jni: don't attach thread if already attached

Thomas Guillem git at videolan.org
Sat Nov 15 12:42:00 CET 2014


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Nov 14 17:10:22 2014 +0100| [03deb727155587be2bdddcb08b67021b7dc12aca] | committer: Jean-Baptiste Kempf

jni: don't attach thread if already attached

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

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

diff --git a/libvlc/jni/vout.c b/libvlc/jni/vout.c
index 1286fe1..eafb310 100644
--- a/libvlc/jni/vout.c
+++ b/libvlc/jni/vout.c
@@ -92,11 +92,17 @@ static void jni_SetAndroidSurfaceSizeEnv(JNIEnv *p_env, int width, int height, i
 void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den)
 {
     JNIEnv *p_env;
+    bool isAttached = false;
 
-    jni_attach_thread(&p_env, THREAD_NAME);
+    if (jni_get_env(&p_env) < 0) {
+        if (jni_attach_thread(&p_env, THREAD_NAME) < 0)
+            return;
+        isAttached = true;
+    }
     jni_SetAndroidSurfaceSizeEnv(p_env, width, height, visible_width, visible_height, sar_num, sar_den);
 
-    jni_detach_thread();
+    if (isAttached)
+        jni_detach_thread();
 }
 
 bool jni_IsVideoPlayerActivityCreated() {



More information about the Android mailing list