Skip to main content

JitterBuffer

Struct JitterBuffer 

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

Buffers packets, reorders them, and reports what went missing.

Implementations§

Source§

impl JitterBuffer

Source

pub fn new(depth: usize) -> Self

A buffer holding depth packets.

Depth is in packets rather than milliseconds because the buffer does not know the packetisation interval; at the usual 20 ms, a depth of 3 is 60 ms of added latency.

Source

pub fn adaptive(min: usize, max: usize) -> Self

A buffer that sizes itself, between min and max packets.

It starts at min and stays there until it has evidence it needs more, so a clean network pays exactly what the fixed buffer would. Feed it with Self::push_at: Self::push carries no arrival time, and a buffer with no arrival times cannot measure jitter and will never adapt.

Source

pub fn push_at(&mut self, packet: Packet, arrival: u32) -> bool

Accept a packet, noting when it arrived.

arrival is the local clock in the same units as the RTP timestamp — for G.711, 8000 per second. The same convention as crate::rtcp::StreamStats::on_packet, and for the same reason: mixing units is how a jitter estimate becomes a number that means nothing.

Source

pub fn depth(&self) -> usize

How deep the buffer currently is, in packets.

Source

pub fn jitter(&self) -> f64

Smoothed interarrival jitter, in timestamp units. Zero under a fixed policy.

Source

pub fn push(&mut self, packet: Packet) -> bool

Accept a packet.

Returns whether it was kept. A packet already released is refused: playing it would put audio out of order, which is worse than the gap it was going to fill.

Source

pub fn pop(&mut self) -> Option<Packet>

Take the next packet, if the buffer has filled enough to release one.

Returns None while still filling — that is the latency being paid for, not an error.

Source

pub fn drain(&mut self) -> Vec<Packet>

Release everything held, in order, regardless of depth.

Source

pub fn len(&self) -> usize

How many packets are held.

Source

pub fn is_empty(&self) -> bool

Whether nothing is held.

Source

pub fn received(&self) -> u64

How many packets arrived.

Source

pub fn lost(&self) -> u64

How many never arrived, as counted at release time.

Source

pub fn duplicates(&self) -> u64

How many arrived more than once.

Source

pub fn late(&self) -> u64

How many arrived after their slot had been played.

Trait Implementations§

Source§

impl Debug for JitterBuffer

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.