v4l by rust process, still sudo, endianess reversed

This commit is contained in:
devdesk 2024-02-17 16:55:53 +02:00
parent a917f75ce0
commit 0ff8d2b1fb
4 changed files with 140 additions and 45 deletions

116
Cargo.lock generated
View File

@ -469,6 +469,29 @@ dependencies = [
"rustc-demangle", "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]] [[package]]
name = "bit-set" name = "bit-set"
version = "0.5.3" version = "0.5.3"
@ -645,6 +668,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -672,6 +704,17 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fc239e0f6cb375d2402d48afb92f76f5404fd1df208a41930ec81eda078bea" 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]] [[package]]
name = "clipboard-win" name = "clipboard-win"
version = "5.1.0" version = "5.1.0"
@ -1084,6 +1127,12 @@ dependencies = [
"winit", "winit",
] ]
[[package]]
name = "either"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
[[package]] [[package]]
name = "emath" name = "emath"
version = "0.26.2" version = "0.26.2"
@ -1473,6 +1522,12 @@ dependencies = [
"xml-rs", "xml-rs",
] ]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]] [[package]]
name = "glow" name = "glow"
version = "0.13.1" version = "0.13.1"
@ -1806,6 +1861,12 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.153" version = "0.2.153"
@ -2289,6 +2350,12 @@ dependencies = [
"rusticata-macros", "rusticata-macros",
] ]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.1" version = "2.3.1"
@ -2385,6 +2452,16 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" 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]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.3.1" version = "1.3.1"
@ -2717,6 +2794,12 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.1" version = "1.4.1"
@ -2907,6 +2990,7 @@ dependencies = [
"png", "png",
"pyo3", "pyo3",
"serde", "serde",
"v4l",
] ]
[[package]] [[package]]
@ -3143,6 +3227,26 @@ dependencies = [
"percent-encoding", "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]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -3484,6 +3588,18 @@ dependencies = [
"web-sys", "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]] [[package]]
name = "widestring" name = "widestring"
version = "1.0.2" version = "1.0.2"

View File

@ -22,3 +22,4 @@ pcap-parser = { version = "0.14.1", features = ["data"] }
png = "0.17.10" png = "0.17.10"
pyo3 = { version = "0.20.0", "features" = ["extension-module"] } pyo3 = { version = "0.20.0", "features" = ["extension-module"] }
serde = { version = "1.0.193", features = ["derive", "serde_derive", "alloc"] } serde = { version = "1.0.193", features = ["derive", "serde_derive", "alloc"] }
v4l = "0.14.0"

View File

@ -1,40 +1,7 @@
use dotenv::dotenv; use dotenv::dotenv;
use std::fs::File;
use std::io::Write; use std::io::Write;
use thermaldecoder::{Frame, Header, HDR_SIZE}; use thermaldecoder::{Header, HDR_SIZE};
use v4l::video::Output;
// 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::<MyApp>::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"));
// });
// });
// }
// }
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
dotenv().ok(); dotenv().ok();
@ -57,7 +24,20 @@ fn main() -> anyhow::Result<()> {
let output = std::env::args() let output = std::env::args()
.nth(1) .nth(1)
.expect("required output file argument"); .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 // Setup Capture
let mut cap = pcap::Capture::from_device(device) let mut cap = pcap::Capture::from_device(device)
@ -68,13 +48,12 @@ fn main() -> anyhow::Result<()> {
// get a packet and print its bytes // get a packet and print its bytes
const PACKET_LEN: usize = 6972; 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 frame = [0u8; FRAME_LEN];
let mut len = 0; let mut len = 0;
let mut out = File::create(&output)?;
while let Ok(p) = cap.next_packet() { while let Ok(p) = cap.next_packet() {
let data = p.data; let data = p.data;
if data.len() != 6972 { if data.len() != PACKET_LEN {
continue; continue;
} }
let data = &data[0x2a..]; let data = &data[0x2a..];

View File

@ -6,9 +6,8 @@ set -e
# Python works but stutters # Python works but stutters
#sudo ./venv/bin/python ./decode.py --live #sudo ./venv/bin/python ./decode.py --live
cargo build --release --example live cargo build --release --example live
sudo ./target/release/examples/live /dev/stdout | gst-launch-1.0 filesrc location=/dev/stdin \ TARGET=./target/release/examples/live
! rawvideoparse use_sink_caps=false height=384 width=288 format=gray16-le \ # setcap does not work yet (EPERM on socket AF_PACKET)
! videoconvertscale \ # sudo setcap cap_net_raw,cap_net_admin=eip $TARGET
! v4l2sink device=/dev/video0 #strace -f -o live.strace $TARGET /dev/video0
# ! videoconvertscale sudo $TARGET /dev/video0