diff --git a/crates/voelin-core/src/link/fake_tests.rs b/crates/voelin-core/src/link/fake_tests.rs index 4c3cd50..cc210e9 100644 --- a/crates/voelin-core/src/link/fake_tests.rs +++ b/crates/voelin-core/src/link/fake_tests.rs @@ -95,7 +95,8 @@ struct HostRig { handle: FakeHandle, cmds: mpsc::UnboundedSender, events: mpsc::UnboundedReceiver, - /// Our voice slot, as the host gave it. + /// Our participant and voice slot, as the host gave them. + own_client: u16, own_slot: u32, /// The clients the link told started talking, in order. talking: Vec, @@ -143,7 +144,7 @@ impl HostRig { }) .expect("the host seated us in voice"); let handle = connector.last_session().expect("the connector made a session"); - Self { handle, cmds, events, own_slot, talking: Vec::new() } + Self { handle, cmds, events, own_client, own_slot, talking: Vec::new() } } /// The next voice packet the audio thread would get; who started to talk on @@ -266,6 +267,26 @@ async fn the_voice_of_other_slots_reaches_the_audio_thread() { assert_eq!(rig.talking, [ALICE as u16, BOB as u16]); } +/// A host whose session loops our own voice back (the fake one does, so that +/// the conformance suite can see media move) does not make the engine play us +/// our own voice or show us as talking: the engine never plays itself. +#[tokio::test(flavor = "multi_thread")] +async fn our_own_voice_coming_back_is_not_played_back() { + let mut rig = HostRig::connect().await; + // The fake host loops accepted media back into the sink (the default). + rig.give(LinkCmd::Audio(voice(&MONO))); + let handle = rig.handle.clone(); + eventually(WAIT, "the packet to leave", || handle.sent_media().len() == 1).await; + // A packet of alice behind it: when this one is out, ours has been through. + handle.inject_media(voice_packet(ALICE_SLOT, voice_sub::CHANNEL, 1, &MONO)); + let own = rig.own_client; + let mut heard = Vec::new(); + while heard.last().is_none_or(|talker| *talker != ALICE as u16) { + heard.push(rig.audio().await.talker.0); + } + assert!(!heard.contains(&own), "the engine played our own voice back: {heard:?}"); +} + /// The link conformance suite of the protocol repository against the session /// the engine's registry hands over: the registry adds nothing to a plain /// connector's session (`Backends::connect` returns it untouched), so the 17 diff --git a/crates/voelin-core/src/link/session_link.rs b/crates/voelin-core/src/link/session_link.rs index a4e351d..20069f4 100644 --- a/crates/voelin-core/src/link/session_link.rs +++ b/crates/voelin-core/src/link/session_link.rs @@ -935,6 +935,12 @@ impl Conn { async fn on_media(&mut self, packet: &MediaPacket) { let Some(incoming) = Incoming::parse(packet) else { return }; + // Our own voice, if the session loops it back (the fake host of the + // protocol repository does, so that a test sees media move): the engine + // neither plays us to ourselves nor shows us as talking. + if incoming.slot == self.slot { + return; + } if !self.slots.contains_key(&incoming.slot) { // The push that tells who has this slot may be on its way: media and // pushes travel apart.