From d05e4481b77009e66b31dfca55d775612828f525 Mon Sep 17 00:00:00 2001 From: lemunozm Date: Sun, 21 Feb 2021 13:37:09 +0100 Subject: [PATCH] Added delay to Processing::Partial --- src/action.rs | 4 +++- src/application.rs | 4 ++-- src/commands/send_file.rs | 5 ++++- src/commands/send_stream/linux.rs | 4 +++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/action.rs b/src/action.rs index c851866..535e2fa 100644 --- a/src/action.rs +++ b/src/action.rs @@ -2,9 +2,11 @@ use crate::state::{State}; use message_io::network::{Network}; +use std::time::{Duration}; + pub enum Processing { Completed, - Partial, + Partial(Duration), } pub trait Action: Send { diff --git a/src/application.rs b/src/application.rs index c86b366..5e4e04d 100644 --- a/src/application.rs +++ b/src/application.rs @@ -279,8 +279,8 @@ impl<'a> Application<'a> { fn process_action(&mut self, mut action: Box) { match action.process(&mut self.state, &mut self.network) { Processing::Completed => (), - Processing::Partial => { - self.event_queue.sender().send(Event::Action(action)); + Processing::Partial(delay) => { + self.event_queue.sender().send_with_timer(Event::Action(action), delay); } } } diff --git a/src/commands/send_file.rs b/src/commands/send_file.rs index eaae40a..ee6e6c7 100644 --- a/src/commands/send_file.rs +++ b/src/commands/send_file.rs @@ -8,6 +8,7 @@ use message_io::network::{Network}; use std::path::{Path}; use std::io::{Read}; +use std::time::{Duration}; pub struct SendFileCommand; @@ -64,7 +65,9 @@ impl Action for SendFile { let (bytes_read, chunk, processing) = match self.file.read(&mut data) { Ok(0) => (0, Chunk::End, Processing::Completed), Ok(bytes_read) => { - (bytes_read, Chunk::Data(data[..bytes_read].to_vec()), Processing::Partial) + // We add a minor delay to introduce a rate in the sending. + let processing = Processing::Partial(Duration::from_micros(100)); + (bytes_read, Chunk::Data(data[..bytes_read].to_vec()), processing) } Err(error) => { format!("Error sending file. error: {}", error).report_err(state); diff --git a/src/commands/send_stream/linux.rs b/src/commands/send_stream/linux.rs index 4f9f359..e3d1259 100644 --- a/src/commands/send_stream/linux.rs +++ b/src/commands/send_stream/linux.rs @@ -11,6 +11,8 @@ use v4l::buffer::Type; use v4l::io::traits::CaptureStream; use v4l::video::traits::Capture; +use std::time::{Duration}; + // Send Stream logic pub struct SendStreamCommand; @@ -88,7 +90,7 @@ impl Action for SendStream { let message = NetMessage::Stream(Some((data, self.width, self.height))); network.send_all(state.all_user_endpoints(), message); - Processing::Partial + Processing::Partial(Duration::from_millis(16)) //~60fps - delay of computation } }