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+62 -14
@@ -9120,11 +9120,32 @@ mod tests {
9120 (ladder, wall)9120 (ladder, wall)
9121 }9121 }
9122 9122
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+
9123 /// The same ladder for this encoder, at four `base_q_idx` points. The PSNR9139 /// 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 that9140+ /// comes from ffmpeg's decode of our own stream, and at EVERY point the
9125- /// decode is asserted sample-exact against our reconstruction -- which is9141+ /// stream is decoded twice -- by ffmpeg and by our own
9126- /// itself a gate: it proves the bitstream says what the encoder thinks.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.
9127 fn our_ladder(9147 fn our_ladder(
9148+ name: &str,
9128 source: &[Picture],9149 source: &[Picture],
9129 width: usize,9150 width: usize,
9130 height: usize,9151 height: usize,
@@ -9137,14 +9158,28 @@ mod tests {
9137 let encoded = encode_sequence_with_ctx(source, q, 0.5, fctx).unwrap();9158 let encoded = encode_sequence_with_ctx(source, q, 0.5, fctx).unwrap();
9138 wall += start.elapsed().as_secs_f64();9159 wall += start.elapsed().as_secs_f64();
9139 let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, source.len());9160 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+ );
9140 for (i, (d, e)) in decoded.iter().zip(&encoded.frames).enumerate() {9167 for (i, (d, e)) in decoded.iter().zip(&encoded.frames).enumerate() {
9141- assert!(9168+ if let Some((plane, s, got, want)) = first_plane_mismatch(d, &e.reconstruction) {
9142- d.y == e.reconstruction.y9169+ panic!(
9143- && d.u == e.reconstruction.u9170+ "{name} q={q} frame {i} plane {plane} sample {s}: ffmpeg decoded \
9144- && d.v == e.reconstruction.v,9171+ {got}, the encoder reconstructed {want}"
9145- "q={q} frame {i}: ffmpeg's decode differs from our reconstruction"
9146 );9172 );
9147 }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+ }
9182+ }
9148 let mean: f64 = decoded9183 let mean: f64 = decoded
9149 .iter()9184 .iter()
9150 .zip(source)9185 .zip(source)
@@ -9180,6 +9215,7 @@ mod tests {
9180 /// the ladder, the wall, and — per pyramid level over the whole ladder —9215 /// the ladder, the wall, and — per pyramid level over the whole ladder —
9181 /// how many frames and how many bytes it spent.9216 /// how many frames and how many bytes it spent.
9182 fn our_ladder_pyramid(9217 fn our_ladder_pyramid(
9218+ name: &str,
9183 source: &[Picture],9219 source: &[Picture],
9184 width: usize,9220 width: usize,
9185 height: usize,9221 height: usize,
@@ -9224,10 +9260,15 @@ mod tests {
9224 // source picture, in the right order -- checked against our own9260 // source picture, in the right order -- checked against our own
9225 // decoder as well as ffmpeg's, both below.9261 // decoder as well as ffmpeg's, both below.
9226 let ours = crate::stream::decode_stream(&stream).expect("our decoder");9262 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");
9228 let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());9264 let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());
9229 for (i, (d, o)) in decoded.iter().zip(&ours).enumerate() {9265 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+ }
9231 }9272 }
9232 let mean: f64 = decoded9273 let mean: f64 = decoded
9233 .iter()9274 .iter()
@@ -9426,8 +9467,15 @@ mod tests {
9426 /// search's own cost, uncut: see the two intra-pruning variants measured9467 /// search's own cost, uncut: see the two intra-pruning variants measured
9427 /// and rejected in the lane report). No9468 /// and rejected in the lane report). No
9428 /// threshold is asserted yet -- this run sets the baseline; the gate9469 /// threshold is asserted yet -- this run sets the baseline; the gate
9429- /// asserts only four monotone points per ladder and that ffmpeg decodes9470+ /// asserts four monotone points per ladder, and at EVERY ladder point of
9430- /// our stream sample-exact against our reconstruction.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.)
9431 ///9479 ///
9432 /// Run:9480 /// Run:
9433 /// cargo test -p ec-av1 --release --lib -- --ignored \9481 /// cargo test -p ec-av1 --release --lib -- --ignored \
@@ -9509,10 +9557,10 @@ mod tests {
9509 let _ = crate::tile::take_compound_pair_hits();9557 let _ = crate::tile::take_compound_pair_hits();
9510 let _ = crate::motion::take_census();9558 let _ = crate::motion::take_census();
9511 let (ours, ours_wall) = match pyramid_from_env() {9559 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),
9513 Some(pyramid) => {9561 Some(pyramid) => {
9514 let (ladder, wall, counts, bytes) =9562 let (ladder, wall, counts, bytes) =
9515- our_ladder_pyramid(&source, width, height, pyramid);9563+ our_ladder_pyramid(name, &source, width, height, pyramid);
9516 eprintln!(9564 eprintln!(
9517 "{name}: pyramid {pyramid:?} -- frames key {} arf {} leaf {} \9565 "{name}: pyramid {pyramid:?} -- frames key {} arf {} leaf {} \
9518 show_existing {}; bytes key {} arf {} leaf {} show_existing {}",9566 show_existing {}; bytes key {} arf {} leaf {} show_existing {}",