Share frames are pulled on display frame callbacks (timer only as stall fallback), 8 ms present lookahead, no 30 fps inactive throttle
Browse files at this commit9668bbd3be3dd928df25cc520fdb108a1e442803Parent: 5cfdcf4- feat
- share frames are pulled on display frame callbacks (timer only as stall fallback), 8 ms present lookahead, no 30 fps inactive throttle
- metrics log presented fps, dropped, interval and sender gap p50/p95, delay swing
6 changed files +119 -36
- crates/client/src/gui.rs +6 -1
- crates/client/src/gui/camera_view.rs +42 -13
- crates/client/src/gui/chat.rs +14 -1
- crates/client/src/gui/share_view.rs +2 -16
- crates/client/src/main.rs +1 -0
- crates/client/src/share/session.rs +54 -5
crates/client/src/gui.rsmodified+6 -1
| @@ -4,7 +4,7 @@ use std::{ | |||
| 4 | fmt::Display, | 4 | fmt::Display, |
| 5 | hash::{DefaultHasher, Hash, Hasher}, | 5 | hash::{DefaultHasher, Hash, Hasher}, |
| 6 | sync::Arc, | 6 | sync::Arc, |
| 7 | - time::Duration, | 7 | + time::{Duration, Instant}, |
| 8 | }; | 8 | }; |
| 9 | 9 | ||
| 10 | use common::{ | 10 | use common::{ |
| @@ -633,6 +633,8 @@ pub struct Yumush { | |||
| 633 | share_tab: common::share::Kind, | 633 | share_tab: common::share::Kind, |
| 634 | camera_modes: Vec<common::share::Mode>, | 634 | camera_modes: Vec<common::share::Mode>, |
| 635 | fullscreen: bool, | 635 | fullscreen: bool, |
| 636 | + pumping: bool, | ||
| 637 | + pumped: Instant, | ||
| 636 | send_order: Arc<tokio::sync::Mutex<()>>, | 638 | send_order: Arc<tokio::sync::Mutex<()>>, |
| 637 | } | 639 | } |
| 638 | 640 | ||
| @@ -695,6 +697,8 @@ impl Yumush { | |||
| 695 | share_tab: common::share::Kind::Screen, | 697 | share_tab: common::share::Kind::Screen, |
| 696 | camera_modes: Vec::new(), | 698 | camera_modes: Vec::new(), |
| 697 | fullscreen: false, | 699 | fullscreen: false, |
| 700 | + pumping: false, | ||
| 701 | + pumped: Instant::now(), | ||
| 698 | send_order: Default::default(), | 702 | send_order: Default::default(), |
| 699 | }; | 703 | }; |
| 700 | yumush.chat.camera_task = Some(camera_view::ticker(cx)); | 704 | yumush.chat.camera_task = Some(camera_view::ticker(cx)); |
| @@ -1393,6 +1397,7 @@ impl Render for Yumush { | |||
| 1393 | self.fullscreen = fullscreen; | 1397 | self.fullscreen = fullscreen; |
| 1394 | window.toggle_fullscreen(); | 1398 | window.toggle_fullscreen(); |
| 1395 | } | 1399 | } |
| 1400 | + self.schedule_pump(window, cx); | ||
| 1396 | let palette = palette(cx); | 1401 | let palette = palette(cx); |
| 1397 | sync_accent(self.themed(cx).accent, cx); | 1402 | sync_accent(self.themed(cx).accent, cx); |
| 1398 | let route = self.current_route; | 1403 | let route = self.current_route; |
crates/client/src/gui/camera_view.rsmodified+42 -13
| @@ -1,4 +1,4 @@ | |||
| 1 | -use std::time::Duration; | 1 | +use std::time::{Duration, Instant}; |
| 2 | 2 | ||
| 3 | use common::model::Id; | 3 | use common::model::Id; |
| 4 | 4 | ||
| @@ -10,18 +10,14 @@ use gpui_kit::{ | |||
| 10 | }; | 10 | }; |
| 11 | 11 | ||
| 12 | use super::{ | 12 | use super::{ |
| 13 | - Palette, Tooltip as _, Yumush, avatar, clickable, | 13 | + Palette, Tooltip as _, Yumush, avatar, clickable, media_view::into_render_image, notify_error, |
| 14 | - media_view::into_render_image, | 14 | + share_view, surface::Surface, text, wave::mini_wave, widget::spawn_warn, |
| 15 | - notify_error, | ||
| 16 | - share_view::{self, FRAME_TICK}, | ||
| 17 | - surface::Surface, | ||
| 18 | - text, | ||
| 19 | - wave::mini_wave, | ||
| 20 | - widget::spawn_warn, | ||
| 21 | }; | 15 | }; |
| 22 | use crate::share::session::WatchQuality; | 16 | use crate::share::session::WatchQuality; |
| 23 | 17 | ||
| 24 | const IDLE_TICK: Duration = Duration::from_millis(250); | 18 | const IDLE_TICK: Duration = Duration::from_millis(250); |
| 19 | +const FRAME_TICK: Duration = Duration::from_millis(16); | ||
| 20 | +const PUMP_STALL: Duration = Duration::from_millis(50); | ||
| 25 | 21 | ||
| 26 | pub(super) const TILE_QUALITY: WatchQuality = WatchQuality::Fixed(Quality { | 22 | pub(super) const TILE_QUALITY: WatchQuality = WatchQuality::Fixed(Quality { |
| 27 | resolution: Resolution::P360, | 23 | resolution: Resolution::P360, |
| @@ -296,18 +292,51 @@ impl Yumush { | |||
| 296 | 292 | ||
| 297 | pub(super) fn ticker(cx: &mut Context<Yumush>) -> Task<()> { | 293 | pub(super) fn ticker(cx: &mut Context<Yumush>) -> Task<()> { |
| 298 | cx.spawn(async move |this, cx| { | 294 | cx.spawn(async move |this, cx| { |
| 299 | - let mut busy = false; | 295 | + let mut tick = IDLE_TICK; |
| 300 | loop { | 296 | loop { |
| 301 | - let tick = if busy { FRAME_TICK } else { IDLE_TICK }; | ||
| 302 | cx.background_executor().timer(tick).await; | 297 | cx.background_executor().timer(tick).await; |
| 303 | - match this.update(cx, |yumush, cx| yumush.tick_tiles(cx)) { | 298 | + match this.update(cx, |yumush, cx| yumush.idle_tick(cx)) { |
| 304 | - Ok(next) => busy = next, | 299 | + Ok(true) => tick = FRAME_TICK, |
| 300 | + Ok(false) => tick = IDLE_TICK, | ||
| 305 | Err(_) => break, | 301 | Err(_) => break, |
| 306 | } | 302 | } |
| 307 | } | 303 | } |
| 308 | }) | 304 | }) |
| 309 | } | 305 | } |
| 310 | 306 | ||
| 307 | +impl Yumush { | ||
| 308 | + fn streaming(&self) -> bool { | ||
| 309 | + self.chat.viewer.is_some() || !self.chat.tiles.is_empty() | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + fn pump(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 313 | + self.pumping = false; | ||
| 314 | + self.pumped = Instant::now(); | ||
| 315 | + self.tick_viewer(cx); | ||
| 316 | + self.tick_tiles(cx); | ||
| 317 | + self.schedule_pump(window, cx); | ||
| 318 | + } | ||
| 319 | + | ||
| 320 | + fn idle_tick(&mut self, cx: &mut Context<Self>) -> bool { | ||
| 321 | + if self.pumped.elapsed() > PUMP_STALL { | ||
| 322 | + self.tick_viewer(cx); | ||
| 323 | + self.tick_tiles(cx); | ||
| 324 | + } | ||
| 325 | + self.streaming() | ||
| 326 | + } | ||
| 327 | + | ||
| 328 | + pub(super) fn schedule_pump(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 329 | + if self.pumping || !self.streaming() { | ||
| 330 | + return; | ||
| 331 | + } | ||
| 332 | + self.pumping = true; | ||
| 333 | + let this = cx.entity().downgrade(); | ||
| 334 | + window.on_next_frame(move |window, cx| { | ||
| 335 | + let _ = this.update(cx, |yumush, cx| yumush.pump(window, cx)); | ||
| 336 | + }); | ||
| 337 | + } | ||
| 338 | +} | ||
| 339 | + | ||
| 311 | fn stage_tile( | 340 | fn stage_tile( |
| 312 | entity: &Entity<Yumush>, | 341 | entity: &Entity<Yumush>, |
| 313 | yumush: &Yumush, | 342 | yumush: &Yumush, |
crates/client/src/gui/chat.rsmodified+14 -1
| @@ -1176,7 +1176,15 @@ impl Chat { | |||
| 1176 | 1176 | ||
| 1177 | pub fn record_share(&mut self, sample: ShareSample) { | 1177 | pub fn record_share(&mut self, sample: ShareSample) { |
| 1178 | for (kind, stat) in &sample.sending { | 1178 | for (kind, stat) in &sample.sending { |
| 1179 | - tracing::debug!(target: "metrics", ?kind, kbps = stat.kbps, fps = stat.fps, "send"); | 1179 | + tracing::debug!( |
| 1180 | + target: "metrics", | ||
| 1181 | + ?kind, | ||
| 1182 | + kbps = stat.kbps, | ||
| 1183 | + fps = stat.fps, | ||
| 1184 | + gap50 = stat.gap_ms.0, | ||
| 1185 | + gap95 = stat.gap_ms.1, | ||
| 1186 | + "send" | ||
| 1187 | + ); | ||
| 1180 | } | 1188 | } |
| 1181 | for (_, kind, stat) in &sample.watching { | 1189 | for (_, kind, stat) in &sample.watching { |
| 1182 | tracing::debug!( | 1190 | tracing::debug!( |
| @@ -1189,6 +1197,11 @@ impl Chat { | |||
| 1189 | latency = stat.latency_ms, | 1197 | latency = stat.latency_ms, |
| 1190 | buffer = stat.buffer_ms, | 1198 | buffer = stat.buffer_ms, |
| 1191 | nacks = stat.nacks, | 1199 | nacks = stat.nacks, |
| 1200 | + shown = stat.shown_fps, | ||
| 1201 | + dropped = stat.dropped, | ||
| 1202 | + interval50 = stat.interval_ms.0, | ||
| 1203 | + interval95 = stat.interval_ms.1, | ||
| 1204 | + swing = stat.swing_ms, | ||
| 1192 | "watch" | 1205 | "watch" |
| 1193 | ); | 1206 | ); |
| 1194 | } | 1207 | } |
crates/client/src/gui/share_view.rsmodified+2 -16
| @@ -14,7 +14,7 @@ const TOP_QUALITY: Quality = Quality { | |||
| 14 | }; | 14 | }; |
| 15 | use gpui_kit::{ | 15 | use gpui_kit::{ |
| 16 | Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, | 16 | Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, |
| 17 | - MouseButton, ParentElement, StatefulInteractiveElement, Styled, Subscription, Task, Window, | 17 | + MouseButton, ParentElement, StatefulInteractiveElement, Styled, Subscription, Window, |
| 18 | assets::IconName, | 18 | assets::IconName, |
| 19 | component::{ | 19 | component::{ |
| 20 | Icon, | 20 | Icon, |
| @@ -50,7 +50,6 @@ use crate::{ | |||
| 50 | 50 | ||
| 51 | const BAR_TTL: Duration = Duration::from_millis(2500); | 51 | const BAR_TTL: Duration = Duration::from_millis(2500); |
| 52 | 52 | ||
| 53 | -pub(super) const FRAME_TICK: Duration = Duration::from_millis(16); | ||
| 54 | const RESOLUTIONS: [(Resolution, &str); 6] = [ | 53 | const RESOLUTIONS: [(Resolution, &str); 6] = [ |
| 55 | (Resolution::P360, "360"), | 54 | (Resolution::P360, "360"), |
| 56 | (Resolution::P480, "480"), | 55 | (Resolution::P480, "480"), |
| @@ -102,7 +101,6 @@ pub(super) struct Viewer { | |||
| 102 | active: Instant, | 101 | active: Instant, |
| 103 | stats: bool, | 102 | stats: bool, |
| 104 | _subscriptions: Vec<Subscription>, | 103 | _subscriptions: Vec<Subscription>, |
| 105 | - _tick: Task<()>, | ||
| 106 | } | 104 | } |
| 107 | 105 | ||
| 108 | impl Yumush { | 106 | impl Yumush { |
| @@ -297,17 +295,6 @@ impl Yumush { | |||
| 297 | this.update_share(cx, |settings| settings.volume = volume); | 295 | this.update_share(cx, |settings| settings.volume = volume); |
| 298 | } | 296 | } |
| 299 | })]; | 297 | })]; |
| 300 | - let tick = cx.spawn(async move |this, cx| { | ||
| 301 | - loop { | ||
| 302 | - cx.background_executor().timer(FRAME_TICK).await; | ||
| 303 | - if this | ||
| 304 | - .update(cx, |yumush, cx| yumush.tick_viewer(cx)) | ||
| 305 | - .is_err() | ||
| 306 | - { | ||
| 307 | - break; | ||
| 308 | - } | ||
| 309 | - } | ||
| 310 | - }); | ||
| 311 | 298 | ||
| 312 | self.chat.viewer = Some(Viewer { | 299 | self.chat.viewer = Some(Viewer { |
| 313 | user_id, | 300 | user_id, |
| @@ -320,7 +307,6 @@ impl Yumush { | |||
| 320 | active: Instant::now(), | 307 | active: Instant::now(), |
| 321 | stats: false, | 308 | stats: false, |
| 322 | _subscriptions: subscriptions, | 309 | _subscriptions: subscriptions, |
| 323 | - _tick: tick, | ||
| 324 | }); | 310 | }); |
| 325 | 311 | ||
| 326 | let network = self.network.clone(); | 312 | let network = self.network.clone(); |
| @@ -377,7 +363,7 @@ impl Yumush { | |||
| 377 | cx.notify(); | 363 | cx.notify(); |
| 378 | } | 364 | } |
| 379 | 365 | ||
| 380 | - fn tick_viewer(&mut self, cx: &mut Context<Self>) { | 366 | + pub(super) fn tick_viewer(&mut self, cx: &mut Context<Self>) { |
| 381 | let Some(viewer) = self.chat.viewer.as_mut() else { | 367 | let Some(viewer) = self.chat.viewer.as_mut() else { |
| 382 | return; | 368 | return; |
| 383 | }; | 369 | }; |
crates/client/src/main.rsmodified+1 -0
| @@ -104,6 +104,7 @@ fn open_window( | |||
| 104 | WindowOptions { | 104 | WindowOptions { |
| 105 | window_bounds: Some(WindowBounds::Windowed(window_bounds)), | 105 | window_bounds: Some(WindowBounds::Windowed(window_bounds)), |
| 106 | titlebar: Some(titlebar), | 106 | titlebar: Some(titlebar), |
| 107 | + inactive_frame_interval: None, | ||
| 107 | ..Default::default() | 108 | ..Default::default() |
| 108 | }, | 109 | }, |
| 109 | |window, cx| { | 110 | |window, cx| { |
crates/client/src/share/session.rsmodified+54 -5
| @@ -62,6 +62,7 @@ const MAX_DELAY_MS: i64 = 200; | |||
| 62 | const RESYNC_MS: i64 = 2000; | 62 | const RESYNC_MS: i64 = 2000; |
| 63 | const DELAY_MARGIN_MS: i64 = 8; | 63 | const DELAY_MARGIN_MS: i64 = 8; |
| 64 | const DELAY_WINDOW_MS: i64 = 1000; | 64 | const DELAY_WINDOW_MS: i64 = 1000; |
| 65 | +const PRESENT_AHEAD_MS: i64 = 8; | ||
| 65 | const DELAY_DECAY: i64 = 16; | 66 | const DELAY_DECAY: i64 = 16; |
| 66 | const LATENESS_WINDOW: usize = 120; | 67 | const LATENESS_WINDOW: usize = 120; |
| 67 | const LATE_MS: i64 = 200; | 68 | const LATE_MS: i64 = 200; |
| @@ -97,6 +98,7 @@ pub struct LayerStats { | |||
| 97 | pub engine: Engine, | 98 | pub engine: Engine, |
| 98 | pub kbps: u32, | 99 | pub kbps: u32, |
| 99 | pub fps: f32, | 100 | pub fps: f32, |
| 101 | + pub gap_ms: (i64, i64), | ||
| 100 | } | 102 | } |
| 101 | 103 | ||
| 102 | #[derive(Default)] | 104 | #[derive(Default)] |
| @@ -110,6 +112,10 @@ pub struct WatchStats { | |||
| 110 | pub buffer_ms: i64, | 112 | pub buffer_ms: i64, |
| 111 | pub latency_ms: Option<i64>, | 113 | pub latency_ms: Option<i64>, |
| 112 | pub nacks: u32, | 114 | pub nacks: u32, |
| 115 | + pub shown_fps: f32, | ||
| 116 | + pub dropped: u32, | ||
| 117 | + pub interval_ms: (i64, i64), | ||
| 118 | + pub swing_ms: i64, | ||
| 113 | } | 119 | } |
| 114 | 120 | ||
| 115 | #[derive(Default)] | 121 | #[derive(Default)] |
| @@ -122,6 +128,8 @@ struct Tally { | |||
| 122 | engine: Engine, | 128 | engine: Engine, |
| 123 | bytes: u64, | 129 | bytes: u64, |
| 124 | frames: u32, | 130 | frames: u32, |
| 131 | + last_ms: Option<u32>, | ||
| 132 | + gaps: Vec<i64>, | ||
| 125 | } | 133 | } |
| 126 | 134 | ||
| 127 | struct Sent { | 135 | struct Sent { |
| @@ -135,9 +143,16 @@ impl Sent { | |||
| 135 | engine: encoded.engine, | 143 | engine: encoded.engine, |
| 136 | bytes: 0, | 144 | bytes: 0, |
| 137 | frames: 0, | 145 | frames: 0, |
| 146 | + last_ms: None, | ||
| 147 | + gaps: Vec::new(), | ||
| 138 | }); | 148 | }); |
| 139 | tally.bytes += encoded.data.len() as u64; | 149 | tally.bytes += encoded.data.len() as u64; |
| 140 | tally.frames += 1; | 150 | tally.frames += 1; |
| 151 | + if let Some(last) = tally.last_ms.replace(encoded.timestamp_ms) { | ||
| 152 | + tally | ||
| 153 | + .gaps | ||
| 154 | + .push(i64::from(encoded.timestamp_ms) - i64::from(last)); | ||
| 155 | + } | ||
| 141 | } | 156 | } |
| 142 | 157 | ||
| 143 | fn take(&mut self) -> Vec<LayerStats> { | 158 | fn take(&mut self) -> Vec<LayerStats> { |
| @@ -147,11 +162,12 @@ impl Sent { | |||
| 147 | .max(f32::EPSILON); | 162 | .max(f32::EPSILON); |
| 148 | let mut stats: Vec<LayerStats> = std::mem::take(&mut self.tallies) | 163 | let mut stats: Vec<LayerStats> = std::mem::take(&mut self.tallies) |
| 149 | .into_iter() | 164 | .into_iter() |
| 150 | - .map(|(layer, tally)| LayerStats { | 165 | + .map(|(layer, mut tally)| LayerStats { |
| 151 | layer, | 166 | layer, |
| 152 | engine: tally.engine, | 167 | engine: tally.engine, |
| 153 | kbps: (tally.bytes as f32 * 8. / 1000. / seconds) as u32, | 168 | kbps: (tally.bytes as f32 * 8. / 1000. / seconds) as u32, |
| 154 | fps: tally.frames as f32 / seconds, | 169 | fps: tally.frames as f32 / seconds, |
| 170 | + gap_ms: spread(&mut tally.gaps), | ||
| 155 | }) | 171 | }) |
| 156 | .collect(); | 172 | .collect(); |
| 157 | stats.sort_by_key(|stat| stat.layer.to_byte()); | 173 | stats.sort_by_key(|stat| stat.layer.to_byte()); |
| @@ -159,6 +175,12 @@ impl Sent { | |||
| 159 | } | 175 | } |
| 160 | } | 176 | } |
| 161 | 177 | ||
| 178 | +fn spread(values: &mut [i64]) -> (i64, i64) { | ||
| 179 | + values.sort_unstable(); | ||
| 180 | + let at = |part: usize| values.get(values.len() * part / 100).copied().unwrap_or(0); | ||
| 181 | + (at(50), at(95)) | ||
| 182 | +} | ||
| 183 | + | ||
| 162 | fn next<T>(rx: &Receiver<T>, stop: &AtomicBool) -> Option<T> { | 184 | fn next<T>(rx: &Receiver<T>, stop: &AtomicBool) -> Option<T> { |
| 163 | while !stop.load(Ordering::Relaxed) { | 185 | while !stop.load(Ordering::Relaxed) { |
| 164 | match rx.recv_timeout(STOP_CHECK) { | 186 | match rx.recv_timeout(STOP_CHECK) { |
| @@ -541,6 +563,7 @@ struct Clock { | |||
| 541 | started: Instant, | 563 | started: Instant, |
| 542 | offset: AtomicI64, | 564 | offset: AtomicI64, |
| 543 | delay: AtomicI64, | 565 | delay: AtomicI64, |
| 566 | + swing: AtomicI64, | ||
| 544 | } | 567 | } |
| 545 | 568 | ||
| 546 | impl Clock { | 569 | impl Clock { |
| @@ -593,9 +616,11 @@ impl Playout { | |||
| 593 | } else { | 616 | } else { |
| 594 | current - ((current - target) / DELAY_DECAY).max(1) | 617 | current - ((current - target) / DELAY_DECAY).max(1) |
| 595 | }; | 618 | }; |
| 619 | + let next = next.clamp(MIN_DELAY_MS, MAX_DELAY_MS); | ||
| 620 | + clock.delay.store(next, Ordering::Relaxed); | ||
| 596 | clock | 621 | clock |
| 597 | - .delay | 622 | + .swing |
| 598 | - .store(next.clamp(MIN_DELAY_MS, MAX_DELAY_MS), Ordering::Relaxed); | 623 | + .fetch_max((next - current).abs(), Ordering::Relaxed); |
| 599 | } | 624 | } |
| 600 | 625 | ||
| 601 | fn queuing(&self) -> i64 { | 626 | fn queuing(&self) -> i64 { |
| @@ -623,6 +648,10 @@ struct Video { | |||
| 623 | queue: VecDeque<(i64, i64, media::Frame)>, | 648 | queue: VecDeque<(i64, i64, media::Frame)>, |
| 624 | generation: u64, | 649 | generation: u64, |
| 625 | decoded: u32, | 650 | decoded: u32, |
| 651 | + presented: u32, | ||
| 652 | + dropped: u32, | ||
| 653 | + last_shown: Option<i64>, | ||
| 654 | + intervals: Vec<i64>, | ||
| 626 | engine: Option<Engine>, | 655 | engine: Option<Engine>, |
| 627 | latency_total: i64, | 656 | latency_total: i64, |
| 628 | latency_count: i64, | 657 | latency_count: i64, |
| @@ -689,6 +718,7 @@ impl Watching { | |||
| 689 | started: Instant::now(), | 718 | started: Instant::now(), |
| 690 | offset: AtomicI64::new(i64::MAX), | 719 | offset: AtomicI64::new(i64::MAX), |
| 691 | delay: AtomicI64::new(INITIAL_DELAY_MS), | 720 | delay: AtomicI64::new(INITIAL_DELAY_MS), |
| 721 | + swing: AtomicI64::new(0), | ||
| 692 | }); | 722 | }); |
| 693 | let video = Arc::new(Mutex::new(Video::default())); | 723 | let video = Arc::new(Mutex::new(Video::default())); |
| 694 | let health = Arc::new(Mutex::new(Health::default())); | 724 | let health = Arc::new(Mutex::new(Health::default())); |
| @@ -782,7 +812,7 @@ impl Watching { | |||
| 782 | .as_secs_f32() | 812 | .as_secs_f32() |
| 783 | .max(f32::EPSILON); | 813 | .max(f32::EPSILON); |
| 784 | let bytes = self.received.swap(0, Ordering::Relaxed); | 814 | let bytes = self.received.swap(0, Ordering::Relaxed); |
| 785 | - let (decoded, engine, buffer_ms, latency_ms) = { | 815 | + let (decoded, engine, buffer_ms, latency_ms, presented, dropped, interval_ms) = { |
| 786 | let mut video = lock(&self.video); | 816 | let mut video = lock(&self.video); |
| 787 | let buffer_ms = match (video.queue.front(), video.queue.back()) { | 817 | let buffer_ms = match (video.queue.front(), video.queue.back()) { |
| 788 | (Some((first, ..)), Some((last, ..))) => last - first, | 818 | (Some((first, ..)), Some((last, ..))) => last - first, |
| @@ -792,11 +822,16 @@ impl Watching { | |||
| 792 | (video.latency_count > 0).then(|| video.latency_total / video.latency_count); | 822 | (video.latency_count > 0).then(|| video.latency_total / video.latency_count); |
| 793 | video.latency_total = 0; | 823 | video.latency_total = 0; |
| 794 | video.latency_count = 0; | 824 | video.latency_count = 0; |
| 825 | + let interval_ms = spread(&mut video.intervals); | ||
| 826 | + video.intervals.clear(); | ||
| 795 | ( | 827 | ( |
| 796 | std::mem::take(&mut video.decoded), | 828 | std::mem::take(&mut video.decoded), |
| 797 | video.engine, | 829 | video.engine, |
| 798 | buffer_ms, | 830 | buffer_ms, |
| 799 | latency_ms, | 831 | latency_ms, |
| 832 | + std::mem::take(&mut video.presented), | ||
| 833 | + std::mem::take(&mut video.dropped), | ||
| 834 | + interval_ms, | ||
| 800 | ) | 835 | ) |
| 801 | }; | 836 | }; |
| 802 | let health = lock(&self.health); | 837 | let health = lock(&self.health); |
| @@ -810,6 +845,10 @@ impl Watching { | |||
| 810 | buffer_ms, | 845 | buffer_ms, |
| 811 | latency_ms, | 846 | latency_ms, |
| 812 | nacks: health.nacks, | 847 | nacks: health.nacks, |
| 848 | + shown_fps: presented as f32 / seconds, | ||
| 849 | + dropped, | ||
| 850 | + interval_ms, | ||
| 851 | + swing_ms: self.clock.swing.swap(0, Ordering::Relaxed), | ||
| 813 | } | 852 | } |
| 814 | } | 853 | } |
| 815 | 854 | ||
| @@ -817,10 +856,19 @@ impl Watching { | |||
| 817 | let now = self.clock.now(); | 856 | let now = self.clock.now(); |
| 818 | let mut video = lock(&self.video); | 857 | let mut video = lock(&self.video); |
| 819 | let mut due = None; | 858 | let mut due = None; |
| 820 | - while video.queue.front().is_some_and(|(at, ..)| *at <= now) { | 859 | + while video |
| 860 | + .queue | ||
| 861 | + .front() | ||
| 862 | + .is_some_and(|(at, ..)| *at <= now + PRESENT_AHEAD_MS) | ||
| 863 | + { | ||
| 864 | + video.dropped += u32::from(due.is_some()); | ||
| 821 | due = video.queue.pop_front(); | 865 | due = video.queue.pop_front(); |
| 822 | } | 866 | } |
| 823 | let (_, origin, mut frame) = due?; | 867 | let (_, origin, mut frame) = due?; |
| 868 | + video.presented += 1; | ||
| 869 | + if let Some(last) = video.last_shown.replace(now) { | ||
| 870 | + video.intervals.push(now - last); | ||
| 871 | + } | ||
| 824 | video.latency_total += now - origin; | 872 | video.latency_total += now - origin; |
| 825 | video.latency_count += 1; | 873 | video.latency_count += 1; |
| 826 | video.generation += 1; | 874 | video.generation += 1; |
| @@ -1167,6 +1215,7 @@ mod tests { | |||
| 1167 | started: Instant::now(), | 1215 | started: Instant::now(), |
| 1168 | offset: AtomicI64::new(i64::MAX), | 1216 | offset: AtomicI64::new(i64::MAX), |
| 1169 | delay: AtomicI64::new(INITIAL_DELAY_MS), | 1217 | delay: AtomicI64::new(INITIAL_DELAY_MS), |
| 1218 | + swing: AtomicI64::new(0), | ||
| 1170 | }; | 1219 | }; |
| 1171 | clock.observe(116_000); | 1220 | clock.observe(116_000); |
| 1172 | assert!((clock.now() - clock.origin(116_000)).abs() < 50); | 1221 | assert!((clock.now() - clock.origin(116_000)).abs() < 50); |