merge: call audio options
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -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
| Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |
179
182
| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |
@@ -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 navigation134
## 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
| Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |181
| Call health and encryption | Partial | Header shows signal bars and a shield; click opens "Call health" with loss, round trip, jitter, bitrate, "Secured by Teams encryption", DTLS-SRTP cipher and media path (direct or via Microsoft media server). Unstable network banner with "Turn off incoming video", overloaded computer banner with "Turn off effects". Thresholds unit tested; not yet seen on a bad live network |179
| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |182
| View and layout | Partial | "View" button between share and "...": Gallery (up to 3x3 of 16:9 tiles, "+N" tile with a pin list; visible tiles only swap after 2 s of speech, one swap per 5 s), Speaker (stage plus filmstrip of up to 6), Focus on content (only while someone shares), Hide people without video with a count chip, Hide me / Show me, Chat bubbles, Full screen (F11, controls hide after 3 s). Choice, Hide people without video and Chat bubbles are remembered. Checked with the demo gallery scene only; not yet in a large live meeting |@@ -127,6 +127,7 @@ pub struct AppState {
127
127
pub call_view: crate::call::ViewSettings,
128
128
pub call_background: crate::call::BackgroundPick,
129
129
pub call_camera: calling::DeviceChoice,
130
pub call_mic: calling::MicSettings,
130
131
pub meet_now_pending: bool,
131
132
pub call_backgrounds: crate::call::BackgroundLibrary,
132
133
pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,
@@ -225,6 +226,7 @@ impl AppState {
225
226
call_view: crate::call::ViewSettings::default(),
226
227
call_background: crate::call::BackgroundPick::None,
227
228
call_camera: calling::DeviceChoice::SystemDefault,
229
call_mic: calling::MicSettings::default(),
228
230
meet_now_pending: false,
229
231
call_backgrounds: if mode.demo {
230
232
crate::call::demo_library()
@@ -244,6 +246,7 @@ impl AppState {
244
246
state.call_view = crate::call::ViewSettings::load(&state.store);
245
247
state.call_background = crate::call::load_background(&state.store);
246
248
state.call_camera = crate::call::load_camera(&state.store);
249
state.call_mic = crate::call::load_mic(&state.store);
247
250
state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);
248
251
state.load_cached_translation_settings();
249
252
if !mode.demo {
@@ -127,6 +127,7 @@ pub struct AppState {127
pub call_view: crate::call::ViewSettings,127
pub call_view: crate::call::ViewSettings,128
pub call_background: crate::call::BackgroundPick,128
pub call_background: crate::call::BackgroundPick,129
pub call_camera: calling::DeviceChoice,129
pub call_camera: calling::DeviceChoice,130
pub call_mic: calling::MicSettings,130
pub meet_now_pending: bool,131
pub meet_now_pending: bool,131
pub call_backgrounds: crate::call::BackgroundLibrary,132
pub call_backgrounds: crate::call::BackgroundLibrary,132
pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,133
pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,@@ -225,6 +226,7 @@ impl AppState {225
call_view: crate::call::ViewSettings::default(),226
call_view: crate::call::ViewSettings::default(),226
call_background: crate::call::BackgroundPick::None,227
call_background: crate::call::BackgroundPick::None,227
call_camera: calling::DeviceChoice::SystemDefault,228
call_camera: calling::DeviceChoice::SystemDefault,229
call_mic: calling::MicSettings::default(),228
meet_now_pending: false,230
meet_now_pending: false,229
call_backgrounds: if mode.demo {231
call_backgrounds: if mode.demo {230
crate::call::demo_library()232
crate::call::demo_library()@@ -244,6 +246,7 @@ impl AppState {244
state.call_view = crate::call::ViewSettings::load(&state.store);246
state.call_view = crate::call::ViewSettings::load(&state.store);245
state.call_background = crate::call::load_background(&state.store);247
state.call_background = crate::call::load_background(&state.store);246
state.call_camera = crate::call::load_camera(&state.store);248
state.call_camera = crate::call::load_camera(&state.store);249
state.call_mic = crate::call::load_mic(&state.store);247
state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);250
state.call_backgrounds.customs = crate::call::load_custom_backgrounds(&state.store);248
state.load_cached_translation_settings();251
state.load_cached_translation_settings();249
if !mode.demo {252
if !mode.demo {@@ -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();
@@ -398,6 +402,35 @@ impl AppState {
398
402
self.send_call_command(CallCommand::SetCamera(on));
399
403
}
400
404
405
pub fn set_call_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
406
self.call_mic = settings;
407
save_mic(&self.store, settings);
408
self.send_call_command(CallCommand::SetMicSettings(settings));
409
cx.notify();
410
}
411
412
pub fn press_push_to_talk(&mut self, _cx: &mut Context<Self>) {
413
let Some(call) = self.call.as_mut() else {
414
return;
415
};
416
let command = call
417
.push_to_talk
418
.press(call.model.muted, call.model.can_unmute());
419
if let Some(command) = command {
420
self.send_call_command(CallCommand::Mute(command));
421
}
422
}
423
424
pub fn release_push_to_talk(&mut self, _cx: &mut Context<Self>) {
425
let command = self
426
.call
427
.as_mut()
428
.and_then(|call| call.push_to_talk.release());
429
if let Some(command) = command {
430
self.send_call_command(CallCommand::Mute(command));
431
}
432
}
433
401
434
pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {
402
435
let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));
403
436
self.call_camera = choice.clone();
@@ -3,7 +3,7 @@ use std::time::{Duration, Instant};3
use calling::meeting::LiveMeeting;3
use calling::meeting::LiveMeeting;4
use calling::{4
use 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
};8
use gpui_kit::*;8
use gpui_kit::*;9
9
@@ -16,6 +16,7 @@ use super::demo::{16
};16
};17
use super::features::room_closed_move;17
use super::features::room_closed_move;18
use super::media::CallMedia;18
use super::media::CallMedia;19
use super::mic::save_mic;19
use super::model::{ActiveCall, CallKind, CallModel, ended_notice};20
use super::model::{ActiveCall, CallKind, CallModel, ended_notice};20
use super::ring::{MissedCall, RingOutcome};21
use super::ring::{MissedCall, RingOutcome};21
use super::target::{is_organizer, plan_for_chat};22
use 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();@@ -398,6 +402,35 @@ impl AppState {398
self.send_call_command(CallCommand::SetCamera(on));402
self.send_call_command(CallCommand::SetCamera(on));399
}403
}400
404
405
pub fn set_call_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {406
self.call_mic = settings;407
save_mic(&self.store, settings);408
self.send_call_command(CallCommand::SetMicSettings(settings));409
cx.notify();410
}411
412
pub fn press_push_to_talk(&mut self, _cx: &mut Context<Self>) {413
let Some(call) = self.call.as_mut() else {414
return;415
};416
let command = call417
.push_to_talk418
.press(call.model.muted, call.model.can_unmute());419
if let Some(command) = command {420
self.send_call_command(CallCommand::Mute(command));421
}422
}423
424
pub fn release_push_to_talk(&mut self, _cx: &mut Context<Self>) {425
let command = self426
.call427
.as_mut()428
.and_then(|call| call.push_to_talk.release());429
if let Some(command) = command {430
self.send_call_command(CallCommand::Mute(command));431
}432
}433
401
pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {434
pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) {402
let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));435
let _ = self.store.set_meta(CAMERA_META_KEY, camera_meta(&choice));403
self.call_camera = choice.clone();436
self.call_camera = choice.clone();@@ -530,7 +530,7 @@ async fn speak_until_hangup(
530
530
camera_on = on;
531
531
control.send(CallUpdate::Camera(on));
532
532
}
533
Some(CallCommand::SelectCamera(_)) => {}
533
Some(CallCommand::SelectCamera(_) | CallCommand::SetMicSettings(_)) => {}
534
534
Some(CallCommand::StartShare(source)) => {
535
535
control.send(CallUpdate::LocalShare(Some(source.label())));
536
536
if share_sound {
@@ -530,7 +530,7 @@ async fn speak_until_hangup(530
camera_on = on;530
camera_on = on;531
control.send(CallUpdate::Camera(on));531
control.send(CallUpdate::Camera(on));532
}532
}533
Some(CallCommand::SelectCamera(_)) => {}533
Some(CallCommand::SelectCamera(_) | CallCommand::SetMicSettings(_)) => {}534
Some(CallCommand::StartShare(source)) => {534
Some(CallCommand::StartShare(source)) => {535
control.send(CallUpdate::LocalShare(Some(source.label())));535
control.send(CallUpdate::LocalShare(Some(source.label())));536
if share_sound {536
if share_sound {@@ -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 @@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
store8
.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_mode24
)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
settings39
}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
}@@ -13,11 +13,13 @@ mod join;
13
13
mod launcher;
14
14
mod list;
15
15
mod media;
16
mod mic;
16
17
mod model;
17
18
mod overlay;
18
19
mod overlay_layout;
19
20
mod pictures;
20
21
mod preview;
22
mod push_to_talk;
21
23
mod ring;
22
24
mod stage_layout;
23
25
mod target;
@@ -25,6 +27,7 @@ mod view_actions;
25
27
mod view_settings;
26
28
27
29
pub use actions::{load_camera, load_share_sound};
30
pub use mic::load_mic;
28
31
pub use agenda::{AgendaRow, fetch_window, join_available};
29
32
pub use background::{
30
33
BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,
@@ -13,11 +13,13 @@ mod join;13
mod launcher;13
mod launcher;14
mod list;14
mod list;15
mod media;15
mod media;16
mod mic;16
mod model;17
mod model;17
mod overlay;18
mod overlay;18
mod overlay_layout;19
mod overlay_layout;19
mod pictures;20
mod pictures;20
mod preview;21
mod preview;22
mod push_to_talk;21
mod ring;23
mod ring;22
mod stage_layout;24
mod stage_layout;23
mod target;25
mod target;@@ -25,6 +27,7 @@ mod view_actions;25
mod view_settings;27
mod view_settings;26
28
27
pub use actions::{load_camera, load_share_sound};29
pub use actions::{load_camera, load_share_sound};30
pub use mic::load_mic;28
pub use agenda::{AgendaRow, fetch_window, join_available};31
pub use agenda::{AgendaRow, fetch_window, join_available};29
pub use background::{32
pub use background::{30
BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,33
BackgroundLibrary, BackgroundPick, default_cache_directory, demo_library, load_background,@@ -17,6 +17,7 @@ use super::fullscreen::FullscreenState;
17
17
use super::pictures::CallPictures;
18
18
use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, VisibleRotation, split_overflow};
19
19
use super::view_settings::{CallLayout, ViewSettings};
20
use super::push_to_talk::PushToTalk;
20
21
21
22
pub const TEST_CALL_TITLE: &str = "Test call";
22
23
pub const ECHO_NAME: &str = "Teams echo";
@@ -48,6 +49,7 @@ pub struct ActiveCall {
48
49
pub meeting_target: Option<MeetingTarget>,
49
50
pub pending_move: Option<PendingMove>,
50
51
pub consult: Option<ConsultCall>,
52
pub push_to_talk: PushToTalk,
51
53
}
52
54
53
55
#[derive(Debug, Clone, PartialEq)]
@@ -110,6 +112,7 @@ impl ActiveCall {
110
112
meeting_target: None,
111
113
pending_move: None,
112
114
consult: None,
115
push_to_talk: PushToTalk::default(),
113
116
}
114
117
}
115
118
@@ -17,6 +17,7 @@ use super::fullscreen::FullscreenState;17
use super::pictures::CallPictures;17
use super::pictures::CallPictures;18
use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, VisibleRotation, split_overflow};18
use super::stage_layout::{FILMSTRIP_MAX, GALLERY_MAX, VisibleRotation, split_overflow};19
use super::view_settings::{CallLayout, ViewSettings};19
use super::view_settings::{CallLayout, ViewSettings};20
use super::push_to_talk::PushToTalk;20
21
21
pub const TEST_CALL_TITLE: &str = "Test call";22
pub const TEST_CALL_TITLE: &str = "Test call";22
pub const ECHO_NAME: &str = "Teams echo";23
pub const ECHO_NAME: &str = "Teams echo";@@ -48,6 +49,7 @@ pub struct ActiveCall {48
pub meeting_target: Option<MeetingTarget>,49
pub meeting_target: Option<MeetingTarget>,49
pub pending_move: Option<PendingMove>,50
pub pending_move: Option<PendingMove>,50
pub consult: Option<ConsultCall>,51
pub consult: Option<ConsultCall>,52
pub push_to_talk: PushToTalk,51
}53
}52
54
53
#[derive(Debug, Clone, PartialEq)]55
#[derive(Debug, Clone, PartialEq)]@@ -110,6 +112,7 @@ impl ActiveCall {110
meeting_target: None,112
meeting_target: None,111
pending_move: None,113
pending_move: None,112
consult: None,114
consult: None,115
push_to_talk: PushToTalk::default(),113
}116
}114
}117
}115
118
@@ -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 @@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.held11
}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
}@@ -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: Environment201
|| environment.system_quiet203
|| environment.system_quiet202
|| environment.own_do_not_disturb204
|| environment.own_do_not_disturb203
|| settings.do_not_disturb205
|| settings.do_not_disturb206
|| (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();@@ -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);@@ -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 @@1
use std::time::{Duration, Instant};1
use std::time::{Duration, Instant};2
2
3
use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};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
use gpui_kit::assets::IconName;5
use gpui_kit::assets::IconName;6
use gpui_kit::component::{6
use 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
};12
use gpui_kit::base::Disableable as _;12
use gpui_kit::prelude::FluentBuilder as _;13
use gpui_kit::prelude::FluentBuilder as _;13
use gpui_kit::*;14
use gpui_kit::*;14
15
@@ -67,7 +68,7 @@ struct Row {67
field: Accessor,68
field: Accessor,68
}69
}69
70
70
const ROWS: [Row; 5] = [71
const 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
..mic528
},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
..mic552
},553
cx,554
)555
})556
}),557
)488
.child(558
.child(489
v_flex()559
v_flex()490
.w_full()560
.w_full()@@ -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 _},
@@ -34,7 +34,7 @@ use super::widgets::{Corner, corner_badge, count_badge, icon};
34
34
use crate::app_state::AppState;
35
35
use crate::call::REACTION_SHOWN;
36
36
use crate::call::TileSize;
37
use crate::call::{CallKind, CallModel, Tile, TileState};
37
use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState};
38
38
use crate::rows::reaction_glyph as chat_reaction_glyph;
39
39
use crate::theme;
40
40
@@ -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 {
@@ -432,6 +436,54 @@ fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {
432
436
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
433
437
}
434
438
439
fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {
440
let app = app.clone();
441
PopupMenuItem::element(move |_, _| {
442
h_flex()
443
.id("call-music-mode-row")
444
.w_full()
445
.gap(px(16.))
446
.items_center()
447
.justify_between()
448
.child(MUSIC_MODE_LABEL)
449
.child(Switch::new("call-music-mode").checked(mic.music_mode))
450
})
451
.on_click(move |_, _, cx| {
452
app.update(cx, |state, cx| {
453
let settings = MicSettings {
454
music_mode: !mic.music_mode,
455
..state.call_mic
456
};
457
state.set_call_mic(settings, cx)
458
})
459
})
460
}
461
462
fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {
463
call.push_to_talk.is_held().then(|| {
464
div()
465
.id("call-push-to-talk")
466
.absolute()
467
.top(px(HEADER_HEIGHT + PUSH_TO_TALK_TOP))
468
.left_0()
469
.right_0()
470
.flex()
471
.justify_center()
472
.child(
473
div()
474
.debug_selector(|| "call/push-to-talk".into())
475
.px(px(12.))
476
.py(px(6.))
477
.rounded_full()
478
.bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))
479
.text_color(theme::white())
480
.text_size(px(13.))
481
.child(PUSH_TO_TALK_HINT),
482
)
483
.into_any_element()
484
})
485
}
486
435
487
fn share_items(
436
488
popup: PopupMenu,
437
489
app: &Entity<AppState>,
@@ -766,7 +818,12 @@ pub(super) fn device_items(
766
818
.collect()
767
819
}
768
820
769
fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {
821
fn devices_menu(
822
popup: PopupMenu,
823
app: &Entity<AppState>,
824
model: &CallModel,
825
mic: MicSettings,
826
) -> PopupMenu {
770
827
let input_app = app.clone();
771
828
let output_app = app.clone();
772
829
let inputs = device_items(
@@ -793,19 +850,42 @@ fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) ->
793
850
popup = popup.item(item);
794
851
}
795
852
}
796
popup = popup.separator().item(PopupMenuItem::label("Speaker"));
853
popup = popup
854
.separator()
855
.item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL));
856
for level in NoiseSuppression::ALL {
857
let level_app = app.clone();
858
popup = popup.item(
859
PopupMenuItem::new(level.label())
860
.checked(level == mic.noise_suppression)
861
.disabled(mic.music_mode)
862
.on_click(move |_, _, cx| {
863
level_app.update(cx, |state, cx| {
864
let settings = MicSettings {
865
noise_suppression: level,
866
..state.call_mic
867
};
868
state.set_call_mic(settings, cx)
869
})
870
}),
871
);
872
}
873
popup = popup
874
.item(music_mode_item(app, mic))
875
.separator()
876
.item(PopupMenuItem::label("Speaker"));
797
877
for item in outputs {
798
878
popup = popup.item(item);
799
879
}
800
880
popup
801
881
}
802
882
803
fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {
883
fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {
804
884
let app = app.clone();
805
885
let model = model.clone();
806
886
chevron_button("call-mic-menu", "call-mic-menu-face")
807
887
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {
808
devices_menu(popup, &app, &model)
888
devices_menu(popup, &app, &model, mic)
809
889
})
810
890
}
811
891
@@ -1007,7 +1087,7 @@ pub fn render_call_view(
1007
1087
.rounded_full()
1008
1088
.bg(theme::surface_raised())
1009
1089
.child(mute_button(app, model, "call-mute", CONTROL_SIZE))
1010
.child(mic_menu_button(app, model)),
1090
.child(mic_menu_button(app, model, state.call_mic)),
1011
1091
)
1012
1092
.child(
1013
1093
h_flex()
@@ -1077,6 +1157,7 @@ pub fn render_call_view(
1077
1157
}
1078
1158
.children(captions_overlay(model, now))
1079
1159
.children(captions_hint_chip(model))
1160
.children(push_to_talk_chip(call))
1080
1161
.children(state.transfer_picker.clone())
1081
1162
.children(consent_overlay(app, model));
1082
1163
Some(
@@ -1,7 +1,7 @@1
use std::sync::Arc;1
use std::sync::Arc;2
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};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
use gpui_kit::assets::IconName;5
use gpui_kit::assets::IconName;6
use gpui_kit::component::{6
use gpui_kit::component::{7
button::{Button, ButtonVariants as _},7
button::{Button, ButtonVariants as _},@@ -34,7 +34,7 @@ use super::widgets::{Corner, corner_badge, count_badge, icon};34
use crate::app_state::AppState;34
use crate::app_state::AppState;35
use crate::call::REACTION_SHOWN;35
use crate::call::REACTION_SHOWN;36
use crate::call::TileSize;36
use crate::call::TileSize;37
use crate::call::{CallKind, CallModel, Tile, TileState};37
use crate::call::{ActiveCall, CallKind, CallModel, Tile, TileState};38
use crate::rows::reaction_glyph as chat_reaction_glyph;38
use crate::rows::reaction_glyph as chat_reaction_glyph;39
use crate::theme;39
use crate::theme;40
40
@@ -72,6 +72,10 @@ const REACTION_RISE: f32 = 24.;72
const REACTION_FADE_FROM: f32 = 0.75;72
const REACTION_FADE_FROM: f32 = 0.75;73
const REACTION_CELL: f32 = 40.;73
const REACTION_CELL: f32 = 40.;74
const SHARE_SOUND_LABEL: &str = "Include computer sound";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
pub fn reaction_glyph(reaction: Reaction) -> String {80
pub fn reaction_glyph(reaction: Reaction) -> String {77
match reaction {81
match reaction {@@ -432,6 +436,54 @@ fn sound_switch_item(app: &Entity<AppState>, sound: bool) -> PopupMenuItem {432
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))436
.on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))433
}437
}434
438
439
fn music_mode_item(app: &Entity<AppState>, mic: MicSettings) -> PopupMenuItem {440
let app = app.clone();441
PopupMenuItem::element(move |_, _| {442
h_flex()443
.id("call-music-mode-row")444
.w_full()445
.gap(px(16.))446
.items_center()447
.justify_between()448
.child(MUSIC_MODE_LABEL)449
.child(Switch::new("call-music-mode").checked(mic.music_mode))450
})451
.on_click(move |_, _, cx| {452
app.update(cx, |state, cx| {453
let settings = MicSettings {454
music_mode: !mic.music_mode,455
..state.call_mic456
};457
state.set_call_mic(settings, cx)458
})459
})460
}461
462
fn push_to_talk_chip(call: &ActiveCall) -> Option<AnyElement> {463
call.push_to_talk.is_held().then(|| {464
div()465
.id("call-push-to-talk")466
.absolute()467
.top(px(HEADER_HEIGHT + PUSH_TO_TALK_TOP))468
.left_0()469
.right_0()470
.flex()471
.justify_center()472
.child(473
div()474
.debug_selector(|| "call/push-to-talk".into())475
.px(px(12.))476
.py(px(6.))477
.rounded_full()478
.bg(hsla(0., 0., 0., NAME_PLATE_BACKGROUND))479
.text_color(theme::white())480
.text_size(px(13.))481
.child(PUSH_TO_TALK_HINT),482
)483
.into_any_element()484
})485
}486
435
fn share_items(487
fn share_items(436
popup: PopupMenu,488
popup: PopupMenu,437
app: &Entity<AppState>,489
app: &Entity<AppState>,@@ -766,7 +818,12 @@ pub(super) fn device_items(766
.collect()818
.collect()767
}819
}768
820
769
fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu {821
fn devices_menu(822
popup: PopupMenu,823
app: &Entity<AppState>,824
model: &CallModel,825
mic: MicSettings,826
) -> PopupMenu {770
let input_app = app.clone();827
let input_app = app.clone();771
let output_app = app.clone();828
let output_app = app.clone();772
let inputs = device_items(829
let inputs = device_items(@@ -793,19 +850,42 @@ fn devices_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) ->793
popup = popup.item(item);850
popup = popup.item(item);794
}851
}795
}852
}796
popup = popup.separator().item(PopupMenuItem::label("Speaker"));853
popup = popup854
.separator()855
.item(PopupMenuItem::label(NOISE_SUPPRESSION_LABEL));856
for level in NoiseSuppression::ALL {857
let level_app = app.clone();858
popup = popup.item(859
PopupMenuItem::new(level.label())860
.checked(level == mic.noise_suppression)861
.disabled(mic.music_mode)862
.on_click(move |_, _, cx| {863
level_app.update(cx, |state, cx| {864
let settings = MicSettings {865
noise_suppression: level,866
..state.call_mic867
};868
state.set_call_mic(settings, cx)869
})870
}),871
);872
}873
popup = popup874
.item(music_mode_item(app, mic))875
.separator()876
.item(PopupMenuItem::label("Speaker"));797
for item in outputs {877
for item in outputs {798
popup = popup.item(item);878
popup = popup.item(item);799
}879
}800
popup880
popup801
}881
}802
882
803
fn mic_menu_button(app: &Entity<AppState>, model: &CallModel) -> impl IntoElement {883
fn mic_menu_button(app: &Entity<AppState>, model: &CallModel, mic: MicSettings) -> impl IntoElement {804
let app = app.clone();884
let app = app.clone();805
let model = model.clone();885
let model = model.clone();806
chevron_button("call-mic-menu", "call-mic-menu-face")886
chevron_button("call-mic-menu", "call-mic-menu-face")807
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {887
.dropdown_menu_with_anchor(Anchor::BottomLeft, move |popup, _, _| {808
devices_menu(popup, &app, &model)888
devices_menu(popup, &app, &model, mic)809
})889
})810
}890
}811
891
@@ -1007,7 +1087,7 @@ pub fn render_call_view(1007
.rounded_full()1087
.rounded_full()1008
.bg(theme::surface_raised())1088
.bg(theme::surface_raised())1009
.child(mute_button(app, model, "call-mute", CONTROL_SIZE))1089
.child(mute_button(app, model, "call-mute", CONTROL_SIZE))1010
.child(mic_menu_button(app, model)),1090
.child(mic_menu_button(app, model, state.call_mic)),1011
)1091
)1012
.child(1092
.child(1013
h_flex()1093
h_flex()@@ -1077,6 +1157,7 @@ pub fn render_call_view(1077
}1157
}1078
.children(captions_overlay(model, now))1158
.children(captions_overlay(model, now))1079
.children(captions_hint_chip(model))1159
.children(captions_hint_chip(model))1160
.children(push_to_talk_chip(call))1080
.children(state.transfer_picker.clone())1161
.children(state.transfer_picker.clone())1081
.children(consent_overlay(app, model));1162
.children(consent_overlay(app, model));1082
Some(1163
Some(@@ -16,7 +16,7 @@ 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, OpenLobbyList, OpenSaved, PreviousConversation, Scope,
19
OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk, Scope,
20
20
ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
21
21
ToggleCallHand, ToggleCallShare,
22
22
};
@@ -48,6 +48,7 @@ pub fn bind_keys(cx: &mut App) {
48
48
Scope::Global,
49
49
Scope::OutsideComposer,
50
50
Scope::GlobalOverTextFields,
51
Scope::OutsideTextFields,
51
52
],
52
53
);
53
54
}
@@ -215,6 +216,9 @@ impl AppShell {
215
216
if window.is_window_active() {
216
217
this.state
217
218
.update(cx, |state, cx| state.refresh_calendar(cx));
219
} else {
220
this.state
221
.update(cx, |state, cx| state.release_push_to_talk(cx));
218
222
}
219
223
});
220
224
let closing = notifications.clone();
@@ -751,6 +755,22 @@ impl Render for AppShell {
751
755
this.state
752
756
.update(cx, |state, cx| state.toggle_call_mute(cx));
753
757
}))
758
.on_action(cx.listener(|this, _: &PushToTalk, _, cx| {
759
this.state
760
.update(cx, |state, cx| state.press_push_to_talk(cx));
761
}))
762
.on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| {
763
if event.keystroke.key == "space" {
764
this.state
765
.update(cx, |state, cx| state.release_push_to_talk(cx));
766
}
767
}))
768
.on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, _, cx| {
769
if !event.modifiers.control {
770
this.state
771
.update(cx, |state, cx| state.release_push_to_talk(cx));
772
}
773
}))
754
774
.on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
755
775
this.toggle_shortcuts_dialog(window, cx);
756
776
}))
@@ -16,7 +16,7 @@ use super::rail::RailView;16
use super::saved_panel::{SavedPanel, SavedPanelEvent};16
use super::saved_panel::{SavedPanel, SavedPanelEvent};17
use super::shortcuts::{17
use super::shortcuts::{18
AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,18
AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenCallsTab,19
OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, Scope,19
OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk, Scope,20
ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,20
ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,21
ToggleCallHand, ToggleCallShare,21
ToggleCallHand, ToggleCallShare,22
};22
};@@ -48,6 +48,7 @@ pub fn bind_keys(cx: &mut App) {48
Scope::Global,48
Scope::Global,49
Scope::OutsideComposer,49
Scope::OutsideComposer,50
Scope::GlobalOverTextFields,50
Scope::GlobalOverTextFields,51
Scope::OutsideTextFields,51
],52
],52
);53
);53
}54
}@@ -215,6 +216,9 @@ impl AppShell {215
if window.is_window_active() {216
if window.is_window_active() {216
this.state217
this.state217
.update(cx, |state, cx| state.refresh_calendar(cx));218
.update(cx, |state, cx| state.refresh_calendar(cx));219
} else {220
this.state221
.update(cx, |state, cx| state.release_push_to_talk(cx));218
}222
}219
});223
});220
let closing = notifications.clone();224
let closing = notifications.clone();@@ -751,6 +755,22 @@ impl Render for AppShell {751
this.state755
this.state752
.update(cx, |state, cx| state.toggle_call_mute(cx));756
.update(cx, |state, cx| state.toggle_call_mute(cx));753
}))757
}))758
.on_action(cx.listener(|this, _: &PushToTalk, _, cx| {759
this.state760
.update(cx, |state, cx| state.press_push_to_talk(cx));761
}))762
.on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| {763
if event.keystroke.key == "space" {764
this.state765
.update(cx, |state, cx| state.release_push_to_talk(cx));766
}767
}))768
.on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, _, cx| {769
if !event.modifiers.control {770
this.state771
.update(cx, |state, cx| state.release_push_to_talk(cx));772
}773
}))754
.on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {774
.on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {755
this.toggle_shortcuts_dialog(window, cx);775
this.toggle_shortcuts_dialog(window, cx);756
}))776
}))@@ -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,
@@ -30,6 +31,7 @@ actions!(
30
31
StartAudioCall,
31
32
StartVideoCall,
32
33
ToggleCallFullscreen,
34
PushToTalk,
33
35
ShowShortcuts
34
36
]
35
37
);
@@ -65,6 +67,7 @@ pub enum Scope {
65
67
Global,
66
68
OutsideComposer,
67
69
GlobalOverTextFields,
70
OutsideTextFields,
68
71
Composer,
69
72
}
70
73
@@ -123,6 +126,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
123
126
shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),
124
127
shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),
125
128
shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),
129
shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk),
126
130
];
127
131
128
132
impl Shortcut {
@@ -142,6 +146,7 @@ impl Shortcut {
142
146
Scope::Global => &[None],
143
147
Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],
144
148
Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],
149
Scope::OutsideTextFields => &[Some(OUTSIDE_TEXT_FIELD_CONTEXT)],
145
150
Scope::Composer => &[Some(COMPOSER_CONTEXT)],
146
151
};
147
152
let mut keys = vec![self.keys];
@@ -169,6 +174,7 @@ pub fn display_keys(keys: &str) -> String {
169
174
"up" => "Up".to_owned(),
170
175
"down" => "Down".to_owned(),
171
176
"enter" => "Enter".to_owned(),
177
"space" => "Space".to_owned(),
172
178
other => other.to_uppercase(),
173
179
})
174
180
.collect::<Vec<_>>()
@@ -229,7 +235,7 @@ mod tests {
229
235
for shortcut in SHORTCUTS {
230
236
let contexts: &[&str] = match shortcut.scope {
231
237
Scope::Global | Scope::OutsideComposer => &["AppShell"],
232
Scope::GlobalOverTextFields => &["AppShell"],
238
Scope::GlobalOverTextFields | Scope::OutsideTextFields => &["AppShell"],
233
239
Scope::Composer => &["AppShell", "Composer"],
234
240
};
235
241
assert_eq!(
@@ -259,6 +265,16 @@ mod tests {
259
265
}
260
266
}
261
267
268
#[gpui_kit::test]
269
fn push_to_talk_is_not_bound_while_typing_in_a_text_field(cx: &mut TestAppContext) {
270
registered(cx);
271
assert!(bound_action(cx, "ctrl-space", &["AppShell"]).is_some());
272
assert_eq!(
273
bound_action(cx, "ctrl-space", &["AppShell", "Composer", "Input"]),
274
None
275
);
276
}
277
262
278
#[gpui_kit::test]
263
279
fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {
264
280
registered(cx);
@@ -300,5 +316,6 @@ mod tests {
300
316
assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");
301
317
assert_eq!(display_keys("alt-up"), "Alt+Up");
302
318
assert_eq!(display_keys("ctrl-."), "Ctrl+.");
319
assert_eq!(display_keys("ctrl-space"), "Ctrl+Space");
303
320
}
304
321
}
@@ -9,6 +9,7 @@ use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};9
9
10
const TEXT_FIELD_CONTEXT: &str = "Input";10
const TEXT_FIELD_CONTEXT: &str = "Input";11
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";11
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";12
const OUTSIDE_TEXT_FIELD_CONTEXT: &str = "!Input";12
13
13
actions!(14
actions!(14
teams,15
teams,@@ -30,6 +31,7 @@ actions!(30
StartAudioCall,31
StartAudioCall,31
StartVideoCall,32
StartVideoCall,32
ToggleCallFullscreen,33
ToggleCallFullscreen,34
PushToTalk,33
ShowShortcuts35
ShowShortcuts34
]36
]35
);37
);@@ -65,6 +67,7 @@ pub enum Scope {65
Global,67
Global,66
OutsideComposer,68
OutsideComposer,67
GlobalOverTextFields,69
GlobalOverTextFields,70
OutsideTextFields,68
Composer,71
Composer,69
}72
}70
73
@@ -123,6 +126,7 @@ pub const SHORTCUTS: &[Shortcut] = &[123
shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),126
shortcut!(Calls, GlobalOverTextFields, "Start an audio call in this chat", "alt-shift-a", None, StartAudioCall),124
shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),127
shortcut!(Calls, GlobalOverTextFields, "Start a video call in this chat", "alt-shift-v", None, StartVideoCall),125
shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),128
shortcut!(Calls, GlobalOverTextFields, "Full screen", "f11", None, ToggleCallFullscreen),129
shortcut!(Calls, OutsideTextFields, "Hold to talk while muted", "ctrl-space", None, PushToTalk),126
];130
];127
131
128
impl Shortcut {132
impl Shortcut {@@ -142,6 +146,7 @@ impl Shortcut {142
Scope::Global => &[None],146
Scope::Global => &[None],143
Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],147
Scope::OutsideComposer => &[Some(OUTSIDE_COMPOSER_CONTEXT)],144
Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],148
Scope::GlobalOverTextFields => &[None, Some(TEXT_FIELD_CONTEXT)],149
Scope::OutsideTextFields => &[Some(OUTSIDE_TEXT_FIELD_CONTEXT)],145
Scope::Composer => &[Some(COMPOSER_CONTEXT)],150
Scope::Composer => &[Some(COMPOSER_CONTEXT)],146
};151
};147
let mut keys = vec![self.keys];152
let mut keys = vec![self.keys];@@ -169,6 +174,7 @@ pub fn display_keys(keys: &str) -> String {169
"up" => "Up".to_owned(),174
"up" => "Up".to_owned(),170
"down" => "Down".to_owned(),175
"down" => "Down".to_owned(),171
"enter" => "Enter".to_owned(),176
"enter" => "Enter".to_owned(),177
"space" => "Space".to_owned(),172
other => other.to_uppercase(),178
other => other.to_uppercase(),173
})179
})174
.collect::<Vec<_>>()180
.collect::<Vec<_>>()@@ -229,7 +235,7 @@ mod tests {229
for shortcut in SHORTCUTS {235
for shortcut in SHORTCUTS {230
let contexts: &[&str] = match shortcut.scope {236
let contexts: &[&str] = match shortcut.scope {231
Scope::Global | Scope::OutsideComposer => &["AppShell"],237
Scope::Global | Scope::OutsideComposer => &["AppShell"],232
Scope::GlobalOverTextFields => &["AppShell"],238
Scope::GlobalOverTextFields | Scope::OutsideTextFields => &["AppShell"],233
Scope::Composer => &["AppShell", "Composer"],239
Scope::Composer => &["AppShell", "Composer"],234
};240
};235
assert_eq!(241
assert_eq!(@@ -259,6 +265,16 @@ mod tests {259
}265
}260
}266
}261
267
268
#[gpui_kit::test]269
fn push_to_talk_is_not_bound_while_typing_in_a_text_field(cx: &mut TestAppContext) {270
registered(cx);271
assert!(bound_action(cx, "ctrl-space", &["AppShell"]).is_some());272
assert_eq!(273
bound_action(cx, "ctrl-space", &["AppShell", "Composer", "Input"]),274
None275
);276
}277
262
#[gpui_kit::test]278
#[gpui_kit::test]263
fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {279
fn composer_link_shortcut_still_beats_the_switcher_while_typing(cx: &mut TestAppContext) {264
registered(cx);280
registered(cx);@@ -300,5 +316,6 @@ mod tests {300
assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");316
assert_eq!(display_keys("ctrl-shift-a"), "Ctrl+Shift+A");301
assert_eq!(display_keys("alt-up"), "Alt+Up");317
assert_eq!(display_keys("alt-up"), "Alt+Up");302
assert_eq!(display_keys("ctrl-."), "Ctrl+.");318
assert_eq!(display_keys("ctrl-."), "Ctrl+.");319
assert_eq!(display_keys("ctrl-space"), "Ctrl+Space");303
}320
}304
}321
}@@ -35,9 +35,9 @@ use crate::engine::{CallEngine, EngineConfig, Inner};
35
35
use crate::error::{Error, Result};
36
36
use crate::health::{CallHealth, HealthCounters, HealthSampler, QualityTracker, TransportDetails, health_from_stats};
37
37
use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};
38
use crate::mic_processing::MicSettings;
38
39
use crate::mute::{MuteCommand, MuteEffect};
39
40
use crate::push::CallNotification;
40
use crate::share_audio::ShareAudio;
41
41
use crate::relay::{DEFAULT_RELAY_HOST, RelayGrant, fetch_relay_grant};
42
42
use crate::renegotiation::{MediaAction, MediaNegotiator, MediaPath};
43
43
use crate::organizer::Target;
@@ -48,6 +48,7 @@ use crate::signaling::{
48
48
Answer, Attached, Callee, Conversation, Invitation, InviteTarget, LeaveReason, MeetingTarget, Participant, Signaling,
49
49
TenantRouting, chat_thread_id, find_echo_bot_thread, escalation_answer_body, renegotiation_body,
50
50
};
51
use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};
51
52
use crate::state::{CallSignal, CallState};
52
53
use crate::timeline::{Timeline, TimelineEntry};
53
54
use crate::transfer::{TransferEvent, TransferTarget};
@@ -810,8 +811,9 @@ async fn drive(
810
811
if sending_camera {
811
812
control.send(CallUpdate::Camera(true));
812
813
}
813
let mut share_audio: Option<ShareAudio> = None;
814
let mut software_audio: Option<SoftwareAudio> = None;
814
815
let mut share_sound_wanted = false;
816
let mut mic_settings = MicSettings::default();
815
817
let mut remote_audio: Option<RtcAudioTrack> = None;
816
818
let mut own_hand: Option<String> = None;
817
819
let mut depacketizer = Depacketizer::default();
@@ -1064,7 +1066,7 @@ async fn drive(
1064
1066
consent_pending = required;
1065
1067
control.send(CallUpdate::ConsentRequired(required));
1066
1068
if required {
1067
withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, &mut local_video, control);
1069
withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, &mut local_video, control);
1068
1070
}
1069
1071
}
1070
1072
if !main_meeting_sent
@@ -1183,7 +1185,10 @@ async fn drive(
1183
1185
}
1184
1186
PeerEvent::Track(remote_track) => {
1185
1187
timeline.record("remote audio track", "receiving");
1186
remote_audio = Some(remote_track.clone());
1188
let had_far_end = remote_audio.replace(remote_track.clone()).is_some();
1189
if !had_far_end && software_audio.is_some() {
1190
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);
1191
}
1187
1192
if options.record_remote {
1188
1193
tokio::spawn(record_track(remote_track, recording.clone(), options.tone_hz));
1189
1194
}
@@ -1212,7 +1217,7 @@ async fn drive(
1212
1217
timeline.record("escalation", "new peer connection connected, old one dropped");
1213
1218
let old = std::mem::replace(&mut current, pending.session);
1214
1219
old.peer.close();
1215
if let Some(audio) = &share_audio
1220
if let Some(audio) = &software_audio
1216
1221
&& let Err(error) = swap_audio_track(¤t.peer, &audio.track)
1217
1222
{
1218
1223
timeline.record("computer sound not carried over", error.to_string());
@@ -1249,7 +1254,7 @@ async fn drive(
1249
1254
if consent_pending && !mute.target(muted) {
1250
1255
control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));
1251
1256
} else {
1252
muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, control);
1257
muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, control);
1253
1258
}
1254
1259
}
1255
1260
Some(CallCommand::SelectInput(choice)) => {
@@ -1258,6 +1263,13 @@ async fn drive(
1258
1263
}
1259
1264
input = choice;
1260
1265
control.send(CallUpdate::Selected { input: input.clone(), output: output.clone() });
1266
if software_audio.is_some() {
1267
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);
1268
}
1269
}
1270
Some(CallCommand::SetMicSettings(settings)) => {
1271
mic_settings = settings;
1272
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1261
1273
}
1262
1274
Some(CallCommand::SelectOutput(choice)) => {
1263
1275
if live.audio.as_ref().is_some_and(AudioSetup::uses_devices) {
@@ -1332,9 +1344,7 @@ async fn drive(
1332
1344
Ok(()) => {
1333
1345
control.send(CallUpdate::LocalShare(Some(source.label())));
1334
1346
tell_media_descriptions(&remote, &media_links, MediaDescription::share(true), &mut media_description_request, timeline);
1335
if share_sound_wanted && share_audio.is_none() {
1336
share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, control, timeline);
1337
}
1347
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1338
1348
}
1339
1349
Err(error) => control.send(CallUpdate::Notice(format!("Sharing could not start: {error}"))),
1340
1350
}
@@ -1343,20 +1353,14 @@ async fn drive(
1343
1353
Some(CallCommand::StopShare) => {
1344
1354
if local_video.sharing() {
1345
1355
local_video.stop_share();
1346
release_share_sound(¤t.peer, &track, &mut share_audio, control, timeline);
1356
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1347
1357
control.send(CallUpdate::LocalShare(None));
1348
1358
tell_media_descriptions(&remote, &media_links, MediaDescription::share(false), &mut media_description_request, timeline);
1349
1359
}
1350
1360
}
1351
1361
Some(CallCommand::SetShareSound(on)) => {
1352
1362
share_sound_wanted = on;
1353
if local_video.sharing() {
1354
if on && share_audio.is_none() {
1355
share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, control, timeline);
1356
} else if !on {
1357
release_share_sound(¤t.peer, &track, &mut share_audio, control, timeline);
1358
}
1359
}
1363
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);
1360
1364
}
1361
1365
Some(CallCommand::RefreshShareSources) => refresh_share_sources(control.updates(), options.video),
1362
1366
Some(CallCommand::SetHand(true)) => match remote.signaling.raise_hand(&remote.conversation, &remote.participant).await {
@@ -1588,7 +1592,7 @@ async fn drive(
1588
1592
path: negotiator.path(),
1589
1593
}));
1590
1594
}
1591
let local_level = if muted && share_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };
1595
let local_level = if muted && software_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };
1592
1596
control.send(CallUpdate::Levels { local: local_level, remote: snapshot.audio_level as f32 });
1593
1597
if snapshot.selected_pair.is_some() {
1594
1598
report.selected_pair = snapshot.selected_pair.clone();
@@ -1956,12 +1960,12 @@ fn undo_change(change: Change, local_video: &mut LocalVideo, control: &CallContr
1956
1960
fn withhold_media(
1957
1961
muted: &mut bool,
1958
1962
audio: &AudioSetup,
1959
share_audio: Option<&ShareAudio>,
1963
software_audio: Option<&SoftwareAudio>,
1960
1964
remote: &RemoteCall,
1961
1965
local_video: &mut LocalVideo,
1962
1966
control: &CallControl,
1963
1967
) {
1964
*muted = apply_mute(MuteCommand::Mute, *muted, audio, share_audio, remote, control);
1968
*muted = apply_mute(MuteCommand::Mute, *muted, audio, software_audio, remote, control);
1965
1969
if local_video.camera_on() {
1966
1970
local_video.stop_camera();
1967
1971
control.send(CallUpdate::Camera(false));
@@ -2120,14 +2124,14 @@ fn apply_mute(
2120
2124
command: MuteCommand,
2121
2125
currently_muted: bool,
2122
2126
audio: &AudioSetup,
2123
share_audio: Option<&ShareAudio>,
2127
software_audio: Option<&SoftwareAudio>,
2124
2128
remote: &RemoteCall,
2125
2129
control: &CallControl,
2126
2130
) -> bool {
2127
2131
let effect = MuteEffect::for_muted(command.target(currently_muted));
2128
2132
audio.track.set_enabled(effect.track_enabled);
2129
if let Some(share_audio) = share_audio {
2130
share_audio.set_microphone_muted(effect.muted);
2133
if let Some(software_audio) = software_audio {
2134
software_audio.set_microphone_muted(effect.muted);
2131
2135
}
2132
2136
control.send(CallUpdate::Muted(effect.muted));
2133
2137
let remote = remote.clone();
@@ -2151,52 +2155,73 @@ fn swap_audio_track(peer: &PeerConnection, track: &RtcAudioTrack) -> Result<()>
2151
2155
.map_err(|error| Error::Webrtc(error.to_string()))
2152
2156
}
2153
2157
2158
fn software_wanted(
2159
mic_settings: MicSettings,
2160
share_sound_wanted: bool,
2161
local_video: &LocalVideo,
2162
audio: Option<&AudioSetup>,
2163
) -> Option<SoftwareAudioPlan> {
2164
let sharing_sound = share_sound_wanted && local_video.sharing();
2165
SoftwareAudioPlan::wanted(mic_settings, sharing_sound, audio.is_some_and(AudioSetup::uses_devices))
2166
}
2167
2154
2168
#[allow(clippy::too_many_arguments)]
2155
fn engage_share_sound(
2169
fn sync_software_audio(
2156
2170
factory: &PeerConnectionFactory,
2157
2171
options: &CallOptions,
2158
2172
input: &DeviceChoice,
2159
2173
muted: bool,
2160
2174
remote_audio: Option<RtcAudioTrack>,
2161
2175
peer: &PeerConnection,
2176
device_track: &RtcAudioTrack,
2177
wanted: Option<SoftwareAudioPlan>,
2178
restart: bool,
2179
software_audio: &mut Option<SoftwareAudio>,
2162
2180
control: &CallControl,
2163
2181
timeline: &Timeline,
2164
) -> Option<ShareAudio> {
2165
let started = ShareAudio::start(factory, options.audio, options.tone_hz, input, muted, remote_audio)
2182
) {
2183
let running = software_audio.as_ref().map(|audio| audio.plan);
2184
if running == wanted && !restart {
2185
return;
2186
}
2187
*software_audio = None;
2188
let was_sharing_sound = running.is_some_and(|plan| plan.computer_sound);
2189
let Some(plan) = wanted else {
2190
if let Err(error) = swap_audio_track(peer, device_track) {
2191
timeline.record("microphone track not restored", error.to_string());
2192
}
2193
control.send(CallUpdate::ShareSound(false));
2194
return;
2195
};
2196
let started = SoftwareAudio::start(factory, options.audio, options.tone_hz, input, plan, muted, remote_audio)
2166
2197
.and_then(|audio| swap_audio_track(peer, &audio.track).map(|()| audio));
2167
2198
match started {
2168
2199
Ok(audio) => {
2169
timeline.record("computer sound", format!("{:?}, own playback excluded: {}", audio.loopback, audio.loopback.excludes_own_playback()));
2200
timeline.record("software audio", format!("{:?}, computer sound {:?}", plan.processing, audio.loopback));
2170
2201
if let Some(warning) = &audio.warning {
2171
2202
timeline.record("computer sound warning", warning.clone());
2172
2203
}
2173
control.send(CallUpdate::ShareSound(true));
2174
Some(audio)
2204
control.send(CallUpdate::ShareSound(plan.computer_sound));
2205
*software_audio = Some(audio);
2175
2206
}
2176
2207
Err(error) => {
2177
timeline.record("computer sound failed", error.to_string());
2178
control.send(CallUpdate::Notice("Computer sound could not start, sharing without it".into()));
2179
None
2208
timeline.record("software audio failed", error.to_string());
2209
if let Err(error) = swap_audio_track(peer, device_track) {
2210
timeline.record("microphone track not restored", error.to_string());
2211
}
2212
if was_sharing_sound || plan.computer_sound {
2213
control.send(CallUpdate::ShareSound(false));
2214
}
2215
let notice = if plan.computer_sound {
2216
"Computer sound could not start, sharing without it"
2217
} else {
2218
"Microphone processing could not start, using the standard microphone"
2219
};
2220
control.send(CallUpdate::Notice(notice.into()));
2180
2221
}
2181
2222
}
2182
2223
}
2183
2224
2184
fn release_share_sound(
2185
peer: &PeerConnection,
2186
device_track: &RtcAudioTrack,
2187
share_audio: &mut Option<ShareAudio>,
2188
control: &CallControl,
2189
timeline: &Timeline,
2190
) {
2191
if share_audio.take().is_none() {
2192
return;
2193
}
2194
if let Err(error) = swap_audio_track(peer, device_track) {
2195
timeline.record("microphone track not restored", error.to_string());
2196
}
2197
control.send(CallUpdate::ShareSound(false));
2198
}
2199
2200
2225
async fn tear_down(mut live: Live, inner: &Inner, timeline: &Timeline, report: &mut CallReport, cancelled: bool) {
2201
2226
if let Some(audio) = &live.audio {
2202
2227
audio.track.set_enabled(false);
@@ -35,9 +35,9 @@ use crate::engine::{CallEngine, EngineConfig, Inner};35
use crate::error::{Error, Result};35
use crate::error::{Error, Result};36
use crate::health::{CallHealth, HealthCounters, HealthSampler, QualityTracker, TransportDetails, health_from_stats};36
use crate::health::{CallHealth, HealthCounters, HealthSampler, QualityTracker, TransportDetails, health_from_stats};37
use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};37
use crate::hold::{HoldState, INACTIVE, MediaLine, accepted_modalities, is_hold, rewrite_directions};38
use crate::mic_processing::MicSettings;38
use crate::mute::{MuteCommand, MuteEffect};39
use crate::mute::{MuteCommand, MuteEffect};39
use crate::push::CallNotification;40
use crate::push::CallNotification;40
use crate::share_audio::ShareAudio;41
use crate::relay::{DEFAULT_RELAY_HOST, RelayGrant, fetch_relay_grant};41
use crate::relay::{DEFAULT_RELAY_HOST, RelayGrant, fetch_relay_grant};42
use crate::renegotiation::{MediaAction, MediaNegotiator, MediaPath};42
use crate::renegotiation::{MediaAction, MediaNegotiator, MediaPath};43
use crate::organizer::Target;43
use crate::organizer::Target;@@ -48,6 +48,7 @@ use crate::signaling::{48
Answer, Attached, Callee, Conversation, Invitation, InviteTarget, LeaveReason, MeetingTarget, Participant, Signaling,48
Answer, Attached, Callee, Conversation, Invitation, InviteTarget, LeaveReason, MeetingTarget, Participant, Signaling,49
TenantRouting, chat_thread_id, find_echo_bot_thread, escalation_answer_body, renegotiation_body,49
TenantRouting, chat_thread_id, find_echo_bot_thread, escalation_answer_body, renegotiation_body,50
};50
};51
use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};51
use crate::state::{CallSignal, CallState};52
use crate::state::{CallSignal, CallState};52
use crate::timeline::{Timeline, TimelineEntry};53
use crate::timeline::{Timeline, TimelineEntry};53
use crate::transfer::{TransferEvent, TransferTarget};54
use crate::transfer::{TransferEvent, TransferTarget};@@ -810,8 +811,9 @@ async fn drive(810
if sending_camera {811
if sending_camera {811
control.send(CallUpdate::Camera(true));812
control.send(CallUpdate::Camera(true));812
}813
}813
let mut share_audio: Option<ShareAudio> = None;814
let mut software_audio: Option<SoftwareAudio> = None;814
let mut share_sound_wanted = false;815
let mut share_sound_wanted = false;816
let mut mic_settings = MicSettings::default();815
let mut remote_audio: Option<RtcAudioTrack> = None;817
let mut remote_audio: Option<RtcAudioTrack> = None;816
let mut own_hand: Option<String> = None;818
let mut own_hand: Option<String> = None;817
let mut depacketizer = Depacketizer::default();819
let mut depacketizer = Depacketizer::default();@@ -1064,7 +1066,7 @@ async fn drive(1064
consent_pending = required;1066
consent_pending = required;1065
control.send(CallUpdate::ConsentRequired(required));1067
control.send(CallUpdate::ConsentRequired(required));1066
if required {1068
if required {1067
withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, &mut local_video, control);1069
withhold_media(&mut muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, &mut local_video, control);1068
}1070
}1069
}1071
}1070
if !main_meeting_sent1072
if !main_meeting_sent@@ -1183,7 +1185,10 @@ async fn drive(1183
}1185
}1184
PeerEvent::Track(remote_track) => {1186
PeerEvent::Track(remote_track) => {1185
timeline.record("remote audio track", "receiving");1187
timeline.record("remote audio track", "receiving");1186
remote_audio = Some(remote_track.clone());1188
let had_far_end = remote_audio.replace(remote_track.clone()).is_some();1189
if !had_far_end && software_audio.is_some() {1190
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);1191
}1187
if options.record_remote {1192
if options.record_remote {1188
tokio::spawn(record_track(remote_track, recording.clone(), options.tone_hz));1193
tokio::spawn(record_track(remote_track, recording.clone(), options.tone_hz));1189
}1194
}@@ -1212,7 +1217,7 @@ async fn drive(1212
timeline.record("escalation", "new peer connection connected, old one dropped");1217
timeline.record("escalation", "new peer connection connected, old one dropped");1213
let old = std::mem::replace(&mut current, pending.session);1218
let old = std::mem::replace(&mut current, pending.session);1214
old.peer.close();1219
old.peer.close();1215
if let Some(audio) = &share_audio1220
if let Some(audio) = &software_audio1216
&& let Err(error) = swap_audio_track(¤t.peer, &audio.track)1221
&& let Err(error) = swap_audio_track(¤t.peer, &audio.track)1217
{1222
{1218
timeline.record("computer sound not carried over", error.to_string());1223
timeline.record("computer sound not carried over", error.to_string());@@ -1249,7 +1254,7 @@ async fn drive(1249
if consent_pending && !mute.target(muted) {1254
if consent_pending && !mute.target(muted) {1250
control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));1255
control.send(CallUpdate::Notice(CONSENT_FIRST_NOTICE.into()));1251
} else {1256
} else {1252
muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), share_audio.as_ref(), &remote, control);1257
muted = apply_mute(mute, muted, live.audio.as_ref().expect("audio set above"), software_audio.as_ref(), &remote, control);1253
}1258
}1254
}1259
}1255
Some(CallCommand::SelectInput(choice)) => {1260
Some(CallCommand::SelectInput(choice)) => {@@ -1258,6 +1263,13 @@ async fn drive(1258
}1263
}1259
input = choice;1264
input = choice;1260
control.send(CallUpdate::Selected { input: input.clone(), output: output.clone() });1265
control.send(CallUpdate::Selected { input: input.clone(), output: output.clone() });1266
if software_audio.is_some() {1267
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), true, &mut software_audio, control, timeline);1268
}1269
}1270
Some(CallCommand::SetMicSettings(settings)) => {1271
mic_settings = settings;1272
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);1261
}1273
}1262
Some(CallCommand::SelectOutput(choice)) => {1274
Some(CallCommand::SelectOutput(choice)) => {1263
if live.audio.as_ref().is_some_and(AudioSetup::uses_devices) {1275
if live.audio.as_ref().is_some_and(AudioSetup::uses_devices) {@@ -1332,9 +1344,7 @@ async fn drive(1332
Ok(()) => {1344
Ok(()) => {1333
control.send(CallUpdate::LocalShare(Some(source.label())));1345
control.send(CallUpdate::LocalShare(Some(source.label())));1334
tell_media_descriptions(&remote, &media_links, MediaDescription::share(true), &mut media_description_request, timeline);1346
tell_media_descriptions(&remote, &media_links, MediaDescription::share(true), &mut media_description_request, timeline);1335
if share_sound_wanted && share_audio.is_none() {1347
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);1336
share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, control, timeline);1337
}1338
}1348
}1339
Err(error) => control.send(CallUpdate::Notice(format!("Sharing could not start: {error}"))),1349
Err(error) => control.send(CallUpdate::Notice(format!("Sharing could not start: {error}"))),1340
}1350
}@@ -1343,20 +1353,14 @@ async fn drive(1343
Some(CallCommand::StopShare) => {1353
Some(CallCommand::StopShare) => {1344
if local_video.sharing() {1354
if local_video.sharing() {1345
local_video.stop_share();1355
local_video.stop_share();1346
release_share_sound(¤t.peer, &track, &mut share_audio, control, timeline);1356
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);1347
control.send(CallUpdate::LocalShare(None));1357
control.send(CallUpdate::LocalShare(None));1348
tell_media_descriptions(&remote, &media_links, MediaDescription::share(false), &mut media_description_request, timeline);1358
tell_media_descriptions(&remote, &media_links, MediaDescription::share(false), &mut media_description_request, timeline);1349
}1359
}1350
}1360
}1351
Some(CallCommand::SetShareSound(on)) => {1361
Some(CallCommand::SetShareSound(on)) => {1352
share_sound_wanted = on;1362
share_sound_wanted = on;1353
if local_video.sharing() {1363
sync_software_audio(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, &track, software_wanted(mic_settings, share_sound_wanted, &local_video, live.audio.as_ref()), false, &mut software_audio, control, timeline);1354
if on && share_audio.is_none() {1355
share_audio = engage_share_sound(&factory, options, &input, muted, remote_audio.clone(), ¤t.peer, control, timeline);1356
} else if !on {1357
release_share_sound(¤t.peer, &track, &mut share_audio, control, timeline);1358
}1359
}1360
}1364
}1361
Some(CallCommand::RefreshShareSources) => refresh_share_sources(control.updates(), options.video),1365
Some(CallCommand::RefreshShareSources) => refresh_share_sources(control.updates(), options.video),1362
Some(CallCommand::SetHand(true)) => match remote.signaling.raise_hand(&remote.conversation, &remote.participant).await {1366
Some(CallCommand::SetHand(true)) => match remote.signaling.raise_hand(&remote.conversation, &remote.participant).await {@@ -1588,7 +1592,7 @@ async fn drive(1588
path: negotiator.path(),1592
path: negotiator.path(),1589
}));1593
}));1590
}1594
}1591
let local_level = if muted && share_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };1595
let local_level = if muted && software_audio.is_none() { 0.0 } else { snapshot.local_level as f32 };1592
control.send(CallUpdate::Levels { local: local_level, remote: snapshot.audio_level as f32 });1596
control.send(CallUpdate::Levels { local: local_level, remote: snapshot.audio_level as f32 });1593
if snapshot.selected_pair.is_some() {1597
if snapshot.selected_pair.is_some() {1594
report.selected_pair = snapshot.selected_pair.clone();1598
report.selected_pair = snapshot.selected_pair.clone();@@ -1956,12 +1960,12 @@ fn undo_change(change: Change, local_video: &mut LocalVideo, control: &CallContr1956
fn withhold_media(1960
fn withhold_media(1957
muted: &mut bool,1961
muted: &mut bool,1958
audio: &AudioSetup,1962
audio: &AudioSetup,1959
share_audio: Option<&ShareAudio>,1963
software_audio: Option<&SoftwareAudio>,1960
remote: &RemoteCall,1964
remote: &RemoteCall,1961
local_video: &mut LocalVideo,1965
local_video: &mut LocalVideo,1962
control: &CallControl,1966
control: &CallControl,1963
) {1967
) {1964
*muted = apply_mute(MuteCommand::Mute, *muted, audio, share_audio, remote, control);1968
*muted = apply_mute(MuteCommand::Mute, *muted, audio, software_audio, remote, control);1965
if local_video.camera_on() {1969
if local_video.camera_on() {1966
local_video.stop_camera();1970
local_video.stop_camera();1967
control.send(CallUpdate::Camera(false));1971
control.send(CallUpdate::Camera(false));@@ -2120,14 +2124,14 @@ fn apply_mute(2120
command: MuteCommand,2124
command: MuteCommand,2121
currently_muted: bool,2125
currently_muted: bool,2122
audio: &AudioSetup,2126
audio: &AudioSetup,2123
share_audio: Option<&ShareAudio>,2127
software_audio: Option<&SoftwareAudio>,2124
remote: &RemoteCall,2128
remote: &RemoteCall,2125
control: &CallControl,2129
control: &CallControl,2126
) -> bool {2130
) -> bool {2127
let effect = MuteEffect::for_muted(command.target(currently_muted));2131
let effect = MuteEffect::for_muted(command.target(currently_muted));2128
audio.track.set_enabled(effect.track_enabled);2132
audio.track.set_enabled(effect.track_enabled);2129
if let Some(share_audio) = share_audio {2133
if let Some(software_audio) = software_audio {2130
share_audio.set_microphone_muted(effect.muted);2134
software_audio.set_microphone_muted(effect.muted);2131
}2135
}2132
control.send(CallUpdate::Muted(effect.muted));2136
control.send(CallUpdate::Muted(effect.muted));2133
let remote = remote.clone();2137
let remote = remote.clone();@@ -2151,52 +2155,73 @@ fn swap_audio_track(peer: &PeerConnection, track: &RtcAudioTrack) -> Result<()>2151
.map_err(|error| Error::Webrtc(error.to_string()))2155
.map_err(|error| Error::Webrtc(error.to_string()))2152
}2156
}2153
2157
2158
fn software_wanted(2159
mic_settings: MicSettings,2160
share_sound_wanted: bool,2161
local_video: &LocalVideo,2162
audio: Option<&AudioSetup>,2163
) -> Option<SoftwareAudioPlan> {2164
let sharing_sound = share_sound_wanted && local_video.sharing();2165
SoftwareAudioPlan::wanted(mic_settings, sharing_sound, audio.is_some_and(AudioSetup::uses_devices))2166
}2167
2154
#[allow(clippy::too_many_arguments)]2168
#[allow(clippy::too_many_arguments)]2155
fn engage_share_sound(2169
fn sync_software_audio(2156
factory: &PeerConnectionFactory,2170
factory: &PeerConnectionFactory,2157
options: &CallOptions,2171
options: &CallOptions,2158
input: &DeviceChoice,2172
input: &DeviceChoice,2159
muted: bool,2173
muted: bool,2160
remote_audio: Option<RtcAudioTrack>,2174
remote_audio: Option<RtcAudioTrack>,2161
peer: &PeerConnection,2175
peer: &PeerConnection,2176
device_track: &RtcAudioTrack,2177
wanted: Option<SoftwareAudioPlan>,2178
restart: bool,2179
software_audio: &mut Option<SoftwareAudio>,2162
control: &CallControl,2180
control: &CallControl,2163
timeline: &Timeline,2181
timeline: &Timeline,2164
) -> Option<ShareAudio> {2182
) {2165
let started = ShareAudio::start(factory, options.audio, options.tone_hz, input, muted, remote_audio)2183
let running = software_audio.as_ref().map(|audio| audio.plan);2184
if running == wanted && !restart {2185
return;2186
}2187
*software_audio = None;2188
let was_sharing_sound = running.is_some_and(|plan| plan.computer_sound);2189
let Some(plan) = wanted else {2190
if let Err(error) = swap_audio_track(peer, device_track) {2191
timeline.record("microphone track not restored", error.to_string());2192
}2193
control.send(CallUpdate::ShareSound(false));2194
return;2195
};2196
let started = SoftwareAudio::start(factory, options.audio, options.tone_hz, input, plan, muted, remote_audio)2166
.and_then(|audio| swap_audio_track(peer, &audio.track).map(|()| audio));2197
.and_then(|audio| swap_audio_track(peer, &audio.track).map(|()| audio));2167
match started {2198
match started {2168
Ok(audio) => {2199
Ok(audio) => {2169
timeline.record("computer sound", format!("{:?}, own playback excluded: {}", audio.loopback, audio.loopback.excludes_own_playback()));2200
timeline.record("software audio", format!("{:?}, computer sound {:?}", plan.processing, audio.loopback));2170
if let Some(warning) = &audio.warning {2201
if let Some(warning) = &audio.warning {2171
timeline.record("computer sound warning", warning.clone());2202
timeline.record("computer sound warning", warning.clone());2172
}2203
}2173
control.send(CallUpdate::ShareSound(true));2204
control.send(CallUpdate::ShareSound(plan.computer_sound));2174
Some(audio)2205
*software_audio = Some(audio);2175
}2206
}2176
Err(error) => {2207
Err(error) => {2177
timeline.record("computer sound failed", error.to_string());2208
timeline.record("software audio failed", error.to_string());2178
control.send(CallUpdate::Notice("Computer sound could not start, sharing without it".into()));2209
if let Err(error) = swap_audio_track(peer, device_track) {2179
None2210
timeline.record("microphone track not restored", error.to_string());2211
}2212
if was_sharing_sound || plan.computer_sound {2213
control.send(CallUpdate::ShareSound(false));2214
}2215
let notice = if plan.computer_sound {2216
"Computer sound could not start, sharing without it"2217
} else {2218
"Microphone processing could not start, using the standard microphone"2219
};2220
control.send(CallUpdate::Notice(notice.into()));2180
}2221
}2181
}2222
}2182
}2223
}2183
2224
2184
fn release_share_sound(2185
peer: &PeerConnection,2186
device_track: &RtcAudioTrack,2187
share_audio: &mut Option<ShareAudio>,2188
control: &CallControl,2189
timeline: &Timeline,2190
) {2191
if share_audio.take().is_none() {2192
return;2193
}2194
if let Err(error) = swap_audio_track(peer, device_track) {2195
timeline.record("microphone track not restored", error.to_string());2196
}2197
control.send(CallUpdate::ShareSound(false));2198
}2199
2200
async fn tear_down(mut live: Live, inner: &Inner, timeline: &Timeline, report: &mut CallReport, cancelled: bool) {2225
async fn tear_down(mut live: Live, inner: &Inner, timeline: &Timeline, report: &mut CallReport, cancelled: bool) {2201
if let Some(audio) = &live.audio {2226
if let Some(audio) = &live.audio {2202
audio.track.set_enabled(false);2227
audio.track.set_enabled(false);@@ -10,6 +10,7 @@ use crate::devices::{DeviceChoice, DeviceLists};
10
10
use crate::error::{Error, Result};
11
11
use crate::health::CallHealth;
12
12
use crate::hold::HoldState;
13
use crate::mic_processing::MicSettings;
13
14
use crate::mute::MuteCommand;
14
15
use crate::reaction::Reaction;
15
16
use crate::roster::RosterEntry;
@@ -25,6 +26,7 @@ pub enum CallCommand {
25
26
Mute(MuteCommand),
26
27
SelectInput(DeviceChoice),
27
28
SelectOutput(DeviceChoice),
29
SetMicSettings(MicSettings),
28
30
RefreshDevices,
29
31
SetCamera(bool),
30
32
SelectCamera(DeviceChoice),
@@ -10,6 +10,7 @@ use crate::devices::{DeviceChoice, DeviceLists};10
use crate::error::{Error, Result};10
use crate::error::{Error, Result};11
use crate::health::CallHealth;11
use crate::health::CallHealth;12
use crate::hold::HoldState;12
use crate::hold::HoldState;13
use crate::mic_processing::MicSettings;13
use crate::mute::MuteCommand;14
use crate::mute::MuteCommand;14
use crate::reaction::Reaction;15
use crate::reaction::Reaction;15
use crate::roster::RosterEntry;16
use crate::roster::RosterEntry;@@ -25,6 +26,7 @@ pub enum CallCommand {25
Mute(MuteCommand),26
Mute(MuteCommand),26
SelectInput(DeviceChoice),27
SelectInput(DeviceChoice),27
SelectOutput(DeviceChoice),28
SelectOutput(DeviceChoice),29
SetMicSettings(MicSettings),28
RefreshDevices,30
RefreshDevices,29
SetCamera(bool),31
SetCamera(bool),30
SelectCamera(DeviceChoice),32
SelectCamera(DeviceChoice),@@ -21,6 +21,7 @@ pub mod level;
21
21
#[cfg(windows)]
22
22
mod loopback_windows;
23
23
pub mod meeting;
24
pub mod mic_processing;
24
25
pub mod mixer;
25
26
pub mod mute;
26
27
pub mod organizer;
@@ -34,8 +35,8 @@ pub mod ring;
34
35
pub mod roster;
35
36
pub mod screen;
36
37
pub mod sdp;
37
pub mod share_audio;
38
38
pub mod signaling;
39
pub mod software_audio;
39
40
pub mod sound_capture;
40
41
pub mod state;
41
42
pub mod timeline;
@@ -69,6 +70,7 @@ pub use signaling::{Callee, MeetingTarget};
69
70
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};
70
71
pub use error::{Error, Result};
71
72
pub use level::SpeakingDetector;
73
pub use mic_processing::{ApmConfig, MicSettings, NoiseSuppression};
72
74
pub use mute::MuteCommand;
73
75
pub use state::{CallSignal, CallState, EndReason};
74
76
pub use camera::{CameraDevice, camera_entries};
@@ -21,6 +21,7 @@ pub mod level;21
#[cfg(windows)]21
#[cfg(windows)]22
mod loopback_windows;22
mod loopback_windows;23
pub mod meeting;23
pub mod meeting;24
pub mod mic_processing;24
pub mod mixer;25
pub mod mixer;25
pub mod mute;26
pub mod mute;26
pub mod organizer;27
pub mod organizer;@@ -34,8 +35,8 @@ pub mod ring;34
pub mod roster;35
pub mod roster;35
pub mod screen;36
pub mod screen;36
pub mod sdp;37
pub mod sdp;37
pub mod share_audio;38
pub mod signaling;38
pub mod signaling;39
pub mod software_audio;39
pub mod sound_capture;40
pub mod sound_capture;40
pub mod state;41
pub mod state;41
pub mod timeline;42
pub mod timeline;@@ -69,6 +70,7 @@ pub use signaling::{Callee, MeetingTarget};69
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};70
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};70
pub use error::{Error, Result};71
pub use error::{Error, Result};71
pub use level::SpeakingDetector;72
pub use level::SpeakingDetector;73
pub use mic_processing::{ApmConfig, MicSettings, NoiseSuppression};72
pub use mute::MuteCommand;74
pub use mute::MuteCommand;73
pub use state::{CallSignal, CallState, EndReason};75
pub use state::{CallSignal, CallState, EndReason};74
pub use camera::{CameraDevice, camera_entries};76
pub use camera::{CameraDevice, camera_entries};@@ -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 @@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
}@@ -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
5
use futures_util::StreamExt;5
use futures_util::StreamExt;6
use libwebrtc::audio_source::native::NativeAudioSource;6
use libwebrtc::audio_source::native::NativeAudioSource;7
use libwebrtc::native::apm::AudioProcessingModule;8
use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;7
use libwebrtc::peer_connection_factory::native::PeerConnectionFactoryExt;9
use libwebrtc::audio_stream::native::NativeAudioStream;8
use libwebrtc::audio_stream::native::NativeAudioStream;10
use libwebrtc::prelude::*;9
use libwebrtc::prelude::*;@@ -15,6 +14,7 @@ use crate::audio_io::AudioMode;15
use crate::capture::Capture;14
use crate::capture::Capture;16
use crate::devices::DeviceChoice;15
use crate::devices::DeviceChoice;17
use crate::error::{Error, Result};16
use crate::error::{Error, Result};17
use crate::mic_processing::{ApmConfig, MicSettings};18
use crate::mixer::mix_frames;18
use crate::mixer::mix_frames;19
use crate::pcm::SampleQueue;19
use crate::pcm::SampleQueue;20
use crate::sound_capture::{LoopbackKind, start_loopback, start_microphone};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
struct Feeder {50
struct 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
54
impl Feeder {61
impl 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.90
pub struct ShareAudio {97
pub 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
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
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::Silence148
FrameSource::Silence126
}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::Silence156
FrameSource::Silence134
};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::Silence162
};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
173
impl Drop for ShareAudio {203
impl 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) {193
mod tests {223
mod 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
}