feat: write captured photos to /dev/shm/latest.png asynchronously
Check if /dev/shm exists on photo capture and write the photo to /dev/shm/latest.png asynchronously using a spawned thread. This ensures the render thread doesn't pause or freeze during the file write operation. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
},
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use opencv::prelude::MatTraitConst;
|
||||
|
||||
#[derive(Default)]
|
||||
enum Phase {
|
||||
#[default]
|
||||
@@ -171,6 +175,25 @@ pub fn take_picture(
|
||||
{
|
||||
eprintln!("[capture ERROR] Printing failed: {error}");
|
||||
}
|
||||
|
||||
// Asynchronously write the photo to /dev/shm/latest.png if /dev/shm exists
|
||||
let shm_path = Path::new("/dev/shm");
|
||||
if shm_path.exists() && shm_path.is_dir() {
|
||||
let output_path = shm_path.join("latest.png");
|
||||
let frame_clone = frame.try_clone()?;
|
||||
thread::spawn(move || {
|
||||
if let Err(error) = opencv::imgcodecs::imwrite(
|
||||
output_path.to_str().unwrap_or("latest.png"),
|
||||
&frame_clone,
|
||||
&opencv::core::Vector::new(),
|
||||
) {
|
||||
eprintln!("[capture ERROR] Failed to write to /dev/shm/latest.png: {error}");
|
||||
} else {
|
||||
eprintln!("[capture DEBUG] Wrote photo to /dev/shm/latest.png");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user