aboutsummaryrefslogtreecommitdiff
path: root/rtp/src/rtp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rtp/src/rtp.rs')
-rw-r--r--rtp/src/rtp.rs18
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()