Let a viewer pick the simulcast layer of a Voelin stream

The streamer chose each viewer's layer from its bandwidth estimate, and a
viewer could neither see which layers there were nor ask for one: the watch
screen's quality picker only asked for a keyframe.

A Voelin streamer with several layers now lists them in its offer, in a
session-level SDP attribute, `a=x-voelin-layers:<id>/<WxH or
scale>/<bitrate>[/<fps>] ...`, added to the SDP str0m makes (peer.rs is
untouched). A Voelin viewer reports them (WatchEvent::Layers,
Event::WatchLayers) and asks for one with Command::SetWatchLayer, which
sends `{"cmd":"x-voelin-layer","args":{"layer":<id or null>}}` through
streamsignaling. The streamer moves that viewer to the layer at its next
keyframe and keeps it there whatever the estimate says, without letting it
lower the layer's bitrate for everyone else; null ("Auto") hands the
choice back to the estimate. The watch screen's picker now drives it.

Official clients are not affected. libwebrtc skips session attributes it
does not know: headless Chromium 152 answers an offer carrying the line
and decodes as before (browser interop test, which now sends it). A viewer
sends the request only to a streamer whose offer had the attribute, and
only Voelin streamers add it, so official streamers never get the signal;
which codecs are offered does not change.

Tests: two sessions with peers on loopback switch the viewer to layer 1
and back on request; a streamer whose offer lists no layers is never
asked; the attribute round-trips. Through the TeamSpeak 6 dev server,
`voelinctl stream watch --layer 1` against a two-layer placeholder stream
kept the viewer on layer 1 at an estimate that fits layer 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 18:10:17 +03:00
1 parent f2ffd761fc
commit 8d14b0d5be
13 files changed
+450 -19

No files matched your search

+15 -4
View File
@@ -154,6 +154,17 @@ impl App {
Event::WatchState { session, stream_id, state } => {
self.watch_state(session as i64, &stream_id, state);
}
Event::WatchLayers { session, stream_id, layers, layer } => {
if let Some(watch) = self
.watch
.as_mut()
.filter(|w| w.session == Some(session as i64) && w.stream_id == stream_id)
{
watch.layers = layers;
watch.layer = layer;
self.refresh_viewer();
}
}
// Also flagged on the sink, which the encoder reads.
Event::StreamKeyframeRequest { .. } => {}
_ => {}
@@ -369,17 +380,17 @@ impl App {
}
/// A simulcast layer of the watched stream (0: follow the bandwidth
/// estimate). The streamer picks the layer from each viewer's estimate,
/// so this asks for the picture again; a viewer-side choice needs an
/// engine API that does not exist yet.
/// estimate), asked of the streamer; the engine confirms with
/// `WatchLayers`.
pub(crate) fn set_stream_quality(&mut self, index: i32) {
let Some(watch) = &mut self.watch else { return };
watch.layer =
usize::try_from(index - 1).ok().and_then(|i| watch.layers.get(i)).map(|l| l.id);
if let Some(session) = watch.session {
self.engine.send(Command::RequestStreamKeyframe {
self.engine.send(Command::SetWatchLayer {
session: session as u64,
stream_id: watch.stream_id.clone(),
layer: watch.layer,
});
}
self.refresh_viewer();