Skip to content

Commit

Permalink
rename again
Browse files Browse the repository at this point in the history
  • Loading branch information
Curid committed Nov 17, 2023
1 parent f76fc5d commit 7126ba0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions src/codec/h264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down
42 changes: 21 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -233,22 +233,22 @@ impl VideoTimestamp {
#[inline]
pub fn new(pts: i64, dts: i64, clock_rate: NonZeroU32, start: u32) -> Option<Self> {
pts.checked_sub(i64::from(start)).map(|_| VideoTimestamp {
timestamp: pts,
timestamp_dts: dts,
pts,
dts,
clock_rate,
start,
})
}

/// 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.
Expand All @@ -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<Self> {
// 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,
})
Expand All @@ -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,
)
}
}
Expand Down

0 comments on commit 7126ba0

Please sign in to comment.