mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-03-06 18:09:53 +00:00
wasapi: Deal with HDMI or DisplayPort-based audio devices.
They can vanish for UP TO EIGHT SECONDS...! This is for devices that connect to HDMI/DisplayPort/etc, where it presumably has to wait for a display to get up and running before it can play audio through it, so one can see the audio device fail when changing display modes, or the system returning from sleep. Since this can be triggered by a game changing video resolutions at startup (either before or after opening the audio device!), it's important to deal with. In normal conditions, it shouldn't take this long to open or recover an audio device, but this is better than unexpectedly losing the device in this situation. Fixes #7044. Fixes #5571.
This commit is contained in:
parent
7308325559
commit
48e71ae87b
|
@ -357,19 +357,32 @@ void SDL_IMMDevice_Quit(void)
|
|||
|
||||
int SDL_IMMDevice_Get(LPCWSTR devid, IMMDevice **device, SDL_bool iscapture)
|
||||
{
|
||||
const Uint64 timeout = SDL_GetTicks64() + 8000; /* intel's audio drivers can fail for up to EIGHT SECONDS after a device is connected or we wake from sleep. */
|
||||
HRESULT ret;
|
||||
|
||||
SDL_assert(device != NULL);
|
||||
|
||||
if (devid == NULL) {
|
||||
const EDataFlow dataflow = iscapture ? eCapture : eRender;
|
||||
ret = IMMDeviceEnumerator_GetDefaultAudioEndpoint(enumerator, dataflow, SDL_IMMDevice_role, device);
|
||||
} else {
|
||||
ret = IMMDeviceEnumerator_GetDevice(enumerator, devid, device);
|
||||
}
|
||||
while (SDL_TRUE) {
|
||||
if (devid == NULL) {
|
||||
const EDataFlow dataflow = iscapture ? eCapture : eRender;
|
||||
ret = IMMDeviceEnumerator_GetDefaultAudioEndpoint(enumerator, dataflow, SDL_IMMDevice_role, device);
|
||||
} else {
|
||||
ret = IMMDeviceEnumerator_GetDevice(enumerator, devid, device);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(ret)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == E_NOTFOUND) {
|
||||
const Uint64 now = SDL_GetTicks64();
|
||||
if (timeout > now) {
|
||||
const Uint64 ticksleft = timeout - now;
|
||||
SDL_Delay(SDL_min(ticksleft, 300)); /* wait awhile and try again. */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILED(ret)) {
|
||||
SDL_assert(*device == NULL);
|
||||
return WIN_SetErrorFromHRESULT("WASAPI can't find requested audio endpoint", ret);
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue