alsa-pcm-sink may not release all buffers when it pauses, causing underruns when it starts again
I am seeing a bug at random where alsa-pcm-sink starts underrunning while switching playback from a client node that uses large buffers to another one. It looks like this is what happens:
- first client node links to the audioadapter that contains this alsa-pcm-sink; playback starts well.
- because the buffers are big, alsa-pcm-sink consumes them in smaller chunks and releases the buffer back to fmtconvert when the whole buffer is consumed (audioadapter pipeline is:
merger ! channelmix ! resampler ! fmtconvert ! alsa-pcm-sink
) - the client node is unlinked, the audioadapter is sent
SPA_NODE_COMMAND_Pause
; this propagates to the alsa-pcm-sink and the device is closed, but:- if the buffer was not consumed entirely, it is not released back to fmtconvert
- second client links, audioadapter is sent
SPA_NODE_COMMAND_Start
-
negotiate_buffers()
in audioadapter doesn't do anything, because there is already 1 buffer allocated - playback starts, but now every time the fmtconvert process() function is called, it returns -EPIPE because this 1 buffer is still not released by alsa-pcm-sink. alsa-pcm-sink starts underrunning
- this never stops, until you restart pipewire