Fall back to the next decoder at runtime; recover from losses
A watched stream now decodes with the best decoder of its codec and, when it fails, with the next of the codec's ladder, without ending the watch: three failures in a row (errors, or ten frames without a picture) replace it, the keyframe that failed starts the next one at once, and otherwise a keyframe is asked for. Each switch is logged with its reason, and DecodeStats tells the decoder in use. The official client's H.264 has B-frames and rare keyframes, and the pipeline dropped every frame after a loss or an error until the next keyframe, which such an encoder seldom sends. Decoders that conceal what a loss leaves missing (FFmpeg's H.264 and HEVC) now go on decoding while a keyframe is asked for; the others still skip to it. Whenever one is wanted it is asked for again every half second until it comes, also while no frame arrives, instead of once per skipped frame. Pictures come from a small pool and go to the callback as Arc<VideoFrame>: decoders write into a free one (decode_into), and a consumer that converts and drops each picture, as the app does, costs no allocations. Settings stream.hardware_decoding and stream.decoder_backend choose the decoders like the encoder settings (decoder_preference); the app applies them when they change, to streams watched from then on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
66a2b8329b
commit
289e7d4e6b
5 files changed
+404
-55
No files matched your search
@@ -1031,14 +1031,31 @@ pub static STREAM_SRTP_PROFILES: Key<Vec<String>> = Key::new(
|
||||
)
|
||||
.validated(valid_srtp);
|
||||
|
||||
/// Use hardware video encoders and decoders where available.
|
||||
/// Use hardware video encoders where available.
|
||||
pub static STREAM_HARDWARE_ACCELERATION: Key<bool> = Key::new(
|
||||
"stream.hardware_acceleration",
|
||||
Kind::Bool,
|
||||
"Use hardware video encoders and decoders where available.",
|
||||
"Use hardware video encoders where available.",
|
||||
|| true,
|
||||
);
|
||||
|
||||
/// Use hardware video decoders where available.
|
||||
pub static STREAM_HARDWARE_DECODING: Key<bool> = Key::new(
|
||||
"stream.hardware_decoding",
|
||||
Kind::Bool,
|
||||
"Use hardware video decoders where available.",
|
||||
|| true,
|
||||
);
|
||||
|
||||
/// Video decoder: `auto`, `software`, or the name of a decoder backend.
|
||||
pub static STREAM_DECODER_BACKEND: Key<String> = Key::new(
|
||||
"stream.decoder_backend",
|
||||
Kind::Text { suggestions: &["auto", "software"] },
|
||||
"Video decoder: auto, software, or a decoder's name.",
|
||||
|| "auto".into(),
|
||||
)
|
||||
.validated(not_empty);
|
||||
|
||||
/// Who may watch our stream without being asked.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
@@ -1282,6 +1299,8 @@ pub fn builtin_keys() -> Vec<&'static dyn Setting> {
|
||||
&STREAM_ENCODER_BACKEND,
|
||||
&STREAM_SRTP_PROFILES,
|
||||
&STREAM_HARDWARE_ACCELERATION,
|
||||
&STREAM_HARDWARE_DECODING,
|
||||
&STREAM_DECODER_BACKEND,
|
||||
&STREAM_PERMISSIONS,
|
||||
&CHAT_STORE_HISTORY,
|
||||
&CHAT_HISTORY_PAGE,
|
||||
@@ -1352,6 +1371,8 @@ mod tests {
|
||||
);
|
||||
assert!(s.get(&STREAM_HARDWARE_ACCELERATION));
|
||||
assert_eq!(s.get(&STREAM_ENCODER_BACKEND), "auto");
|
||||
assert!(s.get(&STREAM_HARDWARE_DECODING));
|
||||
assert_eq!(s.get(&STREAM_DECODER_BACKEND), "auto");
|
||||
assert!(s.get(&CHAT_STORE_HISTORY));
|
||||
assert_eq!(s.get(&CHAT_HISTORY_PAGE), 100);
|
||||
assert_eq!(s.get(&CHAT_DEDUPE_TOLERANCE_MS), 5000);
|
||||
|
||||
Reference in new issue
Block a user