Skip to content

Commit

Permalink
Added delay to Processing::Partial (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm authored Feb 22, 2021
1 parent be146fc commit 8e3d0a5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ impl<'a> Application<'a> {
fn process_action(&mut self, mut action: Box<dyn Action>) {
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);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/commands/send_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use message_io::network::{Network};

use std::path::{Path};
use std::io::{Read};
use std::time::{Duration};

pub struct SendFileCommand;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/commands/send_stream/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 8e3d0a5

Please sign in to comment.