diff --git a/crates/ec-av1/fixtures/ii-flake-1.obu b/crates/ec-av1/fixtures/ii-flake-1.obu new file mode 100644 index 0000000000000000000000000000000000000000..b796d23af1ab6dd41f818b8360e18c1c2ffb3d0b GIT binary patch literal 579 zcmWe);NoInU|?GRf9-n)4kJeahRqBLO&kha=Kl2gxa_!)f%u!h!5dtDJuR(X#i_VE z=7jU-$clxJqH3hY4zI48u`gnkRtn?vlPAAU2#TLm_+g2&5QCAR0rPpDKm^aVH-H5>Sa=2CD$fdh1q*U<2rh7d zX+M3&K#0Lez<@_U%%FpHHAMTV8(@We3Q`9yvMy(EWMOb&I4LF|#9$<3Ab4PYpcGg) zgA2n2&K-PUr9zDILCUO4A=;1mYk&nsn7AM5z|1_l4&)>O12GofB2(5?5S2$Az-CHt z2rjZ?T?r98xPbYJ5Q7oFfs}xlkvQvmi0EOkW*G&kLsG08AwoOtz{=#nR&Rlb?H6J& zk~UBTS?rn*5xVHSch{tyo6Z&AxXKQ4f|!Q*0oBhUO(z%>Sy+@9&KKvd{CsJ(m64!^ zFca%%6Q#2aiYzSZ40{p}7zr9EpWuGZ!McXQiG#zB;lhpsU{|OJh?aA(u7wE-F-S3< z07+C~lzO`QZW3vokNC&;|+DVWEjnQ(M+=S%@5treYKr+ z+L6VlZwi?RTY;aAWE9N`Kc=-s?cmkpWW?A9Rpf|$)OmD<6pVSvD>~@1sEm;@gT=58 z*2LZSE}1YkcUwK3i37TN(%`JeAzhJB%`JUqX65%%`BZgP?~CaTwILFZc@1mfn?)pS znna~|wq@W(jdW5Wi>w{9%DIG14`RA0Egex;3anB+f?dGklse8tJ&RnUx=nm}{ yy{QPRE~Knwbs&kCl8IC%)K%I^=2dc2pJ;5`f3AP$gIeW?BZ!T58_QxPIJFJU)R2$> literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/ii-flake-3.obu b/crates/ec-av1/fixtures/ii-flake-3.obu new file mode 100644 index 0000000000000000000000000000000000000000..729f887746e41584164d22747f54092b26ef3ae8 GIT binary patch literal 670 zcmWe);NoInU|?GRf9-n)4x%p} z?L4L@#%FkKNutG-O+Iz3;o64MOhzw#Z~X||YG?ZBd7)MNp_KG5$pw+Y1!ZU7XIRBu z>QDczSoQGs+K7V>Wt5J03G7tPFfb_X2U)Jf zaDkoY&Qz1kjq`bv!jgg=R%Yz06hDC=Onm82H87}NNU?iZy)X2c#&~z3i zWF%<7e1w7FBI_1L76Au8kRl-lDaIW_3`PP5Y#w|JjjWqtG9ZZ+APEgN57vl=ri)NR z78nT_a3yeUTnIO00Z8c!uo-+V(hDQu5)L4V8DQu0C35cMn)Q#VOQE5I;p~l@4<~L@ zSeD%994h7=qI`(8!AL-ZTZMBcXVbxkMI9jLI~WNV2r&v5JG0JWbOpKfJSZIa4MY^U zlAT#MK*c~7+yIM91c)zEW?c;tKL-|)Vv+hJ%(?|G1o5bfhIoSJY8jYY&b4TpFy4Fb z{7UGU1N&cox8LV(xcqf664DTI=v-~Xw2uMooHHNuUm5Xh2u$Ey?V@xFB6i-0-$0H- zSo{L(dWaQgK(6@#wpuAb?pO!Rm0)pDQ1WYtII-?FVYfG$wA9sJ9i%AUHJ-k$3nd>%pt#>T%G0szmk7N~9FH~M! zYED}^ge(zhSIOWaz111neEaKssT`}Qy=E$EnDaQwO3yZj#~KSuj!t9^%(gZ>+I|w4 zuBz`9g1)hScjC-;!EESf_58h!@&yc{SPFbZ-S=Y((^gP1SmDX$kNbySs~hSX~PZTxQSK-gt1su zWCTYtV}(LPFoC%mm(gJ_nd^(BV Y>{LTab(3rqROPs?qtTt9LJ8Xc0e}wBhX4Qo literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/ii-flake-6.obu b/crates/ec-av1/fixtures/ii-flake-6.obu new file mode 100644 index 0000000000000000000000000000000000000000..1cd806c7096d96b50002ab10da4ff7d98d0f3b64 GIT binary patch literal 632 zcmWe);NoInU|?GRf9-n)4x?-VhK&shEgA}2=AF{MG41)EW4lGP_q>pH$y~*JNaLnP zj;7>wyVrjn+8v!ooAxHtqCIIy-rL{HxXtK<<7Gw5KQ!@vkqc}j&5WT=n&h@q9^`528jwA z2p*UpD8)JpB6?x({FE(V7YH%R2Pv~ogeu;)0IXJoiTjZb>tu*shwpy31Q{V zG?W-F?qi?*vu~S`kcKc5>t_?DQy^h=hKsHm4~zs2luvL!=U`pU;N%hD$8cc>$aw+= zDgvVA9IRVlfZj3+=68lnQ6t2LNzFn~>1D`6yHpy4PSeu8x^ROtec(jQWlfwAgOQ*C^MM8i z2G?2!M-B%Uh6`L(LJUSi1}uy$3=FKZAcE%$a~i-(*_b#Q7+7aQM9)nL5@IkCHsE04 z6<}cPfe4;e(|rk1%f%tMz=3r>MEH#61tA6_0RtWZF@p})*$}}~Enxk83Q`9yvQB`A zop6g-djjkN!2|OHrC29IgfHx!5e7Cuh*3UBnRPKl^tb?6r3e%EBOTU>3=SPCE)2&H zwB~@_D#pTFWXjsh;Mk($!f^0t4_Lbdhu|VRkoFFc-~zCADFHDfan=P4jvY2G3`ZGj z9l+XU6r>JGv95=R?sQK8YnKDtz6Bz<`+yLGk&1yL$oA4bjBJXA0t^>l9rAeNvLfHx z<(qeRdWj(x*bu)t_SpNc$(jQJy@ literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/ii-flake-8.obu b/crates/ec-av1/fixtures/ii-flake-8.obu new file mode 100644 index 0000000000000000000000000000000000000000..bf08733e2f5cc8c2735b05b4ece78e69378bd671 GIT binary patch literal 635 zcmWe);NoInU|?GRf9-n)4x=0ahII@IEdmN#=3SUIGq-T{#hXUUikCz$Hojo~T)5(q zW3;ch>v>LAkE0tBivFm2E#TWMrhc+_^0c1r4YCEwHd}n8zZFLCFfF?f9J_V@*7g_5ehMq`Y*#@#p z*g){W{6HzzX$(#vV=wGou>|BaAp;>s`5}5)d;IXI;(U1QI+F09GiYAazKJbt6P< z=Z=M7g>qoqw?Irh1oFS6fg;H6(gTbf3JV1oF1|YSX8-Re|BHWFf+RJ>52$_?X*$xN z$fBaeaPde&$G!E&J*UHMj081=nOHxYC|v?csWa@B%rO!)P(H!^oP%{egA<2`AH#(m zAoB$bR0KrJIlvA93koqvF`fWPXow1MuGV0>$pAKBdxVjIfrg`S_zBicQ2h%)N`HXO S(D9IUD*(G2WQGGsq5}Zx#8(eZ~f`ayBN81_ss!i13<80b%|Q zLJUTt1{^HB0t}{a7�M3NWlNPmC`+4w4Wu;NlQm;J`W`qT!gk9LRJ*10De}gAUfk z5YZz^r@>136r>JZH0ywvaqyt;0uM0M3}fA>6qC-1SjQr&-P0-N-F8O339!Vffx&Kk*Qe%M0V$0 z#{*zd2@b(Uc4j#c(QT7nH-JT@1jLNQ&1xW`$B%RrfkkB$qz*}$Er5t_2;MXY>=Ze$ zQ!YS6*ItYgVlYxQPy{)JwUWV!$H9eRi>Ln&C^78i-YnX8ViI@iqQghITsx2L+-D@DAXbs zl^cu%4U|uCKj&aw$lxU6;Ky)b2goY|1}Xxg literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/rect-flake-1.obu b/crates/ec-av1/fixtures/rect-flake-1.obu new file mode 100644 index 0000000000000000000000000000000000000000..40a0e8f61f1e88997bfd91e40b28a338822e3fef GIT binary patch literal 607 zcmXxfQAiX~6b9h4Vg#1Q?-f4c#rGZf=w5o#zR#Fjd^1eL8CAS{O_Hz3%!ANMPgsIJyQF81*oD z*Q=${uu%HG8nyB8Q|nKOR}9mL7;N5(x>ndTg=&&=dk4yJdz|B_;|PnQI~=ne9){?8 zLw}~DK8{a(+Tb70avCMTG+OSRKK(TSU|}fk`W8**>zXdg1lT$=>Q*g=o#(dUXcaJh z@XXYFd8}d2mSdSQrkJXL7Hfo8wqa|VV8n45rtw_qCkfpL5Eq~@?EM>}mALGzg!)&E tfF8(sZkFNIeWoxAAf(`<%|g_))WbQH<-uMrxa2RW-W^M({(Hjn^gnodsnq}g literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/rect-flake-2.obu b/crates/ec-av1/fixtures/rect-flake-2.obu new file mode 100644 index 0000000000000000000000000000000000000000..e727407a96118cdd04cfc64b12f3abf7d8270530 GIT binary patch literal 601 zcmX}oO=uHA7zW@so1L(xNu8afNm#V5MrkNPhe3~)6jv!8N?V13Q1K*)_=DCeSYe|c zL_CNdJoSfy7Ohy*28@TmDk|GHY9dk;5v6Jc6^rEJMUEp{Iro@n<*&t)+^pYov$-F|90&04PV?+Fru*jYy5{t6R*UA~;qmAXg}5VBbO@<1I@qDk5k*v5r*(^1 z)SULoB03mM8xae|d*k)<`||z$-s7+=0LIk6=j))- zXPAVWqwef&>sj0QLUZ4`d(w7?OND{+LuW58j?Pat9Q=jQpRNx*dK3Q0tkwT^b!EPM zdU)i)iyM_pkwY@EDaZoH1_9GY)%vK-jF|w*Yg@hSYHKiP7Gzl4yRmK#X$xvLF_1gj zCQdB}95OB}Y8U+tTz<h!D0ISccqloS0#~Nh0hdhq#wWeKq`%Fah9MTbKz4m5Avz6^__pi)d z3O3gThfI2{!QL>Lt7KV@wqrG3TRGG(nU^p~xW9cx={|hDE^X0KZu~~cIMOD1QJqtl zGO>rX3{WzGw8<25II*%i!)sw%N}ll{YJDY{@Ol#G%4B*YSyahCx}x*M&f{0fjQYi1 JRDCtb{|Co5luZBt literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/warp-flake-5.obu b/crates/ec-av1/fixtures/warp-flake-5.obu new file mode 100644 index 0000000000000000000000000000000000000000..1ea57620a51a86018506edb8f42fc06e4d5185c0 GIT binary patch literal 602 zcmXw$Pe>F|9LIn2+?S6roj0>>*&y4Dh(4lXdX=Z3X;?@*j0qh(7kMxO z0I8ywcR?jr;5tJ|05`P~C=#7YbKPku0aWoEAVPhSGQd=F25{=^>1lx^ezrT2jL=vi ziD&98Bf?W+z#7N#)NtxO$Ytd*PMy7prv6Vj3!W@?Mf8{KpkCab#xvj%@S!a3qB#c9 z3R(Q3&P4XU0sJ7NSJj%1-h_9|mlD;!dyNSzk>QjzyLW3*RNq)BaLw5tiEWSI=i$aR z+1qLv3nO?o^j+K4)tol3sdx;}htX9Tjg#h^ol=4N0-4G;1Gvc!3>@BQORai6+u#tG;fNM^>6`Lja5qLm-SeC^dN<2^S0-!oF70FplA+JxO kb+CbSL6vI`>(TEl3n>73Hv9<9IWo|)dO?^8UJ+*L|C!jJ(*OVf literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/warp-flake-7.obu b/crates/ec-av1/fixtures/warp-flake-7.obu new file mode 100644 index 0000000000000000000000000000000000000000..d70ae41c5e2b8779743900ea20f998ba5350fd52 GIT binary patch literal 723 zcmY+AZAep59Ebn5-L~$`dv;TY)9j|{t|fRneJC{QDzi63XOUtdDOr}Gy^5BGw<*3v z(WIbgR$KMKMe4+*8IKqx>SFVuq5Ri{5!ks0HvaP-8f3YvbNvUal56Ycw7rIg2$N!w~~NX^9W@#2DC zvjc`N+UXMdo}c>8aI=qu@Cu&@V8)W@E_j*(zRw*CeHy#<8VTZM*8v2hSJcud3cLpl zwbqbsqQLF7Nkg4WN;0#WmnQjsGVhe3S<>0oe| zNDx-$1iY!I9RIf#Y5QYQ;;#?2+mKOfrl}YTjR|8Zk&2btWAQ<`4!4>ou*571Hv4;N~|5s`BA;LfX~pYrS#U-PqX?mk@|U*6t;Gg_)H z+ovi^Wo=0rZEnRtM=8N0)^W)wQ&eYjY$U{6Jc<)e#4>LXp?-}v*%je|( zbr$)BzjFPu^0y7=A(olXer+lfo9r!C9&+$>b?-cW*#-8}6Bxx0nW-^O@=urVy&|Mr zC2b$}bLsjow+{$07)fgIJaAxOU^>a5(4wHku*>zWa?D?W?H|n@j082<9yBm8G@WD+ zXi-pSxUl1Zk$?tsBLjm&(@6#fh>($>0rL?ChKsDL85lVn{6LC?7>ooASU3b2F0!tG z2?{YtG423Ma0KujXk=Z)pa@pI04&C(AbDXS>uRW&14!`-kc0+j6YGbPrb`S4V9OR5 z2^jEsa6gn}UBi$F(tf@{h{1^8K!8cK(2#WlR1Bp11Xx@oK=8s&*7Xqab6_Dc1u4To z)-7-$DaIK>3`Tky;tBl=`DQ(1I3%#3gJExHP{ZUC*9+sl>la-4oO+5uW<$u8;GpxV zCgCA^pB^U~31|qq@GsgRST`~x za@hDWoPmV^zkyr;U$GPG28INvxDmgBf`a5>C)SM+p%WmbH$cwS5Lv|ik(cR01K67L zM*IdUPU4T5Sl2?#g!ocTfbTOCI7DpxAbKI F1psz@w2}Y- literal 0 HcmV?d00001 diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index fda89ad7..e6662c1a 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5019,9 +5019,77 @@ pub(crate) mod tests { bytes } + /// The bit depth the stream's OWN sequence header declares, read from + /// the bytes rather than taken from the gate's name or recipe (class + /// `helper-packs-u16-for-an-8-bit-stream`: aomdec's `--rawvideo` + /// writes 8 bits per sample for an 8-bit stream and 16 bits LE for a + /// high-bitdepth one, so a u16 packer turns every 8-bit compare into a + /// raw-SIZE failure that never looks at a sample). + fn stream_bit_depth(stream: &[u8], name: &str) -> u8 { + let mut probe = Av1Parser::new(); + let mut pos = 0usize; + while pos < stream.len() && probe.sequence_header().is_none() { + let obu = probe + .parse_obu(&stream[pos..]) + .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}")); + pos += obu.total_size; + } + probe + .sequence_header() + .unwrap_or_else(|| panic!("{name}: the stream carries no sequence header OBU")) + .color_config + .bit_depth + } + + /// Packs decoded planes the way `aomdec --rawvideo` writes them for + /// `bit_depth`: 1 byte per sample at 8-bit, 2 bytes little-endian at + /// 10/12-bit. Plane order is Y, U, V at the frame's own subsampled + /// shape, which is exactly what rawvideo emits. + fn pack_rawvideo(decoded: &[Pic], bit_depth: u8, name: &str) -> Vec { + let mut ours: Vec = Vec::new(); + for (fi, f) in decoded.iter().enumerate() { + for p in [&f.y, &f.u, &f.v] { + if bit_depth == 8 { + for &s in p { + assert!( + s <= 0xff, + "{name}: decode-order frame {fi} carries the sample {s}, which an \ + 8-bit stream cannot hold -- the stream is not the one this gate thinks \ + it is" + ); + ours.push(s as u8); + } + } else { + for &s in p { + ours.extend_from_slice(&s.to_le_bytes()); + } + } + } + } + ours + } + /// Decodes `stream` and the oracle's `aomdec --rawvideo` output and /// requires every sample of every frame to agree, in decode order. - fn assert_rawvideo_matches(obu: &std::path::Path, stream: &[u8], name: &str, frames: usize) { + /// + /// `bit_depth` is the depth the CALLER believes the stream has; it is + /// asserted against the stream's own sequence header, so a gate that + /// hands this an 8-bit stream under a 10-bit label fails here by name + /// instead of dying on a raw-size mismatch that reads like a pixel bug. + fn assert_rawvideo_matches( + obu: &std::path::Path, + stream: &[u8], + name: &str, + frames: usize, + bit_depth: u8, + ) { + let actual_depth = stream_bit_depth(stream, name); + assert_eq!( + actual_depth, bit_depth, + "{name}: the stream's sequence header says {actual_depth}-bit, the gate passed \ + {bit_depth}-bit -- aomdec's --rawvideo writes {actual_depth} bits per sample for it, \ + so packing for {bit_depth} compares nothing" + ); let dir = std::env::temp_dir().join(format!("ec-av1-{name}-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).expect("scratch dir"); @@ -5043,15 +5111,20 @@ pub(crate) mod tests { let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); let _ = std::fs::remove_dir_all(&dir); let decoded = decode_stream(stream).expect("decode for comparison"); - let mut ours: Vec = Vec::with_capacity(ref_raw.len()); - for f in &decoded { - for p in [&f.y, &f.u, &f.v] { - for s in p { - ours.extend_from_slice(&s.to_le_bytes()); - } - } - } - assert_eq!(ours.len(), ref_raw.len(), "{name}: raw sizes differ"); + let ours = pack_rawvideo(&decoded, bit_depth, name); + assert_eq!( + ours.len(), + ref_raw.len(), + "{name}: {bit_depth}-bit raw sizes differ -- ours packs {} bytes ({} samples at \ + {} bit/sample), aomdec wrote {}", + ours.len(), + decoded + .iter() + .map(|f| f.y.len() + f.u.len() + f.v.len()) + .sum::(), + bit_depth, + ref_raw.len() + ); assert_eq!(decoded.len(), frames, "{name}: frame count"); let first = ours .iter() @@ -5067,6 +5140,115 @@ pub(crate) mod tests { ); } + /// lane-av1rawhelper: `assert_rawvideo_matches` used to pack our samples + /// as `u16` for EVERY stream, while `aomdec --rawvideo` writes 8 bits + /// per sample for an 8-bit stream. An 8-bit caller therefore died on a + /// raw-SIZE assertion (2359296 vs 1179648) without comparing a single + /// sample, and a high-bitdepth caller was the only one that could work. + /// + /// Two arms, both on a real `aomenc` 8-bit stream: + /// + /// 1. the correct label compares real samples -- the byte counts it + /// walks equal the oracle's, so every `u8` in the 8-bit pack is + /// zipped against a real oracle byte; + /// 2. a WRONG label fails by name, quoting both depths and the fact that + /// the pack would compare nothing, rather than by size. Arm 2 is what + /// keeps arm 1 from being a green that a reverted check would also + /// give. + #[test] + fn the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth() { + const NAME: &str = "the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth"; + let _gate_lock = lock_gate_counters(); + if !have_aomenc() || !have_ffmpeg() { + eprintln!("SKIP {NAME}: no aomenc/aomdec oracle or no ffmpeg"); + return; + } + let (w, h) = (192usize, 128usize); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &gradients_source(7, w, h, "duration=0.24:rate=25"), + "-pix_fmt", + "yuv420p", + "-t", + "0.24", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=40", + "--cpu-used=2", + "--threads=1", + "--row-mt=0", + "--limit=6", + "--obu", + "-o", + "-", + "-", + ]; + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); + assert!( + out.status.success(), + "{NAME}: aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + assert_eq!( + stream_bit_depth(&stream, NAME), + 8, + "{NAME}: the fixture must really be 8-bit, or this gate measures nothing" + ); + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-raw8-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let obu = dir.join("in.obu"); + std::fs::write(&obu, &stream).expect("writing the stream"); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the 8-bit stream no longer decodes: {e}")) + .len(); + assert!(frames > 0, "{NAME}: nothing decoded"); + + // ARM 2 first: the wrong label must be refused BY NAME. A helper that + // packed u16 unconditionally got this far and then failed on size. + let wrong = std::panic::catch_unwind(|| { + assert_rawvideo_matches(&obu, &stream, NAME, frames, 10); + }); + let boom = wrong + .err() + .map(|e| e.downcast_ref::().cloned().unwrap_or_default()) + .unwrap_or_default(); + assert!( + boom.contains("sequence header says 8-bit") && boom.contains("compares nothing"), + "{NAME}: a 10-bit label on an 8-bit stream must be refused by the depth check \ + naming both depths; the panic read: {boom}" + ); + + // ARM 1: the correct label compares real samples. The pre-fix helper + // reached a size mismatch here (ours 2x the oracle); reaching the + // sample compare is what this arm proves. + assert_rawvideo_matches(&obu, &stream, NAME, frames, 8); + let _ = std::fs::remove_dir_all(&dir); + eprintln!("{NAME}: {frames} 8-bit frame(s) byte-identical to aomdec --rawvideo"); + } + fn fnv1a64(bytes: &[u8]) -> u64 { let mut hash = 0xcbf29ce484222325u64; for &b in bytes { @@ -6886,7 +7068,7 @@ pub(crate) mod tests { let _ = decode_stream(&ctrl_stream) .unwrap_or_else(|e| panic!("{NAME}: the control arm no longer decodes cleanly: {e}")); if aomdec_path().is_file() { - assert_rawvideo_matches(&ctrl, &ctrl_stream, NAME, FRAMES); + assert_rawvideo_matches(&ctrl, &ctrl_stream, NAME, FRAMES, 10); } else { eprintln!( "SKIP {NAME} control aomdec arm: no oracle aomdec at {}", @@ -6980,7 +7162,7 @@ pub(crate) mod tests { assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); } if aomdec_path().is_file() { - assert_rawvideo_matches(&obu, &stream, NAME, FRAMES); + assert_rawvideo_matches(&obu, &stream, NAME, FRAMES, 10); } else { eprintln!( "SKIP {NAME} aomdec arm: no oracle aomdec at {}", @@ -23795,10 +23977,10 @@ pub(crate) mod tests { /// delta=2). `GOLDEN_FRAME` refuses by name until this decodes exact. /// /// LIVE since lane-av1pinslive r3. The old shape was the worst of the - /// class: a `concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/...")` - /// literal, which points at the GITIGNORED root and can therefore never be - /// satisfied by a committed pin, combined with a bare `.expect()`. The - /// bytes are now committed at + /// class: a `concat!` of `CARGO_MANIFEST_DIR` with the GITIGNORED + /// repo-root `fixtures/` directory, which no committed pin can satisfy, + /// combined with a bare `.expect()`. + /// The bytes are now committed at /// `crates/ec-av1/fixtures/golden7-forwarding-mismatch.obu` (152 bytes; /// sha256 `81b3bf657a85e95085287b30d97dee93ba5aea0ed1db1e1f4fcd19a06afc17be`, /// recovered byte-for-byte from the runner library). @@ -31197,59 +31379,67 @@ pub(crate) mod tests { /// clamping; ii-flake-1..8: interintra neighbours excluded from /// warp-sample gathering, ref_frame[1] == INTRA_FRAME in the mi grid). /// `EC_AV1_GATE_DUMP_PIN` overrides to a single stream. - /// Deterministic and static -- `#[ignore]`d because the gitignored - /// fixtures dir may be absent; run manually. + /// + /// Un-`#[ignore]`d with the pin shape fixed: the fourteen pins are COMMITTED + /// under `crates/ec-av1/fixtures/`, so the gate runs on a clean checkout + /// and carries `warp_selected_hits` 0 -> 113 over the set instead of + /// skipping GREEN having read nothing. #[test] - #[ignore = "reads pinned fixture paths under the gitignored fixtures dir; run manually"] fn pinned_warp_stream_decodes_pixel_exact() { if !have_ffmpeg() { eprintln!("SKIP pinned_warp_stream_decodes_pixel_exact: no ffmpeg"); return; } - let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures"); - let paths: Vec = match std::env::var("EC_AV1_GATE_DUMP_PIN") { - Ok(p) => vec![p], - Err(_) => [ - "warp-mismatch", - "warp-flake-5", - "warp-flake-7", - "ii-flake-1", - "ii-flake-2", - "ii-flake-3", - "ii-flake-5", - "ii-flake-6", - "ii-flake-7", - "ii-flake-8", + // Every pin is COMMITTED under `crates/ec-av1/fixtures/` and named by a + // string literal, which is the convention every other pinned gate here + // uses and the only shape the pin census can resolve name-by-name. The + // old shape -- one GITIGNORED root directory literal plus a runtime + // name list formatted against it -- can never be satisfied by a + // committed tree, so this gate skipped GREEN having tested nothing. + let pins = match std::env::var("EC_AV1_GATE_DUMP_PIN") { + Ok(p) => vec![std::path::PathBuf::from(p)], + Err(_) => vec![ + crate_pin("warp-mismatch.obu"), + crate_pin("warp-flake-5.obu"), + crate_pin("warp-flake-7.obu"), + crate_pin("ii-flake-1.obu"), + crate_pin("ii-flake-2.obu"), + crate_pin("ii-flake-3.obu"), + crate_pin("ii-flake-5.obu"), + crate_pin("ii-flake-6.obu"), + crate_pin("ii-flake-7.obu"), + crate_pin("ii-flake-8.obu"), // switchable_interp missing from reset_counts (counter // saturation slowed the adaptation rate) -- unrelated to // interintra, caught by the same gate. - "ii-flake-9", + crate_pin("ii-flake-9.obu"), // lane-rect r2: HORZ strip rect defects (mvstack size_h, // warp sample/projection dims, OBMC overlap, deblock tx-h). - "rect-flake-1", + crate_pin("rect-flake-1.obu"), // scan_row/scan_col weight `inc` min'd by the wrong candidate // axis (width vs height) -- ties reordered DRL entry 1 for a // block under a 32x16 strip, and suppressed the -5 extended // row scan. - "rect-flake-2", + crate_pin("rect-flake-2.obu"), // overlappable_left stepped the vertical walk by the // neighbour's WIDTH: a 32x16 left strip swallowed the strip // below it, blending the wrong OBMC prediction there. - "rect-flake-3", - ] - .iter() - .map(|n| format!("{fixtures}/{n}.obu")) - .collect(), + crate_pin("rect-flake-3.obu"), + ], }; - for path in paths { - eprintln!("pin: {path}"); + for path in pins { + eprintln!("pin: {}", path.display()); check_pinned_warp_stream(&path); } } - fn check_pinned_warp_stream(path: &str) { + fn check_pinned_warp_stream(path: &std::path::Path) { use crate::decode::warp_selected_hits; - let stream = std::fs::read(path).expect("reading pinned stream"); + let name = path + .file_name() + .map(|n| n.to_string_lossy().into_owned()) + .unwrap_or_default(); + let stream = require_pin(path, &name); let before = warp_selected_hits(); let frames = decode_stream(&stream).expect("pinned stream must decode"); eprintln!( diff --git a/lanes/av1rawhelper.report.md b/lanes/av1rawhelper.report.md new file mode 100644 index 00000000..af7c5728 --- /dev/null +++ b/lanes/av1rawhelper.report.md @@ -0,0 +1,305 @@ +# lane-av1rawhelper — `assert_rawvideo_matches` cannot judge an 8-bit stream + +**Branch:** `lane-av1rawhelper` +**Base:** `7f8817cbcbb567fd1c037c2d3780bdf12c0d2b14` ("Merge lane-av1pins @ 44a05b40 — three +recovered pins committed under the crate + gate rewiring"), taken at lane start while the +13-branch merge wave was landing in main. Worktree `~/.cache/wt/av1rawhelper`; main was never +touched. +**Scope:** tests + test helpers only. No decoder logic touched (`git diff --stat`: +`crates/ec-av1/src/stream.rs` only, and only its `#[cfg(test)]` module). + +## 1. Audit + +### 1a. `assert_rawvideo_matches` call sites + +Before this lane the helper had exactly **one** call site in the whole crate. It packed our +samples as `u16` unconditionally (`for s in p { ours.extend_from_slice(&s.to_le_bytes()) }`) +while `aomdec --rawvideo` writes 8 bits/sample for an 8-bit stream. + +| file:line | gate | stream bit depth (source) | helper packing matches? | outcome on a real run | +|---|---|---|---|---| +| `stream.rs:6877` (pre-fix) | `a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major` control arm | **10-bit**, from the gate's own recipe doc (`testsrc2 128x96 yuv444p10le`, `--profile=1 --lossless=1`) and from the fixture's parsed sequence header | YES — `u16` LE is what `--rawvideo` writes at 10-bit | PASS, a real compare: 6 frames byte-identical. Re-verified post-fix (see §3) | +| *(none — the defect was latent)* | any 8-bit gate | 8-bit | NO — `u16` pack vs 8-bit oracle | dies on `raw sizes differ` with no sample compared | + +There was no in-tree 8-bit caller. That is exactly why the defect survived: the single caller +happened to be high-bit-depth. The handing lane hit it the moment an 8-bit gate appeared. + +### 1b. Every other raw-comparison helper in the crate + +| helper | file:line | oracle | packing | 8-bit safe? | verdict | +|---|---|---|---|---|---| +| `decode_all_frames_vs_oracle` | `stream.rs:9217` | `EC_AV1_FINAL_DUMP` rung 12, both sides | **depth-aware on BOTH sides** — ours at `stream.rs:2142` (`if bit_depth == 8 { as u8 } else { to_le_bytes() }`), the oracle at `scripts/instrument-aom-oracle.sh` rung 12 (`YV12_FLAG_HIGHBITDEPTH` → `fwrite(...,2,...)` else `(...,1,...)`) | YES | correct as written; the depth is the frame's own `bit_depth`, not the gate's label | +| `ffmpeg_decode_sequence` | `stream.rs:5270` | `ffmpeg -pix_fmt yuv420p` | 8-bit by construction, size-asserted before unpacking | n/a (8-bit only) | correct | +| `ffmpeg_decode_gray_sequence` | `stream.rs:5322` | `ffmpeg -pix_fmt gray` | 8-bit, mono | n/a | correct | +| `ffmpeg_decode_sequence_10bit` | `stream.rs:5353` | `-pix_fmt yuv420p10le` | 2-byte LE, size-asserted | n/a | correct | +| `ffmpeg_decode_sequence_12bit` | `stream.rs:13211` | `-pix_fmt yuv420p12le` | 2-byte LE, size-asserted | n/a | correct | +| `dump_yuv` (example) | `examples/dump_yuv.rs:33` | none — a dump tool the user diffs by hand | `u16` LE, documented as the **high-bit-depth companion** to `EC_AV1_PREFILT_DUMP` | not a gate; its doc names `yuv420p10le` | left alone — not a gate, and its contract is explicitly HBD | +| `assert_rawvideo_matches` | `stream.rs:5012` (pre-fix) | `aomdec --rawvideo` | `u16` unconditional | **NO** | **the defect** | + +`decode_all_frames_vs_oracle` is the model the fix follows: it already derives the packing from +the decoded frame's own bit depth, and its oracle side is bit-depth correct in the instrument +script, so both sides agree at any depth. + +## 2. Fix + +Three changes, all in the `#[cfg(test)]` module of `crates/ec-av1/src/stream.rs`: + +1. **`stream_bit_depth(stream, name) -> u8`** (new, `stream.rs:5016`): parses the stream's own + sequence-header OBU and returns `color_config.bit_depth`. The depth comes from the bytes, not + from the gate's name or recipe. +2. **`pack_rawvideo(decoded, bit_depth, name)`** (new, `stream.rs:5036`): packs Y, U, V per + frame in the frame's own subsampled shape — 1 byte/sample at 8-bit, 2 bytes LE at 10/12-bit. + At 8-bit it hard-asserts every sample `<= 0xff` and names the frame, so a decode that + produced out-of-range samples is caught as "this is not an 8-bit stream", not as a pixel + diff. +3. **`assert_rawvideo_matches(..., bit_depth: u8)`** (`stream.rs:5067`): the label is now an + explicit argument, asserted against `stream_bit_depth` before anything else runs. A + mismatched label panics naming both depths and the consequence ("packing for 10 compares + nothing") instead of dying later on a raw-size mismatch. The size assertion now prints + `{bit_depth}-bit`, our byte count, the sample count, and the oracle's byte count, so a size + failure reads as a packing problem rather than a data bug. + +An 8-bit call now **works correctly** rather than being refused: the u8 path is the tightly +packed planes, which is what `aomdec --rawvideo` emits. The loud failure is reserved for the +genuinely-wrong case (a label that contradicts the header), and it names the depths. + +The one existing call site (`stream.rs:7056`) now passes `10`, which the new assert confirms +against the fixture's own header. + +## 3. Proof, both directions + +New gate: `the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth` +(`stream.rs:5144`). It builds a real `aomenc` 8-bit stream from an ffmpeg `gradients` source +(192x128, `--limit=6`, `--obu`), asserts the stream really is 8-bit from its parsed header, and +then runs **two** arms. + +**Green-after (8-bit, compares real samples):** +``` +the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth: + 6 8-bit frame(s) byte-identical to aomdec --rawvideo +test result: ok. 1 passed; 0 failed +``` + +**Wrong-label arm (must fail by name, not by size):** the same stream handed in with a +`10` label panics with +``` +the stream's sequence header says 8-bit, the gate passed 10-bit -- aomdec's --rawvideo +writes 8 bits per sample for it, so packing for 10 compares nothing +``` +caught by `catch_unwind` and asserted on its text. Without this arm the gate would be a green +that a reverted depth check would also give. + +**Red-before (fix reverted, both symptoms return):** I set `pack_rawvideo`'s depth branch to +`if false` and deleted the depth assert, rebuilt, and reran. The 8-bit gate fails exactly the +way the handing lane measured: +``` +10-bit raw sizes differ -- ours packs 442368 bytes (221184 samples at 10 bit/sample), +aomdec wrote 221184 + left: 442368 + right: 221184 +... +a 10-bit label on an 8-bit stream must be refused by the depth check naming both depths; +the panic read: ... raw sizes differ ... +test result: FAILED +``` +221184 vs 442368 is the same 2x raw-size class as the handing lane's 2359296 vs 1179648, at +this gate's smaller geometry. **Not one sample is compared on that path.** The fix was then +restored and both arms went green again. + +**Unchanged high-bit-depth gate:** the helper's only pre-existing caller, +`a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major`, passes post-fix +(`test result: ok. 1 passed`). Its control arm still runs the same 6-frame `u16` LE compare +against `aomdec --rawvideo` — the new label argument matches what the packing already did, so +the arm's substance is untouched. + +**Cross-check on the other helper:** `a_pinned_rect_stream_with_a_64x64_intra_block_in_an_inter_frame_decodes_pixel_exact` +(an 8-bit stream through `decode_all_frames_vs_oracle`) passes, confirming that helper's +depth-aware path is sound at 8-bit and is not part of the defect. + +## 4. False greens + +**None found, and the reason matters: the defect produced a hard failure, never a silent +pass.** The pre-fix helper asserted `ours.len() == ref_raw.len()` before comparing anything, +and a `u16` pack of an 8-bit stream is exactly 2x the oracle's size, so the assert always +fired. The 8-bit cell was a **loud, misleading failure**, not a vacuous green: the test +reported "raw sizes differ" and a reader would reasonably read that as a decoder or fixture +bug rather than as "this helper cannot judge this stream". No gate in the suite was reporting +a pass it had not earned through this helper. + +What *was* silently absent: any 8-bit coverage of `assert_rawvideo_matches` itself. The only +caller was 10-bit, so the helper's 8-bit path had never been exercised and no test asserted +anything about it. The new gate closes that, and its wrong-label arm is what makes the depth +check itself non-vacuous. + +Two adjacent traps checked and left alone, both outside this lane's scope (tests/helpers only, +and neither is a false green): + +- `dump_yuv` (`examples/dump_yuv.rs`) packs `u16` unconditionally, like the old helper. It is + a diagnostic dump tool, not a gate, and its docstring states it is the high-bit-depth + companion to `EC_AV1_PREFILT_DUMP` and names `yuv420p10le` as the reference. Handing an + 8-bit stream to it produces a dump that will not `cmp` against `yuv420p10le` — same trap, + but the contract is documented and nothing asserts on it. Flagging for a follow-up lane, not + fixing here. +- `ffmpeg_decode_sequence*` all hard-code their own pix_fmt and size-assert before unpacking, + so a depth mismatch is a loud failure there too. + +--- + +# r2 — rebase onto main and fix the stranded call site + +**Rework reason (Main, from an independent review):** the 4-arg → 5-arg signature change +stranded a call site this branch never saw. `git merge-tree` reported the merge CLEAN and the +merged tree then failed to compile with E0061. + +**The trap, stated once: a signature change must be validated by COMPILING the merged result, +not by `git merge-tree`'s conflict report.** `merge-tree` reasons about content overlap, not +about arity — a call site on lines the signature diff never touches is a non-conflict to it and +an E0061 to rustc. + +## 1. Rebase and the full call-site set + +Rebased `lane-av1rawhelper` onto current main `9b2f6c9ddb5c704e7649900c704b911e6822cd43` +(clean rebase, 1 commit replayed → `8bf6c4fe`). The call-site set was then re-established from +the CURRENT tree with `grep -rn "assert_rawvideo_matches(" crates/`, not from the branch's +pre-rebase view. + +| | count | sites (rebased tree) | +|---|---|---| +| before r2 | 2 real call sites, 1 of them 4-arg stranded | `stream.rs:7071` (updated), `stream.rs:7165` (**stranded**, 4-arg) | +| after r2 | 2 real call sites, both 5-arg | `stream.rs:7071`, `stream.rs:7165` | + +(The r1 gate contributes 2 more call sites of its own — `stream.rs:5232` and `:5247` — which +are the deliberate wrong-label and correct-label arms.) + +**Depth of the stranded site, from the bytes.** `stream.rs:7165` belongs to +`a_lossless_block_clips_its_transform_grid_at_the_frame_edge`, added by `7b9f46fa`, which the +r1 base `7f8817cb` predates. Its depth is **not** taken from the gate's doc prose, which says +"128x96 yuv444p 4:4:4 lossless" without naming a depth. It is read off the pin's own parsed +sequence header via the crate's own parser: + +``` +$ cargo run -p ec-av1 --example decode_probe -- fixtures/ll444_128root_lossless.obu +SEQ: use_128x128_superblock=true bit_depth=10 mono_chrome=false max_frame=128x96 +$ cargo run -p ec-av1 --example decode_probe -- fixtures/ll444_minp64_128root_control.obu +SEQ: use_128x128_superblock=true bit_depth=10 mono_chrome=false max_frame=128x96 +``` + +Both pins are genuinely 10-bit, so both sites take `10` — and the new in-helper assert +independently re-derives and confirms that at runtime, so a wrong label here could not pass +silently. + +## 2. Both gates green (tails) + +``` +$ cargo test -p ec-av1 --lib the_rawvideo_helper_compares_real_samples -- --nocapture +the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth: + 6 8-bit frame(s) byte-identical to aomdec --rawvideo +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 742 filtered out +``` + +``` +$ cargo test -p ec-av1 --lib a_lossless_block_clips_its_transform_grid_at_the_frame_edge -- --nocapture +running 1 test +test stream::tests::a_lossless_block_clips_its_transform_grid_at_the_frame_edge ... ok +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 742 filtered out +``` + +The second tail is the one that matters: `a_lossless_block_clips_its_transform_grid_at_the_frame_edge` +is the gate that owns the stranded site, so its green is the proof that the site the branch +never saw is now correct — and it is a real 6-frame `aomdec --rawvideo` compare at 10-bit, not +a compile-only pass. + +## 3. `cargo check -p ec-av1 --all-targets` + +**CLEAN.** No errors, no warnings: + +``` +$ touch crates/ec-av1/src/stream.rs && cargo check -p ec-av1 --all-targets + Checking ec-av1 v0.1.0 (/home/user/.cache/wt/av1rawhelper/crates/ec-av1) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 7.36s +``` + +(The `touch` is load-bearing: an earlier run reported `Finished in 0.01s` off a cached binary, +which is not evidence of anything.) + +## 4. The merged result itself, compiled + +Checking the branch alone is not the check — the defect only exists in the MERGED tree. So the +merge was materialised and compiled: + +``` +$ git merge-tree --write-tree main HEAD # tree 7125a2a3 +$ git commit-tree 7125a2a3 -p main -p HEAD -m "merge-sim" # 72954a27 +$ git worktree add --detach ~/.cache/wt/av1rawhelper-merge 72954a27 +$ cargo check -p ec-av1 --all-targets + Finished `dev` profile [unoptimized + debuginfo] target(s) in 7.81s +``` + +**The merged result compiles clean.** Its call sites are the ones the branch intended: + +``` +5079: fn assert_rawvideo_matches( +5232: assert_rawvideo_matches(&obu, &stream, NAME, frames, 10); +5247: assert_rawvideo_matches(&obu, &stream, NAME, frames, 8); +7071: assert_rawvideo_matches(&ctrl, &ctrl_stream, NAME, FRAMES, 10); +7165: assert_rawvideo_matches(&obu, &stream, NAME, FRAMES, 10); +``` + +### Red-before for the rework + +With `stream.rs:7165` reverted to its 4-arg form inside the merged tree, the merged result +fails at exactly the line and error the review reported: + +``` +error[E0061]: this function takes 5 arguments but 4 arguments were supplied + --> crates/ec-av1/src/stream.rs:7165:13 + | +7165 | assert_rawvideo_matches(&obu, &stream, NAME, FRAMES); + | ^^^^^^^^^^^^^^^^^^^^^^^------------------------ argument #5 of type `u8` is missing +error: could not compile `ec-av1` (lib test) due to 1 previous error +``` + +The line and the error match the review's finding, and `git merge-tree` had called this same +merge CLEAN. Restored to the 5-arg form it compiles clean again; the scratch merge worktree and +its target dir were removed. + +## 5. Process note + +Any lane that changes a function signature in this crate should, before reporting done: +establish the call-site set from the current tree, and then compile a materialised merge +(`git merge-tree --write-tree` + `git commit-tree` + worktree + `cargo check`) rather than +trusting the conflict report. Signature churn during a multi-lane merge wave is the exact +condition under which `merge-tree` is confidently wrong. + +## r2 second pass — main moved again mid-verification + +Main advanced 3 merges (`4532caa6` lane-av1pinslive, `bd588822` lane-av1leftwit, `1cc2f250` +lane-av1txsearch, landing as `8dd07ed7`) between the first r2 rebase and the end of it. Rebased +again onto `8dd07ed7` (3 commits replayed) and re-established the call-site set from the new +tip: **still exactly 2 real call sites** (`stream.rs:7071`, `stream.rs:7165`), both now 5-arg on +the branch, and main's own two sites (`:6889`, `:6983`) remain 4-arg for the merge to resolve. +Nothing new was stranded by the second wave. + +Re-verified on the rebased tip: +- `cargo check -p ec-av1 --all-targets` — clean, no warnings +- `the_rawvideo_helper_compares_real_samples_at_the_streams_own_bit_depth` — ok, 1 passed +- `a_lossless_block_clips_its_transform_grid_at_the_frame_edge` (owner of the stranded site) — + ok, 1 passed +- merged result materialised again against the new main + (`merge-tree` tree `e2bb41c8` → merge commit `f8c7eaec`) and compiled: + `Finished dev profile in 7.74s`, with all four call sites in the 5-arg form + +Final branch tip: `a5584e43` (report) over `f6d45be0` (stranded-site fix) over `970c72cf` +(the fix itself). Not pushed. + +### A second stale-binary trap, same family + +`cargo test` reported `0 passed ... 715 filtered out` for +`a_lossless_block_clips_its_transform_grid_at_the_frame_edge` even though the test existed in +the source at `stream.rs:7117` — a stale test binary from before the rebase, with 715 tests +instead of 747. `touch crates/ec-av1/src/stream.rs` before the run restored it. Two independent +`cargo test` invocations in this lane returned confident green-looking summaries +(`0 passed, 0 failed` and `Finished in 0.01s`) that were both **serving a stale binary**, so a +run that reports fewer tests than the previous run is evidence of nothing until the file is +touched. Same shape as the `merge-tree` lesson: a tool reporting a clean result is not the same +as the result being correct.