pub struct JitterBuffer { /* private fields */ }Expand description
Buffers packets, reorders them, and reports what went missing.
Implementations§
Source§impl JitterBuffer
impl JitterBuffer
Sourcepub fn new(depth: usize) -> Self
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.
Sourcepub fn adaptive(min: usize, max: usize) -> Self
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.
Sourcepub fn push_at(&mut self, packet: Packet, arrival: u32) -> bool
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.
Sourcepub fn jitter(&self) -> f64
pub fn jitter(&self) -> f64
Smoothed interarrival jitter, in timestamp units. Zero under a fixed policy.
Sourcepub fn push(&mut self, packet: Packet) -> bool
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.
Sourcepub fn pop(&mut self) -> Option<Packet>
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.
Sourcepub fn duplicates(&self) -> u64
pub fn duplicates(&self) -> u64
How many arrived more than once.