pub struct SystemInstant { /* private fields */ }Expand description
A monotonic Instant paired with the wall-clock time it was taken at.
Sans-I/O protocol code measures time with a monotonic Instant, but RTCP timestamps
and NTP fields need wall-clock time. Capturing both once lets either be derived from the
other later without re-reading the (non-monotonic) system clock.
Implementations§
Source§impl SystemInstant
impl SystemInstant
Sourcepub fn now(now: Instant) -> Self
pub fn now(now: Instant) -> Self
Captures the current monotonic instant together with the current wall-clock time.
The process’s one wall-clock anchor, taken at the first call (with now as its
monotonic half) and the same for every later caller.
RTCP fields that compare NTP times written by different parts of an endpoint use it:
RFC 8888 section 3.1 derives the report timestamp “from the same clock used to generate
the NTP timestamp field in RTCP SR packets”, and RFC 3550 section 6.4.1 has every
sender report of a participant on one wallclock. Each taking its own
now at a different moment would pair a different wall-clock reading with
each anchor instant: under a clock the caller drives (virtual time) the two differ by
however far that clock ran ahead of the machine’s.
Sourcepub fn at(instant: Instant, duration_since_unix_epoch: Duration) -> Self
pub fn at(instant: Instant, duration_since_unix_epoch: Duration) -> Self
Pairs a monotonic instant with the wall-clock time the caller says it corresponds to.
Reads no clock: for a time derived from another SystemInstant (an earlier or later
instant on the same anchor) or carried by a protocol field (an RTCP sender report’s NTP
timestamp).
Sourcepub fn from_epoch(duration_since_unix_epoch: Duration) -> Self
pub fn from_epoch(duration_since_unix_epoch: Duration) -> Self
Only used for deserialization
Sourcepub fn instant(&self, duration_since_unix_epoch: Duration) -> Instant
pub fn instant(&self, duration_since_unix_epoch: Duration) -> Instant
Converts a Unix-epoch duration back into the monotonic Instant it corresponds to.
Sourcepub fn duration_since_unix_epoch(&self) -> Duration
pub fn duration_since_unix_epoch(&self) -> Duration
The wall-clock time, as a duration since the Unix epoch, captured at construction.
Sourcepub fn unix(&self, now: Instant) -> Duration
pub fn unix(&self, now: Instant) -> Duration
Converts the monotonic now into wall-clock time as a duration since the Unix epoch.
An instant before the anchor’s maps to as much before its wall-clock time (saturating
at the Unix epoch).
Sourcepub fn ntp(&self, now: Instant) -> u64
pub fn ntp(&self, now: Instant) -> u64
Converts the monotonic now into a 64-bit NTP timestamp, as RTCP Sender Reports carry.
Sourcepub fn unix2ntp(duration_since_unix_epoch: Duration) -> u64
pub fn unix2ntp(duration_since_unix_epoch: Duration) -> u64
Converts a Unix-epoch duration into a 64-bit NTP timestamp.
The result is seconds since the NTP epoch (1900-01-01) in the high 32 bits and a binary fraction of a second in the low 32.
Sourcepub fn ntp2unix(ntp: u64) -> Duration
pub fn ntp2unix(ntp: u64) -> Duration
Converts a 64-bit NTP timestamp into a duration since the Unix epoch.
The inverse of Self::unix2ntp.