pub struct StreamInstant { /* private fields */ }Expand description
A monotonic time instance associated with a stream, retrieved from either:
- A timestamp provided to the stream’s underlying audio data callback or
- The same time source used to generate timestamps for a stream’s underlying audio data callback.
StreamInstant represents a moment on a stream’s monotonic clock. Because the underlying clock
is monotonic, StreamInstant values are always positive and increasing.
Within a single stream, all instants share the same clock, so arithmetic between them is meaningful. Across different streams, origins are not guaranteed to be shared. On some hosts each stream starts its own independent clock at zero, so subtracting a timestamp from one stream and one from another may produce a meaningless result.
§Time sources by host
| Host | Time source |
|---|---|
| AAudio | AAudioStream_getTimestamp(CLOCK_MONOTONIC) |
| ALSA | snd_pcm_status_get_htstamp() |
| ASIO | timeGetTime() |
| AudioWorklet | AudioContext.currentTime |
| CoreAudio | mach_absolute_time() |
| JACK | jack_get_time() |
| PipeWire | pw_stream_get_time_n() |
| PulseAudio | std::time::Instant |
| WASAPI | QueryPerformanceCounter() |
| WebAudio | AudioContext.currentTime |
Disclaimer: These system calls might change over time.
Note: The
+and-operators onStreamInstantmay panic if the result cannot be represented as aStreamInstant. Usechecked_addorchecked_subfor non-panicking variants.
Implementations§
Source§impl StreamInstant
impl StreamInstant
Sourcepub fn checked_duration_since(&self, earlier: StreamInstant) -> Option<Duration>
pub fn checked_duration_since(&self, earlier: StreamInstant) -> Option<Duration>
Returns the amount of time elapsed from earlier to self, or None if earlier is
later than self.
Sourcepub fn saturating_duration_since(&self, earlier: StreamInstant) -> Duration
pub fn saturating_duration_since(&self, earlier: StreamInstant) -> Duration
Returns the amount of time elapsed from earlier to self, saturating to
Duration::ZERO if earlier is later than self.
Sourcepub fn duration_since(&self, earlier: StreamInstant) -> Duration
pub fn duration_since(&self, earlier: StreamInstant) -> Duration
Returns the amount of time elapsed from earlier to self, saturating to
Duration::ZERO if earlier is later than self.
Sourcepub fn checked_add(&self, duration: Duration) -> Option<Self>
pub fn checked_add(&self, duration: Duration) -> Option<Self>
Returns Some(t) where t is self + duration, or None if the result cannot be
represented as a StreamInstant.
Sourcepub fn checked_sub(&self, duration: Duration) -> Option<Self>
pub fn checked_sub(&self, duration: Duration) -> Option<Self>
Returns Some(t) where t is self - duration, or None if the result cannot be
represented as a StreamInstant (i.e. would be negative).
Sourcepub fn as_nanos(&self) -> u128
pub fn as_nanos(&self) -> u128
Returns the total number of nanoseconds contained by this StreamInstant.
Sourcepub fn from_nanos(nanos: u64) -> Self
pub fn from_nanos(nanos: u64) -> Self
Creates a new StreamInstant from the specified number of nanoseconds.
Note: Using this on the return value of as_nanos() might cause unexpected behavior:
as_nanos() returns a u128, and can return values that do not fit in u64, e.g. 585
years. Instead, consider using the pattern
StreamInstant::new(t.as_secs(), t.subsec_nanos()) if you cannot copy/clone the
StreamInstant directly.
Sourcepub fn from_millis(millis: u64) -> Self
pub fn from_millis(millis: u64) -> Self
Creates a new StreamInstant from the specified number of milliseconds.
Sourcepub fn from_micros(micros: u64) -> Self
pub fn from_micros(micros: u64) -> Self
Creates a new StreamInstant from the specified number of microseconds.
Sourcepub fn from_secs_f64(secs: f64) -> Self
pub fn from_secs_f64(secs: f64) -> Self
Creates a new StreamInstant from the specified number of seconds represented as f64.
§Panics
Panics if secs is negative, not finite, or overflows the range of StreamInstant.
Sourcepub fn new(secs: u64, nanos: u32) -> Self
pub fn new(secs: u64, nanos: u32) -> Self
Creates a new StreamInstant from the specified number of whole seconds and additional
nanoseconds.
If nanos is greater than or equal to 1 billion (the number of nanoseconds in a second),
the excess carries over into secs.
§Panics
Panics if the carry from nanos overflows the seconds counter.
Trait Implementations§
Source§impl Add<Duration> for StreamInstant
impl Add<Duration> for StreamInstant
Source§impl AddAssign<Duration> for StreamInstant
impl AddAssign<Duration> for StreamInstant
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+= operation. Read moreSource§impl Clone for StreamInstant
impl Clone for StreamInstant
Source§fn clone(&self) -> StreamInstant
fn clone(&self) -> StreamInstant
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for StreamInstant
Source§impl Debug for StreamInstant
impl Debug for StreamInstant
impl Eq for StreamInstant
Source§impl Hash for StreamInstant
impl Hash for StreamInstant
Source§impl Ord for StreamInstant
impl Ord for StreamInstant
Source§fn cmp(&self, other: &StreamInstant) -> Ordering
fn cmp(&self, other: &StreamInstant) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for StreamInstant
impl PartialEq for StreamInstant
Source§fn eq(&self, other: &StreamInstant) -> bool
fn eq(&self, other: &StreamInstant) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for StreamInstant
impl PartialOrd for StreamInstant
impl StructuralPartialEq for StreamInstant
Source§impl Sub for StreamInstant
impl Sub for StreamInstant
Source§fn sub(self, rhs: StreamInstant) -> Self::Output
fn sub(self, rhs: StreamInstant) -> Self::Output
Returns the duration from rhs to self, saturating to Duration::ZERO if rhs is
later than self.
Source§impl Sub<Duration> for StreamInstant
impl Sub<Duration> for StreamInstant
Source§impl SubAssign<Duration> for StreamInstant
impl SubAssign<Duration> for StreamInstant
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-= operation. Read more