feat(dred): continuous DRED tuning, PMTUD, extended Opus6k window
- DredTuner: maps live network metrics (loss/RTT/jitter) to continuous DRED duration every ~500ms instead of discrete tier-locked values. Includes jitter-spike detection for pre-emptive Starlink-style boost. - Opus6k DRED extended from 500ms to 1040ms (max libopus 1.5 supports) - PMTUD: quinn MtuDiscoveryConfig with upper_bound=1452, 300s interval - TrunkedForwarder respects discovered MTU (was hard-coded 1200) - QuinnPathSnapshot exposes quinn internal stats + discovered MTU - AudioEncoder trait: set_expected_loss() + set_dred_duration() methods - PathMonitor: sliding-window jitter variance for spike detection - Integrated into both Android and desktop send tasks in engine.rs - 14 new tests (10 tuner unit + 4 encoder integration) - Updated ARCHITECTURE.md, PROGRESS.md, PRD-dred-integration, PRD-mtu Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -123,7 +123,6 @@ fn transport_config() -> quinn::TransportConfig {
|
||||
config.keep_alive_interval(Some(Duration::from_secs(5)));
|
||||
|
||||
// Enable DATAGRAM extension for unreliable media packets.
|
||||
// Allow datagrams up to 1200 bytes (conservative for lossy links).
|
||||
config.datagram_receive_buffer_size(Some(65536));
|
||||
|
||||
// Conservative flow control for bandwidth-constrained links
|
||||
@@ -134,6 +133,26 @@ fn transport_config() -> quinn::TransportConfig {
|
||||
// Aggressive initial RTT estimate for high-latency links
|
||||
config.initial_rtt(Duration::from_millis(300));
|
||||
|
||||
// PMTUD (Path MTU Discovery) — quinn 0.11 enables this by default but
|
||||
// with conservative bounds (initial 1200, upper 1452). We keep the safe
|
||||
// initial_mtu of 1200 so the first packets always get through, but raise
|
||||
// upper_bound so the binary search can discover larger MTUs on paths that
|
||||
// support them. Typical results:
|
||||
// - Ethernet/fiber: discovers ~1452 (Ethernet MTU minus IP/UDP/QUIC)
|
||||
// - WireGuard/VPN: discovers ~1380-1420
|
||||
// - Starlink: discovers ~1400-1452
|
||||
// - Cellular: stays at 1200-1300
|
||||
// Black hole detection automatically falls back to 1200 if probes fail.
|
||||
// This matters for future video frames which can be 1-50 KB and benefit
|
||||
// from fewer application-layer fragments per frame.
|
||||
let mut mtu_config = quinn::MtuDiscoveryConfig::default();
|
||||
mtu_config
|
||||
.upper_bound(1452)
|
||||
.interval(Duration::from_secs(300)) // re-probe every 5 min
|
||||
.black_hole_cooldown(Duration::from_secs(30)); // retry faster on lossy links
|
||||
config.mtu_discovery_config(Some(mtu_config));
|
||||
config.initial_mtu(1200); // safe starting point
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ pub mod reliable;
|
||||
pub use config::{client_config, server_config, server_config_from_seed, tls_fingerprint};
|
||||
pub use connection::{accept, connect, create_endpoint, create_ipv6_endpoint};
|
||||
pub use path_monitor::PathMonitor;
|
||||
pub use quic::QuinnTransport;
|
||||
pub use quic::{QuinnPathSnapshot, QuinnTransport};
|
||||
pub use wzp_proto::{MediaTransport, PathQuality, TransportError};
|
||||
|
||||
// Re-export the quinn Endpoint type so downstream crates (wzp-desktop) can
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
//!
|
||||
//! Tracks packet loss (via sequence number gaps), RTT, jitter, and bandwidth.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use wzp_proto::PathQuality;
|
||||
|
||||
/// EWMA smoothing factor.
|
||||
const ALPHA: f64 = 0.1;
|
||||
|
||||
/// Maximum number of RTT samples in the jitter variance sliding window.
|
||||
/// At ~50 packets/sec (20 ms frame), 10 samples ≈ 200 ms.
|
||||
const JITTER_VARIANCE_WINDOW_SIZE: usize = 10;
|
||||
|
||||
/// Monitors network path quality metrics.
|
||||
pub struct PathMonitor {
|
||||
/// EWMA-smoothed loss percentage (0.0 - 100.0).
|
||||
@@ -31,6 +37,8 @@ pub struct PathMonitor {
|
||||
last_rtt_ms: Option<f64>,
|
||||
/// Whether we have any observations yet.
|
||||
initialized: bool,
|
||||
/// Sliding window of recent RTT samples for variance calculation.
|
||||
rtt_window: VecDeque<f64>,
|
||||
}
|
||||
|
||||
impl PathMonitor {
|
||||
@@ -51,6 +59,7 @@ impl PathMonitor {
|
||||
total_received: 0,
|
||||
last_rtt_ms: None,
|
||||
initialized: false,
|
||||
rtt_window: VecDeque::with_capacity(JITTER_VARIANCE_WINDOW_SIZE),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +131,12 @@ impl PathMonitor {
|
||||
} else {
|
||||
self.rtt_ewma = ALPHA * rtt + (1.0 - ALPHA) * self.rtt_ewma;
|
||||
}
|
||||
|
||||
// Maintain sliding window for variance calculation
|
||||
if self.rtt_window.len() >= JITTER_VARIANCE_WINDOW_SIZE {
|
||||
self.rtt_window.pop_front();
|
||||
}
|
||||
self.rtt_window.push_back(rtt);
|
||||
}
|
||||
|
||||
/// Get the current estimated path quality.
|
||||
@@ -155,6 +170,20 @@ impl PathMonitor {
|
||||
0
|
||||
}
|
||||
|
||||
/// Compute the jitter (RTT standard deviation) over the sliding window.
|
||||
///
|
||||
/// Returns the standard deviation in milliseconds, or 0.0 if insufficient
|
||||
/// samples. Used by `DredTuner` for spike detection.
|
||||
pub fn jitter_variance_ms(&self) -> f64 {
|
||||
let n = self.rtt_window.len();
|
||||
if n < 2 {
|
||||
return 0.0;
|
||||
}
|
||||
let mean = self.rtt_window.iter().sum::<f64>() / n as f64;
|
||||
let var = self.rtt_window.iter().map(|r| (r - mean).powi(2)).sum::<f64>() / n as f64;
|
||||
var.sqrt()
|
||||
}
|
||||
|
||||
/// Detect whether a network handoff likely occurred.
|
||||
///
|
||||
/// Returns `true` if the most recent RTT jitter measurement exceeds 3x
|
||||
|
||||
@@ -13,6 +13,29 @@ use crate::datagram;
|
||||
use crate::path_monitor::PathMonitor;
|
||||
use crate::reliable;
|
||||
|
||||
/// Snapshot of quinn's QUIC-level path statistics.
|
||||
///
|
||||
/// Provides more accurate loss/RTT data than `PathMonitor`'s sequence-gap
|
||||
/// heuristic because quinn sees ACK frames and congestion signals directly.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct QuinnPathSnapshot {
|
||||
/// Smoothed RTT in milliseconds (from quinn's congestion controller).
|
||||
pub rtt_ms: u32,
|
||||
/// Cumulative loss percentage (lost_packets / sent_packets × 100).
|
||||
pub loss_pct: f32,
|
||||
/// Total congestion events observed by the QUIC stack.
|
||||
pub congestion_events: u64,
|
||||
/// Current congestion window in bytes.
|
||||
pub cwnd: u64,
|
||||
/// Total packets sent on this path.
|
||||
pub sent_packets: u64,
|
||||
/// Total packets lost on this path.
|
||||
pub lost_packets: u64,
|
||||
/// Current PMTUD-discovered maximum datagram payload size (bytes).
|
||||
/// Starts at `initial_mtu` (1200) and grows as PMTUD probes succeed.
|
||||
pub current_mtu: usize,
|
||||
}
|
||||
|
||||
/// QUIC-based transport implementing the `MediaTransport` trait.
|
||||
pub struct QuinnTransport {
|
||||
connection: quinn::Connection,
|
||||
@@ -66,6 +89,31 @@ impl QuinnTransport {
|
||||
datagram::max_datagram_payload(&self.connection)
|
||||
}
|
||||
|
||||
/// Snapshot of QUIC-level path stats from quinn, useful for DRED tuning.
|
||||
///
|
||||
/// Returns `(rtt_ms, loss_pct, congestion_events)` derived from quinn's
|
||||
/// internal congestion controller — more accurate than our own sequence-gap
|
||||
/// heuristic in `PathMonitor` because quinn sees ACK frames directly.
|
||||
pub fn quinn_path_stats(&self) -> QuinnPathSnapshot {
|
||||
let stats = self.connection.stats();
|
||||
let rtt_ms = stats.path.rtt.as_millis() as u32;
|
||||
let loss_pct = if stats.path.sent_packets > 0 {
|
||||
(stats.path.lost_packets as f32 / stats.path.sent_packets as f32) * 100.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let current_mtu = self.connection.max_datagram_size().unwrap_or(1200);
|
||||
QuinnPathSnapshot {
|
||||
rtt_ms,
|
||||
loss_pct,
|
||||
congestion_events: stats.path.congestion_events,
|
||||
cwnd: stats.path.cwnd,
|
||||
sent_packets: stats.path.sent_packets,
|
||||
lost_packets: stats.path.lost_packets,
|
||||
current_mtu,
|
||||
}
|
||||
}
|
||||
|
||||
/// Send an encoded [`TrunkFrame`] as a single QUIC datagram.
|
||||
pub fn send_trunk(&self, frame: &TrunkFrame) -> Result<(), TransportError> {
|
||||
let data = frame.encode();
|
||||
|
||||
Reference in New Issue
Block a user