forge
Explore
Log in

Don't you dare go Hollow

Decode OBMC_CAUSAL motion mode (SIMPLE vs OBMC, warp refused)

Browse files at this commit

c0d40241df09faa4dbcb6edb587ffe6ab4f5eb96Ahmet Kaan GümüşParent: 0b6a5ba
  • feat
    • decode OBMC_CAUSAL motion mode (SIMPLE vs OBMC, warp refused)
Show full message
feat(av1): decode OBMC_CAUSAL motion mode (SIMPLE vs OBMC, warp refused)

read_motion_mode ported (spec 5.11.24 / decodemv.c ~1520-1600), placed
between MV assignment and the switchable interp filter read, matching
libaom's own order. motion_mode_allowed (reconinter.h) reduces on this
decoder's single-ref path to "an inter neighbour borders the above row
or left column" -- overlappable_above/left port
foreach_overlappable_nb_{above,left} (obmc.h) over the existing MiGrid,
bsize/global-mv/interintra conditions all hold unconditionally here
(global motion is always IDENTITY, no interintra reader, single-ref
only). allow_warped_motion=1 is refused right at an eligible block
(av1_findSamples/num_proj_ref not ported, so this decoder cannot tell
OBMC_CAUSAL from WARPED_CAUSAL once the header allows warp) rather than
guessed at or refused at the header.

OBMC prediction (av1_build_obmc_inter_prediction, reconinter.c): each
bordering above/left inter neighbour is re-predicted over the overlap
strip with its own mv/ref/filter and blended in with the real
obmc_mask_{4,8,16,32} tables, luma then both 4:2:0 chroma planes,
above pass then left -- max_neighbor_obmc's own cap applied, eligibility
scan stays unbounded per libaom.

New gates: a_real_aomenc_stream_with_obmc_decodes_pixel_exact (3x
green, fires 3 real OBMC blocks pixel-exact against ffmpeg) and
a_real_aomenc_stream_with_warped_motion_refuses_or_matches (40/40 named
refusals, 0 desyncs -- confirms the refuse-vs-desync verdict). Existing
cdf_forwarding/deblocking/compound_references/reference_select gates and
the full lib suite (216/0/16) stay green.

Corner-cut: the obmc.h "4-wide block treated as half a chroma pair"
merge is not ported -- no block this decoder codes is narrower than 8px,
so it never fires on any stream this decoder can reach.
crates/ec-av1/src/decode.rsmodified+336 -0
@@ -154,6 +154,17 @@ pub(crate) fn skip_mode_hits() -> usize {
154154 SKIP_MODE_HITS.load(std::sync::atomic::Ordering::Relaxed)
155155 }
156156
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+
157168 /// How many [`read_inter_compound_mode`] reads actually happened
158169 /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own
159170 /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound
@@ -3959,6 +3970,263 @@ fn ref_planes<'a>(
39593970 }
39603971 }
39613972
3973+/// libaom `foreach_overlappable_nb_above` (`obmc.h`): walks the mi row
3974+/// directly above this block's own column span, one bordering block at a
3975+/// time (stepping by that neighbour's own `MiInfo::size`, which is always
3976+/// `<= 16` since no block this decoder ever codes exceeds 64x64), collecting
3977+/// every *inter* neighbour found (an intra or unset cell is skipped, one mi
3978+/// unit at a time, and does not itself count as a step). `max_neighbors`
3979+/// caller-bounds the scan: `1` for the eligibility check (any hit at all),
3980+/// `av1_build_obmc_inter_prediction`'s own `max_neighbor_obmc` table for the
3981+/// real blend pass. Round 1 corner-cut: libaom's own "4-wide block, treat as
3982+/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) is
3983+/// not ported -- no block this decoder codes is narrower than 8px, so it
3984+/// never fires here regardless of what a neighbour's own decoder was.
3985+fn overlappable_above(
3986+ grid: &MiGrid,
3987+ mi_row: usize,
3988+ mi_col: usize,
3989+ bw4: usize,
3990+ mi_cols: usize,
3991+ max_neighbors: usize,
3992+) -> Vec<(usize, usize, MiInfo)> {
3993+ let mut out = Vec::new();
3994+ if mi_row == 0 {
3995+ return out;
3996+ }
3997+ let end_col = (mi_col + bw4).min(mi_cols);
3998+ let mut col = mi_col;
3999+ while col < end_col && out.len() < max_neighbors {
4000+ let cell = grid.get(mi_row - 1, col);
4001+ let step = cell.map_or(1, |c| c.size).max(1);
4002+ if let Some(info) = cell {
4003+ if info.is_inter {
4004+ out.push((col - mi_col, step.min(end_col - col), *info));
4005+ }
4006+ }
4007+ col += step;
4008+ }
4009+ out
4010+}
4011+
4012+/// `foreach_overlappable_nb_left`'s left-column mirror of
4013+/// [`overlappable_above`] -- see its doc for the shared corner-cut.
4014+fn overlappable_left(
4015+ grid: &MiGrid,
4016+ mi_row: usize,
4017+ mi_col: usize,
4018+ bh4: usize,
4019+ mi_rows: usize,
4020+ max_neighbors: usize,
4021+) -> Vec<(usize, usize, MiInfo)> {
4022+ let mut out = Vec::new();
4023+ if mi_col == 0 {
4024+ return out;
4025+ }
4026+ let end_row = (mi_row + bh4).min(mi_rows);
4027+ let mut row = mi_row;
4028+ while row < end_row && out.len() < max_neighbors {
4029+ let cell = grid.get(row, mi_col - 1);
4030+ let step = cell.map_or(1, |c| c.size).max(1);
4031+ if let Some(info) = cell {
4032+ if info.is_inter {
4033+ out.push((row - mi_row, step.min(end_row - row), *info));
4034+ }
4035+ }
4036+ row += step;
4037+ }
4038+ out
4039+}
4040+
4041+/// `av1_get_obmc_mask` (`reconinter.c`): the per-position blend weight
4042+/// (`AOM_BLEND_A64` numerator, out of 64) for the neighbour's own
4043+/// contribution's *complement* -- i.e. `dst = (mask*orig + (64-mask)*nbr +
4044+/// 32) >> 6`, low near the shared border (heavier neighbour weight) rising
4045+/// to 64 (no neighbour contribution) away from it. Only the lengths this
4046+/// decoder's own overlap sizes ever produce (luma 8/16/32, chroma 4/8/16)
4047+/// are transcribed.
4048+fn obmc_mask(len: usize) -> &'static [u8] {
4049+ const M4: [u8; 4] = [39, 50, 59, 64];
4050+ const M8: [u8; 8] = [36, 42, 48, 53, 57, 61, 64, 64];
4051+ const M16: [u8; 16] = [
4052+ 34, 37, 40, 43, 46, 49, 52, 54, 56, 58, 60, 61, 64, 64, 64, 64,
4053+ ];
4054+ const M32: [u8; 32] = [
4055+ 33, 35, 36, 38, 40, 41, 43, 44, 45, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 60,
4056+ 61, 62, 64, 64, 64, 64, 64, 64, 64, 64,
4057+ ];
4058+ match len {
4059+ 4 => &M4,
4060+ 8 => &M8,
4061+ 16 => &M16,
4062+ 32 => &M32,
4063+ _ => unreachable!("obmc overlap length outside this decoder's own block-size range"),
4064+ }
4065+}
4066+
4067+/// A bordering block's own resolved interp filter kernel, `(h, v)` --
4068+/// mirrors [`resolve_interp_filter`]'s own return order from its stored
4069+/// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` =
4070+/// `[v_sym, h_sym]`). Never calls `from_switchable_symbol` on the `[3, 3]`
4071+/// sentinel: that value is only ever stored for an intra neighbour (already
4072+/// excluded by [`overlappable_above`]/[`overlappable_left`]'s `is_inter`
4073+/// gate) or when `interp_fixed` is `Some` for the whole frame, handled here
4074+/// first.
4075+fn neighbour_filter(
4076+ interp_fixed: Option<mc::InterpFilterKind>,
4077+ sym: [u8; 2],
4078+) -> (mc::InterpFilterKind, mc::InterpFilterKind) {
4079+ if let Some(kind) = interp_fixed {
4080+ return (kind, kind);
4081+ }
4082+ (
4083+ mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize),
4084+ mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize),
4085+ )
4086+}
4087+
4088+/// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh
4089+/// against its own `mv`/reference/filter (libaom `av1_build_inter_predictor`
4090+/// under `av1_setup_build_prediction_by_{above,left}_pred`).
4091+#[allow(clippy::too_many_arguments)]
4092+fn obmc_neighbour_pred(
4093+ refplane: &PlaneBuf,
4094+ x: usize,
4095+ y: usize,
4096+ mv: (i32, i32),
4097+ w: usize,
4098+ h: usize,
4099+ luma: bool,
4100+ h_kind: mc::InterpFilterKind,
4101+ v_kind: mc::InterpFilterKind,
4102+) -> Vec<u8> {
4103+ let mut out = vec![0u8; w * h];
4104+ mc::predict_with_filters(
4105+ &refplane.data,
4106+ refplane.width,
4107+ refplane.true_width,
4108+ refplane.true_height,
4109+ mv_to_q4(x, mv.1, luma),
4110+ mv_to_q4(y, mv.0, luma),
4111+ w,
4112+ h,
4113+ h_kind,
4114+ v_kind,
4115+ &mut out,
4116+ );
4117+ out
4118+}
4119+
4120+/// Blends `tmp` into `dst` (stride `stride`) at `(ox, oy)`, mask varying by
4121+/// row (the above-neighbour pass, `aom_blend_a64_vmask`).
4122+fn obmc_blend_v(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) {
4123+ let mask = obmc_mask(h);
4124+ for row in 0..h {
4125+ let m = u32::from(mask[row]);
4126+ for col in 0..w {
4127+ let d = &mut dst[(oy + row) * stride + ox + col];
4128+ let t = u32::from(tmp[row * w + col]);
4129+ *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8;
4130+ }
4131+ }
4132+}
4133+
4134+/// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the
4135+/// left-neighbour pass, `aom_blend_a64_hmask`).
4136+fn obmc_blend_h(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) {
4137+ let mask = obmc_mask(w);
4138+ for row in 0..h {
4139+ for col in 0..w {
4140+ let m = u32::from(mask[col]);
4141+ let d = &mut dst[(oy + row) * stride + ox + col];
4142+ let t = u32::from(tmp[row * w + col]);
4143+ *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8;
4144+ }
4145+ }
4146+}
4147+
4148+/// `av1_build_obmc_inter_prediction` (libaom `reconinter.c`): re-predicts
4149+/// the overlap strip against each bordering above/left inter neighbour's own
4150+/// mv/ref/filter and blends it into this block's just-built single-reference
4151+/// prediction, luma then both 4:2:0 chroma planes -- above pass first, then
4152+/// left, each reading only the *original* prediction this function was
4153+/// handed (never the other pass's own output), matching libaom's own
4154+/// independence between the two. `max_neighbor_obmc`'s own cap table
4155+/// (`{0,1,2,3,4,4}` indexed by `mi_size_wide_log2`/`_high_log2`, this
4156+/// decoder's own square blocks always index the same value both ways) bounds
4157+/// how many bordering blocks actually get blended, separate from the
4158+/// eligibility scan's own unbounded ("any at all") walk.
4159+#[allow(clippy::too_many_arguments)]
4160+fn obmc_blend(
4161+ grid: &MiGrid,
4162+ neighbours: &Neighbours,
4163+ mi_row: usize,
4164+ mi_col: usize,
4165+ bw4: usize,
4166+ mi_rows: usize,
4167+ mi_cols: usize,
4168+ side: usize,
4169+ chroma_side: usize,
4170+ px: usize,
4171+ py: usize,
4172+ cpx: usize,
4173+ cpy: usize,
4174+ ref_y: &PlaneBuf,
4175+ ref_u: &PlaneBuf,
4176+ ref_v: &PlaneBuf,
4177+ other_refs: &RefSlots,
4178+ interp_fixed: Option<mc::InterpFilterKind>,
4179+ pred_y: &mut [u8],
4180+ pred_u: &mut [u8],
4181+ pred_v: &mut [u8],
4182+) -> Result<()> {
4183+ let max_neighbors = match bw4 {
4184+ 1..=4 => 2,
4185+ 5..=8 => 3,
4186+ _ => 4,
4187+ };
4188+ let overlap = side / 2;
4189+ let coverlap = overlap / 2;
4190+
4191+ for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_neighbors)
4192+ {
4193+ // `Neighbours::above_filter` is indexed in `SUB`(16px)-wide columns
4194+ // (this decoder's own outer block-loop granularity), one step
4195+ // coarser than the mi(4px) units `overlappable_above` walks in --
4196+ // divide back down to that column.
4197+ let (h_kind, v_kind) = neighbour_filter(
4198+ interp_fixed,
4199+ neighbours.above_filter[(mi_col + off4) / SUB_MI as usize],
4200+ );
4201+ let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
4202+ let (bw, bh, ox) = (span4 * 4, overlap, off4 * 4);
4203+ let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind);
4204+ obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y);
4205+ let (cbw, cbh, cox) = (bw / 2, coverlap, ox / 2);
4206+ let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind);
4207+ obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u);
4208+ let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind);
4209+ obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v);
4210+ }
4211+
4212+ for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bw4, mi_rows, max_neighbors) {
4213+ let (h_kind, v_kind) = neighbour_filter(
4214+ interp_fixed,
4215+ neighbours.left_filter[(mi_row + off4) / SUB_MI as usize],
4216+ );
4217+ let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
4218+ let (bw, bh, oy) = (overlap, span4 * 4, off4 * 4);
4219+ let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind);
4220+ obmc_blend_h(pred_y, side, 0, oy, bw, bh, &tmp_y);
4221+ let (cbw, cbh, coy) = (coverlap, bh / 2, oy / 2);
4222+ let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind);
4223+ obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, cbh, &tmp_u);
4224+ let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind);
4225+ obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, cbh, &tmp_v);
4226+ }
4227+ Ok(())
4228+}
4229+
39624230 /// `is_any_masked_compound_used` (libaom `reconinter.h`), specialised to
39634231 /// the square block sizes this decoder ever decodes (32/16/8, all
39644232 /// `min(w,h) >= 8`, `is_comp_ref_allowed` true): `COMPOUND_DIFFWTD` is then
@@ -5015,6 +5283,48 @@ fn decode_inter_block(
50155283 };
50165284 (mv, false)
50175285 };
5286+ // lane-motionmode round 1: `read_motion_mode` (spec 5.11.24;
5287+ // libaom `decodemv.c` read_inter_block_mode_info, ~1520-1528),
5288+ // placed right after MV assignment and before the switchable
5289+ // interp filter read below (`read_mb_interp_filter`, decodemv.c
5290+ // ~1600) -- libaom's own sequential order. `motion_mode_allowed`
5291+ // (`reconinter.h`) reduces, for every block this single-ref path
5292+ // reaches, to "does an inter neighbour border the above row or
5293+ // left column": `is_motion_variation_allowed_bsize` always holds
5294+ // (`side` is never below 16px on this path), `ref_frame[1] !=
5295+ // INTRA_FRAME` always holds (no interintra reader here),
5296+ // `is_motion_variation_allowed_compound` always holds (this is
5297+ // the single-ref branch), and `is_global_mv_block` never
5298+ // triggers (this decoder's global motion is always `IDENTITY`,
5299+ // so its warp `type` is never `> TRANSLATION`). A stream with
5300+ // `allow_warped_motion=1` is refused right at an eligible block
5301+ // rather than guessed at: `av1_findSamples`/`num_proj_ref` is
5302+ // not ported, so this decoder cannot tell a real
5303+ // `WARPED_CAUSAL`-eligible block (3-symbol `motion_mode_cdf`)
5304+ // from an `OBMC_CAUSAL`-only one (2-symbol `obmc_cdf`) whenever
5305+ // the header allows warp -- reading the wrong alphabet desyncs
5306+ // the tile.
5307+ let motion_mode_eligible = switchable_motion_mode
5308+ && !skip_mode
5309+ && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty()
5310+ || !overlappable_left(grid, mi_row, mi_col, bw4, mi_rows as usize, 1)
5311+ .is_empty());
5312+ let mut obmc_selected = false;
5313+ if motion_mode_eligible {
5314+ if allow_warped_motion {
5315+ return Err(unsupported(
5316+ "a motion-variation-eligible block under allow_warped_motion=1 \
5317+ (round 1 only reads the 2-symbol obmc_cdf; telling OBMC_CAUSAL \
5318+ from WARPED_CAUSAL needs av1_findSamples, not ported)",
5319+ ));
5320+ }
5321+ // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3.
5322+ let bsize_idx = (side.trailing_zeros() - 3) as usize;
5323+ obmc_selected = dec.symbol(&mut cdfs.obmc[bsize_idx]) == 1;
5324+ if obmc_selected {
5325+ OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
5326+ }
5327+ }
50185328 // spec `get_ref_filter_type`: a neighbour's own filter only feeds
50195329 // this block's switchable_interp context when that neighbour coded
50205330 // the SAME reference frame this block is about to read -- a
@@ -5120,6 +5430,32 @@ fn decode_inter_block(
51205430 &mut pred_v,
51215431 );
51225432
5433+ if obmc_selected {
5434+ obmc_blend(
5435+ grid,
5436+ neighbours,
5437+ mi_row,
5438+ mi_col,
5439+ bw4,
5440+ mi_rows as usize,
5441+ mi_cols as usize,
5442+ side,
5443+ chroma_side,
5444+ px,
5445+ py,
5446+ cpx,
5447+ cpy,
5448+ ref_y,
5449+ ref_u,
5450+ ref_v,
5451+ other_refs,
5452+ interp_fixed,
5453+ &mut pred_y,
5454+ &mut pred_u,
5455+ &mut pred_v,
5456+ )?;
5457+ }
5458+
51235459 if skip {
51245460 y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);
51255461 u.reconstruct_mc(
crates/ec-av1/src/stream.rsmodified+307 -0
@@ -2900,6 +2900,313 @@ mod tests {
29002900 );
29012901 }
29022902
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 1: `--enable-warped-motion=1` must be a NAMED
3066+ /// refusal, never a silent mis-decode -- this decoder does not port
3067+ /// `av1_findSamples`/`num_proj_ref`, so it cannot tell `OBMC_CAUSAL`
3068+ /// from `WARPED_CAUSAL` at an eligible block once the header allows
3069+ /// warp (see `decode_inter_block`'s own `allow_warped_motion` refusal).
3070+ /// Every attempt across the seed sweep must either name the refusal or
3071+ /// decode pixel-exact (an eligible block simply never fired in that
3072+ /// attempt) -- a silent pixel mismatch here would mean the refusal
3073+ /// failed to fire on a stream that actually needed it.
3074+ #[test]
3075+ fn a_real_aomenc_stream_with_warped_motion_refuses_or_matches() {
3076+ const NAME: &str = "a_real_aomenc_stream_with_warped_motion_refuses_or_matches";
3077+ let _gate_lock = lock_gate_counters();
3078+ if !have_ffmpeg() {
3079+ eprintln!("SKIP {NAME}: no ffmpeg");
3080+ return;
3081+ }
3082+ if !have_aomenc() {
3083+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3084+ return;
3085+ }
3086+ let (width, height, frame_count) = (64usize, 64usize, 24usize);
3087+ let mut named_refusals = 0u32;
3088+ let mut matched = 0u32;
3089+ for attempt in 0..40u32 {
3090+ let seed = 42 + attempt;
3091+ let duration = frame_count as f64 / 25.0;
3092+ let source =
3093+ format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25");
3094+ let y4m = Command::new("ffmpeg")
3095+ .args([
3096+ "-v",
3097+ "error",
3098+ "-f",
3099+ "lavfi",
3100+ "-i",
3101+ &source,
3102+ "-pix_fmt",
3103+ "yuv420p",
3104+ "-f",
3105+ "yuv4mpegpipe",
3106+ "-",
3107+ ])
3108+ .stdin(Stdio::null())
3109+ .stdout(Stdio::piped())
3110+ .stderr(Stdio::piped())
3111+ .output()
3112+ .expect("ffmpeg failed to run");
3113+ assert!(
3114+ y4m.status.success(),
3115+ "ffmpeg fixture: {}",
3116+ String::from_utf8_lossy(&y4m.stderr)
3117+ );
3118+ let args: Vec<&str> = vec![
3119+ "--codec=av1",
3120+ "--passes=1",
3121+ "--end-usage=q",
3122+ "--cq-level=45",
3123+ "--cpu-used=0",
3124+ "--kf-max-dist=1000",
3125+ "--threads=1",
3126+ "--row-mt=0",
3127+ "--auto-alt-ref=1",
3128+ "--lag-in-frames=16",
3129+ "--enable-fwd-kf=0",
3130+ "--enable-order-hint=1",
3131+ "--enable-warped-motion=1",
3132+ "--enable-obmc=1",
3133+ "--enable-masked-comp=0",
3134+ "--enable-interintra-comp=0",
3135+ "--enable-onesided-comp=0",
3136+ "--enable-interintra-wedge=0",
3137+ "--enable-smooth-interintra=0",
3138+ "--enable-rect-partitions=0",
3139+ "--enable-ab-partitions=0",
3140+ "--enable-1to4-partitions=0",
3141+ "--enable-filter-intra=0",
3142+ "--enable-smooth-intra=0",
3143+ "--enable-paeth-intra=0",
3144+ "--enable-directional-intra=0",
3145+ "--enable-angle-delta=0",
3146+ "--enable-tx-size-search=0",
3147+ "--enable-cdef=0",
3148+ "--enable-restoration=0",
3149+ "--max-partition-size=32",
3150+ "--min-partition-size=32",
3151+ "--enable-palette=0",
3152+ "--enable-intrabc=0",
3153+ "--enable-cfl-intra=0",
3154+ "--enable-ref-frame-mvs=0",
3155+ "--obu",
3156+ "-o",
3157+ "-",
3158+ "-",
3159+ ];
3160+ let mut child = Command::new(aomenc_path())
3161+ .args(&args)
3162+ .stdin(Stdio::piped())
3163+ .stdout(Stdio::piped())
3164+ .stderr(Stdio::piped())
3165+ .spawn()
3166+ .expect("aomenc failed to start");
3167+ child
3168+ .stdin
3169+ .take()
3170+ .expect("aomenc stdin")
3171+ .write_all(&y4m.stdout)
3172+ .expect("writing y4m to aomenc");
3173+ let out = child.wait_with_output().expect("aomenc failed to run");
3174+ assert!(
3175+ out.status.success(),
3176+ "aomenc refused the fixture: {}",
3177+ String::from_utf8_lossy(&out.stderr)
3178+ );
3179+ let stream = out.stdout;
3180+ let frames = match decode_stream(&stream) {
3181+ Err(e) => {
3182+ let msg = e.to_string();
3183+ assert!(
3184+ msg.contains("unsupported"),
3185+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3186+ );
3187+ named_refusals += 1;
3188+ continue;
3189+ }
3190+ Ok(frames) => frames,
3191+ };
3192+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
3193+ assert_eq!(frames.len(), frame_count);
3194+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3195+ assert_eq!(
3196+ got.y, want.y,
3197+ "{NAME} frame {i} luma vs ffmpeg (seed {seed}) -- decoded without a named \
3198+ refusal but mismatched, meaning the refusal failed to fire"
3199+ );
3200+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
3201+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
3202+ }
3203+ matched += 1;
3204+ }
3205+ eprintln!(
3206+ "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of 40"
3207+ );
3208+ }
3209+
29033210 /// `LAST2_FRAME`/`LAST3_FRAME` are just older slots in the same forward
29043211 /// reference-buffer ring `LAST_FRAME`/`GOLDEN_FRAME` already prove --
29053212 /// dropping the golden gate's `--max-reference-frames=3