sketching out network sending

main
_ 2023-09-12 22:54:53 -05:00
parent b90c934242
commit d6297dcbd3
2 changed files with 66 additions and 16 deletions

View File

@ -6,8 +6,9 @@ use std::
pub enum MsgFromController
{
RepaintGui (RgbaFrame),
StartCapture,
StartJpegDecoder (JpegFrame),
StartNetworkSend (JpegFrame),
StartCapture,
}
#[derive (Clone)]
@ -29,12 +30,16 @@ pub struct Controller
gui_has_new_frame: bool,
gui_needs_frame: bool,
capture_is_running: bool,
jpeg_decoder_is_running: bool,
jpeg_decoder_has_new_frame: bool,
jpeg_decoder_needs_frame: bool,
network_send_is_running: bool,
network_send_has_new_frame: bool,
network_send_needs_frame: bool,
capture_is_running: bool,
rgba_frame: RgbaFrame,
jpeg_frame: JpegFrame,
}
@ -48,11 +53,16 @@ impl Controller
gui_has_new_frame: false,
gui_needs_frame: false,
capture_is_running: false,
jpeg_decoder_has_new_frame: false,
jpeg_decoder_is_running: false,
jpeg_decoder_needs_frame: false,
network_send_has_new_frame: false,
network_send_is_running: false,
network_send_needs_frame: true,
capture_is_running: false,
rgba_frame: RgbaFrame
{
data: Default::default (),
@ -66,6 +76,25 @@ impl Controller
}
}
pub fn handle_gui_needs_frame (&mut self)
{
// println! ("handle_gui_needs_frame");
self.gui_needs_frame = true;
}
pub fn handle_network_write_needs_frame (&mut self)
{
println! ("handle_network_write_needs_frame");
self.network_send_needs_frame = true;
}
pub fn handle_network_write_finished (&mut self)
{
println! ("handle_network_write_finished");
self.network_send_has_new_frame = false;
self.network_send_is_running = false;
}
pub fn handle_rgba_frame (&mut self, frame: RgbaFrame)
{
// println! ("handle_rgba_frame");
@ -79,18 +108,18 @@ impl Controller
{
// println! ("handle_capture");
self.capture_is_running = false;
self.jpeg_frame = jpeg;
self.jpeg_decoder_has_new_frame = true;
}
pub fn handle_gui_needs_frame (&mut self)
{
// println! ("handle_gui_needs_frame");
self.gui_needs_frame = true;
self.jpeg_frame = jpeg;
self.jpeg_decoder_has_new_frame = true;
self.network_send_has_new_frame = true;
}
pub fn poll (&mut self) -> Option <MsgFromController>
{
let capture_for_jpeg_decoder = self.jpeg_decoder_needs_frame && ! self.jpeg_decoder_has_new_frame;
let capture_for_network_send = self.network_send_needs_frame && ! self.network_send_has_new_frame;
if self.gui_needs_frame && self.gui_has_new_frame
{
self.gui_has_new_frame = false;
@ -105,7 +134,13 @@ impl Controller
// println! ("StartJpegDecoder");
Some (MsgFromController::StartJpegDecoder (self.jpeg_frame.clone ()))
}
else if self.jpeg_decoder_needs_frame && ! self.jpeg_decoder_has_new_frame && ! self.capture_is_running
else if self.network_send_has_new_frame && ! self.network_send_is_running && self.network_send_needs_frame
{
self.network_send_is_running = true;
self.network_send_needs_frame = false;
Some (MsgFromController::StartNetworkSend (self.jpeg_frame.clone ()))
}
else if (capture_for_jpeg_decoder || capture_for_network_send) && ! self.capture_is_running
{
self.capture_is_running = true;
// println! ("StartCapture");

View File

@ -21,8 +21,9 @@ use crate::
pub enum MsgToDriver
{
GuiNeedsRgbaFrame,
GotCapture ((Capture, JpegFrame)),
DecodedJpegToRgba (RgbaFrame),
NetworkWriteFinished,
GotCapture ((Capture, JpegFrame)),
}
pub enum MsgToGui
@ -75,19 +76,23 @@ impl Driver
{
match self.recv.recv().unwrap ()
{
MsgToDriver::GuiNeedsRgbaFrame =>
{
self.ctl.handle_gui_needs_frame ();
},
MsgToDriver::DecodedJpegToRgba (frame) =>
{
self.ctl.handle_rgba_frame (frame);
},
MsgToDriver::NetworkWriteFinished =>
{
self.ctl.handle_network_write_finished ();
},
MsgToDriver::GotCapture ((capture, jpeg)) =>
{
self.ctl.handle_capture (jpeg);
self.capture = Some (capture);
},
MsgToDriver::GuiNeedsRgbaFrame =>
{
self.ctl.handle_gui_needs_frame ();
},
}
while let Some (msg) = self.ctl.poll ()
@ -120,6 +125,16 @@ impl Driver
send.send (MsgToDriver::DecodedJpegToRgba (rgba)).unwrap ();
});
},
MsgFromController::StartNetworkSend (jpeg) =>
{
let send = self.send.clone ();
pool.spawn (move ||
{
sleep_ms (50);
send.send (MsgToDriver::NetworkWriteFinished).unwrap ();
});
},
MsgFromController::StartCapture =>
{
let mut capture = self.capture.take ().unwrap ();