diff options
Diffstat (limited to 'stream/src/lib.rs')
-rw-r--r-- | stream/src/lib.rs | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/stream/src/lib.rs b/stream/src/lib.rs index 1ee0690..ee5c78a 100644 --- a/stream/src/lib.rs +++ b/stream/src/lib.rs @@ -15,7 +15,7 @@ use jellybase::{permission::PermissionSetExt, CONF}; use jellycommon::{ stream::{StreamFormat, StreamSpec}, user::{PermissionSet, UserPermission}, - LocalTrack, Node, + LocalTrack, Node, TrackSource, }; use jhls::jhls_stream; use segment::segment_stream; @@ -56,24 +56,38 @@ pub async fn stream( let (a, b) = duplex(4096); // TODO remux of mixed remote and local tracks?! - let track_sources = match node + let track_sources = node .private .source - .as_ref() - .ok_or(anyhow!("node has no media"))? - { - // MediaSource::Local { tracks } => tracks.to_owned(), - _ => bail!("node tracks are not local"), - }; + .to_owned() + .ok_or(anyhow!("node has no media"))?; + + let local_tracks = spec + .tracks + .iter() + .map(|i| { + anyhow::Ok( + match track_sources + .get(*i) + .ok_or(anyhow!("track does not exist"))? + { + TrackSource::Local(t) => t.to_owned(), + TrackSource::Remote => bail!("track is not local"), + }, + ) + }) + .collect::<anyhow::Result<Vec<_>>>()? + .into_iter() + .collect::<Vec<_>>(); match spec.format { - StreamFormat::Original => original_stream(track_sources, spec, range, b).await?, - StreamFormat::Matroska => remux_stream(node, track_sources, spec, range, b).await?, - StreamFormat::HlsMaster => hls_master_stream(node, track_sources, spec, b).await?, - StreamFormat::HlsVariant => hls_variant_stream(node, track_sources, spec, b).await?, - StreamFormat::Jhls => jhls_stream(node, track_sources, spec, b, perms).await?, - StreamFormat::Segment => segment_stream(node, track_sources, spec, b, perms).await?, - StreamFormat::Webvtt => webvtt_stream(node, track_sources, spec, b).await?, + StreamFormat::Original => original_stream(local_tracks, spec, range, b).await?, + StreamFormat::Matroska => remux_stream(node, local_tracks, spec, range, b).await?, + StreamFormat::HlsMaster => hls_master_stream(node, local_tracks, spec, b).await?, + StreamFormat::HlsVariant => hls_variant_stream(node, local_tracks, spec, b).await?, + StreamFormat::Jhls => jhls_stream(node, &track_sources, spec, b, perms).await?, + StreamFormat::Segment => segment_stream(node, local_tracks, spec, b, perms).await?, + StreamFormat::Webvtt => webvtt_stream(node, local_tracks, spec, b).await?, } Ok(a) @@ -81,7 +95,7 @@ pub async fn stream( async fn remux_stream( node: Node, - track_sources: Vec<LocalTrack>, + local_tracks: Vec<LocalTrack>, spec: StreamSpec, range: Range<usize>, b: DuplexStream, @@ -94,7 +108,7 @@ async fn remux_stream( range, CONF.library_path.to_owned(), node.public, - track_sources, + local_tracks, spec.tracks, spec.webm.unwrap_or(false), ) @@ -104,7 +118,7 @@ async fn remux_stream( } async fn original_stream( - track_sources: Vec<LocalTrack>, + local_tracks: Vec<LocalTrack>, spec: StreamSpec, range: Range<usize>, b: DuplexStream, @@ -113,7 +127,7 @@ async fn original_stream( bail!("invalid amout of source \"tracks\". original only allows for exactly one.") } - let source = track_sources[spec.tracks[0]].clone(); + let source = local_tracks[spec.tracks[0]].clone(); let mut file = File::open(CONF.library_path.join(source.path)) .await .context("opening source")?; |