Some lame-ass optimizations to JNI, which can make SDL crash

This commit is contained in:
Sergii Pylypenko
2013-03-25 21:23:49 +02:00
parent f0e8a3d12f
commit 6f4483c9a5
8 changed files with 47 additions and 16 deletions

View File

@@ -363,7 +363,7 @@ if [ -z "$AppRecordsAudio" -o -z "$AUTO" ]; then
echo
echo "Application records audio (it will use any available source, such a s microphone)"
echo "API is defined in file SDL_android.h: int SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec); void SDL_ANDROID_CloseAudioRecording(void);"
echo -n "This option will add additional permission to Android manifest ($AppRecordsAudio): "
echo -n "This option will add additional permission to Android manifest (y)/(n) ($AppRecordsAudio): "
read var
if [ -n "$var" ] ; then
AppRecordsAudio="$var"

View File

@@ -47,7 +47,7 @@ AppVersionCode=08822
AppVersionName="0.8.8.22"
ResetSdlConfigForThisVersion=n
DeleteFilesOnUpgrade="libsdl-DownloadFinished-10.flag"
CompiledLibraries="sdl_mixer sdl_image freetype curl vorbis ogg"
CompiledLibraries="sdl_mixer sdl_image freetype curl vorbis ogg openal"
CustomBuildScript=y
AppCflags='-O2 -finline-functions'
AppLdflags=''

View File

@@ -24,7 +24,7 @@ env NO_SHARED_LIBS=1 BUILD_EXECUTABLE=1 V=1 ../setEnvironment-armeabi.sh make -C
../setEnvironment-$1.sh make -j8 -C engine release \
PLATFORM=android ARCH=$1 USE_GLES=1 USE_LOCAL_HEADERS=0 BUILD_CLIENT_SMP=0 \
USE_OPENAL=0 USE_VOIP=1 USE_CURL=1 USE_CURL_DLOPEN=0 USE_CODEC_VORBIS=1 USE_MUMBLE=0 USE_FREETYPE=1 \
USE_OPENAL=1 USE_OPENAL_DLOPEN=0 USE_VOIP=1 USE_CURL=1 USE_CURL_DLOPEN=0 USE_CODEC_VORBIS=1 USE_MUMBLE=0 USE_FREETYPE=1 \
USE_RENDERER_DLOPEN=0 USE_INTERNAL_ZLIB=0 USE_INTERNAL_JPEG=1 BUILD_RENDERER_REND2=0 && \
echo "Copying engine/build/release-android-$1/openarena.$1 -> libapplication-$1.so" && \
cp -f engine/build/release-android-$1/openarena.$1 libapplication-$1.so || exit 1

View File

@@ -16,6 +16,11 @@ SdlVideoResizeKeepAspect=n
CompatibilityHacks=n
CompatibilityHacksStaticInit=n
CompatibilityHacksTextInputEmulatesHwKeyboard=n
CompatibilityHacksPreventAudioChopping=n
CompatibilityHacksAppIgnoresAudioBufferSize=n
CompatibilityHacksAdditionalPreloadedSharedLibraries=""
CompatibilityHacksSlowCompatibleEventQueue=n
CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState=
AppUsesMouse=y
AppNeedsTwoButtonMouse=y
ShowMouseCursor=n
@@ -23,17 +28,21 @@ ForceRelativeMouseMode=n
AppNeedsArrowKeys=n
AppNeedsTextInput=y
AppUsesJoystick=n
AppHandlesJoystickSensitivity=n
AppUsesAccelerometer=n
AppUsesGyroscope=n
AppUsesMultitouch=y
AppRecordsAudio=n
NonBlockingSwapBuffers=n
RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE"
AppTouchscreenKeyboardKeysAmount=0
AppTouchscreenKeyboardKeysAmountAutoFire=0
RedefinedKeysScreenKb="0 1 2 3 4 5 6 7 8 9"
RedefinedKeysScreenKbNames="0 1 2 3 4 5 6 7 8 9"
StartupMenuButtonTimeout=3000
HiddenMenuOptions='OptionalDownloadConfig DisplaySizeConfig'
FirstStartMenuOptions=''
MultiABI=y
AppMinimumRAM=0
AppVersionCode=101
AppVersionName="1.01"
ResetSdlConfigForThisVersion=n
@@ -42,6 +51,12 @@ CompiledLibraries="sdl_mixer sdl_image"
CustomBuildScript=n
AppCflags='-O2 -finline-functions'
AppLdflags=''
AppOverlapsSystemHeaders=
AppSubdirsBuild=''
AppBuildExclude=''
AppCmdline=''
ReadmeText='^Readme text'
MinimumScreenSize=s
AdmobPublisherId=n
AdmobTestDeviceId=
AdmobBannerSize=

View File

@@ -306,10 +306,15 @@ static void ANDROIDAUD_ThreadInit(_THIS)
JavaInitThread = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "initAudioThread", "()I");
(*jniEnvPlaying)->CallIntMethod( jniEnvPlaying, JavaAudioThread, JavaInitThread );
// Audio recording
JavaStartRecording = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "startRecording", "(IIII)[B");
JavaStopRecording = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "stopRecording", "()V");
JavaGetBuffer = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "getBuffer", "()[B");
audioBufferJNI = (*jniEnvPlaying)->CallObjectMethod( jniEnvPlaying, JavaAudioThread, JavaGetBuffer );
audioBufferJNI = (*jniEnvPlaying)->NewGlobalRef(jniEnvPlaying, audioBufferJNI);
audioBuffer = (unsigned char *) (*jniEnvPlaying)->GetByteArrayElements(jniEnvPlaying, audioBufferJNI, &isCopy);
//audioBuffer = (unsigned char *) (*jniEnvPlaying)->GetByteArrayElements(jniEnvPlaying, audioBufferJNI, &isCopy);
audioBuffer = (unsigned char *) (*jniEnvPlaying)->GetPrimitiveArrayCritical(jniEnvPlaying, audioBufferJNI, &isCopy);
if( !audioBuffer )
{
__android_log_print(ANDROID_LOG_ERROR, "libSDL", "ANDROIDAUD_ThreadInit() JNI::GetByteArrayElements() failed! we will crash now");
@@ -320,14 +325,13 @@ static void ANDROIDAUD_ThreadInit(_THIS)
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROIDAUD_ThreadInit()");
SDL_memset(audioBuffer, this->spec.silence, this->spec.size);
// Audio recording
JavaStartRecording = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "startRecording", "(IIII)[B");
JavaStopRecording = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "stopRecording", "()V");
};
static void ANDROIDAUD_ThreadDeinit(_THIS)
{
//(*jniEnvPlaying)->ReleaseByteArrayElements(jniEnvPlaying, audioBufferJNI, (jbyte *)audioBuffer, 0);
(*jniEnvPlaying)->ReleasePrimitiveArrayCritical(jniEnvPlaying, audioBufferJNI, (jbyte *)audioBuffer, 0);
// (*jniEnvPlaying)->DeleteGlobalRef(jniEnvPlaying, audioBufferJNI); // Application crashes here for some unknown reason
(*jniVM)->DetachCurrentThread(jniVM);
};
@@ -336,12 +340,14 @@ static void ANDROIDAUD_SendAudioToJava(void)
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROIDAUD_PlayAudio()");
//jboolean isCopy = JNI_TRUE;
(*jniEnvPlaying)->ReleaseByteArrayElements(jniEnvPlaying, audioBufferJNI, (jbyte *)audioBuffer, 0);
//(*jniEnvPlaying)->ReleaseByteArrayElements(jniEnvPlaying, audioBufferJNI, (jbyte *)audioBuffer, 0);
(*jniEnvPlaying)->ReleasePrimitiveArrayCritical(jniEnvPlaying, audioBufferJNI, (jbyte *)audioBuffer, 0);
audioBuffer = NULL;
(*jniEnvPlaying)->CallIntMethod( jniEnvPlaying, JavaAudioThread, JavaFillBuffer );
audioBuffer = (unsigned char *) (*jniEnvPlaying)->GetByteArrayElements(jniEnvPlaying, audioBufferJNI, NULL);
//audioBuffer = (unsigned char *) (*jniEnvPlaying)->GetByteArrayElements(jniEnvPlaying, audioBufferJNI, NULL);
audioBuffer = (unsigned char *) (*jniEnvPlaying)->GetPrimitiveArrayCritical(jniEnvPlaying, audioBufferJNI, NULL);
if( !audioBuffer )
__android_log_print(ANDROID_LOG_ERROR, "libSDL", "ANDROIDAUD_PlayAudio() JNI::GetByteArrayElements() failed! we will crash now");
@@ -425,7 +431,8 @@ JNIEXPORT void JNICALL JAVA_EXPORT_NAME(AudioThread_nativeAudioRecordCallback) (
return;
}
Uint8 *buffer = (Uint8 *) (*jniEnv)->GetByteArrayElements(jniEnv, recordingBufferJNI, NULL);
//Uint8 *buffer = (Uint8 *) (*jniEnv)->GetByteArrayElements(jniEnv, recordingBufferJNI, NULL);
Uint8 *buffer = (Uint8 *) (*jniEnv)->GetPrimitiveArrayCritical(jniEnv, recordingBufferJNI, NULL);
if( !buffer )
{
__android_log_print(ANDROID_LOG_ERROR, "libSDL", "AudioThread_nativeAudioRecordCallbacks(): error: JNI::GetByteArrayElements() failed!");
@@ -436,7 +443,8 @@ JNIEXPORT void JNICALL JAVA_EXPORT_NAME(AudioThread_nativeAudioRecordCallback) (
recording.callback(recording.userdata, buffer, recordingBufferSize);
(*jniEnv)->ReleaseByteArrayElements(jniEnv, recordingBufferJNI, (jbyte *)buffer, 0);
//(*jniEnv)->ReleaseByteArrayElements(jniEnv, recordingBufferJNI, (jbyte *)buffer, 0);
(*jniEnv)->ReleasePrimitiveArrayCritical(jniEnv, recordingBufferJNI, (jbyte *)buffer, 0);
}
extern DECLSPEC int SDLCALL SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec)
@@ -457,6 +465,8 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec)
return 0;
}
__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_ANDROID_OpenAudioRecording(): VM %p", jniVM);
(*jniVM)->AttachCurrentThread( jniVM, &jniEnv, NULL );
recordingBufferJNI = (*jniEnv)->CallObjectMethod( jniEnv, JavaAudioThread, JavaStartRecording,
@@ -469,7 +479,7 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec)
}
recordingBufferJNI = (*jniEnv)->NewGlobalRef( jniEnv, recordingBufferJNI );
recordingBufferSize = (*jniEnv)->GetArrayLength( jniEnv, recordingBufferJNI );
//__android_log_print(ANDROID_LOG_ERROR, "libSDL", "SDL_ANDROID_OpenAudioRecording(): JNI buffer %p len %d", recordingBufferJNI, recordingBufferSize);
__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_ANDROID_OpenAudioRecording(): JNI buffer %p len %d", recordingBufferJNI, recordingBufferSize);
return 1;
}

View File

@@ -140,10 +140,12 @@ int SDL_ANDROID_CallJavaSwapBuffers()
}
if( showScreenKeyboardDeferred )
{
(*JavaEnv)->PushLocalFrame(JavaEnv, 1);
jstring s = (*JavaEnv)->NewStringUTF(JavaEnv, showScreenKeyboardOldText);
showScreenKeyboardDeferred = 0;
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, s, showScreenKeyboardSendBackspace );
(*JavaEnv)->DeleteLocalRef( JavaEnv, s );
(*JavaEnv)->PopLocalFrame(JavaEnv, NULL);
}
SDL_ANDROID_ProcessDeferredEvents();
return 1;
@@ -283,9 +285,11 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf,
}
else
{
(*JavaEnv)->PushLocalFrame(JavaEnv, 1);
jstring s = (*JavaEnv)->NewStringUTF( JavaEnv, oldText );
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, s, 0 );
(*JavaEnv)->DeleteLocalRef( JavaEnv, s );
(*JavaEnv)->PopLocalFrame(JavaEnv, NULL);
}
while( !SDL_ANDROID_TextInputFinished )
@@ -318,10 +322,12 @@ int SDL_ANDROID_IsScreenKeyboardShown()
void SDL_ANDROID_CallJavaSetScreenKeyboardHintMessage(const char *hint)
{
(*JavaEnv)->PushLocalFrame(JavaEnv, 1);
jstring s = hint ? (*JavaEnv)->NewStringUTF(JavaEnv, hint) : NULL;
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaSetScreenKeyboardHintMessage, s );
if( s )
(*JavaEnv)->DeleteLocalRef( JavaEnv, s );
(*JavaEnv)->PopLocalFrame(JavaEnv, NULL);
}
void SDL_ANDROID_CallJavaStartAccelerometerGyroscope(int start)