From 0844d35411b36165a9b2ae88d23ec922c4ebffbd Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 01:12:15 +0000 Subject: [PATCH] voelin-core: live test of a viewer that answers another codec Against the TeamSpeak 6 dev server: the streamer offers VP9 (its stream codec) and VP8, a viewer that decodes only VP8 answers VP8 and decodes pictures from the encoder made for it, and the VP9 encoder, wanted by nobody, idles. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G --- crates/voelin-core/tests/media_live.rs | 79 +++++++++++++++++++++++++- docs/media.md | 3 +- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/crates/voelin-core/tests/media_live.rs b/crates/voelin-core/tests/media_live.rs index 3226768..f27ec7f 100644 --- a/crates/voelin-core/tests/media_live.rs +++ b/crates/voelin-core/tests/media_live.rs @@ -14,7 +14,7 @@ use voelin_core::media::voelin_media::capture::SourceId; use voelin_core::media::voelin_media::capture::synthetic::RECT_COLOR; use voelin_core::media::voelin_media::{Codec, Codecs, convert}; use voelin_core::media::{Streamer, StreamerConfig, Viewer, peer_config, stream_codec}; -use voelin_core::stream::{PeerConfig, StreamSetup}; +use voelin_core::stream::{PeerConfig, StreamSetup, VideoCodec}; use voelin_core::{Command, Engine, Event, StreamState, VoiceOptions, VoiceState, WatchState}; fn live() -> bool { @@ -177,3 +177,80 @@ async fn ts6_test_pattern_decoded() { engine.send(Command::CloseSession { session: 2 }); tokio::time::sleep(Duration::from_millis(500)).await; } + +/// The streamer's offer lists VP9 (its stream codec) and VP8; a viewer that +/// only decodes VP8 answers VP8 and gets VP8 pictures from an encoder made +/// for it, while the VP9 encoder, wanted by nobody, idles. +#[tokio::test(flavor = "multi_thread")] +async fn ts6_viewer_gets_the_codec_it_chose() { + if !live() { + eprintln!("skipped: set VOELIN_LIVE=1 with the dev servers running"); + return; + } + let engine = Engine::start(); + let mut events = engine.subscribe(); + let codecs = Arc::new(Codecs::builtin()); + let vp9_first = PeerConfig { video_codecs: vec![VideoCodec::Vp9], ..PeerConfig::loopback() }; + let streamer_peer = peer_config(&codecs, vp9_first); + assert_eq!(streamer_peer.video_codecs, [VideoCodec::Vp9, VideoCodec::Vp8]); + let codec = stream_codec(&codecs, &streamer_peer).expect("an encoder"); + assert_eq!(codec, Codec::Vp9); + let viewer_peer = + PeerConfig { accept_video_codecs: vec![VideoCodec::Vp8], ..PeerConfig::loopback() }; + let tag = std::process::id() % 10_000; + connect(&engine, &mut events, 1, &format!("c-streamer-{tag}"), streamer_peer).await; + connect(&engine, &mut events, 2, &format!("c-viewer-{tag}"), viewer_peer).await; + + let config = StreamerConfig { + source: SourceId::Synthetic, + synthetic_size: (320, 180), + bitrate_kbps: 1000, + codec, + ..StreamerConfig::default() + }; + let streamer = Streamer::start(&codecs, config).await.unwrap(); + let setup = StreamSetup { name: format!("codecs {tag}"), ..Default::default() }; + engine.send(Command::StartStream { session: 1, setup, auto_accept: true }); + let mut live = None; + let mut listed = Vec::new(); + let (id, sink) = wait_for(&mut events, "stream live and in the viewer's list", |e| { + match e { + Event::StreamState { session: 1, state: StreamState::Live { id, sink } } => { + live = Some((id.clone(), sink.clone())); + } + Event::StreamsChanged { session: 2, streams } => { + listed = streams.iter().map(|s| s.id.clone()).collect(); + } + _ => {} + } + live.clone().filter(|(id, _)| listed.contains(id)) + }) + .await; + streamer.attach(Arc::new(sink)); + let (tx, pictures) = std_mpsc::channel(); + let viewer = Viewer::start(&engine, 2, &id, codecs, move |picture| { + let _ = tx.send(picture); + }); + engine.send(Command::WatchStream { session: 2, stream_id: id.clone() }); + let decoded = tokio::task::spawn_blocking(move || { + let mut decoded = 0; + while decoded < 30 { + let picture = pictures.recv_timeout(Duration::from_secs(15)).expect("no picture"); + assert_eq!((picture.width, picture.height), (320, 180)); + decoded += 1; + } + decoded + }) + .await + .unwrap(); + let sent = streamer.stats(); + eprintln!("decoded {decoded}, sent {sent:?}"); + assert_eq!(sent.layers[0].codecs, [Codec::Vp8], "only the codec a viewer chose"); + assert!(viewer.stats().error.is_none()); + engine.send(Command::StopStream { session: 1 }); + drop(viewer); + drop(streamer); + engine.send(Command::CloseSession { session: 1 }); + engine.send(Command::CloseSession { session: 2 }); + tokio::time::sleep(Duration::from_millis(500)).await; +} diff --git a/docs/media.md b/docs/media.md index a99bea6..958e23c 100644 --- a/docs/media.md +++ b/docs/media.md @@ -607,7 +607,8 @@ has not run on Windows yet. | Answer's codec reported to the streamer, H.264 level in the offer, HEVC offered | `voelin-stream` `peer::tests::streamer_learns_the_answered_codec`, `h264::tests` | tested (str0m on loopback) | | x264 / SVT-AV1 / libaom in the streamer pipeline | `voelinctl stream bench --encoder ...` | 720p30: x264 8.7 ms per frame, SVT-AV1 1.3 ms, libaom 37 ms; 1.1 allocations per encoded frame | | Hardware encoders (VA-API, NVENC, Quick Sync, AMF, Media Foundation, VideoToolbox), DMA-BUF import | – | compile only (no GPU here); the Windows code type-checks for `x86_64-pc-windows-gnu` | -| Several codecs against official TeamSpeak viewers | – | not tested live | +| Offer [VP9, VP8], a viewer that decodes only VP8 → its own VP8 encoder, VP9 idle, pictures decoded | `voelin-core/tests/media_live.rs` `ts6_viewer_gets_the_codec_it_chose` (`VOELIN_LIVE=1`) | tested against the TeamSpeak 6 dev server (our client on both ends) | +| Several codecs against official TeamSpeak viewers | – | not tested (no official client here) | | Test pattern → VP8 → decoder, rectangle position and colour | `voelin-core` `media::tests::local_preview_decodes_the_pattern` | tested | | Test pattern → two engine stream tasks → str0m peers on loopback → decoder | `voelin-core` `stream::tests::test_pattern_through_stream_tasks` | tested | | Stream audio (RTP time → jitter buffer ids, volume, end) | `voelin-core` `audio::tests::stream_audio_with_volume`, stream task test | tested |