BlueGit

ict rusty-teams

feat(calls): noise suppression levels, music mode, push to talk, mute notifications in calls

- Mic menu and Settings > Devices: noise suppression Auto or Off, Music mode switch (persisted, applied live)
- Auto keeps the device track with WebRTC's built-in processing; Off and Music mode run a cpal mic through our own APM (software_audio, was share_audio) and swap the sender track
- The libwebrtc APM has on/off flags only, so no Low and High levels
- Push to talk: hold Ctrl+Space while muted, hint chip on the stage, not bound inside text fields
- Setting "Mute notifications during calls and meetings" drops message toasts while a call is active

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-13 · 7 weeks ago

Hash
91c68a386c733662f6ff9e82a83456eac64d1e10
Parent
46ed3a3c
19 files changed +659 −80
ROADMAP.md +3 −0
@@ -128,6 +128,7 @@ Feature parity with the Microsoft Teams desktop client.
128 128 | Mentions-only mode, preview off | Done | |
129 129 | Stack of 3, queue, Hide all, fade-out | Done | |
130 130 | Muted chats stay quiet | Done | Toast, sound and taskbar badge only for @mentions |
131 | Mute notifications during calls and meetings | Done | Settings > Notifications switch, default off; message toasts and sounds stay away while a call is active, call rings still show |
131 132 | Notifications on Linux | Missing | |
132 133
133 134 ## Search and navigation
@@ -174,6 +175,8 @@ Feature parity with the Microsoft Teams desktop client.
174 175 | Video calls (1:1 and incoming) | Partial | Camera button in 1:1 calls renegotiates a video line on the same peer connection (modalities Audio and Video), incoming video ring toast with Decline / Audio / Video, accept with video answers the video line sending, accept with audio receive-only. Offer and answer built from the Teams code and unit tested at SDP level; needs a second person |
175 176 | Recording | Partial | Organizer "..." > Start recording / Stop recording (confirm) through the recorder bot, red dot and "Recording" in the header for everyone from the meeting state, consent notice that keeps mic and camera off until OK. Bodies unit tested; start and stop run live through `meet_now --record`, consent needs a tenant with the policy on and a second person |
176 177 | Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |
178 | Noise suppression, music mode | Partial | Mic menu and Settings > Devices: Auto (device track with WebRTC echo cancellation, AGC, NS) or Off, Music mode keeps echo cancellation only. No Low/High, the APM has on/off flags only. Off and Music mode run a cpal mic through our own APM; checked with synthetic sources only, not with a real mic in a call |
179 | Push to talk | Partial | Hold Ctrl+Space while muted to talk, release to mute; main window focused, not inside text fields; hint chip on the stage. Unit tested, not tried on the Windows build |
177 180 | Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
178 181 | Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
179 182 | Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
@@ -128,6 +128,7 @@ Feature parity with the Microsoft Teams desktop client.
128| Mentions-only mode, preview off | Done | |
128| Mentions-only mode, preview off | Done | |
129| Stack of 3, queue, Hide all, fade-out | Done | |
129| Stack of 3, queue, Hide all, fade-out | Done | |
130| Muted chats stay quiet | Done | Toast, sound and taskbar badge only for @mentions |
130| Muted chats stay quiet | Done | Toast, sound and taskbar badge only for @mentions |
131| Mute notifications during calls and meetings | Done | Settings > Notifications switch, default off; message toasts and sounds stay away while a call is active, call rings still show |
131| Notifications on Linux | Missing | |
132| Notifications on Linux | Missing | |
132
133
133## Search and navigation
134## Search and navigation
@@ -174,6 +175,8 @@ Feature parity with the Microsoft Teams desktop client.
174| Video calls (1:1 and incoming) | Partial | Camera button in 1:1 calls renegotiates a video line on the same peer connection (modalities Audio and Video), incoming video ring toast with Decline / Audio / Video, accept with video answers the video line sending, accept with audio receive-only. Offer and answer built from the Teams code and unit tested at SDP level; needs a second person |
175| Video calls (1:1 and incoming) | Partial | Camera button in 1:1 calls renegotiates a video line on the same peer connection (modalities Audio and Video), incoming video ring toast with Decline / Audio / Video, accept with video answers the video line sending, accept with audio receive-only. Offer and answer built from the Teams code and unit tested at SDP level; needs a second person |
175| Recording | Partial | Organizer "..." > Start recording / Stop recording (confirm) through the recorder bot, red dot and "Recording" in the header for everyone from the meeting state, consent notice that keeps mic and camera off until OK. Bodies unit tested; start and stop run live through `meet_now --record`, consent needs a tenant with the policy on and a second person |
176| Recording | Partial | Organizer "..." > Start recording / Stop recording (confirm) through the recorder bot, red dot and "Recording" in the header for everyone from the meeting state, consent notice that keeps mic and camera off until OK. Bodies unit tested; start and stop run live through `meet_now --record`, consent needs a tenant with the policy on and a second person |
176| Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |
177| Hold, resume, transfer | Partial | 1:1 "..." > Hold renegotiates every line inactive, "On hold" view with Resume, "You're on hold" when the other side holds, Transfer... person picker with Transfer now (blind) and Consult first (second call, first held, Transfer now). Needs a second person; redirect and park not built |
178| Noise suppression, music mode | Partial | Mic menu and Settings > Devices: Auto (device track with WebRTC echo cancellation, AGC, NS) or Off, Music mode keeps echo cancellation only. No Low/High, the APM has on/off flags only. Off and Music mode run a cpal mic through our own APM; checked with synthetic sources only, not with a real mic in a call |
179| Push to talk | Partial | Hold Ctrl+Space while muted to talk, release to mute; main window focused, not inside text fields; hint chip on the stage. Unit tested, not tried on the Windows build |
177| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
180| Breakout rooms (participant) | Partial | Move message from the participant update or the replacement invite: notice "Moving you to <room>", leave and join the room, "Return to main meeting" in the header, a closed room goes back to the main meeting. Parsing unit tested; needs an organizer who moves people |
178| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
181| Whiteboard | Partial | Stage shows "<name> is sharing a whiteboard" with Open in browser, "..." > Whiteboard opens the meeting's board. State parsing unit tested; the share callback link is registered on join but not yet seen live |
179| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
182| Call history | Done | Calls tab (Ctrl+5) from the Teams call log: avatar, name, Missed call in red, Outgoing / Incoming / Meeting with duration, time like the chat list. Click calls back or opens the meeting chat; right-click Call back and Open chat. Refreshes on tab open and after a call ends. Read live (counts and shapes); no realtime update |
crates/app/src/app_state.rs +3 −0
@@ -126,6 +126,7 @@ pub struct AppState {
126 126 pub call_share_sound: bool,
127 127 pub call_background: crate::call::BackgroundPick,
128 128 pub call_camera: calling::DeviceChoice,
129 pub call_mic: calling::MicSettings,
129 130 pub meet_now_pending: bool,
130 131 pub call_backgrounds: crate::call::BackgroundLibrary,
131 132 pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,
@@ -223,6 +224,7 @@ impl AppState {
223 224 call_share_sound: false,
224 225 call_background: crate::call::BackgroundPick::None,
225 226 call_camera: calling::DeviceChoice::SystemDefault,
227 call_mic: calling::MicSettings::default(),
226 228 meet_now_pending: false,
227 229 call_backgrounds: if mode.demo {
228 230 crate::call::demo_library()
@@ -241,6 +243,7 @@ impl AppState {
241 243 state.call_share_sound = crate::call::load_share_sound(&state.store);
242 244 state.call_background = crate::call::load_background(&state.store);
243 245 state.call_camera = crate::call::load_camera(&state.store);
246 state.call_mic = crate::call::load_mic(&state.store);
244 247 state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
245 248 state.load_cached_translation_settings();
246 249 if !mode.demo {
@@ -126,6 +126,7 @@ pub struct AppState {
126 pub call_share_sound: bool,
126 pub call_share_sound: bool,
127 pub call_background: crate::call::BackgroundPick,
127 pub call_background: crate::call::BackgroundPick,
128 pub call_camera: calling::DeviceChoice,
128 pub call_camera: calling::DeviceChoice,
129 pub call_mic: calling::MicSettings,
129 pub meet_now_pending: bool,
130 pub meet_now_pending: bool,
130 pub call_backgrounds: crate::call::BackgroundLibrary,
131 pub call_backgrounds: crate::call::BackgroundLibrary,
131 pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,
132 pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,
@@ -223,6 +224,7 @@ impl AppState {
223 call_share_sound: false,
224 call_share_sound: false,
224 call_background: crate::call::BackgroundPick::None,
225 call_background: crate::call::BackgroundPick::None,
225 call_camera: calling::DeviceChoice::SystemDefault,
226 call_camera: calling::DeviceChoice::SystemDefault,
227 call_mic: calling::MicSettings::default(),
226 meet_now_pending: false,
228 meet_now_pending: false,
227 call_backgrounds: if mode.demo {
229 call_backgrounds: if mode.demo {
228 crate::call::demo_library()
230 crate::call::demo_library()
@@ -241,6 +243,7 @@ impl AppState {
241 state.call_share_sound = crate::call::load_share_sound(&state.store);
243 state.call_share_sound = crate::call::load_share_sound(&state.store);
242 state.call_background = crate::call::load_background(&state.store);
244 state.call_background = crate::call::load_background(&state.store);
243 state.call_camera = crate::call::load_camera(&state.store);
245 state.call_camera = crate::call::load_camera(&state.store);
246 state.call_mic = crate::call::load_mic(&state.store);
244 state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
247 state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
245 state.load_cached_translation_settings();
248 state.load_cached_translation_settings();
246 if !mode.demo {
249 if !mode.demo {
crates/app/src/call/actions.rs +34 −1
@@ -3,7 +3,7 @@ use std::time::{Duration, Instant};
3 3 use calling::meeting::LiveMeeting;
4 4 use calling::{
5 5 AcceptMode, CallCommand, CallHandle, CallSpec, CallState, CallUpdate, Callee, DeviceChoice,
6 EndReason, EngineEvent, MuteCommand, Reaction, RingSignal, ShareSource, VideoKey,
6 EndReason, EngineEvent, MicSettings, MuteCommand, Reaction, RingSignal, ShareSource, VideoKey,
7 7 };
8 8 use gpui_kit::*;
9 9
@@ -16,6 +16,7 @@ use super::demo::{
16 16 };
17 17 use super::features::room_closed_move;
18 18 use super::media::CallMedia;
19 use super::mic::save_mic;
19 20 use super::model::{ActiveCall, CallKind, CallModel, ended_notice};
20 21 use super::ring::{MissedCall, RingOutcome};
21 22 use super::target::{is_organizer, plan_for_chat};
@@ -215,6 +216,9 @@ impl AppState {
215 216 if self.call_share_sound {
216 217 self.send_call_command(CallCommand::SetShareSound(true));
217 218 }
219 if self.call_mic != MicSettings::default() {
220 self.send_call_command(CallCommand::SetMicSettings(self.call_mic));
221 }
218 222 if let Some(call) = self.call.as_mut() {
219 223 call.model.background = self.call_background.clone();
220 224 call.model.camera = self.call_camera.clone();
@@ -395,6 +399,35 @@ impl AppState {
395 399 self.send_call_command(CallCommand::SetCamera(on));
396 400 }
397 401
402 pub fn set_call_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
403 self.call_mic = settings;
404 save_mic(&self.store, settings);
405 self.send_call_command(CallCommand::SetMicSettings(settings));
406 cx.notify();
407 }
408
409 pub fn press_push_to_talk(&mut self, _cx: &mut Context<Self>) {
410 let Some(call) = self.call.as_mut() else {
411 return;
412 };
413 let command = call
414 .push_to_talk
415 .press(call.model.muted, call.model.can_unmute());
416 if let Some(command) = command {
417 self.send_call_command(CallCommand::Mute(command));
418 }
419 }
420
421 pub fn release_push_to_talk(&mut self, _cx: &mut Context<Self>) {
422 let command = self
423 .call
424 .as_mut()
425 .and_then(|call| call.push_to_talk.release());
426 if let Some(command) = command {
427 self.send_call_command(CallCommand::Mute(command));
428 }
429 }
430
398 431 pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
399 432 let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));
400 433 self.call_camera = choice.clone();
@@ -3,7 +3,7 @@ use std::time::{Duration, Instant};
3use calling::meeting::LiveMeeting;
3use calling::meeting::LiveMeeting;
4use calling::{
4use calling::{
5 AcceptMode, CallCommand, CallHandle, CallSpec, CallState, CallUpdate, Callee, DeviceChoice,
5 AcceptMode, CallCommand, CallHandle, CallSpec, CallState, CallUpdate, Callee, DeviceChoice,
6 EndReason, EngineEvent, MuteCommand, Reaction, RingSignal, ShareSource, VideoKey,
6 EndReason, EngineEvent, MicSettings, MuteCommand, Reaction, RingSignal, ShareSource, VideoKey,
7};
7};
8use gpui_kit::*;
8use gpui_kit::*;
9
9
@@ -16,6 +16,7 @@ use super::demo::{
16};
16};
17use super::features::room_closed_move;
17use super::features::room_closed_move;
18use super::media::CallMedia;
18use super::media::CallMedia;
19use super::mic::save_mic;
19use super::model::{ActiveCall, CallKind, CallModel, ended_notice};
20use super::model::{ActiveCall, CallKind, CallModel, ended_notice};
20use super::ring::{MissedCall, RingOutcome};
21use super::ring::{MissedCall, RingOutcome};
21use super::target::{is_organizer, plan_for_chat};
22use super::target::{is_organizer, plan_for_chat};
@@ -215,6 +216,9 @@ impl AppState {
215 if self.call_share_sound {
216 if self.call_share_sound {
216 self.send_call_command(CallCommand::SetShareSound(true));
217 self.send_call_command(CallCommand::SetShareSound(true));
217 }
218 }
219 if self.call_mic != MicSettings::default() {
220 self.send_call_command(CallCommand::SetMicSettings(self.call_mic));
221 }
218 if let Some(call) = self.call.as_mut() {
222 if let Some(call) = self.call.as_mut() {
219 call.model.background = self.call_background.clone();
223 call.model.background = self.call_background.clone();
220 call.model.camera = self.call_camera.clone();
224 call.model.camera = self.call_camera.clone();
@@ -395,6 +399,35 @@ impl AppState {
395 self.send_call_command(CallCommand::SetCamera(on));
399 self.send_call_command(CallCommand::SetCamera(on));
396 }
400 }
397
401
402 pub fn set_call_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
403 self.call_mic = settings;
404 save_mic(&self.store, settings);
405 self.send_call_command(CallCommand::SetMicSettings(settings));
406 cx.notify();
407 }
408
409 pub fn press_push_to_talk(&mut self, _cx: &mut Context<Self>) {
410 let Some(call) = self.call.as_mut() else {
411 return;
412 };
413 let command = call
414 .push_to_talk
415 .press(call.model.muted, call.model.can_unmute());
416 if let Some(command) = command {
417 self.send_call_command(CallCommand::Mute(command));
418 }
419 }
420
421 pub fn release_push_to_talk(&mut self, _cx: &mut Context<Self>) {
422 let command = self
423 .call
424 .as_mut()
425 .and_then(|call| call.push_to_talk.release());
426 if let Some(command) = command {
427 self.send_call_command(CallCommand::Mute(command));
428 }
429 }
430
398 pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
431 pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
399 let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));
432 let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));
400 self.call_camera = choice.clone();
433 self.call_camera = choice.clone();
crates/app/src/call/demo.rs +1 −1
@@ -471,7 +471,7 @@ async fn speak_until_hangup(
471 471 camera_on = on;
472 472 control.send(CallUpdate::Camera(on));
473 473 }
474 Some(CallCommand::SelectCamera(_)) => {}
474 Some(CallCommand::SelectCamera(_) | CallCommand::SetMicSettings(_)) => {}
475 475 Some(CallCommand::StartShare(source)) => {
476 476 control.send(CallUpdate::LocalShare(Some(source.label())));
477 477 if share_sound {
@@ -471,7 +471,7 @@ async fn speak_until_hangup(
471 camera_on = on;
471 camera_on = on;
472 control.send(CallUpdate::Camera(on));
472 control.send(CallUpdate::Camera(on));
473 }
473 }
474 Some(CallCommand::SelectCamera(_)) => {}
474 Some(CallCommand::SelectCamera(_) | CallCommand::SetMicSettings(_)) => {}
475 Some(CallCommand::StartShare(source)) => {
475 Some(CallCommand::StartShare(source)) => {
476 control.send(CallUpdate::LocalShare(Some(source.label())));
476 control.send(CallUpdate::LocalShare(Some(source.label())));
477 if share_sound {
477 if share_sound {
crates/app/src/call/mic.rs added +71 −0
@@ -0,0 +1,71 @@
1 use calling::{MicSettings, NoiseSuppression};
2 use store::Store;
3
4 const META_KEY: &str = "call_mic";
5
6 pub fn load_mic(store: &Store) -> MicSettings {
7 store
8 .meta(META_KEY)
9 .ok()
10 .flatten()
11 .map(|text| parse(&text))
12 .unwrap_or_default()
13 }
14
15 pub fn save_mic(store: &Store, settings: MicSettings) {
16 let _ = store.set_meta(META_KEY, &serialize(settings));
17 }
18
19 fn serialize(settings: MicSettings) -> String {
20 format!(
21 "noise={}\nmusic={}",
22 settings.noise_suppression.key(),
23 settings.music_mode
24 )
25 }
26
27 fn parse(text: &str) -> MicSettings {
28 let mut settings = MicSettings::default();
29 for (key, value) in text.lines().filter_map(|line| line.split_once('=')) {
30 match key {
31 "noise" => {
32 settings.noise_suppression = NoiseSuppression::from_key(value).unwrap_or_default()
33 }
34 "music" => settings.music_mode = value == "true",
35 _ => {}
36 }
37 }
38 settings
39 }
40
41 #[cfg(test)]
42 mod tests {
43 use super::*;
44
45 #[test]
46 fn round_trips_every_field() {
47 let settings = MicSettings {
48 noise_suppression: NoiseSuppression::Off,
49 music_mode: true,
50 };
51 assert_eq!(parse(&serialize(settings)), settings);
52 }
53
54 #[test]
55 fn garbage_gives_defaults() {
56 assert_eq!(parse(""), MicSettings::default());
57 assert_eq!(parse("noise=loud\nmusic"), MicSettings::default());
58 }
59
60 #[test]
61 fn persists_in_store() {
62 let store = Store::open_in_memory().unwrap();
63 assert_eq!(load_mic(&store), MicSettings::default());
64 let changed = MicSettings {
65 noise_suppression: NoiseSuppression::Off,
66 music_mode: false,
67 };
68 save_mic(&store, changed);
69 assert_eq!(load_mic(&store), changed);
70 }
71 }
@@ -0,0 +1,71 @@
1use calling::{MicSettings, NoiseSuppression};
2use store::Store;
3
4const META_KEY: &str = "call_mic";
5
6pub fn load_mic(store: &Store) -> MicSettings {
7 store
8 .meta(META_KEY)
9 .ok()
10 .flatten()
11 .map(|text| parse(&text))
12 .unwrap_or_default()
13}
14
15pub fn save_mic(store: &Store, settings: MicSettings) {
16 let _ = store.set_meta(META_KEY, &serialize(settings));
17}
18
19fn serialize(settings: MicSettings) -> String {
20 format!(
21 "noise={}\nmusic={}",
22 settings.noise_suppression.key(),
23 settings.music_mode
24 )
25}
26
27fn parse(text: &str) -> MicSettings {
28 let mut settings = MicSettings::default();
29 for (key, value) in text.lines().filter_map(|line| line.split_once('=')) {
30 match key {
31 "noise" => {
32 settings.noise_suppression = NoiseSuppression::from_key(value).unwrap_or_default()
33 }
34 "music" => settings.music_mode = value == "true",
35 _ => {}
36 }
37 }
38 settings
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn round_trips_every_field() {
47 let settings = MicSettings {
48 noise_suppression: NoiseSuppression::Off,
49 music_mode: true,
50 };
51 assert_eq!(parse(&serialize(settings)), settings);
52 }
53
54 #[test]
55 fn garbage_gives_defaults() {
56 assert_eq!(parse(""), MicSettings::default());
57 assert_eq!(parse("noise=loud\nmusic"), MicSettings::default());
58 }
59
60 #[test]
61 fn persists_in_store() {
62 let store = Store::open_in_memory().unwrap();
63 assert_eq!(load_mic(&store), MicSettings::default());
64 let changed = MicSettings {
65 noise_suppression: NoiseSuppression::Off,
66 music_mode: false,
67 };
68 save_mic(&store, changed);
69 assert_eq!(load_mic(&store), changed);
70 }
71}
crates/app/src/call/mod.rs +3 −0
@@ -10,15 +10,18 @@ mod join;
10 10 mod launcher;
11 11 mod list;
12 12 mod media;
13 mod mic;
13 14 mod model;
14 15 mod overlay;
15 16 mod overlay_layout;
16 17 mod pictures;
17 18 mod preview;
19 mod push_to_talk;
18 20 mod ring;
19 21 mod target;
20 22
21 23 pub use actions::{load_camera, load_share_sound};
24 pub use mic::load_mic;
22 25 pub use agenda::{AgendaRow, fetch_window, join_available};
23 26 pub use background::{
24 27 BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
@@ -10,15 +10,18 @@ mod join;
10mod launcher;
10mod launcher;
11mod list;
11mod list;
12mod media;
12mod media;
13mod mic;
13mod model;
14mod model;
14mod overlay;
15mod overlay;
15mod overlay_layout;
16mod overlay_layout;
16mod pictures;
17mod pictures;
17mod preview;
18mod preview;
19mod push_to_talk;
18mod ring;
20mod ring;
19mod target;
21mod target;
20
22
21pub use actions::{load_camera, load_share_sound};
23pub use actions::{load_camera, load_share_sound};
24pub use mic::load_mic;
22pub use agenda::{AgendaRow, fetch_window, join_available};
25pub use agenda::{AgendaRow, fetch_window, join_available};
23pub use background::{
26pub use background::{
24 BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
27 BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
crates/app/src/call/model.rs +3 −0
@@ -10,6 +10,7 @@ use tokio::sync::mpsc::UnboundedSender;
10 10
11 11 use super::background::BackgroundPick;
12 12 use super::pictures::CallPictures;
13 use super::push_to_talk::PushToTalk;
13 14
14 15 pub const TEST_CALL_TITLE: &str = "Test call";
15 16 pub const ECHO_NAME: &str = "Teams echo";
@@ -37,6 +38,7 @@ pub struct ActiveCall {
37 38 pub meeting_target: Option<MeetingTarget>,
38 39 pub pending_move: Option<PendingMove>,
39 40 pub consult: Option<ConsultCall>,
41 pub push_to_talk: PushToTalk,
40 42 }
41 43
42 44 #[derive(Debug, Clone, PartialEq)]
@@ -94,6 +96,7 @@ impl ActiveCall {
94 96 meeting_target: None,
95 97 pending_move: None,
96 98 consult: None,
99 push_to_talk: PushToTalk::default(),
97 100 }
98 101 }
99 102
@@ -10,6 +10,7 @@ use tokio::sync::mpsc::UnboundedSender;
10
10
11use super::background::BackgroundPick;
11use super::background::BackgroundPick;
12use super::pictures::CallPictures;
12use super::pictures::CallPictures;
13use super::push_to_talk::PushToTalk;
13
14
14pub const TEST_CALL_TITLE: &str = "Test call";
15pub const TEST_CALL_TITLE: &str = "Test call";
15pub const ECHO_NAME: &str = "Teams echo";
16pub const ECHO_NAME: &str = "Teams echo";
@@ -37,6 +38,7 @@ pub struct ActiveCall {
37 pub meeting_target: Option<MeetingTarget>,
38 pub meeting_target: Option<MeetingTarget>,
38 pub pending_move: Option<PendingMove>,
39 pub pending_move: Option<PendingMove>,
39 pub consult: Option<ConsultCall>,
40 pub consult: Option<ConsultCall>,
41 pub push_to_talk: PushToTalk,
40}
42}
41
43
42#[derive(Debug, Clone, PartialEq)]
44#[derive(Debug, Clone, PartialEq)]
@@ -94,6 +96,7 @@ impl ActiveCall {
94 meeting_target: None,
96 meeting_target: None,
95 pending_move: None,
97 pending_move: None,
96 consult: None,
98 consult: None,
99 push_to_talk: PushToTalk::default(),
97 }
100 }
98 }
101 }
99
102
crates/app/src/call/push_to_talk.rs added +60 −0
@@ -0,0 +1,60 @@
1 use calling::MuteCommand;
2
3 #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
4 pub struct PushToTalk {
5 held: bool,
6 }
7
8 impl PushToTalk {
9 pub fn is_held(self) -> bool {
10 self.held
11 }
12
13 pub fn press(&mut self, muted: bool, can_unmute: bool) -> Option<MuteCommand> {
14 if self.held || !muted || !can_unmute {
15 return None;
16 }
17 self.held = true;
18 Some(MuteCommand::Unmute)
19 }
20
21 pub fn release(&mut self) -> Option<MuteCommand> {
22 std::mem::take(&mut self.held).then_some(MuteCommand::Mute)
23 }
24 }
25
26 #[cfg(test)]
27 mod tests {
28 use super::*;
29
30 #[test]
31 fn pressing_while_muted_unmutes_and_releasing_mutes_again() {
32 let mut talk = PushToTalk::default();
33 assert_eq!(talk.press(true, true), Some(MuteCommand::Unmute));
34 assert!(talk.is_held());
35 assert_eq!(talk.release(), Some(MuteCommand::Mute));
36 assert!(!talk.is_held());
37 }
38
39 #[test]
40 fn key_repeat_sends_one_unmute() {
41 let mut talk = PushToTalk::default();
42 assert!(talk.press(true, true).is_some());
43 assert_eq!(talk.press(false, true), None);
44 assert_eq!(talk.press(true, true), None);
45 }
46
47 #[test]
48 fn pressing_while_unmuted_does_nothing_and_release_stays_quiet() {
49 let mut talk = PushToTalk::default();
50 assert_eq!(talk.press(false, true), None);
51 assert_eq!(talk.release(), None);
52 }
53
54 #[test]
55 fn listen_only_never_unmutes() {
56 let mut talk = PushToTalk::default();
57 assert_eq!(talk.press(true, false), None);
58 assert_eq!(talk.release(), None);
59 }
60 }
@@ -0,0 +1,60 @@
1use calling::MuteCommand;
2
3#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
4pub struct PushToTalk {
5 held: bool,
6}
7
8impl PushToTalk {
9 pub fn is_held(self) -> bool {
10 self.held
11 }
12
13 pub fn press(&mut self, muted: bool, can_unmute: bool) -> Option<MuteCommand> {
14 if self.held || !muted || !can_unmute {
15 return None;
16 }
17 self.held = true;
18 Some(MuteCommand::Unmute)
19 }
20
21 pub fn release(&mut self) -> Option<MuteCommand> {
22 std::mem::take(&mut self.held).then_some(MuteCommand::Mute)
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn pressing_while_muted_unmutes_and_releasing_mutes_again() {
32 let mut talk = PushToTalk::default();
33 assert_eq!(talk.press(true, true), Some(MuteCommand::Unmute));
34 assert!(talk.is_held());
35 assert_eq!(talk.release(), Some(MuteCommand::Mute));
36 assert!(!talk.is_held());
37 }
38
39 #[test]
40 fn key_repeat_sends_one_unmute() {
41 let mut talk = PushToTalk::default();
42 assert!(talk.press(true, true).is_some());
43 assert_eq!(talk.press(false, true), None);
44 assert_eq!(talk.press(true, true), None);
45 }
46
47 #[test]
48 fn pressing_while_unmuted_does_nothing_and_release_stays_quiet() {
49 let mut talk = PushToTalk::default();
50 assert_eq!(talk.press(false, true), None);
51 assert_eq!(talk.release(), None);
52 }
53
54 #[test]
55 fn listen_only_never_unmutes() {
56 let mut talk = PushToTalk::default();
57 assert_eq!(talk.press(true, false), None);
58 assert_eq!(talk.release(), None);
59 }
60}
crates/app/src/notify/rules.rs +17 −0
@@ -75,6 +75,7 @@ pub struct Settings {
75 75 pub flash: bool,
76 76 pub close_to_tray: bool,
77 77 pub do_not_disturb: bool,
78 pub mute_in_calls: bool,
78 79 pub ringtone: Ringtone,
79 80 }
80 81
@@ -88,6 +89,7 @@ impl Default for Settings {
88 89 flash: true,
89 90 close_to_tray: true,
90 91 do_not_disturb: false,
92 mute_in_calls: false,
91 93 ringtone: Ringtone::Default,
92 94 }
93 95 }
@@ -201,6 +203,7 @@ pub fn decide(settings: &Settings, incoming: &Incoming, environment: Environment
201 203 || environment.system_quiet
202 204 || environment.own_do_not_disturb
203 205 || settings.do_not_disturb
206 || (settings.mute_in_calls && environment.in_call)
204 207 || (incoming.muted && !incoming.mentions_me)
205 208 || (settings.mentions_only && !incoming.mentions_me && !incoming.is_direct());
206 209 if suppressed {
@@ -392,6 +395,20 @@ mod tests {
392 395 );
393 396 }
394 397
398 #[test]
399 fn mute_in_calls_drops_the_toast_only_while_in_a_call() {
400 let settings = Settings {
401 mute_in_calls: true,
402 ..Default::default()
403 };
404 let in_call = Environment {
405 in_call: true,
406 ..Default::default()
407 };
408 assert_eq!(decide(&settings, &group(), in_call), SILENT);
409 assert!(decide(&settings, &group(), Environment::default()).toast);
410 }
411
395 412 #[test]
396 413 fn muted_chat_only_notifies_for_mentions() {
397 414 let mut muted = group();
@@ -75,6 +75,7 @@ pub struct Settings {
75 pub flash: bool,
75 pub flash: bool,
76 pub close_to_tray: bool,
76 pub close_to_tray: bool,
77 pub do_not_disturb: bool,
77 pub do_not_disturb: bool,
78 pub mute_in_calls: bool,
78 pub ringtone: Ringtone,
79 pub ringtone: Ringtone,
79}
80}
80
81
@@ -88,6 +89,7 @@ impl Default for Settings {
88 flash: true,
89 flash: true,
89 close_to_tray: true,
90 close_to_tray: true,
90 do_not_disturb: false,
91 do_not_disturb: false,
92 mute_in_calls: false,
91 ringtone: Ringtone::Default,
93 ringtone: Ringtone::Default,
92 }
94 }
93 }
95 }
@@ -201,6 +203,7 @@ pub fn decide(settings: &Settings, incoming: &Incoming, environment: Environment
201 || environment.system_quiet
203 || environment.system_quiet
202 || environment.own_do_not_disturb
204 || environment.own_do_not_disturb
203 || settings.do_not_disturb
205 || settings.do_not_disturb
206 || (settings.mute_in_calls && environment.in_call)
204 || (incoming.muted && !incoming.mentions_me)
207 || (incoming.muted && !incoming.mentions_me)
205 || (settings.mentions_only && !incoming.mentions_me && !incoming.is_direct());
208 || (settings.mentions_only && !incoming.mentions_me && !incoming.is_direct());
206 if suppressed {
209 if suppressed {
@@ -392,6 +395,20 @@ mod tests {
392 );
395 );
393 }
396 }
394
397
398 #[test]
399 fn mute_in_calls_drops_the_toast_only_while_in_a_call() {
400 let settings = Settings {
401 mute_in_calls: true,
402 ..Default::default()
403 };
404 let in_call = Environment {
405 in_call: true,
406 ..Default::default()
407 };
408 assert_eq!(decide(&settings, &group(), in_call), SILENT);
409 assert!(decide(&settings, &group(), Environment::default()).toast);
410 }
411
395 #[test]
412 #[test]
396 fn muted_chat_only_notifies_for_mentions() {
413 fn muted_chat_only_notifies_for_mentions() {
397 let mut muted = group();
414 let mut muted = group();
crates/app/src/notify/settings.rs +3 −0
@@ -27,6 +27,7 @@ fn serialize(settings: &Settings) -> String {
27 27 ("taskbar_flash", settings.flash.to_string()),
28 28 ("close_to_tray", settings.close_to_tray.to_string()),
29 29 ("do_not_disturb", settings.do_not_disturb.to_string()),
30 ("mute_in_calls", settings.mute_in_calls.to_string()),
30 31 ("ringtone", settings.ringtone.key().to_owned()),
31 32 ]
32 33 .iter()
@@ -50,6 +51,7 @@ fn parse(text: &str) -> Settings {
50 51 "taskbar_flash" => settings.flash = flag,
51 52 "close_to_tray" => settings.close_to_tray = flag,
52 53 "do_not_disturb" => settings.do_not_disturb = flag,
54 "mute_in_calls" => settings.mute_in_calls = flag,
53 55 "ringtone" => settings.ringtone = Ringtone::from_key(value).unwrap_or_default(),
54 56 _ => {}
55 57 }
@@ -71,6 +73,7 @@ mod tests {
71 73 flash: false,
72 74 close_to_tray: false,
73 75 do_not_disturb: true,
76 mute_in_calls: true,
74 77 ringtone: Ringtone::Chime,
75 78 };
76 79 assert_eq!(parse(&serialize(&settings)), settings);
@@ -27,6 +27,7 @@ fn serialize(settings: &Settings) -> String {
27 ("taskbar_flash", settings.flash.to_string()),
27 ("taskbar_flash", settings.flash.to_string()),
28 ("close_to_tray", settings.close_to_tray.to_string()),
28 ("close_to_tray", settings.close_to_tray.to_string()),
29 ("do_not_disturb", settings.do_not_disturb.to_string()),
29 ("do_not_disturb", settings.do_not_disturb.to_string()),
30 ("mute_in_calls", settings.mute_in_calls.to_string()),
30 ("ringtone", settings.ringtone.key().to_owned()),
31 ("ringtone", settings.ringtone.key().to_owned()),
31 ]
32 ]
32 .iter()
33 .iter()
@@ -50,6 +51,7 @@ fn parse(text: &str) -> Settings {
50 "taskbar_flash" => settings.flash = flag,
51 "taskbar_flash" => settings.flash = flag,
51 "close_to_tray" => settings.close_to_tray = flag,
52 "close_to_tray" => settings.close_to_tray = flag,
52 "do_not_disturb" => settings.do_not_disturb = flag,
53 "do_not_disturb" => settings.do_not_disturb = flag,
54 "mute_in_calls" => settings.mute_in_calls = flag,
53 "ringtone" => settings.ringtone = Ringtone::from_key(value).unwrap_or_default(),
55 "ringtone" => settings.ringtone = Ringtone::from_key(value).unwrap_or_default(),
54 _ => {}
56 _ => {}
55 }
57 }
@@ -71,6 +73,7 @@ mod tests {
71 flash: false,
73 flash: false,
72 close_to_tray: false,
74 close_to_tray: false,
73 do_not_disturb: true,
75 do_not_disturb: true,
76 mute_in_calls: true,
74 ringtone: Ringtone::Chime,
77 ringtone: Ringtone::Chime,
75 };
78 };
76 assert_eq!(parse(&serialize(&settings)), settings);
79 assert_eq!(parse(&serialize(&settings)), settings);
crates/app/src/notify/settings_view.rs +72 −2
@@ -1,7 +1,7 @@
1 1 use std::time::{Duration, Instant};
2 2
3 3 use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4 use calling::{DeviceChoice, DeviceEntry, camera_entries};
4 use calling::{DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries};
5 5 use gpui_kit::assets::IconName;
6 6 use gpui_kit::component::{
7 7 button::Button,
@@ -9,6 +9,7 @@ use gpui_kit::component::{
9 9 menu::{DropdownMenu as _, PopupMenuItem},
10 10 v_flex,
11 11 };
12 use gpui_kit::base::Disableable as _;
12 13 use gpui_kit::prelude::FluentBuilder as _;
13 14 use gpui_kit::*;
14 15
@@ -67,7 +68,7 @@ struct Row {
67 68 field: Accessor,
68 69 }
69 70
70 const ROWS: [Row; 5] = [
71 const ROWS: [Row; 6] = [
71 72 Row {
72 73 title: "Sound",
73 74 detail: "Messages and mentions",
@@ -88,6 +89,11 @@ const ROWS: [Row; 5] = [
88 89 detail: "On new messages, until you open the window",
89 90 field: |settings| &mut settings.flash,
90 91 },
92 Row {
93 title: "Mute notifications during calls and meetings",
94 detail: "No message toasts while a call is active",
95 field: |settings| &mut settings.mute_in_calls,
96 },
91 97 Row {
92 98 title: "Minimize to tray on close",
93 99 detail: "The title bar X hides the window",
@@ -248,6 +254,12 @@ impl SettingsView {
248 254 cx.notify();
249 255 }
250 256
257 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
258 let app = self.center.read(cx).app().clone();
259 app.update(cx, |state, cx| state.set_call_mic(settings, cx));
260 cx.notify();
261 }
262
251 263 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
252 264 self.background = pick.clone();
253 265 let app = self.center.read(cx).app().clone();
@@ -422,6 +434,9 @@ impl SettingsView {
422 434 .find(|(pick, _)| *pick == self.background)
423 435 .map_or("None".to_owned(), |(_, label)| label.clone());
424 436 let current_background = self.background.clone();
437 let mic = self.center.read(cx).app().read(cx).call_mic;
438 let noise_view = view.clone();
439 let music_view = view.clone();
425 440 let image = self.preview.image(Instant::now());
426 441 let status = if self.preview_blocked {
427 442 CAMERA_IN_USE.to_owned()
@@ -485,6 +500,61 @@ impl SettingsView {
485 500 })
486 501 }),
487 502 ))
503 .child(control_row(
504 "Noise suppression",
505 if mic.music_mode {
506 "Off while music mode is on"
507 } else {
508 "Echo, hum and background noise"
509 },
510 Button::new("noise-suppression-select")
511 .outline()
512 .w(px(SELECT_WIDTH))
513 .label(mic.noise_suppression.label())
514 .icon(IconName::ChevronDown)
515 .disabled(mic.music_mode)
516 .dropdown_menu(move |menu, _, _| {
517 NoiseSuppression::ALL.iter().fold(menu, |menu, level| {
518 let (view, level) = (noise_view.clone(), *level);
519 menu.item(
520 PopupMenuItem::new(level.label())
521 .checked(level == mic.noise_suppression)
522 .on_click(move |_, _, cx| {
523 view.update(cx, |view, cx| {
524 view.set_mic(
525 MicSettings {
526 noise_suppression: level,
527 ..mic
528 },
529 cx,
530 )
531 })
532 }),
533 )
534 })
535 }),
536 ))
537 .child(
538 control_row(
539 "Music mode",
540 "Keeps echo cancellation, turns off the rest",
541 switch(mic.music_mode),
542 )
543 .id("music-mode-row")
544 .cursor_pointer()
545 .hover(|row| row.bg(theme::row_hover()))
546 .on_click(move |_, _, cx| {
547 music_view.update(cx, |view, cx| {
548 view.set_mic(
549 MicSettings {
550 music_mode: !mic.music_mode,
551 ..mic
552 },
553 cx,
554 )
555 })
556 }),
557 )
488 558 .child(
489 559 v_flex()
490 560 .w_full()
@@ -1,7 +1,7 @@
1use std::time::{Duration, Instant};
1use std::time::{Duration, Instant};
2
2
3use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
3use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4use calling::{DeviceChoice, DeviceEntry, camera_entries};
4use calling::{DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries};
5use gpui_kit::assets::IconName;
5use gpui_kit::assets::IconName;
6use gpui_kit::component::{
6use gpui_kit::component::{
7 button::Button,
7 button::Button,
@@ -9,6 +9,7 @@ use gpui_kit::component::{
9 menu::{DropdownMenu as _, PopupMenuItem},
9 menu::{DropdownMenu as _, PopupMenuItem},
10 v_flex,
10 v_flex,
11};
11};
12use gpui_kit::base::Disableable as _;
12use gpui_kit::prelude::FluentBuilder as _;
13use gpui_kit::prelude::FluentBuilder as _;
13use gpui_kit::*;
14use gpui_kit::*;
14
15
@@ -67,7 +68,7 @@ struct Row {
67 field: Accessor,
68 field: Accessor,
68}
69}
69
70
70const ROWS: [Row; 5] = [
71const ROWS: [Row; 6] = [
71 Row {
72 Row {
72 title: "Sound",
73 title: "Sound",
73 detail: "Messages and mentions",
74 detail: "Messages and mentions",
@@ -88,6 +89,11 @@ const ROWS: [Row; 5] = [
88 detail: "On new messages, until you open the window",
89 detail: "On new messages, until you open the window",
89 field: |settings| &mut settings.flash,
90 field: |settings| &mut settings.flash,
90 },
91 },
92 Row {
93 title: "Mute notifications during calls and meetings",
94 detail: "No message toasts while a call is active",
95 field: |settings| &mut settings.mute_in_calls,
96 },
91 Row {
97 Row {
92 title: "Minimize to tray on close",
98 title: "Minimize to tray on close",
93 detail: "The title bar X hides the window",
99 detail: "The title bar X hides the window",
@@ -248,6 +254,12 @@ impl SettingsView {
248 cx.notify();
254 cx.notify();
249 }
255 }
250
256
257 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
258 let app = self.center.read(cx).app().clone();
259 app.update(cx, |state, cx| state.set_call_mic(settings, cx));
260 cx.notify();
261 }
262
251 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
263 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
252 self.background = pick.clone();
264 self.background = pick.clone();
253 let app = self.center.read(cx).app().clone();
265 let app = self.center.read(cx).app().clone();
@@ -422,6 +434,9 @@ impl SettingsView {
422 .find(|(pick, _)| *pick == self.background)
434 .find(|(pick, _)| *pick == self.background)
423 .map_or("None".to_owned(), |(_, label)| label.clone());
435 .map_or("None".to_owned(), |(_, label)| label.clone());
424 let current_background = self.background.clone();
436 let current_background = self.background.clone();
437 let mic = self.center.read(cx).app().read(cx).call_mic;
438 let noise_view = view.clone();
439 let music_view = view.clone();
425 let image = self.preview.image(Instant::now());
440 let image = self.preview.image(Instant::now());
426 let status = if self.preview_blocked {
441 let status = if self.preview_blocked {
427 CAMERA_IN_USE.to_owned()
442 CAMERA_IN_USE.to_owned()
@@ -485,6 +500,61 @@ impl SettingsView {
485 })
500 })
486 }),
501 }),
487 ))
502 ))
503 .child(control_row(
504 "Noise suppression",
505 if mic.music_mode {
506 "Off while music mode is on"
507 } else {
508 "Echo, hum and background noise"
509 },
510 Button::new("noise-suppression-select")
511 .outline()
512 .w(px(SELECT_WIDTH))
513 .label(mic.noise_suppression.label())
514 .icon(IconName::ChevronDown)
515 .disabled(mic.music_mode)
516 .dropdown_menu(move |menu, _, _| {
517 NoiseSuppression::ALL.iter().fold(menu, |menu, level| {
518 let (view, level) = (noise_view.clone(), *level);
519 menu.item(
520 PopupMenuItem::new(level.label())
521 .checked(level == mic.noise_suppression)
522 .on_click(move |_, _, cx| {
523 view.update(cx, |view, cx| {
524 view.set_mic(
525 MicSettings {
526 noise_suppression: level,
527 ..mic
528 },
529 cx,
530 )
531 })
532 }),
533 )
534 })
535 }),
536 ))
537 .child(
538 control_row(
539 "Music mode",
540 "Keeps echo cancellation, turns off the rest",
541 switch(mic.music_mode),
542 )
543 .id("music-mode-row")
544 .cursor_pointer()
545 .hover(|row| row.bg(theme::row_hover()))
546 .on_click(move |_, _, cx| {
547 music_view.update(cx, |view, cx| {
548 view.set_mic(
549 MicSettings {
550 music_mode: !mic.music_mode,
551 ..mic
552 },
553 cx,
554 )
555 })
556 }),
557 )
488 .child(
558 .child(
489 v_flex()
559 v_flex()
490 .w_full()
560 .w_full()
crates/app/src/views/call_view.rs +88 −7
@@ -1,7 +1,7 @@
1 1 use std::sync::Arc;
2 2 use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
3 3
4 use calling::{DeviceEntry, Reaction, VideoKey};
4 use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, VideoKey};
5 5 use gpui_kit::assets::IconName;
6 6 use gpui_kit::component::{
7 7 button::{Button, ButtonVariants as _},
@@ -32,7 +32,7 @@ use crate::app_state::AppState;
32 32 use crate::call::REACTION_SHOWN;
33 33 use crate::call::TileSize;
34 34 use crate::call::{
35 CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
35 ActiveCall, CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
36 36 tile_size,
37 37 };
38 38 use crate::rows::reaction_glyph as chat_reaction_glyph;
@@ -72,6 +72,10 @@ const REACTION_RISE: f32 = 24.;
72 72 const REACTION_FADE_FROM: f32 = 0.75;
73 73 const REACTION_CELL: f32 = 40.;
74 74 const SHARE_SOUND_LABEL: &str = "Include computer sound";
75 const NOISE_SUPPRESSION_LABEL: &str = "Noise suppression";
76 const MUSIC_MODE_LABEL: &str = "Music mode";
77 const PUSH_TO_TALK_HINT: &str = "Unmuted - release Ctrl+Space to mute";
78 const PUSH_TO_TALK_TOP: f32 = 12.;
75 79
76 80 pub fn reaction_glyph(reaction: Reaction) -> String {
77 81 match reaction {
@@ -449,6 +453,54 @@ fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
449 453 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
450 454 }
451 455
456 fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
457 let app = app.clone();
458 PopupMenuItem::element(move |_, _| {
459 h_flex()
460 .id("call-music-mode-row")
461 .w_full()
462 .gap(px(16.))
463 .items_center()
464 .justify_between()
465 .child(MUSIC_MODE_LABEL)
466 .child(Switch::new("call-music-mode").checked(mic.music_mode))
467 })
468 .on_click(move |_, _, cx| {
469 app.update(cx, |state, cx| {
470 let settings = MicSettings {
471 music_mode: !mic.music_mode,
472 ..state.call_mic
473 };
474 state.set_call_mic(settings, cx)
475 })
476 })
477 }
478
479 fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {
480 call.push_to_talk.is_held().then(|| {
481 div()
482 .id("call-push-to-talk")
483 .absolute()
484 .top(px(HEADER_HEIGHT + PUSH_TO_TALK_TOP))
485 .left_0()
486 .right_0()
487 .flex()
488 .justify_center()
489 .child(
490 div()
491 .debug_selector(|| "call/push-to-talk".into())
492 .px(px(12.))
493 .py(px(6.))
494 .rounded_full()
495 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
496 .text_color(theme::white())
497 .text_size(px(13.))
498 .child(PUSH_TO_TALK_HINT),
499 )
500 .into_any_element()
501 })
502 }
503
452 504 fn share_items(
453 505 popup: PopupMenu,
454 506 app: &Entity<AppState>,
@@ -773,7 +825,12 @@ pub(super) fn device_items(
773 825 .collect()
774 826 }
775 827
776 fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
828 fn devices_menu(
829 popup: PopupMenu,
830 app: &Entity<AppState>,
831 model: &CallModel,
832 mic: MicSettings,
833 ) -> PopupMenu {
777 834 let input_app = app.clone();
778 835 let output_app = app.clone();
779 836 let inputs = device_items(
@@ -800,19 +857,42 @@ fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) ->
800 857 popup = popup.item(item);
801 858 }
802 859 }
803 popup = popup.separator().item(PopupMenuItem::label("Speaker"));
860 popup = popup
861 .separator()
862 .item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL));
863 for level in NoiseSuppression::ALL {
864 let level_app = app.clone();
865 popup = popup.item(
866 PopupMenuItem::new(level.label())
867 .checked(level == mic.noise_suppression)
868 .disabled(mic.music_mode)
869 .on_click(move |_, _, cx| {
870 level_app.update(cx, |state, cx| {
871 let settings = MicSettings {
872 noise_suppression: level,
873 ..state.call_mic
874 };
875 state.set_call_mic(settings, cx)
876 })
877 }),
878 );
879 }
880 popup = popup
881 .item(music_mode_item(app, mic))
882 .separator()
883 .item(PopupMenuItem::label("Speaker"));
804 884 for item in outputs {
805 885 popup = popup.item(item);
806 886 }
807 887 popup
808 888 }
809 889
810 fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
890 fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {
811 891 let app = app.clone();
812 892 let model = model.clone();
813 893 chevron_button("call-mic-menu", "call-mic-menu-face")
814 894 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
815 devices_menu(popup, &app, &model)
895 devices_menu(popup, &app, &model, mic)
816 896 })
817 897 }
818 898
@@ -1083,7 +1163,7 @@ pub fn render_call_view(
1083 1163 .rounded_full()
1084 1164 .bg(theme::surface_raised())
1085 1165 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1086 .child(mic_menu_button(app, model)),
1166 .child(mic_menu_button(app, model, state.call_mic)),
1087 1167 )
1088 1168 .child(
1089 1169 h_flex()
@@ -1148,6 +1228,7 @@ pub fn render_call_view(
1148 1228 .child(controls)
1149 1229 .children(captions_overlay(model, now))
1150 1230 .children(captions_hint_chip(model))
1231 .children(push_to_talk_chip(call))
1151 1232 .children(state.transfer_picker.clone())
1152 1233 .children(consent_overlay(app, model));
1153 1234 Some(
@@ -1,7 +1,7 @@
1use std::sync::Arc;
1use std::sync::Arc;
2use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
2use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
3
3
4use calling::{DeviceEntry, Reaction, VideoKey};
4use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, VideoKey};
5use gpui_kit::assets::IconName;
5use gpui_kit::assets::IconName;
6use gpui_kit::component::{
6use gpui_kit::component::{
7 button::{Button, ButtonVariants as _},
7 button::{Button, ButtonVariants as _},
@@ -32,7 +32,7 @@ use crate::app_state::AppState;
32use crate::call::REACTION_SHOWN;
32use crate::call::REACTION_SHOWN;
33use crate::call::TileSize;
33use crate::call::TileSize;
34use crate::call::{
34use crate::call::{
35 CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
35 ActiveCall, CHAT_OPEN_TILES, CallKind, CallModel, GridLayout, MAX_TILES, Tile, TileState, grid_layout,
36 tile_size,
36 tile_size,
37};
37};
38use crate::rows::reaction_glyph as chat_reaction_glyph;
38use crate::rows::reaction_glyph as chat_reaction_glyph;
@@ -72,6 +72,10 @@ const REACTION_RISE: f32 = 24.;
72const REACTION_FADE_FROM: f32 = 0.75;
72const REACTION_FADE_FROM: f32 = 0.75;
73const REACTION_CELL: f32 = 40.;
73const REACTION_CELL: f32 = 40.;
74const SHARE_SOUND_LABEL: &str = "Include computer sound";
74const SHARE_SOUND_LABEL: &str = "Include computer sound";
75const NOISE_SUPPRESSION_LABEL: &str = "Noise suppression";
76const MUSIC_MODE_LABEL: &str = "Music mode";
77const PUSH_TO_TALK_HINT: &str = "Unmuted - release Ctrl+Space to mute";
78const PUSH_TO_TALK_TOP: f32 = 12.;
75
79
76pub fn reaction_glyph(reaction: Reaction) -> String {
80pub fn reaction_glyph(reaction: Reaction) -> String {
77 match reaction {
81 match reaction {
@@ -449,6 +453,54 @@ fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
449 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
453 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
450}
454}
451
455
456fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
457 let app = app.clone();
458 PopupMenuItem::element(move |_, _| {
459 h_flex()
460 .id("call-music-mode-row")
461 .w_full()
462 .gap(px(16.))
463 .items_center()
464 .justify_between()
465 .child(MUSIC_MODE_LABEL)
466 .child(Switch::new("call-music-mode").checked(mic.music_mode))
467 })
468 .on_click(move |_, _, cx| {
469 app.update(cx, |state, cx| {
470 let settings = MicSettings {
471 music_mode: !mic.music_mode,
472 ..state.call_mic
473 };
474 state.set_call_mic(settings, cx)
475 })
476 })
477}
478
479fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {
480 call.push_to_talk.is_held().then(|| {
481 div()
482 .id("call-push-to-talk")
483 .absolute()
484 .top(px(HEADER_HEIGHT + PUSH_TO_TALK_TOP))
485 .left_0()
486 .right_0()
487 .flex()
488 .justify_center()
489 .child(
490 div()
491 .debug_selector(|| "call/push-to-talk".into())
492 .px(px(12.))
493 .py(px(6.))
494 .rounded_full()
495 .bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
496 .text_color(theme::white())
497 .text_size(px(13.))
498 .child(PUSH_TO_TALK_HINT),
499 )
500 .into_any_element()
501 })
502}
503
452fn share_items(
504fn share_items(
453 popup: PopupMenu,
505 popup: PopupMenu,
454 app: &Entity<AppState>,
506 app: &Entity<AppState>,
@@ -773,7 +825,12 @@ pub(super) fn device_items(
773 .collect()
825 .collect()
774}
826}
775
827
776fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
828fn devices_menu(
829 popup: PopupMenu,
830 app: &Entity<AppState>,
831 model: &CallModel,
832 mic: MicSettings,
833) -> PopupMenu {
777 let input_app = app.clone();
834 let input_app = app.clone();
778 let output_app = app.clone();
835 let output_app = app.clone();
779 let inputs = device_items(
836 let inputs = device_items(
@@ -800,19 +857,42 @@ fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) ->
800 popup = popup.item(item);
857 popup = popup.item(item);
801 }
858 }
802 }
859 }
803 popup = popup.separator().item(PopupMenuItem::label("Speaker"));
860 popup = popup
861 .separator()
862 .item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL));
863 for level in NoiseSuppression::ALL {
864 let level_app = app.clone();
865 popup = popup.item(
866 PopupMenuItem::new(level.label())
867 .checked(level == mic.noise_suppression)
868 .disabled(mic.music_mode)
869 .on_click(move |_, _, cx| {
870 level_app.update(cx, |state, cx| {
871 let settings = MicSettings {
872 noise_suppression: level,
873 ..state.call_mic
874 };
875 state.set_call_mic(settings, cx)
876 })
877 }),
878 );
879 }
880 popup = popup
881 .item(music_mode_item(app, mic))
882 .separator()
883 .item(PopupMenuItem::label("Speaker"));
804 for item in outputs {
884 for item in outputs {
805 popup = popup.item(item);
885 popup = popup.item(item);
806 }
886 }
807 popup
887 popup
808}
888}
809
889
810fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
890fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {
811 let app = app.clone();
891 let app = app.clone();
812 let model = model.clone();
892 let model = model.clone();
813 chevron_button("call-mic-menu", "call-mic-menu-face")
893 chevron_button("call-mic-menu", "call-mic-menu-face")
814 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
894 .dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
815 devices_menu(popup, &app, &model)
895 devices_menu(popup, &app, &model, mic)
816 })
896 })
817}
897}
818
898
@@ -1083,7 +1163,7 @@ pub fn render_call_view(
1083 .rounded_full()
1163 .rounded_full()
1084 .bg(theme::surface_raised())
1164 .bg(theme::surface_raised())
1085 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1165 .child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1086 .child(mic_menu_button(app, model)),
1166 .child(mic_menu_button(app, model, state.call_mic)),
1087 )
1167 )
1088 .child(
1168 .child(
1089 h_flex()
1169 h_flex()
@@ -1148,6 +1228,7 @@ pub fn render_call_view(
1148 .child(controls)
1228 .child(controls)
1149 .children(captions_overlay(model, now))
1229 .children(captions_overlay(model, now))
1150 .children(captions_hint_chip(model))
1230 .children(captions_hint_chip(model))
1231 .children(push_to_talk_chip(call))
1151 .children(state.transfer_picker.clone())
1232 .children(state.transfer_picker.clone())
1152 .children(consent_overlay(app, model));
1233 .children(consent_overlay(app, model));
1153 Some(
1234 Some(
crates/app/src/views/shell.rs +22 −2
@@ -16,8 +16,8 @@ use super::rail::RailView;
16 16 use super::saved_panel::{SavedPanel, SavedPanelEvent};
17 17 use super::shortcuts::{
18 18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
19 OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts,
20 ToggleCallCamera, ToggleCallShare,
19 OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, PushToTalk, Scope,
20 ShowShortcuts, ToggleCallCamera, ToggleCallShare,
21 21 };
22 22 use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
23 23 use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
@@ -47,6 +47,7 @@ pub fn bind_keys(cx: &mut App) {
47 47 Scope::Global,
48 48 Scope::OutsideComposer,
49 49 Scope::GlobalOverTextFields,
50 Scope::OutsideTextFields,
50 51 ],
51 52 );
52 53 }
@@ -212,6 +213,9 @@ impl AppShell {
212 213 if window.is_window_active() {
213 214 this.state
214 215 .update(cx, |state, cx| state.refresh_calendar(cx));
216 } else {
217 this.state
218 .update(cx, |state, cx| state.release_push_to_talk(cx));
215 219 }
216 220 });
217 221 let closing = notifications.clone();
@@ -715,6 +719,22 @@ impl Render for AppShell {
715 719 this.state
716 720 .update(cx, |state, cx| state.toggle_call_mute(cx));
717 721 }))
722 .on_action(cx.listener(|this, _: &PushToTalk, _, cx| {
723 this.state
724 .update(cx, |state, cx| state.press_push_to_talk(cx));
725 }))
726 .on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| {
727 if event.keystroke.key == "space" {
728 this.state
729 .update(cx, |state, cx| state.release_push_to_talk(cx));
730 }
731 }))
732 .on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, _, cx| {
733 if !event.modifiers.control {
734 this.state
735 .update(cx, |state, cx| state.release_push_to_talk(cx));
736 }
737 }))
718 738 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
719 739 this.toggle_shortcuts_dialog(window, cx);
720 740 }))
@@ -16,8 +16,8 @@ use super::rail::RailView;
16use super::saved_panel::{SavedPanel, SavedPanelEvent};
16use super::saved_panel::{SavedPanel, SavedPanelEvent};
17use super::shortcuts::{
17use super::shortcuts::{
18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
18 AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,
19 OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts,
19 OpenChannelsTab, OpenChatsTab, OpenSaved, PreviousConversation, PushToTalk, Scope,
20 ToggleCallCamera, ToggleCallShare,
20 ShowShortcuts, ToggleCallCamera, ToggleCallShare,
21};
21};
22use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
22use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
23use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
23use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
@@ -47,6 +47,7 @@ pub fn bind_keys(cx: &mut App) {
47 Scope::Global,
47 Scope::Global,
48 Scope::OutsideComposer,
48 Scope::OutsideComposer,
49 Scope::GlobalOverTextFields,
49 Scope::GlobalOverTextFields,
50 Scope::OutsideTextFields,
50 ],
51 ],
51 );
52 );
52}
53}
@@ -212,6 +213,9 @@ impl AppShell {
212 if window.is_window_active() {
213 if window.is_window_active() {
213 this.state
214 this.state
214 .update(cx, |state, cx| state.refresh_calendar(cx));
215 .update(cx, |state, cx| state.refresh_calendar(cx));
216 } else {
217 this.state
218 .update(cx, |state, cx| state.release_push_to_talk(cx));
215 }
219 }
216 });
220 });
217 let closing = notifications.clone();
221 let closing = notifications.clone();
@@ -715,6 +719,22 @@ impl Render for AppShell {
715 this.state
719 this.state
716 .update(cx, |state, cx| state.toggle_call_mute(cx));
720 .update(cx, |state, cx| state.toggle_call_mute(cx));
717 }))
721 }))
722 .on_action(cx.listener(|this, _: &PushToTalk, _, cx| {
723 this.state
724 .update(cx, |state, cx| state.press_push_to_talk(cx));
725 }))
726 .on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| {
727 if event.keystroke.key == "space" {
728 this.state
729 .update(cx, |state, cx| state.release_push_to_talk(cx));
730 }
731 }))
732 .on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, _, cx| {
733 if !event.modifiers.control {
734 this.state
735 .update(cx, |state, cx| state.release_push_to_talk(cx));
736 }
737 }))
718 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
738 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
719 this.toggle_shortcuts_dialog(window, cx);
739 this.toggle_shortcuts_dialog(window, cx);
720 }))
740 }))
crates/app/src/views/shortcuts.rs +18 −1
@@ -9,6 +9,7 @@ use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};
9 9
10 10 const TEXT_FIELD_CONTEXT: &str = "Input";
11 11 const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
12 const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";
12 13
13 14 actions!(
14 15 teams,
@@ -25,6 +26,7 @@ actions!(
25 26 HangUpCall,
26 27 ToggleCallCamera,
27 28 ToggleCallShare,
29 PushToTalk,
28 30 ShowShortcuts
29 31 ]
30 32 );
@@ -60,6 +62,7 @@ pub enum Scope {
60 62 Global,
61 63 OutsideComposer,
62 64 GlobalOverTextFields,
65 OutsideTextFields,
63 66 Composer,
64 67 }
65 68
@@ -113,6 +116,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
113 116 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
114 117 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
115 118 shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
119 shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk),
116 120 ];
117 121
118 122 impl Shortcut {
@@ -132,6 +136,7 @@ impl Shortcut {
132 136 Scope::Global => &[None],
133 137 Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],
134 138 Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],
139 Scope::OutsideTextFields => &[Some(OUTSIDE_TEXT_FIELD_CONTEXT)],
135 140 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
136 141 };
137 142 let mut keys = vec![self.keys];
@@ -159,6 +164,7 @@ pub fn display_keys(keys: &str) -> String {
159 164 "up" => "Up".to_owned(),
160 165 "down" => "Down".to_owned(),
161 166 "enter" => "Enter".to_owned(),
167 "space" => "Space".to_owned(),
162 168 other => other.to_uppercase(),
163 169 })
164 170 .collect::<Vec<_>>()
@@ -219,7 +225,7 @@ mod tests {
219 225 for shortcut in SHORTCUTS {
220 226 let contexts: &[&str] = match shortcut.scope {
221 227 Scope::Global | Scope::OutsideComposer => &["AppShell"],
222 Scope::GlobalOverTextFields => &["AppShell"],
228 Scope::GlobalOverTextFields | Scope::OutsideTextFields => &["AppShell"],
223 229 Scope::Composer => &["AppShell", "Composer"],
224 230 };
225 231 assert_eq!(
@@ -249,6 +255,16 @@ mod tests {
249 255 }
250 256 }
251 257
258 #[gpui_kit::test]
259 fn push_to_talk_is_not_bound_while_typing_in_a_text_field(cx: &mut TestAppContext) {
260 registered(cx);
261 assert!(bound_action(cx, "ctrl-space", &["AppShell"]).is_some());
262 assert_eq!(
263 bound_action(cx, "ctrl-space", &["AppShell", "Composer", "Input"]),
264 None
265 );
266 }
267
252 268 #[gpui_kit::test]
253 269 fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {
254 270 registered(cx);
@@ -290,5 +306,6 @@ mod tests {
290 306 assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");
291 307 assert_eq!(display_keys("alt-up"), "Alt+Up");
292 308 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
309 assert_eq!(display_keys("ctrl-space"), "Ctrl+Space");
293 310 }
294 311 }
@@ -9,6 +9,7 @@ use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};
9
9
10const TEXT_FIELD_CONTEXT: &str = "Input";
10const TEXT_FIELD_CONTEXT: &str = "Input";
11const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
11const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
12const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";
12
13
13actions!(
14actions!(
14 teams,
15 teams,
@@ -25,6 +26,7 @@ actions!(
25 HangUpCall,
26 HangUpCall,
26 ToggleCallCamera,
27 ToggleCallCamera,
27 ToggleCallShare,
28 ToggleCallShare,
29 PushToTalk,
28 ShowShortcuts
30 ShowShortcuts
29 ]
31 ]
30);
32);
@@ -60,6 +62,7 @@ pub enum Scope {
60 Global,
62 Global,
61 OutsideComposer,
63 OutsideComposer,
62 GlobalOverTextFields,
64 GlobalOverTextFields,
65 OutsideTextFields,
63 Composer,
66 Composer,
64}
67}
65
68
@@ -113,6 +116,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
113 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
116 shortcut!(Calls, GlobalOverTextFields, "Mute or unmute", "ctrl-shift-m", None, ToggleCallMute),
114 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
117 shortcut!(Calls, GlobalOverTextFields, "Turn camera on or off", "ctrl-shift-o", Some("cmd-shift-o"), ToggleCallCamera),
115 shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
118 shortcut!(Calls, GlobalOverTextFields, "Start or stop sharing the screen", "ctrl-shift-e", Some("cmd-shift-e"), ToggleCallShare),
119 shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk),
116];
120];
117
121
118impl Shortcut {
122impl Shortcut {
@@ -132,6 +136,7 @@ impl Shortcut {
132 Scope::Global => &[None],
136 Scope::Global => &[None],
133 Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],
137 Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],
134 Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],
138 Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],
139 Scope::OutsideTextFields => &[Some(OUTSIDE_TEXT_FIELD_CONTEXT)],
135 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
140 Scope::Composer => &[Some(COMPOSER_CONTEXT)],
136 };
141 };
137 let mut keys = vec![self.keys];
142 let mut keys = vec![self.keys];
@@ -159,6 +164,7 @@ pub fn display_keys(keys: &str) -> String {
159 "up" => "Up".to_owned(),
164 "up" => "Up".to_owned(),
160 "down" => "Down".to_owned(),
165 "down" => "Down".to_owned(),
161 "enter" => "Enter".to_owned(),
166 "enter" => "Enter".to_owned(),
167 "space" => "Space".to_owned(),
162 other => other.to_uppercase(),
168 other => other.to_uppercase(),
163 })
169 })
164 .collect::<Vec<_>>()
170 .collect::<Vec<_>>()
@@ -219,7 +225,7 @@ mod tests {
219 for shortcut in SHORTCUTS {
225 for shortcut in SHORTCUTS {
220 let contexts: &[&str] = match shortcut.scope {
226 let contexts: &[&str] = match shortcut.scope {
221 Scope::Global | Scope::OutsideComposer => &["AppShell"],
227 Scope::Global | Scope::OutsideComposer => &["AppShell"],
222 Scope::GlobalOverTextFields => &["AppShell"],
228 Scope::GlobalOverTextFields | Scope::OutsideTextFields => &["AppShell"],
223 Scope::Composer => &["AppShell", "Composer"],
229 Scope::Composer => &["AppShell", "Composer"],
224 };
230 };
225 assert_eq!(
231 assert_eq!(
@@ -249,6 +255,16 @@ mod tests {
249 }
255 }
250 }
256 }
251
257
258 #[gpui_kit::test]
259 fn push_to_talk_is_not_bound_while_typing_in_a_text_field(cx: &mut TestAppContext) {
260 registered(cx);
261 assert!(bound_action(cx, "ctrl-space", &["AppShell"]).is_some());
262 assert_eq!(
263 bound_action(cx, "ctrl-space", &["AppShell", "Composer", "Input"]),
264 None
265 );
266 }
267
252 #[gpui_kit::test]
268 #[gpui_kit::test]
253 fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {
269 fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {
254 registered(cx);
270 registered(cx);
@@ -290,5 +306,6 @@ mod tests {
290 assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");
306 assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");
291 assert_eq!(display_keys("alt-up"), "Alt+Up");
307 assert_eq!(display_keys("alt-up"), "Alt+Up");
292 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
308 assert_eq!(display_keys("ctrl-."), "Ctrl+.");
309 assert_eq!(display_keys("ctrl-space"), "Ctrl+Space");
293 }
310 }
294}
311}
crates/calling/src/call.rs +73 −48
@@ -34,9 +34,9 @@ use crate::end::EndKind;
34 34 use crate::engine::{CallEngine, EngineConfig, Inner};
35 35 use crate::error::{Error, Result};
36 36 use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};
37 use crate::mic_processing::MicSettings;
37 38 use crate::mute::{MuteCommand, MuteEffect};
38 39 use crate::push::CallNotification;
39 use crate::share_audio::ShareAudio;
40 40 use crate::relay::{DEFAULT_RELAY_HOST, RelayGrant, fetch_relay_grant};
41 41 use crate::renegotiation::{MediaAction, MediaNegotiator, MediaPath};
42 42 use crate::organizer::Target;
@@ -47,6 +47,7 @@ use crate::signaling::{
47 47 Answer, Attached, Callee, Conversation, Invitation, InviteTarget, LeaveReason, MeetingTarget, Participant, Signaling,
48 48 TenantRouting, chat_thread_id, find_echo_bot_thread, escalation_answer_body, renegotiation_body,
49 49 };
50 use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};
50 51 use crate::state::{CallSignal, CallState};
51 52 use crate::timeline::{Timeline, TimelineEntry};
52 53 use crate::transfer::{TransferEvent, TransferTarget};
@@ -806,8 +807,9 @@ async fn drive(
806 807 if sending_camera {
807 808 control.send(CallUpdate::Camera(true));
808 809 }
809 let mut share_audio: Option<ShareAudio> = None;
810 let mut software_audio: Option<SoftwareAudio> = None;
810 811 let mut share_sound_wanted = false;
812 let mut mic_settings = MicSettings::default();
811 813 let mut remote_audio: Option<RtcAudioTrack> = None;
812 814 let mut own_hand: Option<String> = None;
813 815 let mut depacketizer = Depacketizer::default();
@@ -1060,7 +1062,7 @@ async fn drive(
1060 1062 consent_pending = required;
1061 1063 control.send(CallUpdate::ConsentRequired(required));
1062 1064 if required {
1063 withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, &mut local_video, control);
1065 withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, &mut local_video, control);
1064 1066 }
1065 1067 }
1066 1068 if !main_meeting_sent
@@ -1179,7 +1181,10 @@ async fn drive(
1179 1181 }
1180 1182 PeerEvent::Track(remote_track) => {
1181 1183 timeline.record("remote audio track", "receiving");
1182 remote_audio = Some(remote_track.clone());
1184 let had_far_end = remote_audio.replace(remote_track.clone()).is_some();
1185 if !had_far_end && software_audio.is_some() {
1186 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);
1187 }
1183 1188 if options.record_remote {
1184 1189 tokio::spawn(record_track(remote_track, recording.clone(), options.tone_hz));
1185 1190 }
@@ -1208,7 +1213,7 @@ async fn drive(
1208 1213 timeline.record("escalation", "new peer connection connected, old one dropped");
1209 1214 let old = std::mem::replace(&mut current, pending.session);
1210 1215 old.peer.close();
1211 if let Some(audio) = &share_audio
1216 if let Some(audio) = &software_audio
1212 1217 && let Err(error) = swap_audio_track(&current.peer, &audio.track)
1213 1218 {
1214 1219 timeline.record("computer sound not carried over", error.to_string());
@@ -1245,7 +1250,7 @@ async fn drive(
1245 1250 if consent_pending && !mute.target(muted) {
1246 1251 control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));
1247 1252 } else {
1248 muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, control);
1253 muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, control);
1249 1254 }
1250 1255 }
1251 1256 Some(CallCommand::SelectInput(choice)) => {
@@ -1254,6 +1259,13 @@ async fn drive(
1254 1259 }
1255 1260 input = choice;
1256 1261 control.send(CallUpdate::Selected { input: input.clone(), output: output.clone() });
1262 if software_audio.is_some() {
1263 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);
1264 }
1265 }
1266 Some(CallCommand::SetMicSettings(settings)) => {
1267 mic_settings = settings;
1268 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1257 1269 }
1258 1270 Some(CallCommand::SelectOutput(choice)) => {
1259 1271 if live.audio.as_ref().is_some_and(AudioSetup::uses_devices) {
@@ -1328,9 +1340,7 @@ async fn drive(
1328 1340 Ok(()) => {
1329 1341 control.send(CallUpdate::LocalShare(Some(source.label())));
1330 1342 tell_media_descriptions(&remote, &media_links, MediaDescription::share(true), &mut media_description_request, timeline);
1331 if share_sound_wanted && share_audio.is_none() {
1332 share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), &current.peer, control, timeline);
1333 }
1343 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1334 1344 }
1335 1345 Err(error) => control.send(CallUpdate::Notice(format!("Sharing could not start: {error}"))),
1336 1346 }
@@ -1339,20 +1349,14 @@ async fn drive(
1339 1349 Some(CallCommand::StopShare) => {
1340 1350 if local_video.sharing() {
1341 1351 local_video.stop_share();
1342 release_share_sound(&current.peer, &track, &mut share_audio, control, timeline);
1352 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1343 1353 control.send(CallUpdate::LocalShare(None));
1344 1354 tell_media_descriptions(&remote, &media_links, MediaDescription::share(false), &mut media_description_request, timeline);
1345 1355 }
1346 1356 }
1347 1357 Some(CallCommand::SetShareSound(on)) => {
1348 1358 share_sound_wanted = on;
1349 if local_video.sharing() {
1350 if on && share_audio.is_none() {
1351 share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), &current.peer, control, timeline);
1352 } else if !on {
1353 release_share_sound(&current.peer, &track, &mut share_audio, control, timeline);
1354 }
1355 }
1359 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1356 1360 }
1357 1361 Some(CallCommand::RefreshShareSources) => refresh_share_sources(control.updates(), options.video),
1358 1362 Some(CallCommand::SetHand(true)) => match remote.signaling.raise_hand(&remote.conversation, &remote.participant).await {
@@ -1561,7 +1565,7 @@ async fn drive(
1561 1565 {
1562 1566 control.send(CallUpdate::BlurTiming(average_ms));
1563 1567 }
1564 let local_level = if muted && share_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };
1568 let local_level = if muted && software_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };
1565 1569 control.send(CallUpdate::Levels { local: local_level, remote: snapshot.audio_level as f32 });
1566 1570 if snapshot.selected_pair.is_some() {
1567 1571 report.selected_pair = snapshot.selected_pair.clone();
@@ -1929,12 +1933,12 @@ fn undo_change(change: Change, local_video: &mut LocalVideo, control: &CallContr
1929 1933 fn withhold_media(
1930 1934 muted: &mut bool,
1931 1935 audio: &AudioSetup,
1932 share_audio: Option<&ShareAudio>,
1936 software_audio: Option<&SoftwareAudio>,
1933 1937 remote: &RemoteCall,
1934 1938 local_video: &mut LocalVideo,
1935 1939 control: &CallControl,
1936 1940 ) {
1937 *muted = apply_mute(MuteCommand::Mute, *muted, audio, share_audio, remote, control);
1941 *muted = apply_mute(MuteCommand::Mute, *muted, audio, software_audio, remote, control);
1938 1942 if local_video.camera_on() {
1939 1943 local_video.stop_camera();
1940 1944 control.send(CallUpdate::Camera(false));
@@ -2093,14 +2097,14 @@ fn apply_mute(
2093 2097 command: MuteCommand,
2094 2098 currently_muted: bool,
2095 2099 audio: &AudioSetup,
2096 share_audio: Option<&ShareAudio>,
2100 software_audio: Option<&SoftwareAudio>,
2097 2101 remote: &RemoteCall,
2098 2102 control: &CallControl,
2099 2103 ) -> bool {
2100 2104 let effect = MuteEffect::for_muted(command.target(currently_muted));
2101 2105 audio.track.set_enabled(effect.track_enabled);
2102 if let Some(share_audio) = share_audio {
2103 share_audio.set_microphone_muted(effect.muted);
2106 if let Some(software_audio) = software_audio {
2107 software_audio.set_microphone_muted(effect.muted);
2104 2108 }
2105 2109 control.send(CallUpdate::Muted(effect.muted));
2106 2110 let remote = remote.clone();
@@ -2124,52 +2128,73 @@ fn swap_audio_track(peer: &PeerConnection, track: &RtcAudioTrack) -> Result<()>
2124 2128 .map_err(|error| Error::Webrtc(error.to_string()))
2125 2129 }
2126 2130
2131 fn software_wanted(
2132 mic_settings: MicSettings,
2133 share_sound_wanted: bool,
2134 local_video: &LocalVideo,
2135 audio: Option<&AudioSetup>,
2136 ) -> Option<SoftwareAudioPlan> {
2137 let sharing_sound = share_sound_wanted && local_video.sharing();
2138 SoftwareAudioPlan::wanted(mic_settings, sharing_sound, audio.is_some_and(AudioSetup::uses_devices))
2139 }
2140
2127 2141 #[allow(clippy::too_many_arguments)]
2128 fn engage_share_sound(
2142 fn sync_software_audio(
2129 2143 factory: &PeerConnectionFactory,
2130 2144 options: &CallOptions,
2131 2145 input: &DeviceChoice,
2132 2146 muted: bool,
2133 2147 remote_audio: Option<RtcAudioTrack>,
2134 2148 peer: &PeerConnection,
2149 device_track: &RtcAudioTrack,
2150 wanted: Option<SoftwareAudioPlan>,
2151 restart: bool,
2152 software_audio: &mut Option<SoftwareAudio>,
2135 2153 control: &CallControl,
2136 2154 timeline: &Timeline,
2137 ) -> Option<ShareAudio> {
2138 let started = ShareAudio::start(factory, options.audio, options.tone_hz, input, muted, remote_audio)
2155 ) {
2156 let running = software_audio.as_ref().map(|audio| audio.plan);
2157 if running == wanted && !restart {
2158 return;
2159 }
2160 *software_audio = None;
2161 let was_sharing_sound = running.is_some_and(|plan| plan.computer_sound);
2162 let Some(plan) = wanted else {
2163 if let Err(error) = swap_audio_track(peer, device_track) {
2164 timeline.record("microphone track not restored", error.to_string());
2165 }
2166 control.send(CallUpdate::ShareSound(false));
2167 return;
2168 };
2169 let started = SoftwareAudio::start(factory, options.audio, options.tone_hz, input, plan, muted, remote_audio)
2139 2170 .and_then(|audio| swap_audio_track(peer, &audio.track).map(|()| audio));
2140 2171 match started {
2141 2172 Ok(audio) => {
2142 timeline.record("computer sound", format!("{:?}, own playback excluded: {}", audio.loopback, audio.loopback.excludes_own_playback()));
2173 timeline.record("software audio", format!("{:?}, computer sound {:?}", plan.processing, audio.loopback));
2143 2174 if let Some(warning) = &audio.warning {
2144 2175 timeline.record("computer sound warning", warning.clone());
2145 2176 }
2146 control.send(CallUpdate::ShareSound(true));
2147 Some(audio)
2177 control.send(CallUpdate::ShareSound(plan.computer_sound));
2178 *software_audio = Some(audio);
2148 2179 }
2149 2180 Err(error) => {
2150 timeline.record("computer sound failed", error.to_string());
2151 control.send(CallUpdate::Notice("Computer sound could not start, sharing without it".into()));
2152 None
2181 timeline.record("software audio failed", error.to_string());
2182 if let Err(error) = swap_audio_track(peer, device_track) {
2183 timeline.record("microphone track not restored", error.to_string());
2184 }
2185 if was_sharing_sound || plan.computer_sound {
2186 control.send(CallUpdate::ShareSound(false));
2187 }
2188 let notice = if plan.computer_sound {
2189 "Computer sound could not start, sharing without it"
2190 } else {
2191 "Microphone processing could not start, using the standard microphone"
2192 };
2193 control.send(CallUpdate::Notice(notice.into()));
2153 2194 }
2154 2195 }
2155 2196 }
2156 2197
2157 fn release_share_sound(
2158 peer: &PeerConnection,
2159 device_track: &RtcAudioTrack,
2160 share_audio: &mut Option<ShareAudio>,
2161 control: &CallControl,
2162 timeline: &Timeline,
2163 ) {
2164 if share_audio.take().is_none() {
2165 return;
2166 }
2167 if let Err(error) = swap_audio_track(peer, device_track) {
2168 timeline.record("microphone track not restored", error.to_string());
2169 }
2170 control.send(CallUpdate::ShareSound(false));
2171 }
2172
2173 2198 async fn tear_down(mut live: Live, inner: &Inner, timeline: &Timeline, report: &mut CallReport, cancelled: bool) {
2174 2199 if let Some(audio) = &live.audio {
2175 2200 audio.track.set_enabled(false);
@@ -34,9 +34,9 @@ use crate::end::EndKind;
34use crate::engine::{CallEngine, EngineConfig, Inner};
34use crate::engine::{CallEngine, EngineConfig, Inner};
35use crate::error::{Error, Result};
35use crate::error::{Error, Result};
36use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};
36use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};
37use crate::mic_processing::MicSettings;
37use crate::mute::{MuteCommand, MuteEffect};
38use crate::mute::{MuteCommand, MuteEffect};
38use crate::push::CallNotification;
39use crate::push::CallNotification;
39use crate::share_audio::ShareAudio;
40use crate::relay::{DEFAULT_RELAY_HOST, RelayGrant, fetch_relay_grant};
40use crate::relay::{DEFAULT_RELAY_HOST, RelayGrant, fetch_relay_grant};
41use crate::renegotiation::{MediaAction, MediaNegotiator, MediaPath};
41use crate::renegotiation::{MediaAction, MediaNegotiator, MediaPath};
42use crate::organizer::Target;
42use crate::organizer::Target;
@@ -47,6 +47,7 @@ use crate::signaling::{
47 Answer, Attached, Callee, Conversation, Invitation, InviteTarget, LeaveReason, MeetingTarget, Participant, Signaling,
47 Answer, Attached, Callee, Conversation, Invitation, InviteTarget, LeaveReason, MeetingTarget, Participant, Signaling,
48 TenantRouting, chat_thread_id, find_echo_bot_thread, escalation_answer_body, renegotiation_body,
48 TenantRouting, chat_thread_id, find_echo_bot_thread, escalation_answer_body, renegotiation_body,
49};
49};
50use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};
50use crate::state::{CallSignal, CallState};
51use crate::state::{CallSignal, CallState};
51use crate::timeline::{Timeline, TimelineEntry};
52use crate::timeline::{Timeline, TimelineEntry};
52use crate::transfer::{TransferEvent, TransferTarget};
53use crate::transfer::{TransferEvent, TransferTarget};
@@ -806,8 +807,9 @@ async fn drive(
806 if sending_camera {
807 if sending_camera {
807 control.send(CallUpdate::Camera(true));
808 control.send(CallUpdate::Camera(true));
808 }
809 }
809 let mut share_audio: Option<ShareAudio> = None;
810 let mut software_audio: Option<SoftwareAudio> = None;
810 let mut share_sound_wanted = false;
811 let mut share_sound_wanted = false;
812 let mut mic_settings = MicSettings::default();
811 let mut remote_audio: Option<RtcAudioTrack> = None;
813 let mut remote_audio: Option<RtcAudioTrack> = None;
812 let mut own_hand: Option<String> = None;
814 let mut own_hand: Option<String> = None;
813 let mut depacketizer = Depacketizer::default();
815 let mut depacketizer = Depacketizer::default();
@@ -1060,7 +1062,7 @@ async fn drive(
1060 consent_pending = required;
1062 consent_pending = required;
1061 control.send(CallUpdate::ConsentRequired(required));
1063 control.send(CallUpdate::ConsentRequired(required));
1062 if required {
1064 if required {
1063 withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, &mut local_video, control);
1065 withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, &mut local_video, control);
1064 }
1066 }
1065 }
1067 }
1066 if !main_meeting_sent
1068 if !main_meeting_sent
@@ -1179,7 +1181,10 @@ async fn drive(
1179 }
1181 }
1180 PeerEvent::Track(remote_track) => {
1182 PeerEvent::Track(remote_track) => {
1181 timeline.record("remote audio track", "receiving");
1183 timeline.record("remote audio track", "receiving");
1182 remote_audio = Some(remote_track.clone());
1184 let had_far_end = remote_audio.replace(remote_track.clone()).is_some();
1185 if !had_far_end && software_audio.is_some() {
1186 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);
1187 }
1183 if options.record_remote {
1188 if options.record_remote {
1184 tokio::spawn(record_track(remote_track, recording.clone(), options.tone_hz));
1189 tokio::spawn(record_track(remote_track, recording.clone(), options.tone_hz));
1185 }
1190 }
@@ -1208,7 +1213,7 @@ async fn drive(
1208 timeline.record("escalation", "new peer connection connected, old one dropped");
1213 timeline.record("escalation", "new peer connection connected, old one dropped");
1209 let old = std::mem::replace(&mut current, pending.session);
1214 let old = std::mem::replace(&mut current, pending.session);
1210 old.peer.close();
1215 old.peer.close();
1211 if let Some(audio) = &share_audio
1216 if let Some(audio) = &software_audio
1212 && let Err(error) = swap_audio_track(&current.peer, &audio.track)
1217 && let Err(error) = swap_audio_track(&current.peer, &audio.track)
1213 {
1218 {
1214 timeline.record("computer sound not carried over", error.to_string());
1219 timeline.record("computer sound not carried over", error.to_string());
@@ -1245,7 +1250,7 @@ async fn drive(
1245 if consent_pending && !mute.target(muted) {
1250 if consent_pending && !mute.target(muted) {
1246 control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));
1251 control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));
1247 } else {
1252 } else {
1248 muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, control);
1253 muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, control);
1249 }
1254 }
1250 }
1255 }
1251 Some(CallCommand::SelectInput(choice)) => {
1256 Some(CallCommand::SelectInput(choice)) => {
@@ -1254,6 +1259,13 @@ async fn drive(
1254 }
1259 }
1255 input = choice;
1260 input = choice;
1256 control.send(CallUpdate::Selected { input: input.clone(), output: output.clone() });
1261 control.send(CallUpdate::Selected { input: input.clone(), output: output.clone() });
1262 if software_audio.is_some() {
1263 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);
1264 }
1265 }
1266 Some(CallCommand::SetMicSettings(settings)) => {
1267 mic_settings = settings;
1268 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1257 }
1269 }
1258 Some(CallCommand::SelectOutput(choice)) => {
1270 Some(CallCommand::SelectOutput(choice)) => {
1259 if live.audio.as_ref().is_some_and(AudioSetup::uses_devices) {
1271 if live.audio.as_ref().is_some_and(AudioSetup::uses_devices) {
@@ -1328,9 +1340,7 @@ async fn drive(
1328 Ok(()) => {
1340 Ok(()) => {
1329 control.send(CallUpdate::LocalShare(Some(source.label())));
1341 control.send(CallUpdate::LocalShare(Some(source.label())));
1330 tell_media_descriptions(&remote, &media_links, MediaDescription::share(true), &mut media_description_request, timeline);
1342 tell_media_descriptions(&remote, &media_links, MediaDescription::share(true), &mut media_description_request, timeline);
1331 if share_sound_wanted && share_audio.is_none() {
1343 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1332 share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), &current.peer, control, timeline);
1333 }
1334 }
1344 }
1335 Err(error) => control.send(CallUpdate::Notice(format!("Sharing could not start: {error}"))),
1345 Err(error) => control.send(CallUpdate::Notice(format!("Sharing could not start: {error}"))),
1336 }
1346 }
@@ -1339,20 +1349,14 @@ async fn drive(
1339 Some(CallCommand::StopShare) => {
1349 Some(CallCommand::StopShare) => {
1340 if local_video.sharing() {
1350 if local_video.sharing() {
1341 local_video.stop_share();
1351 local_video.stop_share();
1342 release_share_sound(&current.peer, &track, &mut share_audio, control, timeline);
1352 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1343 control.send(CallUpdate::LocalShare(None));
1353 control.send(CallUpdate::LocalShare(None));
1344 tell_media_descriptions(&remote, &media_links, MediaDescription::share(false), &mut media_description_request, timeline);
1354 tell_media_descriptions(&remote, &media_links, MediaDescription::share(false), &mut media_description_request, timeline);
1345 }
1355 }
1346 }
1356 }
1347 Some(CallCommand::SetShareSound(on)) => {
1357 Some(CallCommand::SetShareSound(on)) => {
1348 share_sound_wanted = on;
1358 share_sound_wanted = on;
1349 if local_video.sharing() {
1359 sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), &current.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1350 if on && share_audio.is_none() {
1351 share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), &current.peer, control, timeline);
1352 } else if !on {
1353 release_share_sound(&current.peer, &track, &mut share_audio, control, timeline);
1354 }
1355 }
1356 }
1360 }
1357 Some(CallCommand::RefreshShareSources) => refresh_share_sources(control.updates(), options.video),
1361 Some(CallCommand::RefreshShareSources) => refresh_share_sources(control.updates(), options.video),
1358 Some(CallCommand::SetHand(true)) => match remote.signaling.raise_hand(&remote.conversation, &remote.participant).await {
1362 Some(CallCommand::SetHand(true)) => match remote.signaling.raise_hand(&remote.conversation, &remote.participant).await {
@@ -1561,7 +1565,7 @@ async fn drive(
1561 {
1565 {
1562 control.send(CallUpdate::BlurTiming(average_ms));
1566 control.send(CallUpdate::BlurTiming(average_ms));
1563 }
1567 }
1564 let local_level = if muted && share_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };
1568 let local_level = if muted && software_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };
1565 control.send(CallUpdate::Levels { local: local_level, remote: snapshot.audio_level as f32 });
1569 control.send(CallUpdate::Levels { local: local_level, remote: snapshot.audio_level as f32 });
1566 if snapshot.selected_pair.is_some() {
1570 if snapshot.selected_pair.is_some() {
1567 report.selected_pair = snapshot.selected_pair.clone();
1571 report.selected_pair = snapshot.selected_pair.clone();
@@ -1929,12 +1933,12 @@ fn undo_change(change: Change, local_video: &mut LocalVideo, control: &CallContr
1929fn withhold_media(
1933fn withhold_media(
1930 muted: &mut bool,
1934 muted: &mut bool,
1931 audio: &AudioSetup,
1935 audio: &AudioSetup,
1932 share_audio: Option<&ShareAudio>,
1936 software_audio: Option<&SoftwareAudio>,
1933 remote: &RemoteCall,
1937 remote: &RemoteCall,
1934 local_video: &mut LocalVideo,
1938 local_video: &mut LocalVideo,
1935 control: &CallControl,
1939 control: &CallControl,
1936) {
1940) {
1937 *muted = apply_mute(MuteCommand::Mute, *muted, audio, share_audio, remote, control);
1941 *muted = apply_mute(MuteCommand::Mute, *muted, audio, software_audio, remote, control);
1938 if local_video.camera_on() {
1942 if local_video.camera_on() {
1939 local_video.stop_camera();
1943 local_video.stop_camera();
1940 control.send(CallUpdate::Camera(false));
1944 control.send(CallUpdate::Camera(false));
@@ -2093,14 +2097,14 @@ fn apply_mute(
2093 command: MuteCommand,
2097 command: MuteCommand,
2094 currently_muted: bool,
2098 currently_muted: bool,
2095 audio: &AudioSetup,
2099 audio: &AudioSetup,
2096 share_audio: Option<&ShareAudio>,
2100 software_audio: Option<&SoftwareAudio>,
2097 remote: &RemoteCall,
2101 remote: &RemoteCall,
2098 control: &CallControl,
2102 control: &CallControl,
2099) -> bool {
2103) -> bool {
2100 let effect = MuteEffect::for_muted(command.target(currently_muted));
2104 let effect = MuteEffect::for_muted(command.target(currently_muted));
2101 audio.track.set_enabled(effect.track_enabled);
2105 audio.track.set_enabled(effect.track_enabled);
2102 if let Some(share_audio) = share_audio {
2106 if let Some(software_audio) = software_audio {
2103 share_audio.set_microphone_muted(effect.muted);
2107 software_audio.set_microphone_muted(effect.muted);
2104 }
2108 }
2105 control.send(CallUpdate::Muted(effect.muted));
2109 control.send(CallUpdate::Muted(effect.muted));
2106 let remote = remote.clone();
2110 let remote = remote.clone();
@@ -2124,52 +2128,73 @@ fn swap_audio_track(peer: &PeerConnection, track: &RtcAudioTrack) -> Result<()>
2124 .map_err(|error| Error::Webrtc(error.to_string()))
2128 .map_err(|error| Error::Webrtc(error.to_string()))
2125}
2129}
2126
2130
2131fn software_wanted(
2132 mic_settings: MicSettings,
2133 share_sound_wanted: bool,
2134 local_video: &LocalVideo,
2135 audio: Option<&AudioSetup>,
2136) -> Option<SoftwareAudioPlan> {
2137 let sharing_sound = share_sound_wanted && local_video.sharing();
2138 SoftwareAudioPlan::wanted(mic_settings, sharing_sound, audio.is_some_and(AudioSetup::uses_devices))
2139}
2140
2127#[allow(clippy::too_many_arguments)]
2141#[allow(clippy::too_many_arguments)]
2128fn engage_share_sound(
2142fn sync_software_audio(
2129 factory: &PeerConnectionFactory,
2143 factory: &PeerConnectionFactory,
2130 options: &CallOptions,
2144 options: &CallOptions,
2131 input: &DeviceChoice,
2145 input: &DeviceChoice,
2132 muted: bool,
2146 muted: bool,
2133 remote_audio: Option<RtcAudioTrack>,
2147 remote_audio: Option<RtcAudioTrack>,
2134 peer: &PeerConnection,
2148 peer: &PeerConnection,
2149 device_track: &RtcAudioTrack,
2150 wanted: Option<SoftwareAudioPlan>,
2151 restart: bool,
2152 software_audio: &mut Option<SoftwareAudio>,
2135 control: &CallControl,
2153 control: &CallControl,
2136 timeline: &Timeline,
2154 timeline: &Timeline,
2137) -> Option<ShareAudio> {
2155) {
2138 let started = ShareAudio::start(factory, options.audio, options.tone_hz, input, muted, remote_audio)
2156 let running = software_audio.as_ref().map(|audio| audio.plan);
2157 if running == wanted && !restart {
2158 return;
2159 }
2160 *software_audio = None;
2161 let was_sharing_sound = running.is_some_and(|plan| plan.computer_sound);
2162 let Some(plan) = wanted else {
2163 if let Err(error) = swap_audio_track(peer, device_track) {
2164 timeline.record("microphone track not restored", error.to_string());
2165 }
2166 control.send(CallUpdate::ShareSound(false));
2167 return;
2168 };
2169 let started = SoftwareAudio::start(factory, options.audio, options.tone_hz, input, plan, muted, remote_audio)
2139 .and_then(|audio| swap_audio_track(peer, &audio.track).map(|()| audio));
2170 .and_then(|audio| swap_audio_track(peer, &audio.track).map(|()| audio));
2140 match started {
2171 match started {
2141 Ok(audio) => {
2172 Ok(audio) => {
2142 timeline.record("computer sound", format!("{:?}, own playback excluded: {}", audio.loopback, audio.loopback.excludes_own_playback()));
2173 timeline.record("software audio", format!("{:?}, computer sound {:?}", plan.processing, audio.loopback));
2143 if let Some(warning) = &audio.warning {
2174 if let Some(warning) = &audio.warning {
2144 timeline.record("computer sound warning", warning.clone());
2175 timeline.record("computer sound warning", warning.clone());
2145 }
2176 }
2146 control.send(CallUpdate::ShareSound(true));
2177 control.send(CallUpdate::ShareSound(plan.computer_sound));
2147 Some(audio)
2178 *software_audio = Some(audio);
2148 }
2179 }
2149 Err(error) => {
2180 Err(error) => {
2150 timeline.record("computer sound failed", error.to_string());
2181 timeline.record("software audio failed", error.to_string());
2151 control.send(CallUpdate::Notice("Computer sound could not start, sharing without it".into()));
2182 if let Err(error) = swap_audio_track(peer, device_track) {
2152 None
2183 timeline.record("microphone track not restored", error.to_string());
2184 }
2185 if was_sharing_sound || plan.computer_sound {
2186 control.send(CallUpdate::ShareSound(false));
2187 }
2188 let notice = if plan.computer_sound {
2189 "Computer sound could not start, sharing without it"
2190 } else {
2191 "Microphone processing could not start, using the standard microphone"
2192 };
2193 control.send(CallUpdate::Notice(notice.into()));
2153 }
2194 }
2154 }
2195 }
2155}
2196}
2156
2197
2157fn release_share_sound(
2158 peer: &PeerConnection,
2159 device_track: &RtcAudioTrack,
2160 share_audio: &mut Option<ShareAudio>,
2161 control: &CallControl,
2162 timeline: &Timeline,
2163) {
2164 if share_audio.take().is_none() {
2165 return;
2166 }
2167 if let Err(error) = swap_audio_track(peer, device_track) {
2168 timeline.record("microphone track not restored", error.to_string());
2169 }
2170 control.send(CallUpdate::ShareSound(false));
2171}
2172
2173async fn tear_down(mut live: Live, inner: &Inner, timeline: &Timeline, report: &mut CallReport, cancelled: bool) {
2198async fn tear_down(mut live: Live, inner: &Inner, timeline: &Timeline, report: &mut CallReport, cancelled: bool) {
2174 if let Some(audio) = &live.audio {
2199 if let Some(audio) = &live.audio {
2175 audio.track.set_enabled(false);
2200 audio.track.set_enabled(false);
crates/calling/src/control.rs +2 −0
@@ -9,6 +9,7 @@ use crate::captions::{CaptionEntry, CaptionState};
9 9 use crate::devices::{DeviceChoice, DeviceLists};
10 10 use crate::error::{Error, Result};
11 11 use crate::hold::HoldState;
12 use crate::mic_processing::MicSettings;
12 13 use crate::mute::MuteCommand;
13 14 use crate::reaction::Reaction;
14 15 use crate::roster::RosterEntry;
@@ -24,6 +25,7 @@ pub enum CallCommand {
24 25 Mute(MuteCommand),
25 26 SelectInput(DeviceChoice),
26 27 SelectOutput(DeviceChoice),
28 SetMicSettings(MicSettings),
27 29 RefreshDevices,
28 30 SetCamera(bool),
29 31 SelectCamera(DeviceChoice),
@@ -9,6 +9,7 @@ use crate::captions::{CaptionEntry, CaptionState};
9use crate::devices::{DeviceChoice, DeviceLists};
9use crate::devices::{DeviceChoice, DeviceLists};
10use crate::error::{Error, Result};
10use crate::error::{Error, Result};
11use crate::hold::HoldState;
11use crate::hold::HoldState;
12use crate::mic_processing::MicSettings;
12use crate::mute::MuteCommand;
13use crate::mute::MuteCommand;
13use crate::reaction::Reaction;
14use crate::reaction::Reaction;
14use crate::roster::RosterEntry;
15use crate::roster::RosterEntry;
@@ -24,6 +25,7 @@ pub enum CallCommand {
24 Mute(MuteCommand),
25 Mute(MuteCommand),
25 SelectInput(DeviceChoice),
26 SelectInput(DeviceChoice),
26 SelectOutput(DeviceChoice),
27 SelectOutput(DeviceChoice),
28 SetMicSettings(MicSettings),
27 RefreshDevices,
29 RefreshDevices,
28 SetCamera(bool),
30 SetCamera(bool),
29 SelectCamera(DeviceChoice),
31 SelectCamera(DeviceChoice),
crates/calling/src/lib.rs +3 −1
@@ -20,6 +20,7 @@ pub mod level;
20 20 #[cfg(windows)]
21 21 mod loopback_windows;
22 22 pub mod meeting;
23 pub mod mic_processing;
23 24 pub mod mixer;
24 25 pub mod mute;
25 26 pub mod organizer;
@@ -33,8 +34,8 @@ pub mod ring;
33 34 pub mod roster;
34 35 pub mod screen;
35 36 pub mod sdp;
36 pub mod share_audio;
37 37 pub mod signaling;
38 pub mod software_audio;
38 39 pub mod sound_capture;
39 40 pub mod state;
40 41 pub mod timeline;
@@ -66,6 +67,7 @@ pub use signaling::{Callee, MeetingTarget};
66 67 pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};
67 68 pub use error::{Error, Result};
68 69 pub use level::SpeakingDetector;
70 pub use mic_processing::{ApmConfig, MicSettings, NoiseSuppression};
69 71 pub use mute::MuteCommand;
70 72 pub use state::{CallSignal, CallState, EndReason};
71 73 pub use camera::{CameraDevice, camera_entries};
@@ -20,6 +20,7 @@ pub mod level;
20#[cfg(windows)]
20#[cfg(windows)]
21mod loopback_windows;
21mod loopback_windows;
22pub mod meeting;
22pub mod meeting;
23pub mod mic_processing;
23pub mod mixer;
24pub mod mixer;
24pub mod mute;
25pub mod mute;
25pub mod organizer;
26pub mod organizer;
@@ -33,8 +34,8 @@ pub mod ring;
33pub mod roster;
34pub mod roster;
34pub mod screen;
35pub mod screen;
35pub mod sdp;
36pub mod sdp;
36pub mod share_audio;
37pub mod signaling;
37pub mod signaling;
38pub mod software_audio;
38pub mod sound_capture;
39pub mod sound_capture;
39pub mod state;
40pub mod state;
40pub mod timeline;
41pub mod timeline;
@@ -66,6 +67,7 @@ pub use signaling::{Callee, MeetingTarget};
66pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};
67pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};
67pub use error::{Error, Result};
68pub use error::{Error, Result};
68pub use level::SpeakingDetector;
69pub use level::SpeakingDetector;
70pub use mic_processing::{ApmConfig, MicSettings, NoiseSuppression};
69pub use mute::MuteCommand;
71pub use mute::MuteCommand;
70pub use state::{CallSignal, CallState, EndReason};
72pub use state::{CallSignal, CallState, EndReason};
71pub use camera::{CameraDevice, camera_entries};
73pub use camera::{CameraDevice, camera_entries};
crates/calling/src/mic_processing.rs added +113 −0
@@ -0,0 +1,113 @@
1 use libwebrtc::native::apm::AudioProcessingModule;
2
3 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
4 pub enum NoiseSuppression {
5 #[default]
6 Auto,
7 Off,
8 }
9
10 impl NoiseSuppression {
11 pub const ALL: [NoiseSuppression; 2] = [NoiseSuppression::Auto, NoiseSuppression::Off];
12
13 pub fn label(self) -> &'static str {
14 match self {
15 NoiseSuppression::Auto => "Auto",
16 NoiseSuppression::Off => "Off",
17 }
18 }
19
20 pub fn key(self) -> &'static str {
21 match self {
22 NoiseSuppression::Auto => "auto",
23 NoiseSuppression::Off => "off",
24 }
25 }
26
27 pub fn from_key(key: &str) -> Option<NoiseSuppression> {
28 NoiseSuppression::ALL.into_iter().find(|level| level.key() == key)
29 }
30 }
31
32 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
33 pub struct MicSettings {
34 pub noise_suppression: NoiseSuppression,
35 pub music_mode: bool,
36 }
37
38 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
39 pub struct ApmConfig {
40 pub echo_canceller: bool,
41 pub gain_controller: bool,
42 pub high_pass_filter: bool,
43 pub noise_suppression: bool,
44 }
45
46 impl ApmConfig {
47 pub fn is_passthrough(self) -> bool {
48 self == ApmConfig { echo_canceller: false, gain_controller: false, high_pass_filter: false, noise_suppression: false }
49 }
50
51 pub fn module(self) -> Option<AudioProcessingModule> {
52 (!self.is_passthrough()).then(|| {
53 AudioProcessingModule::new(self.echo_canceller, self.gain_controller, self.high_pass_filter, self.noise_suppression)
54 })
55 }
56 }
57
58 impl MicSettings {
59 pub fn apm_config(self) -> ApmConfig {
60 if self.music_mode {
61 return ApmConfig { echo_canceller: true, gain_controller: false, high_pass_filter: false, noise_suppression: false };
62 }
63 let on = self.noise_suppression == NoiseSuppression::Auto;
64 ApmConfig { echo_canceller: on, gain_controller: on, high_pass_filter: on, noise_suppression: on }
65 }
66
67 pub fn uses_device_track(self) -> bool {
68 self == MicSettings::default()
69 }
70 }
71
72 #[cfg(test)]
73 mod tests {
74 use super::*;
75
76 #[test]
77 fn auto_keeps_the_device_track_with_everything_on() {
78 let settings = MicSettings::default();
79 assert!(settings.uses_device_track());
80 assert_eq!(
81 settings.apm_config(),
82 ApmConfig { echo_canceller: true, gain_controller: true, high_pass_filter: true, noise_suppression: true }
83 );
84 }
85
86 #[test]
87 fn off_leaves_the_device_track_and_processes_nothing() {
88 let settings = MicSettings { noise_suppression: NoiseSuppression::Off, music_mode: false };
89 assert!(!settings.uses_device_track());
90 assert!(settings.apm_config().is_passthrough());
91 assert!(settings.apm_config().module().is_none());
92 }
93
94 #[test]
95 fn music_mode_keeps_only_echo_cancellation_whatever_the_noise_choice() {
96 for noise_suppression in NoiseSuppression::ALL {
97 let settings = MicSettings { noise_suppression, music_mode: true };
98 assert!(!settings.uses_device_track());
99 assert_eq!(
100 settings.apm_config(),
101 ApmConfig { echo_canceller: true, gain_controller: false, high_pass_filter: false, noise_suppression: false }
102 );
103 }
104 }
105
106 #[test]
107 fn noise_levels_round_trip_through_their_keys() {
108 for level in NoiseSuppression::ALL {
109 assert_eq!(NoiseSuppression::from_key(level.key()), Some(level));
110 }
111 assert_eq!(NoiseSuppression::from_key("high"), None);
112 }
113 }
@@ -0,0 +1,113 @@
1use libwebrtc::native::apm::AudioProcessingModule;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
4pub enum NoiseSuppression {
5 #[default]
6 Auto,
7 Off,
8}
9
10impl NoiseSuppression {
11 pub const ALL: [NoiseSuppression; 2] = [NoiseSuppression::Auto, NoiseSuppression::Off];
12
13 pub fn label(self) -> &'static str {
14 match self {
15 NoiseSuppression::Auto => "Auto",
16 NoiseSuppression::Off => "Off",
17 }
18 }
19
20 pub fn key(self) -> &'static str {
21 match self {
22 NoiseSuppression::Auto => "auto",
23 NoiseSuppression::Off => "off",
24 }
25 }
26
27 pub fn from_key(key: &str) -> Option<NoiseSuppression> {
28 NoiseSuppression::ALL.into_iter().find(|level| level.key() == key)
29 }
30}
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
33pub struct MicSettings {
34 pub noise_suppression: NoiseSuppression,
35 pub music_mode: bool,
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub struct ApmConfig {
40 pub echo_canceller: bool,
41 pub gain_controller: bool,
42 pub high_pass_filter: bool,
43 pub noise_suppression: bool,
44}
45
46impl ApmConfig {
47 pub fn is_passthrough(self) -> bool {
48 self == ApmConfig { echo_canceller: false, gain_controller: false, high_pass_filter: false, noise_suppression: false }
49 }
50
51 pub fn module(self) -> Option<AudioProcessingModule> {
52 (!self.is_passthrough()).then(|| {
53 AudioProcessingModule::new(self.echo_canceller, self.gain_controller, self.high_pass_filter, self.noise_suppression)
54 })
55 }
56}
57
58impl MicSettings {
59 pub fn apm_config(self) -> ApmConfig {
60 if self.music_mode {
61 return ApmConfig { echo_canceller: true, gain_controller: false, high_pass_filter: false, noise_suppression: false };
62 }
63 let on = self.noise_suppression == NoiseSuppression::Auto;
64 ApmConfig { echo_canceller: on, gain_controller: on, high_pass_filter: on, noise_suppression: on }
65 }
66
67 pub fn uses_device_track(self) -> bool {
68 self == MicSettings::default()
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn auto_keeps_the_device_track_with_everything_on() {
78 let settings = MicSettings::default();
79 assert!(settings.uses_device_track());
80 assert_eq!(
81 settings.apm_config(),
82 ApmConfig { echo_canceller: true, gain_controller: true, high_pass_filter: true, noise_suppression: true }
83 );
84 }
85
86 #[test]
87 fn off_leaves_the_device_track_and_processes_nothing() {
88 let settings = MicSettings { noise_suppression: NoiseSuppression::Off, music_mode: false };
89 assert!(!settings.uses_device_track());
90 assert!(settings.apm_config().is_passthrough());
91 assert!(settings.apm_config().module().is_none());
92 }
93
94 #[test]
95 fn music_mode_keeps_only_echo_cancellation_whatever_the_noise_choice() {
96 for noise_suppression in NoiseSuppression::ALL {
97 let settings = MicSettings { noise_suppression, music_mode: true };
98 assert!(!settings.uses_device_track());
99 assert_eq!(
100 settings.apm_config(),
101 ApmConfig { echo_canceller: true, gain_controller: false, high_pass_filter: false, noise_suppression: false }
102 );
103 }
104 }
105
106 #[test]
107 fn noise_levels_round_trip_through_their_keys() {
108 for level in NoiseSuppression::ALL {
109 assert_eq!(NoiseSuppression::from_key(level.key()), Some(level));
110 }
111 assert_eq!(NoiseSuppression::from_key("high"), None);
112 }
113}
crates/calling/src/share_audio.rs crates/calling/src/software_audio.rs renamed +70 −17
@@ -4,7 +4,6 @@ use std::time::{Duration, Instant};
4 4
5 5 use futures_util::StreamExt;
6 6 use libwebrtc::audio_source::native::NativeAudioSource;
7 use libwebrtc::native::apm::AudioProcessingModule;
8 7 use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;
9 8 use libwebrtc::audio_stream::native::NativeAudioStream;
10 9 use libwebrtc::prelude::*;
@@ -15,6 +14,7 @@ use crate::audio_io::AudioMode;
15 14 use crate::capture::Capture;
16 15 use crate::devices::DeviceChoice;
17 16 use crate::error::{Error, Result};
17 use crate::mic_processing::{ApmConfig, MicSettings};
18 18 use crate::mixer::mix_frames;
19 19 use crate::pcm::SampleQueue;
20 20 use crate::sound_capture::{LoopbackKind, start_loopback, start_microphone};
@@ -41,7 +41,14 @@ impl FrameSource {
41 41 }
42 42 }
43 43
44 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
45 pub struct SoftwareAudioPlan {
46 pub processing: ApmConfig,
47 pub computer_sound: bool,
48 }
49
44 50 struct Feeder {
51 processing: ApmConfig,
45 52 source: NativeAudioSource,
46 53 microphone: FrameSource,
47 54 computer: FrameSource,
@@ -53,7 +60,7 @@ struct Feeder {
53 60
54 61 impl Feeder {
55 62 fn run(mut self) {
56 let mut processing = AudioProcessingModule::new(true, false, true, true);
63 let mut processing = self.processing.module();
57 64 let mut due = Instant::now();
58 65 while self.running.load(Ordering::SeqCst) {
59 66 due += FRAME_PERIOD;
@@ -64,12 +71,12 @@ impl Feeder {
64 71 due = now;
65 72 }
66 73 let (mut far_end, has_far_end) = self.far_end.next_frame();
67 if has_far_end {
74 if has_far_end && let Some(processing) = processing.as_mut() {
68 75 let _ = processing.process_reverse_stream(&mut far_end, SAMPLE_RATE as i32, 1);
69 76 }
70 77 let muted = self.microphone_muted.load(Ordering::SeqCst);
71 78 let mut microphone = self.microphone.next_frame();
72 if !muted {
79 if !muted && let Some(processing) = processing.as_mut() {
73 80 let _ = processing.process_stream(&mut microphone, SAMPLE_RATE as i32, 1);
74 81 }
75 82 let computer = self.computer.next_frame();
@@ -86,10 +93,11 @@ impl Feeder {
86 93 }
87 94 }
88 95
89 /// Mic plus computer sound mixed into one track that replaces the device track while sharing.
90 pub struct ShareAudio {
96 /// Mic through our own processing, plus computer sound when planned, as one track that replaces the device track.
97 pub struct SoftwareAudio {
91 98 pub track: RtcAudioTrack,
92 pub loopback: LoopbackKind,
99 pub plan: SoftwareAudioPlan,
100 pub loopback: Option<LoopbackKind>,
93 101 pub warning: Option<String>,
94 102 microphone_muted: Arc<AtomicBool>,
95 103 running: Arc<AtomicBool>,
@@ -98,12 +106,22 @@ pub struct ShareAudio {
98 106 _captures: Vec<Capture>,
99 107 }
100 108
101 impl ShareAudio {
109 impl SoftwareAudioPlan {
110 pub fn wanted(mic: MicSettings, sharing_sound: bool, uses_devices: bool) -> Option<Self> {
111 (sharing_sound || (uses_devices && !mic.uses_device_track())).then(|| SoftwareAudioPlan {
112 processing: mic.apm_config(),
113 computer_sound: sharing_sound,
114 })
115 }
116 }
117
118 impl SoftwareAudio {
102 119 pub fn start(
103 120 factory: &PeerConnectionFactory,
104 121 mode: AudioMode,
105 122 tone_hz: f32,
106 123 input: &DeviceChoice,
124 plan: SoftwareAudioPlan,
107 125 microphone_muted: bool,
108 126 remote: Option<RtcAudioTrack>,
109 127 ) -> Result<Self> {
@@ -111,9 +129,14 @@ impl ShareAudio {
111 129 let mut warning = None;
112 130 let (microphone, computer, loopback) = if mode == AudioMode::Platform {
113 131 let computer_queue = SampleQueue::default();
114 let started = start_loopback(computer_queue.clone())?;
115 captures.push(started.capture);
116 warning = started.warning;
132 let (computer, loopback) = if plan.computer_sound {
133 let started = start_loopback(computer_queue.clone())?;
134 captures.push(started.capture);
135 warning = started.warning;
136 (FrameSource::Captured(computer_queue), Some(started.kind))
137 } else {
138 (FrameSource::Silence, None)
139 };
117 140 let microphone_queue = SampleQueue::default();
118 141 let microphone = match start_microphone(input, microphone_queue.clone()) {
119 142 Ok(capture) => {
@@ -125,14 +148,19 @@ impl ShareAudio {
125 148 FrameSource::Silence
126 149 }
127 150 };
128 (microphone, FrameSource::Captured(computer_queue), started.kind)
151 (microphone, computer, loopback)
129 152 } else {
130 153 let microphone = if mode == AudioMode::Tone {
131 154 FrameSource::Tone(SineGenerator::new(tone_hz, SYNTHETIC_AMPLITUDE))
132 155 } else {
133 156 FrameSource::Silence
134 157 };
135 (microphone, FrameSource::Tone(SineGenerator::new(SYSTEM_TONE_HZ, SYNTHETIC_AMPLITUDE)), LoopbackKind::Synthetic)
158 let computer = if plan.computer_sound {
159 FrameSource::Tone(SineGenerator::new(SYSTEM_TONE_HZ, SYNTHETIC_AMPLITUDE))
160 } else {
161 FrameSource::Silence
162 };
163 (microphone, computer, plan.computer_sound.then_some(LoopbackKind::Synthetic))
136 164 };
137 165 let source = NativeAudioSource::new(AudioSourceOptions::default(), SAMPLE_RATE, 1, SOURCE_QUEUE_MS);
138 166 let track = factory.create_audio_track("microphone", source.clone());
@@ -141,6 +169,7 @@ impl ShareAudio {
141 169 let microphone_muted = Arc::new(AtomicBool::new(microphone_muted));
142 170 let running = Arc::new(AtomicBool::new(true));
143 171 let feeder = Feeder {
172 processing: plan.processing,
144 173 source,
145 174 microphone,
146 175 computer,
@@ -153,8 +182,9 @@ impl ShareAudio {
153 182 .name("share-audio".into())
154 183 .spawn(move || feeder.run())
155 184 .map_err(|error| Error::Audio(format!("share audio thread: {error}")))?;
156 Ok(ShareAudio {
185 Ok(SoftwareAudio {
157 186 track,
187 plan,
158 188 loopback,
159 189 warning,
160 190 microphone_muted,
@@ -170,7 +200,7 @@ impl ShareAudio {
170 200 }
171 201 }
172 202
173 impl Drop for ShareAudio {
203 impl Drop for SoftwareAudio {
174 204 fn drop(&mut self) {
175 205 self.running.store(false, Ordering::SeqCst);
176 206 if let Some(task) = self.far_end_task.take() {
@@ -193,14 +223,37 @@ async fn feed_far_end(remote: RtcAudioTrack, queue: SampleQueue) {
193 223 mod tests {
194 224 use super::*;
195 225 use crate::devices::shared_factory;
226 use crate::mic_processing::NoiseSuppression;
196 227
197 228 #[tokio::test(flavor = "multi_thread")]
198 229 async fn synthetic_sources_start_and_stop_cleanly() {
199 let audio = ShareAudio::start(&shared_factory(), AudioMode::Tone, 440.0, &DeviceChoice::SystemDefault, true, None).unwrap();
200 assert_eq!(audio.loopback, LoopbackKind::Synthetic);
230 let plan = SoftwareAudioPlan { processing: MicSettings::default().apm_config(), computer_sound: true };
231 let audio = SoftwareAudio::start(&shared_factory(), AudioMode::Tone, 440.0, &DeviceChoice::SystemDefault, plan, true, None).unwrap();
232 assert_eq!(audio.loopback, Some(LoopbackKind::Synthetic));
201 233 assert!(audio.warning.is_none());
202 234 audio.set_microphone_muted(false);
203 235 tokio::time::sleep(Duration::from_millis(60)).await;
204 236 drop(audio);
205 237 }
238
239 #[test]
240 fn the_plan_follows_sharing_and_the_mic_choice() {
241 let auto = MicSettings::default();
242 let off = MicSettings { noise_suppression: NoiseSuppression::Off, music_mode: false };
243 assert_eq!(SoftwareAudioPlan::wanted(auto, false, true), None);
244 assert_eq!(SoftwareAudioPlan::wanted(off, false, false), None);
245 let mic_only = SoftwareAudioPlan::wanted(off, false, true).unwrap();
246 assert!(!mic_only.computer_sound && mic_only.processing.is_passthrough());
247 let sharing = SoftwareAudioPlan::wanted(auto, true, false).unwrap();
248 assert!(sharing.computer_sound && sharing.processing.echo_canceller);
249 }
250
251 #[tokio::test(flavor = "multi_thread")]
252 async fn a_microphone_only_plan_has_no_computer_sound() {
253 let plan = SoftwareAudioPlan { processing: MicSettings::default().apm_config(), computer_sound: false };
254 let audio = SoftwareAudio::start(&shared_factory(), AudioMode::Silence, 440.0, &DeviceChoice::SystemDefault, plan, false, None).unwrap();
255 assert_eq!(audio.loopback, None);
256 tokio::time::sleep(Duration::from_millis(60)).await;
257 drop(audio);
258 }
206 259 }
@@ -4,7 +4,6 @@ use std::time::{Duration, Instant};
4
4
5use futures_util::StreamExt;
5use futures_util::StreamExt;
6use libwebrtc::audio_source::native::NativeAudioSource;
6use libwebrtc::audio_source::native::NativeAudioSource;
7use libwebrtc::native::apm::AudioProcessingModule;
8use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;
7use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;
9use libwebrtc::audio_stream::native::NativeAudioStream;
8use libwebrtc::audio_stream::native::NativeAudioStream;
10use libwebrtc::prelude::*;
9use libwebrtc::prelude::*;
@@ -15,6 +14,7 @@ use crate::audio_io::AudioMode;
15use crate::capture::Capture;
14use crate::capture::Capture;
16use crate::devices::DeviceChoice;
15use crate::devices::DeviceChoice;
17use crate::error::{Error, Result};
16use crate::error::{Error, Result};
17use crate::mic_processing::{ApmConfig, MicSettings};
18use crate::mixer::mix_frames;
18use crate::mixer::mix_frames;
19use crate::pcm::SampleQueue;
19use crate::pcm::SampleQueue;
20use crate::sound_capture::{LoopbackKind, start_loopback, start_microphone};
20use crate::sound_capture::{LoopbackKind, start_loopback, start_microphone};
@@ -41,7 +41,14 @@ impl FrameSource {
41 }
41 }
42}
42}
43
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45pub struct SoftwareAudioPlan {
46 pub processing: ApmConfig,
47 pub computer_sound: bool,
48}
49
44struct Feeder {
50struct Feeder {
51 processing: ApmConfig,
45 source: NativeAudioSource,
52 source: NativeAudioSource,
46 microphone: FrameSource,
53 microphone: FrameSource,
47 computer: FrameSource,
54 computer: FrameSource,
@@ -53,7 +60,7 @@ struct Feeder {
53
60
54impl Feeder {
61impl Feeder {
55 fn run(mut self) {
62 fn run(mut self) {
56 let mut processing = AudioProcessingModule::new(true, false, true, true);
63 let mut processing = self.processing.module();
57 let mut due = Instant::now();
64 let mut due = Instant::now();
58 while self.running.load(Ordering::SeqCst) {
65 while self.running.load(Ordering::SeqCst) {
59 due += FRAME_PERIOD;
66 due += FRAME_PERIOD;
@@ -64,12 +71,12 @@ impl Feeder {
64 due = now;
71 due = now;
65 }
72 }
66 let (mut far_end, has_far_end) = self.far_end.next_frame();
73 let (mut far_end, has_far_end) = self.far_end.next_frame();
67 if has_far_end {
74 if has_far_end && let Some(processing) = processing.as_mut() {
68 let _ = processing.process_reverse_stream(&mut far_end, SAMPLE_RATE as i32, 1);
75 let _ = processing.process_reverse_stream(&mut far_end, SAMPLE_RATE as i32, 1);
69 }
76 }
70 let muted = self.microphone_muted.load(Ordering::SeqCst);
77 let muted = self.microphone_muted.load(Ordering::SeqCst);
71 let mut microphone = self.microphone.next_frame();
78 let mut microphone = self.microphone.next_frame();
72 if !muted {
79 if !muted && let Some(processing) = processing.as_mut() {
73 let _ = processing.process_stream(&mut microphone, SAMPLE_RATE as i32, 1);
80 let _ = processing.process_stream(&mut microphone, SAMPLE_RATE as i32, 1);
74 }
81 }
75 let computer = self.computer.next_frame();
82 let computer = self.computer.next_frame();
@@ -86,10 +93,11 @@ impl Feeder {
86 }
93 }
87}
94}
88
95
89/// Mic plus computer sound mixed into one track that replaces the device track while sharing.
96/// Mic through our own processing, plus computer sound when planned, as one track that replaces the device track.
90pub struct ShareAudio {
97pub struct SoftwareAudio {
91 pub track: RtcAudioTrack,
98 pub track: RtcAudioTrack,
92 pub loopback: LoopbackKind,
99 pub plan: SoftwareAudioPlan,
100 pub loopback: Option<LoopbackKind>,
93 pub warning: Option<String>,
101 pub warning: Option<String>,
94 microphone_muted: Arc<AtomicBool>,
102 microphone_muted: Arc<AtomicBool>,
95 running: Arc<AtomicBool>,
103 running: Arc<AtomicBool>,
@@ -98,12 +106,22 @@ pub struct ShareAudio {
98 _captures: Vec<Capture>,
106 _captures: Vec<Capture>,
99}
107}
100
108
101impl ShareAudio {
109impl SoftwareAudioPlan {
110 pub fn wanted(mic: MicSettings, sharing_sound: bool, uses_devices: bool) -> Option<Self> {
111 (sharing_sound || (uses_devices && !mic.uses_device_track())).then(|| SoftwareAudioPlan {
112 processing: mic.apm_config(),
113 computer_sound: sharing_sound,
114 })
115 }
116}
117
118impl SoftwareAudio {
102 pub fn start(
119 pub fn start(
103 factory: &PeerConnectionFactory,
120 factory: &PeerConnectionFactory,
104 mode: AudioMode,
121 mode: AudioMode,
105 tone_hz: f32,
122 tone_hz: f32,
106 input: &DeviceChoice,
123 input: &DeviceChoice,
124 plan: SoftwareAudioPlan,
107 microphone_muted: bool,
125 microphone_muted: bool,
108 remote: Option<RtcAudioTrack>,
126 remote: Option<RtcAudioTrack>,
109 ) -> Result<Self> {
127 ) -> Result<Self> {
@@ -111,9 +129,14 @@ impl ShareAudio {
111 let mut warning = None;
129 let mut warning = None;
112 let (microphone, computer, loopback) = if mode == AudioMode::Platform {
130 let (microphone, computer, loopback) = if mode == AudioMode::Platform {
113 let computer_queue = SampleQueue::default();
131 let computer_queue = SampleQueue::default();
114 let started = start_loopback(computer_queue.clone())?;
132 let (computer, loopback) = if plan.computer_sound {
115 captures.push(started.capture);
133 let started = start_loopback(computer_queue.clone())?;
116 warning = started.warning;
134 captures.push(started.capture);
135 warning = started.warning;
136 (FrameSource::Captured(computer_queue), Some(started.kind))
137 } else {
138 (FrameSource::Silence, None)
139 };
117 let microphone_queue = SampleQueue::default();
140 let microphone_queue = SampleQueue::default();
118 let microphone = match start_microphone(input, microphone_queue.clone()) {
141 let microphone = match start_microphone(input, microphone_queue.clone()) {
119 Ok(capture) => {
142 Ok(capture) => {
@@ -125,14 +148,19 @@ impl ShareAudio {
125 FrameSource::Silence
148 FrameSource::Silence
126 }
149 }
127 };
150 };
128 (microphone, FrameSource::Captured(computer_queue), started.kind)
151 (microphone, computer, loopback)
129 } else {
152 } else {
130 let microphone = if mode == AudioMode::Tone {
153 let microphone = if mode == AudioMode::Tone {
131 FrameSource::Tone(SineGenerator::new(tone_hz, SYNTHETIC_AMPLITUDE))
154 FrameSource::Tone(SineGenerator::new(tone_hz, SYNTHETIC_AMPLITUDE))
132 } else {
155 } else {
133 FrameSource::Silence
156 FrameSource::Silence
134 };
157 };
135 (microphone, FrameSource::Tone(SineGenerator::new(SYSTEM_TONE_HZ, SYNTHETIC_AMPLITUDE)), LoopbackKind::Synthetic)
158 let computer = if plan.computer_sound {
159 FrameSource::Tone(SineGenerator::new(SYSTEM_TONE_HZ, SYNTHETIC_AMPLITUDE))
160 } else {
161 FrameSource::Silence
162 };
163 (microphone, computer, plan.computer_sound.then_some(LoopbackKind::Synthetic))
136 };
164 };
137 let source = NativeAudioSource::new(AudioSourceOptions::default(), SAMPLE_RATE, 1, SOURCE_QUEUE_MS);
165 let source = NativeAudioSource::new(AudioSourceOptions::default(), SAMPLE_RATE, 1, SOURCE_QUEUE_MS);
138 let track = factory.create_audio_track("microphone", source.clone());
166 let track = factory.create_audio_track("microphone", source.clone());
@@ -141,6 +169,7 @@ impl ShareAudio {
141 let microphone_muted = Arc::new(AtomicBool::new(microphone_muted));
169 let microphone_muted = Arc::new(AtomicBool::new(microphone_muted));
142 let running = Arc::new(AtomicBool::new(true));
170 let running = Arc::new(AtomicBool::new(true));
143 let feeder = Feeder {
171 let feeder = Feeder {
172 processing: plan.processing,
144 source,
173 source,
145 microphone,
174 microphone,
146 computer,
175 computer,
@@ -153,8 +182,9 @@ impl ShareAudio {
153 .name("share-audio".into())
182 .name("share-audio".into())
154 .spawn(move || feeder.run())
183 .spawn(move || feeder.run())
155 .map_err(|error| Error::Audio(format!("share audio thread: {error}")))?;
184 .map_err(|error| Error::Audio(format!("share audio thread: {error}")))?;
156 Ok(ShareAudio {
185 Ok(SoftwareAudio {
157 track,
186 track,
187 plan,
158 loopback,
188 loopback,
159 warning,
189 warning,
160 microphone_muted,
190 microphone_muted,
@@ -170,7 +200,7 @@ impl ShareAudio {
170 }
200 }
171}
201}
172
202
173impl Drop for ShareAudio {
203impl Drop for SoftwareAudio {
174 fn drop(&mut self) {
204 fn drop(&mut self) {
175 self.running.store(false, Ordering::SeqCst);
205 self.running.store(false, Ordering::SeqCst);
176 if let Some(task) = self.far_end_task.take() {
206 if let Some(task) = self.far_end_task.take() {
@@ -193,14 +223,37 @@ async fn feed_far_end(remote: RtcAudioTrack, queue: SampleQueue) {
193mod tests {
223mod tests {
194 use super::*;
224 use super::*;
195 use crate::devices::shared_factory;
225 use crate::devices::shared_factory;
226 use crate::mic_processing::NoiseSuppression;
196
227
197 #[tokio::test(flavor = "multi_thread")]
228 #[tokio::test(flavor = "multi_thread")]
198 async fn synthetic_sources_start_and_stop_cleanly() {
229 async fn synthetic_sources_start_and_stop_cleanly() {
199 let audio = ShareAudio::start(&shared_factory(), AudioMode::Tone, 440.0, &DeviceChoice::SystemDefault, true, None).unwrap();
230 let plan = SoftwareAudioPlan { processing: MicSettings::default().apm_config(), computer_sound: true };
200 assert_eq!(audio.loopback, LoopbackKind::Synthetic);
231 let audio = SoftwareAudio::start(&shared_factory(), AudioMode::Tone, 440.0, &DeviceChoice::SystemDefault, plan, true, None).unwrap();
232 assert_eq!(audio.loopback, Some(LoopbackKind::Synthetic));
201 assert!(audio.warning.is_none());
233 assert!(audio.warning.is_none());
202 audio.set_microphone_muted(false);
234 audio.set_microphone_muted(false);
203 tokio::time::sleep(Duration::from_millis(60)).await;
235 tokio::time::sleep(Duration::from_millis(60)).await;
204 drop(audio);
236 drop(audio);
205 }
237 }
238
239 #[test]
240 fn the_plan_follows_sharing_and_the_mic_choice() {
241 let auto = MicSettings::default();
242 let off = MicSettings { noise_suppression: NoiseSuppression::Off, music_mode: false };
243 assert_eq!(SoftwareAudioPlan::wanted(auto, false, true), None);
244 assert_eq!(SoftwareAudioPlan::wanted(off, false, false), None);
245 let mic_only = SoftwareAudioPlan::wanted(off, false, true).unwrap();
246 assert!(!mic_only.computer_sound && mic_only.processing.is_passthrough());
247 let sharing = SoftwareAudioPlan::wanted(auto, true, false).unwrap();
248 assert!(sharing.computer_sound && sharing.processing.echo_canceller);
249 }
250
251 #[tokio::test(flavor = "multi_thread")]
252 async fn a_microphone_only_plan_has_no_computer_sound() {
253 let plan = SoftwareAudioPlan { processing: MicSettings::default().apm_config(), computer_sound: false };
254 let audio = SoftwareAudio::start(&shared_factory(), AudioMode::Silence, 440.0, &DeviceChoice::SystemDefault, plan, false, None).unwrap();
255 assert_eq!(audio.loopback, None);
256 tokio::time::sleep(Duration::from_millis(60)).await;
257 drop(audio);
258 }
206}
259}