forge
Explore
Log in

Don't you dare go Hollow

Declare reduced_tx_set in the key-frame header

Browse files at this commit

a9fbebe8588e68d3599bdced11fb24d43be1491dAhmet Kaan GümüşParent: e3b2c93
  • fix
    • declare reduced_tx_set in the key-frame header
    • rng in traces
Show full message
fix(av1): declare reduced_tx_set in the key-frame header; rng in traces

The writer coded 8x8-leaf tx types against TX_SET_INTRA_2 tables while
the header's reduced_tx_set:false told decoders to read TX_SET_INTRA_1 —
a 7-vs-5-symbol alphabet skew that shifts the arithmetic coder's range
with no symbol value ever differing. All existing sizes still round-trip
bit-exact (16x16 resolves to the same 5-symbol set under both headers).
Straddle test stays ignored: a further divergence remains past leaf(0,8).
crates/ec-av1/src/encode.rsmodified+16 -1
@@ -419,6 +419,19 @@ pub(crate) fn key_frame_headers_colour(
419419 ..QuantizationParams::default()
420420 },
421421 tx_mode: TxMode::Largest,
422+ // Forces `get_tx_set` (spec 5.11.48) to `TX_SET_INTRA_2` for every
423+ // intra transform below 32x32, not only 16x16 -- the set this crate
424+ // carries a table for at 8x8/16x16 (`INTRA_TX_TYPE_SET2_8`/`_16`).
425+ // This bit is part of the bitstream (spec 5.9.2's `reduced_tx_set`),
426+ // so a decoder honouring the header picks the same CDF the writer
427+ // used only if this is set here too, not only on the inter variant
428+ // below -- an r14 lane-av1-rect fix: a key frame's own header used to
429+ // default this to `false`, so `av1_get_ext_tx_set_type` picked the
430+ // 7-symbol `TX_SET_INTRA_1` table on the decoder side while the
431+ // writer coded against the 5-symbol `TX_SET_INTRA_2` one, diverging
432+ // the arithmetic coder's `rng` register from the very first 8x8-leaf
433+ // luma transform onward with no symbol value ever differing.
434+ reduced_tx_set: true,
422435 ..FrameHeader::default()
423436 };
424437 Ok((seq, header))
@@ -3919,7 +3932,9 @@ mod tests {
39193932 /// yet isolated to a single named symbol. Ignored rather than deleted,
39203933 /// so the class stays named and the gate stays green.
39213934 #[test]
3922- #[ignore = "lane-av1-rect r12: 8x8-leaf path desyncs dav1d; leaf(2,8) reads the wrong tx size"]
3935+ #[ignore = "lane-av1-rect r14: leaf(0,8)'s rng now matches through several further \
3936+ leaves after the reduced_tx_set header fix; residual desync moved past \
3937+ mi_row=4, not yet isolated to a named symbol"]
39233938 fn a_single_axis_straddle_round_trips_through_ffmpeg() {
39243939 if !have_ffmpeg() {
39253940 eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg");
crates/ec-av1/src/msac.rsmodified+7 -0
@@ -77,6 +77,13 @@ impl SymbolEncoder {
7777 self.bits
7878 }
7979
80+ /// The coder's current interval width — libaom's `od_ec_enc_rng` /
81+ /// decoder's `rng` field. Exposed only for the rng-register bisect trace
82+ /// (`EC_RNG=1`); not part of the bitstream contract.
83+ pub(crate) fn rng(&self) -> u32 {
84+ self.rng
85+ }
86+
8087 /// The exact bit position the stream has committed to so far (libaom's
8188 /// `od_ec_enc_tell`, `entenc.c`): `cnt + 10` undoes the `-9` `cnt` starts
8289 /// at and reserves the one bit `finish` always spends, and `precarry`
crates/ec-av1/src/tile.rsmodified+12 -5
@@ -1277,7 +1277,7 @@ fn write_intra_mode(
12771277 mode,
12781278 &mut cdfs.kf_y_mode[INTRA_MODE_CTX[above_mode]][INTRA_MODE_CTX[left_mode]],
12791279 );
1280- ec_rng_trace(|| format!("EC_YMODE mode={mode} tell={}", enc.tell()));
1280+ ec_rng_trace(|| format!("EC_YMODE mode={mode} tell={} rng={}", enc.tell(), enc.rng()));
12811281 if (V_PRED..=D67_PRED).contains(&mode) {
12821282 enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[mode - V_PRED]);
12831283 }
@@ -1633,9 +1633,10 @@ fn write_coeffs(
16331633 if plane.is_some() {
16341634 ec_rng_trace(|| {
16351635 format!(
1636- "EC_TXBSKIP ctx={skip_ctx} eob0={} tell={}",
1636+ "EC_TXBSKIP ctx={skip_ctx} eob0={} tell={} rng={}",
16371637 usize::from(eob == 0),
1638- enc.tell()
1638+ enc.tell(),
1639+ enc.rng()
16391640 )
16401641 });
16411642 }
@@ -1648,7 +1649,7 @@ fn write_coeffs(
16481649 if let Some(tx_type) = coding.tx_type.as_deref_mut() {
16491650 enc.symbol(TX_TYPE_DCT_DCT_SET2, tx_type);
16501651 if plane.is_some() {
1651- ec_rng_trace(|| format!("EC_TXTYPE tell={}", enc.tell()));
1652+ ec_rng_trace(|| format!("EC_TXTYPE tell={} rng={}", enc.tell(), enc.rng()));
16521653 }
16531654 }
16541655
@@ -1761,7 +1762,13 @@ fn write_eob(enc: &mut SymbolEncoder, coding: &mut TxbTables, eob: usize, plane:
17611762 // reaches is the size of its own end-of-block alphabet.
17621763 enc.symbol(group - 1, coding.eob_pt);
17631764 if let Some(plane) = plane {
1764- ec_rng_trace(|| format!("EC_EOBPT plane={plane} eob_pt={group} tell={}", enc.tell()));
1765+ ec_rng_trace(|| {
1766+ format!(
1767+ "EC_EOBPT plane={plane} eob_pt={group} tell={} rng={}",
1768+ enc.tell(),
1769+ enc.rng()
1770+ )
1771+ });
17651772 }
17661773
17671774 let bits = OFFSET_BITS[group];