Check if the frame length is zero in SkipDuration. (#388)

If the source we are skipping runs out of data, it will return Some(0)
as the frame length. Before, this would cause an infinite loop because
we would skip zero samples forever. This commit fixes it by checking
explicitly if the frame length is zero and bailing out if it is.
This commit is contained in:
Aaron Kofsky 2021-07-17 18:52:16 -04:00 committed by GitHub
parent ba78af2070
commit 2e08a7efa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,6 +33,12 @@ where
// .unwrap() safety: if `current_frame_len()` is None, the body of the `if` statement // .unwrap() safety: if `current_frame_len()` is None, the body of the `if` statement
// above returns before we get here. // above returns before we get here.
let frame_len: usize = input.current_frame_len().unwrap(); let frame_len: usize = input.current_frame_len().unwrap();
// If frame_len is zero, then there is no more data to skip. Instead
// just bail out.
if frame_len == 0 {
return;
}
let ns_per_sample: u128 = let ns_per_sample: u128 =
NS_PER_SECOND / input.sample_rate() as u128 / input.channels() as u128; NS_PER_SECOND / input.sample_rate() as u128 / input.channels() as u128;