Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALSA PCM.try_recover: error handling #909

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- ALSA(process_output): pass `silent=true` to `PCM.try_recover`, so it doesn't write to stderr

# Version 0.15.3 (2024-03-04)

- Add `try_with_sample_rate`, a non-panicking variant of `with_sample_rate`.
Expand Down
12 changes: 9 additions & 3 deletions src/host/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,15 @@ fn process_output(
loop {
match stream.channel.io_bytes().writei(buffer) {
Err(err) if err.errno() == libc::EPIPE => {
// buffer underrun
// TODO: Notify the user of this.
let _ = stream.channel.try_recover(err, false);
// ALSA underrun or overrun.
// See https://github.com/alsa-project/alsa-lib/blob/b154d9145f0e17b9650e4584ddfdf14580b4e0d7/src/pcm/pcm.c#L8767-L8770
// Even if these recover successfully, they still may cause audible glitches.

// TODO:
// Should we notify the user about successfully recovered errors?
// Should we notify the user about failures in try_recover, rather than ignoring them?
// (Both potentially not real-time-safe)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling the error callback is safe for our purposes. It's the user's responsibility to do real-time-safe things in their callbacks, or accept the risk of failing to.

_ = stream.channel.try_recover(err, true);
}
Err(err) => {
error_callback(err.into());
Expand Down