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 commit1 changed file +63 -15
- crates/ec-av1/src/encode.rs +63 -15
crates/ec-av1/src/encode.rsmodified+63 -15
| @@ -9399,11 +9399,32 @@ mod tests { | ||
| 9399 | 9399 | (ladder, wall) |
| 9400 | 9400 | } |
| 9401 | 9401 | |
| 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 | + | |
| 9402 | 9418 | /// 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. | |
| 9406 | 9426 | fn our_ladder( |
| 9427 | + name: &str, | |
| 9407 | 9428 | source: &[Picture], |
| 9408 | 9429 | width: usize, |
| 9409 | 9430 | height: usize, |
| @@ -9416,13 +9437,27 @@ mod tests { | ||
| 9416 | 9437 | let encoded = encode_sequence_with_ctx(source, q, 0.5, fctx).unwrap(); |
| 9417 | 9438 | wall += start.elapsed().as_secs_f64(); |
| 9418 | 9439 | 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 | + ); | |
| 9419 | 9446 | 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 | + } | |
| 9426 | 9461 | } |
| 9427 | 9462 | let mean: f64 = decoded |
| 9428 | 9463 | .iter() |
| @@ -9459,6 +9494,7 @@ mod tests { | ||
| 9459 | 9494 | /// the ladder, the wall, and — per pyramid level over the whole ladder — |
| 9460 | 9495 | /// how many frames and how many bytes it spent. |
| 9461 | 9496 | fn our_ladder_pyramid( |
| 9497 | + name: &str, | |
| 9462 | 9498 | source: &[Picture], |
| 9463 | 9499 | width: usize, |
| 9464 | 9500 | height: usize, |
| @@ -9503,10 +9539,15 @@ mod tests { | ||
| 9503 | 9539 | // source picture, in the right order -- checked against our own |
| 9504 | 9540 | // decoder as well as ffmpeg's, both below. |
| 9505 | 9541 | 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"); | |
| 9507 | 9543 | let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len()); |
| 9508 | 9544 | 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 | + } | |
| 9510 | 9551 | } |
| 9511 | 9552 | let mean: f64 = decoded |
| 9512 | 9553 | .iter() |
| @@ -9705,8 +9746,15 @@ mod tests { | ||
| 9705 | 9746 | /// search's own cost, uncut: see the two intra-pruning variants measured |
| 9706 | 9747 | /// and rejected in the lane report). No |
| 9707 | 9748 | /// 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.) | |
| 9710 | 9758 | /// |
| 9711 | 9759 | /// Run: |
| 9712 | 9760 | /// cargo test -p ec-av1 --release --lib -- --ignored \ |
| @@ -9789,10 +9837,10 @@ mod tests { | ||
| 9789 | 9837 | let _ = crate::tile::take_compound_size_hits(); |
| 9790 | 9838 | let _ = crate::motion::take_census(); |
| 9791 | 9839 | 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), | |
| 9793 | 9841 | Some(pyramid) => { |
| 9794 | 9842 | let (ladder, wall, counts, bytes) = |
| 9795 | - our_ladder_pyramid(&source, width, height, pyramid); | |
| 9843 | + our_ladder_pyramid(name, &source, width, height, pyramid); | |
| 9796 | 9844 | eprintln!( |
| 9797 | 9845 | "{name}: pyramid {pyramid:?} -- frames key {} arf {} leaf {} \ |
| 9798 | 9846 | show_existing {}; bytes key {} arf {} leaf {} show_existing {}", |