]> git.nihav.org Git - nihav.git/commitdiff
fix NATimeInfo::time_to_ts()
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 25 Oct 2020 15:08:50 +0000 (16:08 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 25 Oct 2020 15:09:44 +0000 (16:09 +0100)
nihav-core/src/frame.rs
nihav-llaudio/src/demuxers/flac.rs

index 8c58e19b66756c2ebbcaf45fb981cc245ac37394..5ddec1adbba0d247c323df82ce8e5e20c34a4e1b 100644 (file)
@@ -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
                 }
             }
         }
index 16f8388b27a4f273a757d474ac6e5767f62c0bf9..0b917dd7e6ab077cd3dc6372dd83db5c986e56b5 100644 (file)
@@ -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 {