pub struct Timestamp { /* private fields */ }
Expand description
An annotated RTP timestamp.
This couples together three pieces of information:
-
The stream’s starting time. In client use, this is often as received in the RTSP
RTP-Info
header but may be controlled viacrate::client::InitialTimestampPolicy
. According to RFC 3550 section 5.1, “the initial value of the timestamp SHOULD be random”. -
The codec-specific clock rate.
-
The timestamp as an
i64
. In client use, its top bits should be inferred from wraparounds of 32-bit RTP timestamps. The Retina client’s policy is that timestamps that differ by more thani32::MAX
from previous timestamps are treated as backwards jumps. It’s allowed for a timestamp to indicate a time before the stream’s starting point.
In combination, these allow conversion to “normal play time” (NPT): seconds since start of the stream.
According to RFC 3550 section 5.1,
RTP timestamps “MUST be derived from a clock that increments monotonically”. In practice,
many RTP servers violate this. The Retina client allows such violations unless
crate::client::PlayOptions::enforce_timestamps_with_max_jump_secs
says otherwise.
Timestamp
can’t represent timestamps which overflow/underflow i64
can’t be constructed or
elapsed times (elapsed = timestamp - start
) which underflow i64
. The client will return
error in these cases. This should rarely cause problems. It’d take ~2^32 packets (~4 billion)
to advance the time this far forward or backward even with a hostile server.
The Display
and Debug
implementations currently display:
- the bottom 32 bits, as seen in RTP packet headers. This advances at a codec-specified clock rate.
- the full timestamp.
- NPT
Implementations§
source§impl Timestamp
impl Timestamp
sourcepub fn new(timestamp: i64, clock_rate: NonZeroU32, start: u32) -> Option<Self>
pub fn new(timestamp: i64, clock_rate: NonZeroU32, start: u32) -> Option<Self>
Creates a new timestamp unless timestamp - start
underflows.
sourcepub fn timestamp(&self) -> i64
pub fn timestamp(&self) -> i64
Returns time since some arbitrary point before the stream started.
sourcepub fn clock_rate(&self) -> NonZeroU32
pub fn clock_rate(&self) -> NonZeroU32
Returns codec-specified clock rate, in Hz.
sourcepub fn elapsed_secs(&self) -> f64
pub fn elapsed_secs(&self) -> f64
Returns elapsed time since the stream start in seconds, aka “normal play time” (NPT).