diff --git a/Cargo.toml b/Cargo.toml index 31b6fa6..5debb58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +tracker-state-debug = [] + [dependencies] async-channel = "2.2.0" config = "0.14.0" diff --git a/src/coordinator/mod.rs b/src/coordinator/mod.rs index b578433..1b6aae3 100644 --- a/src/coordinator/mod.rs +++ b/src/coordinator/mod.rs @@ -239,6 +239,7 @@ pub async fn start_coordinator( state.socket_send(socket_message).await; } ApplicationEvent::EnableAutomatic(do_enable) => { + #[cfg(feature = "tracker-state-debug")] debug!("Trying to get lock on tracker_state for enable automatic"); if let Ok(mut ts) = state.tracker_state.lock() { ts.enabled = do_enable; diff --git a/src/remote_sources/shared_video_pipe.rs b/src/remote_sources/shared_video_pipe.rs index 7a0886e..87474c4 100644 --- a/src/remote_sources/shared_video_pipe.rs +++ b/src/remote_sources/shared_video_pipe.rs @@ -113,7 +113,6 @@ pub async fn create_outbound_pipe( break; } }; - // info!("Video frame {}x{} with stride of {}, is this many bytes: {}", video_frame.width(), video_frame.height(), video_frame.plane_stride()[0], video_frame.plane_data(0).unwrap().len()); // Send video frame to pipe if let Err(e) = send_to_pipe(&mut state.pipe, video_frame.plane_data(0).unwrap()).await @@ -168,20 +167,19 @@ async fn send_to_pipe<'a>( message: &'a [u8], ) -> Result<(), Box> { pipe.write_all(message).await?; - // pipe.shutdown().await?; - Ok(()) } fn calculate_tracking( tracker_state: &Arc>, ) -> core::result::Result<(i32, i32), String> { + #[cfg(feature = "tracker-state-debug")] debug!("Getting lock on tracker state for caculate tracking"); if let Ok(mut ts) = tracker_state.lock() { - if ts.last_detect + Duration::from_secs(2) < Instant::now() && !ts.identity_boxes.is_empty() { - info!("Setting new target: {}", ts.identity_boxes[0].id); - ts.tracking_id = ts.identity_boxes[0].id; - } + // if ts.last_detect + Duration::from_secs(2) < Instant::now() && !ts.identity_boxes.is_empty() { + // info!("Setting new target: {}", ts.identity_boxes[0].id); + // ts.tracking_id = ts.identity_boxes[0].id; + // } if let Some(target_box) = ts.identity_boxes.iter().find(|e| e.id == ts.tracking_id) { let x_adjust = calc_x_adjust(target_box.x1, target_box.x2); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index bbde2b1..4f9b623 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -163,15 +163,19 @@ pub fn build_ui(app: &Application, runtime: Handle) { overlay_box.add_overlay(&drawable); let items = tracker_panel.items.clone(); + let id_label = tracker_panel.current_id.clone(); glib::timeout_add_seconds_local(1, - glib::clone!(@strong items => move || { + glib::clone!(@strong items, @strong id_label => move || { + #[cfg(feature = "tracker-state-debug")] debug!("Getting lock on tracker state for checking identity boxes"); // don't update the stringlist until after letting go of the tracker state // due to async interweaving causing a mutex deadlock let mut ids: Option> = None; + let mut current_id: Option = None; if let Ok(ts) = tracker_state.lock() { + current_id = Some(ts.tracking_id); if ts.update_ids { ids = Some(ts.identity_boxes .iter() @@ -180,6 +184,10 @@ pub fn build_ui(app: &Application, runtime: Handle) { } } + if let Some(id) = current_id { + id_label.set_text(id.to_string().as_str()); + } + if let Some (ids) = ids { let old_len = items.n_items(); items.splice(0, old_len, &ids.iter().map(|x| x.as_str()).collect::>()[0..]) @@ -252,6 +260,7 @@ fn draw_boxes( ); ctx.set_font_size(24.0); + #[cfg(feature = "tracker-state-debug")] debug!("Getting tracker state for drawing boxes"); if let Ok(ts) = tracker_state.lock() { let active = ts.tracking_id; diff --git a/src/ui/tracker_panel.rs b/src/ui/tracker_panel.rs index ce4b9aa..334459f 100644 --- a/src/ui/tracker_panel.rs +++ b/src/ui/tracker_panel.rs @@ -14,7 +14,7 @@ pub struct TrackerPanel { top_level: Box, enable_disable: ToggleButton, - current_id: Label, + pub current_id: Label, scrolled_window: ScrolledWindow, pub items: StringList, @@ -40,7 +40,11 @@ impl TrackerPanel { let items = StringList::new(&["item1", "item2", "item3"]); - let model = SingleSelection::builder().model(&items).build(); + let model = SingleSelection::builder() + .model(&items) + .autoselect(false) + .can_unselect(false) + .build(); model.connect_selected_item_notify(move |x| { let item = x @@ -49,6 +53,7 @@ impl TrackerPanel { if let Some(item) = item { if let Ok(id) = item.string().parse::() { + #[cfg(feature = "tracker-state-debug")] debug!("Getting lock on tracker state for setting active tracking id!"); if let Ok(mut ts) = tracker_state.lock() { ts.tracking_id = id;