forge
Explore
Log in

Don't you dare go Hollow

The BD gate decodes every ladder point with our own decoder too

Browse files at this commit

8f036d9b0e0c01ca9a31b8e02e79681df2de8ee2Ahmet Kaan GümüşParent: d4248c3
  • test
    • the BD gate decodes every ladder point with our own decoder too
Show full message
test(av1): the BD gate decodes every ladder point with our own decoder too

`our_ladder` already decoded each of our streams with ffmpeg and asserted
that decode sample-exact against the encoder's reconstruction; what it
never did was run OUR decoder over the same stream, so every feature
only our writer/reader had seen (size-8 chroma palettes on the screen
clip, say) was gated by ffmpeg alone. Each ladder point now decodes the
stream twice and asserts all three pictures -- reconstruction, ffmpeg,
ours -- equal in Y, U and V over every shown frame in display order, and
a failure names the clip, q, frame, plane and first differing sample.
The `EC_AV1_PYRAMID` path gets the same all-plane compare (the facade
exposes no per-packet reconstruction, so it pins the two decoders).
crates/ec-av1/src/encode.rsmodified+63 -15
@@ -9120,11 +9120,32 @@ mod tests {
91209120 (ladder, wall)
91219121 }
91229122
9123+ /// First differing sample between two pictures, as
9124+ /// `(plane, index, left, right)` -- so a gate failure names the plane and
9125+ /// the sample instead of just "differs". A length difference counts as a
9126+ /// mismatch of that plane at the first index past the shorter one.
9127+ fn first_plane_mismatch(a: &Picture, b: &Picture) -> Option<(&'static str, usize, i64, i64)> {
9128+ for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] {
9129+ if let Some(i) = l.iter().zip(r.iter()).position(|(x, y)| x != y) {
9130+ return Some((plane, i, i64::from(l[i]), i64::from(r[i])));
9131+ }
9132+ if l.len() != r.len() {
9133+ return Some((plane, l.len().min(r.len()), l.len() as i64, r.len() as i64));
9134+ }
9135+ }
9136+ None
9137+ }
9138+
91239139 /// The same ladder for this encoder, at four `base_q_idx` points. The PSNR
9124- /// comes from ffmpeg's decode of our own stream, and every frame of that
9125- /// decode is asserted sample-exact against our reconstruction -- which is
9126- /// itself a gate: it proves the bitstream says what the encoder thinks.
9140+ /// comes from ffmpeg's decode of our own stream, and at EVERY point the
9141+ /// stream is decoded twice -- by ffmpeg and by our own
9142+ /// [`crate::stream::decode_stream`] -- and all three pictures (encoder
9143+ /// reconstruction, ffmpeg's decode, our decode) are asserted sample-exact
9144+ /// in Y, U and V over every shown frame in display order. That is itself
9145+ /// a gate: it proves the bitstream says what the encoder thinks, in the
9146+ /// only two decoders that read it.
91279147 fn our_ladder(
9148+ name: &str,
91289149 source: &[Picture],
91299150 width: usize,
91309151 height: usize,
@@ -9137,13 +9158,27 @@ mod tests {
91379158 let encoded = encode_sequence_with_ctx(source, q, 0.5, fctx).unwrap();
91389159 wall += start.elapsed().as_secs_f64();
91399160 let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, source.len());
9161+ let ours = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
9162+ assert_eq!(
9163+ ours.len(),
9164+ source.len(),
9165+ "{name} q={q}: our decoder's display-order frame count"
9166+ );
91409167 for (i, (d, e)) in decoded.iter().zip(&encoded.frames).enumerate() {
9141- assert!(
9142- d.y == e.reconstruction.y
9143- && d.u == e.reconstruction.u
9144- && d.v == e.reconstruction.v,
9145- "q={q} frame {i}: ffmpeg's decode differs from our reconstruction"
9146- );
9168+ if let Some((plane, s, got, want)) = first_plane_mismatch(d, &e.reconstruction) {
9169+ panic!(
9170+ "{name} q={q} frame {i} plane {plane} sample {s}: ffmpeg decoded \
9171+ {got}, the encoder reconstructed {want}"
9172+ );
9173+ }
9174+ }
9175+ for (i, (o, e)) in ours.iter().zip(&encoded.frames).enumerate() {
9176+ if let Some((plane, s, got, want)) = first_plane_mismatch(o, &e.reconstruction) {
9177+ panic!(
9178+ "{name} q={q} frame {i} plane {plane} sample {s}: our decoder decoded \
9179+ {got}, the encoder reconstructed {want}"
9180+ );
9181+ }
91479182 }
91489183 let mean: f64 = decoded
91499184 .iter()
@@ -9180,6 +9215,7 @@ mod tests {
91809215 /// the ladder, the wall, and — per pyramid level over the whole ladder —
91819216 /// how many frames and how many bytes it spent.
91829217 fn our_ladder_pyramid(
9218+ name: &str,
91839219 source: &[Picture],
91849220 width: usize,
91859221 height: usize,
@@ -9224,10 +9260,15 @@ mod tests {
92249260 // source picture, in the right order -- checked against our own
92259261 // decoder as well as ffmpeg's, both below.
92269262 let ours = crate::stream::decode_stream(&stream).expect("our decoder");
9227- assert_eq!(ours.len(), source.len(), "q={q}: our display-order count");
9263+ assert_eq!(ours.len(), source.len(), "{name} q={q}: our display-order count");
92289264 let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());
92299265 for (i, (d, o)) in decoded.iter().zip(&ours).enumerate() {
9230- assert!(d.y == o.y, "q={q} display frame {i}: ffmpeg differs from our decoder");
9266+ if let Some((plane, s, got, want)) = first_plane_mismatch(d, o) {
9267+ panic!(
9268+ "{name} q={q} display frame {i} plane {plane} sample {s}: ffmpeg \
9269+ decoded {got}, our decoder decoded {want}"
9270+ );
9271+ }
92319272 }
92329273 let mean: f64 = decoded
92339274 .iter()
@@ -9426,8 +9467,15 @@ mod tests {
94269467 /// search's own cost, uncut: see the two intra-pruning variants measured
94279468 /// and rejected in the lane report). No
94289469 /// threshold is asserted yet -- this run sets the baseline; the gate
9429- /// asserts only four monotone points per ladder and that ffmpeg decodes
9430- /// our stream sample-exact against our reconstruction.
9470+ /// asserts four monotone points per ladder, and at EVERY ladder point of
9471+ /// EVERY clip it decodes our stream twice -- with ffmpeg and with our own
9472+ /// `crate::stream::decode_stream` -- and asserts the encoder's
9473+ /// reconstruction, ffmpeg's decode and our decode sample-exact in Y, U
9474+ /// and V over every shown frame in display order. A failure names the
9475+ /// clip, the q, the frame, the plane and the first differing sample.
9476+ /// (Under `EC_AV1_PYRAMID` the frames come out of the streaming facade,
9477+ /// which exposes no per-packet reconstruction, so that path asserts the
9478+ /// two decoders against each other on all three planes.)
94319479 ///
94329480 /// Run:
94339481 /// cargo test -p ec-av1 --release --lib -- --ignored \
@@ -9509,10 +9557,10 @@ mod tests {
95099557 let _ = crate::tile::take_compound_pair_hits();
95109558 let _ = crate::motion::take_census();
95119559 let (ours, ours_wall) = match pyramid_from_env() {
9512- None => our_ladder(&source, width, height, fctx),
9560+ None => our_ladder(name, &source, width, height, fctx),
95139561 Some(pyramid) => {
95149562 let (ladder, wall, counts, bytes) =
9515- our_ladder_pyramid(&source, width, height, pyramid);
9563+ our_ladder_pyramid(name, &source, width, height, pyramid);
95169564 eprintln!(
95179565 "{name}: pyramid {pyramid:?} -- frames key {} arf {} leaf {} \
95189566 show_existing {}; bytes key {} arf {} leaf {} show_existing {}",