aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2020-07-09 10:17:06 +0200
committerKostya Shishkov <kostya.shishkov@gmail.com>2020-07-09 10:17:06 +0200
commit0eb53738b53a489850cc7d3ad8ba21aa8f93a093 (patch)
tree9e69b18523e42fbf88f10f1a8ac018cb05b15d7d
parent2c6462c81d1c18ccb26a6262400b33108e983820 (diff)
downloadnihav-0eb53738b53a489850cc7d3ad8ba21aa8f93a093.tar.gz
core/frame: add None to NATimePoint and comparison functions to NATimeInfo
-rw-r--r--nihav-core/src/frame.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs
index f0794a8..741c175 100644
--- a/nihav-core/src/frame.rs
+++ b/nihav-core/src/frame.rs
@@ -969,6 +969,33 @@ impl NATimeInfo {
}
}
}
+ fn get_cur_ts(&self) -> u64 { self.pts.unwrap_or(self.dts.unwrap_or(0)) }
+ fn get_cur_millis(&self) -> u64 {
+ let ts = self.get_cur_ts();
+ Self::ts_to_time(ts, 1000, self.tb_num, self.tb_den)
+ }
+ /// Checks whether the current time information is earler than provided reference time.
+ pub fn less_than(&self, time: NATimePoint) -> bool {
+ if self.pts.is_none() && self.dts.is_none() {
+ return true;
+ }
+ match time {
+ NATimePoint::PTS(rpts) => self.get_cur_ts() < rpts,
+ NATimePoint::Milliseconds(ms) => self.get_cur_millis() < ms,
+ NATimePoint::None => false,
+ }
+ }
+ /// Checks whether the current time information is the same as provided reference time.
+ pub fn equal(&self, time: NATimePoint) -> bool {
+ if self.pts.is_none() && self.dts.is_none() {
+ return time == NATimePoint::None;
+ }
+ match time {
+ NATimePoint::PTS(rpts) => self.get_cur_ts() == rpts,
+ NATimePoint::Milliseconds(ms) => self.get_cur_millis() == ms,
+ NATimePoint::None => false,
+ }
+ }
}
/// Time information for specifying durations or seek positions.
@@ -978,6 +1005,8 @@ pub enum NATimePoint {
Milliseconds(u64),
/// Stream timestamp.
PTS(u64),
+ /// No time information present.
+ None,
}
impl fmt::Display for NATimePoint {
@@ -1013,6 +1042,9 @@ impl fmt::Display for NATimePoint {
NATimePoint::PTS(pts) => {
write!(f, "{}pts", pts)
},
+ NATimePoint::None => {
+ write!(f, "none")
+ },
}
}
}