Skip to content

Commit

Permalink
Merge pull request #454 from oto313/feature/fix-calculation-rtp-heade…
Browse files Browse the repository at this point in the history
…r-size

Fix of rtp header size calculation
  • Loading branch information
yngrtc authored Jun 12, 2023
2 parents f33c5f5 + 81c7b56 commit 92d376b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions media/src/io/ivf_writer/ivf_writer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn test_ivf_writer_add_packet_and_close() -> Result<()> {
csrc: vec![],
padding: false,
extensions: vec![],
extensions_padding: 0,
},
payload: raw_valid_pkt.slice(20..),
};
Expand Down Expand Up @@ -51,6 +52,7 @@ fn test_ivf_writer_add_packet_and_close() -> Result<()> {
csrc: vec![],
padding: raw_mid_part_pkt.len() % 4 != 0,
extensions: vec![],
extensions_padding: 0,
},
payload: raw_mid_part_pkt.slice(20..),
};
Expand Down Expand Up @@ -78,6 +80,7 @@ fn test_ivf_writer_add_packet_and_close() -> Result<()> {
csrc: vec![],
padding: raw_keyframe_pkt.len() % 4 != 0,
extensions: vec![],
extensions_padding: 0,
},
payload: raw_keyframe_pkt.slice(20..),
};
Expand Down
1 change: 1 addition & 0 deletions media/src/io/ogg_writer/ogg_writer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn test_ogg_writer_add_packet_and_close() -> Result<()> {
csrc: vec![],
padding: false,
extensions: vec![],
extensions_padding: 0,
},
payload: raw_pkt.slice(20..),
};
Expand Down
8 changes: 6 additions & 2 deletions rtp/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct Header {
pub csrc: Vec<u32>,
pub extension_profile: u16,
pub extensions: Vec<Extension>,
pub extensions_padding: usize,
}

impl Unmarshal for Header {
Expand Down Expand Up @@ -97,7 +98,7 @@ impl Unmarshal for Header {
for _ in 0..cc {
csrc.push(raw_packet.get_u32());
}

let mut extensions_padding: usize = 0;
let (extension_profile, extensions) = if extension {
let expected = curr_offset + 4;
if raw_packet_len < expected {
Expand All @@ -123,6 +124,7 @@ impl Unmarshal for Header {
if b == 0x00 {
// padding
curr_offset += 1;
extensions_padding += 1;
continue;
}

Expand All @@ -149,6 +151,7 @@ impl Unmarshal for Header {
if b == 0x00 {
// padding
curr_offset += 1;
extensions_padding += 1;
continue;
}

Expand Down Expand Up @@ -194,6 +197,7 @@ impl Unmarshal for Header {
csrc,
extension_profile,
extensions,
extensions_padding,
})
}
}
Expand All @@ -203,7 +207,7 @@ impl MarshalSize for Header {
fn marshal_size(&self) -> usize {
let mut head_size = 12 + (self.csrc.len() * CSRC_LENGTH);
if self.extension {
let extension_payload_len = self.get_extension_payload_len();
let extension_payload_len = self.get_extension_payload_len() + self.extensions_padding;
let extension_payload_size = (extension_payload_len + 3) / 4;
head_size += 4 + extension_payload_size * 4;
}
Expand Down
1 change: 1 addition & 0 deletions rtp/src/packetizer/packetizer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fn test_packetizer_abs_send_time() -> Result<()> {
id: 1,
payload: Bytes::from_static(&[0x40, 0, 0]),
}],
extensions_padding: 0,
},
payload: Bytes::from_static(&[0x11, 0x12, 0x13, 0x14]),
};
Expand Down

0 comments on commit 92d376b

Please sign in to comment.