Bug 1410456 - Pass in cubeb JNIEnv instead of JavaVM. r=padenot

MozReview-Commit-ID: Cf8FvZzShVv

--HG--
extra : rebase_source : 28b4a8658e5be271af228a0d0398eaa2fba4320b
This commit is contained in:
Alex Chronopoulos 2018-03-01 12:11:32 +02:00
Родитель 599f535864
Коммит 6bd9c1333c
2 изменённых файлов: 7 добавлений и 27 удалений

Просмотреть файл

@ -18,10 +18,10 @@
* and application's Context object.
* */
JavaVM *
cubeb_jni_get_java_vm()
JNIEnv *
cubeb_get_jni_env_for_thread()
{
return mozilla::jni::GetVM();
return mozilla::jni::GetEnvForThread();
}
jobject

Просмотреть файл

@ -4,21 +4,7 @@
#define AUDIO_STREAM_TYPE_MUSIC 3
JNIEnv *
cubeb_jni_get_env_for_thread(JavaVM * java_vm)
{
JNIEnv * env = nullptr;
if (!java_vm->AttachCurrentThread(&env, nullptr)) {
assert(env);
return env;
}
assert(false && "Failed to get JNIEnv for thread");
return nullptr; // unreachable
}
struct cubeb_jni {
JavaVM * s_java_vm = nullptr;
jobject s_audio_manager_obj = nullptr;
jclass s_audio_manager_class = nullptr;
jmethodID s_get_output_latency_id = nullptr;
@ -28,21 +14,15 @@ extern "C"
cubeb_jni *
cubeb_jni_init()
{
JavaVM * javaVM = cubeb_jni_get_java_vm();
jobject ctx_obj = cubeb_jni_get_context_instance();
if (!javaVM || !ctx_obj) {
JNIEnv * jni_env = cubeb_get_jni_env_for_thread();
if (!jni_env || !ctx_obj) {
return nullptr;
}
JNIEnv * jni_env = cubeb_jni_get_env_for_thread(javaVM);
assert(jni_env);
cubeb_jni * cubeb_jni_ptr = new cubeb_jni;
assert(cubeb_jni_ptr);
cubeb_jni_ptr->s_java_vm = javaVM;
// Find the audio manager object and make it global to call it from another method
jclass context_class = jni_env->FindClass("android/content/Context");
jfieldID audio_service_field = jni_env->GetStaticFieldID(context_class, "AUDIO_SERVICE", "Ljava/lang/String;");
@ -69,7 +49,7 @@ extern "C"
int cubeb_get_output_latency_from_jni(cubeb_jni * cubeb_jni_ptr)
{
assert(cubeb_jni_ptr);
JNIEnv * jni_env = cubeb_jni_get_env_for_thread(cubeb_jni_ptr->s_java_vm);
JNIEnv * jni_env = cubeb_get_jni_env_for_thread();
return jni_env->CallIntMethod(cubeb_jni_ptr->s_audio_manager_obj, cubeb_jni_ptr->s_get_output_latency_id, AUDIO_STREAM_TYPE_MUSIC); //param: AudioManager.STREAM_MUSIC
}
@ -78,7 +58,7 @@ void cubeb_jni_destroy(cubeb_jni * cubeb_jni_ptr)
{
assert(cubeb_jni_ptr);
JNIEnv * jni_env = cubeb_jni_get_env_for_thread(cubeb_jni_ptr->s_java_vm);
JNIEnv * jni_env = cubeb_get_jni_env_for_thread();
assert(jni_env);
jni_env->DeleteGlobalRef(cubeb_jni_ptr->s_audio_manager_obj);