From 0eb53738b53a489850cc7d3ad8ba21aa8f93a093 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 9 Jul 2020 10:17:06 +0200 Subject: [PATCH] core/frame: add None to NATimePoint and comparison functions to NATimeInfo --- nihav-core/src/frame.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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") + }, } } } -- 2.39.5