Skip to main content

JitterBuffer

Struct JitterBuffer 

Source
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

Source

pub fn new(capacity: usize) -> Self

Create an empty buffer holding at most capacity packets.

Source

pub fn ssrc(&self) -> Option<u32>

The SSRC this buffer is bound to, once a packet has established it.

Source

pub fn len(&self) -> usize

How many packets are currently held.

Source

pub fn is_empty(&self) -> bool

Whether the buffer holds nothing.

Source

pub fn stats(&self) -> JitterBufferStats

Counters describing what this buffer has coped with.

Source

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.

Source

pub fn front_sequence(&self) -> Option<u64>

The extended sequence number of the packet nearest playout, if any.

Source

pub fn peek(&self) -> Option<&TaggedPacket>

Look at the packet nearest playout without removing it.

Source

pub fn state(&self) -> State

Whether the buffer is filling or emitting.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn peek_at_sequence(&self, sequence_number: u16) -> Option<&TaggedPacket>

Borrow the packet with this wire sequence number without removing it.

Source

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.

Source

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.

Source

pub fn find(&self, extended: u64) -> Option<&TaggedPacket>

Borrow the packet at extended without removing it.

Source

pub fn front_timestamp(&self) -> Option<u32>

The RTP timestamp of the packet nearest playout.

Source

pub fn reset(&mut self)

Drop everything, keeping the SSRC binding and stats.

Used when a stream restarts: the ordering anchors are meaningless across a discontinuity, but what the buffer has coped with so far is still worth reporting.

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.

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