diff --git a/Cargo.toml b/Cargo.toml index 0840f19..367d1bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,10 @@ name = "zap-stream-core" version = "0.1.0" edition = "2021" +[[bin]] +name = "zap-stream-core" +path = "src/bin/zap_stream_core.rs" + [features] default = ["test-source"] srt = ["dep:srt-tokio"] diff --git a/Dockerfile b/Dockerfile index 3fc5e88..1a23249 100755 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN git clone --depth=1 https://git.ffmpeg.org/ffmpeg.git && \ --disable-static \ --enable-shared && \ make -j$(nproc) && make install -RUN cargo install --path . --root /app/build +RUN cargo install --path . --bin zap-stream-core --root /app/build FROM $IMAGE as runner WORKDIR /app diff --git a/src/bin/nostr_sidecar.rs b/src/bin/nostr_sidecar.rs new file mode 100644 index 0000000..2c13210 --- /dev/null +++ b/src/bin/nostr_sidecar.rs @@ -0,0 +1,6 @@ + + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + +} \ No newline at end of file diff --git a/src/main.rs b/src/bin/zap_stream_core.rs similarity index 77% rename from src/main.rs rename to src/bin/zap_stream_core.rs index 8f332ea..6b3d46f 100644 --- a/src/main.rs +++ b/src/bin/zap_stream_core.rs @@ -5,17 +5,12 @@ use ffmpeg_rs_raw::rstr; use log::{error, info}; use url::Url; -use crate::egress::http::listen_out_dir; -use crate::settings::Settings; +use zap_stream_core::egress::http::listen_out_dir; +#[cfg(feature = "srt")] +use zap_stream_core::ingress::srt; +use zap_stream_core::ingress::{file, tcp, test}; +use zap_stream_core::settings::Settings; -mod egress; -mod fraction; -mod ingress; -mod ipc; -mod pipeline; -mod settings; -mod variant; -mod webhook; #[derive(Parser, Debug)] struct Args { @@ -53,8 +48,8 @@ async fn main() -> anyhow::Result<()> { let addr = format!("{}:{}", u.host_str().unwrap(), u.port().unwrap()); match u.scheme() { #[cfg(feature = "srt")] - "srt" => listeners.push(tokio::spawn(ingress::srt::listen(addr, settings.clone()))), - "tcp" => listeners.push(tokio::spawn(ingress::tcp::listen(addr, settings.clone()))), + "srt" => listeners.push(tokio::spawn(srt::listen(addr, settings.clone()))), + "tcp" => listeners.push(tokio::spawn(tcp::listen(addr, settings.clone()))), _ => { error!("Unknown endpoint config: {e}"); } @@ -66,14 +61,14 @@ async fn main() -> anyhow::Result<()> { ))); if let Some(p) = args.file { - listeners.push(tokio::spawn(ingress::file::listen( + listeners.push(tokio::spawn(file::listen( p.parse()?, settings.clone(), ))); } #[cfg(feature = "test-source")] if args.test_pattern { - listeners.push(tokio::spawn(ingress::test::listen(settings.clone()))); + listeners.push(tokio::spawn(test::listen(settings.clone()))); } for handle in listeners { diff --git a/src/fraction.rs b/src/fraction.rs deleted file mode 100644 index 4f6c1ee..0000000 --- a/src/fraction.rs +++ /dev/null @@ -1,34 +0,0 @@ -#[derive(Clone, Debug, Copy)] -pub struct Fraction { - pub num: usize, - pub den: usize, -} - -fn gcd(mut a: usize, mut b: usize) -> usize { - if a == b { - return a; - } - if b > a { - std::mem::swap(&mut a, &mut b); - } - while b > 0 { - let temp = a; - a = b; - b = temp % b; - } - a -} - -impl From<(usize, usize)> for Fraction { - fn from(value: (usize, usize)) -> Self { - let num = value.0; - let den = value.1; - - let gcd = gcd(num, den); - - Self { - num: num / gcd, - den: den / gcd, - } - } -} diff --git a/src/ipc.rs b/src/ipc.rs deleted file mode 100644 index b1c2bba..0000000 --- a/src/ipc.rs +++ /dev/null @@ -1,35 +0,0 @@ -use anyhow::Error; -use async_trait::async_trait; - -#[async_trait] -pub trait Rx { - async fn recv(&mut self) -> Result; - fn try_recv_next(&mut self) -> Result; -} - -#[async_trait] -impl Rx for tokio::sync::mpsc::UnboundedReceiver -where - T: Send + Sync, -{ - async fn recv(&mut self) -> Result { - self.recv().await.ok_or(Error::msg("recv error")) - } - - fn try_recv_next(&mut self) -> Result { - Ok(self.try_recv()?) - } -} - -#[async_trait] -impl Rx for tokio::sync::broadcast::Receiver -where - T: Send + Sync + Clone, -{ - async fn recv(&mut self) -> Result { - Ok(self.recv().await?) - } - fn try_recv_next(&mut self) -> Result { - Ok(self.try_recv()?) - } -} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b90fc52 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,6 @@ +pub mod egress; +pub mod ingress; +pub mod pipeline; +pub mod settings; +pub mod variant; +pub mod webhook; diff --git a/src/pipeline/runner.rs b/src/pipeline/runner.rs index 8159e12..5ac7e96 100644 --- a/src/pipeline/runner.rs +++ b/src/pipeline/runner.rs @@ -102,7 +102,7 @@ impl PipelineRunner { // Copy frame from GPU if using hwaccel decoding let frame = get_frame_from_hw(frame)?; - /// Get the variants which want this pkt + // Get the variants which want this pkt let pkt_vars = self .config .variants