diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/src/stream.rs | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/common/src/stream.rs b/common/src/stream.rs index 59166b8..3fb1008 100644 --- a/common/src/stream.rs +++ b/common/src/stream.rs @@ -13,7 +13,7 @@ pub struct StreamSpec { } #[rustfmt::skip] -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] #[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] pub enum StreamFormat { @@ -36,3 +36,47 @@ impl Default for StreamSpec { } } } + +impl StreamSpec { + pub fn to_query(&self) -> String { + use std::fmt::Write; + let mut u = String::new(); + writeln!(u, "format={}", self.format.ident()).unwrap(); + + if !self.tracks.is_empty() { + writeln!( + u, + "&tracks={}", + self.tracks + .iter() + .map(|s| s.to_string()) + .collect::<Vec<_>>() + .join(",") + ) + .unwrap(); + } + if let Some(abr) = self.abr { + writeln!(u, "&abr={abr}").unwrap(); + } + if let Some(vbr) = self.vbr { + writeln!(u, "&vbr={vbr}").unwrap(); + } + if let Some(index) = self.index { + writeln!(u, "&index={index}").unwrap(); + } + u + } +} + +impl StreamFormat { + pub fn ident(&self) -> &'static str { + match self { + StreamFormat::Original => "original", + StreamFormat::Matroska => "matroska", + StreamFormat::Webm => "webm", + StreamFormat::Hls => "hls", + StreamFormat::Jhls => "jhls", + StreamFormat::Segment => "hlsseg", + } + } +} |