Commit 15d6df20 authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf

android/jni: use a libvlcjni function to attach/detach java thread

Fix ART warning about java thread attached without a name.

(cherry picked from commit d26fefcfa700d3a9c1b2c26f30a1667e72ac381b)
Signed-off-by: default avatarEdward Wang <edward.c.wang@compdigitec.com>
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent b64149c0
......@@ -46,7 +46,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();
......@@ -327,7 +330,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) =
......@@ -539,7 +542,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);
......@@ -549,7 +552,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;
}
......@@ -567,7 +570,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)
......@@ -593,7 +596,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);
......@@ -627,14 +630,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;
}
......@@ -950,7 +953,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;
......@@ -976,7 +979,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;
......@@ -1014,7 +1017,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;
......
......@@ -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();
......
......@@ -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 };
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment