forge
Explore
Log in

Don't you dare go Hollow

ec-vp8 M3: long MV components read bits 9,8,7,6,5,4 (mvlong_width=10) — bit 9 was missing

Browse files at this commit

d5796e3313c9d3b8813b77eb268664c2d729d51cAhmet Kaan GümüşParent: 12884f5
RFC 6386 §17.1 and libvpx read SIX long-form bits (9 down to 4) before
the sometimes-implicit bit 3; the port read only five (8..4), so every
large motion vector decoded as garbage while short MVs and ZEROMV
stayed correct. gop-160x96 frame 1: 51% -> 95.3% pixel match; frames
0-3 of gop and clip-obs now byte-exact vs ffmpeg. Remaining divergence
from frame 4 onward is the next M3 target.
crates/ec-vp8/src/decode.rsmodified+4 -0
@@ -557,6 +557,10 @@ impl Decoder {
557557 header.refresh.sign_bias_altref,
558558 ];
559559
560+ // §13.3: non-existent neighbours are empty — the above context
561+ // is cleared at every frame start, like the key-frame path.
562+ self.token_ctxs.reset_above_row();
563+
560564 // Phase 1: every mode record of the frame, row-major (§16).
561565 eprintln!("STAGE modes");
562566 for row in 1..=self.mb_rows {
crates/ec-vp8/src/modes.rsmodified+1 -1
@@ -356,7 +356,7 @@ pub fn read_mv_component(d: &mut BoolDecoder<'_>, probs: &[u8; MVP_COUNT]) -> i1
356356 for i in 0..3 {
357357 x += i32::from(d.read_bool(probs[MVP_BITS + i])) << i;
358358 }
359- let mut i = 8;
359+ let mut i = 9;
360360 loop {
361361 x += i32::from(d.read_bool(probs[MVP_BITS + i])) << i;
362362 i -= 1;
crates/ec-vp8/src/tokens.rsmodified+6 -0
@@ -268,7 +268,13 @@ pub(crate) fn decode_mb_tokens(
268268 let n0 = usize::from($ptype == 0);
269269 let (l, a) = ctxs.ctx_pair(mb_col, $idx);
270270 let ctx = (usize::from(l) + usize::from(a)).min(2);
271+ if std::env::var_os("EC_VP8_TRACE").is_some() {
272+ eprintln!("TB {} ctx={} l={} a={}", $idx, ctx, l, a);
273+ }
271274 let eob = get_coeffs(bc, &probs[$ptype], ctx, n0, $dc, $ac, $slot);
275+ if std::env::var_os("EC_VP8_TRACE").is_some() {
276+ eprintln!("TBE {} eob={}", $idx, eob);
277+ }
272278 out.eobs[$idx] = eob as u8;
273279 let t = u8::from(eob > 0);
274280 ctxs.set_ctx(mb_col, $idx, t);
scripts/vp8ref_model.pymodified+3 -1
@@ -299,7 +299,7 @@ def main():
299299 x = 0
300300 for i in range(3):
301301 x += d.bool(p[9 + i]) << i
302- for i in (8, 7, 6, 5, 4):
302+ for i in (9, 8, 7, 6, 5, 4):
303303 x += d.bool(p[9 + i]) << i
304304 if (x & 0xFFF0) == 0 or d.bool(p[9 + 3]):
305305 x += 8
@@ -610,8 +610,10 @@ def main():
610610 def one(blkidx, ptype, n0):
611611 o = [0] * 16
612612 ctxv = min(2, left_ctx[LEFT[blkidx]] + above_ctx[c - 1][ABOVE[blkidx]])
613+ print(f"TB {blkidx} ctx={ctxv} l={left_ctx[LEFT[blkidx]]} a={above_ctx[c - 1][ABOVE[blkidx]]}")
613614 print(f"T {r-1} {c-1} {blkidx} {ptype} {ctxv}")
614615 eob = get_coeffs(ptype, n0, ctxv, o)
616+ print(f"TBE {blkidx} eob={eob}")
615617 t = 1 if eob > 0 else 0
616618 left_ctx[LEFT[blkidx]] = t
617619 above_ctx[c - 1][ABOVE[blkidx]] = t