use moq_net::{AsPath, PathRelativeOwned};
pub fn source_reference(source: impl AsPath, output: impl AsPath) -> Option<PathRelativeOwned> {
let source = source.as_path();
let output = output.as_path();
let rest = output.strip_prefix(&source)?;
if rest.is_empty() {
return None;
}
let parents = rest.parts().count().saturating_sub(1);
let rel = if parents == 0 {
".".to_string()
} else {
vec![".."; parents].join("/")
};
Some(PathRelativeOwned::from(rel))
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Rung {
pub height: u32,
pub bitrate: u64,
}
impl Rung {
pub fn new(height: u32, bitrate: u64) -> Self {
Self { height, bitrate }
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Config {
pub rungs: Vec<Rung>,
pub source: Option<PathRelativeOwned>,
pub encoder: moq_video::encode::Kind,
pub decoder: moq_video::decode::Kind,
pub resize: moq_video::resize::Config,
}
impl Default for Config {
fn default() -> Self {
Self {
rungs: vec![
Rung::new(1080, 5_000_000),
Rung::new(720, 2_500_000),
Rung::new(480, 1_200_000),
Rung::new(360, 600_000),
Rung::new(240, 350_000),
],
source: None,
encoder: moq_video::encode::Kind::default(),
decoder: moq_video::decode::Kind::default(),
resize: moq_video::resize::Config::default(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn source_reference_normalizes_and_counts_output_depth() {
assert_eq!(source_reference("a/b", "a/b/transcode.hang").unwrap().as_str(), ".");
assert_eq!(source_reference("/a//b/", "a/b/dir/").unwrap().as_str(), ".");
assert_eq!(
source_reference("a/b", "a/b/dir/transcode.hang").unwrap().as_str(),
".."
);
assert_eq!(
source_reference("a/b", "a/b/one/two/transcode.hang").unwrap().as_str(),
"../.."
);
assert!(source_reference("a/b", "other/transcode.hang").is_none());
assert!(source_reference("a/b", "a/b").is_none());
}
}