fmp4mux: Use saturing subtraction to calculate sample durations

PTS/DTS might go backwards if the input is borderline broken but that
shouldn't cause a panic.
This commit is contained in:
Sebastian Dröge 2022-05-13 13:27:42 +03:00 committed by Sebastian Dröge
parent dcad6ffe34
commit 4bc0ae09fa

View file

@ -650,14 +650,14 @@ impl FMP4Mux {
if let Some(buffer) = bs.pop_front() {
dequeued_time += match bs.front() {
Some(next_buffer) => match Option::zip(next_buffer.dts, buffer.dts) {
Some((b, a)) => b - a,
None => next_buffer.pts - buffer.pts,
Some((b, a)) => b.saturating_sub(a),
None => next_buffer.pts.saturating_sub(buffer.pts),
},
None => {
let timing_info = timing_infos[idx].as_ref().unwrap();
match Option::zip(timing_info.end_dts, buffer.dts) {
Some((b, a)) => b - a,
None => timing_info.end_pts - buffer.pts,
Some((b, a)) => b.saturating_sub(a),
None => timing_info.end_pts.saturating_sub(buffer.pts),
}
}
};