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 {
557 header.refresh.sign_bias_altref,557 header.refresh.sign_bias_altref,
558 ];558 ];
559 559
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+
560 // Phase 1: every mode record of the frame, row-major (§16).564 // Phase 1: every mode record of the frame, row-major (§16).
561 eprintln!("STAGE modes");565 eprintln!("STAGE modes");
562 for row in 1..=self.mb_rows {566 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
356 for i in 0..3 {356 for i in 0..3 {
357 x += i32::from(d.read_bool(probs[MVP_BITS + i])) << i;357 x += i32::from(d.read_bool(probs[MVP_BITS + i])) << i;
358 }358 }
359- let mut i = 8;359+ let mut i = 9;
360 loop {360 loop {
361 x += i32::from(d.read_bool(probs[MVP_BITS + i])) << i;361 x += i32::from(d.read_bool(probs[MVP_BITS + i])) << i;
362 i -= 1;362 i -= 1;
crates/ec-vp8/src/tokens.rsmodified+6 -0
@@ -268,7 +268,13 @@ pub(crate) fn decode_mb_tokens(
268 let n0 = usize::from($ptype == 0);268 let n0 = usize::from($ptype == 0);
269 let (l, a) = ctxs.ctx_pair(mb_col, $idx);269 let (l, a) = ctxs.ctx_pair(mb_col, $idx);
270 let ctx = (usize::from(l) + usize::from(a)).min(2);270 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+ }
271 let eob = get_coeffs(bc, &probs[$ptype], ctx, n0, $dc, $ac, $slot);274 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+ }
272 out.eobs[$idx] = eob as u8;278 out.eobs[$idx] = eob as u8;
273 let t = u8::from(eob > 0);279 let t = u8::from(eob > 0);
274 ctxs.set_ctx(mb_col, $idx, t);280 ctxs.set_ctx(mb_col, $idx, t);
scripts/vp8ref_model.pymodified+3 -1
@@ -299,7 +299,7 @@ def main():
299 x = 0299 x = 0
300 for i in range(3):300 for i in range(3):
301 x += d.bool(p[9 + i]) << i301 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):
303 x += d.bool(p[9 + i]) << i303 x += d.bool(p[9 + i]) << i
304 if (x & 0xFFF0) == 0 or d.bool(p[9 + 3]):304 if (x & 0xFFF0) == 0 or d.bool(p[9 + 3]):
305 x += 8305 x += 8
@@ -610,8 +610,10 @@ def main():
610 def one(blkidx, ptype, n0):610 def one(blkidx, ptype, n0):
611 o = [0] * 16611 o = [0] * 16
612 ctxv = min(2, left_ctx[LEFT[blkidx]] + above_ctx[c - 1][ABOVE[blkidx]])612 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]]}")
613 print(f"T {r-1} {c-1} {blkidx} {ptype} {ctxv}")614 print(f"T {r-1} {c-1} {blkidx} {ptype} {ctxv}")
614 eob = get_coeffs(ptype, n0, ctxv, o)615 eob = get_coeffs(ptype, n0, ctxv, o)
616+ print(f"TBE {blkidx} eob={eob}")
615 t = 1 if eob > 0 else 0617 t = 1 if eob > 0 else 0
616 left_ctx[LEFT[blkidx]] = t618 left_ctx[LEFT[blkidx]] = t
617 above_ctx[c - 1][ABOVE[blkidx]] = t619 above_ctx[c - 1][ABOVE[blkidx]] = t