A high-performance, full-stack real-time communication library — WebRTC, RTP/SRTP, T.38 Fax, and UPnP NAT traversal — all through a unified PeerConnection API.
- High performance — ~2.7× faster than
webrtc-rsand ~2.4× faster thanpion(Go) in throughput, with ~30% less memory thanwebrtc-rs(see the benchmark below). - Full protocol stack — WebRTC, RTP, SRTP, and T.38 fax in a single library, plus UPnP IGD NAT traversal. Few moving parts, no missing pieces.
- Unified
PeerConnectionAPI — one interface for every transport mode (WebRtcICE/DTLS/SRTP,Srtp,Rtp, and T.38). No fragmented APIs. - WebRTC compliant — interoperable with Chrome/WebRTC and pion; offer/answer, renegotiation, and standard SDP attributes.
- Complete media pipeline — packetizer/depacketizer, jitter buffer, NACK/FIR/PLI, TWCC, and REMB for audio and video.
- Full ICE — STUN, TURN (UDP + TCP), ICE Lite, ICE TCP (RFC 6544), and single-port UDP mux for SFU/WHEP deployments.
- NAT traversal & deployment — RTP latching, UPnP IGD port mapping, and firewall-friendly port ranges (
rtp_start_port/rtp_end_port). - Production extras — RTP rewrite bridge (SSRC/PT/sequence remapping) and a WebRTC-compatible stats model.
CPU: AMD Ryzen 7 5700X 8-Core Processor
OS 5.15.0-118-generic #128-Ubuntu
Compiler rustc 1.97.1 (8bab26f4f 2026-07-14), go version go1.23.0 linux/amd64
nice@miuda.ai rustrtc % cargo run -r --example benchmark
Comparison (Baseline: webrtc)
Metric | webrtc | rustrtc | pion
--------------------------------------------------------------------------------
Duration (s) | 10.05 | 10.05 | 10.08
Setup Latency (ms) | 0.92 | 0.20 | 0.90
Throughput (MB/s) | 285.64 | 758.67 | 310.14
Msg Rate (msg/s) | 292495.02 | 776880.40 | 317586.71
CPU Usage (%) | 1348.20 | 1341.00 | 1154.67
Memory (MB) | 33.00 | 23.00 | 44.00
--------------------------------------------------------------------------------
Performance Charts
==================
Throughput (MB/s) (Higher is better)
webrtc | ███████████████ 285.64
rustrtc | ████████████████████████████████████████ 758.67
pion | ████████████████ 310.14
Message Rate (msg/s) (Higher is better)
webrtc | ███████████████ 292495.02
rustrtc | ████████████████████████████████████████ 776880.40
pion | ████████████████ 317586.71
Setup Latency (ms) (Lower is better)
webrtc | ████████████████████████████████████████ 0.92
rustrtc | █████████ 0.20
pion | ███████████████████████████████████████ 0.90
CPU Usage (%) (Lower is better)
webrtc | ████████████████████████████████████████ 1348.20
rustrtc | ███████████████████████████████████████ 1341.00
pion | ██████████████████████████████████ 1154.67
Memory (MB) (Lower is better)
webrtc | ██████████████████████████████ 33.00
rustrtc | █████████████████████ 23.00
pion | ████████████████████████████████████████ 44.00Key Findings:
- Throughput:
rustrtcis ~2.7x faster thanwebrtc-rsand ~2.4x faster thanpion. - Memory:
rustrtcuses ~30% less memory thanwebrtc-rsand ~48% less thanpion. - Setup Latency: Significantly faster connection setup (0.20ms vs 0.92ms/0.90ms).
Here is a simple example of how to create a PeerConnection and handle an offer:
use rustrtc::{PeerConnection, RtcConfiguration, SessionDescription, SdpType};
#[tokio::main]
async fn main() {
let config = RtcConfiguration::default();
let pc = PeerConnection::new(config);
// Create a Data Channel
let dc = pc.create_data_channel("data", None).unwrap();
// Handle received messages
let dc_clone = dc.clone();
tokio::spawn(async move {
while let Some(event) = dc_clone.recv().await {
if let rustrtc::DataChannelEvent::Message(data) = event {
println!("Received: {:?}", String::from_utf8_lossy(&data));
}
}
});
// Create an offer
let offer = pc.create_offer().unwrap();
pc.set_local_description(offer).unwrap();
// Wait for ICE gathering to complete
pc.wait_for_gathering_complete().await;
// Get the complete SDP with candidates
let complete_offer = pc.local_description().unwrap();
println!("Offer SDP: {}", complete_offer.to_sdp_string());
}All configuration goes through RtcConfiguration (or its builder RtcConfigurationBuilder):
transport_mode—TransportMode::WebRtc(default),TransportMode::Srtp, orTransportMode::Rtp.ice_servers— STUN/TURN server list.ice_transport_policy—AllorRelay.rtp_start_port/rtp_end_port— Restrict RTP/ICE to a port range.external_ip— Override the external IP for ICE candidates (NAT scenarios).bind_ip— Bind to a specific local IP.disable_ipv6— Disable IPv6 candidate gathering.enable_ice_lite— Enable ICE Lite mode.ice_tcp_policy—IceTcpPolicy::Disabled(default),IceTcpPolicy::Enabled, orIceTcpPolicy::PassiveOnly. Controls ICE TCP candidate support per RFC 6544.ice_udp_mux/ice_udp_mux_port— Share a single UDP socket across manyPeerConnections (single-port multiplexing for SFU/WHEP). Setice_udp_mux = trueandice_udp_mux_port = <port>; incoming packets are demuxed by the server ufrag in the STUN Binding Request, then by remote source address.
enable_upnp— Auto-map ports via UPnP IGD.upnp_lease_duration— UPnP port mapping lease duration in seconds (default: 3600).
enable_latching— Enable dynamic remote address detection for RTP-only mode.probation_max_packets— Number of packets to observe before committing a latched address.
media_capabilities— Configure audio/video/image (T.38) codecs and SCTP port viaMediaCapabilities.ssrc_start— Starting SSRC value for local tracks.
sctp_rto_initial,sctp_rto_min,sctp_rto_max,sctp_max_association_retransmits,sctp_receive_window,sctp_heartbeat_interval,sctp_max_heartbeat_failures,sctp_max_burst,sctp_max_cwnd
rtp_buffer_capacity— Per-SSRC receive buffer capacity.buffer_drop_strategy—DropNeworDropOldestwhen buffer is full.
use rustrtc::{
PeerConnection, RtcConfiguration, RtcConfigurationBuilder,
IceServer, TransportMode, config::T38Capability,
};
// Using builder
let config = RtcConfigurationBuilder::new()
.transport_mode(TransportMode::Rtp)
.enable_latching(true)
.probation_max_packets(Some(5))
.rtp_port_range(50000, 50100)
.enable_upnp(true)
.ice_tcp_policy(config::IceTcpPolicy::Enabled)
.ice_server(IceServer::new(vec!["stun:stun.l.google.com:19302"]))
.build();
let pc = PeerConnection::new(config);// Direct field access
let mut config = RtcConfiguration::default();
config.transport_mode = TransportMode::WebRtc;
config.enable_latching = true;
config.rtp_start_port = Some(50000);
config.rtp_end_port = Some(50100);
config.enable_upnp = true;You can run the examples provided in the repository.
A multi-user video conferencing server. It receives media from each participant and forwards it to others.
-
Run the server:
cargo run --example rustrtc_sfu
-
Open your browser and navigate to
http://127.0.0.1:8081. Open multiple tabs/windows to simulate multiple users.
The echo server example demonstrates how to accept a WebRTC connection, receive data on a data channel, and echo it back. It also supports video playback if an IVF file is provided.
-
Run the server:
cargo run --example echo_server
-
Open your browser and navigate to
http://127.0.0.1:3000.
A multi-user chat room using WebRTC DataChannels.
-
Run the server:
cargo run --example datachannel_chat
-
Open your browser and navigate to
http://127.0.0.1:3000. Open multiple tabs to chat between them.
Records audio from the browser's microphone and saves it to a file (output.ulaw) on the server.
-
Run the server:
cargo run --example audio_saver
-
Open your browser and navigate to
http://127.0.0.1:3000. Click "Start" to begin recording.
Streams a video file (examples/static/output.ivf) via RTP to a UDP port, which can be played back using ffplay.
-
Run the server:
cargo run --example rtp_play
-
In a separate terminal, run
ffplay(requires ffmpeg installed):ffplay -protocol_whitelist file,udp,rtp -i examples/rtp_play.sdp
This project is licensed under the MIT License.
