Step down to another codec when the video never decodes

The viewer's runtime step keyed on video arriving at the transport. Now
that the pipeline keeps decoding after losses and tries a ladder of
decoders, "no media flows" has to be judged by decoded pictures: video
that keeps coming in a codec none of our decoders can show is the same
failure as no video, one layer up.

The app's Viewer watches the pipeline's decoded count (DecodeWatch): when
frames of one codec have come for 10 s, at least 60 of them, without a
single picture (time for every decoder of the codec's ladder to fail),
it sends Command::StreamUndecodable once. The stream task passes it to
Streams::video_undecodable, which asks the streamer for a new connection
without that codec if it offered another we take (the same Fallback as
the transport checks, logged, nothing left: logged and nothing loops).
A codec that decoded once is never reported: later losses are the
pipeline's to repair.

Tests: DecodeWatch alone (time and frames both needed, once per codec,
a codec that decoded is fine), through a real VideoPipeline (VP9 frames
that are not VP9 are reported after the wait, real VP8 keyframes never),
and two sessions where video_undecodable moves the viewer from VP9 to
VP8 and then, with nothing left, stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-04 03:28:09 +03:00
1 parent a1d6c6f8aa
commit 0d9c9ce836
6 files changed
+215 -13

No files matched your search

+33 -12
View File
@@ -1597,15 +1597,15 @@ impl ViewerSession {
Ok(())
}
/// Connected, but no video came ([`PeerEvent::NoVideo`]): ask for a new
/// connection with the next lower set ([`Fallback`]), without the SRTP
/// profile this one negotiated when nothing came at all, without its
/// video codec when audio did (or no other profile is left).
fn fall_back(&mut self, audio: bool, out: &mut Outbox) {
/// The media of this connection does not get through (`why`): ask for a
/// new connection with the next lower set ([`Fallback`]): without the
/// SRTP profile this one negotiated when `srtp` (nothing came at all),
/// else (or when no other profile is left) without its video codec.
fn fall_back(&mut self, srtp: bool, why: &str, out: &mut Outbox) {
let config = self.fallback.apply(&self.config);
let profile = self.peer.as_ref().and_then(Peer::srtp_profile);
let mut step = None;
if !audio && let Some(profile) = profile {
if srtp && let Some(profile) = profile {
step = self
.fallback
.without_srtp(&config, profile)
@@ -1625,18 +1625,24 @@ impl ViewerSession {
.map(|left| format!("without {codec} (left: {})", list(&left)));
}
let Some(step) = step else {
warn!(stream = self.id, audio, "connected, but no video; nothing left to fall back to");
warn!(stream = self.id, "{why}; nothing left to fall back to");
return;
};
warn!(
stream = self.id,
audio, "connected, but no video; asking for a new connection {step}"
);
warn!(stream = self.id, "{why}; asking for a new connection {step}");
self.peer = None;
self.state = WatchState::Connecting;
self.signal(Signal::Reconnect, out);
}
/// Video arrives, but none of it decodes here (the app's decoders told
/// [`Streams::video_undecodable`]): a new connection without its codec,
/// if the streamer offered another we take.
pub fn video_undecodable(&mut self, out: &mut Outbox) {
if self.state == WatchState::Connected {
self.fall_back(false, "video arrives, but none of it decodes", out);
}
}
/// Drop the connection and ask the streamer for a new offer (`reconnect`).
pub fn reconnect(&mut self, out: &mut Outbox) {
if matches!(self.state, WatchState::Connecting | WatchState::Connected) {
@@ -1716,7 +1722,12 @@ impl ViewerSession {
self.event(WatchEvent::Frame(frame), out);
}
}
PeerEvent::NoVideo { audio } => self.fall_back(audio, out),
PeerEvent::NoVideo { audio: false } => {
self.fall_back(true, "connected, but nothing arrives", out);
}
PeerEvent::NoVideo { audio: true } => {
self.fall_back(false, "connected, but no video arrives (audio does)", out);
}
PeerEvent::KeyframeRequest
| PeerEvent::LayerKeyframeRequest(_)
| PeerEvent::BitrateEstimate(_)
@@ -1944,6 +1955,16 @@ impl Streams {
viewer.set_layer(layer, &mut self.out)
}
/// The video of a watched stream arrives, but none of it decodes: watch
/// it in another codec the streamer offered, if there is one (see
/// [`ViewerSession::video_undecodable`]).
pub fn video_undecodable(&mut self, id: &str) -> Result<(), SessionError> {
let viewer =
self.viewers.get_mut(id).ok_or_else(|| SessionError::NotWatching(id.into()))?;
viewer.video_undecodable(&mut self.out);
Ok(())
}
/// Reconnect to a watched stream: the streamer sends a new offer.
pub fn reconnect(&mut self, id: &str) -> Result<(), SessionError> {
let viewer =