feat(telemetry,ui): add PC pipeline latency, --gst-latency-trace & Glass-to-Glass stopwatch

This commit is contained in:
bleackstorm committed 2026-11-26 14:06:20 +01:00
1 parent 9f0c64f873
commit b24d4e0a27
9 files changed
+140 -6

No files matched your search

+4
View File
@@ -252,6 +252,10 @@ pub struct AppConfig {
#[arg(long, default_value_t = false)]
pub zero_copy_dmabuf: bool,
/// Active le traceur de latence GStreamer natif (`GST_TRACERS=latency`) dans les logs
#[arg(long, default_value_t = false)]
pub gst_latency_trace: bool,
/// Chemin du fichier journal d'erreurs et de diagnostic
#[arg(long, default_value = "steamframe_fpv.log")]
pub log_file: String,
+3
View File
@@ -96,6 +96,7 @@ pub fn run_desktop_fallback_loop(ctx: &mut EngineWorkerRefs<'_>) {
let mut has_new_raw_frame = false;
let mut has_video_stream = false;
let mut frame_fmt = PixelFormat::Rgba;
let mut frame_received_at: Option<Instant> = None;
if let Some(rx) = ctx.video_rx_opt {
let (live, taken) = rx.take_latest_frame(
@@ -108,6 +109,7 @@ pub fn run_desktop_fallback_loop(ctx: &mut EngineWorkerRefs<'_>) {
if meta.width == ctx.cfg.video_width && meta.height == ctx.cfg.video_height {
last_frame_id = meta.frame_id;
frame_fmt = meta.format;
frame_received_at = Some(meta.received_at);
fps_counter += 1;
has_new_raw_frame = true;
}
@@ -166,6 +168,7 @@ pub fn run_desktop_fallback_loop(ctx: &mut EngineWorkerRefs<'_>) {
has_new_raw_frame,
has_video_stream,
last_frame_id,
frame_received_at,
&mut fps_counter,
&mut fps_timer,
&mut last_preview_push,
+12
View File
@@ -667,6 +667,7 @@ pub fn compose_osd_and_publish(
has_new_raw_frame: bool,
has_video_stream: bool,
last_frame_id: u64,
frame_received_at: Option<Instant>,
fps_counter: &mut u32,
fps_timer: &mut Instant,
last_preview_push: &mut Option<Instant>,
@@ -801,8 +802,10 @@ pub fn compose_osd_and_publish(
let push_preview = ctx.control.is_preview_active()
&& last_preview_push.is_none_or(|t| t.elapsed() >= Duration::from_millis(33));
if push_preview || fps_timer.elapsed() >= Duration::from_secs(1) || frame_received_at.is_some() {
if push_preview || fps_timer.elapsed() >= Duration::from_secs(1) {
sync_video_status(ctx.cfg, ctx.video_rx_opt, &ctx.shared.monitor);
}
let preview_arc = if push_preview {
*last_preview_push = Some(Instant::now());
// Conversion directe RGBA -> BGRA sur le worker (zéro swizzle/clone sur le thread UI GPUI)
@@ -812,6 +815,14 @@ pub fn compose_osd_and_publish(
None
};
let mut mon = ctx.shared.monitor.lock();
if let Some(recv_at) = frame_received_at {
let eng_ms = recv_at.elapsed().as_secs_f32() * 1000.0;
mon.video_engine_latency_ms = if mon.video_engine_latency_ms <= 0.01 {
eng_ms
} else {
mon.video_engine_latency_ms * 0.8 + eng_ms * 0.2
};
}
if fps_timer.elapsed() >= Duration::from_secs(1) {
if has_video_stream {
mon.video_fps = *fps_counter as f32 / fps_timer.elapsed().as_secs_f32();
@@ -840,6 +851,7 @@ pub fn compose_osd_and_publish(
mon.preview_width = ctx.cfg.video_width;
mon.preview_height = ctx.cfg.video_height;
mon.preview_bgra = arc;
mon.preview_received_at = frame_received_at;
mon.preview_frame_seq = mon.preview_frame_seq.wrapping_add(1);
}
}
+4
View File
@@ -65,9 +65,11 @@ pub struct RuntimeMonitor {
pub dmabuf_active: bool,
pub video_fps: f32,
pub video_jitter_ms: f32,
pub video_engine_latency_ms: f32,
pub video_dropped_frames: u64,
pub video_decoder_name: String,
pub video_frames_total: u64,
pub preview_received_at: Option<Instant>,
pub latest_head_pose: HeadPoseSample,
pub latest_telemetry: TelemetryState,
pub latest_g29: G29State,
@@ -104,9 +106,11 @@ impl Default for RuntimeMonitor {
dmabuf_active: false,
video_fps: 0.0,
video_jitter_ms: 0.0,
video_engine_latency_ms: 0.0,
video_dropped_frames: 0,
video_decoder_name: "auto".to_string(),
video_frames_total: 0,
preview_received_at: None,
latest_head_pose: HeadPoseSample::default(),
latest_telemetry: TelemetryState::default(),
latest_g29: G29State::default(),
+4
View File
@@ -546,6 +546,7 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
let mut has_new_raw_frame = false;
let mut has_video_stream = false;
let mut taken_dmabuf: Option<DmaBufFrame> = None;
let mut frame_received_at: Option<Instant> = None;
if let Some(rx) = ctx.video_rx_opt {
rx.set_dmabuf_handoff(want_dmabuf);
@@ -559,6 +560,7 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
if d.width == ctx.cfg.video_width && d.height == ctx.cfg.video_height {
last_frame_id = d.frame_id;
raw_frame_format = d.format;
frame_received_at = Some(d.received_at);
fps_counter += 1;
has_new_raw_frame = true;
taken_dmabuf = Some(d);
@@ -579,6 +581,7 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
{
last_frame_id = meta.frame_id;
raw_frame_format = meta.format;
frame_received_at = Some(meta.received_at);
fps_counter += 1;
has_new_raw_frame = true;
}
@@ -662,6 +665,7 @@ pub fn try_run_openxr_session(ctx: &mut EngineWorkerRefs<'_>) -> Result<()> {
has_new_raw_frame,
has_video_stream,
last_frame_id,
frame_received_at,
&mut fps_counter,
&mut fps_timer,
&mut last_preview_push,
+8
View File
@@ -45,6 +45,14 @@ fn install_signal_handlers() {
fn main() -> Result<()> {
install_signal_handlers();
let mut cfg = AppConfig::parse_with_saved();
if cfg.gst_latency_trace {
if std::env::var_os("GST_TRACERS").is_none() {
std::env::set_var("GST_TRACERS", "latency(flags=pipeline+element)");
}
if std::env::var_os("GST_DEBUG").is_none() {
std::env::set_var("GST_DEBUG", "GST_TRACER:7");
}
}
let log_buffer = GuiLogger::init(&cfg.log_file);
let mode_label = if cfg.vr_only {
+70 -1
View File
@@ -125,7 +125,12 @@ impl SteamFrameGpuiApp {
.rounded_md()
.text_xs()
.text_color(rgb(COLOR_TEXT_MUTED))
.child(format!("{} trames", self.video_frames_total)),
.child(format!(
"{} trames • PC {:.1} ms (moteur {:.1} ms)",
self.video_frames_total,
self.video_pc_latency_ms,
self.video_engine_latency_ms
)),
),
)
// 2.3 Overlay Supérieur Droit (VR & Format)
@@ -185,6 +190,35 @@ impl SteamFrameGpuiApp {
"⏮ Replay 30s".to_string()
}),
)
.child(
div()
.id("btn_toggle_g2g")
.px_2p5()
.py_1()
.bg(rgba(0x0a101abb))
.border_1()
.border_color(if self.glass_to_glass_test {
rgb(COLOR_CYAN)
} else {
rgb(COLOR_BORDER_SUBTLE)
})
.rounded_md()
.text_xs()
.text_color(if self.glass_to_glass_test {
rgb(COLOR_CYAN)
} else {
rgb(COLOR_TEXT_MUTED)
})
.cursor_pointer()
.on_click(cx.listener(|this, _, _, cx| {
this.glass_to_glass_test = !this.glass_to_glass_test;
if this.glass_to_glass_test {
this.glass_to_glass_t0 = std::time::Instant::now();
}
cx.notify();
}))
.child("⏱️ Chrono G2G"),
)
.child(
div()
.id("btn_toggle_hud")
@@ -208,6 +242,41 @@ impl SteamFrameGpuiApp {
}),
),
)
// 2.3b Chrono haute précision pour mesure Glass-to-Glass (filmer l'écran avec la caméra FPV)
.when(self.glass_to_glass_test, |el| {
let elapsed_ms = self.glass_to_glass_t0.elapsed().as_millis();
let secs = elapsed_ms / 1000;
let ms = elapsed_ms % 1000;
el.child(
div()
.absolute()
.top_12()
.left_3()
.px_4()
.py_2()
.bg(rgb(0x000000))
.border_2()
.border_color(rgb(COLOR_CYAN))
.rounded_lg()
.flex()
.flex_col()
.gap_1()
.child(
div()
.text_xs()
.font_weight(gpui::FontWeight::BOLD)
.text_color(rgb(COLOR_CYAN))
.child("⏱️ TEST GLASS-TO-GLASS (pointer la caméra FPV ici)"),
)
.child(
div()
.text_2xl()
.font_weight(gpui::FontWeight::BOLD)
.text_color(rgb(0xffffff))
.child(format!("{:04}.{:03} s", secs, ms)),
),
)
})
// 2.4 Bandeau Flottant Inférieur (HUD Télémetrie & Suivi Tête discret)
.child(if self.show_hud_overlay {
div()
+30 -3
View File
@@ -78,9 +78,13 @@ pub struct SteamFrameGpuiApp {
dmabuf_active: bool,
video_fps: f32,
video_jitter_ms: f32,
video_engine_latency_ms: f32,
video_pc_latency_ms: f32,
video_dropped_frames: u64,
video_decoder_name: String,
video_frames_total: u64,
glass_to_glass_test: bool,
glass_to_glass_t0: Instant,
latest_pose: HeadPoseSample,
latest_telem: TelemetryState,
latest_g29: G29State,
@@ -159,9 +163,13 @@ impl SteamFrameGpuiApp {
dmabuf_active: false,
video_fps: 0.0,
video_jitter_ms: 0.0,
video_engine_latency_ms: 0.0,
video_pc_latency_ms: 0.0,
video_dropped_frames: 0,
video_decoder_name: "auto".to_string(),
video_frames_total: 0,
glass_to_glass_test: false,
glass_to_glass_t0: Instant::now(),
latest_pose: HeadPoseSample::default(),
latest_telem: TelemetryState::default(),
latest_g29: G29State::default(),
@@ -257,11 +265,13 @@ impl SteamFrameGpuiApp {
}
if (self.video_fps - mon.video_fps).abs() > 0.1
|| (self.video_jitter_ms - mon.video_jitter_ms).abs() > 0.1
|| (self.video_engine_latency_ms - mon.video_engine_latency_ms).abs() > 0.2
|| self.video_dropped_frames != mon.video_dropped_frames
|| self.video_decoder_name != mon.video_decoder_name
{
self.video_fps = mon.video_fps;
self.video_jitter_ms = mon.video_jitter_ms;
self.video_engine_latency_ms = mon.video_engine_latency_ms;
self.video_dropped_frames = mon.video_dropped_frames;
self.video_decoder_name = mon.video_decoder_name.clone();
changed = true;
@@ -321,13 +331,18 @@ impl SteamFrameGpuiApp {
self.latest_controller = mon.latest_controller.clone();
// Récupération directe du tampon BGRA pré-converti par le worker (zéro swizzle UI)
let frame_data: Option<(u32, u32, Arc<Vec<u8>>)> = if self.active_tab == ActiveTab::Cockpit
let frame_data: Option<(u32, u32, Arc<Vec<u8>>, Option<Instant>)> = if self.active_tab == ActiveTab::Cockpit
&& mon.preview_frame_seq != self.last_frame_seq
&& !mon.preview_bgra.is_empty()
&& mon.preview_width > 0
&& mon.preview_height > 0
{
Some((mon.preview_width, mon.preview_height, Arc::clone(&mon.preview_bgra)))
Some((
mon.preview_width,
mon.preview_height,
Arc::clone(&mon.preview_bgra),
mon.preview_received_at,
))
} else {
None
};
@@ -346,7 +361,7 @@ impl SteamFrameGpuiApp {
}
// 2. Upload RenderImage GPU direct (pixels déjà en BGRA — plus de swizzle CPU sur thread UI)
if let Some((w, h, bgra_arc)) = new_frame_data {
if let Some((w, h, bgra_arc, recv_at_opt)) = new_frame_data {
let bgra_buf = match Arc::try_unwrap(bgra_arc) {
Ok(v) => v,
Err(shared) => (*shared).clone(),
@@ -360,6 +375,14 @@ impl SteamFrameGpuiApp {
}
self.current_render_image = Some(new_render_image);
self.last_frame_seq = preview_frame_seq;
if let Some(recv_at) = recv_at_opt {
let pc_ms = recv_at.elapsed().as_secs_f32() * 1000.0;
self.video_pc_latency_ms = if self.video_pc_latency_ms <= 0.01 {
pc_ms
} else {
self.video_pc_latency_ms * 0.8 + pc_ms * 0.2
};
}
changed = true;
while self.images_to_drop.len() > 2 {
@@ -393,6 +416,10 @@ impl SteamFrameGpuiApp {
}
}
if self.glass_to_glass_test && self.active_tab == ActiveTab::Cockpit {
changed = true;
}
changed
}
+5 -2
View File
@@ -149,8 +149,11 @@ impl SteamFrameGpuiApp {
"🎥 LIEN VIDÉO",
&format!("{:.1} FPS", self.video_fps),
&format!(
"Jitter {:.1} ms • Drop {} • {}",
self.video_jitter_ms, self.video_dropped_frames, self.video_decoder_name
"Jitter {:.1} ms • PC {:.1} ms (mot. {:.1} ms) • Drop {}",
self.video_jitter_ms,
self.video_pc_latency_ms,
self.video_engine_latency_ms,
self.video_dropped_frames
),
if self.video_fps > 1.0 { COLOR_CYAN } else { COLOR_TEXT_MUTED },
))