Declare reduced_tx_set in the key-frame header
Browse files at this commita9fbebe8588e68d3599bdced11fb24d43be1491dParent: e3b2c93- fix
- declare reduced_tx_set in the key-frame header
- rng in traces
3 changed files +35 -6
- crates/ec-av1/src/encode.rs +16 -1
- crates/ec-av1/src/msac.rs +7 -0
- crates/ec-av1/src/tile.rs +12 -5
crates/ec-av1/src/encode.rsmodified+16 -1
| @@ -419,6 +419,19 @@ pub(crate) fn key_frame_headers_colour( | ||
| 419 | 419 | ..QuantizationParams::default() |
| 420 | 420 | }, |
| 421 | 421 | 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, | |
| 422 | 435 | ..FrameHeader::default() |
| 423 | 436 | }; |
| 424 | 437 | Ok((seq, header)) |
| @@ -3919,7 +3932,9 @@ mod tests { | ||
| 3919 | 3932 | /// yet isolated to a single named symbol. Ignored rather than deleted, |
| 3920 | 3933 | /// so the class stays named and the gate stays green. |
| 3921 | 3934 | #[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"] | |
| 3923 | 3938 | fn a_single_axis_straddle_round_trips_through_ffmpeg() { |
| 3924 | 3939 | if !have_ffmpeg() { |
| 3925 | 3940 | 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 { | ||
| 77 | 77 | self.bits |
| 78 | 78 | } |
| 79 | 79 | |
| 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 | + | |
| 80 | 87 | /// The exact bit position the stream has committed to so far (libaom's |
| 81 | 88 | /// `od_ec_enc_tell`, `entenc.c`): `cnt + 10` undoes the `-9` `cnt` starts |
| 82 | 89 | /// 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( | ||
| 1277 | 1277 | mode, |
| 1278 | 1278 | &mut cdfs.kf_y_mode[INTRA_MODE_CTX[above_mode]][INTRA_MODE_CTX[left_mode]], |
| 1279 | 1279 | ); |
| 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())); | |
| 1281 | 1281 | if (V_PRED..=D67_PRED).contains(&mode) { |
| 1282 | 1282 | enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[mode - V_PRED]); |
| 1283 | 1283 | } |
| @@ -1633,9 +1633,10 @@ fn write_coeffs( | ||
| 1633 | 1633 | if plane.is_some() { |
| 1634 | 1634 | ec_rng_trace(|| { |
| 1635 | 1635 | format!( |
| 1636 | - "EC_TXBSKIP ctx={skip_ctx} eob0={} tell={}", | |
| 1636 | + "EC_TXBSKIP ctx={skip_ctx} eob0={} tell={} rng={}", | |
| 1637 | 1637 | usize::from(eob == 0), |
| 1638 | - enc.tell() | |
| 1638 | + enc.tell(), | |
| 1639 | + enc.rng() | |
| 1639 | 1640 | ) |
| 1640 | 1641 | }); |
| 1641 | 1642 | } |
| @@ -1648,7 +1649,7 @@ fn write_coeffs( | ||
| 1648 | 1649 | if let Some(tx_type) = coding.tx_type.as_deref_mut() { |
| 1649 | 1650 | enc.symbol(TX_TYPE_DCT_DCT_SET2, tx_type); |
| 1650 | 1651 | 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())); | |
| 1652 | 1653 | } |
| 1653 | 1654 | } |
| 1654 | 1655 | |
| @@ -1761,7 +1762,13 @@ fn write_eob(enc: &mut SymbolEncoder, coding: &mut TxbTables, eob: usize, plane: | ||
| 1761 | 1762 | // reaches is the size of its own end-of-block alphabet. |
| 1762 | 1763 | enc.symbol(group - 1, coding.eob_pt); |
| 1763 | 1764 | 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 | + }); | |
| 1765 | 1772 | } |
| 1766 | 1773 | |
| 1767 | 1774 | let bits = OFFSET_BITS[group]; |