[domistream] RTSP server: session state machine, DESCRIBE writer, strict ANNOUNCE parser, response encoder and request framer; test fixes (escaped CRLF in alloc_caps, CSeq test state, clippy)
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
//! The DESCRIBE answer (`docs/PROTOCOL.md` 2.3, 2.5): what the host offers, written as the SDP lines the client
|
||||
//! reads with [`crate::rtsp::HostCapabilities::from_sdp`].
|
||||
|
||||
use crate::rtsp::sdp::{EncryptionFlags, FeatureFlags, OpusConfig};
|
||||
use crate::rtsp::sdp::{EncryptionFlags, FeatureFlags, MAX_OPUS_CONFIGS, OpusConfig, parse_surround_params};
|
||||
use crate::util::{cap, malformed};
|
||||
use crate::{Error, Result};
|
||||
|
||||
/// The `sprop-parameter-sets` line a known host sends; its value is not used by clients (`docs/PROTOCOL.md` 2.3).
|
||||
const SPROP_LINE: &str = "sprop-parameter-sets=AAAAAU";
|
||||
|
||||
/// What the host offers: written into the DESCRIBE answer, and checked against the client's ANNOUNCE.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct HostOffer {
|
||||
@@ -21,7 +25,7 @@ pub struct HostOffer {
|
||||
/// AV1: `a=rtpmap:98 AV1/90000`.
|
||||
pub av1: bool,
|
||||
/// HDR. No DESCRIBE line is known for it (serverinfo again); used only to check ANNOUNCE: without it, a
|
||||
/// `dynamicRangeMode` other than 0 (SDR [M]) is refused.
|
||||
/// `dynamicRangeMode` other than 0 (SDR \[M\]) is refused.
|
||||
pub hdr: bool,
|
||||
/// 4:4:4 chroma. No DESCRIBE line is known; used only to check ANNOUNCE.
|
||||
pub yuv444: bool,
|
||||
@@ -31,7 +35,7 @@ pub struct HostOffer {
|
||||
pub opus_configs: Vec<OpusConfig>,
|
||||
}
|
||||
|
||||
/// Builds the DESCRIBE payload for `offer`, in the line order a known host uses (`docs/PROTOCOL.md` 2.5 [M]):
|
||||
/// Builds the DESCRIBE payload for `offer`, in the line order a known host uses (`docs/PROTOCOL.md` 2.5 \[M\]):
|
||||
/// feature flags, encryption, `sprop-parameter-sets`, reference invalidation, AV1, H.264, then one
|
||||
/// `surround-params` line per Opus configuration. CRLF line ends.
|
||||
///
|
||||
@@ -41,6 +45,41 @@ pub struct HostOffer {
|
||||
/// streams); [`Error::TooLarge`] over [`crate::rtsp::sdp::MAX_OPUS_CONFIGS`]; [`Error::Unsupported`] when no codec
|
||||
/// is offered.
|
||||
pub fn build_describe(offer: &HostOffer) -> Result<Vec<u8>> {
|
||||
let _ = offer;
|
||||
Err(Error::Unimplemented)
|
||||
if !(offer.h264 || offer.hevc || offer.av1) {
|
||||
return Err(Error::Unsupported { what: "a video codec in the host offer" });
|
||||
}
|
||||
cap("describe opus configurations", MAX_OPUS_CONFIGS, offer.opus_configs.len())?;
|
||||
let mut out = String::with_capacity(256 + 48 * offer.opus_configs.len());
|
||||
let mut line = |text: &str| {
|
||||
out.push_str(text);
|
||||
out.push_str("\r\n");
|
||||
};
|
||||
line(&format!("a=x-ss-general.featureFlags:{}", offer.feature_flags.0));
|
||||
line(&format!("a=x-ss-general.encryptionSupported:{}", offer.encryption_supported.0));
|
||||
line(SPROP_LINE);
|
||||
if offer.reference_frame_invalidation {
|
||||
line("a=x-nv-video[0].refPicInvalidation:1");
|
||||
}
|
||||
if offer.av1 {
|
||||
line("a=rtpmap:98 AV1/90000");
|
||||
}
|
||||
if offer.h264 {
|
||||
line("a=fmtp:96 packetization-mode=1");
|
||||
}
|
||||
for config in &offer.opus_configs {
|
||||
line(&format!("a=fmtp:97 surround-params={}", surround_digits(config)?));
|
||||
}
|
||||
Ok(out.into_bytes())
|
||||
}
|
||||
|
||||
/// `surround-params` digits for `config` (`docs/PROTOCOL.md` 2.3): channel count, stream count, coupled count, then
|
||||
/// one mapping digit per channel. The client's own parser checks the result, so nothing it refuses is written.
|
||||
fn surround_digits(config: &OpusConfig) -> Result<String> {
|
||||
let mut digits = String::with_capacity(3 + config.mapping.len());
|
||||
for n in [config.channels, config.streams, config.coupled_streams].iter().chain(&config.mapping) {
|
||||
let d = char::from_digit(u32::from(*n), 10).ok_or(malformed("surround-params: a value above 9"))?;
|
||||
digits.push(d);
|
||||
}
|
||||
parse_surround_params(&digits)?;
|
||||
Ok(digits)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user