Skip to content

Commit

Permalink
refactor(h264): replace unwrap with expects
Browse files Browse the repository at this point in the history
  • Loading branch information
thatdevsherry committed Nov 9, 2022
1 parent 78dafd9 commit d58bb58
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/codec/h264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,32 @@ impl NalParser {
if last_piece.ends_with(&[0x00]) {
let last_byte_index = last_piece.len() - 1;
last_piece.truncate(last_byte_index);
self.nals.last_mut().unwrap().len -= 1;
self.nals
.last_mut()
.expect("nals should be non-empty because pieces is non-empty")
.len -= 1;
data_copy.advance(3);
let nal_header = NalHeader::new(data_copy[0]).expect("Header w/o F bit is valid");
self.start_rtp_nal(nal_header)?;
data_copy.advance(1);
}
} else if !self.pieces.is_empty() && data_copy.first().unwrap() == &0x00 {
} else if !self.pieces.is_empty()
&& data_copy
.first()
.expect("rtp payload should be non-empty because it passes through a len() check")
== &0x00
{
let last_piece = self
.pieces
.last_mut()
.expect("pieces should be non-empty because break_apart_nals checked for it to be non-empty");
if last_piece.ends_with(&[0x00, 0x00]) {
let last_byte_index = last_piece.len() - 1;
last_piece.truncate(last_byte_index - 1);
self.nals.last_mut().unwrap().len -= 1;
self.nals
.last_mut()
.expect("nals should be non-empty because pieces is non-empty")
.len -= 1;
data_copy.advance(2);
let nal_header = NalHeader::new(data_copy[0]).expect("Header w/o F bit is valid");
self.start_rtp_nal(nal_header)?;
Expand Down

0 comments on commit d58bb58

Please sign in to comment.