forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1gatedec' (15c70d52): the BD gate decodes every ladder point with ffmpeg and with this crate's own decoder and asserts all three sample-exact

Browse files at this commit

c759b78f2f190ba710b54e61d84dc69e830c66e5Ahmet Kaan GümüşParent: 8b1a7338f036d9
The ffmpeg leg always ran; the own-decoder leg was missing on the flat
ladder. Failures now name clip, q, frame, plane and sample.
crates/ec-av1/src/encode.rsmodified+63 -15
@@ -9399,11 +9399,32 @@ mod tests {
93999399 (ladder, wall)
94009400 }
94019401
9402+ /// First differing sample between two pictures, as
9403+ /// `(plane, index, left, right)` -- so a gate failure names the plane and
9404+ /// the sample instead of just "differs". A length difference counts as a
9405+ /// mismatch of that plane at the first index past the shorter one.
9406+ fn first_plane_mismatch(a: &Picture, b: &Picture) -> Option<(&'static str, usize, i64, i64)> {
9407+ for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] {
9408+ if let Some(i) = l.iter().zip(r.iter()).position(|(x, y)| x != y) {
9409+ return Some((plane, i, i64::from(l[i]), i64::from(r[i])));
9410+ }
9411+ if l.len() != r.len() {
9412+ return Some((plane, l.len().min(r.len()), l.len() as i64, r.len() as i64));
9413+ }
9414+ }
9415+ None
9416+ }
9417+
94029418 /// The same ladder for this encoder, at four `base_q_idx` points. The PSNR
9403- /// comes from ffmpeg's decode of our own stream, and every frame of that
9404- /// decode is asserted sample-exact against our reconstruction -- which is
9405- /// itself a gate: it proves the bitstream says what the encoder thinks.
9419+ /// comes from ffmpeg's decode of our own stream, and at EVERY point the
9420+ /// stream is decoded twice -- by ffmpeg and by our own
9421+ /// [`crate::stream::decode_stream`] -- and all three pictures (encoder
9422+ /// reconstruction, ffmpeg's decode, our decode) are asserted sample-exact
9423+ /// in Y, U and V over every shown frame in display order. That is itself
9424+ /// a gate: it proves the bitstream says what the encoder thinks, in the
9425+ /// only two decoders that read it.
94069426 fn our_ladder(
9427+ name: &str,
94079428 source: &[Picture],
94089429 width: usize,
94099430 height: usize,
@@ -9416,13 +9437,27 @@ mod tests {
94169437 let encoded = encode_sequence_with_ctx(source, q, 0.5, fctx).unwrap();
94179438 wall += start.elapsed().as_secs_f64();
94189439 let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, source.len());
9440+ let ours = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
9441+ assert_eq!(
9442+ ours.len(),
9443+ source.len(),
9444+ "{name} q={q}: our decoder's display-order frame count"
9445+ );
94199446 for (i, (d, e)) in decoded.iter().zip(&encoded.frames).enumerate() {
9420- assert!(
9421- d.y == e.reconstruction.y
9422- && d.u == e.reconstruction.u
9423- && d.v == e.reconstruction.v,
9424- "q={q} frame {i}: ffmpeg's decode differs from our reconstruction"
9425- );
9447+ if let Some((plane, s, got, want)) = first_plane_mismatch(d, &e.reconstruction) {
9448+ panic!(
9449+ "{name} q={q} frame {i} plane {plane} sample {s}: ffmpeg decoded \
9450+ {got}, the encoder reconstructed {want}"
9451+ );
9452+ }
9453+ }
9454+ for (i, (o, e)) in ours.iter().zip(&encoded.frames).enumerate() {
9455+ if let Some((plane, s, got, want)) = first_plane_mismatch(o, &e.reconstruction) {
9456+ panic!(
9457+ "{name} q={q} frame {i} plane {plane} sample {s}: our decoder decoded \
9458+ {got}, the encoder reconstructed {want}"
9459+ );
9460+ }
94269461 }
94279462 let mean: f64 = decoded
94289463 .iter()
@@ -9459,6 +9494,7 @@ mod tests {
94599494 /// the ladder, the wall, and — per pyramid level over the whole ladder —
94609495 /// how many frames and how many bytes it spent.
94619496 fn our_ladder_pyramid(
9497+ name: &str,
94629498 source: &[Picture],
94639499 width: usize,
94649500 height: usize,
@@ -9503,10 +9539,15 @@ mod tests {
95039539 // source picture, in the right order -- checked against our own
95049540 // decoder as well as ffmpeg's, both below.
95059541 let ours = crate::stream::decode_stream(&stream).expect("our decoder");
9506- assert_eq!(ours.len(), source.len(), "q={q}: our display-order count");
9542+ assert_eq!(ours.len(), source.len(), "{name} q={q}: our display-order count");
95079543 let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());
95089544 for (i, (d, o)) in decoded.iter().zip(&ours).enumerate() {
9509- assert!(d.y == o.y, "q={q} display frame {i}: ffmpeg differs from our decoder");
9545+ if let Some((plane, s, got, want)) = first_plane_mismatch(d, o) {
9546+ panic!(
9547+ "{name} q={q} display frame {i} plane {plane} sample {s}: ffmpeg \
9548+ decoded {got}, our decoder decoded {want}"
9549+ );
9550+ }
95109551 }
95119552 let mean: f64 = decoded
95129553 .iter()
@@ -9705,8 +9746,15 @@ mod tests {
97059746 /// search's own cost, uncut: see the two intra-pruning variants measured
97069747 /// and rejected in the lane report). No
97079748 /// threshold is asserted yet -- this run sets the baseline; the gate
9708- /// asserts only four monotone points per ladder and that ffmpeg decodes
9709- /// our stream sample-exact against our reconstruction.
9749+ /// asserts four monotone points per ladder, and at EVERY ladder point of
9750+ /// EVERY clip it decodes our stream twice -- with ffmpeg and with our own
9751+ /// `crate::stream::decode_stream` -- and asserts the encoder's
9752+ /// reconstruction, ffmpeg's decode and our decode sample-exact in Y, U
9753+ /// and V over every shown frame in display order. A failure names the
9754+ /// clip, the q, the frame, the plane and the first differing sample.
9755+ /// (Under `EC_AV1_PYRAMID` the frames come out of the streaming facade,
9756+ /// which exposes no per-packet reconstruction, so that path asserts the
9757+ /// two decoders against each other on all three planes.)
97109758 ///
97119759 /// Run:
97129760 /// cargo test -p ec-av1 --release --lib -- --ignored \
@@ -9789,10 +9837,10 @@ mod tests {
97899837 let _ = crate::tile::take_compound_size_hits();
97909838 let _ = crate::motion::take_census();
97919839 let (ours, ours_wall) = match pyramid_from_env() {
9792- None => our_ladder(&source, width, height, fctx),
9840+ None => our_ladder(name, &source, width, height, fctx),
97939841 Some(pyramid) => {
97949842 let (ladder, wall, counts, bytes) =
9795- our_ladder_pyramid(&source, width, height, pyramid);
9843+ our_ladder_pyramid(name, &source, width, height, pyramid);
97969844 eprintln!(
97979845 "{name}: pyramid {pyramid:?} -- frames key {} arf {} leaf {} \
97989846 show_existing {}; bytes key {} arf {} leaf {} show_existing {}",