[smpeg] THREADED_AUDIO decoding

Eric Branlund ebranlund at fastmail.com
Sun May 23 20:31:06 EDT 2021


On an OpenBSD 6.9 system which has smpeg handle mp3 loading for sdl-mixer (both are the current versions installed from pkg_add; smpeg is smpeg-0.4.4p17 and sdl-mixer is sdl-mixer-1.2.12p5), trying to play an mp3 file with sdl-mixer's command-line utility, playmus, hangs.  The mp3 file used was this one, https://github.com/angband/angband/blob/master/lib/sounds/pls_tone_blurk.mp3?raw=true , and the command line used with playmus was

playmus pls_tone_blurk.mp3

Other sounds from Angband also hang as does that game's own sound handling which uses sdl-mixer.  The call stack reported by gdb for playmus's threads at the point of the hang are at the end of this message.

Building smpeg with the debugging output statements in MPEGring.cpp uncommented and using that with sdl-mixer points to write buffers being acquired but never made available for reading when trying to play that sound file:

Waiting for write buffer (16 available)
Waiting for read buffer (0 available)
Finished waiting for write buffer
Waiting for write buffer (15 available)
Finished waiting for write buffer
Waiting for write buffer (14 available)
Finished waiting for write buffer
Waiting for write buffer (13 available)
Finished waiting for write buffer
Waiting for write buffer (12 available)
Finished waiting for write buffer
Waiting for write buffer (11 available)
Finished waiting for write buffer
Waiting for write buffer (10 available)
Finished waiting for write buffer
Finished write buffer of 0 bytes, making available for reads (0+1 available for reads)
Finished waiting for read buffer
Finished read buffer, making available for writes (9+1 available for writes)
Waiting for read buffer (0 available)

The apparent cause of that are these lines in audio/mpegtoraw.cpp's Decode_MPEGaudio():

            if((Uint32)audio->rawdatawriteoffset*2 <= audio->ring->BufferSize())
              audio->ring->WriteDone(audio->rawdatawriteoffset*2, timestamp);

Those lines haven't changed between 0.4.4 and the current version on svn.icculus.org.  Changing them to

            assert(audio->rawdatawriteoffset <= audio->ring->BufferSize());
            audio->ring->WriteDone(audio->rawdatawriteoffset, timestamp);

avoids the hang.  That change is attached as a patch (computed against revision 413 of audio/mpegtoraw.cpp).


Eric Branlund
ebranlund at fastmail.com

         
playmus state at point of hang according to gdb:

>info threads
2 thread 603235 futex () at /tmp/-:3
*1 thread 247780 futex() at /tmp/-:3
>bt
0 futex () at /tmp/-:3
1 0x000000db57ad17a7 in _rthread_mutex_timedlock () at include/machine/atomic.h:94
2 0x000000da8c5de18c in SDL_mutex/libP () from /usr/local/libSDL.so.8.0
3 0x000000dac14be458 in Mix_PlayingMusic () from /usr/local/lib/libSDL_mixer.so.5.0
4 0x000000d8684cea98 in ?? from /usr/local/bin/playmus
5 0x000000d8684ce271 in ?? from /usr/local/bin/playmus
6 0x0000000000000000 in ?? ()
>thread 2
[Switching to thread 2 (thread 603235)] 0 futex () at /tmp/-:3
3 in /tmp/-
>bt
0 futex () at /tmp/-:3
1 0x000000da6f489320 in sem_wait () at synch.h:41
2 0x000000da8c5dde08 in SDL_SemWait () from /usr/local/lib/libSDL.so.8.0
3 0x000000db59fb1393 in MPEG_ring::NextReadBuffer () from /usr/local/lib/libsmpeg.so.2.0
4 0x000000db59fcc210 in Play_MPEGaudio () from /usr/local/lib/libsmpeg.so.2.0
5 0x000000dac14bcc08 in music_mixer () from /usr/local/lib/libSDL_mixer.so.5.0
6 0x000000dac14ba474 in mix_channels () from /usr/local/lib/libSDL_mixer.so.5.0
7 0x000000da8c59014e in SDL_RunAudio () from /usr/local/lib/libSDL.so.8.0
8 0x000000da8c59c01c in SDL_RunThread () from /usr/local/lib/libSDL.so.8.0
9 0x000000da8c5ddc29 in RunThread () from /usr/local/lib/libSDL.so.8.0
10 0x000000da6f48af51 in _rthread_start () from /usr/src/lib/librthread/rthread.c:96
11 0x000000db57a6eb9a in _tfork_thread () at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:84
12 0x000000db57a6eb9a in _tfork_thread () at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:84
Previous frame identical to this frame (corrupt stack?)`

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: smpeg-THREADED_AUDIO-patch.txt
URL: <http://icculus.org/pipermail/smpeg/attachments/20210523/57057f0e/attachment.txt>


More information about the smpeg mailing list