audio: Reuse jmethodID objects

This commit is contained in:
Hajime Hoshi 2017-04-08 01:41:07 +09:00
parent b5a422700a
commit 7e4e762d96

View File

@ -133,21 +133,21 @@ static char* writeToAudioTrack(uintptr_t java_vm, uintptr_t jni_env,
} }
jint result; jint result;
static jmethodID write1 = NULL;
static jmethodID write2 = NULL;
if (!write1) {
write1 = (*env)->GetMethodID(env, android_media_AudioTrack, "write", "([BII)I");
}
if (!write2) {
write2 = (*env)->GetMethodID(env, android_media_AudioTrack, "write", "([SII)I");
}
switch (bytesPerSample) { switch (bytesPerSample) {
case 1: case 1:
result = result = (*env)->CallIntMethod(env, audioTrack, write1, arrInBytes, 0, length);
(*env)->CallIntMethod(
env, audioTrack,
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([BII)I"),
arrInBytes, 0, length);
(*env)->DeleteLocalRef(env, arrInBytes); (*env)->DeleteLocalRef(env, arrInBytes);
break; break;
case 2: case 2:
result = result = (*env)->CallIntMethod(env, audioTrack, write2, arrInShorts, 0, length);
(*env)->CallIntMethod(
env, audioTrack,
(*env)->GetMethodID(env, android_media_AudioTrack, "write", "([SII)I"),
arrInShorts, 0, length);
(*env)->DeleteLocalRef(env, arrInShorts); (*env)->DeleteLocalRef(env, arrInShorts);
break; break;
} }