Improve android java support

- Use Log.d/Log.w instead of System.printf
- Remove commented code
- Cherry-pick: Manual backport of d698814367
This commit is contained in:
Xavier Sellier
2018-02-22 00:38:04 -05:00
parent 0af3f8e053
commit 88e779cd5e
25 changed files with 127 additions and 433 deletions

View File

@ -58,21 +58,6 @@ const char *AudioDriverAndroid::get_name() const {
Error AudioDriverAndroid::init() {
mutex = Mutex::create();
/*
// TODO: pass in/return a (Java) device ID, also whether we're opening for input or output
this->spec.samples = Android_JNI_OpenAudioDevice(this->spec.freq, this->spec.format == AUDIO_U8 ? 0 : 1, this->spec.channels, this->spec.samples);
SDL_CalculateAudioSpec(&this->spec);
if (this->spec.samples == 0) {
// Init failed?
SDL_SetError("Java-side initialization failed!");
return 0;
}
*/
// Android_JNI_SetupThread();
// __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device");
JNIEnv *env = ThreadAndroid::get_env();
int mix_rate = GLOBAL_DEF("audio/mix_rate", 44100);
@ -84,7 +69,6 @@ Error AudioDriverAndroid::init() {
print_line("audio buffer size: " + itos(buffer_size));
}
__android_log_print(ANDROID_LOG_INFO, "godot", "Initializing audio! params: %i,%i ", mix_rate, buffer_size);
audioBuffer = env->CallObjectMethod(io, _init_audio, mix_rate, buffer_size);
ERR_FAIL_COND_V(audioBuffer == NULL, ERR_INVALID_PARAMETER);
@ -111,29 +95,10 @@ void AudioDriverAndroid::setup(jobject p_io) {
jclass c = env->GetObjectClass(io);
cls = (jclass)env->NewGlobalRef(c);
__android_log_print(ANDROID_LOG_INFO, "godot", "starting to attempt get methods");
_init_audio = env->GetMethodID(cls, "audioInit", "(II)Ljava/lang/Object;");
if (_init_audio != 0) {
__android_log_print(ANDROID_LOG_INFO, "godot", "*******GOT METHOD _init_audio ok!!");
} else {
__android_log_print(ANDROID_LOG_INFO, "godot", "audioinit ok!");
}
_write_buffer = env->GetMethodID(cls, "audioWriteShortBuffer", "([S)V");
if (_write_buffer != 0) {
__android_log_print(ANDROID_LOG_INFO, "godot", "*******GOT METHOD _write_buffer ok!!");
}
_quit = env->GetMethodID(cls, "audioQuit", "()V");
if (_quit != 0) {
__android_log_print(ANDROID_LOG_INFO, "godot", "*******GOT METHOD _quit ok!!");
}
_pause = env->GetMethodID(cls, "audioPause", "(Z)V");
if (_quit != 0) {
__android_log_print(ANDROID_LOG_INFO, "godot", "*******GOT METHOD _pause ok!!");
}
}
void AudioDriverAndroid::thread_func(JNIEnv *env) {
@ -142,7 +107,6 @@ void AudioDriverAndroid::thread_func(JNIEnv *env) {
if (cls) {
cls = (jclass)env->NewGlobalRef(cls);
__android_log_print(ANDROID_LOG_INFO, "godot", "*******CLASS FOUND!!!");
}
jfieldID fid = env->GetStaticFieldID(cls, "io", "Lorg/godotengine/godot/GodotIO;");
jobject ob = env->GetStaticObjectField(cls, fid);
@ -150,9 +114,6 @@ void AudioDriverAndroid::thread_func(JNIEnv *env) {
jclass c = env->GetObjectClass(gob);
jclass lcls = (jclass)env->NewGlobalRef(c);
_write_buffer = env->GetMethodID(lcls, "audioWriteShortBuffer", "([S)V");
if (_write_buffer != 0) {
__android_log_print(ANDROID_LOG_INFO, "godot", "*******GOT METHOD _write_buffer ok!!");
}
while (!quit) {