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
@@ -812,7 +812,7 @@ async fn watch(
|
||||
);
|
||||
let mut tick = tokio::time::interval(Duration::from_millis(100));
|
||||
let mut first_picture = true;
|
||||
let mut last_picture: Option<VideoFrame> = None;
|
||||
let mut last_picture: Option<Arc<VideoFrame>> = None;
|
||||
let summary = |video: u64, audio: u64, decoder: &VideoPipeline| {
|
||||
let stats = decoder.stats();
|
||||
println!(
|
||||
@@ -821,7 +821,7 @@ async fn watch(
|
||||
stats.error.map(|e| format!(" (last error: {e})")).unwrap_or_default()
|
||||
);
|
||||
};
|
||||
let save_last = |last: &Option<VideoFrame>| -> Result<()> {
|
||||
let save_last = |last: &Option<Arc<VideoFrame>>| -> Result<()> {
|
||||
match (save, last) {
|
||||
(Some(path), Some(picture)) => {
|
||||
save_png(picture, path)?;
|
||||
|
||||
Reference in new issue
Block a user