From 2530014cce41cad9eb06a88b062bb8d1722246db Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Mon, 9 May 2022 12:56:03 -0700 Subject: [PATCH] ignore unparseable rtptime values https://github.com/scottlamb/moonfire-nvr/issues/224 --- CHANGELOG.md | 6 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/client/parse.rs | 37 ++++++++++++++++++++++++----- src/client/testdata/bad_rtptime.txt | 9 +++++++ 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/client/testdata/bad_rtptime.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d658b8..ec070e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## `v0.3.10` (2022-05-09) + +* ignore unparseable `rtptime` values in the `PLAY` response's `RTP-Info` header. + This improves compatibility with the OMNY M5S2A 2812 camera, as described in + [scottlamb/moonfire-nvr#224](https://github.com/scottlamb/moonfire-nvr/issues/224). + ## `v0.3.9` (2022-04-12) * camera interop: eliminate `bad clockrate in rtpmap` errors with cameras that diff --git a/Cargo.lock b/Cargo.lock index 95ee9ea..18c3326 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -910,7 +910,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "retina" -version = "0.3.9" +version = "0.3.10" dependencies = [ "anyhow", "base64", diff --git a/Cargo.toml b/Cargo.toml index 5141338..80da7c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "retina" -version = "0.3.9" +version = "0.3.10" authors = ["Scott Lamb "] license = "MIT/Apache-2.0" edition = "2018" diff --git a/src/client/parse.rs b/src/client/parse.rs index b914182..eddcdd3 100644 --- a/src/client/parse.rs +++ b/src/client/parse.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use bytes::Bytes; -use log::debug; +use log::{debug, warn}; use sdp_types::Media; use std::{net::IpAddr, num::NonZeroU16}; use url::Url; @@ -640,11 +640,10 @@ pub(crate) fn parse_play( .map_err(|_| format!("bad seq {:?}", value))?; state.initial_seq = Some(seq); } - "rtptime" => { - let rtptime = u32::from_str_radix(value, 10) - .map_err(|_| format!("bad rtptime {:?}", value))?; - state.initial_rtptime = Some(rtptime); - } + "rtptime" => match u32::from_str_radix(value, 10) { + Ok(v) => state.initial_rtptime = Some(v), + Err(_) => warn!("Unparseable rtptime in RTP-Info header {:?}", rtp_info), + }, "ssrc" => { let ssrc = u32::from_str_radix(value, 16) .map_err(|_| format!("Unparseable ssrc {}", value))?; @@ -1063,6 +1062,32 @@ mod tests { }; } + /// Simulates a negative `rtptime` value in the `PLAY` response, as returned by the OMNY M5S2A + /// 2812 in [scottlamb/moonfire-nvr#224](https://github.com/scottlamb/moonfire-nvr/issues/224). + /// + /// The rest of the data is copied from the `bunny` test above. + /// + /// This is currently treated as if the `rtptime` parameter were absent. + #[test] + fn bad_rtptime() { + let prefix = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; + let mut p = parse_describe(prefix, include_bytes!("testdata/bunny_describe.txt")).unwrap(); + p.streams[0].state = StreamState::Init(StreamStateInit::default()); + super::parse_play( + &response(include_bytes!("testdata/bad_rtptime.txt")), + &mut p, + ) + .unwrap(); + match p.streams[0].state { + StreamState::Init(state) => { + assert_eq!(state.initial_rtptime, None); + assert_eq!(state.initial_seq, Some(1)); + assert_eq!(state.ssrc, None); + } + _ => panic!(), + }; + } + #[test] fn foscam() { // DESCRIBE. diff --git a/src/client/testdata/bad_rtptime.txt b/src/client/testdata/bad_rtptime.txt new file mode 100644 index 0000000..1aff116 --- /dev/null +++ b/src/client/testdata/bad_rtptime.txt @@ -0,0 +1,9 @@ +RTSP/1.0 200 OK +Notes: copied from bunny_play.txt; modified to simulate a bad rtptime value as in https://github.com/scottlamb/moonfire-nvr/issues/224 +RTP-Info: url=trackID=1;seq=1;rtptime=-1,url=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov/trackID=2;seq=1;rtptime=-1 +CSeq: 3 +Server: Wowza Streaming Engine 4.8.10 build20210217143515 +Cache-Control: no-cache +Range: npt=0.0-596.48 +Session: 551045787;timeout=60 +