mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-02 15:55:39 +00:00
Prevent a deadlock if the audio device stops consuming data
This commit is contained in:
parent
6d220a9062
commit
364093aef8
@ -100,12 +100,6 @@ void* SdlAudioRenderer::getAudioBuffer(int*)
|
|||||||
|
|
||||||
bool SdlAudioRenderer::submitAudio(int bytesWritten)
|
bool SdlAudioRenderer::submitAudio(int bytesWritten)
|
||||||
{
|
{
|
||||||
// Our device may enter a permanent error status upon removal, so we need
|
|
||||||
// to recreate the audio device to pick up the new default audio device.
|
|
||||||
if (SDL_GetAudioDeviceStatus(m_AudioDevice) == SDL_AUDIO_STOPPED) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytesWritten == 0) {
|
if (bytesWritten == 0) {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
return true;
|
return true;
|
||||||
@ -118,8 +112,20 @@ bool SdlAudioRenderer::submitAudio(int bytesWritten)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Provide backpressure on the queue to ensure too many frames don't build up
|
// Provide backpressure on the queue to ensure too many frames don't build up
|
||||||
// in SDL's audio queue.
|
// in SDL's audio queue, but don't wait forever to avoid a deadlock if the
|
||||||
while (SDL_GetQueuedAudioSize(m_AudioDevice) / m_FrameSize > 10) {
|
// audio device fails.
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
// Our device may enter a permanent error status upon removal, so we need
|
||||||
|
// to recreate the audio device to pick up the new default audio device.
|
||||||
|
if (SDL_GetAudioDeviceStatus(m_AudioDevice) == SDL_AUDIO_STOPPED) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only queue more samples where there are 10 frames or less in SDL's queue
|
||||||
|
if (SDL_GetQueuedAudioSize(m_AudioDevice) / m_FrameSize <= 10) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Delay(1);
|
SDL_Delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user