ALSA: Don't panic when handling invalid stream timestamps. (#886)

This commit is contained in:
Jonas Wagner 2024-05-13 00:40:06 +02:00 • committed by GitHub
parent 8615160344
commit 0246442da2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -872,19 +872,23 @@ fn stream_timestamp(
let ts = status.get_htstamp(); let ts = status.get_htstamp();
let nanos = timespec_diff_nanos(ts, trigger_ts); let nanos = timespec_diff_nanos(ts, trigger_ts);
if nanos < 0 { if nanos < 0 {
panic!( let description = format!(
"get_htstamp `{}.{}` was earlier than get_trigger_htstamp `{}.{}`", "get_htstamp `{}.{}` was earlier than get_trigger_htstamp `{}.{}`",
ts.tv_sec, ts.tv_nsec, trigger_ts.tv_sec, trigger_ts.tv_nsec ts.tv_sec, ts.tv_nsec, trigger_ts.tv_sec, trigger_ts.tv_nsec
); );
return Err(BackendSpecificError { description });
} }
Ok(crate::StreamInstant::from_nanos(nanos)) Ok(crate::StreamInstant::from_nanos(nanos))
} }
Some(creation) => { Some(creation) => {
let now = std::time::Instant::now(); let now = std::time::Instant::now();
let duration = now.duration_since(creation); let duration = now.duration_since(creation);
let instant = crate::StreamInstant::from_nanos_i128(duration.as_nanos() as i128) crate::StreamInstant::from_nanos_i128(duration.as_nanos() as i128).ok_or(
.expect("stream duration has exceeded `StreamInstant` representation"); BackendSpecificError {
Ok(instant) description: "stream duration has exceeded `StreamInstant` representation"
.to_string(),
},
)
} }
} }
} }