]> git.nihav.org Git - nihav.git/commitdiff
core: add ts_to_time() utility function
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 15 Nov 2019 18:43:37 +0000 (19:43 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 15 Nov 2019 18:43:37 +0000 (19:43 +0100)
nihav-core/src/frame.rs

index b1a81b72874b40bcf2a73656fd6daf10ea8a855d..ae61c8810a16a7539e22490adf69d686999cb8d6 100644 (file)
@@ -685,6 +685,26 @@ impl NATimeInfo {
             }
         }
     }
+    pub fn ts_to_time(ts: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 {
+        let tb_num = tb_num as u64;
+        let tb_den = tb_den as u64;
+        let tmp = ts.checked_mul(base);
+        if let Some(tmp) = tmp {
+            let tmp2 = tmp.checked_mul(tb_num);
+            if let Some(tmp2) = tmp2 {
+                tmp2 / tb_den
+            } else {
+                (tmp / tb_den) * tb_num
+            }
+        } else {
+            let tmp = ts.checked_mul(tb_num);
+            if let Some(tmp) = tmp {
+                (tmp / tb_den) * base
+            } else {
+                (ts / tb_den) * base * tb_num
+            }
+        }
+    }
 }
 
 #[allow(dead_code)]