diff --git a/Cargo.lock b/Cargo.lock index b8c2982..12dd28b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -469,6 +469,29 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bindgen" +version = "0.65.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.48", + "which", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -645,6 +668,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -672,6 +704,17 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0fc239e0f6cb375d2402d48afb92f76f5404fd1df208a41930ec81eda078bea" +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading 0.8.1", +] + [[package]] name = "clipboard-win" version = "5.1.0" @@ -1084,6 +1127,12 @@ dependencies = [ "winit", ] +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + [[package]] name = "emath" version = "0.26.2" @@ -1473,6 +1522,12 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "glow" version = "0.13.1" @@ -1806,6 +1861,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.153" @@ -2289,6 +2350,12 @@ dependencies = [ "rusticata-macros", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -2385,6 +2452,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" +[[package]] +name = "prettyplease" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" +dependencies = [ + "proc-macro2", + "syn 2.0.48", +] + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -2717,6 +2794,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2907,6 +2990,7 @@ dependencies = [ "png", "pyo3", "serde", + "v4l", ] [[package]] @@ -3143,6 +3227,26 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "v4l" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8fbfea44a46799d62c55323f3c55d06df722fbe577851d848d328a1041c3403" +dependencies = [ + "bitflags 1.3.2", + "libc", + "v4l2-sys-mit", +] + +[[package]] +name = "v4l2-sys-mit" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6779878362b9bacadc7893eac76abe69612e8837ef746573c4a5239daf11990b" +dependencies = [ + "bindgen", +] + [[package]] name = "version_check" version = "0.9.4" @@ -3484,6 +3588,18 @@ dependencies = [ "web-sys", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix 0.38.31", +] + [[package]] name = "widestring" version = "1.0.2" diff --git a/Cargo.toml b/Cargo.toml index 49dabc1..0556052 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,4 @@ 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"] } +v4l = "0.14.0" diff --git a/examples/live.rs b/examples/live.rs index e0c8b4d..2ff2c42 100644 --- a/examples/live.rs +++ b/examples/live.rs @@ -1,40 +1,7 @@ use dotenv::dotenv; -use std::fs::File; use std::io::Write; -use thermaldecoder::{Frame, Header, HDR_SIZE}; - -// fn main() -> Result<(), eframe::Error> { -// env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). -// let options = eframe::NativeOptions { -// viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 800.0]), -// ..Default::default() -// }; -// let (sender, receiver) = crossbeam::channel::unbounded(); -// eframe::run_native( -// "Image Viewer", -// options, -// Box::new(|cc| { -// // This gives us image support: -// egui_extras::install_image_loaders(&cc.egui_ctx); -// Box::::default() -// }), -// ) -// } - -// #[derive(Default)] -// struct MyApp {} - -// impl eframe::App for MyApp { -// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { -// egui::CentralPanel::default().show(ctx, |ui| { -// egui::ScrollArea::both().show(ui, |ui| { -// ui.add(egui::Image::new().rounding(10.0)); - -// ui.image(egui::include_image!("ferris.svg")); -// }); -// }); -// } -// } +use thermaldecoder::{Header, HDR_SIZE}; +use v4l::video::Output; fn main() -> anyhow::Result<()> { dotenv().ok(); @@ -57,7 +24,20 @@ fn main() -> anyhow::Result<()> { let output = std::env::args() .nth(1) .expect("required output file argument"); - println!("Using output {}", output); + println!("Using output v4l2loopback device {}", output); + + const WIDTH: usize = 288; + const HEIGHT: usize = 384; + + let mut out = v4l::Device::with_path(output)?; + // To find the fourcc code, use v4l2-ctl --list-formats-out /dev/video0 + // (or read the source :) + let format = v4l::Format::new( + WIDTH as u32, + HEIGHT as u32, + v4l::format::FourCC::new(b"Y16 "), + ); + Output::set_format(&out, &format)?; // Setup Capture let mut cap = pcap::Capture::from_device(device) @@ -68,13 +48,12 @@ fn main() -> anyhow::Result<()> { // get a packet and print its bytes const PACKET_LEN: usize = 6972; - const FRAME_LEN: usize = 288 * 384 * 2; + const FRAME_LEN: usize = WIDTH * HEIGHT * 2; let mut frame = [0u8; FRAME_LEN]; let mut len = 0; - let mut out = File::create(&output)?; while let Ok(p) = cap.next_packet() { let data = p.data; - if data.len() != 6972 { + if data.len() != PACKET_LEN { continue; } let data = &data[0x2a..]; diff --git a/run_live.sh b/run_live.sh index 495575d..2008df6 100755 --- a/run_live.sh +++ b/run_live.sh @@ -6,9 +6,8 @@ set -e # Python works but stutters #sudo ./venv/bin/python ./decode.py --live cargo build --release --example live -sudo ./target/release/examples/live /dev/stdout | gst-launch-1.0 filesrc location=/dev/stdin \ - ! rawvideoparse use_sink_caps=false height=384 width=288 format=gray16-le \ - ! videoconvertscale \ - ! v4l2sink device=/dev/video0 -# ! videoconvertscale - +TARGET=./target/release/examples/live +# setcap does not work yet (EPERM on socket AF_PACKET) +# sudo setcap cap_net_raw,cap_net_admin=eip $TARGET +#strace -f -o live.strace $TARGET /dev/video0 +sudo $TARGET /dev/video0