ignore trailing spaces in rtpmap attribute

https://github.com/scottlamb/moonfire-nvr/issues/213
This commit is contained in:
Scott Lamb 2022-04-04 19:34:22 -07:00
parent 27bc8caf04
commit 31080f324d
2 changed files with 41 additions and 1 deletions

View File

@ -268,7 +268,8 @@ fn parse_media(base_url: &Url, media_description: &Media) -> Result<Stream, Stri
let v = a
.value
.as_ref()
.ok_or_else(|| "rtpmap attribute with no value".to_string())?;
.ok_or_else(|| "rtpmap attribute with no value".to_string())?
.trim_end_matches(" ");
// https://tools.ietf.org/html/rfc8866#section-6.6
// rtpmap-value = payload-type SP encoding-name
// "/" clock-rate [ "/" encoding-params ]
@ -277,6 +278,8 @@ fn parse_media(base_url: &Url, media_description: &Media) -> Result<Stream, Stri
// clock-rate = integer
// encoding-params = channels
// channels = integer
//
// At least one camera (improperly) sends a trailing space; trim this.
let (rtpmap_payload_type, v) = v
.split_once(' ')
.ok_or_else(|| "invalid rtmap attribute".to_string())?;
@ -1340,4 +1343,19 @@ mod tests {
.unwrap();
assert_eq!(p.streams.len(), 1);
}
/// Tests parsing SDP from an "IPCAM C9F0SeZ3N0PbL0" [sic], as quoted in
/// [imoonfire-nvr#213](https://github.com/scottlamb/moonfire-nvr/issues/213).
///
/// This camera notably sends a trailing space in its `rtpmap` attribute.
#[test]
fn ipcam() {
// DESCRIBE.
let p = parse_describe(
"rtsp://camera",
include_bytes!("testdata/ipcam_describe.txt"),
)
.unwrap();
assert_eq!(p.streams.len(), 1);
}
}

22
src/client/testdata/ipcam_describe.txt vendored Normal file
View File

@ -0,0 +1,22 @@
RTSP/1.0 200 OK
CSeq: 1
Content-Length: 476
Content-Type: application/sdp
x-notes: This camera claims manufacturer IPCAM, model C9F0SeZ3N0PbL0, firmware V13.1.48.16.3-20200320.
x-notes: These headers are made up; the SDP is as returned by the camera.
v=0
o=- 38990265062388 38990265062388 IN IP4 192.168.1.67
s=RTSP Session
c=IN IP4 192.168.1.67
t=0 0
a=control:*
a=range:npt=0-
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=range:npt=0-
a=framerate:0S
a=fmtp:96 profile-level-id=4d0020; packetization-mode=1; sprop-parameter-sets=J00AII1qBQB5oQAAAwABAAADACiE,KO48gA==
a=Media_header:MEDIAINFO=494D4B48010100000400010000000000000000000000000000000000000000000000000000000000;
a=framerate:25
a=control:trackID=1