diff options
Diffstat (limited to 'stream')
-rw-r--r-- | stream/Cargo.toml | 1 | ||||
-rw-r--r-- | stream/src/hls.rs | 4 | ||||
-rw-r--r-- | stream/src/jhls.rs | 43 | ||||
-rw-r--r-- | stream/src/segment.rs | 4 |
4 files changed, 48 insertions, 4 deletions
diff --git a/stream/Cargo.toml b/stream/Cargo.toml index a03a85c..7228384 100644 --- a/stream/Cargo.toml +++ b/stream/Cargo.toml @@ -13,3 +13,4 @@ log = { workspace = true } anyhow = { workspace = true } tokio = { version = "1.32.0", features = ["io-util"] } tokio-util = { version = "0.7.9", features = ["io", "io-util"] } +serde_json = "1.0.107" diff --git a/stream/src/hls.rs b/stream/src/hls.rs index 81d0c8c..c5b7f91 100644 --- a/stream/src/hls.rs +++ b/stream/src/hls.rs @@ -48,8 +48,8 @@ pub async fn hls_variant_stream( ) -> Result<()> { let track = *spec.tracks.get(0).ok_or(anyhow!("no track"))?; let snips = jellyremuxer::snippet::snippet_index( - CONF.library_path.clone(), - node.public.clone(), + &CONF.library_path, + &node.public, &track_sources, track, )?; diff --git a/stream/src/jhls.rs b/stream/src/jhls.rs new file mode 100644 index 0000000..5e15d6f --- /dev/null +++ b/stream/src/jhls.rs @@ -0,0 +1,43 @@ +use anyhow::Result; +use jellybase::CONF; +use jellycommon::{ + jhls::{JhlsMetadata, JhlsTrack}, + stream::StreamSpec, + LocalTrack, Node, +}; +use tokio::io::{AsyncWriteExt, DuplexStream}; + +pub async fn jhls_stream( + node: Node, + track_sources: Vec<LocalTrack>, + _spec: StreamSpec, + mut b: DuplexStream, +) -> Result<()> { + let tracks = tokio::task::spawn_blocking(move || { + node.public + .media + .as_ref() + .unwrap() + .tracks + .iter() + .enumerate() + .map(|(i, t)| { + let segments = jellyremuxer::snippet::snippet_index( + &CONF.library_path, + &node.public, + &track_sources, + i, + )?; + Ok::<_, anyhow::Error>(JhlsTrack { + info: t.to_owned(), + segments, + }) + }) + .try_collect::<Vec<_>>() + }) + .await??; + + let out = serde_json::to_string(&JhlsMetadata { tracks })?; + tokio::spawn(async move { b.write_all(out.as_bytes()).await }); + Ok(()) +} diff --git a/stream/src/segment.rs b/stream/src/segment.rs index 77f1238..78afc4f 100644 --- a/stream/src/segment.rs +++ b/stream/src/segment.rs @@ -27,8 +27,8 @@ pub async fn segment_stream( tokio::task::spawn_blocking(move || { if let Err(err) = jellyremuxer::write_snippet_into( b, - CONF.library_path.clone(), - node.public.clone(), + &CONF.library_path, + &node.public, track_sources, track, spec.webm.unwrap_or(false), |