aaudio: Block the audio device thread when in the background.

Fixes #8748.
This commit is contained in:
Ryan C. Gordon 2024-01-19 15:09:59 -05:00
parent bb969ac747
commit 910e040e9e
No known key found for this signature in database
GPG key ID: FA148B892AB48044
2 changed files with 4 additions and 37 deletions

View file

@ -345,8 +345,8 @@ void aaudio_PauseDevices(void)
/* TODO: Handle multiple devices? */
struct SDL_PrivateAudioData *private;
if (audioDevice && audioDevice->hidden) {
SDL_LockMutex(audioDevice->mixer_lock);
private = (struct SDL_PrivateAudioData *)audioDevice->hidden;
if (private->stream) {
aaudio_result_t res = ctx.AAudioStream_requestPause(private->stream);
if (res != AAUDIO_OK) {
@ -354,20 +354,11 @@ void aaudio_PauseDevices(void)
SDL_SetError("%s : %s", __func__, ctx.AAudio_convertResultToText(res));
}
}
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) {
SDL_LockMutex(captureDevice->mixer_lock);
private = (struct SDL_PrivateAudioData *)captureDevice->hidden;
if (private->stream) {
/* Pause() isn't implemented for 'capture', use Stop() */
aaudio_result_t res = ctx.AAudioStream_requestStop(private->stream);
@ -376,15 +367,6 @@ void aaudio_PauseDevices(void)
SDL_SetError("%s : %s", __func__, ctx.AAudio_convertResultToText(res));
}
}
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;
}
}
}
@ -395,13 +377,6 @@ void aaudio_ResumeDevices(void)
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 (private->stream) {
aaudio_result_t res = ctx.AAudioStream_requestStart(private->stream);
if (res != AAUDIO_OK) {
@ -409,17 +384,11 @@ void aaudio_ResumeDevices(void)
SDL_SetError("%s : %s", __func__, ctx.AAudio_convertResultToText(res));
}
}
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);
}
if (private->stream) {
aaudio_result_t res = ctx.AAudioStream_requestStart(private->stream);
if (res != AAUDIO_OK) {
@ -427,6 +396,7 @@ void aaudio_ResumeDevices(void)
SDL_SetError("%s : %s", __func__, ctx.AAudio_convertResultToText(res));
}
}
SDL_UnlockMutex(captureDevice->mixer_lock);
}
}

View file

@ -38,9 +38,6 @@ struct SDL_PrivateAudioData
Uint8 *mixbuf;
int mixlen;
int frame_size;
/* Resume device if it was paused automatically */
int resume;
};
void aaudio_ResumeDevices(void);