diff --git a/webrtc/src/peer_connection/peer_connection_internal.rs b/webrtc/src/peer_connection/peer_connection_internal.rs index 032cfde24..2d8c1d9d6 100644 --- a/webrtc/src/peer_connection/peer_connection_internal.rs +++ b/webrtc/src/peer_connection/peer_connection_internal.rs @@ -1050,17 +1050,15 @@ impl PeerConnectionInternal { let mut buf = vec![0u8; self.setting_engine.get_receive_mtu()]; let n = rtp_stream.read(&mut buf).await?; - let mut b = &buf[..n]; + let packet = rtp::packet::Packet::unmarshal(&mut &buf[..n]).unwrap(); let (mut mid, mut rid, mut rsid, payload_type) = handle_unknown_rtp_packet( - b, + &packet.header, mid_extension_id as u8, sid_extension_id as u8, rsid_extension_id as u8, )?; - let packet = rtp::packet::Packet::unmarshal(&mut b).unwrap(); - // TODO: Can we have attributes on the first packets? buffered_packets.push_back((packet, Attributes::new())); @@ -1092,7 +1090,7 @@ impl PeerConnectionInternal { if mid.is_empty() || (rid.is_empty() && rsid.is_empty()) { let (pkt, _) = rtp_interceptor.read(&mut buf, &a).await?; let (m, r, rs, _) = handle_unknown_rtp_packet( - &buf[..n], + &pkt.header, mid_extension_id as u8, sid_extension_id as u8, rsid_extension_id as u8, diff --git a/webrtc/src/rtp_transceiver/mod.rs b/webrtc/src/rtp_transceiver/mod.rs index d15c09886..e43b0e03e 100644 --- a/webrtc/src/rtp_transceiver/mod.rs +++ b/webrtc/src/rtp_transceiver/mod.rs @@ -14,7 +14,6 @@ use portable_atomic::{AtomicBool, AtomicU8}; use serde::{Deserialize, Serialize}; use smol_str::SmolStr; use tokio::sync::{Mutex, OnceCell}; -use util::Unmarshal; use crate::api::media_engine::MediaEngine; use crate::error::{Error, Result}; @@ -527,33 +526,30 @@ pub(crate) async fn satisfy_type_and_direction( /// handle_unknown_rtp_packet consumes a single RTP Packet and returns information that is helpful /// for demuxing and handling an unknown SSRC (usually for Simulcast) pub(crate) fn handle_unknown_rtp_packet( - buf: &[u8], + header: &rtp::header::Header, mid_extension_id: u8, sid_extension_id: u8, rsid_extension_id: u8, ) -> Result<(String, String, String, PayloadType)> { - let mut reader = buf; - let rp = rtp::packet::Packet::unmarshal(&mut reader)?; - - if !rp.header.extension { + if !header.extension { return Ok((String::new(), String::new(), String::new(), 0)); } - let payload_type = rp.header.payload_type; + let payload_type = header.payload_type; - let mid = if let Some(payload) = rp.header.get_extension(mid_extension_id) { + let mid = if let Some(payload) = header.get_extension(mid_extension_id) { String::from_utf8(payload.to_vec())? } else { String::new() }; - let rid = if let Some(payload) = rp.header.get_extension(sid_extension_id) { + let rid = if let Some(payload) = header.get_extension(sid_extension_id) { String::from_utf8(payload.to_vec())? } else { String::new() }; - let srid = if let Some(payload) = rp.header.get_extension(rsid_extension_id) { + let srid = if let Some(payload) = header.get_extension(rsid_extension_id) { String::from_utf8(payload.to_vec())? } else { String::new()