Skip to main content

StreamInstant

Struct StreamInstant 

Source
pub struct StreamInstant { /* private fields */ }
Expand description

A monotonic time instance associated with a stream, retrieved from either:

  1. A timestamp provided to the stream’s underlying audio data callback or
  2. 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

HostTime source
AAudioAAudioStream_getTimestamp(CLOCK_MONOTONIC)
ALSAsnd_pcm_status_get_htstamp()
ASIOtimeGetTime()
AudioWorkletAudioContext.currentTime
CoreAudiomach_absolute_time()
JACKjack_get_time()
PipeWirepw_stream_get_time_n()
PulseAudiostd::time::Instant
WASAPIQueryPerformanceCounter()
WebAudioAudioContext.currentTime

Disclaimer: These system calls might change over time.

Note: The + and - operators on StreamInstant may panic if the result cannot be represented as a StreamInstant. Use checked_add or checked_sub for non-panicking variants.

Implementations§

Source§

impl StreamInstant

Source

pub const ZERO: Self

A StreamInstant with secs and nanos both set to zero.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn as_nanos(&self) -> u128

Returns the total number of nanoseconds contained by this StreamInstant.

Source

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.

Source

pub fn from_millis(millis: u64) -> Self

Creates a new StreamInstant from the specified number of milliseconds.

Source

pub fn from_micros(micros: u64) -> Self

Creates a new StreamInstant from the specified number of microseconds.

Source

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.

Source

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

Source§

fn add(self, rhs: Duration) -> Self::Output

§Panics

Panics if the result overflows the range of StreamInstant. Use checked_add for a non-panicking variant.

Source§

type Output = StreamInstant

The resulting type after applying the + operator.
Source§

impl AddAssign<Duration> for StreamInstant

Source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
Source§

impl Clone for StreamInstant

Source§

fn clone(&self) -> StreamInstant

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for StreamInstant

Source§

impl Debug for StreamInstant

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for StreamInstant

Source§

impl Hash for StreamInstant

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for StreamInstant

Source§

fn cmp(&self, other: &StreamInstant) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for StreamInstant

Source§

fn eq(&self, other: &StreamInstant) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for StreamInstant

Source§

fn partial_cmp(&self, other: &StreamInstant) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for StreamInstant

Source§

impl Sub for StreamInstant

Source§

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§

type Output = Duration

The resulting type after applying the - operator.
Source§

impl Sub<Duration> for StreamInstant

Source§

fn sub(self, rhs: Duration) -> Self::Output

§Panics

Panics if the result underflows the range of StreamInstant. Use checked_sub for a non-panicking variant.

Source§

type Output = StreamInstant

The resulting type after applying the - operator.
Source§

impl SubAssign<Duration> for StreamInstant

Source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.