androidaudio: same fix as AAudio for pausing thread when backgrounding app.

Reference Issue #8748.
This commit is contained in:
Ryan C. Gordon 2024-01-19 22:15:27 -05:00
parent 109bb2f17e
commit 1e13aa2c98
No known key found for this signature in database
GPG key ID: FA148B892AB48044
2 changed files with 5 additions and 34 deletions

View file

@ -148,29 +148,12 @@ AudioBootStrap ANDROIDAUDIO_bootstrap = {
void ANDROIDAUDIO_PauseDevices(void)
{
/* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private;
if (audioDevice && audioDevice->hidden) {
private = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (SDL_AtomicGet(&audioDevice->paused)) {
/* The device is already paused, leave it alone */
private->resume = SDL_FALSE;
} else {
SDL_LockMutex(audioDevice->mixer_lock);
SDL_AtomicSet(&audioDevice->paused, 1);
private->resume = SDL_TRUE;
}
}
if (captureDevice && captureDevice->hidden) {
private = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (SDL_AtomicGet(&captureDevice->paused)) {
/* The device is already paused, leave it alone */
private->resume = SDL_FALSE;
} else {
SDL_LockMutex(captureDevice->mixer_lock);
SDL_AtomicSet(&captureDevice->paused, 1);
private->resume = SDL_TRUE;
}
}
}
@ -178,24 +161,13 @@ void ANDROIDAUDIO_PauseDevices(void)
void ANDROIDAUDIO_ResumeDevices(void)
{
/* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private;
if (audioDevice && audioDevice->hidden) {
private = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (private->resume) {
SDL_AtomicSet(&audioDevice->paused, 0);
private->resume = SDL_FALSE;
SDL_UnlockMutex(audioDevice->mixer_lock);
}
}
if (captureDevice && captureDevice->hidden) {
private = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (private->resume) {
SDL_AtomicSet(&captureDevice->paused, 0);
private->resume = SDL_FALSE;
SDL_UnlockMutex(captureDevice->mixer_lock);
}
}
}
#else

View file

@ -30,8 +30,7 @@
struct SDL_PrivateAudioData
{
/* Resume device if it was paused automatically */
int resume;
int unused;
};
void ANDROIDAUDIO_ResumeDevices(void);