diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-28 13:52:41 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-28 13:52:41 +0100 |
commit | f0dbf139d8708194d1ff7e887b1dff48ccc166fa (patch) | |
tree | c88a1ae37f404a243ded8a9548fe260d2cc26832 /common | |
parent | 26d3a70b0be2809177076e155f987e18e2b2ceb2 (diff) | |
download | jellything-f0dbf139d8708194d1ff7e887b1dff48ccc166fa.tar jellything-f0dbf139d8708194d1ff7e887b1dff48ccc166fa.tar.bz2 jellything-f0dbf139d8708194d1ff7e887b1dff48ccc166fa.tar.zst |
spec + break things
Diffstat (limited to 'common')
-rw-r--r-- | common/src/stream.rs | 120 | ||||
-rw-r--r-- | common/src/user.rs | 46 |
2 files changed, 60 insertions, 106 deletions
diff --git a/common/src/stream.rs b/common/src/stream.rs index 3e227e1..46f6abc 100644 --- a/common/src/stream.rs +++ b/common/src/stream.rs @@ -1,82 +1,60 @@ -use bincode::{Decode, Encode}; /* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -#[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 track: Vec<usize>, - pub format: StreamFormat, - pub webm: Option<bool>, - pub profile: Option<usize>, - pub index: Option<usize>, +pub enum StreamSpec { + Whep { + track: u64, + seek: u64, + }, + WhepControl { + token: String, + }, + Remux { + track: Vec<u64>, + container: StreamContainer, + }, + Original { + track: u64, + }, + HlsSuperMultiVariant { + container: StreamContainer, + }, + HlsMultiVariant { + segment: u64, + container: StreamContainer, + }, + HlsVariant { + segment: u64, + track: u64, + container: StreamContainer, + format: usize, + }, + Info { + segment: Option<u64>, + }, + FragmentIndex { + segment: u64, + track: u64, + }, + Fragment { + segment: u64, + track: u64, + index: u64, + container: StreamContainer, + format: usize, + }, } -#[rustfmt::skip] -#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash, Encode, Decode)] -#[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 = "hlsmaster"))] HlsMaster, - #[cfg_attr(feature = "rocket", field(value = "hlsvariant"))] HlsVariant, - #[cfg_attr(feature = "rocket", field(value = "jhlsi"))] JhlsIndex, - #[cfg_attr(feature = "rocket", field(value = "frag"))] Fragment, - #[cfg_attr(feature = "rocket", field(value = "webvtt"))] Webvtt, - #[cfg_attr(feature = "rocket", field(value = "jvtt"))] Jvtt, -} - -impl Default for StreamSpec { - fn default() -> Self { - Self { - track: Vec::new(), - format: StreamFormat::Matroska, - webm: Some(true), - profile: None, - index: None, - } - } -} - -impl StreamSpec { - pub fn to_query(&self) -> String { - use std::fmt::Write; - let mut u = String::new(); - write!(u, "format={}", self.format.ident()).unwrap(); - for t in &self.track { - write!(u, "&track={}", t).unwrap(); - } - if let Some(profile) = self.profile { - write!(u, "&profile={profile}").unwrap(); - } - if let Some(index) = self.index { - write!(u, "&index={index}").unwrap(); - } - if let Some(webm) = self.webm { - write!(u, "&webm={webm}").unwrap(); - } - u - } -} - -impl StreamFormat { - pub fn ident(&self) -> &'static str { - match self { - StreamFormat::Jvtt => "jvtt", - StreamFormat::Original => "original", - StreamFormat::Matroska => "matroska", - StreamFormat::HlsMaster => "hlsmaster", - StreamFormat::HlsVariant => "hlsvariant", - StreamFormat::JhlsIndex => "jhlsi", - StreamFormat::Fragment => "frag", - StreamFormat::Webvtt => "webvtt", - } - } +#[derive(Debug, Clone, Copy, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum StreamContainer { + WebM, + Matroska, + WebVTT, + JVTT, } diff --git a/common/src/user.rs b/common/src/user.rs index ef78eca..e0e7a0d 100644 --- a/common/src/user.rs +++ b/common/src/user.rs @@ -3,7 +3,6 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -use crate::{stream::StreamFormat, user}; use bincode::{Decode, Encode}; #[cfg(feature = "rocket")] use rocket::{FromFormField, UriDisplayQuery}; @@ -99,7 +98,6 @@ pub enum UserPermission { ManageSelf, AccessNode(String), - StreamFormat(StreamFormat), Transcode, FederatedContent, } @@ -107,33 +105,11 @@ pub enum UserPermission { impl UserPermission { pub const ALL_ENUMERABLE: &'static [UserPermission] = { use UserPermission::*; - &[ - Admin, - Transcode, - ManageSelf, - FederatedContent, - StreamFormat(user::StreamFormat::Original), - ] + &[Admin, Transcode, ManageSelf, FederatedContent] }; pub fn default_value(&self) -> bool { - use user::StreamFormat::*; use UserPermission::*; - matches!( - self, - Transcode - | ManageSelf - | FederatedContent - | StreamFormat( - JhlsIndex - | Jvtt - | HlsMaster - | HlsVariant - | Matroska - | Fragment - | Webvtt - | Original // TODO remove later - ) - ) + matches!(self, Transcode | ManageSelf | FederatedContent) } } @@ -143,15 +119,15 @@ impl Display for UserPermission { UserPermission::ManageSelf => "manage self (password, display name, etc.)".to_string(), UserPermission::FederatedContent => "access to federated content".to_string(), UserPermission::Admin => "administrative rights".to_string(), - UserPermission::StreamFormat(StreamFormat::Original) => { - "downloading the original media".to_string() - } - UserPermission::StreamFormat(StreamFormat::Matroska) => { - "downloading a remuxed WebM/Matroska version of the media ".to_string() - } - UserPermission::StreamFormat(x) => { - format!("downloading media via {x:?}") - } + // UserPermission::StreamFormat(StreamFormat::Original) => { + // "downloading the original media".to_string() + // } + // UserPermission::StreamFormat(StreamFormat::Matroska) => { + // "downloading a remuxed WebM/Matroska version of the media ".to_string() + // } + // UserPermission::StreamFormat(x) => { + // format!("downloading media via {x:?}") + // } UserPermission::Transcode => "transcoding".to_string(), // UserPermission::ManageUsers => format!("management of all users"), // UserPermission::GenerateInvite => format!("inviting new users"), |