pub struct JitterBuffer { /* private fields */ }Expand description
A single stream’s packets, ordered by extended sequence number.
One buffer per SSRC. The buffer records the SSRC of the first packet it accepts and
rejects any other, so two streams cannot interleave into one sequence-number ordering. That is
a deliberate correction: pion’s ReceiverInterceptor holds a single buffer for every remote
stream and its BindRemoteStream ignores info.SSRC, so two streams’ sequence numbers sort
against each other.
Ordering is by extended sequence number — the 16-bit value plus its wrap count — so a packet that arrives after a wrap still sorts into its true position; and because the map is keyed by that value, duplicates collapse rather than being inserted twice as they are upstream.
Implementations§
Source§impl JitterBuffer
impl JitterBuffer
Sourcepub fn ssrc(&self) -> Option<u32>
pub fn ssrc(&self) -> Option<u32>
The SSRC this buffer is bound to, once a packet has established it.
Sourcepub fn stats(&self) -> JitterBufferStats
pub fn stats(&self) -> JitterBufferStats
Counters describing what this buffer has coped with.
Sourcepub fn push(&mut self, packet: TaggedPacket) -> Result<u64, Rejected>
pub fn push(&mut self, packet: TaggedPacket) -> Result<u64, Rejected>
Store a packet, returning its extended sequence number, or why it was not stored.
A non-RTP packet is rejected as foreign: this buffer orders by sequence number, and RTCP has none.
Sourcepub fn front_sequence(&self) -> Option<u64>
pub fn front_sequence(&self) -> Option<u64>
The extended sequence number of the packet nearest playout, if any.
Sourcepub fn peek(&self) -> Option<&TaggedPacket>
pub fn peek(&self) -> Option<&TaggedPacket>
Look at the packet nearest playout without removing it.
Sourcepub fn begin_emitting(&mut self)
pub fn begin_emitting(&mut self)
Start handing packets out.
Called by the playout policy when its start condition is met — a buffered depth here, where upstream uses a packet count.
Sourcepub fn begin_buffering(&mut self)
pub fn begin_buffering(&mut self)
Stop handing packets out and fill again.
A stream that has run dry, or restarted across a discontinuity, has to re-accumulate before playout is smooth again.
Sourcepub fn pop(&mut self) -> Option<TaggedPacket>
pub fn pop(&mut self) -> Option<TaggedPacket>
Remove and return the packet nearest playout.
Yields nothing while State::Buffering — upstream returns ErrPopWhileBuffering here,
a sentinel its synchronous reader needs; in sans-I/O “nothing yet” is just None.
Releasing a packet also marks its position played out, so a later-arriving copy or an even older straggler is rejected rather than emitted behind it.
Gaps are skipped, not waited for. Upstream pops strictly at its playout head and counts an underflow when that exact sequence number is missing, which stalls a stream on any un-recovered loss. Whether a gap is worth waiting for is a question about deadlines, so it belongs to the playout policy above this: it decides when a packet is due, and this hands over whatever is due now.
Sourcepub fn pop_at_sequence(&mut self, sequence_number: u16) -> Option<TaggedPacket>
pub fn pop_at_sequence(&mut self, sequence_number: u16) -> Option<TaggedPacket>
Remove and return the packet with this wire sequence number, if it is held.
Takes the 16-bit number off the wire, as a caller naturally holds; the extension to the internal ordering key happens here.
Sourcepub fn peek_at_sequence(&self, sequence_number: u16) -> Option<&TaggedPacket>
pub fn peek_at_sequence(&self, sequence_number: u16) -> Option<&TaggedPacket>
Borrow the packet with this wire sequence number without removing it.
Sourcepub fn pop_at_timestamp(&mut self, timestamp: u32) -> Option<TaggedPacket>
pub fn pop_at_timestamp(&mut self, timestamp: u32) -> Option<TaggedPacket>
Remove and return the first held packet carrying this RTP timestamp.
One packet, not a whole frame: a video frame spans several packets sharing a timestamp, so
releasing the frame means calling this until it yields None. That matches upstream’s
PopAtTimestamp, and keeps the “how much of a frame is releasable” decision in the
playout policy where the deadline lives.
Sourcepub fn pop_at(&mut self, extended: u64) -> Option<TaggedPacket>
pub fn pop_at(&mut self, extended: u64) -> Option<TaggedPacket>
Remove and return the packet at extended, if it is held.
The extended key is the buffer’s own ordering space; pop_at_sequence
is the one to reach for from outside.
Sourcepub fn find(&self, extended: u64) -> Option<&TaggedPacket>
pub fn find(&self, extended: u64) -> Option<&TaggedPacket>
Borrow the packet at extended without removing it.
Sourcepub fn front_timestamp(&self) -> Option<u32>
pub fn front_timestamp(&self) -> Option<u32>
The RTP timestamp of the packet nearest playout.
Trait Implementations§
Source§impl Debug for JitterBuffer
Summarises the buffer rather than dumping its contents: TaggedPacket is not Debug, and a
list of buffered packets is not what anyone wants from a debug print anyway.
impl Debug for JitterBuffer
Summarises the buffer rather than dumping its contents: TaggedPacket is not Debug, and a
list of buffered packets is not what anyone wants from a debug print anyway.