diff --git a/src/main.rs b/src/main.rs index cd4b8a1..4a28edf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::{ f32::consts::FRAC_PI_2, - io::stdout, + io::{stdin, stdout, Read}, net::{Ipv4Addr, SocketAddr, UdpSocket}, path::PathBuf, thread::sleep, @@ -84,6 +84,7 @@ enum Action { Image { path: PathBuf, }, + Video, Clear, } @@ -239,6 +240,32 @@ fn main() -> anyhow::Result<()> { }, )?; } + Action::Video => { + print!("{}", termion::clear::All); + + let mut frame_num: u32 = rand::thread_rng().gen(); + loop { + let w = layout.width_px(); + let h = layout.height_px(); + + let mut buf = vec![0; w as usize * h as usize * 3]; + stdin().lock().read_exact(&mut buf)?; + for c in &mut buf { + *c /= 6; + } + let image = RgbImage::from_vec(w, h, buf).unwrap(); + + print_image(&image); + + match send_frame(&socket, layout, frame_num, &image) { + Ok(()) | Err(SenderError::ConfirmationTimeout) => {} + Err(e) => return Err(e.into()), + }; + frame_num += 1; + + sleep(Duration::from_millis(30)); + } + } }; let frame_num: u32 = rand::thread_rng().gen();