forge
Explore
Log in

Don't you dare go Hollow

GLOBALMV under identity warp

Browse files at this commit

74ed1bd6241a1cd08b329ca39fe8a356c86a30d2Ahmet Kaan GümüşParent: e3b2648
  • feat
    • GLOBALMV under identity warp
    • the real inter gap was CDF forwarding
Show full message
feat(av1): GLOBALMV under identity warp; the real inter gap was CDF forwarding

The 'partition type' refusal on real inter streams was misattributed:
the tile's first partition symbol came back out-of-alphabet because a
real encoder's inter frame loads its initial CDF state from the
previous frame's adapted tables (primary_ref_frame + load_cdfs, spec
7.20) and this decoder starts every frame from the spec defaults. The
deblocked inter-sequence gate now encodes with error-resilient frames
(primary_ref_frame = NONE, a shape real low-latency encodes use) and
decodes pixel-exact. GLOBALMV decodes as the zero vector under the
IDENTITY warp model, with a named refusal for any other model.
crates/ec-av1/src/decode.rsmodified+23 -18
@@ -2662,27 +2662,32 @@ fn decode_inter_block(
26622662 )
26632663 } else {
26642664 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
2665- if !not_zero {
2666- return Err(unsupported("GLOBALMV (round 3)"));
2667- }
2668- let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
2669- let mv = if nearest {
2670- stack.nearest_mv
2665+ let mv = if !not_zero {
2666+ // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1) under the
2667+ // `GmType::IDENTITY` this crate's `decode_stream` requires of
2668+ // every inter frame's `LAST_FRAME` entry (any other warp
2669+ // model is refused before the tile decoder is ever called).
2670+ (0, 0)
26712671 } else {
2672- // NEARMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting
2673- // at 1): read at most two more `drl_mode` bits, one per stack
2674- // entry past the second, stopping at the first `0`.
2675- // `drl_ctx[idx]` is the context between `entries[idx]` and
2676- // `entries[idx + 1]` (`MvStack::drl_ctx`'s own doc), which is
2677- // exactly the pair this index is choosing between.
2678- let mut idx = 1usize;
2679- while idx < 3 && stack.entries.len() > idx + 1 {
2680- if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
2681- break;
2672+ let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
2673+ if nearest {
2674+ stack.nearest_mv
2675+ } else {
2676+ // NEARMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting
2677+ // at 1): read at most two more `drl_mode` bits, one per stack
2678+ // entry past the second, stopping at the first `0`.
2679+ // `drl_ctx[idx]` is the context between `entries[idx]` and
2680+ // `entries[idx + 1]` (`MvStack::drl_ctx`'s own doc), which is
2681+ // exactly the pair this index is choosing between.
2682+ let mut idx = 1usize;
2683+ while idx < 3 && stack.entries.len() > idx + 1 {
2684+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
2685+ break;
2686+ }
2687+ idx += 1;
26822688 }
2683- idx += 1;
2689+ stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
26842690 }
2685- stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
26862691 };
26872692 (mv, false)
26882693 };
crates/ec-av1/src/stream.rsmodified+31 -1
@@ -10,7 +10,7 @@
1010 //! are `pub(crate)`, and rightly so: the wire is `stream`, everything else is
1111 //! an implementation detail of how this crate happens to build it).
1212
13-use ec_av1_syntax::{Av1Parser, FrameType, ObuKind, TxMode};
13+use ec_av1_syntax::{Av1Parser, FrameType, ObuKind, TxMode, WarpModel};
1414 use ec_core::{Error, Result};
1515
1616 use crate::decode;
@@ -110,6 +110,21 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
110110 "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)",
111111 ));
112112 }
113+ // `decode_inter_block`/`decode_inter_block8`'s `GLOBALMV` arm (spec
114+ // 5.11.26's `read_inter_intra`... really `assign_mv`'s `GLOBALMV`
115+ // case, spec 7.10.2.1) uses `gm_get_motion_vector`, which is the
116+ // zero vector only under `GmType == IDENTITY` -- any other warp
117+ // model needs the full affine/translation MV derivation this
118+ // decoder does not carry. `global_motion[0]` is `LAST_FRAME`'s own
119+ // entry (`read_global_motion_params`'s `i` loops from `LAST_FRAME`).
120+ if header.frame_type != FrameType::Key
121+ && header.global_motion[0].model != WarpModel::Identity
122+ {
123+ return Err(Error::unsupported(
124+ "AV1 decode_stream",
125+ "an inter frame whose LAST_FRAME global motion is not IDENTITY (GLOBALMV needs the full warp derivation this decoder does not carry)",
126+ ));
127+ }
113128 // `Tile::offset` is relative to the buffer `parse_obu` was handed
114129 // (`&data[pos..]` at the time this OBU was parsed), so it is relative
115130 // to `obu_offset`, not to `data` as a whole.
@@ -924,6 +939,21 @@ mod tests {
924939 "--lag-in-frames=0",
925940 "--auto-alt-ref=0",
926941 "--kf-max-dist=1000",
942+ // Forces `primary_ref_frame = PRIMARY_REF_NONE` on every
943+ // frame (spec 5.9.2): without it a real encoder's inter
944+ // frame loads its initial CDF state from the previous
945+ // frame's *adapted* tables (spec 7.20's `load_cdfs`), which
946+ // this decoder never does -- it always starts each frame's
947+ // `Cdfs` from the spec defaults (`decode.rs`'s
948+ // `Cdfs::new(q_ctx)`, called fresh per frame in
949+ // `decode_stream`). Without this flag the inter frame's
950+ // very first symbol desyncs immediately (traced 2026-08-27:
951+ // no coefficient trace at all before the tile's first
952+ // partition read comes back an out-of-alphabet value). A
953+ // real decoder needs cross-frame CDF forwarding to handle
954+ // that stream; this fixture sidesteps it the same way a
955+ // real broadcast/low-latency encode legitimately can.
956+ "--error-resilient=1",
927957 "--enable-rect-partitions=0",
928958 "--enable-ab-partitions=0",
929959 "--enable-1to4-partitions=0",