diff --git a/crates/voelin-core/src/media.rs b/crates/voelin-core/src/media.rs index 045f3cf..3d7c322 100644 --- a/crates/voelin-core/src/media.rs +++ b/crates/voelin-core/src/media.rs @@ -3548,10 +3548,24 @@ mod tests { }; told(30).await; assert_eq!(streamer.bitrate_kbps(), 1105); - // Not per frame. - let count = lock(&sink.formats).len(); - tokio::time::sleep(Duration::from_millis(200)).await; - assert_eq!(lock(&sink.formats).len(), count); + // Not per frame. The sink is told when it is attached and again by the + // encoder before its first frame (the same format twice), so the count is + // taken once a frame has been handed over and compared after more have; + // the frames, not a pause, are what "per frame" counts. + let frames_by = |frames: u64| { + let streamer = &streamer; + async move { + let deadline = Instant::now() + Duration::from_secs(30); + while streamer.stats().layers[0].frames < frames { + assert!(Instant::now() < deadline, "{frames} frames: {:?}", streamer.stats()); + tokio::time::sleep(Duration::from_millis(20)).await; + } + } + }; + frames_by(1).await; + let (count, seen) = (lock(&sink.formats).len(), streamer.stats().layers[0].frames); + frames_by(seen + 5).await; + assert_eq!(lock(&sink.formats).len(), count, "told again within five frames"); // The stats follow the sink's being told, not the other way round. let deadline = Instant::now() + Duration::from_secs(10); while streamer.stats().layers[0].bitrate != auto_bitrate(640, 480, 30) {