Browser interop checks the SRTP cipher; docs on SRTP, BWE and simulcast
The interop test now reads the transport's getStats() and requires srtpCipher AES_CM_128_HMAC_SHA1_80 in both directions, and bandwidth estimates from Chromium's transport-cc feedback. The docs describe the SRTP profile order, the bandwidth estimation and the simulcast layers of our stream, and the findings with Chromium 141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
6 files changed
+86
-9
No files matched your search
@@ -82,6 +82,9 @@ cargo run -p voelinctl -- connect 127.0.0.1:9988 --nick ear voice record out.wav
|
||||
# Streams (TeamSpeak 6): share the test pattern (or --source x11), watch and decode it
|
||||
cargo run -p voelinctl -- connect 127.0.0.1:9988 --nick eye stream watch --save-frame shot.png &
|
||||
cargo run -p voelinctl -- connect 127.0.0.1:9988 --nick me stream start --synthetic --auto-accept
|
||||
# Simulcast layers without an encoder; prints each viewer's layer, estimate and SRTP profile
|
||||
cargo run -p voelinctl -- connect 127.0.0.1:9988 --nick me stream start --placeholder --auto-accept \
|
||||
--layer 1.0:6000k --layer 0.5:1500k:min=800k
|
||||
|
||||
# ServerQuery (dev password voelin-dev-admin): invisible presence and relay chat
|
||||
cargo run -p voelinctl -- observe ssh 127.0.0.1:10022 --secret voelin-dev-admin --allowlisted
|
||||
|
||||
@@ -13,7 +13,8 @@ use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, Lines};
|
||||
use tokio::process::{Child, ChildStdin, ChildStdout, Command};
|
||||
use tokio::time::timeout;
|
||||
use voelin_stream::{
|
||||
Codec, FrameSource, MediaKind, Peer, PeerConfig, PeerEvent, Signal, SyntheticSource,
|
||||
Codec, FrameSource, MediaKind, Peer, PeerConfig, PeerEvent, Signal, SrtpProfile,
|
||||
SyntheticSource,
|
||||
};
|
||||
|
||||
fn enabled() -> bool {
|
||||
@@ -95,7 +96,9 @@ async fn wait_connected(peer: &mut Peer) {
|
||||
.expect("no connection with the browser");
|
||||
}
|
||||
|
||||
/// Our streamer peer (as in a TeamSpeak stream) sends VP8 + Opus to Chromium.
|
||||
/// Our streamer peer (as in a TeamSpeak stream) sends VP8 + Opus to Chromium,
|
||||
/// which answers as DTLS client: our SRTP order gives AES_CM_128_HMAC_SHA1_80,
|
||||
/// and its transport-cc feedback drives our bandwidth estimation and pacer.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn rust_streams_to_browser() {
|
||||
if !enabled() {
|
||||
@@ -116,6 +119,7 @@ async fn rust_streams_to_browser() {
|
||||
let mut source = SyntheticSource::new(30, 3000, true);
|
||||
let mut frames = Vec::new();
|
||||
let mut keyframe_requests = 0;
|
||||
let mut estimates = Vec::new();
|
||||
let end = Instant::now() + Duration::from_secs(3);
|
||||
while Instant::now() < end {
|
||||
source.poll_frames(Instant::now(), &mut frames);
|
||||
@@ -123,15 +127,21 @@ async fn rust_streams_to_browser() {
|
||||
peer.write(f.kind, f.time, f.data);
|
||||
}
|
||||
while let Some(event) = peer.try_next_event() {
|
||||
if let PeerEvent::KeyframeRequest = event {
|
||||
keyframe_requests += 1;
|
||||
match event {
|
||||
PeerEvent::KeyframeRequest => keyframe_requests += 1,
|
||||
PeerEvent::BitrateEstimate(bitrate) => estimates.push(bitrate),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
let stats = browser.call(json!({ "op": "stats" })).await;
|
||||
eprintln!("browser stats: {stats:#}\nkeyframe requests from the browser: {keyframe_requests}");
|
||||
eprintln!("bandwidth estimates (bit/s): {estimates:?}");
|
||||
assert_eq!(stats["connectionState"], "connected");
|
||||
assert_eq!(stats["transport"]["srtpCipher"], "AES_CM_128_HMAC_SHA1_80", "{stats:#}");
|
||||
assert_eq!(peer.srtp_profile(), Some(SrtpProfile::Aes128CmSha1_80));
|
||||
assert!(!estimates.is_empty(), "no bandwidth estimate from the browser's feedback");
|
||||
let video = &stats["inbound"]["video"];
|
||||
let audio = &stats["inbound"]["audio"];
|
||||
assert_eq!(video["codec"], "video/VP8");
|
||||
@@ -299,6 +309,8 @@ async fn browser_streams_to_rust() {
|
||||
}
|
||||
}
|
||||
wait_connected(&mut peer).await;
|
||||
// We are the DTLS server here too: our order picks the profile.
|
||||
assert_eq!(peer.srtp_profile(), Some(SrtpProfile::Aes128CmSha1_80), "{name}");
|
||||
let received = receive(&mut peer, Duration::from_secs(8), 60).await;
|
||||
eprintln!(
|
||||
"{name}: video {:?}, audio {:?}, VP8 keyframes {}",
|
||||
@@ -316,5 +328,7 @@ async fn browser_streams_to_rust() {
|
||||
tested.push(name);
|
||||
}
|
||||
assert!(tested.contains(&"VP8") && tested.contains(&"VP9"), "tested {tested:?}");
|
||||
let stats = browser.call(json!({ "op": "stats" })).await;
|
||||
assert_eq!(stats["transport"]["srtpCipher"], "AES_CM_128_HMAC_SHA1_80", "{stats:#}");
|
||||
browser.quit().await;
|
||||
}
|
||||
+35
-2
@@ -92,6 +92,38 @@ offer in `respondjoinstreamrequest`), `ViewerSession` one watched stream
|
||||
(answer through `streamsignaling`), and `StreamDirectory` the streams of our
|
||||
channel. Its tests drive two instances through a fake relay server.
|
||||
|
||||
Transport details of our stream (`voelin-stream`):
|
||||
|
||||
- **SRTP profile**: DTLS negotiates the profile in the order of
|
||||
`PeerConfig::srtp_profiles`, by default AES_CM_128_HMAC_SHA1_80 (what
|
||||
official TS6 streams use), then AEAD_AES_128_GCM and AEAD_AES_256_GCM for
|
||||
peers without it. Our peer is the DTLS server with official clients and
|
||||
browsers, so our order decides. `dtls::VoelinDtlsProvider` wraps str0m's
|
||||
dimpl DTLS with that order; dimpl is vendored in `third_party/dimpl` with a
|
||||
patch for it (`VOELIN-PATCH.md`). The order is a setting
|
||||
(`Streams::set_srtp_profiles`, `Command::SetSrtpProfiles`) and applies to
|
||||
new connections.
|
||||
- **Bandwidth estimation and pacing**: each viewer connection of our stream
|
||||
runs str0m's send-side estimation (transport-cc feedback; REMB if a viewer
|
||||
sends only that) and paces packets to it. Estimates are per viewer
|
||||
(`ViewerInfo::estimate`). The offer is unchanged by it: str0m always offers
|
||||
the transport-cc and abs-send-time extensions.
|
||||
- **Simulcast**: `StreamerOptions::layers` lists the encodings (`LayerSpec`).
|
||||
A viewer gets the highest layer whose `min_bitrate` its estimate reaches:
|
||||
down at once, up after the estimate exceeded the next layer's minimum by 20%
|
||||
for 2 s. A switch asks for a keyframe of the new layer and waits for it
|
||||
before the viewer's frames change layer; the RTP timestamps come from one
|
||||
capture clock, so the viewer's single video track continues. Keyframe
|
||||
requests (PLI/FIR) go to the viewer's layer only. Each layer's bitrate
|
||||
target is the lowest estimate of its viewers, at least 30 kbit/s, at most
|
||||
its `max_bitrate`; the encoders read targets and keyframe requests through
|
||||
`LayerFeedback` (lock-free, via `StreamSink::layer_bitrate` and
|
||||
`take_layer_keyframes`), and events report them. Peers that negotiate RID
|
||||
simulcast (`PeerConfig::simulcast`, off for TeamSpeak; for SFUs or WHIP) get
|
||||
every layer with its RID. The layer list can change while live
|
||||
(`Streams::set_layers`, `Command::SetStreamLayers`). Without layers the
|
||||
stream has one layer 0 at the setup's bitrate and every viewer gets it.
|
||||
|
||||
In `voelin-core` a stream task per voice connection runs `Streams`; the voice task
|
||||
forwards `MessageEvent`s and sends the requests. Encoders push frames through
|
||||
the `StreamSink` of `StreamState::Live`; received frames of watched streams go
|
||||
@@ -107,8 +139,9 @@ and feeds the `StreamSink`, honouring keyframe requests. `Viewer` decodes a
|
||||
watched stream on its own thread (skipping to the next keyframe after losses
|
||||
and asking for one) and hands pictures to the UI, which keeps only the newest
|
||||
(`Latest`). `EncodedSource` wraps a `Streamer` as a `voelin-stream::FrameSource`
|
||||
for `voelinctl stream start`; `SyntheticSource` (fake VP8 bytes) remains for
|
||||
voelin-stream's own tests.
|
||||
for `voelinctl stream start`; `SyntheticSource` (fake VP8 bytes, one frame per
|
||||
layer) remains for voelin-stream's own tests and `voelinctl stream start
|
||||
--placeholder`.
|
||||
|
||||
## Milestones
|
||||
|
||||
|
||||
@@ -208,6 +208,19 @@ libwebrtc, the stack the official client is built on:
|
||||
resolver (or its server-reflexive candidates) on our side.
|
||||
- str0m answers in its own codec order and the offerer sends the answer's
|
||||
first codec, so `Peer::answer` orders the viewer's codecs like the offer.
|
||||
- SRTP profile: libwebrtc answers our `setup:actpass` offer as DTLS client
|
||||
(`setup:active`) and offers AEAD_AES_256_GCM, AEAD_AES_128_GCM and
|
||||
AES_CM_128_HMAC_SHA1_80; the server picks. dimpl, str0m's DTLS, always
|
||||
picked AES-256-GCM, while streams between official clients are reported to
|
||||
use AES_CM_128_HMAC_SHA1_80 (and official clients failed with ours). Our
|
||||
peers now pick in the order of `PeerConfig::srtp_profiles`, by default
|
||||
AES_CM_128_HMAC_SHA1_80 first; Chromium's `getStats()` confirms
|
||||
`srtpCipher: AES_CM_128_HMAC_SHA1_80` (DTLS 1.2,
|
||||
`TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256`). Whether this was what broke the
|
||||
official client is still to be confirmed with it.
|
||||
- With bandwidth estimation on our streamer peer, Chromium's transport-cc
|
||||
feedback gives estimates; the offer is the same as without (str0m always
|
||||
offers transport-cc and abs-send-time).
|
||||
|
||||
## Open questions
|
||||
|
||||
|
||||
+11
-2
@@ -8,8 +8,8 @@ on stdin/stdout. No TeamSpeak server is involved.
|
||||
|
||||
| Test | What it checks |
|
||||
|---|---|
|
||||
| `rust_streams_to_browser` | Our streamer offer (`PeerConfig::loopback()`, VP8 + Opus) answered by an `RTCPeerConnection`; `SyntheticSource` media for 3 s; `inbound-rtp` stats: VP8 packets and bytes, decoded frames (the synthetic frames are real 1x1 VP8 keyframes), Opus packets |
|
||||
| `browser_streams_to_rust` | Chromium offers a canvas `captureStream` and an oscillator with VP8, VP9, H264 and AV1 preferred in turn (codecs the browser cannot send are skipped); our viewer `Peer::answer` must receive frames of that codec and Opus. VP8 also uses trickled browser candidates and checks that a PLI brings a keyframe |
|
||||
| `rust_streams_to_browser` | Our streamer offer (`PeerConfig::loopback()`, VP8 + Opus) answered by an `RTCPeerConnection`; `SyntheticSource` media for 3 s; `inbound-rtp` stats: VP8 packets and bytes, decoded frames (the synthetic frames are real 1x1 VP8 keyframes), Opus packets; the `transport` stats' `srtpCipher` is `AES_CM_128_HMAC_SHA1_80` (our SRTP order, we are the DTLS server); our bandwidth estimation gets estimates from Chromium's transport-cc feedback |
|
||||
| `browser_streams_to_rust` | Chromium offers a canvas `captureStream` and an oscillator with VP8, VP9, H264 and AV1 preferred in turn (codecs the browser cannot send are skipped); our viewer `Peer::answer` must receive frames of that codec and Opus, over `AES_CM_128_HMAC_SHA1_80`. VP8 also uses trickled browser candidates and checks that a PLI brings a keyframe |
|
||||
| `trickled_candidates_reach_browser` | A server-reflexive candidate (from a fake STUN server) as our sessions trickle it (`iceCandidate` signal with the peer's mid) is accepted by `addIceCandidate` |
|
||||
|
||||
## Running
|
||||
@@ -44,3 +44,12 @@ may do the same; see `docs/protocol-notes/ts6-streaming.md`.
|
||||
- str0m mids are random strings (`a=mid:fhs`), not `0`/`1`; trickled
|
||||
candidates must carry the real mid, or browsers reject them.
|
||||
- Playwright's Chromium build sends VP8, VP9 and AV1, not H.264.
|
||||
- Chromium 141 offers AEAD_AES_256_GCM, AEAD_AES_128_GCM and
|
||||
AES_CM_128_HMAC_SHA1_80 as DTLS client; with our default order
|
||||
(`PeerConfig::srtp_profiles`) the connection uses AES_CM_128_HMAC_SHA1_80
|
||||
(`getStats()` transport: `srtpCipher`, DTLS 1.2 `FEFD`,
|
||||
`TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256`). Before, dimpl picked AES-256-GCM.
|
||||
- With str0m's bandwidth estimation and pacer on our streamer peer, Chromium's
|
||||
transport-cc feedback yields estimates within the first second (about
|
||||
640 kbit/s rising towards the desired bitrate with the 720 kbit/s synthetic
|
||||
stream).
|
||||
@@ -11,7 +11,8 @@
|
||||
// accept {sdp} apply the answer to our offer
|
||||
// candidate {candidate, sdpMid, sdpMLineIndex} add a remote candidate
|
||||
// stats connection state, inbound/outbound RTP counters,
|
||||
// frames shown by a <video> element
|
||||
// frames shown by a <video> element, the DTLS/SRTP
|
||||
// parameters of the transport
|
||||
// quit
|
||||
'use strict';
|
||||
|
||||
@@ -134,10 +135,12 @@ window.peer = {
|
||||
const codecs = {};
|
||||
const inbound = {};
|
||||
const outbound = {};
|
||||
let transport = {};
|
||||
report.forEach((s) => {
|
||||
if (s.type === 'codec') codecs[s.id] = s.mimeType;
|
||||
if (s.type === 'inbound-rtp') inbound[s.kind] = s;
|
||||
if (s.type === 'outbound-rtp') outbound[s.kind] = s;
|
||||
if (s.type === 'transport') transport = s;
|
||||
});
|
||||
const pick = (s, keys) => {
|
||||
const o = { codec: codecs[s.codecId] };
|
||||
@@ -145,6 +148,8 @@ window.peer = {
|
||||
return o;
|
||||
};
|
||||
const out = { connectionState: this.pc.connectionState, shownFrames: this.shownFrames, inbound: {}, outbound: {} };
|
||||
out.transport = {};
|
||||
['dtlsState', 'dtlsRole', 'tlsVersion', 'dtlsCipher', 'srtpCipher'].forEach((k) => (out.transport[k] = transport[k]));
|
||||
for (const k in inbound) {
|
||||
out.inbound[k] = pick(inbound[k], ['packetsReceived', 'bytesReceived', 'packetsLost', 'framesReceived', 'framesDecoded', 'keyFramesDecoded', 'pliCount', 'totalSamplesReceived']);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user