//! Round-trip gate for `ec_h265::decode`: our own encoder's IDR stream, //! decoded back, must equal the encoder's own reconstruction byte-for-byte — //! and, separately, ffmpeg's decode of the same stream (the two-oracle rule). mod common; use ec_h265::decode::decode_idr_au; use ec_h265::encoder::{Encoder, EncoderConfig, RateControl}; fn roundtrip_at(width: u32, height: u32) { let frame = common::test_frame(width, height, 7); let cfg = EncoderConfig { rate_control: RateControl::ConstantQp(27), threads: 1, keep_recon: true, ..EncoderConfig::new(width, height) }; let enc = Encoder::new(cfg).expect("encoder config"); let picture = enc.encode_idr(&frame).expect("encode"); let recon = picture.recon.expect("keep_recon was on"); let decoded = decode_idr_au(&picture.au).unwrap_or_else(|e| { panic!("decode {width}x{height}: {e}"); }); let sps = enc.sps(); assert_eq!(decoded.width, sps.pic_width_in_luma_samples as usize); // Compare over the displayed region only: `recon` is cropped by the // conformance window, `decoded` is the full coded (padded) picture. let (w, h) = (width as usize, height as usize); let (cw, ch) = (w.div_ceil(2), h.div_ceil(2)); for row in 0..h { let want = recon.planes[0].row(row, w).unwrap(); let got = &decoded.y[row * decoded.width..row * decoded.width + w]; assert_eq!(got, want, "{width}x{height} luma row {row} diverges"); } for row in 0..ch { let want_cb = recon.planes[1].row(row, cw).unwrap(); let got_cb = &decoded.cb[row * decoded.width / 2..row * decoded.width / 2 + cw]; assert_eq!(got_cb, want_cb, "{width}x{height} Cb row {row} diverges"); let want_cr = recon.planes[2].row(row, cw).unwrap(); let got_cr = &decoded.cr[row * decoded.width / 2..row * decoded.width / 2 + cw]; assert_eq!(got_cr, want_cr, "{width}x{height} Cr row {row} diverges"); } } #[test] fn decode_matches_the_encoders_own_reconstruction_at_one_ctb() { roundtrip_at(32, 32); } #[test] fn decode_matches_the_encoders_own_reconstruction_over_several_ctbs() { roundtrip_at(96, 64); } #[test] fn decode_matches_the_encoders_own_reconstruction_at_an_odd_padded_size() { roundtrip_at(70, 50); } #[test] fn decode_matches_the_encoders_own_reconstruction_at_another_odd_size() { roundtrip_at(150, 94); } #[test] fn decode_matches_the_encoders_own_reconstruction_at_an_extreme_odd_size() { roundtrip_at(41, 33); }