gated debug statements behind a feature

This commit is contained in:
Nickiel12 2024-05-04 18:00:40 -07:00
parent b5c7afadcb
commit c84a9748e7
5 changed files with 26 additions and 10 deletions

View file

@ -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"

View file

@ -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;

View file

@ -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<dyn std::error::Error>> {
pipe.write_all(message).await?;
// pipe.shutdown().await?;
Ok(())
}
fn calculate_tracking(
tracker_state: &Arc<Mutex<TrackerState>>,
) -> 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);

View file

@ -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<Vec<String>> = None;
let mut current_id: Option<u32> = 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::<Vec<&str>>()[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;

View file

@ -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::<u32>() {
#[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;