[vlc-devel] [PATCH 1/3] android/jni: use a libvlcjni function to attach/detach java thread
Thomas Guillem
tom at gllm.fr
Tue Oct 14 11:35:55 CEST 2014
Fix art warning about java thread attached without a name.
---
modules/codec/omxil/android_mediacodec.c | 29 ++++++++++++++++-------------
modules/codec/omxil/omxil.c | 8 +++++---
modules/video_output/android/nativewindow.c | 8 +++++---
modules/video_output/android/opaque.c | 8 +++++---
modules/video_output/android/surface.c | 8 +++++---
5 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/modules/codec/omxil/android_mediacodec.c b/modules/codec/omxil/android_mediacodec.c
index 6edd932..13d774a 100644
--- a/modules/codec/omxil/android_mediacodec.c
+++ b/modules/codec/omxil/android_mediacodec.c
@@ -47,7 +47,10 @@
#define INFO_OUTPUT_FORMAT_CHANGED -2
#define INFO_TRY_AGAIN_LATER -1
-extern JavaVM *myVm;
+#define THREAD_NAME "android_mediacodec"
+
+extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
+extern void jni_detach_thread();
/* JNI functions to get/set an Android Surface object. */
extern jobject jni_LockAndGetAndroidJavaSurface();
extern void jni_UnlockAndroidSurface();
@@ -331,7 +334,7 @@ static int OpenDecoder(vlc_object_t *p_this)
p_dec->b_need_packetized = true;
JNIEnv* env = NULL;
- (*myVm)->AttachCurrentThread(myVm, &env, NULL);
+ jni_attach_thread(&env, THREAD_NAME);
for (int i = 0; classes[i].name; i++) {
*(jclass*)((uint8_t*)p_sys + classes[i].offset) =
@@ -545,7 +548,7 @@ static int OpenDecoder(vlc_object_t *p_this)
goto error;
(*env)->DeleteLocalRef(env, format);
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
const int timestamp_fifo_size = 32;
p_sys->timestamp_fifo = timestamp_FifoNew(timestamp_fifo_size);
@@ -555,7 +558,7 @@ static int OpenDecoder(vlc_object_t *p_this)
return VLC_SUCCESS;
error:
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
CloseDecoder(p_this);
return VLC_EGENERIC;
}
@@ -573,7 +576,7 @@ static void CloseDecoder(vlc_object_t *p_this)
* to prevent the vout from using destroyed output buffers. */
if (p_sys->direct_rendering)
InvalidateAllPictures(p_dec);
- (*myVm)->AttachCurrentThread(myVm, &env, NULL);
+ jni_attach_thread(&env, THREAD_NAME);
if (p_sys->input_buffers)
(*env)->DeleteGlobalRef(env, p_sys->input_buffers);
if (p_sys->output_buffers)
@@ -599,7 +602,7 @@ static void CloseDecoder(vlc_object_t *p_this)
}
if (p_sys->buffer_info)
(*env)->DeleteGlobalRef(env, p_sys->buffer_info);
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
free(p_sys->name);
ArchitectureSpecificCopyHooksDestroy(p_sys->pixel_format, &p_sys->architecture_specific_data);
@@ -633,14 +636,14 @@ static void DisplayBuffer(picture_sys_t* p_picsys, bool b_render)
/* Release the MediaCodec buffer. */
JNIEnv *env = NULL;
- (*myVm)->AttachCurrentThread(myVm, &env, NULL);
+ jni_attach_thread(&env, THREAD_NAME);
(*env)->CallVoidMethod(env, p_sys->codec, p_sys->release_output_buffer, i_index, b_render);
if ((*env)->ExceptionOccurred(env)) {
msg_Err(p_dec, "Exception in MediaCodec.releaseOutputBuffer (DisplayBuffer)");
(*env)->ExceptionClear(env);
}
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
p_picsys->b_valid = false;
vlc_mutex_unlock(get_android_opaque_mutex());
@@ -896,7 +899,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
return NULL;
}
- (*myVm)->AttachCurrentThread(myVm, &env, NULL);
+ jni_attach_thread(&env, THREAD_NAME);
if (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) {
block_Release(p_block);
@@ -916,7 +919,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
}
}
p_sys->decoded = false;
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
return NULL;
}
@@ -948,7 +951,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
* without assigning NULL to *pp_block. The next call
* to DecodeVideo will try to send the input packet again.
*/
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
return p_pic;
}
timeout = 30 * 1000;
@@ -974,7 +977,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
block_Release(p_block);
*pp_block = NULL;
}
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
return invalid_picture;
}
continue;
@@ -1006,7 +1009,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
}
if (!p_pic)
GetOutput(p_dec, env, &p_pic, 0);
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
block_Release(p_block);
*pp_block = NULL;
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 3997ca4..a9b496a 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -66,7 +66,9 @@
#if defined(USE_IOMX)
/* JNI functions to get/set an Android Surface object. */
-extern JavaVM *myVm;
+#define THREAD_NAME "omxil"
+extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
+extern void jni_detach_thread();
extern jobject jni_LockAndGetAndroidJavaSurface();
extern void jni_UnlockAndroidSurface();
extern void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);
@@ -2093,9 +2095,9 @@ static void HwBuffer_Init( decoder_t *p_dec, OmxPort *p_port )
goto error;
}
- (*myVm)->AttachCurrentThread( myVm, &p_env, NULL );
+ jni_attach_thread( &p_env, THREAD_NAME );
p_port->p_hwbuf->window = p_port->p_hwbuf->native_window.winFromSurface( p_env, surf );
- (*myVm)->DetachCurrentThread( myVm );
+ jni_detach_thread();
jni_UnlockAndroidSurface();
if( !p_port->p_hwbuf->window ) {
diff --git a/modules/video_output/android/nativewindow.c b/modules/video_output/android/nativewindow.c
index 29014b5..d3f308e 100644
--- a/modules/video_output/android/nativewindow.c
+++ b/modules/video_output/android/nativewindow.c
@@ -37,7 +37,9 @@
#include "utils.h"
-extern JavaVM *myVm;
+#define THREAD_NAME "ANativeWindow"
+extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
+extern void jni_detach_thread();
extern jobject jni_LockAndGetAndroidJavaSurface();
extern void jni_UnlockAndroidSurface();
extern void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);
@@ -89,9 +91,9 @@ static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)
goto error;
JNIEnv *p_env;
- (*myVm)->AttachCurrentThread(myVm, &p_env, NULL);
+ jni_attach_thread(&p_env, THREAD_NAME);
p_sys->window = p_sys->native_window.winFromSurface(p_env, javaSurface); // ANativeWindow_fromSurface call.
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
jni_UnlockAndroidSurface();
diff --git a/modules/video_output/android/opaque.c b/modules/video_output/android/opaque.c
index eac9d46..7c28667 100644
--- a/modules/video_output/android/opaque.c
+++ b/modules/video_output/android/opaque.c
@@ -50,7 +50,9 @@ vlc_module_begin()
set_callbacks(Open, Close)
vlc_module_end()
-extern JavaVM *myVm;
+#define THREAD_NAME "vout_mediacodec"
+extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
+extern void jni_detach_thread();
extern jobject jni_LockAndGetSubtitlesSurface();
extern void jni_UnlockAndroidSurface();
@@ -124,9 +126,9 @@ static void DisplaySubpicture(vout_display_t *vd, subpicture_t *subpicture)
if (!sys->window)
{
JNIEnv *p_env;
- (*myVm)->AttachCurrentThread(myVm, &p_env, NULL);
+ jni_attach_thread(&p_env, THREAD_NAME);
sys->window = sys->native_window.winFromSurface(p_env, jsurf);
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
}
ANativeWindow_Buffer buf = { 0 };
diff --git a/modules/video_output/android/surface.c b/modules/video_output/android/surface.c
index 63cbf15..9ab2f53 100644
--- a/modules/video_output/android/surface.c
+++ b/modules/video_output/android/surface.c
@@ -73,7 +73,9 @@ vlc_module_end()
* JNI prototypes
*****************************************************************************/
-extern JavaVM *myVm;
+#define THREAD_NAME "AndroidSurface"
+extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
+extern void jni_detach_thread();
extern void *jni_LockAndGetAndroidSurface();
extern jobject jni_LockAndGetAndroidJavaSurface();
extern void jni_UnlockAndroidSurface();
@@ -370,9 +372,9 @@ static int AndroidLockSurface(picture_t *picture)
sys->jsurf = jsurf;
if (!sys->window) {
JNIEnv *p_env;
- (*myVm)->AttachCurrentThread(myVm, &p_env, NULL);
+ jni_attach_thread(&p_env, THREAD_NAME);
sys->window = sys->native_window.winFromSurface(p_env, jsurf);
- (*myVm)->DetachCurrentThread(myVm);
+ jni_detach_thread();
}
// Using sys->window instead of the native surface object
// as parameter to the unlock function
--
2.1.0
More information about the vlc-devel
mailing list