Android: Audio thread is already setup for the JVM
authorSylvain Becker <sylvain.becker@gmail.com>
Fri, 11 Jan 2019 15:33:02 +0100
changeset 125270aa9da921db6
parent 12526 2fd98a88f320
child 12528 e3fddfb03620
Android: Audio thread is already setup for the JVM
In 'src/thread/pthread/SDL_systhread.c' RunThread() calls first 'Android_JNI_SetupThread()'
src/core/android/SDL_android.c
     1.1 --- a/src/core/android/SDL_android.c	Fri Jan 11 15:27:53 2019 +0100
     1.2 +++ b/src/core/android/SDL_android.c	Fri Jan 11 15:33:02 2019 +0100
     1.3 @@ -1223,11 +1223,6 @@
     1.4  
     1.5      JNIEnv *env = Android_JNI_GetEnv();
     1.6  
     1.7 -    if (!env) {
     1.8 -        LOGE("callback_handler: failed to attach current thread");
     1.9 -    }
    1.10 -    Android_JNI_SetupThread();
    1.11 -
    1.12      switch (spec->format) {
    1.13      case AUDIO_U8:
    1.14          audioformat = ENCODING_PCM_8BIT;
    1.15 @@ -1386,20 +1381,20 @@
    1.16  
    1.17  void Android_JNI_WriteAudioBuffer(void)
    1.18  {
    1.19 -    JNIEnv *mAudioEnv = Android_JNI_GetEnv();
    1.20 +    JNIEnv *env = Android_JNI_GetEnv();
    1.21  
    1.22      switch (audioBufferFormat) {
    1.23      case ENCODING_PCM_8BIT:
    1.24 -        (*mAudioEnv)->ReleaseByteArrayElements(mAudioEnv, (jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT);
    1.25 -        (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
    1.26 +        (*env)->ReleaseByteArrayElements(env, (jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT);
    1.27 +        (*env)->CallStaticVoidMethod(env, mAudioManagerClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
    1.28          break;
    1.29      case ENCODING_PCM_16BIT:
    1.30 -        (*mAudioEnv)->ReleaseShortArrayElements(mAudioEnv, (jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT);
    1.31 -        (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
    1.32 +        (*env)->ReleaseShortArrayElements(env, (jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT);
    1.33 +        (*env)->CallStaticVoidMethod(env, mAudioManagerClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
    1.34          break;
    1.35      case ENCODING_PCM_FLOAT:
    1.36 -        (*mAudioEnv)->ReleaseFloatArrayElements(mAudioEnv, (jfloatArray)audioBuffer, (jfloat *)audioBufferPinned, JNI_COMMIT);
    1.37 -        (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteFloatBuffer, (jfloatArray)audioBuffer);
    1.38 +        (*env)->ReleaseFloatArrayElements(env, (jfloatArray)audioBuffer, (jfloat *)audioBufferPinned, JNI_COMMIT);
    1.39 +        (*env)->CallStaticVoidMethod(env, mAudioManagerClass, midAudioWriteFloatBuffer, (jfloatArray)audioBuffer);
    1.40          break;
    1.41      default:
    1.42          __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: unhandled audio buffer format");