pipewire-alsa hangs in busy wait when reaching hw_ptr wrap point
When pipewire-alsa's hw_ptr reaches the boundary (defined in snd_pcm_pipewire_t) the application will hang in snd_pcm_readi() while consuming a lot of CPU. This takes hours on a 32-bit arch and probably forever on a 64-bit arch unless the boundary in snd_pcm_sw_params is set to a lower value than default. I reproduced it faster by hacking alsa-lib:
diff --git a/src/pcm/pcm_params.c b/src/pcm/pcm_params.c index ceb3b1a..802b26e 100644 --- a/src/pcm/pcm_params.c +++ b/src/pcm/pcm_params.c @@ -2337,6 +2337,7 @@ static int snd_pcm_sw_params_default(snd_pcm_t *pcm, snd_pcm_sw_params_t *params params->boundary = pcm->buffer_size; while (params->boundary * 2 <= LONG_MAX - pcm->buffer_size) params->boundary *= 2;
-
params->boundary = 16 * pcm->buffer_size; return 0;
}
Note that for some reason it doesn't happen on the first stream after pipewire (server) has been restarted. But on the second stream it seems to always happen.