diff --git a/Cargo.lock b/Cargo.lock index 1fff9cc..338bd9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -632,40 +632,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset 0.9.0", - "scopeguard", -] - [[package]] name = "crossbeam-utils" version = "0.8.16" @@ -809,12 +775,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - [[package]] name = "emath" version = "0.22.0" @@ -935,7 +895,6 @@ version = "0.1.0" dependencies = [ "eframe", "linuxvideo", - "rayon", "thiserror", "tokio", "zune-core", @@ -1396,15 +1355,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1854,28 +1804,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" -[[package]] -name = "rayon" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - [[package]] name = "redox_syscall" version = "0.3.5" diff --git a/Cargo.toml b/Cargo.toml index abbb030..e6918ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] eframe = "0.22.0" linuxvideo = { path = "deps/LinuxVideo" } -rayon = "1.7.0" thiserror = "1.0.48" tokio = { version = "1.32.0", features = ["full"] } zune-core = { path = "deps/zune-image/zune-core" } diff --git a/src/driver.rs b/src/driver.rs index 0ce9af1..fc8d5f7 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -30,7 +30,7 @@ pub enum MsgToDriver pub enum MsgToGui { - NewRgbaFrame (RgbaFrame), + NewRgbaFrame ((RgbaFrame, Instant)), } pub struct Driver @@ -101,7 +101,7 @@ impl Driver { MsgFromController::RepaintGui (rgba_frame) => { - self.send_to_gui.send (MsgToGui::NewRgbaFrame (rgba_frame)).await.ok (); + self.send_to_gui.send (MsgToGui::NewRgbaFrame ((rgba_frame, Instant::now ()))).await.ok (); self.gui_ctx.request_repaint(); }, MsgFromController::StartJpegDecoder (jpeg_frame) => @@ -143,7 +143,10 @@ impl Driver tokio::task::spawn_blocking (move || { let mut data = vec! [0u8; capture.size_image()]; - capture.wait_for_frame(&mut data).unwrap (); + + let len = capture.wait_for_frame(&mut data).unwrap (); + + data.resize (len, 0u8); let frame = JpegFrame { diff --git a/src/main.rs b/src/main.rs index e63bd25..84dbd32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,10 +120,10 @@ impl eframe::App for App { { match msg { - MsgToGui::NewRgbaFrame (frame) => + MsgToGui::NewRgbaFrame ((frame, _present_time)) => { texture.set (egui::ColorImage::from_rgba_premultiplied([1280,720], &frame.data), Default::default ()); - self.latency = Instant::now () - frame.capture_time; + self.latency = std::cmp::max (self.latency, Instant::now () - frame.capture_time); self.camera_frames += 1; // println! (" Camera"); }, @@ -139,10 +139,11 @@ impl eframe::App for App { self.camera_fps = self.camera_frames; self.gui_frames = 0; self.camera_frames = 0; + self.latency = Duration::default (); self.next_stat_refresh += Duration::from_secs(1); } - ui.heading (format! ("{0}, {1}, {2}", self.camera_fps, self.gui_fps, self.latency.as_millis ())); + ui.heading (format! ("{0}, latency {1} ms", self.camera_fps, self.latency.as_millis ())); let available = ui.available_size() - egui::Vec2::new (0.0, 20.0); let tex_size = egui::Vec2::new (texture.size()[0] as f32, texture.size()[1] as f32); let scaled_width = available.y * tex_size.x / tex_size.y; @@ -162,8 +163,6 @@ impl eframe::App for App { // println! ("GUI"); ui.checkbox(&mut self.requesting_frames, "Run"); - - // driver::sleep_ms (500); }); } }