Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion crates/tinyclient/src/gui/call/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,15 @@ pub(in crate::gui) struct ChartSample {
pub at: Instant,
pub rtt_ms: u32,
pub recv_kbps: u32,
pub video_kbps: Option<(u32, u32)>,
}

/// Append one poll to the chart, dropping the oldest past [`CHART_SECONDS`].
pub(in crate::gui) fn push_chart(samples: &mut VecDeque<ChartSample>, stats: &CallStats, at: Instant) {
if samples.len() >= CHART_SECONDS {
samples.pop_front();
}
samples.push_back(ChartSample { at, rtt_ms: stats.rtt_ms, recv_kbps: stats.receive_kbps });
samples.push_back(ChartSample { at, rtt_ms: stats.rtt_ms, recv_kbps: stats.receive_kbps, video_kbps: stats.video.as_ref().map(|video| (video.send_kbps, video.receive_kbps)) });
}

/// A full minute of made-up samples around `stats`, for `--shot` so the graph is not empty.
Expand All @@ -207,6 +208,7 @@ pub(in crate::gui) fn seed_chart(stats: &CallStats, now: Instant) -> VecDeque<Ch
at: now - Duration::from_secs((CHART_SECONDS - 1 - i) as u64),
rtt_ms: (base_rtt as i32 + rtt_wobble).max(1) as u32,
recv_kbps: (base_recv as i32 + recv_wobble * 2).max(1) as u32,
video_kbps: stats.video.as_ref().map(|video| (video.send_kbps, video.receive_kbps)),
}
})
.collect()
Expand Down Expand Up @@ -566,6 +568,20 @@ mod tests {
assert_eq!(seeded.back().map(|sample| sample.at), Some(start));
}

#[test]
fn video_history_keeps_its_own_rates_and_does_not_invent_them_while_inactive() {
let mut samples = VecDeque::new();
let mut stats = CallStats { rtt_ms: 40, receive_kbps: 900, ..Default::default() };
let now = Instant::now();
push_chart(&mut samples, &stats, now);
stats.video = Some(protocol::VideoStats { send_kbps: 440, receive_kbps: 800, ..Default::default() });
push_chart(&mut samples, &stats, now + Duration::from_secs(1));
stats.video = None;
push_chart(&mut samples, &stats, now + Duration::from_secs(2));
assert_eq!(samples.iter().map(|sample| sample.video_kbps).collect::<Vec<_>>(), [None, Some((440, 800)), None]);
assert!(samples.iter().all(|sample| sample.rtt_ms == 40 && sample.recv_kbps == 900));
}

#[test]
fn a_packet_lost_now_and_then_does_not_move_the_bars() {
// One packet of fifty is 20 per mille, and three in one bad second is 60: the old grade
Expand Down
8 changes: 8 additions & 0 deletions crates/tinyclient/src/gui/call/shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
//!
//! `tiny_sharing` is a call where I share my screen and mediad has painted the first picture of
//! it for my own tile (a made-up one, the demo's schematic); `--tiny-stream` focuses my stream.
//!
//! `TINYCLIENT_SHOT_VIDEO=1` adds sample video metrics; `--tiny-menu stats-video` selects
//! the compact health card's Video tab. These are design previews, not measured call proof.

use super::phone::{Sheet, Shown};
use super::security::Place;
Expand Down Expand Up @@ -65,6 +68,11 @@ pub(super) fn stats() -> Option<protocol::CallStats> {
let name = asked().filter(|name| name.starts_with("tiny_"))?;
let poor = name == "tiny_poor";
Some(protocol::CallStats {
video: std::env::var_os("TINYCLIENT_SHOT_VIDEO").map(|_| protocol::VideoStats {
send_kbps: 440, receive_kbps: 2100, send_fps: 30, receive_fps: 60, rendered_fps: 58,
receive_expected: true, watching_ms: 30_000, width: 1920, height: 1080, frame_age_ms: Some(16),
}),
link_measured: true,
rtt_ms: if poor { 184 } else { 38 },
jitter_ms: if poor { 41 } else { 4 },
loss_permille: if poor { 62 } else { 2 },
Expand Down
22 changes: 22 additions & 0 deletions crates/tinyclient/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ pub(crate) fn prove_health_grade() -> Result<(), &'static str> {
}
}

/// The lab's compact-call-health driver. The Video tab's history holds video's own rates, and
/// holds nothing for the seconds no video ran.
pub(crate) fn prove_compact_call_health() -> Result<(), &'static str> {
let mut samples = std::collections::VecDeque::new();
let mut stats = protocol::CallStats { rtt_ms: 40, receive_kbps: 900, ..Default::default() };
let now = std::time::Instant::now();
call::health::push_chart(&mut samples, &stats, now);
stats.video = Some(protocol::VideoStats { send_kbps: 440, receive_kbps: 800, ..Default::default() });
call::health::push_chart(&mut samples, &stats, now + std::time::Duration::from_secs(1));
stats.video = None;
call::health::push_chart(&mut samples, &stats, now + std::time::Duration::from_secs(2));
let video: Vec<_> = samples.iter().map(|sample| sample.video_kbps).collect();
if video != [None, Some((440, 800)), None] {
return Err("the Video tab's history did not keep video's own rates");
}
if samples.iter().all(|sample| sample.rtt_ms == 40 && sample.recv_kbps == 900) {
Ok(())
} else {
Err("video samples changed the Connection tab's history")
}
}

/// The lab's cancel-join driver. A leave is accepted while a join is still in flight.
pub(crate) fn prove_cancel_join() -> Result<(), &'static str> {
if tiny::call_accepts(true, true) && !tiny::call_accepts(true, false) {
Expand Down
2 changes: 1 addition & 1 deletion crates/tinyclient/src/gui/tiny/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Shell {
}
Float::Stats => {
let at = anchor(RAIL_WIDTH + 8., tall - PANEL, sidebar - 16., PANEL);
let card = popover().p(px(14.)).child(self.tiny_stats_card());
let card = popover().p(px(14.)).child(self.tiny_stats_card(cx));
out.push(placed("tiny-stats", Place::Above(at), Layer::Popover, window, fade_in("tiny-stats-fade", 120, card)));
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/tinyclient/src/gui/tiny/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ pub struct State {
stats_before: Option<CallStats>,
/// The last minute of ping and receive bitrate for Call health's time graph.
stats_chart: VecDeque<health::ChartSample>,
stats_tab: panel::StatsTab,
/// The polls over the last several seconds: what the bars and the numbers show.
steady: health::Steady,
/// Why there are no numbers, when mediad said.
Expand Down Expand Up @@ -336,6 +337,7 @@ impl State {
stats: None,
stats_before: None,
stats_chart: VecDeque::new(),
stats_tab: panel::StatsTab::default(),
steady: health::Steady::default(),
stats_note: None,
stats_task: None,
Expand Down Expand Up @@ -1573,6 +1575,10 @@ impl Shell {
}
}
match flag("--tiny-menu").as_deref() {
Some("stats-video") => {
self.tiny_state.stats_tab = panel::StatsTab::Video;
self.tiny_open_float(Float::Stats, cx);
}
Some("header") => self.tiny_open_float(Float::Header, cx),
Some("stats") => self.tiny_open_float(Float::Stats, cx),
Some("channel") => {
Expand Down
Loading
Loading