feat: add video playback
This commit is contained in:
parent
c29d5b96a8
commit
3c36bc6766
1 changed files with 28 additions and 1 deletions
29
src/main.rs
29
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();
|
||||
|
|
Loading…
Reference in a new issue