From c62eb3a2fdaa80f472be6ecbfc2cbf2479d8d914 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 29 Sep 2023 20:56:36 +0200 Subject: move stream generation to new crate --- common/src/lib.rs | 5 ++++- common/src/stream.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 common/src/stream.rs (limited to 'common/src') diff --git a/common/src/lib.rs b/common/src/lib.rs index 6c76903..b7f975a 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -6,6 +6,7 @@ pub mod config; pub mod helpers; pub mod r#impl; +pub mod stream; use bincode::{Decode, Encode}; #[cfg(feature = "rocket")] @@ -88,10 +89,12 @@ pub enum PublicMediaSource { Remote(String), } +pub type TrackID = usize; + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct LocalTrack { pub path: PathBuf, - pub track: usize, + pub track: TrackID, pub codec_private: Option>, } diff --git a/common/src/stream.rs b/common/src/stream.rs new file mode 100644 index 0000000..59166b8 --- /dev/null +++ b/common/src/stream.rs @@ -0,0 +1,38 @@ +#[cfg(feature = "rocket")] +use rocket::{FromForm, FromFormField, UriDisplayQuery}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "rocket", derive(FromForm, UriDisplayQuery))] +pub struct StreamSpec { + pub tracks: Vec, + pub format: StreamFormat, + pub abr: Option, + pub vbr: Option, + pub index: Option, +} + +#[rustfmt::skip] +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] +pub enum StreamFormat { + #[cfg_attr(feature = "rocket", field(value = "original"))] Original, + #[cfg_attr(feature = "rocket", field(value = "matroska"))] Matroska, + #[cfg_attr(feature = "rocket", field(value = "webm"))] Webm, + #[cfg_attr(feature = "rocket", field(value = "hls"))] Hls, + #[cfg_attr(feature = "rocket", field(value = "jhls"))] Jhls, + #[cfg_attr(feature = "rocket", field(value = "hlsseg"))] Segment, +} + +impl Default for StreamSpec { + fn default() -> Self { + Self { + tracks: Default::default(), + format: StreamFormat::Webm, + abr: Default::default(), + vbr: Default::default(), + index: Default::default(), + } + } +} -- cgit v1.2.3-70-g09d2