chore: convert to bin

This commit is contained in:
kieran 2024-11-13 19:57:36 +00:00
parent 82c12b725f
commit 7734ae9c84
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
8 changed files with 27 additions and 85 deletions

View File

@ -3,6 +3,10 @@ name = "zap-stream-core"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[[bin]]
name = "zap-stream-core"
path = "src/bin/zap_stream_core.rs"
[features] [features]
default = ["test-source"] default = ["test-source"]
srt = ["dep:srt-tokio"] srt = ["dep:srt-tokio"]

View File

@ -25,7 +25,7 @@ RUN git clone --depth=1 https://git.ffmpeg.org/ffmpeg.git && \
--disable-static \ --disable-static \
--enable-shared && \ --enable-shared && \
make -j$(nproc) && make install 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 FROM $IMAGE as runner
WORKDIR /app WORKDIR /app

6
src/bin/nostr_sidecar.rs Normal file
View File

@ -0,0 +1,6 @@
#[tokio::main]
async fn main() -> anyhow::Result<()> {
}

View File

@ -5,17 +5,12 @@ use ffmpeg_rs_raw::rstr;
use log::{error, info}; use log::{error, info};
use url::Url; use url::Url;
use crate::egress::http::listen_out_dir; use zap_stream_core::egress::http::listen_out_dir;
use crate::settings::Settings; #[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)] #[derive(Parser, Debug)]
struct Args { struct Args {
@ -53,8 +48,8 @@ async fn main() -> anyhow::Result<()> {
let addr = format!("{}:{}", u.host_str().unwrap(), u.port().unwrap()); let addr = format!("{}:{}", u.host_str().unwrap(), u.port().unwrap());
match u.scheme() { match u.scheme() {
#[cfg(feature = "srt")] #[cfg(feature = "srt")]
"srt" => listeners.push(tokio::spawn(ingress::srt::listen(addr, settings.clone()))), "srt" => listeners.push(tokio::spawn(srt::listen(addr, settings.clone()))),
"tcp" => listeners.push(tokio::spawn(ingress::tcp::listen(addr, settings.clone()))), "tcp" => listeners.push(tokio::spawn(tcp::listen(addr, settings.clone()))),
_ => { _ => {
error!("Unknown endpoint config: {e}"); error!("Unknown endpoint config: {e}");
} }
@ -66,14 +61,14 @@ async fn main() -> anyhow::Result<()> {
))); )));
if let Some(p) = args.file { if let Some(p) = args.file {
listeners.push(tokio::spawn(ingress::file::listen( listeners.push(tokio::spawn(file::listen(
p.parse()?, p.parse()?,
settings.clone(), settings.clone(),
))); )));
} }
#[cfg(feature = "test-source")] #[cfg(feature = "test-source")]
if args.test_pattern { 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 { for handle in listeners {

View File

@ -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,
}
}
}

View File

@ -1,35 +0,0 @@
use anyhow::Error;
use async_trait::async_trait;
#[async_trait]
pub trait Rx<T> {
async fn recv(&mut self) -> Result<T, Error>;
fn try_recv_next(&mut self) -> Result<T, Error>;
}
#[async_trait]
impl<T> Rx<T> for tokio::sync::mpsc::UnboundedReceiver<T>
where
T: Send + Sync,
{
async fn recv(&mut self) -> Result<T, Error> {
self.recv().await.ok_or(Error::msg("recv error"))
}
fn try_recv_next(&mut self) -> Result<T, Error> {
Ok(self.try_recv()?)
}
}
#[async_trait]
impl<T> Rx<T> for tokio::sync::broadcast::Receiver<T>
where
T: Send + Sync + Clone,
{
async fn recv(&mut self) -> Result<T, Error> {
Ok(self.recv().await?)
}
fn try_recv_next(&mut self) -> Result<T, Error> {
Ok(self.try_recv()?)
}
}

6
src/lib.rs Normal file
View File

@ -0,0 +1,6 @@
pub mod egress;
pub mod ingress;
pub mod pipeline;
pub mod settings;
pub mod variant;
pub mod webhook;

View File

@ -102,7 +102,7 @@ impl PipelineRunner {
// Copy frame from GPU if using hwaccel decoding // Copy frame from GPU if using hwaccel decoding
let frame = get_frame_from_hw(frame)?; 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 let pkt_vars = self
.config .config
.variants .variants