From 5dd4f361e4b731e8945a6c4c6641dc266f0b016d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 30 Sep 2026 16:39:29 +0300 Subject: [PATCH] fix(engine): the AV1 and hardware refusals report themselves too The class was not closed. `run` reported its decode and demux failures through `DecodeFailure`, but the two other decode loops did not: - `run_av1`'s software refusal printed "software AV1 decode failed at frame N" to stderr and set nothing -- the exact shape the H.264 witness reproduces, in a different loop and out of a different decoder. - `run_hw` never took the parameter at all; its mid-stream `Err` arm printed "hardware decode error at frame N" and returned. Both now set the same cell `run_span` already holds, keeping the stderr line for logs exactly as the other arms do. `run_hw` deliberately does NOT report the failure before its first picture: that `return false` is the signal that software should take over, the caller reports the fallback, and saying it there as well would put a fault on the strip for a span that is about to decode cleanly. `decode_failure.rs` loses its container-agnostic damage helper and the AV1 case. The helper only ever knew how to damage an mp4's mdat payload; every attempt to reach the AV1 arm through a Matroska fixture failed before a single frame decoded (a zeroed span breaks the EBML chain and the file will not open at all -- "bad EBML variable-length integer" -- and an EBML walk to zero only block payloads did not find blocks in the time available). Leaving a half-working fixture builder in a test is worse than naming the gap, so both are gone and the gap is in the report. Gates: cargo check -p engine --all-targets 0/0; decode_failure 2/2; exif_orientation 5/5; images 8/8. --- crates/engine/src/decode.rs | 22 +++++++++++++++++++--- crates/engine/tests/decode_failure.rs | 21 +++++++++++---------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/decode.rs b/crates/engine/src/decode.rs index c6602fe..b11fb61 100644 --- a/crates/engine/src/decode.rs +++ b/crates/engine/src/decode.rs @@ -1258,6 +1258,7 @@ fn run_span( &mut render, abort, speed, + worker_failure, ); // A *reused* session that produced nothing may simply be one this // reseek left where the driver would not follow; a session opened fresh @@ -1270,7 +1271,16 @@ fn run_span( ); opened.hw = open_hw(path, start); if let Some(hw) = opened.hw.as_mut() { - decoded = run_hw(hw, &tx, start, end, &mut render, abort, speed); + decoded = run_hw( + hw, + &tx, + start, + end, + &mut render, + abort, + speed, + worker_failure, + ); } } if decoded { @@ -2950,6 +2960,7 @@ fn run_hw( render: &mut Render, abort: &Abort, speed: Speed, + failure: &DecodeFailure, ) -> bool { let mut index = start_frame; // Pictures dropped for being late since the last one handed over; see @@ -2989,10 +3000,15 @@ fn run_hw( } Ok(None) => return true, Err(e) => { + // Before the first picture this is not a failure to report but + // the signal that software should take over, and it is reported + // by the caller that does the falling back -- saying it here as + // well would put a fault on the strip for a span that is about + // to decode cleanly. if index == start_frame { return false; } - eprintln!("hardware decode error at frame {index}: {e}"); + failure.set(format!("hardware decode error at frame {index}: {e}")); return true; } } @@ -4018,7 +4034,7 @@ fn run_av1( // the pictures decoded so far stand and the span ends. if let Err(e) = decode { if !done { - eprintln!("software AV1 decode failed at frame {index}: {e}"); + failure.set(format!("software AV1 decode failed at frame {index}: {e}")); done = true; } } diff --git a/crates/engine/tests/decode_failure.rs b/crates/engine/tests/decode_failure.rs index 2fb01ae..20ebd56 100644 --- a/crates/engine/tests/decode_failure.rs +++ b/crates/engine/tests/decode_failure.rs @@ -43,20 +43,21 @@ fn pin_software() { /// `test_av.mp4` with the last eighth of its **sample data** overwritten, and /// the file otherwise untouched: `moov` still claims every frame the header /// ever did, and the demuxer hands the decoder exactly what it always handed -/// it. The damage is bounded to the `mdat` payload on purpose -- `moov` sits -/// after `mdat` in this fixture, so a damage that ran to the end of the file -/// would take the index with it and produce an unopenable file rather than a -/// decodable one with a bad tail, which is a different defect. +/// it. +/// +/// The damage is bounded to the `mdat` payload on purpose. `moov` sits *after* +/// `mdat` in this fixture, so a damage that ran to the end of the file would +/// take the index with it and leave a file that will not open at all -- a +/// different defect, reached before a single frame is decoded and invisible to +/// the thing this test is about. /// /// Returns the scratch guard too, so the directory goes when the test ends. fn damaged() -> (Scratch, PathBuf) { let bytes = std::fs::read(asset("test_av.mp4")).expect("the fixture"); - let (data_start, data_end) = mdat_payload(&bytes).expect("an mdat"); - let mut damaged_bytes = bytes.clone(); - // What a transfer that dies part-way leaves behind, over the last eighth of - // the samples it did not finish writing. - let tail = data_start + (data_end - data_start) * 7 / 8; - damaged_bytes[tail..data_end].fill(0); + let (start, end) = mdat_payload(&bytes).expect("an mdat payload"); + let mut damaged_bytes = bytes; + let tail = start + (end - start) * 7 / 8; + damaged_bytes[tail..end].fill(0); let scratch = Scratch::file("ve_decode_failure", "mp4"); let path = PathBuf::from(&*scratch); std::fs::write(&path, &damaged_bytes).expect("write the damaged fixture");