feat: add sequence number
This commit is contained in:
parent
4a364f3826
commit
cf3c7e3c1b
|
@ -43,9 +43,10 @@ impl UdpHandle {
|
|||
/// Constructs and sends encoded opus rtp data.
|
||||
///
|
||||
/// Automatically makes an [RtpPacket](discorrtp::rtp::RtpPacket), encrypts it and sends it.
|
||||
pub async fn send_opus_data(&self, sequence: u16, timestamp: u32, payload: Vec<u8>) {
|
||||
let data_lock = self.data.read().await;
|
||||
let ssrc = data_lock.ready_data.clone().unwrap().ssrc;
|
||||
pub async fn send_opus_data(&self, timestamp: u32, payload: Vec<u8>) {
|
||||
let ssrc = self.data.read().await.ready_data.clone().unwrap().ssrc.clone();
|
||||
let sequence_number = self.data.read().await.last_sequence_number.clone().wrapping_add(1);
|
||||
self.data.write().await.last_sequence_number = sequence_number;
|
||||
|
||||
let payload_len = payload.len();
|
||||
|
||||
|
@ -59,14 +60,12 @@ impl UdpHandle {
|
|||
marker: 0,
|
||||
payload_type: discortp::rtp::RtpType::Dynamic(120),
|
||||
// Actually variable
|
||||
sequence: sequence.into(),
|
||||
sequence: sequence_number.into(),
|
||||
timestamp: timestamp.into(),
|
||||
ssrc,
|
||||
payload,
|
||||
};
|
||||
|
||||
debug!("VUDP: Constructed udp data: {:?}", rtp_data);
|
||||
|
||||
let mut buffer = Vec::new();
|
||||
|
||||
let buffer_size = payload_len + RTP_HEADER_SIZE as usize;
|
||||
|
@ -98,9 +97,7 @@ impl UdpHandle {
|
|||
) -> Vec<u8> {
|
||||
let payload = packet.payload();
|
||||
|
||||
let data_lock = self.data.read().await;
|
||||
|
||||
let session_description_result = data_lock.session_description.clone();
|
||||
let session_description_result = self.data.read().await.session_description.clone();
|
||||
|
||||
if session_description_result.is_none() {
|
||||
// FIXME: Make this function reutrn a result with a proper error type for these kinds
|
||||
|
@ -286,9 +283,7 @@ impl UdpHandler {
|
|||
let ciphertext = buf[12..buf.len()].to_vec();
|
||||
trace!("VUDP: Parsed packet as rtp!");
|
||||
|
||||
let data_lock = self.data.read().await;
|
||||
|
||||
let session_description_result = data_lock.session_description.clone();
|
||||
let session_description_result = self.data.read().await.session_description.clone();
|
||||
|
||||
if session_description_result.is_none() {
|
||||
warn!("VUDP: Received encyrpted voice data, but no encryption key, CANNOT DECRYPT!");
|
||||
|
|
|
@ -10,5 +10,7 @@ pub struct VoiceData {
|
|||
pub session_description: Option<SessionDescription>,
|
||||
pub user_id: Snowflake,
|
||||
pub session_id: String,
|
||||
/// The last sequence number we used, has to be incremeted by one every time we send a message
|
||||
pub last_sequence_number: u16,
|
||||
pub ip_discovery: Option<IpDiscovery>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue