From edad67652d6a007dc40fbdfa669522b4987285bf Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sun, 25 Oct 2020 16:08:50 +0100 Subject: [PATCH] fix NATimeInfo::time_to_ts() --- nihav-core/src/frame.rs | 21 ++++++++++++--------- nihav-llaudio/src/demuxers/flac.rs | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index 8c58e19..5ddec1a 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -940,20 +940,23 @@ impl NATimeInfo { pub fn time_to_ts(time: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 { let tb_num = u64::from(tb_num); let tb_den = u64::from(tb_den); - let tmp = time.checked_mul(tb_num); + let tmp = time.checked_mul(tb_den); if let Some(tmp) = tmp { - tmp / base / tb_den + tmp / base / tb_num } else { - let tmp = time.checked_mul(tb_num); - if let Some(tmp) = tmp { - tmp / base / tb_den + if tb_num < base { + let coarse = time / tb_num; + if let Some(tmp) = coarse.checked_mul(tb_den) { + tmp / base + } else { + (coarse / base) * tb_den + } } else { let coarse = time / base; - let tmp = coarse.checked_mul(tb_num); - if let Some(tmp) = tmp { - tmp / tb_den + if let Some(tmp) = coarse.checked_mul(tb_den) { + tmp / tb_num } else { - (coarse / tb_den) * tb_num + (coarse / tb_num) * tb_den } } } diff --git a/nihav-llaudio/src/demuxers/flac.rs b/nihav-llaudio/src/demuxers/flac.rs index 16f8388..0b917dd 100644 --- a/nihav-llaudio/src/demuxers/flac.rs +++ b/nihav-llaudio/src/demuxers/flac.rs @@ -202,7 +202,7 @@ impl<'a> DemuxCore<'a> for FLACDemuxer<'a> { self.src.seek(SeekFrom::Start(self.data_start + seek_info.pos))?; Ok(()) } else if let NATimePoint::Milliseconds(ms) = time { - let samppos = NATimeInfo::time_to_ts(ms, 1000, self.srate, 1); + let samppos = NATimeInfo::time_to_ts(ms, 1000, 1, self.srate); if self.known_frames.last().unwrap_or(&FrameSeekInfo::default()).sampleend >= samppos { for point in self.known_frames.iter().rev() { if point.samplepos <= samppos { -- 2.39.5