diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-22 23:57:03 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-22 23:57:03 +0100 |
commit | 75949cebdd61dd8f0d06f2e47081c460e2a442f0 (patch) | |
tree | ea0fc2ff003b7694ee06555d731bce1f08199136 /stream/src/jhls.rs | |
parent | c4682c231cbfa2bd4b44e14548800a64cc9cdbb8 (diff) | |
download | jellything-75949cebdd61dd8f0d06f2e47081c460e2a442f0.tar jellything-75949cebdd61dd8f0d06f2e47081c460e2a442f0.tar.bz2 jellything-75949cebdd61dd8f0d06f2e47081c460e2a442f0.tar.zst |
rework import system pt. 8: federated streams & change jhls
Diffstat (limited to 'stream/src/jhls.rs')
-rw-r--r-- | stream/src/jhls.rs | 55 |
1 files changed, 13 insertions, 42 deletions
diff --git a/stream/src/jhls.rs b/stream/src/jhls.rs index e61e918..e58aafe 100644 --- a/stream/src/jhls.rs +++ b/stream/src/jhls.rs @@ -6,66 +6,37 @@ use anyhow::{anyhow, Result}; use jellybase::{permission::PermissionSetExt, CONF}; use jellycommon::{ - jhls::{JhlsMetadata, JhlsTrack}, + jhls::JhlsTrackIndex, stream::StreamSpec, user::{PermissionSet, UserPermission}, - Node, TrackSource, + LocalTrack, Node, }; use tokio::io::{AsyncWriteExt, DuplexStream}; -pub async fn jhls_stream( +pub async fn jhls_index( node: Node, - track_sources: &[TrackSource], + local_tracks: &[LocalTrack], _spec: StreamSpec, mut b: DuplexStream, perms: &PermissionSet, ) -> Result<()> { - let track_sources = track_sources.to_vec(); - let media = node.public.media.clone().unwrap(); - let tracks = tokio::task::spawn_blocking(move || { - media - .tracks - .iter() - .enumerate() - .filter_map(|(i, t)| { - // TODO can we maybe stream the subtitles as .mks in the future? that would be cool - // subtitles can only be supported by snippet_index if we relax constraints on the contents of each cluster - if matches!(t.kind, jellycommon::SourceTrackKind::Subtitles) { - return Some(Ok(JhlsTrack { - info: t.to_owned(), - segments: vec![], // clients need to ignore this - })); - } - match jellyremuxer::snippet::snippet_index( - &CONF.library_path, - &node.public, - match &track_sources[i] { - TrackSource::Local(x) => x, - // TODO fetch seek index from the remote and create a single session to be sent in jhls - TrackSource::Remote(_) => { - return Some(Err(anyhow!("remote tracks dont work yet"))) - } - }, - ) { - Ok(segments) => Some(Ok::<_, anyhow::Error>(JhlsTrack { - info: t.to_owned(), - segments, - })), - Err(e) => Some(Err(e)), - } - }) - .try_collect::<Vec<_>>() + let local_track = local_tracks + .get(0) + .ok_or(anyhow!("track missing"))? + .to_owned(); + + let segments = tokio::task::spawn_blocking(move || { + jellyremuxer::snippet::snippet_index(&CONF.library_path, &node.public, &local_track) }) .await??; - let out = serde_json::to_string(&JhlsMetadata { - tracks, + let out = serde_json::to_string(&JhlsTrackIndex { extra_profiles: if perms.check(&UserPermission::Transcode) { CONF.transcoding_profiles.clone() } else { vec![] }, - duration: media.duration, + segments, })?; tokio::spawn(async move { b.write_all(out.as_bytes()).await }); Ok(()) |