Skip to content
Browse files

Fixed OpenAL eating CPU in background

  • Loading branch information...
1 parent 532b652 commit 0f478832a7fb43cf89b3ade02893e1c478c2e77d @pelya committed Jun 21, 2012
View
2 project/java/Audio.java
@@ -57,7 +57,7 @@ public int fillBuffer()
if( mParent.isPaused() )
{
try{
- Thread.sleep(200);
+ Thread.sleep(500);
} catch (InterruptedException e) {}
}
else
View
5 project/jni/application/alienblaster/AndroidAppSettings.cfg
@@ -15,6 +15,7 @@ SdlVideoResize=y
SdlVideoResizeKeepAspect=n
CompatibilityHacks=
CompatibilityHacksStaticInit=n
+CompatibilityHacksTextInputEmulatesHwKeyboard=n
AppUsesMouse=n
AppNeedsTwoButtonMouse=n
ShowMouseCursor=n
@@ -25,12 +26,12 @@ AppUsesJoystick=n
AppHandlesJoystickSensitivity=n
AppUsesMultitouch=n
NonBlockingSwapBuffers=n
-RedefinedKeys="RETURN LCTRL PAGEUP PAGEDOWN LCTRL"
+RedefinedKeys="RETURN LCTRL NO_REMAP NO_REMAP LCTRL"
AppTouchscreenKeyboardKeysAmount=4
AppTouchscreenKeyboardKeysAmountAutoFire=1
RedefinedKeysScreenKb="RETURN LCTRL PAGEUP PAGEDOWN LCTRL"
StartupMenuButtonTimeout=3000
-HiddenMenuOptions=''
+HiddenMenuOptions='OptionalDownloadConfig'
FirstStartMenuOptions=''
MultiABI=n
AppVersionCode=110014
View
4 project/jni/application/supertux/AndroidAppSettings.cfg
@@ -34,8 +34,8 @@ StartupMenuButtonTimeout=3000
HiddenMenuOptions='OptionalDownloadConfig'
FirstStartMenuOptions=''
MultiABI=n
-AppVersionCode=03302
-AppVersionName="0.3.3.02"
+AppVersionCode=03303
+AppVersionName="0.3.3.03"
ResetSdlConfigForThisVersion=n
DeleteFilesOnUpgrade="%"
CompiledLibraries=" sdl_image physfs boost_system curl openal jpeg png tremor ogg"
View
2 project/jni/openal/Android.mk
@@ -14,7 +14,7 @@ LOCAL_CPP_EXTENSION := .cpp
LOCAL_SRC_FILES := $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cpp))))
LOCAL_SRC_FILES += $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c))))
-LOCAL_SHARED_LIBRARIES :=
+LOCAL_SHARED_LIBRARIES := sdl-$(SDL_VERSION)
LOCAL_STATIC_LIBRARIES :=
View
13 project/jni/openal/src/Alc/android.c
@@ -28,6 +28,12 @@
#include "AL/alc.h"
#include "AL/android.h"
+typedef void ( * SDL_ANDROID_ApplicationPutToBackgroundCallback_t ) (void);
+
+extern int SDL_ANDROID_SetOpenALPutToBackgroundCallback(
+ SDL_ANDROID_ApplicationPutToBackgroundCallback_t PutToBackground,
+ SDL_ANDROID_ApplicationPutToBackgroundCallback_t Restored );
+
static int doPause=0;
int resumeHandled;
int pauseHandled;
@@ -106,6 +112,10 @@ static void* thread_function(void* arg)
{
(*env)->CallNonvirtualVoidMethod(env, track, cAudioTrack, mPause);
pauseHandled=1;
+ while(doPause)
+ {
+ usleep(500000);
+ }
}
if(!doPause && !resumeHandled)
{
@@ -144,6 +154,7 @@ static ALCboolean android_open_playback(ALCdevice *device, const ALCchar *device
int channels;
int bytes;
+ SDL_ANDROID_SetOpenALPutToBackgroundCallback(al_android_pause_playback, al_android_resume_playback);
if (!cAudioTrack)
{
/* Cache AudioTrack class and it's method id's
@@ -308,4 +319,4 @@ AL_API void AL_APIENTRY al_android_resume_playback()
doPause=0;
resumeHandled=0;
AL_PRINT("Audio resumed.");
-}
+}
View
4 project/jni/sdl-1.3/src/video/android/SDL_androidinput.c
@@ -986,10 +986,10 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouseButtonsPressed) (JNIEnv* env, jobj
btn = SDL_BUTTON_MIDDLE;
break;
case MOUSE_HW_BUTTON_BACK:
- btn = SDL_BUTTON_WHEELUP;
+ btn = SDL_BUTTON_X1;
break;
case MOUSE_HW_BUTTON_FORWARD:
- btn = SDL_BUTTON_WHEELDOWN;
+ btn = SDL_BUTTON_X2;
break;
}
SDL_ANDROID_MainThreadPushMouseButton( pressedState ? SDL_PRESSED : SDL_RELEASED, btn );
View
19 project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c
@@ -84,6 +84,8 @@ static void appRestoredCallbackDefault(void)
static SDL_ANDROID_ApplicationPutToBackgroundCallback_t appPutToBackgroundCallback = appPutToBackgroundCallbackDefault;
static SDL_ANDROID_ApplicationPutToBackgroundCallback_t appRestoredCallback = appRestoredCallbackDefault;
+static SDL_ANDROID_ApplicationPutToBackgroundCallback_t openALPutToBackgroundCallback = NULL;
+static SDL_ANDROID_ApplicationPutToBackgroundCallback_t openALRestoredCallback = NULL;
int SDL_ANDROID_CallJavaSwapBuffers()
{
@@ -120,6 +122,8 @@ int SDL_ANDROID_CallJavaSwapBuffers()
__android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context recreated, refreshing textures");
SDL_ANDROID_VideoContextRecreated();
appRestoredCallback();
+ if(openALRestoredCallback)
+ openALRestoredCallback();
}
if( showScreenKeyboardDeferred )
{
@@ -195,6 +199,9 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextLost) ( JNIEnv* env, jobject thiz
__android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context lost, waiting for new OpenGL context");
glContextLost = 1;
appPutToBackgroundCallback();
+ if(openALPutToBackgroundCallback)
+ openALPutToBackgroundCallback();
+
#if SDL_VERSION_ATLEAST(1,3,0)
//if( ANDROID_CurrentWindow )
// SDL_SendWindowEvent(ANDROID_CurrentWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
@@ -293,6 +300,18 @@ int SDL_ANDROID_SetApplicationPutToBackgroundCallback(
appRestoredCallback = appRestored;
}
+extern int SDL_ANDROID_SetOpenALPutToBackgroundCallback(
+ SDL_ANDROID_ApplicationPutToBackgroundCallback_t PutToBackground,
+ SDL_ANDROID_ApplicationPutToBackgroundCallback_t Restored );
+
+int SDL_ANDROID_SetOpenALPutToBackgroundCallback(
+ SDL_ANDROID_ApplicationPutToBackgroundCallback_t PutToBackground,
+ SDL_ANDROID_ApplicationPutToBackgroundCallback_t Restored )
+{
+ openALPutToBackgroundCallback = PutToBackground;
+ openALRestoredCallback = Restored;
+}
+
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetSmoothVideo) (JNIEnv* env, jobject thiz)
{
View
6 readme.txt
@@ -221,11 +221,11 @@ SDL_ANDROID_SetApplicationPutToBackgroundCallback( callback_t appPutToBackground
where callback_t is function pointer of type "void (*) void".
The default callbacks will call another Android-specific functions:
SDL_ANDROID_PauseAudioPlayback() and SDL_ANDROID_ResumeAudioPlayback()
-which will pause and resume audio from HW layer, so appplication does not need to destroy and re-init audio.
+which will pause and resume audio from HW layer, so appplication does not need to destroy and re-init audio,
+and in general you don't need to redefine those functions, unless you want to play audio in background.
Also, the usual event SDL_ACTIVEEVENT with flag SDL_APPACTIVE will be sent when that happens,
and also SDL_VIDEORESIZE event will be sent (the same behavior as in MacOsX SDL implementation).
-If you're using OpenAL for an audio playback you have to call functions al_android_pause_playback()
-and al_android_resume_playback() by yourself when SDL calls your callbacks.
+If you're using OpenAL it will be paused automatically when your app goes to background.
If you're using pure SDL 1.2 API (with or without HW acceleration) you don't need to worry about anything -
the SDL itself will re-create GL textures and fill them with pixel data from existing SDL HW surfaces,

0 comments on commit 0f47883

Please sign in to comment.
Something went wrong with that request. Please try again.