-
Notifications
You must be signed in to change notification settings - Fork 476
Description
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?