forge
Explore
Log in

Don't you dare go Hollow

Quiet but audible voice draws on the line (spectrum floor -66 dB)

Browse files at this commit

d6185826f1d4d9535adbdbf44a540f333123ea24Ahmet Kaan GümüşParent: 7d52f9a
  • fix
    • quiet but audible voice draws on the line (spectrum floor -66 dB)
    • ping shows time since anything was heard once the link goes silent, keep-alive 1 s
Show full message
🐛 fix: quiet but audible voice draws on the line (spectrum floor -66 dB); ping shows time since anything was heard once the link goes silent, keep-alive 1 s
crates/client/src/voice/mod.rsmodified+20 -5
@@ -3,7 +3,7 @@ use std::{
3 Arc, Mutex,3 Arc, Mutex,
4 atomic::{AtomicBool, Ordering},4 atomic::{AtomicBool, Ordering},
5 },5 },
6- time::Duration,6+ time::{Duration, Instant},
7 };7 };
8 8
9 use bytes::Bytes;9 use bytes::Bytes;
@@ -45,6 +45,7 @@ pub struct Voice {
45 choice: Choice,45 choice: Choice,
46 audio: Audio,46 audio: Audio,
47 last_path: Mutex<(u64, u64)>,47 last_path: Mutex<(u64, u64)>,
48+ last_heard: Mutex<(u64, Instant)>,
48 }49 }
49 50
50 pub fn start(connection: Option<Connection>, settings: &VoiceSettings) -> Voice {51 pub fn start(connection: Option<Connection>, settings: &VoiceSettings) -> Voice {
@@ -82,6 +83,7 @@ pub fn start(connection: Option<Connection>, settings: &VoiceSettings) -> Voice
82 choice: settings.choice.clone(),83 choice: settings.choice.clone(),
83 audio,84 audio,
84 last_path: Mutex::new((0, 0)),85 last_path: Mutex::new((0, 0)),
86+ last_heard: Mutex::new((0, Instant::now())),
85 };87 };
86 voice.apply(settings);88 voice.apply(settings);
87 voice89 voice
@@ -308,10 +310,23 @@ impl Voice {
308 }310 }
309 311
310 pub fn sample(&self) -> VoiceSample {312 pub fn sample(&self) -> VoiceSample {
311- let ping_ms = self313+ let ping_ms = self.connection.as_ref().map_or(0.0, |connection| {
312- .connection314+ let received = connection.stats().udp_rx.datagrams;
313- .as_ref()315+ let mut heard = self
314- .map_or(0.0, |connection| connection.rtt().as_secs_f32() * 1000.0);316+ .last_heard
317+ .lock()
318+ .unwrap_or_else(|poisoned| poisoned.into_inner());
319+ if received != heard.0 {
320+ *heard = (received, Instant::now());
321+ }
322+ let silence = heard.1.elapsed();
323+ let rtt = connection.rtt();
324+ if silence > 2 * common::transport::KEEP_ALIVE {
325+ silence.max(rtt).as_secs_f32() * 1000.0
326+ } else {
327+ rtt.as_secs_f32() * 1000.0
328+ }
329+ });
315 let (lost, sent) = self.connection.as_ref().map_or((0, 0), |connection| {330 let (lost, sent) = self.connection.as_ref().map_or((0, 0), |connection| {
316 let path = connection.stats().path;331 let path = connection.stats().path;
317 (path.lost_packets, path.sent_packets)332 (path.lost_packets, path.sent_packets)
crates/common/src/transport.rsmodified+1 -1
@@ -6,7 +6,7 @@ use socket2::{Domain, Protocol, Socket, Type};
6 pub const ALPN: &[u8] = b"yumush/2";6 pub const ALPN: &[u8] = b"yumush/2";
7 7
8 const IDLE_TIMEOUT: Duration = Duration::from_secs(10);8 const IDLE_TIMEOUT: Duration = Duration::from_secs(10);
9-const KEEP_ALIVE: Duration = Duration::from_secs(2);9+pub const KEEP_ALIVE: Duration = Duration::from_secs(1);
10 const BIDI_STREAMS: u32 = 256;10 const BIDI_STREAMS: u32 = 256;
11 const DATAGRAM_BUFFER_BYTES: usize = 4 << 20;11 const DATAGRAM_BUFFER_BYTES: usize = 4 << 20;
12 const SOCKET_BUFFER_BYTES: usize = 8 << 20;12 const SOCKET_BUFFER_BYTES: usize = 8 << 20;
crates/spectrum/src/lib.rsmodified+1 -1
@@ -7,7 +7,7 @@ pub const BANDS: usize = 32;
7 pub const WINDOW: usize = 2048;7 pub const WINDOW: usize = 2048;
8 const LOW_HZ: f32 = 60.0;8 const LOW_HZ: f32 = 60.0;
9 const HIGH_HZ: f32 = 12000.0;9 const HIGH_HZ: f32 = 12000.0;
10-const FLOOR_DB: f32 = -48.0;10+const FLOOR_DB: f32 = -66.0;
11 const CEIL_DB: f32 = -12.0;11 const CEIL_DB: f32 = -12.0;
12 12
13 pub struct Analyzer {13 pub struct Analyzer {