aboutsummaryrefslogtreecommitdiffstats
path: root/nihav-core/src
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2019-11-13 19:41:07 +0100
committerKostya Shishkov <kostya.shishkov@gmail.com>2019-11-13 19:41:07 +0100
commit266da7b9db18727dc065a4e8971ecb0ac0b1e45f (patch)
tree7cc86c0982c6af734bbd78bafc52bc69279805e6 /nihav-core/src
parent37f2396bf98a72c252b18ebc20deb6ba0ce0018f (diff)
downloadnihav-266da7b9db18727dc065a4e8971ecb0ac0b1e45f.tar.gz
core/frame: add time to timestamp conversion utility function
Diffstat (limited to 'nihav-core/src')
-rw-r--r--nihav-core/src/frame.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs
index 091ba99..b1a81b7 100644
--- a/nihav-core/src/frame.rs
+++ b/nihav-core/src/frame.rs
@@ -663,6 +663,28 @@ impl NATimeInfo {
pub fn set_pts(&mut self, pts: Option<u64>) { self.pts = pts; }
pub fn set_dts(&mut self, dts: Option<u64>) { self.dts = dts; }
pub fn set_duration(&mut self, dur: Option<u64>) { self.duration = dur; }
+
+ pub fn time_to_ts(time: 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 = time.checked_mul(tb_num);
+ if let Some(tmp) = tmp {
+ tmp / base / tb_den
+ } else {
+ let tmp = time.checked_mul(tb_num);
+ if let Some(tmp) = tmp {
+ tmp / base / tb_den
+ } else {
+ let coarse = time / base;
+ let tmp = coarse.checked_mul(tb_num);
+ if let Some(tmp) = tmp {
+ tmp / tb_den
+ } else {
+ (coarse / tb_den) * tb_num
+ }
+ }
+ }
+ }
}
#[allow(dead_code)]