cpal
cpal copied to clipboard
Make snd_pcm_recover silent
I am writing a music player with a text user interface (using crossterm and tui-rs).
When running on Linux, cpal uses ALSA. When buffer underrun occurs, the current behaviour is calling snd_pcm_recover with the silent parameter being true, and snd_pcm_recover will print pcm.c:8568:(snd_pcm_recover) underrun occurred on the console.
While this behaviour is okay for usual CLI or GUI programs, it will garbage the TUI screen. Once that happens, the screen must be redrawn, but there is no way for the application to know that underrun occurred. (I can still let user press CTRL+L to redraw the screen to fix this manually, though.) The proper way to indicate error to the user is to log the message and print it in a log window (a particular region of the console screen), if the user actually opened the log window at all.
The code that controls this behaviour in cpal is in src/host/alsa/mod.rs line 806:
loop {
match stream.channel.io_bytes().writei(buffer) {
Err(err) if err.errno() == nix::errno::Errno::EPIPE => {
// buffer underrun
// TODO: Notify the user of this.
let _ = stream.channel.try_recover(err, false);
}
Err(err) => {
error_callback(err.into());
continue;
}
In try_recover(err, false), the false argument is hard-coded. As an application developer, I cannot change this.
Currently, the only workaround I can think about is to call snd_lib_error_set_handler to register my own error handler. This is bad because that is ALSA-specific, and my program may not always run on Linux.
Could you add an option to control the verbosity, or "Notify the user of this." as the comment says?
I think we should either disable this sort of thing (especially if interested users can hook up their own diagnostic anyway) or, perhaps, hook it up to the log crate. Strongly agree that (allowing our dependencies to be) doing stdio behind the scenes is incorrect.
Yeah ideally it should integrate with the log crate.
It is important to not be quite about issues though, otherwise people will complain that they get problems without an error message. But it should be possible to turn it off in a cross platform way.
support change this to log crate or make an option to disable the error.