Skip to content

Commit 33652b3

Browse files
rogurotusrainliu
authored andcommitted
fix
1 parent 60a27ad commit 33652b3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

rtp/src/header.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,15 @@ impl Header {
342342
/// SetExtension sets an RTP header extension
343343
pub fn set_extension(&mut self, id: u8, payload: Bytes) -> Result<(), Error> {
344344
if self.extension {
345-
match self.extension_profile {
345+
let extension_profile_len = match self.extension_profile {
346346
EXTENSION_PROFILE_ONE_BYTE => {
347347
if !(1..=14).contains(&id) {
348348
return Err(Error::ErrRfc8285oneByteHeaderIdrange);
349349
}
350350
if payload.len() > 16 {
351351
return Err(Error::ErrRfc8285oneByteHeaderSize);
352352
}
353+
1
353354
}
354355
EXTENSION_PROFILE_TWO_BYTE => {
355356
if id < 1 {
@@ -358,11 +359,13 @@ impl Header {
358359
if payload.len() > 255 {
359360
return Err(Error::ErrRfc8285twoByteHeaderSize);
360361
}
362+
2
361363
}
362364
_ => {
363365
if id != 0 {
364366
return Err(Error::ErrRfc3550headerIdrange);
365367
}
368+
0
366369
}
367370
};
368371

@@ -374,18 +377,30 @@ impl Header {
374377
{
375378
extension.payload = payload;
376379
} else {
380+
let extension_padding = (payload.len() + extension_profile_len) % 4;
381+
if self.extensions_padding < extension_padding {
382+
self.extensions_padding = self.extensions_padding + 4 - extension_padding;
383+
} else {
384+
self.extensions_padding -= extension_padding
385+
}
377386
self.extensions.push(Extension { id, payload });
378387
}
379388
} else {
380389
// No existing header extensions
381390
self.extension = true;
382-
391+
let mut extension_profile_len = 0;
383392
self.extension_profile = match payload.len() {
384-
0..=16 => EXTENSION_PROFILE_ONE_BYTE,
385-
17..=255 => EXTENSION_PROFILE_TWO_BYTE,
393+
0..=16 => { extension_profile_len = 1 ; EXTENSION_PROFILE_ONE_BYTE},
394+
17..=255 => { extension_profile_len = 2; EXTENSION_PROFILE_TWO_BYTE},
386395
_ => self.extension_profile,
387396
};
388397

398+
let extension_padding = (payload.len() + extension_profile_len) % 4;
399+
if self.extensions_padding < extension_padding {
400+
self.extensions_padding = self.extensions_padding + 4 - extension_padding;
401+
} else {
402+
self.extensions_padding -= extension_padding
403+
}
389404
self.extensions.push(Extension { id, payload });
390405
}
391406
Ok(())

0 commit comments

Comments
 (0)