mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-17 10:18:28 +00:00
audio: Mark disconnected default devices as "zombies".
Zombie devices just sit there doing nothing until a new default device is chosen, and then they migrate all their logical devices before being destroyed. This lets the system deal with the likely outcome of a USB headset being the default audio device, and when its cable is yanked out, the backend will likely announce this _before_ it chooses a new default (or, perhaps, the only device in the system got yanked out and there _isn't_ a new default to be had until the user plugs the cable back in). This lets the audio device hold on without disturbing the app until it can seamlessly migrate audio, and it also means the backend does not have to be careful in how it announces device events, since SDL will manage the time between a device loss and its replacement. Note that this _only_ applies to things opened as the default device (SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, etc). If those USB headphones are the default, and one SDL_OpenAudioDevice() call asked for them specifically and the other just said "give me the system default," the explicitly requested open will get a device-lost notification immediately. The other open will live on as a zombie until it can migrate to the new default. This drops the complexity of the PulseAudio hotplug thread dramatically, back to what it was previously, since it no longer needs to fight against Pulse's asychronous nature, but just report device disconnects and new default choices as they arrive. loopwave has been updated to not check for device removals anymore; since it opens the default device, this is now managed for it; it no longer needs to close and reopen a device, and as far as it knows, the device is never lost in the first place.
This commit is contained in:
parent
cdd2ba81de
commit
fe1daf6fb5
4 changed files with 111 additions and 143 deletions
|
@ -103,14 +103,6 @@ open_audio(void)
|
|||
SDL_SetAudioStreamGetCallback(stream, fillerup, NULL);
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static void reopen_audio(void)
|
||||
{
|
||||
close_audio();
|
||||
open_audio();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int done = 0;
|
||||
|
||||
|
@ -191,8 +183,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
open_audio();
|
||||
|
||||
SDL_FlushEvents(SDL_EVENT_AUDIO_DEVICE_ADDED, SDL_EVENT_AUDIO_DEVICE_REMOVED);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
|
@ -203,10 +193,6 @@ int main(int argc, char *argv[])
|
|||
if (event.type == SDL_EVENT_QUIT) {
|
||||
done = 1;
|
||||
}
|
||||
if ((event.type == SDL_EVENT_AUDIO_DEVICE_ADDED && !event.adevice.iscapture) ||
|
||||
(event.type == SDL_EVENT_AUDIO_DEVICE_REMOVED && !event.adevice.iscapture && event.adevice.which == device)) {
|
||||
reopen_audio();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(100);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue