Streams: SRTP profile order, bandwidth estimation, simulcast layers
Official TeamSpeak 6 clients use AES_CM_128_HMAC_SHA1_80, while our peers negotiated AES-256-GCM. PeerConfig::srtp_profiles now sets the order (default AES_CM_128_HMAC_SHA1_80, then the GCM profiles for peers without it); a DTLS provider wrapping str0m's dimpl DTLS applies it and records the negotiated profile. It can be changed at runtime (Streams::set_srtp_profiles, Command::SetSrtpProfiles) for new connections. Streamer peers now run str0m's bandwidth estimation and pacer. Each viewer gets the simulcast layer its estimate allows (down at once, up after 2 s above the next layer's minimum plus 20%), switching at a keyframe of the new layer, which is requested. Keyframe requests and bitrate targets (lowest estimate of a layer's viewers) are per layer and reach the encoders lock-free through LayerFeedback (StreamSink::take_layer_keyframes, layer_bitrate). Peers that negotiate RID simulcast (PeerConfig::simulcast, for SFUs/WHIP) get every layer with its RID. Layers can change while live. voelinctl stream start takes --layer, --simulcast, --srtp and --placeholder (layered synthetic frames without an encoder) and prints each viewer's layer, estimate and SRTP profile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
8bb060167b
commit
ede9c3941c
14 files changed
+2472
-172
No files matched your search
@@ -1,9 +1,10 @@
|
||||
//! Two peers on loopback: offer/answer, then video and audio frames flow.
|
||||
//! Two peers on loopback: offer/answer, then video and audio frames flow;
|
||||
//! the SRTP profile DTLS negotiates; bandwidth estimates at the streamer.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use tokio::time::timeout;
|
||||
use voelin_stream::{MediaKind, MediaTime, Peer, PeerConfig, PeerEvent};
|
||||
use voelin_stream::{MediaKind, MediaTime, Peer, PeerConfig, PeerEvent, SrtpProfile};
|
||||
|
||||
/// Bytes that look like a VP8 keyframe (frame tag + start code), then filler.
|
||||
pub fn fake_vp8_keyframe(seq: u8, len: usize) -> Vec<u8> {
|
||||
@@ -79,7 +80,47 @@ async fn media_flows_over_loopback() {
|
||||
}
|
||||
})
|
||||
.await;
|
||||
let streamer = sender.await.unwrap();
|
||||
let mut streamer = sender.await.unwrap();
|
||||
assert!(video >= 40 && audio >= 80, "received {video} video / {audio} audio frames");
|
||||
// The viewer's transport-cc feedback gives the streamer bandwidth estimates.
|
||||
let mut estimates = Vec::new();
|
||||
while let Some(event) = streamer.try_next_event() {
|
||||
if let PeerEvent::BitrateEstimate(bitrate) = event {
|
||||
estimates.push(bitrate);
|
||||
}
|
||||
}
|
||||
assert!(!estimates.is_empty(), "no bandwidth estimate");
|
||||
assert!(estimates.iter().all(|b| *b > 0), "{estimates:?}");
|
||||
drop(streamer);
|
||||
}
|
||||
|
||||
/// Connect a streamer and a viewer; the SRTP profile each ended up with.
|
||||
async fn negotiate(streamer: &PeerConfig, viewer: &PeerConfig) -> [Option<SrtpProfile>; 2] {
|
||||
let (mut s, offer) = Peer::offer(streamer, "srtp").await.unwrap();
|
||||
let (mut v, answer) = Peer::answer(viewer, &offer).await.unwrap();
|
||||
s.accept_answer(&answer).await.unwrap();
|
||||
tokio::join!(wait_connected(&mut s), wait_connected(&mut v));
|
||||
[s.srtp_profile(), v.srtp_profile()]
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn srtp_profile_order() {
|
||||
use SrtpProfile::{AeadAes128Gcm, AeadAes256Gcm, Aes128CmSha1_80};
|
||||
let _ = tracing_subscriber::fmt().with_env_filter("warn").with_test_writer().try_init();
|
||||
let default = PeerConfig::loopback();
|
||||
// By default: SRTP_AES128_CM_SHA1_80, as between official TeamSpeak clients.
|
||||
let profiles = negotiate(&default, &default).await;
|
||||
assert_eq!(profiles, [Some(Aes128CmSha1_80); 2]);
|
||||
assert_eq!(profiles[0].unwrap().name(), "AES_CM_128_HMAC_SHA1_80");
|
||||
// The answering peer is the DTLS server (a=setup:passive); its order wins
|
||||
// over a client that offers GCM first, as browsers do.
|
||||
let gcm_first = PeerConfig {
|
||||
srtp_profiles: vec![AeadAes256Gcm, AeadAes128Gcm, Aes128CmSha1_80],
|
||||
..PeerConfig::loopback()
|
||||
};
|
||||
assert_eq!(negotiate(&gcm_first, &default).await, [Some(Aes128CmSha1_80); 2]);
|
||||
assert_eq!(negotiate(&default, &gcm_first).await, [Some(AeadAes256Gcm); 2]);
|
||||
// A peer without AES_CM_128_HMAC_SHA1_80 still connects with GCM.
|
||||
let gcm_only = PeerConfig { srtp_profiles: vec![AeadAes128Gcm], ..PeerConfig::loopback() };
|
||||
assert_eq!(negotiate(&gcm_only, &default).await, [Some(AeadAes128Gcm); 2]);
|
||||
}
|
||||
Reference in new issue
Block a user