Offer the codecs every TeamSpeak client decodes before H.264
The official client could not show a Voelin stream: its decoder was libwebrtc's NullVideoDecoder. Its log says why. On a machine with a hardware H.264 encoder our offer put H.264 first, with every H.264 variant str0m knows; the client answered H.264 42e01f, then had no decoder for it, because it decodes H.264 only with an OpenH264 library it downloads at start-up, and that download failed (HTTP 403). Its SDP capabilities list H.264 either way. VP8, VP9 and AV1 it always decodes: FFmpeg's decoders, dav1d and libaom are built into it. - The hardware encoder order, the automatic stream codec (`preferred_codec`) and the offer (`offer_codecs`) now put the codecs every client decodes (`decoded_everywhere`: AV1, VP9, VP8) before H.264, HEVC last. A viewer answers with the first codec of the offer it lists, so official clients take one they can decode; H.264 stays offered for peers that want it, and `stream.codec` can still choose it (its description now says what that means for official clients). - A streamer offers H.264 only as it encodes it (Constrained High, packetization mode 1), not str0m's other variants, which let a viewer answer a profile, or packetization mode 0, we never send. Viewers still accept every variant. Tests: `crates/voelin-core/tests/browser_codecs.rs` (VOELIN_INTEROP=1) streams the test pattern through every encoder this machine has, VA-API also from DMA-BUFs, to headless Chromium's libwebrtc: VA-API H.264 and AV1, libvpx VP8 and VP9, x264, SVT-AV1 and libaom all decode at 1280x720. A second test makes the offer a share makes here ([AV1, VP8, H264, H265]) and checks the browser picks and decodes a codec every client decodes. The browser driver now takes playwright-core with a system Chromium (VOELIN_CHROMIUM), which decodes H.264, and the interop tests accept Chromium 152's name for the SRTP cipher. The official client itself could not be run here (its beta needs a myTeamSpeak sign-in on first start). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a9a12bb4db
commit
630ff848b2
13 files changed
+431
-116
No files matched your search
+26
-4
@@ -1,15 +1,19 @@
|
||||
# Browser interop test
|
||||
|
||||
`crates/voelin-stream/tests/browser_interop.rs` checks our str0m peers against
|
||||
the WebRTC stack of Chromium (libwebrtc, the same stack as the official
|
||||
`crates/voelin-stream/tests/browser_interop.rs` checks our str0m peers, and
|
||||
`crates/voelin-core/tests/browser_codecs.rs` our real encoders, against the
|
||||
WebRTC stack of Chromium (libwebrtc, the same stack as the official
|
||||
TeamSpeak 6 client). `browser-peer.cjs` runs headless Chromium through
|
||||
Playwright and exchanges SDP and candidates with the Rust test as JSON lines
|
||||
on stdin/stdout. No TeamSpeak server is involved.
|
||||
Playwright and exchanges SDP and candidates with the Rust tests as JSON lines
|
||||
on stdin/stdout (`browser.rs` is the Rust side, shared by both tests). 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; 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 |
|
||||
| `real_encoders_decode_in_browser` (voelin-core) | Every encoder this machine has (`Codecs::encoders()`), as a share uses it: the 1280x720 test pattern through the `Streamer`, VA-API encoders also from DMA-BUFs as the ScreenCast portal hands over the screen; our streamer peer offers that codec alone (H.264 as Constrained Baseline, see below); the browser must decode at least 60 frames at 1280x720 in 3 s. Codecs the browser does not answer (HEVC, H.264 in Playwright's Chromium) are skipped |
|
||||
| `share_offer_picks_a_codec_every_client_decodes` (voelin-core) | The offer a share makes on this machine (`preferred_codec`, `peer_config`): the browser, answering with the first codec of the offer it lists as the official client does, must pick one every TeamSpeak client decodes (`decoded_everywhere`), and decode it |
|
||||
| `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
|
||||
@@ -20,8 +24,16 @@ elsewhere).
|
||||
|
||||
```sh
|
||||
VOELIN_INTEROP=1 cargo test -p voelin-stream --test browser_interop -- --nocapture
|
||||
VOELIN_INTEROP=1 cargo test -p voelin-core --features media-desktop --test browser_codecs -- --nocapture
|
||||
```
|
||||
|
||||
Without Playwright's own browsers, `playwright-core` drives an installed
|
||||
Chromium: `npm install playwright-core` somewhere, then
|
||||
`NODE_PATH=<that>/node_modules VOELIN_CHROMIUM=/usr/bin/chromium`. A system
|
||||
Chromium usually decodes H.264, which Playwright's build does not. Run it
|
||||
headless and away from the desktop session, e.g. with `WAYLAND_DISPLAY` and
|
||||
`DISPLAY` unset under `dbus-run-session`.
|
||||
|
||||
Without `VOELIN_INTEROP=1` the tests return immediately, so `cargo test` passes on
|
||||
machines without a browser. `VOELIN_NODE` selects the node binary; `NODE_PATH`
|
||||
defaults to `npm root -g` so a global Playwright is found.
|
||||
@@ -49,6 +61,16 @@ may do the same; see `docs/protocol-notes/ts6-streaming.md`.
|
||||
(`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.
|
||||
Chromium 152 names the same cipher `SRTP_AES128_CM_HMAC_SHA1_80`.
|
||||
- Chromium 152 (Arch Linux build) decodes every encoder's stream on this
|
||||
machine (AMD, VA-API): H.264 and AV1 from VA-API (from memory and from
|
||||
DMA-BUFs), VP8 and VP9 from libvpx, x264, SVT-AV1 and libaom, all at
|
||||
1280x720, about 100 frames in 3.4 s, no freezes.
|
||||
- Headless Chromium 152 lists H.264 only in the profiles of libwebrtc's
|
||||
software decoder (Baseline, Constrained Baseline, Main, packetization modes
|
||||
0 and 1): it does not answer an offer of Constrained High alone
|
||||
(`640c1f`, what our streamers offer), yet decodes High profile streams
|
||||
when it negotiated another profile (its decoder is FFmpeg's).
|
||||
- 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
|
||||
|
||||
@@ -10,14 +10,22 @@
|
||||
// candidates candidates gathered so far -> {candidates: [{candidate, sdpMid, sdpMLineIndex}]}
|
||||
// accept {sdp} apply the answer to our offer
|
||||
// candidate {candidate, sdpMid, sdpMLineIndex} add a remote candidate
|
||||
// stats connection state, inbound/outbound RTP counters,
|
||||
// stats connection state, inbound/outbound RTP counters
|
||||
// (incl. the decoder and decoded frame size),
|
||||
// frames shown by a <video> element, the DTLS/SRTP
|
||||
// parameters of the transport
|
||||
// quit
|
||||
'use strict';
|
||||
|
||||
const readline = require('node:readline');
|
||||
const { chromium } = require('playwright');
|
||||
// Playwright, or playwright-core driving a browser it did not download
|
||||
// (`VOELIN_CHROMIUM`, e.g. a system Chromium that decodes H.264).
|
||||
let chromium;
|
||||
try {
|
||||
({ chromium } = require('playwright'));
|
||||
} catch {
|
||||
({ chromium } = require('playwright-core'));
|
||||
}
|
||||
|
||||
// Runs in the page.
|
||||
const PAGE_SCRIPT = `
|
||||
@@ -151,7 +159,7 @@ window.peer = {
|
||||
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']);
|
||||
out.inbound[k] = pick(inbound[k], ['packetsReceived', 'bytesReceived', 'packetsLost', 'framesReceived', 'framesDecoded', 'keyFramesDecoded', 'framesDropped', 'frameWidth', 'frameHeight', 'decoderImplementation', 'freezeCount', 'pliCount', 'totalSamplesReceived']);
|
||||
}
|
||||
for (const k in outbound) {
|
||||
out.outbound[k] = pick(outbound[k], ['packetsSent', 'bytesSent', 'framesEncoded', 'keyFramesEncoded', 'pliCount']);
|
||||
@@ -169,6 +177,7 @@ window.peer = {
|
||||
async function main() {
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
executablePath: process.env.VOELIN_CHROMIUM || undefined,
|
||||
args: [
|
||||
// Real host candidates instead of mDNS names (no getUserMedia permission here).
|
||||
'--disable-features=WebRtcHideLocalIpsWithMdns',
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
//! The Node.js side of the browser interop tests (headless Chromium through
|
||||
//! `tests/interop/browser-peer.cjs`), shared by the tests of several crates
|
||||
//! with `#[path = ".../tests/interop/browser.rs"] mod browser;`.
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, Lines};
|
||||
use tokio::process::{Child, ChildStdin, ChildStdout, Command};
|
||||
use tokio::time::timeout;
|
||||
|
||||
/// The tests run only with `VOELIN_INTEROP=1` (see `tests/interop/README.md`).
|
||||
pub fn enabled() -> bool {
|
||||
std::env::var("VOELIN_INTEROP").is_ok_and(|v| v == "1")
|
||||
}
|
||||
|
||||
/// Headless Chromium, driven over stdin/stdout.
|
||||
pub struct Browser {
|
||||
_child: Child,
|
||||
stdin: ChildStdin,
|
||||
stdout: Lines<BufReader<ChildStdout>>,
|
||||
}
|
||||
|
||||
impl Browser {
|
||||
pub async fn start() -> Self {
|
||||
let script = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../tests/interop/browser-peer.cjs")
|
||||
.canonicalize()
|
||||
.expect("tests/interop/browser-peer.cjs");
|
||||
let node = std::env::var("VOELIN_NODE").unwrap_or_else(|_| "node".into());
|
||||
let mut command = Command::new(node);
|
||||
command
|
||||
.arg(script)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::inherit())
|
||||
.kill_on_drop(true);
|
||||
// Playwright is usually installed globally.
|
||||
if std::env::var_os("NODE_PATH").is_none()
|
||||
&& let Ok(out) = std::process::Command::new("npm").args(["root", "-g"]).output()
|
||||
{
|
||||
command.env("NODE_PATH", String::from_utf8_lossy(&out.stdout).trim());
|
||||
}
|
||||
let mut child = command.spawn().expect("cannot start node (set VOELIN_NODE)");
|
||||
let stdin = child.stdin.take().unwrap();
|
||||
let stdout = BufReader::new(child.stdout.take().unwrap()).lines();
|
||||
let mut browser = Self { _child: child, stdin, stdout };
|
||||
let ready = browser.read().await;
|
||||
eprintln!("browser: {}", ready["userAgent"]);
|
||||
browser
|
||||
}
|
||||
|
||||
async fn read(&mut self) -> Value {
|
||||
let line = timeout(Duration::from_secs(60), self.stdout.next_line())
|
||||
.await
|
||||
.expect("browser did not answer")
|
||||
.unwrap()
|
||||
.expect("browser exited");
|
||||
let value: Value = serde_json::from_str(&line).unwrap();
|
||||
if let Some(error) = value.get("error") {
|
||||
panic!("browser: {error}");
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
pub async fn call(&mut self, command: Value) -> Value {
|
||||
let mut line = command.to_string();
|
||||
line.push('\n');
|
||||
self.stdin.write_all(line.as_bytes()).await.unwrap();
|
||||
self.read().await
|
||||
}
|
||||
|
||||
pub async fn quit(mut self) {
|
||||
let _ = self.call(json!({ "op": "quit" })).await;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user