Skip to content

Commit

Permalink
support cameras with no DESCRIBE Content-Type
Browse files Browse the repository at this point in the history
  • Loading branch information
scottlamb committed Jan 9, 2024
1 parent 77265a4 commit 1e4e3dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## unreleased

* attempt to support cameras that do not set `Content-Type` on
`DESCRIBE` responses

## `v0.4.6` (2023-12-29)

* add default User-Agent header
Expand Down
35 changes: 28 additions & 7 deletions src/client/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,25 @@ pub(crate) fn parse_describe(
request_url: Url,
response: &rtsp_types::Response<Bytes>,
) -> Result<Presentation, String> {
if !matches!(response.header(&rtsp_types::headers::CONTENT_TYPE), Some(v) if v.as_str() == "application/sdp")
{
return Err(format!(
"Describe response not of expected application/sdp content type: {:#?}",
&response
));
match response.header(&rtsp_types::headers::CONTENT_TYPE) {
Some(v) if v.as_str() == "application/sdp" => {}
Some(v) => {
let mut buf = vec![];
response.write(&mut buf).map_err(|e| e.to_string())?;
return Err(format!(
"DESCRIBE response at {} has unexpected content type {}:\n{:?}",
request_url.as_str(),
v,
MostlyAscii(&buf)
));
}
None => {
warn!(
"DESCRIBE response at {} has no content type; trying sdp anyway",
request_url.as_str()
);
}
}

let raw_sdp = MostlyAscii(&response.body()[..]);
let sdp = sdp_types::Session::parse(raw_sdp.0)
.map_err(|e| format!("Unable to parse SDP: {e}\n\n{raw_sdp:#?}",))?;
Expand Down Expand Up @@ -1179,6 +1190,16 @@ mod tests {
};
}

#[test]
fn missing_contenttype_describe() {
let prefix = "rtsp://192.168.1.101/live/test";
parse_describe(
prefix,
include_bytes!("testdata/missing_content_type_describe.txt"),
)
.unwrap();
}

/// 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).
///
Expand Down

0 comments on commit 1e4e3dd

Please sign in to comment.