Show what a watched stream delivers: size, frame rate, bitrate

A viewer could see the codec and the picture's size of a watched stream,
but not how many pictures arrived or at what bitrate, so a choppy or
starved stream looked like any other.

DecodeStats now counts the video bytes received and gives the decoded
frame rate and the received bitrate since the previous `stats()` call (at
least half a second; the watch screen asks once a second, other readers
share the same window). The watch screen shows "VP8 · 1280×720 · 30 fps ·
0.4 Mbit/s" in small text in the player's control bar, where a spacer was,
and in Stream Info.

These are read from the decoding pipeline, which runs in the app, rather
than sent as an engine event as planned: the engine never sees the decoded
pictures, and the screen already refreshes from these stats every second.

Tested: the local test pattern decodes at 20-40 fps and 0.1-5 Mbit/s
(media::tests::local_preview_decodes_the_pattern); a headless screenshot
of the watch screen with the sample stream showed the line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 18:20:02 +03:00
1 parent 8d14b0d5be
commit 0bc96437e5
5 files changed
+65 -7

No files matched your search

+39 -1
View File
@@ -79,6 +79,8 @@ const OPUS_BITRATE: i32 = 128_000;
pub const MAX_QUEUED: usize = 30; pub const MAX_QUEUED: usize = 30;
/// Keyframe requests while waiting for one are at least this far apart. /// Keyframe requests while waiting for one are at least this far apart.
const KEYFRAME_RETRY: Duration = Duration::from_millis(500); const KEYFRAME_RETRY: Duration = Duration::from_millis(500);
/// The decoding rates of [`DecodeStats`] cover at least this long.
const RATE_WINDOW: Duration = Duration::from_millis(500);
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum MediaError { pub enum MediaError {
@@ -2401,6 +2403,23 @@ pub struct DecodeStats {
pub height: u32, pub height: u32,
/// The last error (no decoder for the codec, decoding failed). /// The last error (no decoder for the codec, decoding failed).
pub error: Option<String>, pub error: Option<String>,
/// Bytes of video received.
pub bytes: u64,
/// Pictures decoded per second and video received in bit/s, over the
/// time since the previous [`VideoPipeline::stats`] (at least
/// [`RATE_WINDOW`]; the watch screen asks once a second).
pub fps: u32,
pub bitrate: u64,
}
/// Where the rates of [`DecodeStats`] were last measured from.
#[derive(Default)]
struct DecodeRates {
since: Option<Instant>,
decoded: u64,
bytes: u64,
fps: u32,
bitrate: u64,
} }
#[derive(Default)] #[derive(Default)]
@@ -2416,6 +2435,7 @@ struct DecodeQueue {
state: Mutex<QueueState>, state: Mutex<QueueState>,
cond: Condvar, cond: Condvar,
stats: Mutex<DecodeStats>, stats: Mutex<DecodeStats>,
rates: Mutex<DecodeRates>,
} }
/// Feeds frames into a [`VideoPipeline`]; cheap to clone. /// Feeds frames into a [`VideoPipeline`]; cheap to clone.
@@ -2432,6 +2452,7 @@ impl FrameInput {
if frame.kind != MediaKind::Video { if frame.kind != MediaKind::Video {
return; return;
} }
lock(&self.queue.stats).bytes += frame.data.len() as u64;
let mut state = lock(&self.queue.state); let mut state = lock(&self.queue.state);
if state.frames.len() >= MAX_QUEUED { if state.frames.len() >= MAX_QUEUED {
state.frames.clear(); state.frames.clear();
@@ -2486,7 +2507,19 @@ impl VideoPipeline {
} }
pub fn stats(&self) -> DecodeStats { pub fn stats(&self) -> DecodeStats {
lock(&self.input.queue.stats).clone() let mut stats = lock(&self.input.queue.stats).clone();
let mut rates = lock(&self.input.queue.rates);
let now = Instant::now();
let elapsed = rates.since.map(|since| now.saturating_duration_since(since));
if elapsed.is_none_or(|e| e >= RATE_WINDOW) {
if let Some(seconds) = elapsed.map(|e| e.as_secs_f64()) {
rates.fps = ((stats.decoded - rates.decoded) as f64 / seconds).round() as u32;
rates.bitrate = ((stats.bytes - rates.bytes) as f64 * 8.0 / seconds) as u64;
}
(rates.since, rates.decoded, rates.bytes) = (Some(now), stats.decoded, stats.bytes);
}
(stats.fps, stats.bitrate) = (rates.fps, rates.bitrate);
stats
} }
} }
@@ -2981,6 +3014,11 @@ mod tests {
assert!(stats.decoded >= 10 && stats.error.is_none(), "{stats:?}"); assert!(stats.decoded >= 10 && stats.error.is_none(), "{stats:?}");
assert_eq!(stats.codec, Some(Codec::Vp8)); assert_eq!(stats.codec, Some(Codec::Vp8));
assert_eq!(preview.streamer().backend(), "synthetic"); assert_eq!(preview.streamer().backend(), "synthetic");
// Rates over the second since: the pattern's rate, its bitrate.
tokio::time::sleep(Duration::from_secs(1)).await;
let stats = preview.stats();
assert!((20..=40).contains(&stats.fps), "{stats:?}");
assert!((100_000..5_000_000).contains(&stats.bitrate), "{stats:?}");
} }
fn layer(id: LayerId, scale: f32, max_fps: Option<u32>, bitrate: u64) -> LayerSpec { fn layer(id: LayerId, scale: f32, max_fps: Option<u32>, bitrate: u64) -> LayerSpec {
+6 -1
View File
@@ -451,7 +451,8 @@ impl Decoder {
} }
} }
/// One line about the video: codec, size, problems. /// One line about the video: codec, size, decoded frame rate, received
/// bitrate, problems.
pub fn info(&self) -> String { pub fn info(&self) -> String {
let stats = self.stats(); let stats = self.stats();
let mut parts = Vec::new(); let mut parts = Vec::new();
@@ -461,6 +462,10 @@ impl Decoder {
if stats.width > 0 { if stats.width > 0 {
parts.push(size_text(stats.width, stats.height)); parts.push(size_text(stats.width, stats.height));
} }
if stats.decoded > 0 {
parts.push(format!("{} fps", stats.fps));
parts.push(format!("{:.1} Mbit/s", stats.bitrate as f64 / 1_000_000.0));
}
if let Some(e) = stats.error { if let Some(e) = stats.error {
parts.push(e); parts.push(e);
} }
+10 -1
View File
@@ -364,7 +364,16 @@ component StreamPlayer inherits Rectangle {
vertical-alignment: center; vertical-alignment: center;
} }
} }
Rectangle { horizontal-stretch: 1; } // What arrives: codec, size, frame rate, bitrate.
Text {
horizontal-stretch: 1;
text: Bridge.viewer-quality-detail;
color: #ffffff80;
font-size: Theme.font-xs;
horizontal-alignment: right;
vertical-alignment: center;
overflow: elide;
}
if !Bridge.viewer-fullscreen && !Nav.narrow: IconButton { if !Bridge.viewer-fullscreen && !Nav.narrow: IconButton {
icon: Icons.minimize-2; icon: Icons.minimize-2;
label: @tr("Back to the chat (keeps watching)"); label: @tr("Back to the chat (keeps watching)");
+8 -2
View File
@@ -185,7 +185,13 @@ viewer: Engine::subscribe_frames ─ VideoPipeline (thread) ─ VideoDecoder
longer than 30 frames) or a decoder error it skips to the next keyframe, longer than 30 frames) or a decoder error it skips to the next keyframe,
asking for one at most every 500 ms. Keyframes are recognised from the asking for one at most every 500 ms. Keyframes are recognised from the
bitstream (VP8 frame tag, VP9 header, H.264 IDR/SPS NAL units, AV1 bitstream (VP8 frame tag, VP9 header, H.264 IDR/SPS NAL units, AV1
sequence header OBU). sequence header OBU). `stats()` (`DecodeStats`) tells the codec, the
picture's size, pictures decoded and skipped, the video bytes received,
and the decoded frame rate and received bitrate since the previous call
(at least half a second); the watch screen shows codec, size, rate and
bitrate over the player and in Stream Info, refreshed once a second.
These are read from the pipeline, which runs in the app, not sent as
engine events: the engine never sees the decoded pictures.
- `Viewer` feeds a `VideoPipeline` from the engine and sends - `Viewer` feeds a `VideoPipeline` from the engine and sends
`RequestStreamKeyframe`; `LocalPreview` runs capture → encoder → decoder `RequestStreamKeyframe`; `LocalPreview` runs capture → encoder → decoder
without a server (the desktop app's `VOELIN_DEMO_STREAM`). without a server (the desktop app's `VOELIN_DEMO_STREAM`).
@@ -1029,7 +1035,7 @@ has not run on Windows yet.
| Viewer counts: `viewer` of `notifystreaminfo`, counted up and down from the viewers joining and leaving, refreshed one stream at a time | `voelin-stream` `proto::tests::stream_info_answers`, `session::tests::viewer_counts`; `voelinctl stream list` | tested; against the TeamSpeak 6 dev server `stream list` printed "1 watching" while a viewer watched and "0 watching" after | | Viewer counts: `viewer` of `notifystreaminfo`, counted up and down from the viewers joining and leaving, refreshed one stream at a time | `voelin-stream` `proto::tests::stream_info_answers`, `session::tests::viewer_counts`; `voelinctl stream list` | tested; against the TeamSpeak 6 dev server `stream list` printed "1 watching" while a viewer watched and "0 watching" after |
| A viewer picks a layer: the offer's `a=x-voelin-layers`, `Signal::Layer`, the streamer moving it (and back with "Auto"); no request to a streamer whose offer lists no layers | `voelin-stream` `layer::tests::layers_in_the_sdp`, `tests/sessions.rs` `viewer_picks_a_layer` and `no_layer_request_without_the_offer_listing_layers` (two sessions, peers on loopback); `voelinctl stream watch --layer 1` against `stream start --placeholder --layer 1.0:2000k --layer 0.5:500k` | tested, also through the TeamSpeak 6 dev server (the viewer stayed on layer 1 at a 2.5 Mbit/s estimate that fits layer 0) | | A viewer picks a layer: the offer's `a=x-voelin-layers`, `Signal::Layer`, the streamer moving it (and back with "Auto"); no request to a streamer whose offer lists no layers | `voelin-stream` `layer::tests::layers_in_the_sdp`, `tests/sessions.rs` `viewer_picks_a_layer` and `no_layer_request_without_the_offer_listing_layers` (two sessions, peers on loopback); `voelinctl stream watch --layer 1` against `stream start --placeholder --layer 1.0:2000k --layer 0.5:500k` | tested, also through the TeamSpeak 6 dev server (the viewer stayed on layer 1 at a 2.5 Mbit/s estimate that fits layer 0) |
| An offer with `a=x-voelin-layers` against libwebrtc | `tests/browser_interop.rs` `rust_streams_to_browser` (`VOELIN_INTEROP=1`, system Chromium 152 through `playwright-core`) | tested: answered and decoded as before. The official client itself not tried | | An offer with `a=x-voelin-layers` against libwebrtc | `tests/browser_interop.rs` `rust_streams_to_browser` (`VOELIN_INTEROP=1`, system Chromium 152 through `playwright-core`) | tested: answered and decoded as before. The official client itself not tried |
| Test pattern → VP8 → decoder, rectangle position and colour | `voelin-core` `media::tests::local_preview_decodes_the_pattern` | tested | | Test pattern → VP8 → decoder, rectangle position and colour; decoded frame rate and received bitrate | `voelin-core` `media::tests::local_preview_decodes_the_pattern`; the watch screen with the sample stream (`scripts/shots.sh ... watch`) | tested: the screenshot showed "VP8 · 1280×720 · 30 fps · 0.4 Mbit/s" over the player |
| Test pattern → two engine stream tasks → str0m peers on loopback → decoder | `voelin-core` `stream::tests::test_pattern_through_stream_tasks` | tested | | Test pattern → two engine stream tasks → str0m peers on loopback → decoder | `voelin-core` `stream::tests::test_pattern_through_stream_tasks` | tested |
| Stream audio (RTP time → jitter buffer ids, volume, end) | `voelin-core` `audio::tests::stream_audio_with_volume`, stream task test | tested | | Stream audio (RTP time → jitter buffer ids, volume, end) | `voelin-core` `audio::tests::stream_audio_with_volume`, stream task test | tested |
| Stream mixer (latency, fade on underrun, drift correction, rate conversion, limiter, levels, live source changes), `BlockClock` | `voelin-media` `mix::tests`, `tests/mix_alloc.rs` (no allocation per block) | tested | | Stream mixer (latency, fade on underrun, drift correction, rate conversion, limiter, levels, live source changes), `BlockClock` | `voelin-media` `mix::tests`, `tests/mix_alloc.rs` (no allocation per block) | tested |
+2 -2
View File
@@ -136,8 +136,8 @@ comes from the engine's events; what a gateway adds is hidden without it.
| Member card | `member` | Description, groups, talk power, country; private message, poke, friend, block; volume and mute for us | `ContactsChanged`; `Command::SetContact`, `SetClientVolume`, `SetClientMuted`, `Poke` | | Member card | `member` | Description, groups, talk power, country; private message, poke, friend, block; volume and mute for us | `ContactsChanged`; `Command::SetContact`, `SetClientVolume`, `SetClientMuted`, `Poke` |
| Pinned messages | `pins` | In the members panel's place: cards with author, time, text, files and reactions; the pin unpins, a click jumps to the message | `Gateway` `Pins`, `Pinned`, `Unpinned`; `GatewayRequest::Pins`, `Unpin` | | Pinned messages | `pins` | In the members panel's place: cards with author, time, text, files and reactions; the pin unpins, a click jumps to the message | `Gateway` `Pins`, `Pinned`, `Unpinned`; `GatewayRequest::Pins`, `Unpin` |
| Topics | `topics`, `topic:<id>` | In the members panel's place: search, cards with the message count, creator and last activity, Create Topic; an open topic replaces the chat's messages and takes replies | `Gateway` `Topics`, `Topic`, `TopicHistory`; `GatewayRequest::Topics`, `TopicHistory`, `CreateTopic`, `Post` | | Topics | `topics`, `topic:<id>` | In the members panel's place: search, cards with the message count, creator and last activity, Create Topic; an open topic replaces the chat's messages and takes replies | `Gateway` `Topics`, `Topic`, `TopicHistory`; `GatewayRequest::Topics`, `TopicHistory`, `CreateTopic`, `Post` |
| Voice channel | `voice` | Title, topic, "5 in voice / 50 total", Voice Settings, Leave; the people as large avatars (talking ring and bars, muted, crown, streaming); the streams as cards (LIVE, viewers, kind, bitrate, sound, Watch Stream); the channel's chat | `Presence`, `Talking`, `StreamsChanged`, `Gateway` stream directory (viewer counts) | | Voice channel | `voice` | Title, topic, "5 in voice / 50 total", Voice Settings, Leave; the people as large avatars (talking ring and bars, muted, crown, streaming); the streams as cards (LIVE, viewers, kind, bitrate, sound, Watch Stream); the channel's chat | `Presence`, `Talking`, `StreamsChanged`, viewer counts from `StreamsChanged`, else the `Gateway` stream directory |
| Watching a stream | `watch`, `popout` | The channel's header with "5 in voice" and Leave; the player with the streamer, title, viewers, LIVE, the picture's height (the simulcast picker when the streamer offers layers), volume, elapsed time, back to the chat, pop out, full screen; a note that the stream belongs to the channel; the channel's chat and a Stream Info tab. Popped out (and in full screen) it fills the window | `WatchState`, decoded frames (`src/video.rs`), `Gateway` stream directory | | Watching a stream | `watch`, `popout` | The channel's header with "5 in voice" and Leave; the player with the streamer, title, viewers, LIVE, the picture's height (the simulcast picker when a Voelin streamer offers layers), volume, elapsed time, what arrives (codec, size, frame rate, bitrate), back to the chat, pop out, full screen; a note that the stream belongs to the channel; the channel's chat and a Stream Info tab. Popped out (and in full screen) it fills the window | `WatchState`, `WatchLayers`, decoded frames and their stats (`src/video.rs`), `StreamsChanged` (viewer counts; the `Gateway` stream directory where the server gives none) |
The pins and topics share the place of the members panel: opening one The pins and topics share the place of the members panel: opening one
closes the other, and the members button brings the panel back. On the closes the other, and the members button brings the panel back. On the