[domistream] Implementation: HTTP, pairing, RTSP/SDP, ENet, control, input, RTP, FEC, video and audio receivers
Per PROTOCOL.md and the Wolf docs; interop with a real host is unverified. Strict, capped parsers throughout, shared helpers in util.rs. Where PROTOCOL.md says UNKNOWN the Wolf-documented behaviour is used. The audio receiver waits for the jitter budget before rebuilding a missing packet, so a late packet beats a rebuilt one.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
//! `GET /launch` and `GET /resume` (`docs/PROTOCOL.md` 1.4).
|
||||
|
||||
use super::HttpRequest;
|
||||
use crate::SessionKeys;
|
||||
use super::{HttpRequest, Scheme, build, check_unique_id};
|
||||
use crate::util::{cap, check_rtsp_url, hex_encode, malformed};
|
||||
use crate::{Result, SessionKeys};
|
||||
|
||||
/// Maximum size of a launch or resume answer, in bytes.
|
||||
pub const MAX_LAUNCH_RESPONSE_BYTES: usize = 16 * 1024;
|
||||
@@ -19,6 +20,35 @@ pub enum AudioLayout {
|
||||
Surround71,
|
||||
}
|
||||
|
||||
impl AudioLayout {
|
||||
/// Channel count.
|
||||
#[must_use]
|
||||
pub const fn channels(self) -> u8 {
|
||||
match self {
|
||||
Self::Stereo => 2,
|
||||
Self::Surround51 => 6,
|
||||
Self::Surround71 => 8,
|
||||
}
|
||||
}
|
||||
|
||||
/// The speaker mask (WAVE channel-mask bits: FL FR, + FC LFE BL BR, + SL SR). Stereo's `0x3` matches the
|
||||
/// documented default `surroundAudioInfo` 0x30002 [M]; the surround masks are the standard layouts (U4).
|
||||
#[must_use]
|
||||
pub const fn channel_mask(self) -> u32 {
|
||||
match self {
|
||||
Self::Stereo => 0x0003,
|
||||
Self::Surround51 => 0x003F,
|
||||
Self::Surround71 => 0x063F,
|
||||
}
|
||||
}
|
||||
|
||||
/// `surroundAudioInfo`: `(channel_mask << 16) | channel_count`.
|
||||
#[must_use]
|
||||
pub const fn surround_audio_info(self) -> u32 {
|
||||
(self.channel_mask() << 16) | self.channels() as u32
|
||||
}
|
||||
}
|
||||
|
||||
/// What to launch and how.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct LaunchParams {
|
||||
@@ -50,20 +80,43 @@ pub struct LaunchResponse {
|
||||
/// Builds `GET /launch` (HTTPS).
|
||||
///
|
||||
/// # Errors
|
||||
/// [`crate::Error::Malformed`] for a zero size or frame rate, or a bad `unique_id`. Phase A: always
|
||||
/// [`crate::Error::Unimplemented`].
|
||||
pub fn launch_request(params: &LaunchParams, unique_id: &str) -> crate::Result<HttpRequest> {
|
||||
let _ = (params, unique_id);
|
||||
Err(crate::Error::Unimplemented)
|
||||
/// [`crate::Error::Malformed`] for a zero size or frame rate, or a bad `unique_id`.
|
||||
pub fn launch_request(params: &LaunchParams, unique_id: &str) -> Result<HttpRequest> {
|
||||
check_unique_id(unique_id)?;
|
||||
if params.width == 0 || params.height == 0 || params.fps == 0 {
|
||||
return Err(malformed("launch mode"));
|
||||
}
|
||||
let app = params.app_id.to_string();
|
||||
let mode = format!("{}x{}x{}", params.width, params.height, params.fps);
|
||||
let rikey = hex_encode(¶ms.keys.rikey);
|
||||
let rikeyid = params.keys.rikeyid.to_string();
|
||||
let hdr = if params.hdr { "1" } else { "0" };
|
||||
let audio = params.audio.surround_audio_info().to_string();
|
||||
Ok(build(
|
||||
Scheme::Https,
|
||||
"/launch",
|
||||
&[
|
||||
("uniqueid", unique_id),
|
||||
("appid", &app),
|
||||
("mode", &mode),
|
||||
("rikey", &rikey),
|
||||
("rikeyid", &rikeyid),
|
||||
("hdrMode", hdr),
|
||||
("surroundAudioInfo", &audio),
|
||||
],
|
||||
None,
|
||||
))
|
||||
}
|
||||
|
||||
/// Builds `GET /resume` (HTTPS) with fresh keys.
|
||||
///
|
||||
/// # Errors
|
||||
/// As [`launch_request`].
|
||||
pub fn resume_request(keys: &SessionKeys, unique_id: &str) -> crate::Result<HttpRequest> {
|
||||
let _ = (keys, unique_id);
|
||||
Err(crate::Error::Unimplemented)
|
||||
pub fn resume_request(keys: &SessionKeys, unique_id: &str) -> Result<HttpRequest> {
|
||||
check_unique_id(unique_id)?;
|
||||
let rikey = hex_encode(&keys.rikey);
|
||||
let rikeyid = keys.rikeyid.to_string();
|
||||
Ok(build(Scheme::Https, "/resume", &[("uniqueid", unique_id), ("rikey", &rikey), ("rikeyid", &rikeyid)], None))
|
||||
}
|
||||
|
||||
/// Parses a launch or resume answer.
|
||||
@@ -71,8 +124,17 @@ pub fn resume_request(keys: &SessionKeys, unique_id: &str) -> crate::Result<Http
|
||||
/// # Errors
|
||||
/// [`crate::Error::TooLarge`] over [`MAX_LAUNCH_RESPONSE_BYTES`] or [`MAX_SESSION_URL_BYTES`],
|
||||
/// [`crate::Error::HostStatus`] for a non-200 answer, [`crate::Error::Malformed`] for a `sessionUrl0` that is not an
|
||||
/// `rtsp://host:port` URL. Phase A: always [`crate::Error::Unimplemented`].
|
||||
pub fn parse_launch_response(body: &[u8]) -> crate::Result<LaunchResponse> {
|
||||
let _ = body;
|
||||
Err(crate::Error::Unimplemented)
|
||||
/// `rtsp://host:port` URL.
|
||||
pub fn parse_launch_response(body: &[u8]) -> Result<LaunchResponse> {
|
||||
let doc = super::document(body, MAX_LAUNCH_RESPONSE_BYTES, "launch answer")?;
|
||||
let game_session = doc.root.child("gamesession").is_some_and(|g| g.text == "1");
|
||||
let session_url = match doc.root.child("sessionUrl0") {
|
||||
None => None,
|
||||
Some(e) => {
|
||||
cap("sessionUrl0", MAX_SESSION_URL_BYTES, e.text.len())?;
|
||||
check_rtsp_url("sessionUrl0", &e.text)?;
|
||||
Some(e.text.clone())
|
||||
}
|
||||
};
|
||||
Ok(LaunchResponse { game_session, session_url })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user