Interop: Chromium's AV1, VP9 and H.264 decode in the engine's pipeline
The official client sends AV1 from modern GPUs, and H.264 after it re-aligns; nothing checked that our viewer takes what a libwebrtc sender produces. Headless Chromium now offers its canvas in AV1, VP9 and H.264 in turn to our viewer peer, configured with peer_config like a watch (accepting what this machine decodes), and a VideoPipeline must decode 30 pictures of each at the canvas's size with the first decoder of the codec's ladder, keyframe requests going back as PLIs. Chromium 152 (Arch Linux, VOELIN_CHROMIUM=/usr/bin/chromium) sends all three; here they decode on the GPU (av1_vaapi, vp9_vaapi, h264_vaapi). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6484a802c9
commit
db74e72592
2 files changed
+79
-3
No files matched your search
@@ -2,7 +2,8 @@
|
||||
//! pattern, encoded by each encoder this machine has as a share encodes the
|
||||
//! screen, sent by our streamer peer offering just that codec, must decode
|
||||
//! at its size in headless Chromium (libwebrtc, the stack the official
|
||||
//! TeamSpeak 6 client is built on).
|
||||
//! TeamSpeak 6 client is built on). And the other way: what Chromium sends
|
||||
//! (AV1, VP9, H.264) our viewer accepts and the engine's pipeline decodes.
|
||||
//!
|
||||
//! Runs only with `VOELIN_INTEROP=1` (see `tests/interop/README.md`). Codecs
|
||||
//! the browser does not decode (H.264 in Playwright's Chromium, HEVC) are
|
||||
@@ -11,6 +12,8 @@
|
||||
|
||||
#![cfg(feature = "media-desktop")]
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use serde_json::{Value, json};
|
||||
@@ -18,8 +21,8 @@ use tokio::time::timeout;
|
||||
use voelin_core::media::voelin_media::capture::SourceId;
|
||||
use voelin_core::media::voelin_media::{Codec, Codecs};
|
||||
use voelin_core::media::{
|
||||
EncodedSource, EncoderPreference, Streamer, StreamerConfig, decoded_everywhere, media_codec,
|
||||
peer_config, preferred_codec, video_codec,
|
||||
EncodedSource, EncoderPreference, Streamer, StreamerConfig, VideoPipeline, decoded_everywhere,
|
||||
media_codec, peer_config, preferred_codec, video_codec,
|
||||
};
|
||||
use voelin_core::stream::{FrameSource, PeerConfig, VideoCodec};
|
||||
use voelin_stream::{Peer, PeerEvent};
|
||||
@@ -185,3 +188,72 @@ async fn share_offer_picks_a_codec_every_client_decodes() {
|
||||
browser.quit().await;
|
||||
decoded(&video).unwrap();
|
||||
}
|
||||
|
||||
/// Headless Chromium sends its canvas (320x240) in AV1, VP9 and H.264 in
|
||||
/// turn (what it cannot send is skipped; a system Chromium sends H.264) to
|
||||
/// our viewer peer, which accepts what this machine decodes
|
||||
/// (`peer_config`); the engine's pipeline decodes 30 pictures at that size
|
||||
/// with the first decoder of the codec's ladder (VA-API where it decodes
|
||||
/// the codec), asking the browser for keyframes as a watch does.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn browser_streams_decode_in_the_pipeline() {
|
||||
if !enabled() {
|
||||
eprintln!("skipped: set VOELIN_INTEROP=1 (needs node, Playwright and Chromium)");
|
||||
return;
|
||||
}
|
||||
let mut browser = Browser::start().await;
|
||||
let codecs = Arc::new(Codecs::new());
|
||||
let config = peer_config(&codecs, PeerConfig::loopback());
|
||||
let mut decoded = Vec::new();
|
||||
for codec in [Codec::Av1, Codec::Vp9, Codec::H264] {
|
||||
let offer = browser.call(json!({ "op": "offer", "codec": codec.name() })).await;
|
||||
if offer.get("unsupported").is_some() {
|
||||
eprintln!("{codec}: the browser cannot send it, skipped");
|
||||
continue;
|
||||
}
|
||||
assert!(config.accept_video_codecs.contains(&video_codec(codec)), "{codec} not accepted");
|
||||
let (mut peer, answer) =
|
||||
Peer::answer(&config, offer["sdp"].as_str().unwrap()).await.unwrap();
|
||||
browser.call(json!({ "op": "accept", "sdp": answer })).await;
|
||||
let keyframe = Arc::new(AtomicBool::new(false));
|
||||
let (tx, pictures) = std::sync::mpsc::channel();
|
||||
let pipeline = VideoPipeline::new(
|
||||
codecs.clone(),
|
||||
move |picture| {
|
||||
let _ = tx.send((picture.width, picture.height));
|
||||
},
|
||||
{
|
||||
let keyframe = keyframe.clone();
|
||||
move || keyframe.store(true, Ordering::Relaxed)
|
||||
},
|
||||
);
|
||||
let mut sizes = Vec::new();
|
||||
let _ = timeout(Duration::from_secs(15), async {
|
||||
while let Some(event) = peer.next_event().await {
|
||||
match event {
|
||||
PeerEvent::Media(frame) => pipeline.push(frame),
|
||||
PeerEvent::Closed => break,
|
||||
_ => {}
|
||||
}
|
||||
if keyframe.swap(false, Ordering::Relaxed) {
|
||||
peer.request_keyframe();
|
||||
}
|
||||
sizes.extend(pictures.try_iter());
|
||||
if sizes.len() >= 30 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
let stats = pipeline.stats();
|
||||
peer.close();
|
||||
eprintln!("{codec}: {} pictures, {stats:?}", sizes.len());
|
||||
assert!(sizes.len() >= 30, "{codec}: {} pictures decoded, {stats:?}", sizes.len());
|
||||
assert!(sizes.iter().all(|&s| s == (320, 240)), "{codec}: {sizes:?}");
|
||||
assert_eq!(stats.codec, Some(codec));
|
||||
assert_eq!(stats.decoder, codecs.decoders_for(codec).first().copied(), "{stats:?}");
|
||||
decoded.push(codec);
|
||||
}
|
||||
browser.quit().await;
|
||||
assert!(decoded.contains(&Codec::Av1), "the browser sent no AV1: {decoded:?}");
|
||||
}
|
||||
@@ -14,6 +14,7 @@ TeamSpeak server is involved.
|
||||
| `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 |
|
||||
| `browser_streams_decode_in_the_pipeline` (voelin-core) | The other way: Chromium sends its canvas (320x240) in AV1, VP9 and H.264 in turn (skipping what it cannot send) to our viewer peer, which accepts what this machine decodes (`peer_config`); the engine's `VideoPipeline` must decode 30 pictures at 320x240 with the first decoder of the codec's ladder (`Codecs::decoders_for`), keyframe requests going to the browser as PLIs |
|
||||
| `browser_renegotiates_with_rust` | Chromium streams VP8, then sends a new offer on the same connection with VP9 first (as the official client re-offers when it does not encode the codec we chose); `Peer::renegotiate` answers on the same peer, in the new offer's codec order; VP9 frames must arrive |
|
||||
| `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` |
|
||||
|
||||
@@ -72,6 +73,9 @@ may do the same; see `docs/protocol-notes/ts6-streaming.md`.
|
||||
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).
|
||||
- Chromium 152 (Arch Linux build, `VOELIN_CHROMIUM=/usr/bin/chromium`) sends
|
||||
AV1, VP9 and H.264; our pipeline decodes all three on the GPU here (AMD,
|
||||
VA-API: `av1_vaapi`, `vp9_vaapi`, `h264_vaapi`), at the canvas's size.
|
||||
- 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
|
||||
|
||||
Reference in new issue
Block a user