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: Don't panic when handling invalid stream timestamps. #886

Merged
merged 1 commit into from
May 12, 2024
Merged
Changes from all commits
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
12 changes: 8 additions & 4 deletions src/host/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,19 +872,23 @@ fn stream_timestamp(
let ts = status.get_htstamp();
let nanos = timespec_diff_nanos(ts, trigger_ts);
if nanos < 0 {
panic!(
let description = format!(
"get_htstamp `{}.{}` was earlier than get_trigger_htstamp `{}.{}`",
ts.tv_sec, ts.tv_nsec, trigger_ts.tv_sec, trigger_ts.tv_nsec
);
return Err(BackendSpecificError { description });
}
Ok(crate::StreamInstant::from_nanos(nanos))
}
Some(creation) => {
let now = std::time::Instant::now();
let duration = now.duration_since(creation);
let instant = crate::StreamInstant::from_nanos_i128(duration.as_nanos() as i128)
.expect("stream duration has exceeded `StreamInstant` representation");
Ok(instant)
crate::StreamInstant::from_nanos_i128(duration.as_nanos() as i128).ok_or(
BackendSpecificError {
description: "stream duration has exceeded `StreamInstant` representation"
.to_string(),
},
)
}
}
}
Expand Down