Struct retina::Timestamp

source ·
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 via crate::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 than i32::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

source

pub fn new(timestamp: i64, clock_rate: NonZeroU32, start: u32) -> Option<Self>

Creates a new timestamp unless timestamp - start underflows.

source

pub fn timestamp(&self) -> i64

Returns time since some arbitrary point before the stream started.

source

pub fn start(&self) -> u32

Returns timestamp of the start of the stream.

source

pub fn clock_rate(&self) -> NonZeroU32

Returns codec-specified clock rate, in Hz.

source

pub fn elapsed(&self) -> i64

Returns elapsed time since the stream start in clock rate units.

source

pub fn elapsed_secs(&self) -> f64

Returns elapsed time since the stream start in seconds, aka “normal play time” (NPT).

source

pub fn try_add(&self, delta: u32) -> Option<Self>

Returns self + delta unless it would overflow.

Trait Implementations§

source§

impl Clone for Timestamp

source§

fn clone(&self) -> Timestamp

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Timestamp

source§

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

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

impl Display for Timestamp

source§

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

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

impl PartialEq for Timestamp

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Timestamp

source§

impl Eq for Timestamp

source§

impl StructuralEq for Timestamp

source§

impl StructuralPartialEq for Timestamp

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more