Compare commits

..

No commits in common. "8924d2ab8f9641c37d74910dbe1d515dbe0c1556" and "81a4f04d6b7968bd5ab016d7b24a027c6d6ac7fe" have entirely different histories.

5 changed files with 73 additions and 159 deletions

View file

@ -17,9 +17,9 @@ use tokio_tungstenite::{tungstenite::Message, MaybeTlsStream, WebSocketStream};
use tracing::{debug, error, info, instrument};
mod coord_state;
mod perf_state;
mod process_box_string;
mod remote_video_processor;
mod perf_state;
use crate::config::AppConfig;
use crate::remote_sources::TrackerState;
@ -63,15 +63,7 @@ pub async fn start_coordinator(
let mec = pin!(mec);
let mut state = CoordState::new(
mec,
to_mec,
to_gui,
runtime,
tracker_state,
settings,
tracker_header,
);
let mut state = CoordState::new(mec, to_mec, to_gui, runtime, tracker_state, settings, tracker_header);
state
.pipeline

View file

@ -1,4 +1,4 @@
use std::{collections::VecDeque, sync, time::Duration};
use std::{sync, time::Duration, collections::VecDeque};
const MAX_RECORDED_TIMES: usize = 10;
const DEGRADED_TRACKER_TIME: u128 = 100;
@ -7,28 +7,15 @@ const DEGRADED_TRACKER_TIME: u128 = 100;
pub struct TrackerMetrics {
pub header_text: sync::Arc<sync::RwLock<String>>,
tracker_times: VecDeque<u128>,
}
impl TrackerMetrics {
pub fn new(text_reference: sync::Arc<sync::RwLock<String>>) -> Self {
let mut ret = TrackerMetrics {
TrackerMetrics {
header_text: text_reference,
tracker_times: VecDeque::with_capacity(MAX_RECORDED_TIMES),
};
ret.clear_times();
ret
}
pub fn starting_connection(&mut self, fail_count: Option<usize>) {
self.clear_times();
if let Ok(mut writer) = self.header_text.write() {
writer.clear();
match fail_count {
None => writer.push_str("Status: Connecting ..."),
Some(v) => writer.push_str(&format!("Status: Attempt {}/5", v)),
}
}
}
@ -37,10 +24,6 @@ impl TrackerMetrics {
self.tracker_times.pop_front();
}
self.insert_time(Duration::new(0, 0));
if let Ok(mut writer) = self.header_text.write() {
writer.clear();
writer.push_str("Status: Disconnected");
}
}
pub fn insert_time(&mut self, new_measurement: Duration) {
@ -54,29 +37,21 @@ impl TrackerMetrics {
if avg_time == 0 {
if let Ok(mut writer) = self.header_text.write() {
writer.clear();
writer.push_str(&format!(
"Status: Failed Avg Response: {} ms",
avg_time.to_string()
));
writer.push_str(&format!("Status: Failed Avg Response: {} ms", avg_time.to_string()));
}
}
if avg_time > DEGRADED_TRACKER_TIME {
if let Ok(mut writer) = self.header_text.write() {
writer.clear();
writer.push_str(&format!(
"Status: Degraded Avg Response: {} ms",
avg_time.to_string()
));
writer.push_str(&format!("Status: Degraded Avg Response: {} ms", avg_time.to_string()));
}
} else {
if let Ok(mut writer) = self.header_text.write() {
writer.clear();
writer.push_str(&format!(
"Status: Nominal Avg Response: {} ms",
avg_time.to_string()
));
writer.push_str(&format!("Status: Nominal Avg Response: {} ms", avg_time.to_string()));
}
}
}
}

View file

@ -18,10 +18,7 @@ use tracing::{error, info, instrument};
use crate::remote_sources::TrackerState;
use super::{
perf_state::TrackerMetrics, process_box_string::process_incoming_string, ApplicationEvent,
SocketState,
};
use super::{perf_state::TrackerMetrics, process_box_string::process_incoming_string, ApplicationEvent, SocketState};
#[instrument]
pub async fn remote_video_loop(
@ -43,27 +40,10 @@ pub async fn remote_video_loop(
.build()
.expect("Could not build video info!");
let mut fail_count = 0;
{
let mut tm = tracker_metrics.lock().await;
tm.starting_connection(None);
}
loop {
socket_state.is_connected.store(true, Ordering::SeqCst);
match connect_async(&conn_string).await {
Err(e) => {
fail_count += 1;
{
let mut tm = tracker_metrics.lock().await;
tm.starting_connection(Some(fail_count));
}
if fail_count >= 5 {
break;
}
error!("Could not connect to remote video loop! Trying again in 1 seconds: {e}");
sleep_until(Instant::now() + Duration::from_secs(1)).await;
}
@ -137,15 +117,10 @@ pub async fn remote_video_loop(
}
}
if !socket_state.stay_connected.load(Ordering::SeqCst) {
info!("Shutting down remote video loop");
break;
}
}
info!("Shutting down remote video loop");
{
let mut tm = tracker_metrics.lock().await;
tm.clear_times();
}
socket_state.is_connected.store(false, Ordering::SeqCst);
}
@ -191,7 +166,7 @@ async fn listen_to_messages(
}
}
info!(
"Stopping tracker listen connection with keep alive: {}",
"Stopping tracker connection listen with keep alive: {}",
socket_state.stay_connected.load(Ordering::SeqCst)
);
}

View file

@ -1,6 +1,5 @@
use gtk::{
gdk::Paintable, prelude::BoxExt, AspectFrame, Box, DrawingArea, Label, Overlay, Picture,
};
use gtk::{gdk::Paintable, prelude::BoxExt, AspectFrame, Box, DrawingArea, Label, Overlay, Picture};
pub struct LiveViewPanel {
top_level: gtk::Box,
@ -14,6 +13,7 @@ pub struct LiveViewPanel {
impl LiveViewPanel {
pub fn new() -> Self {
let right_box = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.hexpand(true)
@ -23,13 +23,12 @@ impl LiveViewPanel {
let tracker_status_label = Label::builder()
.label("No Status Yet".to_string())
.can_focus(true)
.css_classes(vec!["large-label", "NoConnection"])
.css_classes(vec!["large-label"])
.build();
// let conn_status_label = Label::new(Some(&"No Connection".to_string()));
let cam_status_label = Label::builder()
.label("No Connection".to_string())
.css_classes(vec!["NoConnection"])
.can_focus(true)
.build();

View file

@ -16,8 +16,8 @@ use crate::coordinator::{start_coordinator, ApplicationEvent, MoveEvent};
use crate::remote_sources::TrackerState;
mod control_panel;
mod liveview_panel;
mod settings_modal;
mod liveview_panel;
use control_panel::ControlPanel;
use liveview_panel::LiveViewPanel;
@ -165,7 +165,7 @@ pub fn build_ui(app: &Application, config: Arc<RwLock<AppConfig>>, runtime: Hand
tracker_header.clone(),
));
let control_panel = ControlPanel::new(tracker_state.clone());
let control_panel = Arc::new(ControlPanel::new(tracker_state.clone()));
control_panel.connect_button_callbacks(to_mec.clone());
// left_box.append(&conn_status_label);
@ -221,41 +221,13 @@ pub fn build_ui(app: &Application, config: Arc<RwLock<AppConfig>>, runtime: Hand
}),
);
let tracker_status_label = liveview_panel.tracker_status_label.clone();
let tracker_enable_toggle = control_panel
.connection_buttons
.tracker_enable_toggle
.clone();
glib::timeout_add_seconds_local(1, move || {
if let Ok(reader) = tracker_header.read() {
tracker_status_label.set_text(reader.as_str());
if reader.contains("Failed") || reader.contains("Disconnected") {
tracker_status_label.set_css_classes(&["NoConnection"]);
tracker_enable_toggle.set_label("Press to Connect Tracker");
tracker_enable_toggle.set_active(false);
} else if reader.contains("Degraded") || reader.contains("Connecting") {
tracker_status_label.set_css_classes(&["LoadingConnection"]);
tracker_enable_toggle.set_label("Press to Connect");
tracker_enable_toggle.set_active(false);
} else if reader.contains("Nominal") {
tracker_status_label.set_css_classes(&["YesConnection"]);
tracker_enable_toggle.set_label("Press to Disconnect");
tracker_enable_toggle.set_active(true);
}
glib::ControlFlow::Continue
} else {
error!("Couldn't get rwlock on metrics");
glib::ControlFlow::Break
}
});
glib::spawn_future_local(glib::clone!(@weak drawable => async move {
glib::spawn_future_local(
glib::clone!(@weak drawable => async move {
while let Ok(d) = gui_recv.recv().await {
drawable.queue_draw();
if let Ok(reader) = tracker_header.read() {
liveview_panel.tracker_status_label.set_text(reader.as_str());
}
match d {
GuiUpdate::MoveEvent(msg) => {
liveview_panel.adjustment_label.set_text(
@ -293,7 +265,8 @@ pub fn build_ui(app: &Application, config: Arc<RwLock<AppConfig>>, runtime: Hand
}
}
info!("Closing update loop");
}));
}),
);
window.connect_close_request(move |_| glib::Propagation::Proceed);