diff options
| author | Kyle Simpson <[email protected]> | 2018-04-20 15:57:02 +0100 |
|---|---|---|
| committer | zeyla <[email protected]> | 2018-04-20 07:57:02 -0700 |
| commit | 83a0c85b0bf87cb4272b5d6e189d139fc31a6d23 (patch) | |
| tree | dcfa3bed64ddad1743f2c81ab2ba999c44b360ba /src/voice | |
| parent | Bump to v0.5.2 (diff) | |
| download | serenity-83a0c85b0bf87cb4272b5d6e189d139fc31a6d23.tar.xz serenity-83a0c85b0bf87cb4272b5d6e189d139fc31a6d23.zip | |
Send silence frames upon connection (Fix #301)
Diffstat (limited to 'src/voice')
| -rw-r--r-- | src/voice/audio.rs | 1 | ||||
| -rw-r--r-- | src/voice/connection.rs | 7 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/voice/audio.rs b/src/voice/audio.rs index 2aebb83..b541f49 100644 --- a/src/voice/audio.rs +++ b/src/voice/audio.rs @@ -6,6 +6,7 @@ use std::{ pub const HEADER_LEN: usize = 12; pub const SAMPLE_RATE: u32 = 48_000; +pub static SILENT_FRAME: [u8; 3] = [0xf8, 0xff, 0xfe]; /// A readable audio source. pub trait AudioSource: Send { diff --git a/src/voice/connection.rs b/src/voice/connection.rs index 5c170c6..8e94486 100644 --- a/src/voice/connection.rs +++ b/src/voice/connection.rs @@ -45,7 +45,7 @@ use std::{ }, time::Duration }; -use super::audio::{AudioReceiver, AudioType, HEADER_LEN, SAMPLE_RATE, LockedAudio}; +use super::audio::{AudioReceiver, AudioType, LockedAudio, HEADER_LEN, SAMPLE_RATE, SILENT_FRAME}; use super::connection_info::ConnectionInfo; use super::{payload, VoiceError, CRYPTO_MODE}; use websocket::{ @@ -200,7 +200,8 @@ impl Connection { keepalive_timer: Timer::new(temp_heartbeat), udp, sequence: 0, - silence_frames: 0, + // We need to send some frames to receive any audio. + silence_frames: 100, soft_clip, speaking: false, ssrc: hello.ssrc, @@ -392,7 +393,7 @@ impl Connection { self.silence_frames -= 1; // Explicit "Silence" frame. - opus_frame.extend_from_slice(&[0xf8, 0xff, 0xfe]); + opus_frame.extend_from_slice(&SILENT_FRAME); } else { // Per official guidelines, send 5x silence BEFORE we stop speaking. self.set_speaking(false)?; |