diff --git a/src/codec/h264.rs b/src/codec/h264.rs index 6bd69cc..da21a87 100644 --- a/src/codec/h264.rs +++ b/src/codec/h264.rs @@ -536,8 +536,8 @@ impl Depacketizer { } let timestamp = VideoTimestamp { - timestamp: au.timestamp.timestamp, - timestamp_dts: dts, + pts: au.timestamp.timestamp, + dts, clock_rate: au.timestamp.clock_rate, start: au.timestamp.start, }; @@ -1280,8 +1280,8 @@ mod tests { \x00\x00\x00\x06\x65slice" ); let want = VideoTimestamp { - timestamp: 1, - timestamp_dts: 1, + pts: 1, + dts: 1, clock_rate: NonZeroU32::new(90_000).unwrap(), start: 0, }; @@ -1328,8 +1328,8 @@ mod tests { }; assert_eq!(frame.data(), b"\x00\x00\x00\x06\x01slice"); let want = VideoTimestamp { - timestamp: 0, - timestamp_dts: 0, + pts: 0, + dts: 0, clock_rate: NonZeroU32::new(90_000).unwrap(), start: 0, }; @@ -1395,8 +1395,8 @@ mod tests { \x00\x00\x00\x06\x65slice" ); let want = VideoTimestamp { - timestamp: 1, - timestamp_dts: 1, + pts: 1, + dts: 1, clock_rate: NonZeroU32::new(90_000).unwrap(), start: 0, }; diff --git a/src/lib.rs b/src/lib.rs index 41505d8..4c74ac1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -216,10 +216,10 @@ impl Debug for Timestamp { #[derive(Copy, Clone, PartialEq, Eq)] pub struct VideoTimestamp { /// A presentation timestamp which must be compared to `start`. - timestamp: i64, + pts: i64, /// A decode timestamp. - timestamp_dts: i64, + dts: i64, /// The codec-specified clock rate, in Hz. Must be non-zero. clock_rate: NonZeroU32, @@ -233,8 +233,8 @@ impl VideoTimestamp { #[inline] pub fn new(pts: i64, dts: i64, clock_rate: NonZeroU32, start: u32) -> Option { pts.checked_sub(i64::from(start)).map(|_| VideoTimestamp { - timestamp: pts, - timestamp_dts: dts, + pts, + dts, clock_rate, start, }) @@ -242,13 +242,13 @@ impl VideoTimestamp { /// Returns time since some arbitrary point before the stream started. #[inline] - pub fn timestamp(&self) -> i64 { - self.timestamp + pub fn pts(&self) -> i64 { + self.pts } #[inline] - pub fn timestamp_dts(&self) -> i64 { - self.timestamp_dts + pub fn dts(&self) -> i64 { + self.dts } /// Returns timestamp of the start of the stream. @@ -265,32 +265,32 @@ impl VideoTimestamp { /// Returns elapsed presentation time since the stream start in clock rate units. #[inline] - pub fn pts(&self) -> i64 { - self.timestamp - i64::from(self.start) + pub fn pts_elapsed(&self) -> i64 { + self.pts - i64::from(self.start) } /// Returns elapsed presentation time since the stream start in seconds, aka "normal play /// time" (NPT). #[inline] - pub fn pts_secs(&self) -> f64 { - (self.pts() as f64) / (self.clock_rate.get() as f64) + pub fn pts_elapsed_secs(&self) -> f64 { + (self.pts_elapsed() as f64) / (self.clock_rate.get() as f64) } /// Returns elapsed decode time since the stream start in clock rate units. #[inline] - pub fn dts(&self) -> i64 { - self.timestamp_dts - i64::from(self.start) + pub fn dts_elapsed(&self) -> i64 { + self.dts - i64::from(self.start) } /// Returns `self + delta` unless it would overflow. pub fn try_add(&self, delta: u32) -> Option { // Check for `timestamp` overflow only. We don't need to check for // `timestamp - start` underflow because delta is non-negative. - self.timestamp + self.pts .checked_add(i64::from(delta)) .map(|timestamp| VideoTimestamp { - timestamp, - timestamp_dts: self.timestamp_dts, + pts: timestamp, + dts: self.dts, clock_rate: self.clock_rate, start: self.start, }) @@ -302,10 +302,10 @@ impl Display for VideoTimestamp { write!( f, "{} (mod-2^32: {}), npt {:.03}, dts {:?}", - self.timestamp, - self.timestamp as u32, - self.pts_secs(), - self.timestamp_dts, + self.pts, + self.pts as u32, + self.pts_elapsed_secs(), + self.dts, ) } }