diff options
author | metamuffin <metamuffin@disroot.org> | 2024-11-19 15:28:29 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-11-19 15:28:29 +0100 |
commit | 8d02c52f770e5626a67dfdc47214fc23b744ac47 (patch) | |
tree | 4dc77317e407e1a1e45552870e257745656a40c6 /rtp/src/rtp.rs | |
parent | d40f5bc6ece18c8fa09013d2e47e500a9e333dcd (diff) | |
download | sip-rs-8d02c52f770e5626a67dfdc47214fc23b744ac47.tar sip-rs-8d02c52f770e5626a67dfdc47214fc23b744ac47.tar.bz2 sip-rs-8d02c52f770e5626a67dfdc47214fc23b744ac47.tar.zst |
more rtcp
Diffstat (limited to 'rtp/src/rtp.rs')
-rw-r--r-- | rtp/src/rtp.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/rtp/src/rtp.rs b/rtp/src/rtp.rs index a1ed166..581bc40 100644 --- a/rtp/src/rtp.rs +++ b/rtp/src/rtp.rs @@ -8,12 +8,15 @@ pub enum Error { Padding, } +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SSRC(pub u32); + pub struct RtpPacket<'a> { marker: bool, payload_type: u8, sequence: u16, timestamp: u32, - ssrc: u32, + ssrc: SSRC, csrc_count: u8, csrcs: [u32; 15], extension: Option<(u16, &'a [u8])>, @@ -37,20 +40,15 @@ impl<'a> RtpPacket<'a> { let marker = packet[1] >> 7 != 0; let payload_type = packet[1] & 0x7f; let sequence = u16::from_be_bytes([packet[2], packet[3]]); - let timestamp = u32::from_be_bytes([packet[4], packet[5], packet[6], packet[7]]); - let ssrc = u32::from_be_bytes([packet[8], packet[9], packet[10], packet[11]]); + let timestamp = u32::from_be_bytes(packet[4..8].try_into().unwrap()); + let ssrc = SSRC(u32::from_be_bytes(packet[8..12].try_into().unwrap())); let mut csrcs = [0u32; 15]; if packet.len() < 12 + csrc_count as usize * 4 { return Err(Error::Truncated); } for n in 0..csrc_count as usize { let off = 12 + n * 4; - csrcs[n] = u32::from_be_bytes([ - packet[off + 0], - packet[off + 1], - packet[off + 2], - packet[off + 3], - ]); + csrcs[n] = u32::from_be_bytes(packet[off..off + 4].try_into().unwrap()); } let mut offset = 12 + csrc_count as usize * 4; @@ -110,7 +108,7 @@ impl<'a> RtpPacket<'a> { out.push((self.payload_type & 0x7f) | ((self.marker as u8) << 7)); out.extend(self.sequence.to_be_bytes()); out.extend(self.timestamp.to_be_bytes()); - out.extend(self.ssrc.to_be_bytes()); + out.extend(self.ssrc.0.to_be_bytes()); out.extend( self.csrcs .into_iter() |