forge
Explore
Log in

Don't you dare go Hollow

The AV1 and hardware refusals report themselves too

Browse files at this commit

5dd4f361e4b731e8945a6c4c6641dc266f0b016dAhmet Kaan GümüşParent: 6bc4cc2
  • fix
    • the AV1 and hardware refusals report themselves too
Show full message
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.rsmodified+19 -3
@@ -1258,6 +1258,7 @@ fn run_span(
1258 &mut render,1258 &mut render,
1259 abort,1259 abort,
1260 speed,1260 speed,
1261+ worker_failure,
1261 );1262 );
1262 // A *reused* session that produced nothing may simply be one this1263 // A *reused* session that produced nothing may simply be one this
1263 // reseek left where the driver would not follow; a session opened fresh1264 // reseek left where the driver would not follow; a session opened fresh
@@ -1270,7 +1271,16 @@ fn run_span(
1270 );1271 );
1271 opened.hw = open_hw(path, start);1272 opened.hw = open_hw(path, start);
1272 if let Some(hw) = opened.hw.as_mut() {1273 if let Some(hw) = opened.hw.as_mut() {
1273- decoded = run_hw(hw, &tx, start, end, &mut render, abort, speed);1274+ decoded = run_hw(
1275+ hw,
1276+ &tx,
1277+ start,
1278+ end,
1279+ &mut render,
1280+ abort,
1281+ speed,
1282+ worker_failure,
1283+ );
1274 }1284 }
1275 }1285 }
1276 if decoded {1286 if decoded {
@@ -2950,6 +2960,7 @@ fn run_hw(
2950 render: &mut Render,2960 render: &mut Render,
2951 abort: &Abort,2961 abort: &Abort,
2952 speed: Speed,2962 speed: Speed,
2963+ failure: &DecodeFailure,
2953 ) -> bool {2964 ) -> bool {
2954 let mut index = start_frame;2965 let mut index = start_frame;
2955 // Pictures dropped for being late since the last one handed over; see2966 // Pictures dropped for being late since the last one handed over; see
@@ -2989,10 +3000,15 @@ fn run_hw(
2989 }3000 }
2990 Ok(None) => return true,3001 Ok(None) => return true,
2991 Err(e) => {3002 Err(e) => {
3003+ // Before the first picture this is not a failure to report but
3004+ // the signal that software should take over, and it is reported
3005+ // by the caller that does the falling back -- saying it here as
3006+ // well would put a fault on the strip for a span that is about
3007+ // to decode cleanly.
2992 if index == start_frame {3008 if index == start_frame {
2993 return false;3009 return false;
2994 }3010 }
2995- eprintln!("hardware decode error at frame {index}: {e}");3011+ failure.set(format!("hardware decode error at frame {index}: {e}"));
2996 return true;3012 return true;
2997 }3013 }
2998 }3014 }
@@ -4018,7 +4034,7 @@ fn run_av1(
4018 // the pictures decoded so far stand and the span ends.4034 // the pictures decoded so far stand and the span ends.
4019 if let Err(e) = decode {4035 if let Err(e) = decode {
4020 if !done {4036 if !done {
4021- eprintln!("software AV1 decode failed at frame {index}: {e}");4037+ failure.set(format!("software AV1 decode failed at frame {index}: {e}"));
4022 done = true;4038 done = true;
4023 }4039 }
4024 }4040 }
crates/engine/tests/decode_failure.rsmodified+11 -10
@@ -43,20 +43,21 @@ fn pin_software() {
43 /// `test_av.mp4` with the last eighth of its **sample data** overwritten, and43 /// `test_av.mp4` with the last eighth of its **sample data** overwritten, and
44 /// the file otherwise untouched: `moov` still claims every frame the header44 /// the file otherwise untouched: `moov` still claims every frame the header
45 /// ever did, and the demuxer hands the decoder exactly what it always handed45 /// ever did, and the demuxer hands the decoder exactly what it always handed
46-/// it. The damage is bounded to the `mdat` payload on purpose -- `moov` sits46+/// it.
47-/// after `mdat` in this fixture, so a damage that ran to the end of the file47+///
48-/// would take the index with it and produce an unopenable file rather than a48+/// The damage is bounded to the `mdat` payload on purpose. `moov` sits *after*
49-/// decodable one with a bad tail, which is a different defect.49+/// `mdat` in this fixture, so a damage that ran to the end of the file would
50+/// take the index with it and leave a file that will not open at all -- a
51+/// different defect, reached before a single frame is decoded and invisible to
52+/// the thing this test is about.
50 ///53 ///
51 /// Returns the scratch guard too, so the directory goes when the test ends.54 /// Returns the scratch guard too, so the directory goes when the test ends.
52 fn damaged() -> (Scratch, PathBuf) {55 fn damaged() -> (Scratch, PathBuf) {
53 let bytes = std::fs::read(asset("test_av.mp4")).expect("the fixture");56 let bytes = std::fs::read(asset("test_av.mp4")).expect("the fixture");
54- let (data_start, data_end) = mdat_payload(&bytes).expect("an mdat");57+ let (start, end) = mdat_payload(&bytes).expect("an mdat payload");
55- let mut damaged_bytes = bytes.clone();58+ let mut damaged_bytes = bytes;
56- // What a transfer that dies part-way leaves behind, over the last eighth of59+ let tail = start + (end - start) * 7 / 8;
57- // the samples it did not finish writing.60+ damaged_bytes[tail..end].fill(0);
58- let tail = data_start + (data_end - data_start) * 7 / 8;
59- damaged_bytes[tail..data_end].fill(0);
60 let scratch = Scratch::file("ve_decode_failure", "mp4");61 let scratch = Scratch::file("ve_decode_failure", "mp4");
61 let path = PathBuf::from(&*scratch);62 let path = PathBuf::from(&*scratch);
62 std::fs::write(&path, &damaged_bytes).expect("write the damaged fixture");63 std::fs::write(&path, &damaged_bytes).expect("write the damaged fixture");