Merge branch 'lane-motionmode': decode OBMC motion mode (SIMPLE vs OBMC_CAUSAL)
Browse files at this commit4 changed files +937 -0
- crates/ec-av1/src/cdf.rs +13 -0
- crates/ec-av1/src/cdf_state.rs +11 -0
- crates/ec-av1/src/decode.rs +430 -0
- crates/ec-av1/src/stream.rs +483 -0
crates/ec-av1/src/cdf.rsmodified+13 -0
| @@ -1205,6 +1205,19 @@ pub const SINGLE_REF: [[[u16; 3]; 6]; 3] = [ | ||
| 1205 | 1205 | /// least 8x8 both dims (`is_comp_ref_allowed`) -- lane-av1comp. |
| 1206 | 1206 | pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [8127, 32768, 0]]; |
| 1207 | 1207 | |
| 1208 | +/// `default_obmc_cdf` (spec 9.4): `use_obmc`, by square bsize (`BLOCK_8X8`, | |
| 1209 | +/// `BLOCK_16X16`, `BLOCK_32X32`, `BLOCK_64X64` -- `BLOCK_SIZES_ALL` indices | |
| 1210 | +/// 3/6/9/12, the only sizes this decoder ever codes). Read only once | |
| 1211 | +/// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers | |
| 1212 | +/// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 | |
| 1213 | +/// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. | |
| 1214 | +pub const OBMC: [[u16; 3]; 4] = [ | |
| 1215 | + [10437, 32768, 0], | |
| 1216 | + [17432, 32768, 0], | |
| 1217 | + [25817, 32768, 0], | |
| 1218 | + [30128, 32768, 0], | |
| 1219 | +]; | |
| 1220 | + | |
| 1208 | 1221 | /// `Default_Comp_Mode_Cdf` (spec 9.4, `default_comp_inter_cdf`): whether an |
| 1209 | 1222 | /// inter block reads `SINGLE_REFERENCE` or `COMPOUND_REFERENCE` -- only |
| 1210 | 1223 | /// reached once `read_ref_frames` knows the frame's `reference_select` |
crates/ec-av1/src/cdf_state.rsmodified+11 -0
| @@ -318,6 +318,15 @@ pub(crate) struct Cdfs { | ||
| 318 | 318 | /// Whether a block reads `skip_mode` (lane-av1comp, spec 5.11.29's |
| 319 | 319 | /// `skip_mode`), indexed by `av1_get_skip_mode_context`. |
| 320 | 320 | pub skip_mode: [[u16; 3]; 3], |
| 321 | + /// `use_obmc` (spec 5.11.24's `read_motion_mode`, the `OBMC_CAUSAL`-vs- | |
| 322 | + /// `SIMPLE_TRANSLATION` two-symbol alphabet libaom's `obmc_cdf` reads | |
| 323 | + /// whenever `motion_mode_allowed` can't offer `WARPED_CAUSAL` -- | |
| 324 | + /// lane-motionmode round 1 only reaches this arm, never the three-way | |
| 325 | + /// `motion_mode_cdf`), indexed by this block's own square bsize: 0 = | |
| 326 | + /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` | |
| 327 | + /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- | |
| 328 | + /// this decoder only ever codes those four square sizes). | |
| 329 | + pub obmc: [[u16; 3]; 4], | |
| 321 | 330 | /// Which of the eight `INTER_COMPOUND_MODES` a `COMPOUND_REFERENCE` |
| 322 | 331 | /// block takes (lane-av1comp, spec 5.11.24's `compound_mode`). |
| 323 | 332 | pub inter_compound_mode: [[u16; 9]; 8], |
| @@ -548,6 +557,7 @@ impl Cdfs { | ||
| 548 | 557 | reset3(&mut self.single_ref); |
| 549 | 558 | reset2(&mut self.comp_mode); |
| 550 | 559 | reset2(&mut self.skip_mode); |
| 560 | + reset2(&mut self.obmc); | |
| 551 | 561 | reset2(&mut self.inter_compound_mode); |
| 552 | 562 | reset2(&mut self.comp_ref_type); |
| 553 | 563 | reset3(&mut self.uni_comp_ref); |
| @@ -988,6 +998,7 @@ impl Cdfs { | ||
| 988 | 998 | comp_ref: cdf::COMP_REF, |
| 989 | 999 | comp_bwdref: cdf::COMP_BWDREF, |
| 990 | 1000 | skip_mode: cdf::SKIP_MODE, |
| 1001 | + obmc: cdf::OBMC, | |
| 991 | 1002 | comp_group_idx: cdf::COMP_GROUP_IDX, |
| 992 | 1003 | compound_idx: cdf::COMPOUND_IDX, |
| 993 | 1004 | y_mode: cdf::Y_MODE, |
crates/ec-av1/src/decode.rsmodified+430 -0
| @@ -154,6 +154,28 @@ pub(crate) fn skip_mode_hits() -> usize { | ||
| 154 | 154 | SKIP_MODE_HITS.load(std::sync::atomic::Ordering::Relaxed) |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | +/// lane-motionmode: how many blocks actually decoded `obmc_selected == true` | |
| 158 | +/// (as opposed to just reaching an eligible `read_motion_mode` symbol read) | |
| 159 | +/// -- the gate's own proof that a real aomenc `--enable-obmc=1` stream | |
| 160 | +/// reached [`obmc_blend`], not just the header bit. | |
| 161 | +static OBMC_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 162 | + | |
| 163 | +/// Current value of [`OBMC_HITS`]. | |
| 164 | +pub(crate) fn obmc_hits() -> usize { | |
| 165 | + OBMC_HITS.load(std::sync::atomic::Ordering::Relaxed) | |
| 166 | +} | |
| 167 | + | |
| 168 | +/// lane-motionmode round 3: same proof as [`OBMC_HITS`], narrowed to | |
| 169 | +/// `decode_inter_block8`'s own 8x8-leaf `read_motion_mode` -- a subset of | |
| 170 | +/// [`OBMC_HITS`] (both fire together on an 8x8 hit), lets the gate tell an | |
| 171 | +/// 8x8-leaf OBMC block apart from a 16x16+ one. | |
| 172 | +static OBMC_HITS_8: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 173 | + | |
| 174 | +/// Current value of [`OBMC_HITS_8`]. | |
| 175 | +pub(crate) fn obmc_hits_8() -> usize { | |
| 176 | + OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed) | |
| 177 | +} | |
| 178 | + | |
| 157 | 179 | /// How many [`read_inter_compound_mode`] reads actually happened |
| 158 | 180 | /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own |
| 159 | 181 | /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound |
| @@ -3959,6 +3981,263 @@ fn ref_planes<'a>( | ||
| 3959 | 3981 | } |
| 3960 | 3982 | } |
| 3961 | 3983 | |
| 3984 | +/// libaom `foreach_overlappable_nb_above` (`obmc.h`): walks the mi row | |
| 3985 | +/// directly above this block's own column span, one bordering block at a | |
| 3986 | +/// time (stepping by that neighbour's own `MiInfo::size`, which is always | |
| 3987 | +/// `<= 16` since no block this decoder ever codes exceeds 64x64), collecting | |
| 3988 | +/// every *inter* neighbour found (an intra or unset cell is skipped, one mi | |
| 3989 | +/// unit at a time, and does not itself count as a step). `max_neighbors` | |
| 3990 | +/// caller-bounds the scan: `1` for the eligibility check (any hit at all), | |
| 3991 | +/// `av1_build_obmc_inter_prediction`'s own `max_neighbor_obmc` table for the | |
| 3992 | +/// real blend pass. Round 1 corner-cut: libaom's own "4-wide block, treat as | |
| 3993 | +/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) is | |
| 3994 | +/// not ported -- no block this decoder codes is narrower than 8px, so it | |
| 3995 | +/// never fires here regardless of what a neighbour's own decoder was. | |
| 3996 | +fn overlappable_above( | |
| 3997 | + grid: &MiGrid, | |
| 3998 | + mi_row: usize, | |
| 3999 | + mi_col: usize, | |
| 4000 | + bw4: usize, | |
| 4001 | + mi_cols: usize, | |
| 4002 | + max_neighbors: usize, | |
| 4003 | +) -> Vec<(usize, usize, MiInfo)> { | |
| 4004 | + let mut out = Vec::new(); | |
| 4005 | + if mi_row == 0 { | |
| 4006 | + return out; | |
| 4007 | + } | |
| 4008 | + let end_col = (mi_col + bw4).min(mi_cols); | |
| 4009 | + let mut col = mi_col; | |
| 4010 | + while col < end_col && out.len() < max_neighbors { | |
| 4011 | + let cell = grid.get(mi_row - 1, col); | |
| 4012 | + let step = cell.map_or(1, |c| c.size).max(1); | |
| 4013 | + if let Some(info) = cell { | |
| 4014 | + if info.is_inter { | |
| 4015 | + out.push((col - mi_col, step.min(end_col - col), *info)); | |
| 4016 | + } | |
| 4017 | + } | |
| 4018 | + col += step; | |
| 4019 | + } | |
| 4020 | + out | |
| 4021 | +} | |
| 4022 | + | |
| 4023 | +/// `foreach_overlappable_nb_left`'s left-column mirror of | |
| 4024 | +/// [`overlappable_above`] -- see its doc for the shared corner-cut. | |
| 4025 | +fn overlappable_left( | |
| 4026 | + grid: &MiGrid, | |
| 4027 | + mi_row: usize, | |
| 4028 | + mi_col: usize, | |
| 4029 | + bh4: usize, | |
| 4030 | + mi_rows: usize, | |
| 4031 | + max_neighbors: usize, | |
| 4032 | +) -> Vec<(usize, usize, MiInfo)> { | |
| 4033 | + let mut out = Vec::new(); | |
| 4034 | + if mi_col == 0 { | |
| 4035 | + return out; | |
| 4036 | + } | |
| 4037 | + let end_row = (mi_row + bh4).min(mi_rows); | |
| 4038 | + let mut row = mi_row; | |
| 4039 | + while row < end_row && out.len() < max_neighbors { | |
| 4040 | + let cell = grid.get(row, mi_col - 1); | |
| 4041 | + let step = cell.map_or(1, |c| c.size).max(1); | |
| 4042 | + if let Some(info) = cell { | |
| 4043 | + if info.is_inter { | |
| 4044 | + out.push((row - mi_row, step.min(end_row - row), *info)); | |
| 4045 | + } | |
| 4046 | + } | |
| 4047 | + row += step; | |
| 4048 | + } | |
| 4049 | + out | |
| 4050 | +} | |
| 4051 | + | |
| 4052 | +/// `av1_get_obmc_mask` (`reconinter.c`): the per-position blend weight | |
| 4053 | +/// (`AOM_BLEND_A64` numerator, out of 64) for the neighbour's own | |
| 4054 | +/// contribution's *complement* -- i.e. `dst = (mask*orig + (64-mask)*nbr + | |
| 4055 | +/// 32) >> 6`, low near the shared border (heavier neighbour weight) rising | |
| 4056 | +/// to 64 (no neighbour contribution) away from it. Only the lengths this | |
| 4057 | +/// decoder's own overlap sizes ever produce (luma 8/16/32, chroma 4/8/16) | |
| 4058 | +/// are transcribed. | |
| 4059 | +fn obmc_mask(len: usize) -> &'static [u8] { | |
| 4060 | + const M4: [u8; 4] = [39, 50, 59, 64]; | |
| 4061 | + const M8: [u8; 8] = [36, 42, 48, 53, 57, 61, 64, 64]; | |
| 4062 | + const M16: [u8; 16] = [ | |
| 4063 | + 34, 37, 40, 43, 46, 49, 52, 54, 56, 58, 60, 61, 64, 64, 64, 64, | |
| 4064 | + ]; | |
| 4065 | + const M32: [u8; 32] = [ | |
| 4066 | + 33, 35, 36, 38, 40, 41, 43, 44, 45, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 60, | |
| 4067 | + 61, 62, 64, 64, 64, 64, 64, 64, 64, 64, | |
| 4068 | + ]; | |
| 4069 | + match len { | |
| 4070 | + 4 => &M4, | |
| 4071 | + 8 => &M8, | |
| 4072 | + 16 => &M16, | |
| 4073 | + 32 => &M32, | |
| 4074 | + _ => unreachable!("obmc overlap length outside this decoder's own block-size range"), | |
| 4075 | + } | |
| 4076 | +} | |
| 4077 | + | |
| 4078 | +/// A bordering block's own resolved interp filter kernel, `(h, v)` -- | |
| 4079 | +/// mirrors [`resolve_interp_filter`]'s own return order from its stored | |
| 4080 | +/// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` = | |
| 4081 | +/// `[v_sym, h_sym]`). Never calls `from_switchable_symbol` on the `[3, 3]` | |
| 4082 | +/// sentinel: that value is only ever stored for an intra neighbour (already | |
| 4083 | +/// excluded by [`overlappable_above`]/[`overlappable_left`]'s `is_inter` | |
| 4084 | +/// gate) or when `interp_fixed` is `Some` for the whole frame, handled here | |
| 4085 | +/// first. | |
| 4086 | +fn neighbour_filter( | |
| 4087 | + interp_fixed: Option<mc::InterpFilterKind>, | |
| 4088 | + sym: [u8; 2], | |
| 4089 | +) -> (mc::InterpFilterKind, mc::InterpFilterKind) { | |
| 4090 | + if let Some(kind) = interp_fixed { | |
| 4091 | + return (kind, kind); | |
| 4092 | + } | |
| 4093 | + ( | |
| 4094 | + mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize), | |
| 4095 | + mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize), | |
| 4096 | + ) | |
| 4097 | +} | |
| 4098 | + | |
| 4099 | +/// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh | |
| 4100 | +/// against its own `mv`/reference/filter (libaom `av1_build_inter_predictor` | |
| 4101 | +/// under `av1_setup_build_prediction_by_{above,left}_pred`). | |
| 4102 | +#[allow(clippy::too_many_arguments)] | |
| 4103 | +fn obmc_neighbour_pred( | |
| 4104 | + refplane: &PlaneBuf, | |
| 4105 | + x: usize, | |
| 4106 | + y: usize, | |
| 4107 | + mv: (i32, i32), | |
| 4108 | + w: usize, | |
| 4109 | + h: usize, | |
| 4110 | + luma: bool, | |
| 4111 | + h_kind: mc::InterpFilterKind, | |
| 4112 | + v_kind: mc::InterpFilterKind, | |
| 4113 | +) -> Vec<u8> { | |
| 4114 | + let mut out = vec![0u8; w * h]; | |
| 4115 | + mc::predict_with_filters( | |
| 4116 | + &refplane.data, | |
| 4117 | + refplane.width, | |
| 4118 | + refplane.true_width, | |
| 4119 | + refplane.true_height, | |
| 4120 | + mv_to_q4(x, mv.1, luma), | |
| 4121 | + mv_to_q4(y, mv.0, luma), | |
| 4122 | + w, | |
| 4123 | + h, | |
| 4124 | + h_kind, | |
| 4125 | + v_kind, | |
| 4126 | + &mut out, | |
| 4127 | + ); | |
| 4128 | + out | |
| 4129 | +} | |
| 4130 | + | |
| 4131 | +/// Blends `tmp` into `dst` (stride `stride`) at `(ox, oy)`, mask varying by | |
| 4132 | +/// row (the above-neighbour pass, `aom_blend_a64_vmask`). | |
| 4133 | +fn obmc_blend_v(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) { | |
| 4134 | + let mask = obmc_mask(h); | |
| 4135 | + for row in 0..h { | |
| 4136 | + let m = u32::from(mask[row]); | |
| 4137 | + for col in 0..w { | |
| 4138 | + let d = &mut dst[(oy + row) * stride + ox + col]; | |
| 4139 | + let t = u32::from(tmp[row * w + col]); | |
| 4140 | + *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8; | |
| 4141 | + } | |
| 4142 | + } | |
| 4143 | +} | |
| 4144 | + | |
| 4145 | +/// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the | |
| 4146 | +/// left-neighbour pass, `aom_blend_a64_hmask`). | |
| 4147 | +fn obmc_blend_h(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) { | |
| 4148 | + let mask = obmc_mask(w); | |
| 4149 | + for row in 0..h { | |
| 4150 | + for col in 0..w { | |
| 4151 | + let m = u32::from(mask[col]); | |
| 4152 | + let d = &mut dst[(oy + row) * stride + ox + col]; | |
| 4153 | + let t = u32::from(tmp[row * w + col]); | |
| 4154 | + *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8; | |
| 4155 | + } | |
| 4156 | + } | |
| 4157 | +} | |
| 4158 | + | |
| 4159 | +/// `av1_build_obmc_inter_prediction` (libaom `reconinter.c`): re-predicts | |
| 4160 | +/// the overlap strip against each bordering above/left inter neighbour's own | |
| 4161 | +/// mv/ref/filter and blends it into this block's just-built single-reference | |
| 4162 | +/// prediction, luma then both 4:2:0 chroma planes -- above pass first, then | |
| 4163 | +/// left, each reading only the *original* prediction this function was | |
| 4164 | +/// handed (never the other pass's own output), matching libaom's own | |
| 4165 | +/// independence between the two. `max_neighbor_obmc`'s own cap table | |
| 4166 | +/// (`{0,1,2,3,4,4}` indexed by `mi_size_wide_log2`/`_high_log2`, this | |
| 4167 | +/// decoder's own square blocks always index the same value both ways) bounds | |
| 4168 | +/// how many bordering blocks actually get blended, separate from the | |
| 4169 | +/// eligibility scan's own unbounded ("any at all") walk. | |
| 4170 | +#[allow(clippy::too_many_arguments)] | |
| 4171 | +fn obmc_blend( | |
| 4172 | + grid: &MiGrid, | |
| 4173 | + neighbours: &Neighbours, | |
| 4174 | + mi_row: usize, | |
| 4175 | + mi_col: usize, | |
| 4176 | + bw4: usize, | |
| 4177 | + mi_rows: usize, | |
| 4178 | + mi_cols: usize, | |
| 4179 | + side: usize, | |
| 4180 | + chroma_side: usize, | |
| 4181 | + px: usize, | |
| 4182 | + py: usize, | |
| 4183 | + cpx: usize, | |
| 4184 | + cpy: usize, | |
| 4185 | + ref_y: &PlaneBuf, | |
| 4186 | + ref_u: &PlaneBuf, | |
| 4187 | + ref_v: &PlaneBuf, | |
| 4188 | + other_refs: &RefSlots, | |
| 4189 | + interp_fixed: Option<mc::InterpFilterKind>, | |
| 4190 | + pred_y: &mut [u8], | |
| 4191 | + pred_u: &mut [u8], | |
| 4192 | + pred_v: &mut [u8], | |
| 4193 | +) -> Result<()> { | |
| 4194 | + let max_neighbors = match bw4 { | |
| 4195 | + 1..=4 => 2, | |
| 4196 | + 5..=8 => 3, | |
| 4197 | + _ => 4, | |
| 4198 | + }; | |
| 4199 | + let overlap = side / 2; | |
| 4200 | + let coverlap = overlap / 2; | |
| 4201 | + | |
| 4202 | + for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_neighbors) | |
| 4203 | + { | |
| 4204 | + // `Neighbours::above_filter` is indexed in `SUB`(16px)-wide columns | |
| 4205 | + // (this decoder's own outer block-loop granularity), one step | |
| 4206 | + // coarser than the mi(4px) units `overlappable_above` walks in -- | |
| 4207 | + // divide back down to that column. | |
| 4208 | + let (h_kind, v_kind) = neighbour_filter( | |
| 4209 | + interp_fixed, | |
| 4210 | + neighbours.above_filter[(mi_col + off4) / SUB_MI as usize], | |
| 4211 | + ); | |
| 4212 | + let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; | |
| 4213 | + let (bw, bh, ox) = (span4 * 4, overlap, off4 * 4); | |
| 4214 | + let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind); | |
| 4215 | + obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y); | |
| 4216 | + let (cbw, cbh, cox) = (bw / 2, coverlap, ox / 2); | |
| 4217 | + let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 4218 | + obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u); | |
| 4219 | + let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 4220 | + obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v); | |
| 4221 | + } | |
| 4222 | + | |
| 4223 | + for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bw4, mi_rows, max_neighbors) { | |
| 4224 | + let (h_kind, v_kind) = neighbour_filter( | |
| 4225 | + interp_fixed, | |
| 4226 | + neighbours.left_filter[(mi_row + off4) / SUB_MI as usize], | |
| 4227 | + ); | |
| 4228 | + let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; | |
| 4229 | + let (bw, bh, oy) = (overlap, span4 * 4, off4 * 4); | |
| 4230 | + let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind); | |
| 4231 | + obmc_blend_h(pred_y, side, 0, oy, bw, bh, &tmp_y); | |
| 4232 | + let (cbw, cbh, coy) = (coverlap, bh / 2, oy / 2); | |
| 4233 | + let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 4234 | + obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, cbh, &tmp_u); | |
| 4235 | + let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind); | |
| 4236 | + obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, cbh, &tmp_v); | |
| 4237 | + } | |
| 4238 | + Ok(()) | |
| 4239 | +} | |
| 4240 | + | |
| 3962 | 4241 | /// `is_any_masked_compound_used` (libaom `reconinter.h`), specialised to |
| 3963 | 4242 | /// the square block sizes this decoder ever decodes (32/16/8, all |
| 3964 | 4243 | /// `min(w,h) >= 8`, `is_comp_ref_allowed` true): `COMPOUND_DIFFWTD` is then |
| @@ -4306,6 +4585,10 @@ fn decode_inter_block( | ||
| 4306 | 4585 | // `compound_idx` read (libaom `decodemv.c` 1604-1619, 1382-1384, 1509). |
| 4307 | 4586 | skip_mode_present: bool, |
| 4308 | 4587 | skip_mode_frame: [u8; 2], |
| 4588 | + // lane-motionmode round 1: this frame header's own `is_motion_mode_switchable`/ | |
| 4589 | + // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`). | |
| 4590 | + switchable_motion_mode: bool, | |
| 4591 | + allow_warped_motion: bool, | |
| 4309 | 4592 | ) -> Result<()> { |
| 4310 | 4593 | let (r, c) = at; |
| 4311 | 4594 | let (px, py) = (c * SUB, r * SUB); |
| @@ -5011,6 +5294,48 @@ fn decode_inter_block( | ||
| 5011 | 5294 | }; |
| 5012 | 5295 | (mv, false) |
| 5013 | 5296 | }; |
| 5297 | + // lane-motionmode round 1: `read_motion_mode` (spec 5.11.24; | |
| 5298 | + // libaom `decodemv.c` read_inter_block_mode_info, ~1520-1528), | |
| 5299 | + // placed right after MV assignment and before the switchable | |
| 5300 | + // interp filter read below (`read_mb_interp_filter`, decodemv.c | |
| 5301 | + // ~1600) -- libaom's own sequential order. `motion_mode_allowed` | |
| 5302 | + // (`reconinter.h`) reduces, for every block this single-ref path | |
| 5303 | + // reaches, to "does an inter neighbour border the above row or | |
| 5304 | + // left column": `is_motion_variation_allowed_bsize` always holds | |
| 5305 | + // (`side` is never below 16px on this path), `ref_frame[1] != | |
| 5306 | + // INTRA_FRAME` always holds (no interintra reader here), | |
| 5307 | + // `is_motion_variation_allowed_compound` always holds (this is | |
| 5308 | + // the single-ref branch), and `is_global_mv_block` never | |
| 5309 | + // triggers (this decoder's global motion is always `IDENTITY`, | |
| 5310 | + // so its warp `type` is never `> TRANSLATION`). A stream with | |
| 5311 | + // `allow_warped_motion=1` is refused right at an eligible block | |
| 5312 | + // rather than guessed at: `av1_findSamples`/`num_proj_ref` is | |
| 5313 | + // not ported, so this decoder cannot tell a real | |
| 5314 | + // `WARPED_CAUSAL`-eligible block (3-symbol `motion_mode_cdf`) | |
| 5315 | + // from an `OBMC_CAUSAL`-only one (2-symbol `obmc_cdf`) whenever | |
| 5316 | + // the header allows warp -- reading the wrong alphabet desyncs | |
| 5317 | + // the tile. | |
| 5318 | + let motion_mode_eligible = switchable_motion_mode | |
| 5319 | + && !skip_mode | |
| 5320 | + && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty() | |
| 5321 | + || !overlappable_left(grid, mi_row, mi_col, bw4, mi_rows as usize, 1) | |
| 5322 | + .is_empty()); | |
| 5323 | + let mut obmc_selected = false; | |
| 5324 | + if motion_mode_eligible { | |
| 5325 | + if allow_warped_motion { | |
| 5326 | + return Err(unsupported( | |
| 5327 | + "a motion-variation-eligible block under allow_warped_motion=1 \ | |
| 5328 | + (round 1 only reads the 2-symbol obmc_cdf; telling OBMC_CAUSAL \ | |
| 5329 | + from WARPED_CAUSAL needs av1_findSamples, not ported)", | |
| 5330 | + )); | |
| 5331 | + } | |
| 5332 | + // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3. | |
| 5333 | + let bsize_idx = (side.trailing_zeros() - 3) as usize; | |
| 5334 | + obmc_selected = dec.symbol(&mut cdfs.obmc[bsize_idx]) == 1; | |
| 5335 | + if obmc_selected { | |
| 5336 | + OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 5337 | + } | |
| 5338 | + } | |
| 5014 | 5339 | // spec `get_ref_filter_type`: a neighbour's own filter only feeds |
| 5015 | 5340 | // this block's switchable_interp context when that neighbour coded |
| 5016 | 5341 | // the SAME reference frame this block is about to read -- a |
| @@ -5116,6 +5441,32 @@ fn decode_inter_block( | ||
| 5116 | 5441 | &mut pred_v, |
| 5117 | 5442 | ); |
| 5118 | 5443 | |
| 5444 | + if obmc_selected { | |
| 5445 | + obmc_blend( | |
| 5446 | + grid, | |
| 5447 | + neighbours, | |
| 5448 | + mi_row, | |
| 5449 | + mi_col, | |
| 5450 | + bw4, | |
| 5451 | + mi_rows as usize, | |
| 5452 | + mi_cols as usize, | |
| 5453 | + side, | |
| 5454 | + chroma_side, | |
| 5455 | + px, | |
| 5456 | + py, | |
| 5457 | + cpx, | |
| 5458 | + cpy, | |
| 5459 | + ref_y, | |
| 5460 | + ref_u, | |
| 5461 | + ref_v, | |
| 5462 | + other_refs, | |
| 5463 | + interp_fixed, | |
| 5464 | + &mut pred_y, | |
| 5465 | + &mut pred_u, | |
| 5466 | + &mut pred_v, | |
| 5467 | + )?; | |
| 5468 | + } | |
| 5469 | + | |
| 5119 | 5470 | if skip { |
| 5120 | 5471 | y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); |
| 5121 | 5472 | u.reconstruct_mc( |
| @@ -5421,6 +5772,16 @@ fn decode_inter_block8( | ||
| 5421 | 5772 | // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see |
| 5422 | 5773 | // [`decode_inter_frame_tile_with_cdfs`]'s own doc. |
| 5423 | 5774 | reduced_tx_set: bool, |
| 5775 | + // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/ | |
| 5776 | + // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus | |
| 5777 | + // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour | |
| 5778 | + // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own | |
| 5779 | + // prediction is always `Regular` (documented corner-cut, `mc::predict` | |
| 5780 | + // has no filter param), but an OBMC neighbour can be a real 16x16+ | |
| 5781 | + // block that DID resolve a switchable filter. | |
| 5782 | + interp_fixed: Option<mc::InterpFilterKind>, | |
| 5783 | + switchable_motion_mode: bool, | |
| 5784 | + allow_warped_motion: bool, | |
| 5424 | 5785 | // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a |
| 5425 | 5786 | // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16 |
| 5426 | 5787 | // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own |
| @@ -5868,6 +6229,33 @@ fn decode_inter_block8( | ||
| 5868 | 6229 | }; |
| 5869 | 6230 | (mv, false) |
| 5870 | 6231 | }; |
| 6232 | + // lane-motionmode round 3: `read_motion_mode` (spec 5.11.24) at the | |
| 6233 | + // 8x8 leaf too -- `motion_mode_allowed` still holds here (BLOCK_8X8 | |
| 6234 | + // is the spec's own minimum eligible size, single-ref-only branch, | |
| 6235 | + // no interintra reader, `IDENTITY`-only global motion). Mirrors the | |
| 6236 | + // 16x16 leaf's own `decode_inter_block` read (see its doc above) -- | |
| 6237 | + // same 2-symbol `obmc_cdf` alphabet, same `allow_warped_motion=1` | |
| 6238 | + // refusal (warp needs `av1_findSamples`, not ported at either leaf). | |
| 6239 | + let motion_mode_eligible = switchable_motion_mode | |
| 6240 | + && !skip_mode | |
| 6241 | + && (!overlappable_above(grid, mi_row, mi_col, 2, mi_cols as usize, 1).is_empty() | |
| 6242 | + || !overlappable_left(grid, mi_row, mi_col, 2, mi_rows as usize, 1).is_empty()); | |
| 6243 | + let mut obmc_selected = false; | |
| 6244 | + if motion_mode_eligible { | |
| 6245 | + if allow_warped_motion { | |
| 6246 | + return Err(unsupported( | |
| 6247 | + "a motion-variation-eligible 8x8 leaf under allow_warped_motion=1 \ | |
| 6248 | + (round 3 only reads the 2-symbol obmc_cdf; telling OBMC_CAUSAL \ | |
| 6249 | + from WARPED_CAUSAL needs av1_findSamples, not ported)", | |
| 6250 | + )); | |
| 6251 | + } | |
| 6252 | + // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3. | |
| 6253 | + obmc_selected = dec.symbol(&mut cdfs.obmc[0]) == 1; | |
| 6254 | + if obmc_selected { | |
| 6255 | + OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6256 | + OBMC_HITS_8.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6257 | + } | |
| 6258 | + } | |
| 5871 | 6259 | for dr in 0..2 { |
| 5872 | 6260 | for dc in 0..2 { |
| 5873 | 6261 | grid.set( |
| @@ -5924,6 +6312,32 @@ fn decode_inter_block8( | ||
| 5924 | 6312 | &mut pred_v, |
| 5925 | 6313 | ); |
| 5926 | 6314 | |
| 6315 | + if obmc_selected { | |
| 6316 | + obmc_blend( | |
| 6317 | + grid, | |
| 6318 | + neighbours, | |
| 6319 | + mi_row, | |
| 6320 | + mi_col, | |
| 6321 | + 2, | |
| 6322 | + mi_rows as usize, | |
| 6323 | + mi_cols as usize, | |
| 6324 | + SIDE, | |
| 6325 | + CHROMA_SIDE, | |
| 6326 | + px, | |
| 6327 | + py, | |
| 6328 | + cpx, | |
| 6329 | + cpy, | |
| 6330 | + ref_y, | |
| 6331 | + ref_u, | |
| 6332 | + ref_v, | |
| 6333 | + other_refs, | |
| 6334 | + interp_fixed, | |
| 6335 | + &mut pred_y, | |
| 6336 | + &mut pred_u, | |
| 6337 | + &mut pred_v, | |
| 6338 | + )?; | |
| 6339 | + } | |
| 6340 | + | |
| 5927 | 6341 | if skip { |
| 5928 | 6342 | y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); |
| 5929 | 6343 | u.reconstruct_mc( |
| @@ -6207,6 +6621,8 @@ pub fn decode_inter_frame_tile( | ||
| 6207 | 6621 | false, |
| 6208 | 6622 | [0; 2], |
| 6209 | 6623 | true, |
| 6624 | + false, | |
| 6625 | + false, | |
| 6210 | 6626 | ) |
| 6211 | 6627 | .map(|(picture, _, _)| picture) |
| 6212 | 6628 | } |
| @@ -6257,6 +6673,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6257 | 6673 | // `Set1` coefficient tables at 16x16/8x8 rather than the reduced |
| 6258 | 6674 | // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]). |
| 6259 | 6675 | reduced_tx_set: bool, |
| 6676 | + // lane-motionmode round 1/3: this frame header's own `is_motion_mode_switchable`/ | |
| 6677 | + // `allow_warped_motion` bits, threaded to every `decode_inter_block`/ | |
| 6678 | + // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`). | |
| 6679 | + switchable_motion_mode: bool, | |
| 6680 | + allow_warped_motion: bool, | |
| 6260 | 6681 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { |
| 6261 | 6682 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { |
| 6262 | 6683 | field, |
| @@ -6461,6 +6882,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6461 | 6882 | ref_order_hints, |
| 6462 | 6883 | skip_mode_present, |
| 6463 | 6884 | skip_mode_frame, |
| 6885 | + switchable_motion_mode, | |
| 6886 | + allow_warped_motion, | |
| 6464 | 6887 | )?; |
| 6465 | 6888 | } |
| 6466 | 6889 | PARTITION_SPLIT => { |
| @@ -6531,6 +6954,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6531 | 6954 | ref_order_hints, |
| 6532 | 6955 | skip_mode_present, |
| 6533 | 6956 | skip_mode_frame, |
| 6957 | + switchable_motion_mode, | |
| 6958 | + allow_warped_motion, | |
| 6534 | 6959 | )?; |
| 6535 | 6960 | } else { |
| 6536 | 6961 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| @@ -6593,6 +7018,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6593 | 7018 | skip_mode_present, |
| 6594 | 7019 | skip_mode_frame, |
| 6595 | 7020 | reduced_tx_set, |
| 7021 | + interp_fixed, | |
| 7022 | + switchable_motion_mode, | |
| 7023 | + allow_warped_motion, | |
| 6596 | 7024 | )?; |
| 6597 | 7025 | prev_leaf = Some((leaf_mi, skip, is_inter)); |
| 6598 | 7026 | last_skip_mode = skip_mode_leaf; |
| @@ -7373,6 +7801,8 @@ mod tests { | ||
| 7373 | 7801 | [0; 7], |
| 7374 | 7802 | false, |
| 7375 | 7803 | [0; 2], |
| 7804 | + false, | |
| 7805 | + false, | |
| 7376 | 7806 | ) |
| 7377 | 7807 | .unwrap(); |
| 7378 | 7808 |
crates/ec-av1/src/stream.rsmodified+483 -0
| @@ -379,6 +379,8 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 379 | 379 | header.skip_mode_present, |
| 380 | 380 | header.skip_mode_frame, |
| 381 | 381 | header.reduced_tx_set, |
| 382 | + header.is_motion_mode_switchable, | |
| 383 | + header.allow_warped_motion, | |
| 382 | 384 | )? |
| 383 | 385 | }; |
| 384 | 386 | // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's |
| @@ -2898,6 +2900,487 @@ mod tests { | ||
| 2898 | 2900 | ); |
| 2899 | 2901 | } |
| 2900 | 2902 | |
| 2903 | + /// lane-motionmode round 1: `--enable-obmc=1 --enable-warped-motion=0` | |
| 2904 | + /// on the base recipe (`--auto-alt-ref=1 --lag-in-frames=16 | |
| 2905 | + /// --enable-fwd-kf=0 --enable-ref-frame-mvs=0`) -- pixel-exact against | |
| 2906 | + /// ffmpeg, gated on [`decode::obmc_hits`] actually advancing (a real | |
| 2907 | + /// block picked `OBMC_CAUSAL`, not just that the header bit was set). | |
| 2908 | + /// Structure copied from | |
| 2909 | + /// `a_real_aomenc_stream_with_compound_references_decodes_pixel_exact`: | |
| 2910 | + /// a seed sweep with a named-refusal escape hatch and an | |
| 2911 | + /// `EC_AV1_GATE_DUMP` pin on mismatch. | |
| 2912 | + #[test] | |
| 2913 | + fn a_real_aomenc_stream_with_obmc_decodes_pixel_exact() { | |
| 2914 | + const NAME: &str = "a_real_aomenc_stream_with_obmc_decodes_pixel_exact"; | |
| 2915 | + let _gate_lock = lock_gate_counters(); | |
| 2916 | + if !have_ffmpeg() { | |
| 2917 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 2918 | + return; | |
| 2919 | + } | |
| 2920 | + if !have_aomenc() { | |
| 2921 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 2922 | + return; | |
| 2923 | + } | |
| 2924 | + let (width, height, frame_count) = (64usize, 64usize, 24usize); | |
| 2925 | + let mut refusals = Vec::new(); | |
| 2926 | + let mut never_fired = 0u32; | |
| 2927 | + for attempt in 0..80u32 { | |
| 2928 | + let seed = 42 + attempt % 40; | |
| 2929 | + let duration = frame_count as f64 / 25.0; | |
| 2930 | + let source = | |
| 2931 | + format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25"); | |
| 2932 | + let y4m = Command::new("ffmpeg") | |
| 2933 | + .args([ | |
| 2934 | + "-v", | |
| 2935 | + "error", | |
| 2936 | + "-f", | |
| 2937 | + "lavfi", | |
| 2938 | + "-i", | |
| 2939 | + &source, | |
| 2940 | + "-pix_fmt", | |
| 2941 | + "yuv420p", | |
| 2942 | + "-f", | |
| 2943 | + "yuv4mpegpipe", | |
| 2944 | + "-", | |
| 2945 | + ]) | |
| 2946 | + .stdin(Stdio::null()) | |
| 2947 | + .stdout(Stdio::piped()) | |
| 2948 | + .stderr(Stdio::piped()) | |
| 2949 | + .output() | |
| 2950 | + .expect("ffmpeg failed to run"); | |
| 2951 | + assert!( | |
| 2952 | + y4m.status.success(), | |
| 2953 | + "ffmpeg fixture: {}", | |
| 2954 | + String::from_utf8_lossy(&y4m.stderr) | |
| 2955 | + ); | |
| 2956 | + let args: Vec<&str> = vec![ | |
| 2957 | + "--codec=av1", | |
| 2958 | + "--passes=1", | |
| 2959 | + "--end-usage=q", | |
| 2960 | + "--cq-level=45", | |
| 2961 | + "--cpu-used=0", | |
| 2962 | + "--kf-max-dist=1000", | |
| 2963 | + "--threads=1", | |
| 2964 | + "--row-mt=0", | |
| 2965 | + "--auto-alt-ref=1", | |
| 2966 | + "--lag-in-frames=16", | |
| 2967 | + "--enable-fwd-kf=0", | |
| 2968 | + "--enable-order-hint=1", | |
| 2969 | + "--enable-warped-motion=0", | |
| 2970 | + "--enable-obmc=1", | |
| 2971 | + "--enable-masked-comp=0", | |
| 2972 | + "--enable-interintra-comp=0", | |
| 2973 | + "--enable-onesided-comp=0", | |
| 2974 | + "--enable-interintra-wedge=0", | |
| 2975 | + "--enable-smooth-interintra=0", | |
| 2976 | + "--enable-rect-partitions=0", | |
| 2977 | + "--enable-ab-partitions=0", | |
| 2978 | + "--enable-1to4-partitions=0", | |
| 2979 | + "--enable-filter-intra=0", | |
| 2980 | + "--enable-smooth-intra=0", | |
| 2981 | + "--enable-paeth-intra=0", | |
| 2982 | + "--enable-directional-intra=0", | |
| 2983 | + "--enable-angle-delta=0", | |
| 2984 | + "--enable-tx-size-search=0", | |
| 2985 | + "--enable-cdef=0", | |
| 2986 | + "--enable-restoration=0", | |
| 2987 | + "--max-partition-size=32", | |
| 2988 | + "--min-partition-size=32", | |
| 2989 | + "--enable-palette=0", | |
| 2990 | + "--enable-intrabc=0", | |
| 2991 | + "--enable-cfl-intra=0", | |
| 2992 | + "--enable-ref-frame-mvs=0", | |
| 2993 | + "--obu", | |
| 2994 | + "-o", | |
| 2995 | + "-", | |
| 2996 | + "-", | |
| 2997 | + ]; | |
| 2998 | + let mut child = Command::new(aomenc_path()) | |
| 2999 | + .args(&args) | |
| 3000 | + .stdin(Stdio::piped()) | |
| 3001 | + .stdout(Stdio::piped()) | |
| 3002 | + .stderr(Stdio::piped()) | |
| 3003 | + .spawn() | |
| 3004 | + .expect("aomenc failed to start"); | |
| 3005 | + child | |
| 3006 | + .stdin | |
| 3007 | + .take() | |
| 3008 | + .expect("aomenc stdin") | |
| 3009 | + .write_all(&y4m.stdout) | |
| 3010 | + .expect("writing y4m to aomenc"); | |
| 3011 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 3012 | + assert!( | |
| 3013 | + out.status.success(), | |
| 3014 | + "aomenc refused the fixture: {}", | |
| 3015 | + String::from_utf8_lossy(&out.stderr) | |
| 3016 | + ); | |
| 3017 | + let stream = out.stdout; | |
| 3018 | + let before = decode::obmc_hits(); | |
| 3019 | + let frames = match decode_stream(&stream) { | |
| 3020 | + Err(e) => { | |
| 3021 | + let msg = e.to_string(); | |
| 3022 | + assert!( | |
| 3023 | + msg.contains("unsupported"), | |
| 3024 | + "{NAME} failed outright (seed {seed}): {msg}" | |
| 3025 | + ); | |
| 3026 | + refusals.push(format!("seed {seed}: {msg}")); | |
| 3027 | + continue; | |
| 3028 | + } | |
| 3029 | + Ok(frames) => frames, | |
| 3030 | + }; | |
| 3031 | + if decode::obmc_hits() == before { | |
| 3032 | + never_fired += 1; | |
| 3033 | + continue; | |
| 3034 | + } | |
| 3035 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | |
| 3036 | + assert_eq!(frames.len(), frame_count); | |
| 3037 | + let mismatched = frames | |
| 3038 | + .iter() | |
| 3039 | + .zip(&ffmpeg_frames) | |
| 3040 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | |
| 3041 | + if mismatched { | |
| 3042 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | |
| 3043 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | |
| 3044 | + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | |
| 3045 | + } | |
| 3046 | + } | |
| 3047 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 3048 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); | |
| 3049 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | |
| 3050 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | |
| 3051 | + } | |
| 3052 | + eprintln!( | |
| 3053 | + "{NAME} FIRING seed {seed}: obmc hits advanced by {}", | |
| 3054 | + decode::obmc_hits() - before | |
| 3055 | + ); | |
| 3056 | + return; | |
| 3057 | + } | |
| 3058 | + eprintln!( | |
| 3059 | + "SKIP {NAME}: {never_fired} attempts decoded but never fired obmc, and every \ | |
| 3060 | + other attempt hit a named refusal:\n{}", | |
| 3061 | + refusals.join("\n") | |
| 3062 | + ); | |
| 3063 | + } | |
| 3064 | + | |
| 3065 | + /// lane-motionmode round 3: same shape as | |
| 3066 | + /// `a_real_aomenc_stream_with_obmc_decodes_pixel_exact`, but relaxed the | |
| 3067 | + /// `--min-partition-size=32 --max-partition-size=32` clamp (that other | |
| 3068 | + /// gate's own doc: locked to remove partition-depth choice from the | |
| 3069 | + /// search entirely) to `8`/`32`, to make an 8x8-leaf `OBMC_CAUSAL` pick | |
| 3070 | + /// possible at all. Gated on [`decode::obmc_hits_8`] specifically, not | |
| 3071 | + /// the aggregate [`decode::obmc_hits`]. Measured live (round 3, this | |
| 3072 | + /// box): 80 attempts, 0 ever called `decode_inter_block8` at all -- | |
| 3073 | + /// `cpu-used=0`'s RD search never once splits a 16x16 down to a clean | |
| 3074 | + /// 4-way 8x8 leaf for this smooth `gradients` fixture (large blocks | |
| 3075 | + /// always win the RD cost there); the handful of named refusals seen | |
| 3076 | + /// are `PARTITION_SPLIT` chosen *at* 8x8 (down to 4x4, already refused | |
| 3077 | + /// at `decode.rs`'s `part8 != PARTITION_NONE` check) or | |
| 3078 | + /// `allow_screen_content_tools`, neither reaching a leaf. Kept anyway | |
| 3079 | + /// (mirrors this file's own `never_fired`-skip convention) as the | |
| 3080 | + /// honest record of the attempt; a real 8x8 OBMC fixture needs | |
| 3081 | + /// higher-frequency content than this gate's fixtures use, out of | |
| 3082 | + /// round-3 budget. | |
| 3083 | + #[test] | |
| 3084 | + fn a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact() { | |
| 3085 | + const NAME: &str = "a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact"; | |
| 3086 | + let _gate_lock = lock_gate_counters(); | |
| 3087 | + if !have_ffmpeg() { | |
| 3088 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 3089 | + return; | |
| 3090 | + } | |
| 3091 | + if !have_aomenc() { | |
| 3092 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 3093 | + return; | |
| 3094 | + } | |
| 3095 | + let (width, height, frame_count) = (64usize, 64usize, 24usize); | |
| 3096 | + let mut refusals = Vec::new(); | |
| 3097 | + let mut never_fired = 0u32; | |
| 3098 | + let mut total_obmc8 = 0usize; | |
| 3099 | + for attempt in 0..80u32 { | |
| 3100 | + let seed = 42 + attempt % 40; | |
| 3101 | + let duration = frame_count as f64 / 25.0; | |
| 3102 | + let source = | |
| 3103 | + format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25"); | |
| 3104 | + let y4m = Command::new("ffmpeg") | |
| 3105 | + .args([ | |
| 3106 | + "-v", | |
| 3107 | + "error", | |
| 3108 | + "-f", | |
| 3109 | + "lavfi", | |
| 3110 | + "-i", | |
| 3111 | + &source, | |
| 3112 | + "-pix_fmt", | |
| 3113 | + "yuv420p", | |
| 3114 | + "-f", | |
| 3115 | + "yuv4mpegpipe", | |
| 3116 | + "-", | |
| 3117 | + ]) | |
| 3118 | + .stdin(Stdio::null()) | |
| 3119 | + .stdout(Stdio::piped()) | |
| 3120 | + .stderr(Stdio::piped()) | |
| 3121 | + .output() | |
| 3122 | + .expect("ffmpeg failed to run"); | |
| 3123 | + assert!( | |
| 3124 | + y4m.status.success(), | |
| 3125 | + "ffmpeg fixture: {}", | |
| 3126 | + String::from_utf8_lossy(&y4m.stderr) | |
| 3127 | + ); | |
| 3128 | + let args: Vec<&str> = vec![ | |
| 3129 | + "--codec=av1", | |
| 3130 | + "--passes=1", | |
| 3131 | + "--end-usage=q", | |
| 3132 | + "--cq-level=45", | |
| 3133 | + "--cpu-used=0", | |
| 3134 | + "--kf-max-dist=1000", | |
| 3135 | + "--threads=1", | |
| 3136 | + "--row-mt=0", | |
| 3137 | + "--auto-alt-ref=1", | |
| 3138 | + "--lag-in-frames=16", | |
| 3139 | + "--enable-fwd-kf=0", | |
| 3140 | + "--enable-order-hint=1", | |
| 3141 | + "--enable-warped-motion=0", | |
| 3142 | + "--enable-obmc=1", | |
| 3143 | + "--enable-masked-comp=0", | |
| 3144 | + "--enable-interintra-comp=0", | |
| 3145 | + "--enable-onesided-comp=0", | |
| 3146 | + "--enable-interintra-wedge=0", | |
| 3147 | + "--enable-smooth-interintra=0", | |
| 3148 | + "--enable-rect-partitions=0", | |
| 3149 | + "--enable-ab-partitions=0", | |
| 3150 | + "--enable-1to4-partitions=0", | |
| 3151 | + "--enable-filter-intra=0", | |
| 3152 | + "--enable-smooth-intra=0", | |
| 3153 | + "--enable-paeth-intra=0", | |
| 3154 | + "--enable-directional-intra=0", | |
| 3155 | + "--enable-angle-delta=0", | |
| 3156 | + "--enable-tx-size-search=0", | |
| 3157 | + "--enable-cdef=0", | |
| 3158 | + "--enable-restoration=0", | |
| 3159 | + "--min-partition-size=8", | |
| 3160 | + "--max-partition-size=32", | |
| 3161 | + "--enable-palette=0", | |
| 3162 | + "--enable-intrabc=0", | |
| 3163 | + "--enable-cfl-intra=0", | |
| 3164 | + "--enable-ref-frame-mvs=0", | |
| 3165 | + "--obu", | |
| 3166 | + "-o", | |
| 3167 | + "-", | |
| 3168 | + "-", | |
| 3169 | + ]; | |
| 3170 | + let mut child = Command::new(aomenc_path()) | |
| 3171 | + .args(&args) | |
| 3172 | + .stdin(Stdio::piped()) | |
| 3173 | + .stdout(Stdio::piped()) | |
| 3174 | + .stderr(Stdio::piped()) | |
| 3175 | + .spawn() | |
| 3176 | + .expect("aomenc failed to start"); | |
| 3177 | + child | |
| 3178 | + .stdin | |
| 3179 | + .take() | |
| 3180 | + .expect("aomenc stdin") | |
| 3181 | + .write_all(&y4m.stdout) | |
| 3182 | + .expect("writing y4m to aomenc"); | |
| 3183 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 3184 | + assert!( | |
| 3185 | + out.status.success(), | |
| 3186 | + "aomenc refused the fixture: {}", | |
| 3187 | + String::from_utf8_lossy(&out.stderr) | |
| 3188 | + ); | |
| 3189 | + let stream = out.stdout; | |
| 3190 | + let before8 = decode::obmc_hits_8(); | |
| 3191 | + let frames = match decode_stream(&stream) { | |
| 3192 | + Err(e) => { | |
| 3193 | + let msg = e.to_string(); | |
| 3194 | + assert!( | |
| 3195 | + msg.contains("unsupported"), | |
| 3196 | + "{NAME} failed outright (seed {seed}): {msg}" | |
| 3197 | + ); | |
| 3198 | + refusals.push(format!("seed {seed}: {msg}")); | |
| 3199 | + continue; | |
| 3200 | + } | |
| 3201 | + Ok(frames) => frames, | |
| 3202 | + }; | |
| 3203 | + let fired8 = decode::obmc_hits_8() - before8; | |
| 3204 | + total_obmc8 += fired8; | |
| 3205 | + if fired8 == 0 { | |
| 3206 | + never_fired += 1; | |
| 3207 | + continue; | |
| 3208 | + } | |
| 3209 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | |
| 3210 | + assert_eq!(frames.len(), frame_count); | |
| 3211 | + let mismatched = frames | |
| 3212 | + .iter() | |
| 3213 | + .zip(&ffmpeg_frames) | |
| 3214 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | |
| 3215 | + if mismatched { | |
| 3216 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | |
| 3217 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | |
| 3218 | + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | |
| 3219 | + } | |
| 3220 | + } | |
| 3221 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 3222 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); | |
| 3223 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | |
| 3224 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | |
| 3225 | + } | |
| 3226 | + eprintln!( | |
| 3227 | + "{NAME} FIRING seed {seed}: 8x8 obmc hits {fired8} (total across attempts so far {total_obmc8})" | |
| 3228 | + ); | |
| 3229 | + return; | |
| 3230 | + } | |
| 3231 | + eprintln!( | |
| 3232 | + "SKIP {NAME}: {never_fired} attempts decoded but never fired an 8x8 obmc block \ | |
| 3233 | + ({total_obmc8} total 8x8 obmc hits across all attempts), and every other attempt \ | |
| 3234 | + hit a named refusal:\n{}", | |
| 3235 | + refusals.join("\n") | |
| 3236 | + ); | |
| 3237 | + } | |
| 3238 | + | |
| 3239 | + /// lane-motionmode round 1: `--enable-warped-motion=1` must be a NAMED | |
| 3240 | + /// refusal, never a silent mis-decode -- this decoder does not port | |
| 3241 | + /// `av1_findSamples`/`num_proj_ref`, so it cannot tell `OBMC_CAUSAL` | |
| 3242 | + /// from `WARPED_CAUSAL` at an eligible block once the header allows | |
| 3243 | + /// warp (see `decode_inter_block`'s own `allow_warped_motion` refusal). | |
| 3244 | + /// Every attempt across the seed sweep must either name the refusal or | |
| 3245 | + /// decode pixel-exact (an eligible block simply never fired in that | |
| 3246 | + /// attempt) -- a silent pixel mismatch here would mean the refusal | |
| 3247 | + /// failed to fire on a stream that actually needed it. | |
| 3248 | + #[test] | |
| 3249 | + fn a_real_aomenc_stream_with_warped_motion_refuses_or_matches() { | |
| 3250 | + const NAME: &str = "a_real_aomenc_stream_with_warped_motion_refuses_or_matches"; | |
| 3251 | + let _gate_lock = lock_gate_counters(); | |
| 3252 | + if !have_ffmpeg() { | |
| 3253 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 3254 | + return; | |
| 3255 | + } | |
| 3256 | + if !have_aomenc() { | |
| 3257 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 3258 | + return; | |
| 3259 | + } | |
| 3260 | + let (width, height, frame_count) = (64usize, 64usize, 24usize); | |
| 3261 | + let mut named_refusals = 0u32; | |
| 3262 | + let mut matched = 0u32; | |
| 3263 | + for attempt in 0..40u32 { | |
| 3264 | + let seed = 42 + attempt; | |
| 3265 | + let duration = frame_count as f64 / 25.0; | |
| 3266 | + let source = | |
| 3267 | + format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25"); | |
| 3268 | + let y4m = Command::new("ffmpeg") | |
| 3269 | + .args([ | |
| 3270 | + "-v", | |
| 3271 | + "error", | |
| 3272 | + "-f", | |
| 3273 | + "lavfi", | |
| 3274 | + "-i", | |
| 3275 | + &source, | |
| 3276 | + "-pix_fmt", | |
| 3277 | + "yuv420p", | |
| 3278 | + "-f", | |
| 3279 | + "yuv4mpegpipe", | |
| 3280 | + "-", | |
| 3281 | + ]) | |
| 3282 | + .stdin(Stdio::null()) | |
| 3283 | + .stdout(Stdio::piped()) | |
| 3284 | + .stderr(Stdio::piped()) | |
| 3285 | + .output() | |
| 3286 | + .expect("ffmpeg failed to run"); | |
| 3287 | + assert!( | |
| 3288 | + y4m.status.success(), | |
| 3289 | + "ffmpeg fixture: {}", | |
| 3290 | + String::from_utf8_lossy(&y4m.stderr) | |
| 3291 | + ); | |
| 3292 | + let args: Vec<&str> = vec![ | |
| 3293 | + "--codec=av1", | |
| 3294 | + "--passes=1", | |
| 3295 | + "--end-usage=q", | |
| 3296 | + "--cq-level=45", | |
| 3297 | + "--cpu-used=0", | |
| 3298 | + "--kf-max-dist=1000", | |
| 3299 | + "--threads=1", | |
| 3300 | + "--row-mt=0", | |
| 3301 | + "--auto-alt-ref=1", | |
| 3302 | + "--lag-in-frames=16", | |
| 3303 | + "--enable-fwd-kf=0", | |
| 3304 | + "--enable-order-hint=1", | |
| 3305 | + "--enable-warped-motion=1", | |
| 3306 | + "--enable-obmc=1", | |
| 3307 | + "--enable-masked-comp=0", | |
| 3308 | + "--enable-interintra-comp=0", | |
| 3309 | + "--enable-onesided-comp=0", | |
| 3310 | + "--enable-interintra-wedge=0", | |
| 3311 | + "--enable-smooth-interintra=0", | |
| 3312 | + "--enable-rect-partitions=0", | |
| 3313 | + "--enable-ab-partitions=0", | |
| 3314 | + "--enable-1to4-partitions=0", | |
| 3315 | + "--enable-filter-intra=0", | |
| 3316 | + "--enable-smooth-intra=0", | |
| 3317 | + "--enable-paeth-intra=0", | |
| 3318 | + "--enable-directional-intra=0", | |
| 3319 | + "--enable-angle-delta=0", | |
| 3320 | + "--enable-tx-size-search=0", | |
| 3321 | + "--enable-cdef=0", | |
| 3322 | + "--enable-restoration=0", | |
| 3323 | + "--max-partition-size=32", | |
| 3324 | + "--min-partition-size=32", | |
| 3325 | + "--enable-palette=0", | |
| 3326 | + "--enable-intrabc=0", | |
| 3327 | + "--enable-cfl-intra=0", | |
| 3328 | + "--enable-ref-frame-mvs=0", | |
| 3329 | + "--obu", | |
| 3330 | + "-o", | |
| 3331 | + "-", | |
| 3332 | + "-", | |
| 3333 | + ]; | |
| 3334 | + let mut child = Command::new(aomenc_path()) | |
| 3335 | + .args(&args) | |
| 3336 | + .stdin(Stdio::piped()) | |
| 3337 | + .stdout(Stdio::piped()) | |
| 3338 | + .stderr(Stdio::piped()) | |
| 3339 | + .spawn() | |
| 3340 | + .expect("aomenc failed to start"); | |
| 3341 | + child | |
| 3342 | + .stdin | |
| 3343 | + .take() | |
| 3344 | + .expect("aomenc stdin") | |
| 3345 | + .write_all(&y4m.stdout) | |
| 3346 | + .expect("writing y4m to aomenc"); | |
| 3347 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 3348 | + assert!( | |
| 3349 | + out.status.success(), | |
| 3350 | + "aomenc refused the fixture: {}", | |
| 3351 | + String::from_utf8_lossy(&out.stderr) | |
| 3352 | + ); | |
| 3353 | + let stream = out.stdout; | |
| 3354 | + let frames = match decode_stream(&stream) { | |
| 3355 | + Err(e) => { | |
| 3356 | + let msg = e.to_string(); | |
| 3357 | + assert!( | |
| 3358 | + msg.contains("unsupported"), | |
| 3359 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | |
| 3360 | + ); | |
| 3361 | + named_refusals += 1; | |
| 3362 | + continue; | |
| 3363 | + } | |
| 3364 | + Ok(frames) => frames, | |
| 3365 | + }; | |
| 3366 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | |
| 3367 | + assert_eq!(frames.len(), frame_count); | |
| 3368 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 3369 | + assert_eq!( | |
| 3370 | + got.y, want.y, | |
| 3371 | + "{NAME} frame {i} luma vs ffmpeg (seed {seed}) -- decoded without a named \ | |
| 3372 | + refusal but mismatched, meaning the refusal failed to fire" | |
| 3373 | + ); | |
| 3374 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | |
| 3375 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | |
| 3376 | + } | |
| 3377 | + matched += 1; | |
| 3378 | + } | |
| 3379 | + eprintln!( | |
| 3380 | + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of 40" | |
| 3381 | + ); | |
| 3382 | + } | |
| 3383 | + | |
| 2901 | 3384 | /// `LAST2_FRAME`/`LAST3_FRAME` are just older slots in the same forward |
| 2902 | 3385 | /// reference-buffer ring `LAST_FRAME`/`GOLDEN_FRAME` already prove -- |
| 2903 | 3386 | /// dropping the golden gate's `--max-reference-frames=3 |