We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3623 - ALSA sound sometimes hangs on Raspberry Pi 2 B running Raspbian
Summary: ALSA sound sometimes hangs on Raspberry Pi 2 B running Raspbian
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: 2.0.5
Hardware: ARM Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-05 22:48 UTC by Boris Gjenero
Modified: 2017-05-18 23:21 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Gjenero 2017-04-05 22:48:52 UTC
I have a Raspberry Pi 2 B running Raspbian and connected to a TV via HDMI with sound. There I compiled SDL 2.0.5 for use with full screen apps outside of X using instructions at https://solarianprogrammer.com/2015/01/22/raspberry-pi-raspbian-getting-started-sdl-2/. Sound occasionally hangs inside libasound2 snd_pcm_writei(). Then attempts to quit the app also hang, because the SDLAudioDev1 thread never finishes and close_audio_device() waits forever for it. I'm now reproducing this with the loopwave.c test.

This may just be a Raspberry Pi sound driver or ALSA problem, but I'm reporting it here just in case it is relevant.

Here is the main thread backtrace:

#0  0x76c9a274 in pthread_join (threadid=<optimized out>, 
    thread_return=thread_return@entry=0x0) at pthread_join.c:92
#1  0x76f8f4f8 in SDL_SYS_WaitThread (thread=thread@entry=0x2b040)
    at /home/pi/SDL2-2.0.5/src/thread/pthread/SDL_systhread.c:237
#2  0x76f4f424 in SDL_WaitThread_REAL (thread=0x2b040, status=status@entry=0x0)
    at /home/pi/SDL2-2.0.5/src/thread/SDL_thread.c:469
#3  0x76ed2fac in close_audio_device (device=0x22bf0)
    at /home/pi/SDL2-2.0.5/src/audio/SDL_audio.c:1096
#4  0x00010e14 in main (argc=1, argv=0x7efff384) at loopwave.c:155

Here is the AudioDev1 thread backtrace. To get the whole backtrace I needed to install libasound2-dbg; otherwise this backtrace was truncated and useless.

#0  0x76e36b84 in poll () at ../sysdeps/unix/syscall-template.S:81
#1  0x76bb8428 in poll (__timeout=-1, __nfds=1, __fds=0x76ec2d30)
    at /usr/include/arm-linux-gnueabihf/bits/poll2.h:46
#2  snd1_pcm_wait_nocheck (pcm=pcm@entry=0x26310, timeout=timeout@entry=-1)
    at pcm.c:2418
#3  0x76bbdc04 in snd1_pcm_write_areas (pcm=pcm@entry=0x26310, 
    areas=areas@entry=0x76ec2da8, offset=offset@entry=0, size=<optimized out>, 
    size@entry=4096, func=0x76bffcd4 <ioplug_priv_transfer_areas>)
    at pcm.c:6808
#4  0x76c003cc in snd_pcm_ioplug_writei (pcm=0x26310, buffer=<optimized out>, 
    size=4096) at pcm_ioplug.c:561
#5  0x76f8d4b0 in ALSA_PlayDevice (this=0x22bf0)
    at /home/pi/SDL2-2.0.5/src/audio/alsa/SDL_alsa_audio.c:330
#6  0x76ed2e2c in SDL_RunAudio (devicep=devicep@entry=0x22bf0)
    at /home/pi/SDL2-2.0.5/src/audio/SDL_audio.c:780
#7  0x76f4f01c in SDL_RunThread (data=0x22e90)
    at /home/pi/SDL2-2.0.5/src/thread/SDL_thread.c:283
#8  0x76f8f328 in RunThread (data=<optimized out>)
    at /home/pi/SDL2-2.0.5/src/thread/pthread/SDL_systhread.c:74
#9  0x76c98e90 in start_thread (arg=0x76ec3460) at pthread_create.c:311
#10 0x76e40598 in ?? ()
    at ../ports/sysdeps/unix/sysv/linux/arm/nptl/../clone.S:92
   from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Comment 1 Boris Gjenero 2017-04-06 00:14:05 UTC
This may have nothing to do with SDL. Later I coverted sample.wav to PCM and played it via "while true ; do time aplay sample-pcm.wav ; sleep 2 ; done" and it kept hanging after a few iterations. 

After uninstalling PulseAudio from the Raspberry Pi (pulseaudio-module-x11 pulseaudio pulseaudio-utils libpulsedsp), I'm not seeing these hangs anymore.
Comment 2 Ryan C. Gordon 2017-05-18 23:21:24 UTC
(In reply to Boris Gjenero from comment #1)
> This may have nothing to do with SDL. Later I coverted sample.wav to PCM and
> played it via "while true ; do time aplay sample-pcm.wav ; sleep 2 ; done"
> and it kept hanging after a few iterations. 
> 
> After uninstalling PulseAudio from the Raspberry Pi (pulseaudio-module-x11
> pulseaudio pulseaudio-utils libpulsedsp), I'm not seeing these hangs anymore.

fwiw, I had similar problems on older RPi units when my otherwise totally fine USB cord couldn't deliver enough power (but it could also be a PulseAudio bug).

I'm going to close this bug for now since it doesn't appear to be an SDL issue, but please feel free to reopen it if that turns out to be incorrect!

Thanks,
--ryan.