Skip to content

Commit 0246442

Browse files
authored
ALSA: Don't panic when handling invalid stream timestamps. (#886)
1 parent 8615160 commit 0246442

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/host/alsa/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,19 +872,23 @@ fn stream_timestamp(
872872
let ts = status.get_htstamp();
873873
let nanos = timespec_diff_nanos(ts, trigger_ts);
874874
if nanos < 0 {
875-
panic!(
875+
let description = format!(
876876
"get_htstamp `{}.{}` was earlier than get_trigger_htstamp `{}.{}`",
877877
ts.tv_sec, ts.tv_nsec, trigger_ts.tv_sec, trigger_ts.tv_nsec
878878
);
879+
return Err(BackendSpecificError { description });
879880
}
880881
Ok(crate::StreamInstant::from_nanos(nanos))
881882
}
882883
Some(creation) => {
883884
let now = std::time::Instant::now();
884885
let duration = now.duration_since(creation);
885-
let instant = crate::StreamInstant::from_nanos_i128(duration.as_nanos() as i128)
886-
.expect("stream duration has exceeded `StreamInstant` representation");
887-
Ok(instant)
886+
crate::StreamInstant::from_nanos_i128(duration.as_nanos() as i128).ok_or(
887+
BackendSpecificError {
888+
description: "stream duration has exceeded `StreamInstant` representation"
889+
.to_string(),
890+
},
891+
)
888892
}
889893
}
890894
}

0 commit comments

Comments
 (0)