module/alsa: handle ALSA device disappearing #87
Manually merged
dnkl
merged 1 commits from alsa-handle-device-disconnect
into master
12 months ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'alsa-handle-device-disconnect'
Deleting a branch is permanent. It CANNOT be undone. Continue?
With this patch, a non-existing ALSA device is no longer considered a fatal error. Instead, we keep retrying until we succeed.
Furthermore, if we have successfully opened the ALSA device, and it then disappears, we a) no longer crash, or cause 100% CPU usage, and b) try to re-connect to the device.
With this, we now handle e.g. USB soundcards being disconnected and then re-connected. We should also handle pseudo devices, like pipewire provides ones, when yambar is started before pipewire.
Note that I couldn't find a way to use e.g. inotify, or udev to avoid polling. That doesn't mean it isn't possible. For now, this is still better than before. Note that the polling algorithm starts with a 0.5s interval, but quickly backs off up to 30s.
Closes #59
Closes #61
Closes #86
The fix works great! There might be some issues left with pipewire, but pure alsa works perfectly fine. (Although I would assume it's a bug with pipewire's alsa emulation.)
The warning at alsa.c:150 still triggers inconsistently. Does it make sense to keep the warning when yambar doesn't track channel volume?
Patch for the example configuration:
Patch
No, I'll remove it, but in a separate commit. Future enhancement possibility: add config option to select which channel to use as volume source!
I don't have that, so cannot test. But if any issues show up, report them and I'll try to fix them.
FWIW the reason yambar hanged at 100% is because the ALSA provided FDs returned
POLLER | POLLNVAL
, but notPOLLHUP
when the device disappeared.This meant we never broke out of the
poll()
loop, and thatpoll()
kept returning immediately due to the FDs being in an error state.Looks very similar to what I did while testing this :D
be7ee1d2a0
tobe6e714eb0
12 months ago591cae4c6d
into master manually 12 months ago@JorwLNKwpH
ae7d54fb80
BTW, why did inotify for /dev/snd/ and retry for the card when /dev/snd changes not work?
Hmm, you're right, that should work. I was mainly looking for a way to get the path(s) to the configured soundcard. Something the ALSA API can't do.
But, just watching
/dev/snd
should be enough, and is way better than polling.591cae4c6d
.