diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 1e6b15f6..09ff5efa 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -34115,7 +34115,7 @@ pub(crate) fn decode_inter_frame_tile( &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false, // `enable_filter_intra`: as the `false`s beside it, this convenience // entry names a stream written without the sequence bit (lane-fintra). - switchable_motion_mode, false, false, fctx, + switchable_motion_mode, false, false, DeltaParams::default(), fctx, ) } @@ -34169,6 +34169,8 @@ pub(crate) fn decode_inter_frame_tile_lr( allow_warped_motion: bool, // lane-fintra: see [`decode_inter_frame_tiles_lr`]'s own parameter. enable_filter_intra: bool, + // lane-deltaq: see [`decode_inter_frame_tiles_lr`]'s own parameter. + delta: DeltaParams, fctx: &crate::decode::FrameCtx, ) -> Result { let single_tile = TileInfo { @@ -34200,6 +34202,7 @@ pub(crate) fn decode_inter_frame_tile_lr( switchable_motion_mode, allow_warped_motion, enable_filter_intra, + delta, fctx, ) } @@ -34247,6 +34250,12 @@ pub(crate) fn decode_inter_frame_tiles_lr( // encoder's own trial decode desyncs at the first intra-in-inter DC_PRED // block the moment its sequence header sets the bit. enable_filter_intra: bool, + // lane-deltaq: this frame header's own `delta_q_params`/`delta_lf_params` + // (spec 5.9.17/5.9.18) -- the same stale-header class as the three + // parameters above. Hard-coded `DeltaParams::default()` here until this + // lane, which desyncs the encoder's own trial decode at the first + // superblock the moment its header sets `delta_q_present`. + delta: DeltaParams, fctx: &crate::decode::FrameCtx, ) -> Result { decode_inter_frame_tile_with_cdfs( @@ -34284,7 +34293,7 @@ pub(crate) fn decode_inter_frame_tiles_lr( switchable_motion_mode, allow_warped_motion, allow_screen_content_tools, - DeltaParams::default(), + delta, enable_filter_intra, None, fctx, @@ -38916,6 +38925,7 @@ mod tests { // lane-fintra: the sequence bit the encoder wrote this tile // under -- same stale-header class as the warp bit above. crate::encode::filter_intra_on(), + frame.delta.clone(), fctx, ) .unwrap(); @@ -39260,6 +39270,7 @@ mod tests { // lane-fintra: the sequence bit the encoder wrote this tile // under -- same stale-header class as the warp bit above. crate::encode::filter_intra_on(), + frame.delta.clone(), fctx, ) .unwrap(); diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 9138ab32..fb586165 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1073,6 +1073,7 @@ pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> En loop_filter: encoded.loop_filter, loop_restoration: encoded.loop_restoration, allow_intrabc: encoded.allow_intrabc, + delta: encoded.delta.clone(), cdef: encoded.cdef, } } @@ -1163,6 +1164,12 @@ pub struct Encoded { /// guessed `false` would desync at the first block (same class as /// `screen`/`tx_select`). pub(crate) allow_intrabc: bool, + /// This frame header's `delta_q_params`/`delta_lf_params` (spec + /// 5.9.17/5.9.18) -- with `delta_q_present` every superblock's first + /// coded block carries a `delta_qindex` symbol group, so a raw tile + /// decode that guessed the defaults desyncs at the first superblock + /// (same class as `screen`/`tx_select`). + pub(crate) delta: ec_av1_syntax::DeltaParams, } thread_local! { @@ -6858,6 +6865,7 @@ pub(crate) fn encode_key_frame_inner( cdef: header.cdef, loop_restoration: header.loop_restoration, allow_intrabc, + delta: header.delta.clone(), }) } @@ -8850,6 +8858,105 @@ fn search_inter_block( /// it costs 1.5 ms per 1920x1024 frame against a ~0.8 s encode (0.2%). const TPL_STRENGTH: f64 = 0.5; +/// lane-deltaq: the per-superblock quantizer, `delta_q_present` (spec +/// 5.9.17/5.11.10). `EC_AV1_DELTAQ=0` switches it off (the stream is then +/// byte-identical to the pre-lane one); anything else is the `delta_q_res` +/// LOG2, so `2` is a step of 4 and `3` a step of 8. `None` = off. +/// +/// A frame with no tpl map (no lookahead picture, or `EC_AV1_TPL=0`) has +/// nothing to vary the quantizer BY and codes no delta syntax at all. +fn deltaq_res_log2() -> Option { + match crate::envflags::var("EC_AV1_DELTAQ").ok().as_deref().map(str::trim) { + Some("0") => None, + Some(v) => v.parse::().ok().filter(|r| *r <= 3), + None => Some(crate::speed::at(&crate::speed::DELTAQ_RES)).filter(|r| *r < 4), + } +} + +/// How much of the derived qindex step is actually taken +/// (`EC_AV1_DELTAQ_K`, default 1.0 = the full derivation). +fn deltaq_k() -> f64 { + crate::envflags::var("EC_AV1_DELTAQ_K") + .ok() + .and_then(|v| v.trim().parse::().ok()) + .filter(|k| k.is_finite() && *k >= 0.0) + .unwrap_or(1.0) +} + +/// The largest qindex the map may move a superblock by, either way +/// (`EC_AV1_DELTAQ_CLAMP`, default 16 -- libaom clamps its own objective +/// deltaq around a quarter of the base qindex). +fn deltaq_clamp() -> i32 { + crate::envflags::var("EC_AV1_DELTAQ_CLAMP") + .ok() + .and_then(|v| v.trim().parse::().ok()) + .filter(|c| (0..=63).contains(c)) + .unwrap_or(16) +} + +/// The qindex a lambda factor `f` asks for, derived rather than fitted. +/// +/// The tpl map hands out a factor on LAMBDA, and RD lambda goes as the +/// square of the quantizer step (`encode_inter_frame`'s own +/// `lambda = .. * step * step`), so the step this superblock wants is +/// `sqrt(f)` times the frame's. `ac_q` is not linear in the index, so the +/// step ratio is inverted through the table itself -- the index whose `ac_q` +/// is closest to `ac_q(base) * sqrt(f)` -- rather than through a fitted +/// constant. `k` scales the resulting step (1.0 takes all of it), `clamp` +/// bounds it, and the answer is snapped onto the `res` grid so that every +/// superblock's qindex is congruent to `base` and the coded delta is a whole +/// number of steps. +fn deltaq_for_factor(base: u8, f: f64, k: f64, clamp: i32, res: i32) -> u8 { + let base_ac = f64::from(ac_q(8, i32::from(base))); + let target = base_ac * f.max(1e-6).sqrt(); + let exact = (1..=255) + .min_by(|&a, &b| { + let d = |q: i32| (f64::from(ac_q(8, q)) - target).abs(); + d(a).partial_cmp(&d(b)).expect("ac_q is finite") + }) + .expect("the qindex range is not empty") + - i32::from(base); + let want = (exact as f64 * k).round() as i32; + // Snapped to the `res` grid BEFORE the clamp: `clamp` is a qindex bound + // and need not be a whole number of steps, and clamping afterwards would + // hand back a qindex that is not congruent to `base`. + let max_steps = clamp / res; + let steps = (want as f64 / f64::from(res)).round() as i32; + let delta = steps.clamp(-max_steps, max_steps) * res; + (i32::from(base) + delta).clamp(1, 255) as u8 +} + +/// How many DISTINCT per-superblock quantizer levels the last inter frame's +/// [`sb_q`](encode_inter_frame) grid carried -- lane-deltaq's fire counter +/// (class `gate-blind-to-feature`: every exactness assert below passes on a +/// grid that is one flat value, i.e. on no delta_q at all). Process-global +/// like [`TX_DEPTH_HITS`], and read through [`take_deltaq_levels`], which +/// keeps the LARGEST count seen since the last read. +static DELTAQ_LEVELS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + +/// [`DELTAQ_LEVELS`], reset to 0. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn take_deltaq_levels() -> usize { + DELTAQ_LEVELS.swap(0, std::sync::atomic::Ordering::Relaxed) +} + +/// This superblock's search state: the quantizer it is coded at, and the +/// lambda that quantizer implies. RD lambda goes as the square of the step, +/// which is exactly the relation [`deltaq_for_factor`] inverted, so with no +/// `sb_q` grid the caller keeps the tpl LAMBDA factor alone (the behaviour +/// before lane-deltaq). +fn sb_q_search<'m>( + sb_q: &[u8], + sb_cols: usize, + base_q_idx: u8, + (sb_r, sb_c): (usize, usize), + base: Search<'m>, +) -> Search<'m> { + let q = sb_q[sb_r * sb_cols + sb_c]; + let ratio = f64::from(ac_q(8, i32::from(q))) / f64::from(ac_q(8, i32::from(base_q_idx))); + Search { base_q_idx: q, lambda: base.lambda * ratio * ratio, ..base } +} + fn tpl_strength() -> f64 { std::env::var("EC_AV1_TPL") .ok() @@ -9516,6 +9623,47 @@ pub(crate) fn encode_inter_frame( let (cols, rows) = crate::tile::block_grid(header.mi_cols, header.mi_rows); let (cols, rows) = (cols as usize, rows as usize); let (sb_cols, _sb_rows) = (cols.div_ceil(2), rows.div_ceil(2)); + // lane-deltaq: one absolute qindex per 64x64 superblock, from the same + // tpl map the lambda factor comes from ([`deltaq_for_factor`]). Present + // only when the map is, and `delta_q_res` follows straight into the frame + // header (`write_delta_q_params`) and into the tile writer's own plan. + let deltaq_res: Option = tpl_factors + .as_ref() + .and(deltaq_res_log2().map(|r| 1i32 << r)); + let sb_q: Option> = match (&tpl_factors, deltaq_res) { + (Some(f), Some(res)) => { + let (k, clamp) = (deltaq_k(), deltaq_clamp()); + Some( + (0..sb_cols * _sb_rows) + .map(|sb| { + let (sb_r, sb_c) = (sb / sb_cols, sb % sb_cols); + // The same 16-cell mean the superblock's own lambda + // takes, clamped to the map the frame actually has. + let mean = (0..16) + .map(|i| { + let (cy, cx) = (sb_r * 4 + i / 4, sb_c * 4 + i % 4); + f[(cy.min(f.len() / tpl_cells_x - 1)) * tpl_cells_x + + cx.min(tpl_cells_x - 1)] + }) + .sum::() + / 16.0; + deltaq_for_factor(base_q_idx, mean, k, clamp, res) + }) + .collect(), + ) + } + _ => None, + }; + if let Some(res) = deltaq_res.filter(|_| sb_q.is_some()) { + header.delta.q_present = true; + header.delta.q_res = res.trailing_zeros() as u8; + } + if let Some(g) = &sb_q { + let mut levels: Vec = g.clone(); + levels.sort_unstable(); + levels.dedup(); + DELTAQ_LEVELS.fetch_max(levels.len(), std::sync::atomic::Ordering::Relaxed); + } let (mi_cols, mi_rows) = (header.mi_cols as usize, header.mi_rows as usize); // This frame's tile grid, as in `encode_key_frame_inner`. let (tile_cols_log2, tile_rows_log2) = armed_tiles(); @@ -9607,6 +9755,10 @@ pub(crate) fn encode_inter_frame( // comparison below weighs one cost against four, so both sides // have to be priced at the same lambda. let sb_search = match &tpl_factors { + // lane-deltaq: with a per-superblock quantizer the lambda + // comes from that quantizer, not from the raw map factor -- + // the two agree exactly at `EC_AV1_DELTAQ_K=1` unclamped. + Some(_) if sb_q.is_some() => sb_q_search(sb_q.as_ref().expect("armed"), sb_cols, base_q_idx, (sb_r, sb_c), search), Some(f) if sb64_legal => { let mean = (0..16) .map(|i| f[(sb_r * 4 + i / 4) * tpl_cells_x + sb_c * 4 + i % 4]) @@ -9705,6 +9857,12 @@ pub(crate) fn encode_inter_frame( // one 32x32 cost against four 16x16 ones: a per-leaf lambda // would make those two numbers incomparable. let search = match &tpl_factors { + // lane-deltaq: the quantizer is a SUPERBLOCK-level + // symbol, so all four quadrants take their superblock's + // own qindex and the lambda it implies. No granularity is + // lost: the shipped map (`EC_AV1_TPL_SB`) is already one + // factor per superblock, shared by its sixteen cells. + Some(_) if sb_q.is_some() => sb_q_search(sb_q.as_ref().expect("armed"), sb_cols, base_q_idx, (sb_r, sb_c), search), Some(f) => { let mean = (0..4) .map(|i| f[(r32 * 2 + i / 2) * tpl_cells_x + c32 * 2 + i % 2]) @@ -10205,6 +10363,12 @@ pub(crate) fn encode_inter_frame( -> Result>> { let (out, stored) = write_tiles(layout.count(), store_tile, |index| { crate::tile::arm_cdef_idx(bits, sb_cols, cdef_grid.to_vec()); + crate::tile::arm_delta_q( + deltaq_res.filter(|_| sb_q.is_some()).unwrap_or(0), + sb_cols, + sb_q.clone().unwrap_or_default(), + base_q_idx, + ); crate::tile::arm_lr(64, lr_horz, lr_vert, units.to_vec()); crate::tile::arm_sign_bias(sign_bias); // Thread-locals: every tile job arms its own worker. @@ -10341,6 +10505,10 @@ pub(crate) fn encode_inter_frame( switchable_motion_mode, h.allow_warped_motion, seq.enable_filter_intra, + // lane-deltaq: this frame's own delta_q/delta_lf params, so + // the trial decode reads the per-superblock `delta_qindex` + // syntax the writer just wrote. + h.delta.clone(), fctx, ) }, @@ -10383,6 +10551,7 @@ pub(crate) fn encode_inter_frame( // An inter frame never allows intrabc (spec 5.9.2 codes the bit on // intra frames only). allow_intrabc: false, + delta: header.delta.clone(), }) } diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index c1e0b372..54e2f9be 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -3466,6 +3466,79 @@ mod tests { } } + /// lane-deltaq's three-way witness: a clip with a real gradient of tpl + /// factors -- a moving detail region over a flat background, so the + /// superblocks the NEXT picture predicts from are worth more than the + /// ones it does not -- codes at least two distinct per-superblock + /// quantizer levels (the fire count, class `gate-blind-to-feature`), and + /// both decoders reconstruct every frame sample-exact from the + /// `delta_qindex` syntax that carries them. + #[test] + fn a_moving_detail_clip_codes_two_delta_q_levels_both_decoders_read_exactly() { + let _knobs = crate::speed::knob_read(); + let _gate_lock = crate::stream::tests::lock_gate_counters(); + let (width, height) = (640usize, 384usize); + // The gate's own moving test card, with a 128x128 patch of fine + // detail travelling right by 32 samples a frame laid over it: the + // patch is what the tpl pass finds worth propagating and the card + // around it is not, so the map -- and with it the quantizer grid -- + // is a gradient and not one flat number. + let sources: Vec = (0..4) + .map(|t| { + let mut p = test_card(width, height, t * 3); + let x0 = 32 + t * 32; + for y in 128..256 { + for x in x0..x0 + 128 { + p.y[y * width + x] = + if (x / 2 + y / 3) % 2 == 0 { 40 } else { 210 }; + } + } + p + }) + .collect(); + let config = EncoderConfig { + width, + height, + base_q_idx: 120, + gop: 4, + colour: Colour::Bt709Limited, + tile_cols_log2: 0, + tile_rows_log2: 0, + }; + let mut enc = Av1Encoder::new(config).unwrap(); + let _ = crate::encode::take_deltaq_levels(); + let mut stream = Vec::new(); + for packet in encode_all(&mut enc, &sources) { + stream.extend_from_slice(&packet.data); + } + let levels = crate::encode::take_deltaq_levels(); + assert!( + levels >= 2, + "the quantizer grid was flat ({levels} level(s)): no delta_qindex was coded" + ); + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); + if have_ffmpeg() { + let theirs = ffmpeg_decode_luma(&stream, width, height); + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { + let got: Vec = a.y.iter().map(|&v| v as u8).collect(); + if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) { + panic!( + "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}", + at % width, + at / width, + got[at], + b[at], + ); + } + } + } else { + eprintln!("SKIP the ffmpeg half: no ffmpeg"); + } + eprintln!("delta_q witness: {levels} quantizer levels, {} bytes", stream.len()); + } + /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from /// its neighbour (a preset that changes no byte is a preset that buys no diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index e772520f..a3fa4cd8 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -169,6 +169,11 @@ pub(crate) fn at(table: &[T; 11]) -> T { /// (screen). So it is on at every preset. pub(crate) const B64_ROOT: [bool; 11] = [crate::encode::B64_ROOT; 11]; +/// `encode::deltaq_res_log2`: the per-superblock quantizer's `delta_q_res` +/// LOG2 (2 = a step of 4 qindex), or `4` for "no delta_q syntax at all". +/// It rides the tpl map, which every preset that keeps the map keeps. +pub(crate) const DELTAQ_RES: [u8; 11] = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]; + /// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split /// trial is withheld. The single biggest wall lever in the tile search. pub(crate) const SPLIT_RD: [f64; 11] = [ diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 46974372..f914606f 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -282,6 +282,39 @@ pub(crate) fn arm_cdef_idx(bits: u8, sb_cols: usize, grid: Vec) { }); } +/// One frame's per-superblock quantizer plan (lane-deltaq, see +/// [`arm_delta_q`]): the writer side of decode.rs `maybe_read_delta_q`. +struct DeltaQPlan { + /// `1 << delta_q_res`, the multiplier the coded symbol is scaled by -- + /// every `grid` entry is congruent to `base` modulo it, so the delta the + /// writer codes is always a whole number of steps. + res: i32, + /// Superblocks per row, the stride of `grid`. + sb_cols: usize, + /// The absolute `qindex` each 64x64 superblock is coded at, raster order. + grid: Vec, + /// The spec's `CurrentQIndex`, carried across the superblocks of THIS + /// tile -- armed at the frame's `base_q_idx` because a tile writer is + /// armed once per tile (`encode_inter_frame`'s `code_tiles`), which is + /// exactly the spec's own per-tile reset. + cur: i32, +} + +thread_local! { + static DELTA_Q: std::cell::RefCell> = + const { std::cell::RefCell::new(None) }; +} + +/// Arms the next tile write with one absolute `qindex` per 64x64 superblock. +/// Disarmed (a plain no-op writer, byte for byte what this crate wrote before +/// lane-deltaq) when `res == 0`. +pub(crate) fn arm_delta_q(res: i32, sb_cols: usize, grid: Vec, base: u8) { + DELTA_Q.with(|c| { + *c.borrow_mut() = + (res > 0).then(|| DeltaQPlan { res, sb_cols, grid, cur: i32::from(base) }); + }); +} + thread_local! { static SIGN_BIAS: std::cell::Cell = const { std::cell::Cell::new(crate::mvstack::NO_SIGN_BIAS) }; @@ -1004,6 +1037,7 @@ struct CdefIdxGuard; impl Drop for CdefIdxGuard { fn drop(&mut self) { CDEF_IDX.with(|c| *c.borrow_mut() = None); + DELTA_Q.with(|c| *c.borrow_mut() = None); LR_PLAN.with(|c| *c.borrow_mut() = None); SIGN_BIAS.with(|c| c.set(crate::mvstack::NO_SIGN_BIAS)); SCREEN.with(|c| c.set(false)); @@ -1039,6 +1073,55 @@ fn write_cdef_idx(enc: &mut SymbolEncoder, mi: (usize, usize), skip: bool) { }); } +/// `read_delta_qindex`'s write side (spec 5.11.10), called right after every +/// block's [`write_cdef_idx`] -- the spec's own `skip -> cdef -> delta_q` +/// order, and decode.rs `maybe_read_delta_q` is the reader this mirrors +/// symbol for symbol. A no-op unless this block sits at its superblock's own +/// top-left mode-info position, and (the one case the reader skips too) when +/// that block IS the whole superblock and is skipped, in which case +/// `CurrentQIndex` carries over unchanged on both sides. +fn write_delta_q( + enc: &mut SymbolEncoder, + cdfs: &mut Cdfs, + mi: (usize, usize), + is_whole_sb: bool, + skip: bool, +) { + DELTA_Q.with(|c| { + let mut plan = c.borrow_mut(); + let Some(plan) = plan.as_mut() else { return }; + if mi.0 % SB_MI as usize != 0 || mi.1 % SB_MI as usize != 0 { + return; + } + if is_whole_sb && skip { + return; + } + let sb = (mi.0 / SB_MI as usize) * plan.sb_cols + (mi.1 / SB_MI as usize); + let target = i32::from(plan.grid.get(sb).copied().unwrap_or(0)); + // `reduced` is the spec's `delta_q_abs`/`delta_q_sign_bit` pair: the + // step count, not the qindex difference. + let reduced = (target - plan.cur) / plan.res; + let abs = reduced.unsigned_abs() as usize; + /// spec `DELTA_Q_SMALL`: the largest `delta_q_abs` symbol that is not + /// an escape into the literal pair below. + const DELTA_Q_SMALL: usize = 3; + enc.symbol(abs.min(DELTA_Q_SMALL), &mut cdfs.delta_q); + if abs >= DELTA_Q_SMALL { + // libaom `write_delta_qindex`: `rem_bits = get_msb(abs - 1)`, + // written one less in three bits, and the value offset by the + // threshold `(1 << rem_bits) + 1` the reader adds back. + let rem_bits = 31 - ((abs as u32) - 1).leading_zeros(); + let thr = (1u32 << rem_bits) + 1; + enc.literal(rem_bits - 1, 3); + enc.literal(abs as u32 - thr, rem_bits); + } + if abs != 0 { + enc.literal(u32::from(reduced < 0), 1); + } + plan.cur = (plan.cur + reduced * plan.res).clamp(1, 255); + }); +} + /// round-4 av1-truesize debugging aid: prints `msg()` to stderr when the /// `EC_RNG` environment variable is set, mirroring the `EC_PART`/`EC_TOK` /// trace `/tmp/libaom-src`'s debug `aomdec` build already emits under the @@ -5659,6 +5742,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( + usize::from(neighbours.left_skip[mi_r]); enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); write_cdef_idx(&mut enc, (mi_r, mi_c), block.skip); + write_delta_q(&mut enc, &mut cdfs, (mi_r, mi_c), true, block.skip); let ii_ctx = intra_inter_ctx( has_above, has_left, @@ -6054,6 +6138,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( + usize::from(neighbours.left_skip[mi_r]); enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); write_cdef_idx(&mut enc, (mi_r, mi_c), block.skip); + write_delta_q(&mut enc, &mut cdfs, (mi_r, mi_c), false, block.skip); let is_inter = block.inter.is_some(); let (above_inter, left_inter) = @@ -6314,6 +6399,7 @@ fn write_inter_frame_leaf( let skip_ctx = usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]); enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); write_cdef_idx(enc, (mi_r, mi_c), block.skip); + write_delta_q(enc, cdfs, (mi_r, mi_c), false, block.skip); let (has_above, has_left) = (neighbours.has_above(mi_r), neighbours.has_left(mi_c)); let (above_inter, left_inter) = (neighbours.above_inter[mi_c], neighbours.left_inter[mi_r]); @@ -6564,6 +6650,7 @@ fn write_inter_frame_leaf8( let skip_ctx = usize::from(above_skip) + usize::from(left_skip); enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); write_cdef_idx(enc, leaf_mi, block.skip); + write_delta_q(enc, cdfs, leaf_mi, false, block.skip); let (has_above, has_left) = (neighbours.has_above(leaf_mi.0), neighbours.has_left(leaf_mi.1)); let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);