-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDL_CloseAudioDevice hangs when closing a stream initialized with a very low audio rate. (SDL2, PulseAudio) #9829
Comments
Reproduces on centos 6.10 i686 too. And happens with 10 Hz, really?
|
Forgot to add that it does complete and exit, just expects a wee bit of patience:
|
I was not able to reproduce it with PipeWire as the selected driver, FWIW.
It is a user-configurable setting and I was trying junk values during testing... 😅 |
Huh |
@icculus: What do you make of this? |
Well, for what it's worth, those drain-waits-upon-close are the problem: diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 96586fe..2996b37 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -791,7 +791,7 @@ static int SDLCALL SDL_RunAudio(void *userdata)
}
/* Wait for the audio to drain. */
- SDL_Delay(((device->spec.samples * 1000) / device->spec.freq) * 2);
+// SDL_Delay(((device->spec.samples * 1000) / device->spec.freq) * 2);
current_audio.impl.ThreadDeinit(device);
diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c
index 3ed66f2..b57fe66 100644
--- a/src/audio/alsa/SDL_alsa_audio.c
+++ b/src/audio/alsa/SDL_alsa_audio.c
@@ -454,12 +454,12 @@ static void ALSA_FlushCapture(_THIS)
static void ALSA_CloseDevice(_THIS)
{
if (this->hidden->pcm_handle) {
- /* Wait for the submitted audio to drain
- ALSA_snd_pcm_drop() can hang, so don't use that.
- */
- Uint32 delay = ((this->spec.samples * 1000) / this->spec.freq) * 2;
- SDL_Delay(delay);
-
+// /* Wait for the submitted audio to drain
+// ALSA_snd_pcm_drop() can hang, so don't use that.
+// */
+// Uint32 delay = ((this->spec.samples * 1000) / this->spec.freq) * 2;
+// SDL_Delay(delay);
+//
ALSA_snd_pcm_close(this->hidden->pcm_handle);
}
SDL_free(this->hidden->mixbuf); You don't see the issue with pipewire because (i) it doesn't go through SDL_RunAudio, and (ii) its CloseDevice doesn't try to wait. Alsa is affected the worst because it's hit by waits in both SDL_RunAudio and ALSA_CloseDevice. PulseAudio and Disk are waited through SDL_RunAudio. Haven't looked at other backends. Well, if I say 'shutdown', it means shutdown dam'mit and that I don't care if any buffer is left to play because I did say 'shutdown". (We were hitting a slow shutdown issues in pulseaudio in SDL-1.2 but a patch was rejected because users might expect any left-over buffers to play, i.e. libsdl-org/SDL-1.2#673. I hope we don't do that here this time.) |
Yeah, the waits are because you don't want it to drop the end of playback (you might have said "shutdown dammit," but you also said "play this buffer, dammit," and if you have a media player app it might mean the end of the song cuts off, etc). The problem isn't the wait, it's the wait taking a long long time. There's no reason this should take minutes to quit, so there's probably a bug in the delay calculation. I'll take a look. |
I think the delay calculation—at least in the snippet sezero pasted—is technically correct. At 1Hz with a 1024 frame buffer size, it will take up to 2048 seconds to clear both buffers, or ~34 minutes (consistent with the wait times I saw). |
Well, I said "shutdown dammit" after I said "play this buffer dammit", so that should be considered as an overrule. And if a user hits ^shutdown' in his media player app, then it means he doesn't want to hear anything more. I won't argue further though, let's just fix the issue. |
Operating system: Fedora KDE Plasma Desktop 40
Device: ASUS X555LA
Branch: SDL2
Release: 2.30.3
Release: 2.30.2
Release: 2.30.1 (repository)
Operating system: Fedora KDE Plasma Desktop 39
Device: Acer Aspire E 15 E5-575G-53VG
Release: 2.28.5 (repository)
After initializing an audio device with a very low audio rate (10Hz used in the example),
SDL_CloseAudioDevice
temporarily hangs when attempting to close it. The amount of time it hangs seems inversely proportional to the audio rate requested; it takes a couple of seconds to close a device with 1024Hz, several minutes for 10Hz, and up to an hour for 1Hz. This only happens with the PulseAudio driver.Expected behavior:
SDL_CloseAudioDevice
should not take this long to close an opened device and/orSDL_OpenAudioDevice
should fail for rates where this bug is noticeable.Example: compile with
gcc -g $(sdl2-config --cflags --libs)
and run with gdb.SDL_OpenAudioDevice
will succeed, and thenSDL_CloseAudioDevice
will wait on its mutex for a very long time:(Sorry if this is a duplicate report; I saw similar closed reports for past releases and for SDL3 but none specifically associated with PulseAudio and the requested audio rate.)
The text was updated successfully, but these errors were encountered: