Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feat/optional-ses…
Browse files Browse the repository at this point in the history
…sion-name
  • Loading branch information
nemosupremo committed Aug 14, 2023
2 parents 2919f25 + 56b9454 commit c553513
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html),
specifically the [variant used by Rust](http://doc.crates.io/manifest.html#the-version-field).

## unreleased
### Changed
- Ignore unexpected SDP lines.

## [0.1.5] - 2022-10-28
### Changed
- Fix some clippy warnings.
Expand Down
49 changes: 30 additions & 19 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::*;
#[derive(Debug, PartialEq, Eq)]
pub enum ParserError {
/// The given line started with an unexpected character.
#[deprecated(note = "This is no longer considered an error.")]
UnexpectedLine(usize, u8),
/// The given line was not formatted correctly.
InvalidLineFormat(usize, &'static str),
Expand Down Expand Up @@ -58,6 +59,7 @@ impl std::fmt::Display for ParserError {
use std::convert::TryFrom;

match *self {
#[allow(deprecated)]
ParserError::UnexpectedLine(line, c) => {
if let Ok(c) = char::try_from(c as u32) {
write!(f, "Unexpected line {} starting with '{}'", line, c)
Expand Down Expand Up @@ -368,8 +370,10 @@ impl Media {
) -> Result<Option<Media>, ParserError> {
let media = match lines.next()? {
None => return Ok(None),
Some(line) if line.key == b'm' => Media::parse_m_line(&line)?,
Some(line) => return Err(ParserError::UnexpectedLine(line.n, line.key)),
Some(line) => {
assert_eq!(line.key, b'm');
Media::parse_m_line(&line)?
}
};

// As with Session::parse, be more permissive about order than RFC 8866.
Expand Down Expand Up @@ -412,7 +416,7 @@ impl Media {
// - Can exist not at all, once or multiple times
b'a' => attributes.push(Attribute::parse(&line)?),

o => return Err(ParserError::UnexpectedLine(line.n, o)),
_ => (),
}
}

Expand Down Expand Up @@ -534,10 +538,9 @@ impl Session {
// Parse repeat lines
// - Can exist not at all, once or multiple times
b'r' => {
let t = times
.last_mut()
.ok_or(ParserError::UnexpectedLine(line.n, b't'))?;
t.repeats.push(Repeat::parse(&line)?);
if let Some(t) = times.last_mut() {
t.repeats.push(Repeat::parse(&line)?);
}
}

// Parse zones line:
Expand All @@ -562,7 +565,7 @@ impl Session {
// - Can exist not at all, once or multiple times
b'a' => attributes.push(Attribute::parse(&line)?),

o => return Err(ParserError::UnexpectedLine(line.n, o)),
_ => (),
}
}

Expand Down Expand Up @@ -840,17 +843,6 @@ a=fingerprint:sha-256 3A:96:6D:57:B2:C2:C7:61:A0:46:3E:1C:97:39:D3:F7:0A:88:A0:B
Session::parse(b"v\n").unwrap_err();
}

#[test]
fn unexpected_line_err() {
match Session::parse(b"v=0\r\n*=asdf\r\n") {
Err(ParserError::UnexpectedLine(line, c)) => {
assert_eq!(line, 2);
assert_eq!(c, b'*');
}
o => panic!("bad result: {:#?}", o),
}
}

#[test]
fn parse_sdp_real_camera() {
let sdp = b"v=0\r
Expand Down Expand Up @@ -951,6 +943,25 @@ a=control:track1\r
let _parsed = Session::parse(&sdp[..]).unwrap();
}

#[test]
fn parse_sdp_data_after_media() {
let sdp = b"v=0\r
o=- 1691154453 1 IN IP4 192.168.1.100\r
i=Pagos\r
a=type:broadcast\r
s=RandD2\r
m=video 15002 RTP/AVP 97\r
a=range:npt=0-\r
a=rtpmap:97 H264/90000\r
a=fmtp:97 profile-level-id=4D4029; packetization-mode=1; sprop-parameter-sets=Z01AKZZUBQHsgA==,aO44gA==\r
a=framerate:15.000\r
a=control:rtsp://192.168.1.20/camera1.sdp\r
c=IN IP4 0.0.0.0\r
t=0 0\r
";
let _parsed = Session::parse(&sdp[..]).unwrap();
}

#[test]
fn parse_sdp_without_session_name() {
let sdp = b"v=0\r
Expand Down

0 comments on commit c553513

Please sign in to comment.