Mix_CloseAudio blocking 2 seconds with PulseAudio

Hello,
this has been happening since SDL1, for years, on Ubuntu and Fedora. I
don’t know if I use Mix_CloseAudio the wrong way, or it is a SDL_mixer
or a PulseAudio bug.
Mix_CloseAudio takes two seconds (roughly) to complete, always. The
backtrace of the thread calling the function is:

#0  0x00000037c7c08d97 in pthread_join (threadid=140737264133888,
thread_return=0x0) at pthread_join.c:92
#1  0x0000000000696250 in SDL_SYS_WaitThread (thread=0x225a3d0)
     at
/home/pisto/sorgenti/sauerlab/libSDL/src/thread/pthread/SDL_systhread.c:204
#2  0x000000000067e760 in SDL_WaitThread (thread=0x225a3d0, status=0x0)
     at /home/pisto/sorgenti/sauerlab/libSDL/src/thread/SDL_thread.c:402
#3  0x00000000006376dc in close_audio_device (device=0x27f4a30) at
/home/pisto/sorgenti/sauerlab/libSDL/src/audio/SDL_audio.c:755
#4  0x000000000063833b in SDL_CloseAudioDevice (devid=1) at
/home/pisto/sorgenti/sauerlab/libSDL/src/audio/SDL_audio.c:1163
#5  0x000000000063835f in SDL_CloseAudio () at
/home/pisto/sorgenti/sauerlab/libSDL/src/audio/SDL_audio.c:1171
#6  0x000000000078c849 in Mix_CloseAudio () at mixer.c:1160
#7 <omitted, my application code>

the audio thread has the following backtrace:

#0  0x00000037c74eb8bf in __GI_ppoll (fds=0x2258060, nfds=2,
timeout=<optimized out>, sigmask=sigmask at entry=0x0)
     at ../sysdeps/unix/sysv/linux/ppoll.c:56
#1  0x00000037df822aa7 in ppoll (__ss=0x0, __timeout=<optimized
out>, __nfds=<optimized out>, __fds=<optimized out>)
     at /usr/include/bits/poll2.h:77
#2  pa_mainloop_poll (m=m at entry=0x27f4c80) at pulse/mainloop.c:862
#3  0x00000037df82309e in pa_mainloop_iterate (m=0x27f4c80,
block=<optimized out>, retval=0x0) at pulse/mainloop.c:936
#4  0x000000000068d683 in PULSEAUDIO_WaitDone (this=0x27f4a30)
     at
/home/pisto/sorgenti/sauerlab/libSDL/src/audio/pulseaudio/SDL_pulseaudio.c:281
#5  0x0000000000636eeb in SDL_RunAudio (devicep=0x27f4a30) at
/home/pisto/sorgenti/sauerlab/libSDL/src/audio/SDL_audio.c:510
#6  0x000000000067e4ab in SDL_RunThread (data=0x2258eb0) at
/home/pisto/sorgenti/sauerlab/libSDL/src/thread/SDL_thread.c:280
#7  0x0000000000696004 in RunThread (data=0x2258eb0) at
/home/pisto/sorgenti/sauerlab/libSDL/src/thread/pthread/SDL_systhread.c:69
#8  0x00000037c7c07c53 in start_thread (arg=0x7ffff2a2a700) at
pthread_create.c:308
#9  0x00000037c74f5dbd in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:113

Can someone read this? In my understanding, pa_mainloop_iterate is
called with a block value of 1 from SDL, but the docs are not clear and
it is not specified whether it’s a value in milliseconds, seconds, or
just a boolean. I would guess milliseconds, but if so I don’t understand
this long delay.

Cheers.

It’s a PulseAudio bug. Our notes are here:

 https://bugzilla.libsdl.org/show_bug.cgi?id=1449

(The Pulse bug tracker is down at the moment, so I can’t see if they
ever fixed it, but I doubt it.)

I guess we could spin a thread internally to close the audio device, but
that’s nasty.

–ryan.On 11/10/13, 7:48 AM, Lorenzo Pistone wrote:

Hello,
this has been happening since SDL1, for years, on Ubuntu and Fedora. I
don’t know if I use Mix_CloseAudio the wrong way, or it is a SDL_mixer
or a PulseAudio bug.