Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make some getters public, add various new mutable/immutable APIs and improve docs a bit #14

Merged
merged 8 commits into from
Feb 23, 2024
9 changes: 6 additions & 3 deletions src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ impl<'a> RtpPacket<'a> {
}
}

fn extension_bit(&self) -> bool {
/// Returns whether the extension bit is set for this packet.
pub fn extension_bit(&self) -> bool {
ystreet marked this conversation as resolved.
Show resolved Hide resolved
(self.data[0] & 0b0001_0000) != 0
}

Expand Down Expand Up @@ -213,7 +214,8 @@ impl<'a> RtpPacket<'a> {
Self::MIN_RTP_PACKET_LEN + (self.n_csrcs() as usize) * 4
}

fn extension_len(&self) -> usize {
/// Returns the length of the extension data in this packet.
pub fn extension_len(&self) -> usize {
ystreet marked this conversation as resolved.
Show resolved Hide resolved
if self.extension_bit() {
let offset = self.extension_offset();
4 * ((self.data[offset + 2] as usize) << 8 | self.data[offset + 3] as usize)
Expand All @@ -235,7 +237,8 @@ impl<'a> RtpPacket<'a> {
}
}

fn payload_offset(&self) -> usize {
/// Returns the offset of the payload in this packet relative to the beginning of the packet.
pub fn payload_offset(&self) -> usize {
ystreet marked this conversation as resolved.
Show resolved Hide resolved
self.extension_offset()
+ if self.extension_bit() {
self.extension_len() + 4
Expand Down