libxmp / xmp-cli

Command-line mod player using libxmp
GNU General Public License v2.0
75 stars 22 forks source link

Hang in `snd_pcm_writei` when using the ALSA driver with PipeWire. #44

Closed AliceLR closed 1 year ago

AliceLR commented 2 years ago

In Fedora 35 with PipeWire 0.3.43, xmp will occassionally hang in the ALSA driver's play function during playback. This bug can persist between closing xmp and restarting it. I think this is an upstream bug in PipeWire's ALSA bindings, because they've had nearly identical issues in the past and I've encountered similar problems with software using SDL2 audio.

The hang occurs in a poll() call internal to snd_pcm_writei, which expanded here to snd_pcm_ioplug_writei, identical to the fixed issue linked above:

Thread 1 "xmp" received signal SIGINT, Interrupt.
0x00007ffff7c3f73f in poll () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7c3f73f in poll () from /lib64/libc.so.6
#1  0x00007ffff7e582b9 in snd1_pcm_wait_nocheck () from /lib64/libasound.so.2
#2  0x00007ffff7e6ebe1 in snd1_pcm_write_areas.part.0.constprop () from /lib64/libasound.so.2
#3  0x00007ffff7e6f0cf in snd_pcm_mmap_writei () from /lib64/libasound.so.2
#4  0x00007ffff7e6f2d1 in snd_pcm_ioplug_writei () from /lib64/libasound.so.2
#5  0x0000000000407f25 in play (b=0x489600, i=<optimized out>) at sound_alsa.c:89
#6  0x0000000000403f85 in main (argc=4, argv=<optimized out>) at main.c:554

A native PipeWire driver might be a workaround, but I don't have one fully working yet.

sezero commented 2 years ago

Does snd_pcm_drop instead of snd_pcm_drain help?

sezero commented 2 years ago

Also: is the pulseaudio driver affected? If it is, does pa_stream_flush help instead of pa_stream_drain?

AliceLR commented 2 years ago

Does snd_pcm_drop instead of snd_pcm_drain help?

The only place snd_pcm_drain is used is in the driver flush function, which is only called on exit, so no, I don't think it would help. I did try inserting snd_pcm_drain and then snd_pcm_drop before the snd_pcm_prepare in play and the bug still occurs.

I haven't tried pulseaudio yet...

sezero commented 2 years ago

Ah, I was confused by that upstream bug - your issue is during playback and not exit.

Maybe worth reporting upstream (and maybe also to RedHat bugzilla.)

AliceLR commented 2 years ago

Also: is the pulseaudio driver affected? If it is, does pa_stream_flush help instead of pa_stream_drain?

Yes, though it seems to occur less often than with ALSA. Replacing that function also doesn't help.

AliceLR commented 2 years ago

Yeah... so this happens even linking against PipeWire directly with one of their tutorial programs. https://docs.pipewire.org/tutorial4_8c-example.html

Potentially relevant upstream issue: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1301

edit: I just commented to that issue for now. I don't have anything with PipeWire aside from virtual machine guests right now, but I'll get something set up to confirm it's not a general issue with xmp and PipeWire...

sezero commented 1 year ago

Looks like this isn't our bug and there was a workaround posted at https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1301

Should we close this, or is there really something we can do here?

sezero commented 1 year ago

@AliceLR: PING?

sezero commented 1 year ago

Closing, because there exists a workaround and not our bug.