Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added delay to Processing::Partial #42

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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