From 831322e44a79ae26fed21e4ead970863fbd8b1c7 Mon Sep 17 00:00:00 2001 From: devdesk Date: Tue, 20 Feb 2024 23:29:33 +0200 Subject: [PATCH] initial example axum, streamer runs in thread --- Cargo.lock | 71 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/{main.rs => stream.rs} | 14 +++++--- 3 files changed, 83 insertions(+), 4 deletions(-) rename src/{main.rs => stream.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index d32eae5..4981f6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2384,6 +2384,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -2551,6 +2561,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owned_ttf_parser" version = "0.20.0" @@ -3132,6 +3148,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -3342,6 +3367,8 @@ dependencies = [ "png", "pyo3", "serde", + "tokio", + "tracing-subscriber", "v4l", ] @@ -3365,6 +3392,16 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tiny-skia" version = "0.11.4" @@ -3416,7 +3453,9 @@ dependencies = [ "libc", "mio", "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2 0.5.5", "tokio-macros", "windows-sys 0.48.0", @@ -3533,6 +3572,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", ] [[package]] @@ -3649,6 +3714,12 @@ dependencies = [ "bindgen", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 56eec5c..8821ec0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,6 @@ pcap-parser = { version = "0.14.1", features = ["data"] } png = "0.17.10" pyo3 = { version = "0.20.0", "features" = ["extension-module"] } serde = { version = "1.0.193", features = ["derive", "serde_derive", "alloc"] } +tokio = { version = "1.36.0", features = ["full"] } +tracing-subscriber = "0.3.18" v4l = { version = "0.14.0", features = ["v4l2"], default-features = false } diff --git a/src/main.rs b/src/stream.rs similarity index 95% rename from src/main.rs rename to src/stream.rs index 4b8c98b..472de19 100644 --- a/src/main.rs +++ b/src/stream.rs @@ -1,9 +1,7 @@ -mod offline; - +use crate::offline::{Header, HDR_SIZE}; use clap::Parser; use dotenv::dotenv; -use offline::{Header, HDR_SIZE}; -use std::io::Write; +use std::{io::Write, thread::spawn}; use v4l::video::Output; #[derive(Parser, Debug)] @@ -143,3 +141,11 @@ fn main() -> anyhow::Result<()> { } Ok(()) } + +pub(crate) fn start_stream_thread() { + spawn(move || { + if let Err(e) = main() { + println!("oops: {:?}", e); + } + }); +}