Android/openslES: set audio in paused/resumed state for Android event loop And also in "stopped" state before closing the device.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
diff --git a/src/audio/openslES/SDL_openslES.c b/src/audio/openslES/SDL_openslES.c
index 02efe1a..187e6e5 100644
--- a/src/audio/openslES/SDL_openslES.c
+++ b/src/audio/openslES/SDL_openslES.c
@@ -34,12 +34,15 @@
#define LOG_TAG "SDL_openslES"
-/*#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
-/*#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
-/*#define LOGI(...) do {} while (0) */
-/*#define LOGE(...) do {} while (0) */
+#if 0
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+// #define LOGI(...) do {} while (0)
+// #define LOGE(...) do {} while (0)
+#else
#define LOGI(...)
#define LOGE(...)
+#endif
/* engine interfaces */
static SLObjectItf engineObject = NULL;
@@ -54,7 +57,7 @@ static SLObjectItf outputMixObject = NULL;
/* buffer queue player interfaces */
static SLObjectItf bqPlayerObject = NULL;
-static SLPlayItf bqPlayerPlay;
+static SLPlayItf bqPlayerItf;
static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
/*static SLEffectSendItf bqPlayerEffectSend; */
static SLMuteSoloItf bqPlayerMuteSolo;
@@ -162,7 +165,7 @@ static void openslES_DestroyPCMRecorder(_THIS);
static void openslES_DestroyEngine()
{
LOGI("openslES_DestroyEngine()");
-
+
// openslES_DestroyPCMPlayer(this);
// openslES_DestroyPCMRecorder(this);
@@ -236,11 +239,12 @@ openslES_CreatePCMPlayer(_THIS)
SLDataFormat_PCM format_pcm;
+ SDL_AudioFormat test_format = 0;
SLresult result;
int i;
#if 0
- SDL_AudioFormat test_format;
+
test_format = SDL_FirstAudioFormat( this->spec.format );
while (test_format != 0) {
@@ -349,7 +353,7 @@ openslES_CreatePCMPlayer(_THIS)
}
/* get the play interface */
- result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay);
+ result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerItf);
if (SL_RESULT_SUCCESS != result) {
LOGE("SL_IID_PLAY interface get failed");
goto failed;
@@ -396,7 +400,7 @@ openslES_CreatePCMPlayer(_THIS)
}
/* set the player's state to playing */
- result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
+ result = (*bqPlayerItf)->SetPlayState(bqPlayerItf, SL_PLAYSTATE_PLAYING);
if (SL_RESULT_SUCCESS != result) {
LOGE("Play set state failed");
goto failed;
@@ -433,6 +437,13 @@ static void
openslES_DestroyPCMPlayer(_THIS)
{
struct SDL_PrivateAudioData *audiodata = (struct SDL_PrivateAudioData *) this->hidden;
+ SLresult result;
+
+ /* set the player's state to 'stopped' */
+ result = (*bqPlayerItf)->SetPlayState(bqPlayerItf, SL_PLAYSTATE_STOPPED);
+ if (SL_RESULT_SUCCESS != result) {
+ SDL_SetError("Stopped set state failed");
+ }
/* destroy buffer queue audio player object, and invalidate all associated interfaces */
if (bqPlayerObject != NULL) {
@@ -440,7 +451,7 @@ openslES_DestroyPCMPlayer(_THIS)
(*bqPlayerObject)->Destroy(bqPlayerObject);
bqPlayerObject = NULL;
- bqPlayerPlay = NULL;
+ bqPlayerItf = NULL;
bqPlayerBufferQueue = NULL;
/* bqPlayerEffectSend = NULL; */
bqPlayerMuteSolo = NULL;
@@ -488,7 +499,7 @@ openslES_CloseDevice(_THIS)
LOGI("openslES_CloseDevice( ) for playing");
openslES_DestroyPCMPlayer(this);
}
-
+
SDL_free(this->hidden);
return;
@@ -587,6 +598,28 @@ AudioBootStrap openslES_bootstrap = {
"openslES", "opensl ES audio driver", openslES_Init, 0
};
+void openslES_ResumeDevices()
+{
+ SLresult result;
+
+ /* set the player's state to 'playing' */
+ result = (*bqPlayerItf)->SetPlayState(bqPlayerItf, SL_PLAYSTATE_PLAYING);
+ if (SL_RESULT_SUCCESS != result) {
+ SDL_SetError("Play set state failed");
+ }
+}
+
+void openslES_PauseDevices()
+{
+ SLresult result;
+
+ /* set the player's state to 'paused' */
+ result = (*bqPlayerItf)->SetPlayState(bqPlayerItf, SL_PLAYSTATE_PAUSED);
+ if (SL_RESULT_SUCCESS != result) {
+ SDL_SetError("Playe set state failed");
+ }
+}
+
#endif /* SDL_AUDIO_DRIVER_OPENSLES */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/audio/openslES/SDL_openslES.h b/src/audio/openslES/SDL_openslES.h
index 8ed2804..fde08e8 100644
--- a/src/audio/openslES/SDL_openslES.h
+++ b/src/audio/openslES/SDL_openslES.h
@@ -42,6 +42,9 @@ struct SDL_PrivateAudioData
#endif
};
+void openslES_ResumeDevices(void);
+void openslES_PauseDevices(void);
+
#endif /* _SDL_openslesaudio_h */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c
index 92254ab..1dba149 100644
--- a/src/video/android/SDL_androidevents.c
+++ b/src/video/android/SDL_androidevents.c
@@ -30,9 +30,10 @@
#include "SDL_androidkeyboard.h"
#include "SDL_androidwindow.h"
-#if !SDL_AUDIO_DISABLED
/* Can't include sysaudio "../../audio/android/SDL_androidaudio.h"
* because of THIS redefinition */
+
+#if !SDL_AUDIO_DISABLED && SDL_AUDIO_DRIVER_ANDROID
extern void ANDROIDAUDIO_ResumeDevices(void);
extern void ANDROIDAUDIO_PauseDevices(void);
#else
@@ -40,6 +41,14 @@ static void ANDROIDAUDIO_ResumeDevices(void) {}
static void ANDROIDAUDIO_PauseDevices(void) {}
#endif
+#if !SDL_AUDIO_DISABLED && SDL_AUDIO_DRIVER_OPENSLES
+extern void openslES_ResumeDevices(void);
+extern void openslES_PauseDevices(void);
+#else
+static void openslES_ResumeDevices(void) {}
+static void openslES_PauseDevices(void) {}
+#endif
+
/* Number of 'type' events in the event queue */
static int
SDL_NumberOfEvents(Uint32 type)
@@ -95,12 +104,14 @@ Android_PumpEvents(_THIS)
SDL_UnlockMutex(Android_ActivityMutex);
ANDROIDAUDIO_PauseDevices();
+ openslES_PauseDevices();
if (SDL_SemWait(Android_ResumeSem) == 0) {
isPaused = 0;
ANDROIDAUDIO_ResumeDevices();
+ openslES_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
if (!SDL_HasEvent(SDL_QUIT)) {
@@ -111,7 +122,6 @@ Android_PumpEvents(_THIS)
/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive()) {
- SDL_VideoDevice *_this = SDL_GetVideoDevice();
Android_StartTextInput(_this); /* Only showTextInput */
}
}
@@ -144,6 +154,7 @@ Android_PumpEvents(_THIS)
isPaused = 0;
ANDROIDAUDIO_ResumeDevices();
+ openslES_ResumeDevices();
/* Restore the GL Context from here, as this operation is thread dependent */
if (!SDL_HasEvent(SDL_QUIT)) {
@@ -154,7 +165,6 @@ Android_PumpEvents(_THIS)
/* Make sure SW Keyboard is restored when an app becomes foreground */
if (SDL_IsTextInputActive()) {
- SDL_VideoDevice *_this = SDL_GetVideoDevice();
Android_StartTextInput(_this); /* Only showTextInput */
}
}
@@ -166,6 +176,7 @@ Android_PumpEvents(_THIS)
SDL_UnlockMutex(Android_ActivityMutex);
ANDROIDAUDIO_PauseDevices();
+ openslES_PauseDevices();
isPaused = 1;
}