diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index a4378b09..53536db9 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -419,6 +419,19 @@ pub(crate) fn key_frame_headers_colour( ..QuantizationParams::default() }, tx_mode: TxMode::Largest, + // Forces `get_tx_set` (spec 5.11.48) to `TX_SET_INTRA_2` for every + // intra transform below 32x32, not only 16x16 -- the set this crate + // carries a table for at 8x8/16x16 (`INTRA_TX_TYPE_SET2_8`/`_16`). + // This bit is part of the bitstream (spec 5.9.2's `reduced_tx_set`), + // so a decoder honouring the header picks the same CDF the writer + // used only if this is set here too, not only on the inter variant + // below -- an r14 lane-av1-rect fix: a key frame's own header used to + // default this to `false`, so `av1_get_ext_tx_set_type` picked the + // 7-symbol `TX_SET_INTRA_1` table on the decoder side while the + // writer coded against the 5-symbol `TX_SET_INTRA_2` one, diverging + // the arithmetic coder's `rng` register from the very first 8x8-leaf + // luma transform onward with no symbol value ever differing. + reduced_tx_set: true, ..FrameHeader::default() }; Ok((seq, header)) @@ -3919,7 +3932,9 @@ mod tests { /// yet isolated to a single named symbol. Ignored rather than deleted, /// so the class stays named and the gate stays green. #[test] - #[ignore = "lane-av1-rect r12: 8x8-leaf path desyncs dav1d; leaf(2,8) reads the wrong tx size"] + #[ignore = "lane-av1-rect r14: leaf(0,8)'s rng now matches through several further \ + leaves after the reduced_tx_set header fix; residual desync moved past \ + mi_row=4, not yet isolated to a named symbol"] fn a_single_axis_straddle_round_trips_through_ffmpeg() { if !have_ffmpeg() { eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg"); diff --git a/crates/ec-av1/src/msac.rs b/crates/ec-av1/src/msac.rs index ef17b2c4..51f133c8 100644 --- a/crates/ec-av1/src/msac.rs +++ b/crates/ec-av1/src/msac.rs @@ -77,6 +77,13 @@ impl SymbolEncoder { self.bits } + /// The coder's current interval width — libaom's `od_ec_enc_rng` / + /// decoder's `rng` field. Exposed only for the rng-register bisect trace + /// (`EC_RNG=1`); not part of the bitstream contract. + pub(crate) fn rng(&self) -> u32 { + self.rng + } + /// The exact bit position the stream has committed to so far (libaom's /// `od_ec_enc_tell`, `entenc.c`): `cnt + 10` undoes the `-9` `cnt` starts /// at and reserves the one bit `finish` always spends, and `precarry` diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 601f2313..df87d921 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -1277,7 +1277,7 @@ fn write_intra_mode( mode, &mut cdfs.kf_y_mode[INTRA_MODE_CTX[above_mode]][INTRA_MODE_CTX[left_mode]], ); - ec_rng_trace(|| format!("EC_YMODE mode={mode} tell={}", enc.tell())); + ec_rng_trace(|| format!("EC_YMODE mode={mode} tell={} rng={}", enc.tell(), enc.rng())); if (V_PRED..=D67_PRED).contains(&mode) { enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[mode - V_PRED]); } @@ -1633,9 +1633,10 @@ fn write_coeffs( if plane.is_some() { ec_rng_trace(|| { format!( - "EC_TXBSKIP ctx={skip_ctx} eob0={} tell={}", + "EC_TXBSKIP ctx={skip_ctx} eob0={} tell={} rng={}", usize::from(eob == 0), - enc.tell() + enc.tell(), + enc.rng() ) }); } @@ -1648,7 +1649,7 @@ fn write_coeffs( if let Some(tx_type) = coding.tx_type.as_deref_mut() { enc.symbol(TX_TYPE_DCT_DCT_SET2, tx_type); if plane.is_some() { - ec_rng_trace(|| format!("EC_TXTYPE tell={}", enc.tell())); + ec_rng_trace(|| format!("EC_TXTYPE tell={} rng={}", enc.tell(), enc.rng())); } } @@ -1761,7 +1762,13 @@ fn write_eob(enc: &mut SymbolEncoder, coding: &mut TxbTables, eob: usize, plane: // reaches is the size of its own end-of-block alphabet. enc.symbol(group - 1, coding.eob_pt); if let Some(plane) = plane { - ec_rng_trace(|| format!("EC_EOBPT plane={plane} eob_pt={group} tell={}", enc.tell())); + ec_rng_trace(|| { + format!( + "EC_EOBPT plane={plane} eob_pt={group} tell={} rng={}", + enc.tell(), + enc.rng() + ) + }); } let bits = OFFSET_BITS[group];