diff options
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(()) |