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
impl TsbpdScheduler
Sourcepub 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
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_base—TsbpdTimeBasein microseconds, seeded per rule 12 (T_NOW - HSREQ_TIMESTAMP).tsbpd_delay_ms—TsbpdDelayin milliseconds (rule 10). A value below the minimum 120 ms is silently raised to 120 ms.drift_us— currentDriftcorrection in microseconds (rule 9); supply0when 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. IfNone, the recommended default1.25 × TsbpdDelayis used (rule 19).
Sourcepub fn feed_data(
&mut self,
seq_number: u32,
pkt_timestamp: u32,
now: Duration,
) -> TickOutcome
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 (theT_NOWused to decide whetherPktTsbpdTime ≤ now).
Sourcepub fn tick(&mut self, now: Duration) -> TickOutcome
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.
Sourcepub fn next_release(&self) -> u32
pub fn next_release(&self) -> u32
The next sequence number expected for release.
Sourcepub fn buffered_count(&self) -> usize
pub fn buffered_count(&self) -> usize
Number of packets currently buffered and awaiting their play time.