diff --git a/crates/voelin-core/src/stream.rs b/crates/voelin-core/src/stream.rs index 478db9a..f385e2c 100644 --- a/crates/voelin-core/src/stream.rs +++ b/crates/voelin-core/src/stream.rs @@ -1295,9 +1295,21 @@ mod tests { // Before the viewer asks: its offer is made after this. sink.layer_format(0, format(60_000_000)); handles[1].send(StreamCmd::Watch { stream_id: "s-1".into() }); - wait(&mut rx, |e| match e { - Event::WatchState { session: 2, state: WatchState::Connected, .. } => Some(()), - _ => None, + // Connected for the viewer and for the streamer, in either order: the + // streamer asks for a keyframe when its viewer connects, a moment after + // the viewer has seen the connection. + let (mut watching, mut served) = (false, false); + wait(&mut rx, |e| { + match e { + Event::WatchState { session: 2, state: WatchState::Connected, .. } => { + watching = true; + } + Event::StreamViewers { session: 1, viewers } => { + served |= viewers.iter().any(|v| v.state == ViewerState::Connected); + } + _ => {} + } + (watching && served).then_some(()) }) .await; // 3840x2160 at 60 fps is level 5.2 (0x34) in both profiles. @@ -1312,7 +1324,15 @@ mod tests { sink.take_layer_keyframes(&mut layers); layers.contains(0) }; - keyframes(); + // What asked for a keyframe so far (going live, the viewer's connecting + // and its first picture request) is done when a moment longer than the + // merging interval of requests (250 ms) passes with none. + for _ in 0..50 { + tokio::time::sleep(Duration::from_millis(300)).await; + if !keyframes() { + break; + } + } sink.layer_format(0, format(9_000_000)); timeout(Duration::from_secs(5), async { while !keyframes() {