diff --git a/src/builder.rs b/src/builder.rs index fc15e4b..f4ceb9a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -35,7 +35,7 @@ pub enum RtpWriteError { pub struct RtpPacketBuilder { padding: Option, csrcs: smallvec::SmallVec<[u32; 15]>, - marker: bool, + marker_bit: bool, payload_type: u8, sequence_number: u16, timestamp: u32, @@ -56,7 +56,7 @@ impl RtpPacketBuilder { Self { padding: None, csrcs: smallvec::smallvec![], - marker: false, + marker_bit: false, // set to an invalid value to force the user to update payload_type: 0xff, sequence_number: 0, @@ -92,8 +92,14 @@ impl RtpPacketBuilder { } /// Set the marker bit for this packet. - pub fn marker(mut self, marker: bool) -> Self { - self.marker = marker; + #[deprecated = "Use `marker_bit()` instead"] + pub fn marker(self, marker: bool) -> Self { + self.marker_bit(marker) + } + + /// Set the marker bit for this packet. + pub fn marker_bit(mut self, marker_bit: bool) -> Self { + self.marker_bit = marker_bit; self } @@ -184,7 +190,7 @@ impl RtpPacketBuilder { buf[0] = byte; let mut byte = self.payload_type & 0x7f; - if self.marker { + if self.marker_bit { byte |= 0x80; } buf[1] = byte; @@ -589,7 +595,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 0); - assert!(!rtp.marker()); + assert!(!rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0); assert_eq!(rtp.timestamp(), 0x0); @@ -606,7 +612,7 @@ mod tests { let mut vec = vec![]; let builder = RtpPacketBuilder::new() .payload_type(96) - .marker(true) + .marker_bit(true) .sequence_number(0x0102) .timestamp(0x03040506) .ssrc(0x0708090a) @@ -624,7 +630,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 1); - assert!(rtp.marker()); + assert!(rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -698,7 +704,7 @@ mod tests { let extension_data = [1, 2, 3, 4, 5, 6, 7, 8]; let builder = RtpPacketBuilder::new() .payload_type(96) - .marker(true) + .marker_bit(true) .sequence_number(0x0102) .timestamp(0x03040506) .ssrc(0x0708090a) @@ -717,7 +723,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 1); - assert!(rtp.marker()); + assert!(rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -738,7 +744,7 @@ mod tests { let payload_data = [1, 2, 3, 4, 5, 6, 7, 8]; let builder = RtpPacketBuilder::new() .payload_type(96) - .marker(true) + .marker_bit(true) .sequence_number(0x0102) .timestamp(0x03040506) .ssrc(0x0708090a) @@ -759,7 +765,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), Some(7)); assert_eq!(rtp.n_csrcs(), 1); - assert!(rtp.marker()); + assert!(rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -1011,7 +1017,7 @@ mod tests { let payload_data = TestPayload(vec![11, 12, 13, 14, 15, 16, 17, 18]); let builder = RtpPacketBuilder::new() .payload_type(96) - .marker(true) + .marker_bit(true) .sequence_number(0x0102) .timestamp(0x03040506) .ssrc(0x0708090a) @@ -1028,7 +1034,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), Some(7)); assert_eq!(rtp.n_csrcs(), 1); - assert!(rtp.marker()); + assert!(rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); diff --git a/src/edit.rs b/src/edit.rs index dadfcc0..e5ea493 100644 --- a/src/edit.rs +++ b/src/edit.rs @@ -30,8 +30,14 @@ impl<'a> RtpPacketMut<'a> { } /// Change the marker bit of this packet. + #[deprecated = "Use `set_marker_bit()` instead"] pub fn set_marker(&mut self, marker: bool) { - if marker { + self.set_marker_bit(marker); + } + + /// Change the marker bit of this packet. + pub fn set_marker_bit(&mut self, marker_bit: bool) { + if marker_bit { self.data[1] |= 0x80; } else { self.data[1] &= 0x7f; @@ -116,7 +122,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 0); - assert!(!rtp.marker()); + assert!(!rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -124,8 +130,8 @@ mod tests { assert_eq!(rtp.csrc().count(), 0); assert_eq!(rtp.extension(), None); assert_eq!(rtp.payload(), &[]); - rtp.set_marker(true); - assert!(rtp.marker()); + rtp.set_marker_bit(true); + assert!(rtp.marker_bit()); rtp.set_payload_type(12).unwrap(); assert_eq!(rtp.payload_type(), 12); rtp.set_sequence_number(0x9876); diff --git a/src/packet.rs b/src/packet.rs index eec6754..784a1ad 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -45,7 +45,7 @@ impl<'a> fmt::Debug for RtpPacket<'a> { f.debug_struct("RtpPacket") .field("version", &self.version()) - .field("marker", &self.marker()) + .field("marker_bit", &self.marker_bit()) .field("payload_type", &self.payload_type()) .field("sequence_number", &self.sequence_number()) .field("timestamp", &self.timestamp()) @@ -141,7 +141,8 @@ impl<'a> RtpPacket<'a> { (self.data[0] & 0b1100_0000) >> 6 } - fn padding_bit(&self) -> bool { + /// Returns whether the padding bit is set for this packet. + pub fn padding_bit(&self) -> bool { self.data[0] & 0b0010_0000 != 0 } @@ -167,7 +168,14 @@ impl<'a> RtpPacket<'a> { /// Returns whether the marker bit is set for this packet. The meaning of the marker bit /// is payload-specific. + #[deprecated = "Use `marker_bit()` instead"] pub fn marker(&self) -> bool { + self.marker_bit() + } + + /// Returns whether the marker bit is set for this packet. The meaning of the marker bit + /// is payload-specific. + pub fn marker_bit(&self) -> bool { (self.data[1] & 0b1000_0000) != 0 } @@ -266,7 +274,7 @@ impl<'a> RtpPacket<'a> { /// any padding bytes). Any aspect of the returned builder can be modified. pub fn as_builder(&'a self) -> crate::RtpPacketBuilder<&'a [u8], &'a [u8]> { let mut builder = crate::RtpPacketBuilder::new() - .marker(self.marker()) + .marker_bit(self.marker_bit()) .payload_type(self.payload_type()) .sequence_number(self.sequence_number()) .timestamp(self.timestamp()) @@ -298,7 +306,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 0); - assert!(!rtp.marker()); + assert!(!rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -334,7 +342,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 1); - assert!(!rtp.marker()); + assert!(!rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -373,7 +381,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 0); - assert!(!rtp.marker()); + assert!(!rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -428,7 +436,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), None); assert_eq!(rtp.n_csrcs(), 0); - assert!(!rtp.marker()); + assert!(!rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506); @@ -450,7 +458,7 @@ mod tests { assert_eq!(rtp.version(), 2); assert_eq!(rtp.padding(), Some(2)); assert_eq!(rtp.n_csrcs(), 0); - assert!(!rtp.marker()); + assert!(!rtp.marker_bit()); assert_eq!(rtp.payload_type(), 96); assert_eq!(rtp.sequence_number(), 0x0102); assert_eq!(rtp.timestamp(), 0x03040506);