Merge branch 'lane-av1interpart': GLOBALMV, and the inter gap named
Browse files at this commit2 changed files +54 -19
- crates/ec-av1/src/decode.rs +23 -18
- crates/ec-av1/src/stream.rs +31 -1
crates/ec-av1/src/decode.rsmodified+23 -18
| @@ -2662,27 +2662,32 @@ fn decode_inter_block( | |||
| 2662 | ) | 2662 | ) |
| 2663 | } else { | 2663 | } else { |
| 2664 | let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; | 2664 | let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; |
| 2665 | - if !not_zero { | 2665 | + let mv = if !not_zero { |
| 2666 | - return Err(unsupported("GLOBALMV (round 3)")); | 2666 | + // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1) under the |
| 2667 | - } | 2667 | + // `GmType::IDENTITY` this crate's `decode_stream` requires of |
| 2668 | - let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; | 2668 | + // every inter frame's `LAST_FRAME` entry (any other warp |
| 2669 | - let mv = if nearest { | 2669 | + // model is refused before the tile decoder is ever called). |
| 2670 | - stack.nearest_mv | 2670 | + (0, 0) |
| 2671 | } else { | 2671 | } else { |
| 2672 | - // NEARMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting | 2672 | + let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; |
| 2673 | - // at 1): read at most two more `drl_mode` bits, one per stack | 2673 | + if nearest { |
| 2674 | - // entry past the second, stopping at the first `0`. | 2674 | + stack.nearest_mv |
| 2675 | - // `drl_ctx[idx]` is the context between `entries[idx]` and | 2675 | + } else { |
| 2676 | - // `entries[idx + 1]` (`MvStack::drl_ctx`'s own doc), which is | 2676 | + // NEARMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting |
| 2677 | - // exactly the pair this index is choosing between. | 2677 | + // at 1): read at most two more `drl_mode` bits, one per stack |
| 2678 | - let mut idx = 1usize; | 2678 | + // entry past the second, stopping at the first `0`. |
| 2679 | - while idx < 3 && stack.entries.len() > idx + 1 { | 2679 | + // `drl_ctx[idx]` is the context between `entries[idx]` and |
| 2680 | - if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { | 2680 | + // `entries[idx + 1]` (`MvStack::drl_ctx`'s own doc), which is |
| 2681 | - break; | 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; | ||
| 2682 | } | 2688 | } |
| 2683 | - idx += 1; | 2689 | + stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) |
| 2684 | } | 2690 | } |
| 2685 | - stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) | ||
| 2686 | }; | 2691 | }; |
| 2687 | (mv, false) | 2692 | (mv, false) |
| 2688 | }; | 2693 | }; |
crates/ec-av1/src/stream.rsmodified+31 -1
| @@ -10,7 +10,7 @@ | |||
| 10 | //! are `pub(crate)`, and rightly so: the wire is `stream`, everything else is | 10 | //! are `pub(crate)`, and rightly so: the wire is `stream`, everything else is |
| 11 | //! an implementation detail of how this crate happens to build it). | 11 | //! an implementation detail of how this crate happens to build it). |
| 12 | 12 | ||
| 13 | -use ec_av1_syntax::{Av1Parser, FrameType, ObuKind, TxMode}; | 13 | +use ec_av1_syntax::{Av1Parser, FrameType, ObuKind, TxMode, WarpModel}; |
| 14 | use ec_core::{Error, Result}; | 14 | use ec_core::{Error, Result}; |
| 15 | 15 | ||
| 16 | use crate::decode; | 16 | use crate::decode; |
| @@ -110,6 +110,21 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 110 | "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", | 110 | "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", |
| 111 | )); | 111 | )); |
| 112 | } | 112 | } |
| 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 | + } | ||
| 113 | // `Tile::offset` is relative to the buffer `parse_obu` was handed | 128 | // `Tile::offset` is relative to the buffer `parse_obu` was handed |
| 114 | // (`&data[pos..]` at the time this OBU was parsed), so it is relative | 129 | // (`&data[pos..]` at the time this OBU was parsed), so it is relative |
| 115 | // to `obu_offset`, not to `data` as a whole. | 130 | // to `obu_offset`, not to `data` as a whole. |
| @@ -924,6 +939,21 @@ mod tests { | |||
| 924 | "--lag-in-frames=0", | 939 | "--lag-in-frames=0", |
| 925 | "--auto-alt-ref=0", | 940 | "--auto-alt-ref=0", |
| 926 | "--kf-max-dist=1000", | 941 | "--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", | ||
| 927 | "--enable-rect-partitions=0", | 957 | "--enable-rect-partitions=0", |
| 928 | "--enable-ab-partitions=0", | 958 | "--enable-ab-partitions=0", |
| 929 | "--enable-1to4-partitions=0", | 959 | "--enable-1to4-partitions=0", |