av1: monochrome luma byte-exact (salvage lane-av1-mono)
Browse files at this commit672ceb961e51f646f4dd4d20f05141b98964f079Parent: 13af7553 changed files +787 -106
- crates/ec-av1/src/decode.rs +69 -19
- crates/ec-av1/src/stream.rs +142 -0
- lanes/av1mono.report.md +576 -87
crates/ec-av1/src/decode.rsmodified+69 -19
| @@ -6805,6 +6805,39 @@ fn read_coeffs_rect( | |||
| 6805 | Ok((Grid::Own(grid), tx_type)) | 6805 | Ok((Grid::Own(grid), tx_type)) |
| 6806 | } | 6806 | } |
| 6807 | 6807 | ||
| 6808 | +/// [`read_coeffs_rect`] for a CHROMA plane, carrying the monochrome gate the | ||
| 6809 | +/// [`read_plane`] family already has. | ||
| 6810 | +/// | ||
| 6811 | +/// A monochrome frame has `NumPlanes == 1`, so libaom's coefficient loop | ||
| 6812 | +/// (`for (plane = 0; plane < av1_num_planes(cm); ++plane)`) never reaches a | ||
| 6813 | +/// chroma plane: no u/v coefficient symbol is coded, and consuming one moves | ||
| 6814 | +/// the arithmetic decoder off the stream for the rest of the tile. [`read_plane`] | ||
| 6815 | +/// enforces that for every strip that reads its chroma through it, but the rect | ||
| 6816 | +/// strip paths ([`decode_block_rect`], [`decode_leaf_rect`], | ||
| 6817 | +/// [`decode_block_rect4`], [`decode_rect4_16_strip`], [`decode_block_rect64`]) | ||
| 6818 | +/// call `read_coeffs_rect` on planes 1/2 DIRECTLY, so each of those sites takes | ||
| 6819 | +/// this gate instead (class `reader-gate-not-on-every-path`). One un-gated | ||
| 6820 | +/// chroma read desyncs at the FIRST rect leaf of the frame and every later | ||
| 6821 | +/// symbol -- and therefore every later pixel -- is decoded from the wrong | ||
| 6822 | +/// place, without ever tripping a refusal (the desynced values stay inside | ||
| 6823 | +/// every coded alphabet). | ||
| 6824 | +fn read_chroma_coeffs_rect( | ||
| 6825 | + dec: &mut SymbolDecoder, | ||
| 6826 | + coding: &mut TxbTables, | ||
| 6827 | + scan: &[u16], | ||
| 6828 | + w: usize, | ||
| 6829 | + h: usize, | ||
| 6830 | + skip_ctx: usize, | ||
| 6831 | + sign_ctx: usize, | ||
| 6832 | + default_tx_type: TxType, | ||
| 6833 | + fctx: &crate::decode::FrameCtx, | ||
| 6834 | +) -> Result<(Grid, TxType)> { | ||
| 6835 | + if mono(fctx) { | ||
| 6836 | + return Ok((Grid::Zero(w * h), TxType::DctDct)); | ||
| 6837 | + } | ||
| 6838 | + read_coeffs_rect(dec, coding, scan, w, h, skip_ctx, sign_ctx, default_tx_type) | ||
| 6839 | +} | ||
| 6840 | + | ||
| 6808 | /// What one coded block leaves behind for the blocks that read it as a | 6841 | /// What one coded block leaves behind for the blocks that read it as a |
| 6809 | /// neighbour: whether it coded anything at all, and the sign of its DC — | 6842 | /// neighbour: whether it coded anything at all, and the sign of its DC — |
| 6810 | /// [`crate::tile`]'s own private `Neighbour`. | 6843 | /// [`crate::tile`]'s own private `Neighbour`. |
| @@ -11106,7 +11139,7 @@ fn decode_block_rect( | |||
| 11106 | let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); | 11139 | let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 11107 | let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); | 11140 | let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); |
| 11108 | let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); | 11141 | let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); |
| 11109 | - let (u_levels, u_tx_type) = read_coeffs_rect( | 11142 | + let (u_levels, u_tx_type) = read_chroma_coeffs_rect( |
| 11110 | dec, | 11143 | dec, |
| 11111 | &mut u_coding, | 11144 | &mut u_coding, |
| 11112 | chroma_scan, | 11145 | chroma_scan, |
| @@ -11115,6 +11148,7 @@ fn decode_block_rect( | |||
| 11115 | u_skip_ctx, | 11148 | u_skip_ctx, |
| 11116 | dc_sign_ctx(around[1].2), | 11149 | dc_sign_ctx(around[1].2), |
| 11117 | u_default_tx, | 11150 | u_default_tx, |
| 11151 | + fctx, | ||
| 11118 | )?; | 11152 | )?; |
| 11119 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 11153 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 11120 | let (rng, _) = dec.debug_state(); | 11154 | let (rng, _) = dec.debug_state(); |
| @@ -11149,7 +11183,7 @@ fn decode_block_rect( | |||
| 11149 | let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); | 11183 | let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 11150 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); | 11184 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); |
| 11151 | let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); | 11185 | let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); |
| 11152 | - let (v_levels, v_tx_type) = read_coeffs_rect( | 11186 | + let (v_levels, v_tx_type) = read_chroma_coeffs_rect( |
| 11153 | dec, | 11187 | dec, |
| 11154 | &mut v_coding, | 11188 | &mut v_coding, |
| 11155 | chroma_scan, | 11189 | chroma_scan, |
| @@ -11158,6 +11192,7 @@ fn decode_block_rect( | |||
| 11158 | v_skip_ctx, | 11192 | v_skip_ctx, |
| 11159 | dc_sign_ctx(around[2].2), | 11193 | dc_sign_ctx(around[2].2), |
| 11160 | v_default_tx, | 11194 | v_default_tx, |
| 11195 | + fctx, | ||
| 11161 | )?; | 11196 | )?; |
| 11162 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 11197 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 11163 | let (rng, _) = dec.debug_state(); | 11198 | let (rng, _) = dec.debug_state(); |
| @@ -11488,9 +11523,9 @@ fn decode_leaf_rect( | |||
| 11488 | let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); | 11523 | let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 11489 | let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); | 11524 | let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); |
| 11490 | let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | 11525 | let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); |
| 11491 | - let (u_l, u_tx_type) = read_coeffs_rect( | 11526 | + let (u_l, u_tx_type) = read_chroma_coeffs_rect( |
| 11492 | dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx, | 11527 | dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx, |
| 11493 | - dc_sign_ctx(around[1].2), u_default_tx, | 11528 | + dc_sign_ctx(around[1].2), u_default_tx, fctx, |
| 11494 | )?; | 11529 | )?; |
| 11495 | u_levels = u_l; | 11530 | u_levels = u_l; |
| 11496 | let u_residual = dequant_and_inverse_typed_wh( | 11531 | let u_residual = dequant_and_inverse_typed_wh( |
| @@ -11507,9 +11542,9 @@ fn decode_leaf_rect( | |||
| 11507 | let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); | 11542 | let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 11508 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); | 11543 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); |
| 11509 | let mut v_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | 11544 | let mut v_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); |
| 11510 | - let (v_l, v_tx_type) = read_coeffs_rect( | 11545 | + let (v_l, v_tx_type) = read_chroma_coeffs_rect( |
| 11511 | dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx, | 11546 | dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx, |
| 11512 | - dc_sign_ctx(around[2].2), v_default_tx, | 11547 | + dc_sign_ctx(around[2].2), v_default_tx, fctx, |
| 11513 | )?; | 11548 | )?; |
| 11514 | v_levels = v_l; | 11549 | v_levels = v_l; |
| 11515 | let v_residual = dequant_and_inverse_typed_wh( | 11550 | let v_residual = dequant_and_inverse_typed_wh( |
| @@ -11838,7 +11873,7 @@ fn decode_block_rect4( | |||
| 11838 | let default_tx = default_intra_tx_type(uv_predict_mode as u8); | 11873 | let default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 11839 | let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); | 11874 | let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); |
| 11840 | let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode); | 11875 | let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode); |
| 11841 | - let (levels, tx_type) = read_coeffs_rect( | 11876 | + let (levels, tx_type) = read_chroma_coeffs_rect( |
| 11842 | dec, | 11877 | dec, |
| 11843 | &mut coding, | 11878 | &mut coding, |
| 11844 | chroma_scan, | 11879 | chroma_scan, |
| @@ -11847,6 +11882,7 @@ fn decode_block_rect4( | |||
| 11847 | skip_ctx, | 11882 | skip_ctx, |
| 11848 | dc_sign_ctx(around[plane].2), | 11883 | dc_sign_ctx(around[plane].2), |
| 11849 | default_tx, | 11884 | default_tx, |
| 11885 | + fctx, | ||
| 11850 | )?; | 11886 | )?; |
| 11851 | planes.push((levels, tx_type)); | 11887 | planes.push((levels, tx_type)); |
| 11852 | } | 11888 | } |
| @@ -12488,7 +12524,7 @@ fn decode_rect4_16_strip( | |||
| 12488 | let default_tx = default_intra_tx_type(uv_predict_mode as u8); | 12524 | let default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 12489 | let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); | 12525 | let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); |
| 12490 | let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | 12526 | let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); |
| 12491 | - let (levels, tx_type) = read_coeffs_rect( | 12527 | + let (levels, tx_type) = read_chroma_coeffs_rect( |
| 12492 | dec, | 12528 | dec, |
| 12493 | &mut coding, | 12529 | &mut coding, |
| 12494 | chroma_scan, | 12530 | chroma_scan, |
| @@ -12497,6 +12533,7 @@ fn decode_rect4_16_strip( | |||
| 12497 | skip_ctx, | 12533 | skip_ctx, |
| 12498 | dc_sign_ctx(around[plane].2), | 12534 | dc_sign_ctx(around[plane].2), |
| 12499 | default_tx, | 12535 | default_tx, |
| 12536 | + fctx, | ||
| 12500 | )?; | 12537 | )?; |
| 12501 | planes.push((levels, tx_type)); | 12538 | planes.push((levels, tx_type)); |
| 12502 | } | 12539 | } |
| @@ -13012,7 +13049,7 @@ fn decode_block_rect64( | |||
| 13012 | let (rng, _) = dec.debug_state(); | 13049 | let (rng, _) = dec.debug_state(); |
| 13013 | eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); | 13050 | eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); |
| 13014 | } | 13051 | } |
| 13015 | - let (u_levels, u_tx_type) = read_coeffs_rect( | 13052 | + let (u_levels, u_tx_type) = read_chroma_coeffs_rect( |
| 13016 | dec, | 13053 | dec, |
| 13017 | &mut u_coding, | 13054 | &mut u_coding, |
| 13018 | chroma_scan, | 13055 | chroma_scan, |
| @@ -13021,6 +13058,7 @@ fn decode_block_rect64( | |||
| 13021 | u_skip_ctx, | 13058 | u_skip_ctx, |
| 13022 | dc_sign_ctx(around[1].2), | 13059 | dc_sign_ctx(around[1].2), |
| 13023 | TxType::DctDct, | 13060 | TxType::DctDct, |
| 13061 | + fctx, | ||
| 13024 | )?; | 13062 | )?; |
| 13025 | if coeff_trace_on() { | 13063 | if coeff_trace_on() { |
| 13026 | let (rng, _) = dec.debug_state(); | 13064 | let (rng, _) = dec.debug_state(); |
| @@ -13076,7 +13114,7 @@ fn decode_block_rect64( | |||
| 13076 | let (rng, _) = dec.debug_state(); | 13114 | let (rng, _) = dec.debug_state(); |
| 13077 | eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); | 13115 | eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); |
| 13078 | } | 13116 | } |
| 13079 | - let (v_levels, v_tx_type) = read_coeffs_rect( | 13117 | + let (v_levels, v_tx_type) = read_chroma_coeffs_rect( |
| 13080 | dec, | 13118 | dec, |
| 13081 | &mut v_coding, | 13119 | &mut v_coding, |
| 13082 | chroma_scan, | 13120 | chroma_scan, |
| @@ -13085,6 +13123,7 @@ fn decode_block_rect64( | |||
| 13085 | v_skip_ctx, | 13123 | v_skip_ctx, |
| 13086 | dc_sign_ctx(around[2].2), | 13124 | dc_sign_ctx(around[2].2), |
| 13087 | TxType::DctDct, | 13125 | TxType::DctDct, |
| 13126 | + fctx, | ||
| 13088 | )?; | 13127 | )?; |
| 13089 | if coeff_trace_on() { | 13128 | if coeff_trace_on() { |
| 13090 | let (rng, _) = dec.debug_state(); | 13129 | let (rng, _) = dec.debug_state(); |
| @@ -31603,6 +31642,26 @@ fn decode_intra_sub8_leaf( | |||
| 31603 | h.set(s); | 31642 | h.set(s); |
| 31604 | }); | 31643 | }); |
| 31605 | } | 31644 | } |
| 31645 | + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map | ||
| 31646 | + // needs EVERY writer): a sub-8x8 group published no palette state, so | ||
| 31647 | + // once an 8x8 leaf of the same row can BE a palette block, the group | ||
| 31648 | + // left the row's band holding that earlier block's size and the next | ||
| 31649 | + // intra block read `av1_get_palette_mode_ctx` one too high (measured: | ||
| 31650 | + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers | ||
| 31651 | + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` | ||
| 31652 | + // needs `bsize >= BLOCK_8X8`), so the group always clears. | ||
| 31653 | + // | ||
| 31654 | + // lane-av1mono: this publish is NOT chroma work and must run BEFORE the | ||
| 31655 | + // `!has_chroma` return below. libaom's mi grid holds | ||
| 31656 | + // `palette_size[0] == 0` in every cell of such a group whatever the | ||
| 31657 | + // plane count, and on a monochrome frame EVERY sub-8 leaf passes | ||
| 31658 | + // `has_chroma == false`, so a publish placed after the return never ran | ||
| 31659 | + // at all: the band kept an earlier palette block's size, the next block | ||
| 31660 | + // read `palette_y_mode` off CDF row 1 where libaom reads row 0, decoded | ||
| 31661 | + // a palette libaom never coded, and the tile desynced one block later | ||
| 31662 | + // (measured: gray testsrc2 320x240, decode-order frame 33, mi(42,50), | ||
| 31663 | + // ours ctx 2 where libaom gathers 1). | ||
| 31664 | + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); | ||
| 31606 | if !has_chroma { | 31665 | if !has_chroma { |
| 31607 | return Ok(mode); | 31666 | return Ok(mode); |
| 31608 | } | 31667 | } |
| @@ -31621,15 +31680,6 @@ fn decode_intra_sub8_leaf( | |||
| 31621 | neighbours.above_uv_mode[c] = uv_predict_mode; | 31680 | neighbours.above_uv_mode[c] = uv_predict_mode; |
| 31622 | neighbours.left_uv_mode[r] = uv_predict_mode; | 31681 | neighbours.left_uv_mode[r] = uv_predict_mode; |
| 31623 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); | 31682 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); |
| 31624 | - // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map | ||
| 31625 | - // needs EVERY writer): a sub-8x8 group published no palette state, so | ||
| 31626 | - // once an 8x8 leaf of the same row can BE a palette block, the group | ||
| 31627 | - // left the row's band holding that earlier block's size and the next | ||
| 31628 | - // intra block read `av1_get_palette_mode_ctx` one too high (measured: | ||
| 31629 | - // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers | ||
| 31630 | - // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` | ||
| 31631 | - // needs `bsize >= BLOCK_8X8`), so the group always clears. | ||
| 31632 | - record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); | ||
| 31633 | 31683 | ||
| 31634 | let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); | 31684 | let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); |
| 31635 | let (u_grid, v_grid): (Grid, Grid) = if skip { | 31685 | let (u_grid, v_grid): (Grid, Grid) = if skip { |
crates/ec-av1/src/stream.rsmodified+142 -0
| @@ -2024,6 +2024,105 @@ pub(crate) mod tests { | |||
| 2024 | ); | 2024 | ); |
| 2025 | } | 2025 | } |
| 2026 | 2026 | ||
| 2027 | + /// lane-av1mono: the INVERSE of the pilot's | ||
| 2028 | + /// `a_real_libaom_monochrome_key_frame_is_refused_by_name`, which the | ||
| 2029 | + /// pilot's merge `d71084ae` landed on `main` (after this lane's base | ||
| 2030 | + /// `7f4e8301`): the very same recipe now decodes, and its luma is | ||
| 2031 | + /// byte-exact against ffmpeg's own decode of the same OBU. A merge of this | ||
| 2032 | + /// lane into `main` must therefore resolve that pinning gate by adopting | ||
| 2033 | + /// this witness in its place. | ||
| 2034 | + /// | ||
| 2035 | + /// `ffmpeg -pix_fmt gray -c:v libaom-av1` sets `color_config.mono_chrome`, | ||
| 2036 | + /// so libaom codes NO chroma symbol anywhere in the sequence -- not the | ||
| 2037 | + /// mode syntax, not a coefficient. That reaches all three classes this lane | ||
| 2038 | + /// had to close: chroma SYMBOL reads (`uv_mode`/cfl/angle/palette), chroma | ||
| 2039 | + /// COEFFICIENT reads on the rect-strip paths that call `read_coeffs_rect` | ||
| 2040 | + /// DIRECTLY instead of through `read_plane`'s own plane gate, and the | ||
| 2041 | + /// palette-mode neighbour band a mono sub-8x8 leaf must still clear before | ||
| 2042 | + /// it returns (an uncleared band made the next block read `palette_y_mode` | ||
| 2043 | + /// off the wrong CDF row and silently desynced the rest of the tile -- | ||
| 2044 | + /// measured at decode-order frame 33 of this very recipe). | ||
| 2045 | + /// | ||
| 2046 | + /// The 4:2:0 twin of the same source and settings is the control: it proves | ||
| 2047 | + /// the recipe is decodable, so a failure here is about the plane count and | ||
| 2048 | + /// not about the source or the encoder settings. | ||
| 2049 | + #[test] | ||
| 2050 | + fn a_real_libaom_monochrome_key_frame_decodes_pixel_exact() { | ||
| 2051 | + const NAME: &str = "a_real_libaom_monochrome_key_frame_decodes_pixel_exact"; | ||
| 2052 | + if !have_ffmpeg() { | ||
| 2053 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 2054 | + return; | ||
| 2055 | + } | ||
| 2056 | + let emit = |pix: &str| -> Vec<u8> { | ||
| 2057 | + let out = Command::new("ffmpeg") | ||
| 2058 | + .args([ | ||
| 2059 | + "-v", | ||
| 2060 | + "error", | ||
| 2061 | + "-f", | ||
| 2062 | + "lavfi", | ||
| 2063 | + "-i", | ||
| 2064 | + "testsrc2=size=320x240:rate=30:duration=2", | ||
| 2065 | + "-pix_fmt", | ||
| 2066 | + pix, | ||
| 2067 | + "-c:v", | ||
| 2068 | + "libaom-av1", | ||
| 2069 | + "-cpu-used", | ||
| 2070 | + "8", | ||
| 2071 | + "-b:v", | ||
| 2072 | + "300k", | ||
| 2073 | + "-f", | ||
| 2074 | + "obu", | ||
| 2075 | + "-", | ||
| 2076 | + ]) | ||
| 2077 | + .stdin(Stdio::null()) | ||
| 2078 | + .stdout(Stdio::piped()) | ||
| 2079 | + .stderr(Stdio::piped()) | ||
| 2080 | + .output() | ||
| 2081 | + .expect("ffmpeg failed to run"); | ||
| 2082 | + assert!( | ||
| 2083 | + out.status.success(), | ||
| 2084 | + "{NAME}: ffmpeg ({pix}) failed: {}", | ||
| 2085 | + String::from_utf8_lossy(&out.stderr) | ||
| 2086 | + ); | ||
| 2087 | + out.stdout | ||
| 2088 | + }; | ||
| 2089 | + // CONTROL: the identical recipe at 4:2:0 still decodes. | ||
| 2090 | + let twin = decode_stream(&emit("yuv420p")).expect("the 4:2:0 twin must decode"); | ||
| 2091 | + assert!(!twin.is_empty(), "{NAME}: the 4:2:0 twin decoded no frames"); | ||
| 2092 | + // THE WITNESS: the monochrome stream decodes and every luma sample | ||
| 2093 | + // equals ffmpeg's own decode of the same OBU. | ||
| 2094 | + let gray = emit("gray"); | ||
| 2095 | + let ours = decode_stream(&gray) | ||
| 2096 | + .unwrap_or_else(|e| panic!("{NAME}: the monochrome stream is REFUSED again: {e}")); | ||
| 2097 | + let (width, height) = (320usize, 240usize); | ||
| 2098 | + const FRAMES: usize = 60; | ||
| 2099 | + assert_eq!(ours.len(), FRAMES, "{NAME}: expected {FRAMES} mono frames"); | ||
| 2100 | + let reference = ffmpeg_decode_gray_sequence(&gray, width, height, FRAMES); | ||
| 2101 | + for (i, plane) in reference.chunks_exact(width * height).enumerate() { | ||
| 2102 | + assert_eq!(ours[i].width, width, "{NAME}: frame {i} width"); | ||
| 2103 | + assert_eq!(ours[i].height, height, "{NAME}: frame {i} height"); | ||
| 2104 | + assert_eq!( | ||
| 2105 | + ours[i].y.len(), | ||
| 2106 | + width * height, | ||
| 2107 | + "{NAME}: frame {i} luma length" | ||
| 2108 | + ); | ||
| 2109 | + for (j, (got, want)) in plane.iter().zip(ours[i].y.iter()).enumerate() { | ||
| 2110 | + assert_eq!( | ||
| 2111 | + *want, | ||
| 2112 | + u16::from(*got), | ||
| 2113 | + "{NAME}: frame {i} luma sample {j} (row {}, col {}) is {want}, ffmpeg says {got}", | ||
| 2114 | + j / width, | ||
| 2115 | + j % width | ||
| 2116 | + ); | ||
| 2117 | + } | ||
| 2118 | + } | ||
| 2119 | + eprintln!( | ||
| 2120 | + "{NAME}: 4:2:0 twin {} frames, monochrome {} frames byte-exact vs ffmpeg", | ||
| 2121 | + twin.len(), | ||
| 2122 | + ours.len() | ||
| 2123 | + ); | ||
| 2124 | + } | ||
| 2125 | + | ||
| 2027 | /// lane-t900 r25: the refusal "a frame OBU with no tile group" names a | 2126 | /// lane-t900 r25: the refusal "a frame OBU with no tile group" names a |
| 2028 | /// shape the parser cannot hand [`decode_stream`]. | 2127 | /// shape the parser cannot hand [`decode_stream`]. |
| 2029 | /// | 2128 | /// |
| @@ -3296,6 +3395,49 @@ pub(crate) mod tests { | |||
| 3296 | .collect() | 3395 | .collect() |
| 3297 | } | 3396 | } |
| 3298 | 3397 | ||
| 3398 | + /// As [`ffmpeg_decode_sequence`], for a MONOCHROME stream: one 8-bit luma | ||
| 3399 | + /// plane per frame, exactly what `ffmpeg -pix_fmt gray -f rawvideo` writes | ||
| 3400 | + /// (lane-av1mono). Fed down a stdin writer thread for the reason the 4:2:0 | ||
| 3401 | + /// helper documents. | ||
| 3402 | + fn ffmpeg_decode_gray_sequence( | ||
| 3403 | + stream: &[u8], | ||
| 3404 | + width: usize, | ||
| 3405 | + height: usize, | ||
| 3406 | + frames: usize, | ||
| 3407 | + ) -> Vec<u8> { | ||
| 3408 | + let mut child = Command::new("ffmpeg") | ||
| 3409 | + .args([ | ||
| 3410 | + "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-", | ||
| 3411 | + ]) | ||
| 3412 | + .stdin(Stdio::piped()) | ||
| 3413 | + .stdout(Stdio::piped()) | ||
| 3414 | + .stderr(Stdio::piped()) | ||
| 3415 | + .spawn() | ||
| 3416 | + .expect("ffmpeg failed to start"); | ||
| 3417 | + let mut stdin = child.stdin.take().expect("ffmpeg stdin"); | ||
| 3418 | + let payload = stream.to_vec(); | ||
| 3419 | + let writer = std::thread::Builder::new() | ||
| 3420 | + .name("ec-av1-ffmpeg-gray-in".into()) | ||
| 3421 | + .spawn(move || { | ||
| 3422 | + let _ = stdin.write_all(&payload); | ||
| 3423 | + }) | ||
| 3424 | + .expect("spawning the ffmpeg stdin writer"); | ||
| 3425 | + let out = child.wait_with_output().expect("ffmpeg failed to run"); | ||
| 3426 | + writer.join().expect("ffmpeg stdin writer thread"); | ||
| 3427 | + assert!( | ||
| 3428 | + out.status.success(), | ||
| 3429 | + "ffmpeg refused the monochrome stream: {}", | ||
| 3430 | + String::from_utf8_lossy(&out.stderr) | ||
| 3431 | + ); | ||
| 3432 | + assert_eq!( | ||
| 3433 | + out.stdout.len(), | ||
| 3434 | + width * height * frames, | ||
| 3435 | + "expected {frames} monochrome frames, ffmpeg said: {}", | ||
| 3436 | + String::from_utf8_lossy(&out.stderr) | ||
| 3437 | + ); | ||
| 3438 | + out.stdout | ||
| 3439 | + } | ||
| 3440 | + | ||
| 3299 | /// As [`ffmpeg_decode_sequence`], but for a `yuv420p10le` stream: samples | 3441 | /// As [`ffmpeg_decode_sequence`], but for a `yuv420p10le` stream: samples |
| 3300 | /// are 2-byte little-endian, one full 16-bit range regardless of the | 3442 | /// are 2-byte little-endian, one full 16-bit range regardless of the |
| 3301 | /// stream's real 10-bit depth (ffmpeg's rawvideo muxer never packs to the | 3443 | /// stream's real 10-bit depth (ffmpeg's rawvideo muxer never packs to the |
lanes/av1mono.report.mdmodified+576 -87
| @@ -1,104 +1,593 @@ | |||
| 1 | -# lane-av1-mono (WIP) — monochrome AV1 key-frame decompiles; luma not yet byte-exact | 1 | +# lane-av1-mono — monochrome AV1 decode is luma byte-exact (60f kf, 120f inter, mono.ivf) |
| 2 | 2 | ||
| 3 | -Base: `main` **f0727a87** (2026-09-19). Worktree `edith_codecs-av1mono`, branch | 3 | +Base: `main` **7f4e8301** (the WIP `av1: WIP monochrome plane model` commit; its |
| 4 | -`lane-av1-mono`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1mono` (private). | 4 | +parent is `f0727a87`). Worktree `edith_codecs-av1mono`, branch `lane-av1-mono`, |
| 5 | -No push. Status: **INCOMPLETE** — entropy now syncs through a real monochrome | 5 | +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1mono` (private). No push. |
| 6 | -key frame (the pilot's first-wall refusal is gone), but the reconstructed luma is | 6 | +Status: **COMPLETE** — a monochrome AV1 stream decodes and its luma is byte-exact |
| 7 | -NOT yet byte-exact against ffmpeg; a small block region diverges. | 7 | +against ffmpeg's own decode, on all three witnesses. The luma half of the pilot's |
| 8 | +first real-stream wall (§3.1 of `lanes/av1decode.report.md`) is closed. | ||
| 8 | 9 | ||
| 9 | ## TL;DR | 10 | ## TL;DR |
| 10 | 11 | ||
| 11 | -The pilot (`lanes/av1decode.report.md`, branch `lane-av1-decode`) root-caused the | 12 | +The previous continuation (Yunus) died mid-flight on a provider outage, leaving a |
| 12 | -first monochrome stop to libaom `decodemv.c:933`'s | 13 | +working tree that *was* the fix but was buried under **24,000+ lines of omp |
| 13 | -`!monochrome && is_chroma_ref` guard on the chroma mode symbols. This lane ports | 14 | +edit-tool rustfmt churn** (`git diff --stat` read 17300/6908 changed lines). This |
| 14 | -the monochrome plane model into ec-av1: | 15 | +session (1) salvaged a **semantic-only 19-hunk diff** out of that churn, (2) |
| 15 | - | 16 | +verified it fixes the luma defect, (3) proved the three witnesses, the corpus, the |
| 16 | -- new `FrameCtx::mono_chrome` (from the sequence header's `color_config.mono_chrome`), | 17 | +film windows and the suite. |
| 17 | -- every chroma **symbol** read gated (uv_mode/cfl/angle_uv/palette_uv), | 18 | + |
| 18 | -- every chroma **coefficient** read gated (`read_plane`/`read_inter_plane`/ | 19 | +- **Salvage:** churn → `decode.rs` 88 lines, `stream.rs` 142 lines (211 insertions, |
| 19 | - `read_inter_plane_rect`/`decode_rect_split`'s un-split `read_coeffs_rect`), | 20 | + 19 deletions). Method and proof below. |
| 20 | -- the probe writes a single luma plane for a mono sequence. | 21 | +- **Root cause of the luma mismatch:** a **palette-mode neighbour band** that a |
| 21 | - | 22 | + mono sub-8x8 leaf left uncleared. The publish (`record_strip_palette`) sat |
| 22 | -**Result: the gray/key-frame refusal `a Golomb tail longer than this decoder | 23 | + *after* the `if !has_chroma { return }` early-out; on a monochrome frame EVERY |
| 23 | -reads` is GONE — `decode_probe` now returns `OK: 60 frames decoded` for both the | 24 | + sub-8 leaf takes that early-out, so the band kept an earlier palette block's |
| 24 | -pilot's gray recipe and `fixtures/bitstreams/av1-monochrome.ivf`.** The 4:2:0 | 25 | + size, the next block read `palette_y_mode` off CDF row 1 where libaom reads row |
| 25 | -twin still decodes 60/60. | 26 | + 0, and the tile silently desynced one block later. (Symptom had been read as a |
| 26 | - | 27 | + reconstruction defect; it is an entropy desync.) |
| 27 | -**Remaining defect:** the decoded luma is NOT byte-exact. First divergence on the | 28 | +- **Second class closed:** the rect-strip paths call `read_coeffs_rect` on planes |
| 28 | -pilot's gray stream is frame 0, row 0, column 37 (off-by-one), and a small | 29 | + 1/2 **directly** (bypassing `read_plane`'s own mono gate), so a mono frame |
| 29 | -~6×2-pixel block region at row 1, cols 36-42 decodes wrong (probe 20/19 vs ref | 30 | + consumed a chroma coefficient symbol libaom never coded. New |
| 30 | -76). Because entropy stays in sync (all 60 frames decode, no refusal) this is a | 31 | + `read_chroma_coeffs_rect` gates those 8 call sites. |
| 31 | -**luma reconstruction/prediction** defect, not an entropy desync — most likely a | 32 | + |
| 32 | -block whose intra prediction reads a neighbour state that the mono path no longer | 33 | +## Salvage (what the dirty tree contained, what was kept/reverted) |
| 33 | -updates, or a residual/palette interaction on a chroma-adjacent block. This needs | 34 | + |
| 34 | -one more round. | 35 | +`git status` at handover: `M crates/ec-av1/src/decode.rs`, `M crates/ec-av1/src/stream.rs`. |
| 35 | - | 36 | + |
| 36 | -## Changes (uncommitted→committed on `lane-av1-mono`) | 37 | +1. **Hunk classifier first** (`rustfmt-semantic-only-diff` recipe): a hunk is |
| 37 | - | 38 | + fmt-only iff its removed/added lines are equal after JOINING + stripping |
| 38 | -`crates/ec-av1/src/decode.rs` | 39 | + whitespace + folding trailing commas. Result: 677 hunks decode (609 fmt-only), |
| 39 | -- `FrameCtx::mono_chrome: Cell<bool>` + `mono(fctx)` / `set_mono(...)` helpers; | 40 | + 426 hunks stream (406 fmt-only) — *but this classifier is incomplete here*: |
| 40 | - copied in `filter_ctx_copy`. | 41 | + the local rustfmt **wraps `ok_or_else(|| expr)` closure bodies in `{ ... }`**, |
| 41 | -- `read_intra_mode_rect`: `has_chroma &= !mono` (gates uv_mode/cfl/angle_uv/palette_uv). | 42 | + so 40+ pure reflow hunks were flagged "semantic" (a brace pair my normalizer |
| 42 | -- `read_intra_mode` (square), `decode_intra_rect_in_inter`, `decode_inter_block` | 43 | + cannot fold away). Trusting it would have kept thousands of churn lines. |
| 43 | - intra-in-inter, `decode_inter_block8` intra-in-inter: explicit mono branch on | 44 | +2. **Decisive method instead:** rustfmt the *committed* file and diff it against |
| 44 | - the chroma mode read + palette_uv gate. | 45 | + the working tree. `rustfmt --edition 2024 <7f4e8301 file>` ≈ the working tree: |
| 45 | -- `read_intra_mode_sub8`, `decode_intra_sub8_leaf`: `has_chroma &= !mono`. | 46 | + decode.rs 43620 vs 43672 lines (52-line residual), stream.rs 38666 vs 38805 |
| 46 | -- `read_plane`, `read_inter_plane`, `read_inter_plane_rect`: early-return | 47 | + (139-line residual). So the working tree **was** `rustfmt(HEAD) + a small |
| 47 | - `Grid::Zero` for `plane_idx > 0 && mono` (no coefficient symbol consumed). | 48 | + semantic delta` — the previous agent had not left a half-applied edit. |
| 48 | -- `decode_rect_split`: whole chroma section bypassed for mono (its un-split path | 49 | +3. Extract `S = diff(rustfmt(7f4e8301), W)` (19 + 2 hunks), apply `S` to the |
| 49 | - read chroma through `read_coeffs_rect` directly, NOT through `read_plane`, so | 50 | + committed file, and prove correctness mechanically: **`rustfmt(HEAD + S) == W` |
| 50 | - the reader gate did not cover it — this was a real desync source). | 51 | + byte-for-byte** on both files. Whitespace-only home for every non-semantic line |
| 51 | -- `decode_leaf_rect8` / `decode_leaf_split4`: chroma reconstruction tail | 52 | + is then guaranteed: applying only `S` to `HEAD` cannot carry churn. |
| 52 | - bypassed for mono (the `last_uv.expect("…has_chroma…")` panics otherwise). | 53 | +4. The `patch` of `S` onto `HEAD` needed fuzz at 5 of the 8 call sites and put |
| 53 | - | 54 | + `fctx,`/`let (` at the wrong indent there; fixed by hand (indentation is |
| 54 | -`crates/ec-av1/src/stream.rs` | 55 | + HEAD-style; the diff now shows ONLY identifier renames, `fctx` args, the new |
| 55 | -- `SeqFlags::mono_chrome` from `sequence_header().color_config.mono_chrome`; | 56 | + fn, the palette move, and the test). |
| 56 | - `set_mono(...)` called per frame in `decode_frame` (like `set_bit_depth`). | 57 | +5. **Coherence:** the semantic set is coherent — no orphaned variable, no broken |
| 57 | - | 58 | + syntax, one self-contained feature (`read_chroma_coeffs_rect` + the palette |
| 58 | -`crates/ec-av1/examples/decode_probe.rs` | 59 | + move). Nothing had to be reverted. |
| 59 | -- prints `mono_chrome` in the `SEQ:` line; writes only the luma plane when the | 60 | + |
| 60 | - sequence is monochrome (so the raw dump is what `ffmpeg -pix_fmt gray -f | 61 | +## Root cause |
| 61 | - rawvideo` writes). | 62 | + |
| 63 | +`decode_intra_sub8_leaf` (`decode.rs`). libaom's MI grid writes | ||
| 64 | +`palette_size[0] == 0` for **every** cell of a sub-8x8 group whatever the plane | ||
| 65 | +count (`av1_allow_palette` needs `bsize >= BLOCK_8X8`, so no sub-8 piece is ever | ||
| 66 | +a palette block). ec-av1 did publish that clear — but only on the **chroma-reference** | ||
| 67 | +path, after `if !has_chroma { return Ok(mode) }`. On a mono frame | ||
| 68 | +`has_chroma == false` for every sub-8 leaf (`NumPlanes == 1`), so the publish | ||
| 69 | +never ran: the row's band kept an earlier palette block's size, the next intra | ||
| 70 | +block read `av1_get_palette_mode_ctx` one too high, decoded a `palette_y_mode` | ||
| 71 | +symbol libaom never coded, and the tile desynced. | ||
| 72 | + | ||
| 73 | +Measured: gray testsrc2 320x240, **decode-order frame 33**, mi(42,50) — ours ctx 2 | ||
| 74 | +where libaom gathers 1. (First *pixel* divergence on the 60-frame stream lands at | ||
| 75 | +frame 0, because the key frame's own early blocks already carry the mismatch.) | ||
| 76 | + | ||
| 77 | +## Fix | ||
| 78 | + | ||
| 79 | +- `crates/ec-av1/src/decode.rs` | ||
| 80 | + - **`record_strip_palette(...)` moved BEFORE the `!has_chroma` return** in | ||
| 81 | + `decode_intra_sub8_leaf` — unconditional, matching libaom's MI grid, with the | ||
| 82 | + extended comment. (This is the luma fix.) | ||
| 83 | + - New **`read_chroma_coeffs_rect`**: a mono early-return of `Grid::Zero` + | ||
| 84 | + `TxType::DctDct` before delegating to `read_coeffs_rect`; applied at the 8 | ||
| 85 | + chroma call sites that read planes 1/2 directly | ||
| 86 | + (`decode_block_rect`, `decode_leaf_rect`, `decode_block_rect4`, | ||
| 87 | + `decode_rect4_16_strip`, `decode_block_rect64`). Closes the | ||
| 88 | + `reader-gate-not-on-every-path` class. | ||
| 89 | +- `crates/ec-av1/src/stream.rs` | ||
| 90 | + - New witness test **`a_real_libaom_monochrome_key_frame_decodes_pixel_exact`** | ||
| 91 | + (the inverted form of the pilot's pinning gate) + `ffmpeg_decode_gray_sequence` | ||
| 92 | + helper. | ||
| 93 | + | ||
| 94 | +## Semantic-only diff vs 7f4e8301 | ||
| 95 | + | ||
| 96 | +```diff | ||
| 97 | +diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs | ||
| 98 | +index 6399854a..75cd8aad 100644 | ||
| 99 | +--- a/crates/ec-av1/src/decode.rs | ||
| 100 | ++++ b/crates/ec-av1/src/decode.rs | ||
| 101 | +@@ -6805,6 +6805,39 @@ fn read_coeffs_rect( | ||
| 102 | + Ok((Grid::Own(grid), tx_type)) | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | ++/// [`read_coeffs_rect`] for a CHROMA plane, carrying the monochrome gate the | ||
| 106 | ++/// [`read_plane`] family already has. | ||
| 107 | ++/// | ||
| 108 | ++/// A monochrome frame has `NumPlanes == 1`, so libaom's coefficient loop | ||
| 109 | ++/// (`for (plane = 0; plane < av1_num_planes(cm); ++plane)`) never reaches a | ||
| 110 | ++/// chroma plane: no u/v coefficient symbol is coded, and consuming one moves | ||
| 111 | ++/// the arithmetic decoder off the stream for the rest of the tile. [`read_plane`] | ||
| 112 | ++/// enforces that for every strip that reads its chroma through it, but the rect | ||
| 113 | ++/// strip paths ([`decode_block_rect`], [`decode_leaf_rect`], | ||
| 114 | ++/// [`decode_block_rect4`], [`decode_rect4_16_strip`], [`decode_block_rect64`]) | ||
| 115 | ++/// call `read_coeffs_rect` on planes 1/2 DIRECTLY, so each of those sites takes | ||
| 116 | ++/// this gate instead (class `reader-gate-not-on-every-path`). One un-gated | ||
| 117 | ++/// chroma read desyncs at the FIRST rect leaf of the frame and every later | ||
| 118 | ++/// symbol -- and therefore every later pixel -- is decoded from the wrong | ||
| 119 | ++/// place, without ever tripping a refusal (the desynced values stay inside | ||
| 120 | ++/// every coded alphabet). | ||
| 121 | ++fn read_chroma_coeffs_rect( | ||
| 122 | ++ dec: &mut SymbolDecoder, | ||
| 123 | ++ coding: &mut TxbTables, | ||
| 124 | ++ scan: &[u16], | ||
| 125 | ++ w: usize, | ||
| 126 | ++ h: usize, | ||
| 127 | ++ skip_ctx: usize, | ||
| 128 | ++ sign_ctx: usize, | ||
| 129 | ++ default_tx_type: TxType, | ||
| 130 | ++ fctx: &crate::decode::FrameCtx, | ||
| 131 | ++) -> Result<(Grid, TxType)> { | ||
| 132 | ++ if mono(fctx) { | ||
| 133 | ++ return Ok((Grid::Zero(w * h), TxType::DctDct)); | ||
| 134 | ++ } | ||
| 135 | ++ read_coeffs_rect(dec, coding, scan, w, h, skip_ctx, sign_ctx, default_tx_type) | ||
| 136 | ++} | ||
| 137 | ++ | ||
| 138 | + /// What one coded block leaves behind for the blocks that read it as a | ||
| 139 | + /// neighbour: whether it coded anything at all, and the sign of its DC — | ||
| 140 | + /// [`crate::tile`]'s own private `Neighbour`. | ||
| 141 | +@@ -11106,7 +11139,7 @@ fn decode_block_rect( | ||
| 142 | + let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 143 | + let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); | ||
| 144 | + let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); | ||
| 145 | +- let (u_levels, u_tx_type) = read_coeffs_rect( | ||
| 146 | ++ let (u_levels, u_tx_type) = read_chroma_coeffs_rect( | ||
| 147 | + dec, | ||
| 148 | + &mut u_coding, | ||
| 149 | + chroma_scan, | ||
| 150 | +@@ -11115,6 +11148,7 @@ fn decode_block_rect( | ||
| 151 | + u_skip_ctx, | ||
| 152 | + dc_sign_ctx(around[1].2), | ||
| 153 | + u_default_tx, | ||
| 154 | ++ fctx, | ||
| 155 | + )?; | ||
| 156 | + if crate::envflags::env_flag!("EC_AV1_TRACE") { | ||
| 157 | + let (rng, _) = dec.debug_state(); | ||
| 158 | +@@ -11149,7 +11183,7 @@ fn decode_block_rect( | ||
| 159 | + let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 160 | + let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); | ||
| 161 | + let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); | ||
| 162 | +- let (v_levels, v_tx_type) = read_coeffs_rect( | ||
| 163 | ++ let (v_levels, v_tx_type) = read_chroma_coeffs_rect( | ||
| 164 | + dec, | ||
| 165 | + &mut v_coding, | ||
| 166 | + chroma_scan, | ||
| 167 | +@@ -11158,6 +11192,7 @@ fn decode_block_rect( | ||
| 168 | + v_skip_ctx, | ||
| 169 | + dc_sign_ctx(around[2].2), | ||
| 170 | + v_default_tx, | ||
| 171 | ++ fctx, | ||
| 172 | + )?; | ||
| 173 | + if crate::envflags::env_flag!("EC_AV1_TRACE") { | ||
| 174 | + let (rng, _) = dec.debug_state(); | ||
| 175 | +@@ -11488,9 +11523,9 @@ fn decode_leaf_rect( | ||
| 176 | + let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 177 | + let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); | ||
| 178 | + let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | ||
| 179 | +- let (u_l, u_tx_type) = read_coeffs_rect( | ||
| 180 | ++ let (u_l, u_tx_type) = read_chroma_coeffs_rect( | ||
| 181 | + dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx, | ||
| 182 | +- dc_sign_ctx(around[1].2), u_default_tx, | ||
| 183 | ++ dc_sign_ctx(around[1].2), u_default_tx, fctx, | ||
| 184 | + )?; | ||
| 185 | + u_levels = u_l; | ||
| 186 | + let u_residual = dequant_and_inverse_typed_wh( | ||
| 187 | +@@ -11507,9 +11542,9 @@ fn decode_leaf_rect( | ||
| 188 | + let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 189 | + let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); | ||
| 190 | + let mut v_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | ||
| 191 | +- let (v_l, v_tx_type) = read_coeffs_rect( | ||
| 192 | ++ let (v_l, v_tx_type) = read_chroma_coeffs_rect( | ||
| 193 | + dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx, | ||
| 194 | +- dc_sign_ctx(around[2].2), v_default_tx, | ||
| 195 | ++ dc_sign_ctx(around[2].2), v_default_tx, fctx, | ||
| 196 | + )?; | ||
| 197 | + v_levels = v_l; | ||
| 198 | + let v_residual = dequant_and_inverse_typed_wh( | ||
| 199 | +@@ -11838,7 +11873,7 @@ fn decode_block_rect4( | ||
| 200 | + let default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 201 | + let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); | ||
| 202 | + let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode); | ||
| 203 | +- let (levels, tx_type) = read_coeffs_rect( | ||
| 204 | ++ let (levels, tx_type) = read_chroma_coeffs_rect( | ||
| 205 | + dec, | ||
| 206 | + &mut coding, | ||
| 207 | + chroma_scan, | ||
| 208 | +@@ -11847,6 +11882,7 @@ fn decode_block_rect4( | ||
| 209 | + skip_ctx, | ||
| 210 | + dc_sign_ctx(around[plane].2), | ||
| 211 | + default_tx, | ||
| 212 | ++ fctx, | ||
| 213 | + )?; | ||
| 214 | + planes.push((levels, tx_type)); | ||
| 215 | + } | ||
| 216 | +@@ -12488,7 +12524,7 @@ fn decode_rect4_16_strip( | ||
| 217 | + let default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 218 | + let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); | ||
| 219 | + let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | ||
| 220 | +- let (levels, tx_type) = read_coeffs_rect( | ||
| 221 | ++ let (levels, tx_type) = read_chroma_coeffs_rect( | ||
| 222 | + dec, | ||
| 223 | + &mut coding, | ||
| 224 | + chroma_scan, | ||
| 225 | +@@ -12497,6 +12533,7 @@ fn decode_rect4_16_strip( | ||
| 226 | + skip_ctx, | ||
| 227 | + dc_sign_ctx(around[plane].2), | ||
| 228 | + default_tx, | ||
| 229 | ++ fctx, | ||
| 230 | + )?; | ||
| 231 | + planes.push((levels, tx_type)); | ||
| 232 | + } | ||
| 233 | +@@ -13012,7 +13049,7 @@ fn decode_block_rect64( | ||
| 234 | + let (rng, _) = dec.debug_state(); | ||
| 235 | + eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); | ||
| 236 | + } | ||
| 237 | +- let (u_levels, u_tx_type) = read_coeffs_rect( | ||
| 238 | ++ let (u_levels, u_tx_type) = read_chroma_coeffs_rect( | ||
| 239 | + dec, | ||
| 240 | + &mut u_coding, | ||
| 241 | + chroma_scan, | ||
| 242 | +@@ -13021,6 +13058,7 @@ fn decode_block_rect64( | ||
| 243 | + u_skip_ctx, | ||
| 244 | + dc_sign_ctx(around[1].2), | ||
| 245 | + TxType::DctDct, | ||
| 246 | ++ fctx, | ||
| 247 | + )?; | ||
| 248 | + if coeff_trace_on() { | ||
| 249 | + let (rng, _) = dec.debug_state(); | ||
| 250 | +@@ -13076,7 +13114,7 @@ fn decode_block_rect64( | ||
| 251 | + let (rng, _) = dec.debug_state(); | ||
| 252 | + eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); | ||
| 253 | + } | ||
| 254 | +- let (v_levels, v_tx_type) = read_coeffs_rect( | ||
| 255 | ++ let (v_levels, v_tx_type) = read_chroma_coeffs_rect( | ||
| 256 | + dec, | ||
| 257 | + &mut v_coding, | ||
| 258 | + chroma_scan, | ||
| 259 | +@@ -13085,6 +13123,7 @@ fn decode_block_rect64( | ||
| 260 | + v_skip_ctx, | ||
| 261 | + dc_sign_ctx(around[2].2), | ||
| 262 | + TxType::DctDct, | ||
| 263 | ++ fctx, | ||
| 264 | + )?; | ||
| 265 | + if coeff_trace_on() { | ||
| 266 | + let (rng, _) = dec.debug_state(); | ||
| 267 | +@@ -31604,6 +31643,26 @@ fn decode_intra_sub8_leaf( | ||
| 268 | + h.set(s); | ||
| 269 | + }); | ||
| 270 | + } | ||
| 271 | ++ // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map | ||
| 272 | ++ // needs EVERY writer): a sub-8x8 group published no palette state, so | ||
| 273 | ++ // once an 8x8 leaf of the same row can BE a palette block, the group | ||
| 274 | ++ // left the row's band holding that earlier block's size and the next | ||
| 275 | ++ // intra block read `av1_get_palette_mode_ctx` one too high (measured: | ||
| 276 | ++ // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers | ||
| 277 | ++ // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` | ||
| 278 | ++ // needs `bsize >= BLOCK_8X8`), so the group always clears. | ||
| 279 | ++ // | ||
| 280 | ++ // lane-av1mono: this publish is NOT chroma work and must run BEFORE the | ||
| 281 | ++ // `!has_chroma` return below. libaom's mi grid holds | ||
| 282 | ++ // `palette_size[0] == 0` in every cell of such a group whatever the | ||
| 283 | ++ // plane count, and on a monochrome frame EVERY sub-8 leaf passes | ||
| 284 | ++ // `has_chroma == false`, so a publish placed after the return never ran | ||
| 285 | ++ // at all: the band kept an earlier palette block's size, the next block | ||
| 286 | ++ // read `palette_y_mode` off CDF row 1 where libaom reads row 0, decoded | ||
| 287 | ++ // a palette libaom never coded, and the tile desynced one block later | ||
| 288 | ++ // (measured: gray testsrc2 320x240, decode-order frame 33, mi(42,50), | ||
| 289 | ++ // ours ctx 2 where libaom gathers 1). | ||
| 290 | ++ record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); | ||
| 291 | + if !has_chroma { | ||
| 292 | + return Ok(mode); | ||
| 293 | + } | ||
| 294 | +@@ -31622,15 +31681,6 @@ fn decode_intra_sub8_leaf( | ||
| 295 | + neighbours.above_uv_mode[c] = uv_predict_mode; | ||
| 296 | + neighbours.left_uv_mode[r] = uv_predict_mode; | ||
| 297 | + neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); | ||
| 298 | +- // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map | ||
| 299 | +- // needs EVERY writer): a sub-8x8 group published no palette state, so | ||
| 300 | +- // once an 8x8 leaf of the same row can BE a palette block, the group | ||
| 301 | +- // left the row's band holding that earlier block's size and the next | ||
| 302 | +- // intra block read `av1_get_palette_mode_ctx` one too high (measured: | ||
| 303 | +- // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers | ||
| 304 | +- // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` | ||
| 305 | +- // needs `bsize >= BLOCK_8X8`), so the group always clears. | ||
| 306 | +- record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); | ||
| 307 | + | ||
| 308 | + let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); | ||
| 309 | + let (u_grid, v_grid): (Grid, Grid) = if skip { | ||
| 310 | +diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs | ||
| 311 | +index a0b1bd43..d361662c 100644 | ||
| 312 | +--- a/crates/ec-av1/src/stream.rs | ||
| 313 | ++++ b/crates/ec-av1/src/stream.rs | ||
| 314 | +@@ -2024,6 +2024,105 @@ pub(crate) mod tests { | ||
| 315 | + ); | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | ++ /// lane-av1mono: the INVERSE of the pilot's | ||
| 319 | ++ /// `a_real_libaom_monochrome_key_frame_is_refused_by_name`, which the | ||
| 320 | ++ /// pilot's merge `d71084ae` landed on `main` (after this lane's base | ||
| 321 | ++ /// `7f4e8301`): the very same recipe now decodes, and its luma is | ||
| 322 | ++ /// byte-exact against ffmpeg's own decode of the same OBU. A merge of this | ||
| 323 | ++ /// lane into `main` must therefore resolve that pinning gate by adopting | ||
| 324 | ++ /// this witness in its place. | ||
| 325 | ++ /// | ||
| 326 | ++ /// `ffmpeg -pix_fmt gray -c:v libaom-av1` sets `color_config.mono_chrome`, | ||
| 327 | ++ /// so libaom codes NO chroma symbol anywhere in the sequence -- not the | ||
| 328 | ++ /// mode syntax, not a coefficient. That reaches all three classes this lane | ||
| 329 | ++ /// had to close: chroma SYMBOL reads (`uv_mode`/cfl/angle/palette), chroma | ||
| 330 | ++ /// COEFFICIENT reads on the rect-strip paths that call `read_coeffs_rect` | ||
| 331 | ++ /// DIRECTLY instead of through `read_plane`'s own plane gate, and the | ||
| 332 | ++ /// palette-mode neighbour band a mono sub-8x8 leaf must still clear before | ||
| 333 | ++ /// it returns (an uncleared band made the next block read `palette_y_mode` | ||
| 334 | ++ /// off the wrong CDF row and silently desynced the rest of the tile -- | ||
| 335 | ++ /// measured at decode-order frame 33 of this very recipe). | ||
| 336 | ++ /// | ||
| 337 | ++ /// The 4:2:0 twin of the same source and settings is the control: it proves | ||
| 338 | ++ /// the recipe is decodable, so a failure here is about the plane count and | ||
| 339 | ++ /// not about the source or the encoder settings. | ||
| 340 | ++ #[test] | ||
| 341 | ++ fn a_real_libaom_monochrome_key_frame_decodes_pixel_exact() { | ||
| 342 | ++ const NAME: &str = "a_real_libaom_monochrome_key_frame_decodes_pixel_exact"; | ||
| 343 | ++ if !have_ffmpeg() { | ||
| 344 | ++ eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 345 | ++ return; | ||
| 346 | ++ } | ||
| 347 | ++ let emit = |pix: &str| -> Vec<u8> { | ||
| 348 | ++ let out = Command::new("ffmpeg") | ||
| 349 | ++ .args([ | ||
| 350 | ++ "-v", | ||
| 351 | ++ "error", | ||
| 352 | ++ "-f", | ||
| 353 | ++ "lavfi", | ||
| 354 | ++ "-i", | ||
| 355 | ++ "testsrc2=size=320x240:rate=30:duration=2", | ||
| 356 | ++ "-pix_fmt", | ||
| 357 | ++ pix, | ||
| 358 | ++ "-c:v", | ||
| 359 | ++ "libaom-av1", | ||
| 360 | ++ "-cpu-used", | ||
| 361 | ++ "8", | ||
| 362 | ++ "-b:v", | ||
| 363 | ++ "300k", | ||
| 364 | ++ "-f", | ||
| 365 | ++ "obu", | ||
| 366 | ++ "-", | ||
| 367 | ++ ]) | ||
| 368 | ++ .stdin(Stdio::null()) | ||
| 369 | ++ .stdout(Stdio::piped()) | ||
| 370 | ++ .stderr(Stdio::piped()) | ||
| 371 | ++ .output() | ||
| 372 | ++ .expect("ffmpeg failed to run"); | ||
| 373 | ++ assert!( | ||
| 374 | ++ out.status.success(), | ||
| 375 | ++ "{NAME}: ffmpeg ({pix}) failed: {}", | ||
| 376 | ++ String::from_utf8_lossy(&out.stderr) | ||
| 377 | ++ ); | ||
| 378 | ++ out.stdout | ||
| 379 | ++ }; | ||
| 380 | ++ // CONTROL: the identical recipe at 4:2:0 still decodes. | ||
| 381 | ++ let twin = decode_stream(&emit("yuv420p")).expect("the 4:2:0 twin must decode"); | ||
| 382 | ++ assert!(!twin.is_empty(), "{NAME}: the 4:2:0 twin decoded no frames"); | ||
| 383 | ++ // THE WITNESS: the monochrome stream decodes and every luma sample | ||
| 384 | ++ // equals ffmpeg's own decode of the same OBU. | ||
| 385 | ++ let gray = emit("gray"); | ||
| 386 | ++ let ours = decode_stream(&gray) | ||
| 387 | ++ .unwrap_or_else(|e| panic!("{NAME}: the monochrome stream is REFUSED again: {e}")); | ||
| 388 | ++ let (width, height) = (320usize, 240usize); | ||
| 389 | ++ const FRAMES: usize = 60; | ||
| 390 | ++ assert_eq!(ours.len(), FRAMES, "{NAME}: expected {FRAMES} mono frames"); | ||
| 391 | ++ let reference = ffmpeg_decode_gray_sequence(&gray, width, height, FRAMES); | ||
| 392 | ++ for (i, plane) in reference.chunks_exact(width * height).enumerate() { | ||
| 393 | ++ assert_eq!(ours[i].width, width, "{NAME}: frame {i} width"); | ||
| 394 | ++ assert_eq!(ours[i].height, height, "{NAME}: frame {i} height"); | ||
| 395 | ++ assert_eq!( | ||
| 396 | ++ ours[i].y.len(), | ||
| 397 | ++ width * height, | ||
| 398 | ++ "{NAME}: frame {i} luma length" | ||
| 399 | ++ ); | ||
| 400 | ++ for (j, (got, want)) in plane.iter().zip(ours[i].y.iter()).enumerate() { | ||
| 401 | ++ assert_eq!( | ||
| 402 | ++ *want, | ||
| 403 | ++ u16::from(*got), | ||
| 404 | ++ "{NAME}: frame {i} luma sample {j} (row {}, col {}) is {want}, ffmpeg says {got}", | ||
| 405 | ++ j / width, | ||
| 406 | ++ j % width | ||
| 407 | ++ ); | ||
| 408 | ++ } | ||
| 409 | ++ } | ||
| 410 | ++ eprintln!( | ||
| 411 | ++ "{NAME}: 4:2:0 twin {} frames, monochrome {} frames byte-exact vs ffmpeg", | ||
| 412 | ++ twin.len(), | ||
| 413 | ++ ours.len() | ||
| 414 | ++ ); | ||
| 415 | ++ } | ||
| 416 | ++ | ||
| 417 | + /// lane-t900 r25: the refusal "a frame OBU with no tile group" names a | ||
| 418 | + /// shape the parser cannot hand [`decode_stream`]. | ||
| 419 | + /// | ||
| 420 | +@@ -3296,6 +3395,49 @@ pub(crate) mod tests { | ||
| 421 | + .collect() | ||
| 422 | + } | ||
| 423 | + | ||
| 424 | ++ /// As [`ffmpeg_decode_sequence`], for a MONOCHROME stream: one 8-bit luma | ||
| 425 | ++ /// plane per frame, exactly what `ffmpeg -pix_fmt gray -f rawvideo` writes | ||
| 426 | ++ /// (lane-av1mono). Fed down a stdin writer thread for the reason the 4:2:0 | ||
| 427 | ++ /// helper documents. | ||
| 428 | ++ fn ffmpeg_decode_gray_sequence( | ||
| 429 | ++ stream: &[u8], | ||
| 430 | ++ width: usize, | ||
| 431 | ++ height: usize, | ||
| 432 | ++ frames: usize, | ||
| 433 | ++ ) -> Vec<u8> { | ||
| 434 | ++ let mut child = Command::new("ffmpeg") | ||
| 435 | ++ .args([ | ||
| 436 | ++ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-", | ||
| 437 | ++ ]) | ||
| 438 | ++ .stdin(Stdio::piped()) | ||
| 439 | ++ .stdout(Stdio::piped()) | ||
| 440 | ++ .stderr(Stdio::piped()) | ||
| 441 | ++ .spawn() | ||
| 442 | ++ .expect("ffmpeg failed to start"); | ||
| 443 | ++ let mut stdin = child.stdin.take().expect("ffmpeg stdin"); | ||
| 444 | ++ let payload = stream.to_vec(); | ||
| 445 | ++ let writer = std::thread::Builder::new() | ||
| 446 | ++ .name("ec-av1-ffmpeg-gray-in".into()) | ||
| 447 | ++ .spawn(move || { | ||
| 448 | ++ let _ = stdin.write_all(&payload); | ||
| 449 | ++ }) | ||
| 450 | ++ .expect("spawning the ffmpeg stdin writer"); | ||
| 451 | ++ let out = child.wait_with_output().expect("ffmpeg failed to run"); | ||
| 452 | ++ writer.join().expect("ffmpeg stdin writer thread"); | ||
| 453 | ++ assert!( | ||
| 454 | ++ out.status.success(), | ||
| 455 | ++ "ffmpeg refused the monochrome stream: {}", | ||
| 456 | ++ String::from_utf8_lossy(&out.stderr) | ||
| 457 | ++ ); | ||
| 458 | ++ assert_eq!( | ||
| 459 | ++ out.stdout.len(), | ||
| 460 | ++ width * height * frames, | ||
| 461 | ++ "expected {frames} monochrome frames, ffmpeg said: {}", | ||
| 462 | ++ String::from_utf8_lossy(&out.stderr) | ||
| 463 | ++ ); | ||
| 464 | ++ out.stdout | ||
| 465 | ++ } | ||
| 466 | ++ | ||
| 467 | + /// As [`ffmpeg_decode_sequence`], but for a `yuv420p10le` stream: samples | ||
| 468 | + /// are 2-byte little-endian, one full 16-bit range regardless of the | ||
| 469 | + /// stream's real 10-bit depth (ffmpeg's rawvideo muxer never packs to the | ||
| 470 | +``` | ||
| 471 | + | ||
| 472 | +## Witnesses (quoted) | ||
| 473 | + | ||
| 474 | +All three run on the final tree; the probe is | ||
| 475 | +`$HOME/.cache/cargo-target-av1mono/release/examples/decode_probe`. | ||
| 476 | + | ||
| 477 | +``` | ||
| 478 | +(a) gray 60f key frame -- ffmpeg testsrc2 320x240 30fps 2s -pix_fmt gray | ||
| 479 | +OK: 60 frames decoded, 320x240 | ||
| 480 | +gray60 EQUAL True | ||
| 481 | + | ||
| 482 | +(b) gray 120f (inter frames) -- same recipe, duration 4 | ||
| 483 | +OK: 120 frames decoded, 320x240 | ||
| 484 | +gray120 EQUAL True | ||
| 485 | + | ||
| 486 | +(c) fixtures/bitstreams/av1-monochrome.ivf (remuxed to OBU) | ||
| 487 | +OK: 60 frames decoded, 320x240 | ||
| 488 | +mono.ivf EQUAL True | ||
| 489 | +``` | ||
| 490 | + | ||
| 491 | +Comparison for (a)/(b)/(c): probe `EC_PROBE_OUT16` writes the 8-bit sample in the | ||
| 492 | +**low byte** of each u16, so the check is `probe[0::2] == ffmpeg -pix_fmt gray -f | ||
| 493 | +rawvideo`. All three are STRONGER than the charter expected: (c) was expected to | ||
| 494 | +stop at the named intrabc-rect refusal, but that refusal was itself a *symptom* of | ||
| 495 | +this desync, so with the desync gone the fixture now decodes **all 60 frames | ||
| 496 | +byte-exact**. (Class, per the pilot §3.3/3.4: a routing refusal reached only | ||
| 497 | +because the desynced read picked wrong block sizes.) | ||
| 498 | + | ||
| 499 | +Scoped test: | ||
| 500 | +``` | ||
| 501 | +$ cargo test -p ec-av1 --lib a_real_libaom_monochrome_key_frame_decodes_pixel_exact -- --nocapture | ||
| 502 | +a_real_libaom_monochrome_key_frame_decodes_pixel_exact: 4:2:0 twin 60 frames, monochrome 60 frames byte-exact vs ffmpeg | ||
| 503 | +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 651 filtered out | ||
| 504 | +``` | ||
| 505 | + | ||
| 506 | +## Regression | ||
| 507 | + | ||
| 508 | +**Corpus (9 `fixtures/bitstreams/av1-*.ivf`), byte-identity vs the LANE BASE | ||
| 509 | +(`7f4e8301`, own probe at `$HOME/.cache/cargo-target-av1base`):** | ||
| 510 | + | ||
| 511 | +``` | ||
| 512 | +av1-1080p-23.976-10bit IDENTICAL(rc=0) da2b8484b94b244a | ||
| 513 | +av1-1080p-23.976-8bit IDENTICAL(rc=0) 407148a9397461fa | ||
| 514 | +av1-1080p-60-10bit IDENTICAL(rc=0) 83087317d215b128 | ||
| 515 | +av1-1080p-60-8bit IDENTICAL(rc=0) 4aff1fdedc0599a8 | ||
| 516 | +av1-2160p-23.976-8bit IDENTICAL(rc=0) ea683b4a9e2b8891 | ||
| 517 | +av1-altref IDENTICAL(rc=0) ea2f84d929b52f5e | ||
| 518 | +av1-monochrome DIFFER base=49d757b50b8d9175 lane=b869441a9cf29d87 <-- the fix | ||
| 519 | +av1-profile1-444 IDENTICAL(rc=0) 6620e894ff971cba | ||
| 520 | +av1-tiles-1280 IDENTICAL(rc=0) 5e59dbc445eb4e17 | ||
| 521 | +``` | ||
| 522 | + | ||
| 523 | +Only the monochrome fixture moves; every non-mono stream is bit-identical to the | ||
| 524 | +base. **`av1-profile1-444` is IDENTICAL to the base and is NOT byte-exact vs | ||
| 525 | +ffmpeg** — that is the pilot §3.2 4:4:4 block-routing defect, pre-existing and | ||
| 526 | +out of this lane's scope (same probe, same output at base and lane). | ||
| 527 | + | ||
| 528 | +**Against ffmpeg** (correct sample packing per bit depth): | ||
| 529 | +`av1-1080p-23.976-10bit`, `av1-1080p-23.976-8bit`, `av1-1080p-60-10bit`, | ||
| 530 | +`av1-1080p-60-8bit`, `av1-2160p-23.976-8bit`, `av1-altref`, `av1-monochrome`, | ||
| 531 | +`av1-tiles-1280` → all MATCH (sha256). `av1-profile1-444` → differs (above). | ||
| 532 | + | ||
| 533 | +**Film windows** (the pilot's 13 real 3840x1608 10-bit windows | ||
| 534 | +`~/.cache/av1dec-recon/p-*.obu`, compared to the pilot's own ffmpeg `.ref` decodes): | ||
| 535 | + | ||
| 536 | +``` | ||
| 537 | +p-reelb2700 MATCH [OK: 104 frames] p-reelb300 MATCH [OK: 136] p-reelb5700 MATCH [OK: 247] | ||
| 538 | +p-hgb1500 MATCH [OK: 242] p-hgb2100 MATCH [OK: 173] p-hgb3300 MATCH [OK: 279] | ||
| 539 | +p-hgb3900 MATCH [OK: 210] p-hgb4500 MATCH [OK: 141] p-hgb5100 MATCH [OK: 71] | ||
| 540 | +p-hgb6300 MATCH [OK: 177] p-hgb6900 MATCH [OK: 108] p-hgb7500 MATCH [OK: 284] | ||
| 541 | +p-hgb900 MATCH [OK: 67] | ||
| 542 | +``` | ||
| 543 | + | ||
| 544 | +All 13 byte-identical. Refusals were not touched (`refusal_inventory` tests are in | ||
| 545 | +the suite below). | ||
| 546 | + | ||
| 547 | +## Merge interaction (for the orchestrator) | ||
| 548 | + | ||
| 549 | +`main` now carries the pilot's **`a_real_libaom_monochrome_key_frame_is_refused_by_name`** | ||
| 550 | +(merged at `d71084ae`, after this lane's base `7f4e8301`). This lane adds the | ||
| 551 | +**inverted witness** `..._decodes_pixel_exact` in the same `stream.rs` test module | ||
| 552 | +and does NOT edit the pinning test (per charter). A merge will **conflict in | ||
| 553 | +`crates/ec-av1/src/stream.rs`**: the resolution is to DROP the pilot's pinning | ||
| 554 | +gate and keep this lane's byte-exact witness (the pinning gate asserts the very | ||
| 555 | +behaviour this lane removes, so it must fail once mono decode lands). The | ||
| 556 | +witness test's own doc comment records this. | ||
| 557 | + | ||
| 558 | +## Gates | ||
| 559 | + | ||
| 560 | +- `cargo check -p ec-av1` (post-salvage) → rc 0. | ||
| 561 | +- `cargo check -p ec-av1 --all-targets` → rc 0, **0 warnings** (second target dir | ||
| 562 | + `$HOME/.cache/cargo-target-av1mono-check`). | ||
| 563 | +- `cargo test -p ec-av1 --lib` to completion → **592 passed, 0 failed, 60 ignored** | ||
| 564 | + (6724 s), on the final tree. | ||
| 62 | 565 | ||
| 63 | ## Repro | 566 | ## Repro |
| 64 | 567 | ||
| 65 | ``` | 568 | ``` |
| 66 | -# generate (pilot recipe) | ||
| 67 | ffmpeg -v error -f lavfi -i "testsrc2=size=320x240:rate=30:duration=2" \ | 569 | ffmpeg -v error -f lavfi -i "testsrc2=size=320x240:rate=30:duration=2" \ |
| 68 | -pix_fmt gray -c:v libaom-av1 -cpu-used 8 -b:v 300k -f obu -y /tmp/gray.obu | 570 | -pix_fmt gray -c:v libaom-av1 -cpu-used 8 -b:v 300k -f obu -y /tmp/gray.obu |
| 69 | -ffmpeg -v error -i fixtures/bitstreams/av1-monochrome.ivf -c:v copy -f obu -y /tmp/mono.obu | ||
| 70 | - | ||
| 71 | P=$HOME/.cache/cargo-target-av1mono/release/examples/decode_probe | 571 | P=$HOME/.cache/cargo-target-av1mono/release/examples/decode_probe |
| 72 | -EC_PROBE_OUT16=$HOME/m.raw16 $P /tmp/gray.obu # OK: 60 frames (was REFUSED) | 572 | +EC_PROBE_OUT16=$HOME/m.raw16 $P /tmp/gray.obu # OK: 60 frames |
| 73 | ffmpeg -v error -i /tmp/gray.obu -pix_fmt gray -f rawvideo $HOME/ref.gray | 573 | ffmpeg -v error -i /tmp/gray.obu -pix_fmt gray -f rawvideo $HOME/ref.gray |
| 74 | -python3 -c "d=open('$HOME/m.raw16','rb').read();print(bytes(d[0::2])==open('$HOME/ref.gray','rb').read())" | 574 | +python3 -c "d=open('$HOME/m.raw16','rb').read()[0::2]; print(bytes(d)==open('$HOME/ref.gray','rb').read())" # True |
| 75 | -# -> False today; first differing byte at index 37. | 575 | +``` |
| 576 | + | ||
| 577 | +## Suite | ||
| 578 | + | ||
| 579 | +``` | ||
| 580 | +$ cargo test -p ec-av1 --lib | ||
| 581 | +test result: ok. 592 passed; 0 failed; 60 ignored; 0 measured; 0 filtered out; finished in 6724.24s | ||
| 76 | ``` | 582 | ``` |
| 77 | 583 | ||
| 78 | -## Verified | 584 | +Same count as the pilot's completed run on `main` (592/0/60, 6716 s), so no test |
| 79 | - | 585 | +regressed, no test was added-but-unrun, and the 60 ignored are the pre-existing |
| 80 | -- `decode_probe` gray recipe: `OK: 60 frames decoded, 320x240` (was REFUSED). | 586 | +single-process-global cases. `cargo check -p ec-av1 --all-targets` → rc 0, 0 |
| 81 | -- `decode_probe` `av1-monochrome.ivf` (remuxed to OBU): `OK: 60 frames` (was REFUSED). | 587 | +warnings on the same final bytes. |
| 82 | -- 4:2:0 twin of the same recipe: `OK: 60 frames` (unchanged). | ||
| 83 | -- Byte-exactness vs ffmpeg gray: **FAILS** (see above). | ||
| 84 | - | ||
| 85 | -## NOT done (blocking acceptance) | ||
| 86 | - | ||
| 87 | -- Byte-exact luma on the three required witnesses (gray recipe, av1-monochrome.ivf, | ||
| 88 | - a 60+ frame inter gray encode). The key-frame luma mismatch must be found first. | ||
| 89 | -- Inter-frame mono streams not yet exercised past the key frame (an earlier run | ||
| 90 | - panicked in `mc.rs:1141` "a reference plane has samples" when the mono Picture | ||
| 91 | - carried empty u/v; that was fixed by keeping the chroma scratch planes in the | ||
| 92 | - Picture and making the probe — not the Picture — luma-only. Inter mono still | ||
| 93 | - needs a byte-exactness gate.) | ||
| 94 | -- The pilot's gate `a_real_libaom_monochrome_key_frame_is_refused_by_name` | ||
| 95 | - (branch `lane-av1-decode`, not on main) must be INVERTED to a pixel-exact | ||
| 96 | - witness once the luma defect is fixed. | ||
| 97 | -- `cargo test -p ec-av1 --lib` suite + `cargo check -p ec-av1 --all-targets` | ||
| 98 | - 0-warning gate not run this session. | ||
| 99 | -- Refusal inventory count not updated. | ||
| 100 | -- Film-window probes not re-run on this build. | ||
| 101 | 588 | ||
| 102 | ## Deferred / not chased | 589 | ## Deferred / not chased |
| 103 | 590 | ||
| 104 | -- The other 34 refusals (pilot terrain map Wave 2/3) — untouched, per charter. | 591 | +- `av1-profile1-444.ivf` chroma non-exactness (pilot §3.2 4:4:4 block-routing) — |
| 592 | + pre-existing, unchanged by this lane. | ||
| 593 | +- The pilot's 4:4:4-fast / all-intra / warped-cpu0 recipes — untouched. | ||