aboutsummaryrefslogtreecommitdiff
path: root/src/voice
diff options
context:
space:
mode:
authorNikita Pekin <[email protected]>2018-01-24 21:45:43 -0500
committerZeyla Hellyer <[email protected]>2018-01-24 18:45:43 -0800
commite4612acf58dc42fdc32094426c14274bd61203dd (patch)
tree8f1d8e5f23fd6214a1025227110a868488c1fffa /src/voice
parentTrim after splitting at the mention-end. (#256) (diff)
downloadserenity-e4612acf58dc42fdc32094426c14274bd61203dd.tar.xz
serenity-e4612acf58dc42fdc32094426c14274bd61203dd.zip
Strip RTP header extensions from voice stream
Add code to strip RTP header extensions from an incoming voice stream, if they are present. See https://tools.ietf.org/html/rfc5285 for more info.
Diffstat (limited to 'src/voice')
-rw-r--r--src/voice/connection.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/voice/connection.rs b/src/voice/connection.rs
index 431084d..1b018cb 100644
--- a/src/voice/connection.rs
+++ b/src/voice/connection.rs
@@ -1,4 +1,4 @@
-use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
+use byteorder::{BigEndian, ByteOrder, LittleEndian, ReadBytesExt, WriteBytesExt};
use internal::prelude::*;
use internal::ws_impl::{ReceiverExt, SenderExt};
use internal::Timer;
@@ -192,7 +192,7 @@ impl Connection {
nonce.0[..HEADER_LEN]
.clone_from_slice(&packet[..HEADER_LEN]);
- if let Ok(decrypted) =
+ if let Ok(mut decrypted) =
secretbox::open(&packet[HEADER_LEN..], &nonce, &self.key) {
let channels = opus_packet::get_nb_channels(&decrypted)?;
@@ -201,6 +201,28 @@ impl Connection {
|| OpusDecoder::new(SAMPLE_RATE, channels).unwrap(),
);
+ // Strip RTP Header Extensions (one-byte)
+ if decrypted[0] == 0xBE && decrypted[1] == 0xDE {
+ // Read the length bytes as a big-endian u16.
+ let header_extension_len = BigEndian::read_u16(&decrypted[2..4]);
+ let mut offset = 4;
+ for _ in 0..header_extension_len {
+ let byte = decrypted[offset];
+ offset += 1;
+ if byte == 0 {
+ continue;
+ }
+
+ offset += 1 + (0b1111 & (byte >> 4)) as usize;
+ }
+
+ while decrypted[offset] == 0 {
+ offset += 1;
+ }
+
+ decrypted = decrypted.split_off(offset);
+ }
+
let len = entry.decode(&decrypted, &mut buffer, false)?;
let is_stereo = channels == Channels::Stereo;