Files
qbz/crates/qbz-audio
vicrodh 9fad1dc123 fix(audio): unstick ALSA direct stop, drain and EBADFD write recovery
Three transition killers on drivers that require an explicit drop
(snd-rpi-hifiberry/PCM5122; the desktop's USB DAC tolerated all three,
which is why only the Pi died):

1. stop() called prepare() without drop(): prepare from
   RUNNING/DRAINING returns EBUSY there — every stop failed and left
   the pcm in limbo. Now drop+prepare (drop EBADFD tolerated).
2. A write racing a still-draining pcm (natural end + late gapless
   append) gets EBADFD, and snd_pcm_recover(77) is unsupported on this
   stack, so the write died and the writer thread exited. New
   recover_write_error(): normal recover first, then drop+prepare for
   EBADFD (11 write sites via one helper).
3. snd_pcm_drain can block forever when the device stops clocking —
   the writer wedged and no 'engine empty' ever fired. drain() is now
   bounded: poll pcm.state() with a 10s deadline; the tail finishing
   shows as XRUN (drop+prepare), and a stuck device is cancelled.

km
2026-07-22 09:04:05 -06:00
..