jittr

Crates.iojittr
lib.rsjittr
version0.2.0
sourcesrc
created_at2022-10-27 10:07:38.708188
updated_at2023-01-09 10:30:32.223216
descriptionA binary heap based jitter buffer implementation for zero latency udp/rtp streams
homepage
repositoryhttps://github.com/Hum-Systems/jittr
max_upload_size
id699040
size20,601
Mara Schulke (mara-schulke)

documentation

https://docs.rs/jittr

README

jittr

A binary heap based jitter buffer implementation for zero latency udp/rtp streams

crates.io version docs.rs docs

This implementation is designed to fight network jitter and create reliable media streams through udp packets. Unordered packets and varying network delay is one of the biggest problems when trying to constantly streaming e.g. audio through udp (and most likely rtp). This datastructure buffers packets and reorders them whilst introducing as little delay as possible.

Examples

Opus

Playback opus packets from an udp/rtp stream through the jitter buffer:

use async_std::stream::interval;
use std::time::Duration;
use jittr::{JitterBuffer, Packet};

let mut rtp_stream = /* your rtp stream */;

/// Your Packet implementation
struct Opus { .. }
impl Packet for Opus { .. }

/// Create a jitter buffer for Opus packets
/// It can hold up to 10 packets before it starts to discard old packets
let mut jitter = JitterBuffer::<Opus, 10>::new();

/// Create an interval for packet playback
/// A typical length for audio packets is between 10 and 20ms
let mut playback = interval(Duration::from_millis(20));

loop {
    futures::select! {
        _ = playback.next().fuse() => {
            let packet = jittr.pop();

            let pcm = /* Opus decodes audio if present or infers if none */

            // Write pcm to speaker
        },
        rtp = rtp_stream.next().fuse() => {
            let opus: Opus = rtp.unwrap();
            jittr.push(opus);
        },
    }
}
Commit count: 52

cargo fmt