fix(audio): unbreak bluetooth audio - no sound, and freeze on disconnect - #811
Open
dalexanco wants to merge 1 commit into
Open
fix(audio): unbreak bluetooth audio - no sound, and freeze on disconnect#811dalexanco wants to merge 1 commit into
dalexanco wants to merge 1 commit into
Conversation
Two bugs, one cause. Over a bluetooth headset games had no sound at all, and disconnecting the headset mid-game froze the emulator for good. alsa-lib guards every PCM with a recursive lock, and on the bluealsa sink that lock is never released once the PCM is open. SDL's audio thread blocks inside libasound and never runs our callback - that is the silence. The freeze follows from it: on disconnect minarch resets the audio device from the game loop, and SDL_CloseAudioDevice() waits forever for that stuck thread to exit. LIBASOUND_THREAD_SAFE=0 fixes both. SDL already serialises opening and closing a device against its own audio thread, so alsa's internal locking buys us nothing. The same lock is why SND_quit() was commented out, with a note blaming SDL stream reconnection: closing the device on exit hit the same deadlock. It works now, so the call comes back at the end of main(). It stays out of Core_unload(), which runs while the core is still loaded and can still emit audio into the buffer SND_quit() frees. Tested on a Brick (tg5040): sound in the headset, no freeze on disconnect, clean exit back to the launcher, and audio still fine on the next launch.
Member
|
I'm not ready yet to touch BT again, it has only been three months or so. Its an absolute clusterfuck to get right. 💀 |
Member
|
We will revisit this after h700 lands, maybe together with !736. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two bugs, one cause. Over a bluetooth headset games had no sound at all, and disconnecting the headset mid-game froze the emulator for good.
alsa-lib guards every PCM with a recursive lock, and on the bluealsa sink that lock is never released once the PCM is open. SDL's audio thread blocks inside libasound and never runs our callback - that is the silence. The freeze follows from it: on disconnect minarch resets the audio device from the game loop, and SDL_CloseAudioDevice() waits forever for that stuck thread to exit.
LIBASOUND_THREAD_SAFE=0 fixes both. SDL already serialises opening and closing a device against its own audio thread, so alsa's internal locking buys us nothing.
The same lock is why SND_quit() was commented out, with a note blaming SDL stream reconnection: closing the device on exit hit the same deadlock. It works now, so the call comes back at the end of main(). It stays out of Core_unload(), which runs while the core is still loaded and can still emit audio into the buffer SND_quit() frees.
Tested on a Brick (tg5040): sound in the headset, no freeze on disconnect, clean exit back to the launcher, and audio still fine on the next launch.
#810