Skip to main content

TsbpdScheduler

Struct TsbpdScheduler 

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

SRT receiver-side TSBPD delivery scheduler + Too-Late Packet Drop (draft-sharabayko-srt-01 §4.5/§4.6).

Sans-IO: never reads a wall clock. All timing is driven by caller-supplied now: core::time::Duration in feed_data and tick.

§State variables (per specs/rules/srt-tsbpd.md)

  • TsbpdTimeBase (µs, rule 12) — seeded at construction, reflects the clock difference between receiver-local time and the sender’s timestamp clock.
  • TsbpdDelay (ms, rule 10) — receiver latency buffer, floor 120 ms.
  • Drift (µs, rules 24-27) — current drift correction; not estimated internally, supplied at construction.
  • TLPKTDROP_THRESHOLD (rule 19) — threshold beyond which a packet whose play time has passed is dropped; enabled by default.
  • next_release — the next sequence number to release (cumulative delivery point).

Implementations§

Source§

impl TsbpdScheduler

Source

pub fn new( initial_seq: u32, tsbpd_time_base: u64, tsbpd_delay_ms: u64, drift_us: u64, tlpktdrop_enabled: bool, tlpktdrop_threshold_us: Option<u64>, ) -> Self

Create a new TSBPD scheduler.

§Parameters
  • initial_seq — the first expected sequence number (the peer’s ISN).
  • tsbpd_time_baseTsbpdTimeBase in microseconds, seeded per rule 12 (T_NOW - HSREQ_TIMESTAMP).
  • tsbpd_delay_msTsbpdDelay in milliseconds (rule 10). A value below the minimum 120 ms is silently raised to 120 ms.
  • drift_us — current Drift correction in microseconds (rule 9); supply 0 when no drift estimate is available.
  • tlpktdrop_enabled — whether too-late packet drop is enabled (rule 23).
  • tlpktdrop_threshold_us — custom too-late threshold in microseconds. If None, the recommended default 1.25 × TsbpdDelay is used (rule 19).
Source

pub fn feed_data( &mut self, seq_number: u32, pkt_timestamp: u32, now: Duration, ) -> TickOutcome

Feed a received data packet’s sequence number and timestamp.

Returns TickOutcome with any packets that can be immediately delivered (when the packet fills the next-released sequence gap and its play time is at or before now), plus any packets that are already too late on arrival.

§Parameters
  • seq_number — the data packet’s 31-bit sequence number.
  • pkt_timestamp — the data packet’s 32-bit timestamp (§3.1).
  • now — current receiver time since the fixed epoch (the T_NOW used to decide whether PktTsbpdTime ≤ now).
Source

pub fn tick(&mut self, now: Duration) -> TickOutcome

Advance the virtual clock and release/drop packets whose time has come.

Call this periodically (e.g. every millisecond) to drain the buffer. Packets whose PktTsbpdTime ≤ now are released in sequence order. If too-late drop is enabled, packets whose play time has already passed the threshold are dropped instead.

Source

pub fn next_release(&self) -> u32

The next sequence number expected for release.

Source

pub fn buffered_count(&self) -> usize

Number of packets currently buffered and awaiting their play time.

Source

pub fn has_gap(&self) -> bool

Whether the buffer has a gap (the next expected sequence number is not present).

Trait Implementations§

Source§

impl Debug for TsbpdScheduler

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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.