voelinctl: stream statistics, the desktop pattern and no BWE for measuring

For measuring streams end to end: `stream start --stats` prints once a
second what the encoder makes per layer (size, fps, kbit/s, target,
encode time), `stream watch --stats` what arrives and decodes (decoded
fps, received bitrate, size, decoder, frames decoded and skipped,
keyframe requests), `stream start --pattern desktop` streams the
code-editor test pattern (about as costly as real screen content), and
`stream --no-bwe` turns bandwidth estimation off, to see what the path
carries unpaced. `Action::Stream` is boxed (the arguments grew past
clippy's limit) and `watch` takes its options in one struct.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-04 10:03:35 +03:00
1 parent 2a8ce05f59
commit 6cf1eab96f
2 files changed
+101 -11

No files matched your search

+1 -1
View File
@@ -190,7 +190,7 @@ pub enum Action {
command: VoiceCommand,
},
/// TeamSpeak 6 streams (screen sharing): start, list or watch.
Stream(stream::StreamArgs),
Stream(Box<stream::StreamArgs>),
/// Interactive session. Type `/help` for commands.
Repl,
}
+100 -10
View File
@@ -16,7 +16,7 @@ use tsclientlib::{ClientId, Connection, MessageHandle, StreamItem};
use voelin_core::media::voelin_media::capture::SourceId;
use voelin_core::media::voelin_media::{Codec, Codecs, VideoFrame, convert};
use voelin_core::media::{
CaptureBackend, EncodedSource, EncoderPreference, Latest, Streamer, StreamerConfig,
CaptureBackend, EncodedSource, EncoderPreference, Latest, Pattern, Streamer, StreamerConfig,
VideoPipeline, auto_bitrate, peer_config, preferred_codec, stream_codec, video_codec,
};
use voelin_model::ServerFlavor;
@@ -44,6 +44,10 @@ pub struct StreamArgs {
/// [default: in this order].
#[arg(long, global = true, value_delimiter = ',')]
srtp: Vec<String>,
/// No bandwidth estimation: a streamer sends its bitrate as it is,
/// unpaced, whatever the path takes (for measuring the path).
#[arg(long, global = true)]
no_bwe: bool,
}
#[derive(Subcommand, Debug, Clone)]
@@ -66,6 +70,11 @@ pub enum StreamCommand {
/// Size of the test pattern.
#[arg(long, default_value = "1280x720")]
size: String,
/// What the test pattern shows: `simple` (a flat background, cheap to
/// encode) or `desktop` (a scrolling code editor, about as costly as
/// real screen content).
#[arg(long, default_value = "simple")]
pattern: String,
/// Accept every viewer.
#[arg(long)]
auto_accept: bool,
@@ -109,6 +118,10 @@ pub enum StreamCommand {
/// No hardware encoders unless named with --encoder.
#[arg(long)]
no_hardware: bool,
/// Print what the encoder makes once a second (per layer: size, fps,
/// kbit/s, encode time) while live.
#[arg(long)]
stats: bool,
},
/// List the streams in our channel.
List {
@@ -138,6 +151,10 @@ pub enum StreamCommand {
/// lists its layers (Voelin streamers with several do).
#[arg(long)]
layer: Option<u16>,
/// Print what arrives and decodes once a second (fps, kbit/s, size,
/// decoder, frames skipped).
#[arg(long)]
stats: bool,
},
}
@@ -161,6 +178,7 @@ pub async fn run(con: &mut Connection, args: &StreamArgs) -> Result<()> {
if !args.srtp.is_empty() {
config.srtp_profiles = parse_srtp(&args.srtp)?;
}
config.bandwidth_estimation = !args.no_bwe;
let mut codecs = Codecs::new();
if let StreamCommand::Start {
simulcast,
@@ -230,8 +248,15 @@ pub async fn run(con: &mut Connection, args: &StreamArgs) -> Result<()> {
no_audio,
layers,
placeholder,
stats,
pattern,
..
} => {
let pattern = match pattern.as_str() {
"simple" => Pattern::Simple,
"desktop" => Pattern::Desktop,
other => bail!("unknown pattern {other:?}: simple or desktop"),
};
let mut layers = layers.clone();
number_layers(&mut layers);
let layers = &layers;
@@ -271,6 +296,7 @@ pub async fn run(con: &mut Connection, args: &StreamArgs) -> Result<()> {
encoder: codecs.preference().clone(),
audio: !no_audio,
synthetic_size: parse_size(size)?,
synthetic_pattern: pattern,
layers: layers.clone(),
..StreamerConfig::default()
};
@@ -295,18 +321,30 @@ pub async fn run(con: &mut Connection, args: &StreamArgs) -> Result<()> {
layers: layers.clone(),
..Default::default()
};
start(con, &mut driver, options, source, seconds.map(Duration::from_secs)).await
let length = seconds.map(Duration::from_secs);
start(con, &mut driver, options, source, length, *stats).await
}
StreamCommand::List { settle_ms } => {
list(con, &mut driver, Duration::from_millis(*settle_ms)).await
}
StreamCommand::Watch { id, streamer_nick, expect_frames, timeout, save_frame, layer } => {
StreamCommand::Watch {
id,
streamer_nick,
expect_frames,
timeout,
save_frame,
layer,
stats,
} => {
let target =
Target { id: id.clone(), streamer_nick: streamer_nick.clone(), layer: *layer };
let timeout = timeout.map(Duration::from_secs);
let expect = *expect_frames;
let save = save_frame.as_deref();
watch(con, &mut driver, codecs, &target, expect, timeout, save).await
let until = Until {
frames: *expect_frames,
timeout: timeout.map(Duration::from_secs),
save: save_frame.as_deref(),
stats: *stats,
};
watch(con, &mut driver, codecs, &target, until).await
}
};
driver.finish(con).await;
@@ -614,8 +652,10 @@ async fn start(
options: StreamerOptions,
mut source: Source,
length: Option<Duration>,
stats: bool,
) -> Result<()> {
let auto_accept = options.auto_accept;
let mut stats_at = Instant::now();
driver.streams.start(options)?;
let deadline = length.map(|l| Instant::now() + l);
let mut tick = tokio::time::interval(source.frames().interval());
@@ -640,6 +680,30 @@ async fn start(
}
driver.streams.write_frame(&frame);
}
if stats
&& stats_at.elapsed() >= Duration::from_secs(1)
&& let Source::Encoded(source) = &source
{
stats_at = Instant::now();
let s = source.streamer().stats();
let layers: Vec<String> = s
.layers
.iter()
.map(|l| {
format!(
"L{} {}x{} {:.1} fps {:.0} kbit/s target {} enc {:.2} ms",
l.id,
l.width,
l.height,
l.fps,
l.kbps,
rate(l.bitrate),
l.encode_time.as_secs_f64() * 1e3
)
})
.collect();
println!("encoder: capture {:.1} fps; {}", s.capture_fps, layers.join("; "));
}
}
Wake::Line(None) => lines = None,
Wake::Line(Some(line)) => {
@@ -805,16 +869,27 @@ fn save_png(picture: &VideoFrame, path: &Path) -> Result<()> {
Ok(())
}
/// How long [`watch`] runs and what it reports.
struct Until<'a> {
/// Exit once this many pictures were decoded.
frames: Option<u64>,
timeout: Option<Duration>,
/// Save the last picture here.
save: Option<&'a Path>,
/// Print the decoder's numbers once a second.
stats: bool,
}
async fn watch(
con: &mut Connection,
driver: &mut Driver,
codecs: Arc<Codecs>,
target: &Target,
expect: Option<u64>,
timeout: Option<Duration>,
save: Option<&Path>,
until: Until<'_>,
) -> Result<()> {
let Until { frames: expect, timeout, save, stats: print_stats } = until;
let deadline = timeout.map(|t| Instant::now() + t);
let mut stats_at = Instant::now();
let mut watching: Option<String> = None;
let (mut video, mut audio) = (0u64, 0u64);
let mut codec = None;
@@ -874,6 +949,21 @@ async fn watch(
summary(video, audio, &decoder);
return save_last(&last_picture);
}
if print_stats && watching.is_some() && stats_at.elapsed() >= Duration::from_secs(1) {
stats_at = Instant::now();
let s = decoder.stats();
println!(
"decoded {} fps, received {}, {}x{} {}, {} decoded, {} skipped, {} keyframe requests",
s.fps,
rate(s.bitrate),
s.width,
s.height,
s.decoder.map_or("-".to_owned(), |d| d.to_string()),
s.decoded,
s.skipped,
s.keyframe_requests
);
}
if watching.is_none() {
if let Some((id, streamer)) = target.find(con, &driver.streams) {
println!("watching {id} of {} (clid {})", nick(con, streamer), streamer.0);