forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1lf': the in-loop deblocking filter

Browse files at this commit

e3b26486e2a806132308947a8694fc98e382791aAhmet Kaan GümüşParent: 765bf6366b41fc
Spec 7.14, run before CDEF in both tile paths: edge params collapse
because this decoder's transform always equals block size, uniform
filter level with ref/mode deltas, filter4/6/8/14 kernels from
aom_dsp. Real aomenc intra streams with deblocking on now decode
pixel-exact; the inter-sequence gate skips on a pre-existing
partition-type refusal that is the next lane's work.
crates/ec-av1/src/decode.rsmodified+560 -6
@@ -21,7 +21,7 @@
21 //! too). Anything outside that refuses with [`Error::unsupported`] rather than21 //! too). Anything outside that refuses with [`Error::unsupported`] rather than
22 //! silently miscoding.22 //! silently miscoding.
23 23
24-use ec_av1_syntax::CdefParams;24+use ec_av1_syntax::{CdefParams, LoopFilterParams};
25 use ec_core::{Error, Result};25 use ec_core::{Error, Result};
26 26
27 use crate::cdf;27 use crate::cdf;
@@ -50,6 +50,17 @@ static FILTER_INTRA_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::At
50 pub(crate) fn filter_intra_hits() -> usize {50 pub(crate) fn filter_intra_hits() -> usize {
51 FILTER_INTRA_HITS.load(std::sync::atomic::Ordering::Relaxed)51 FILTER_INTRA_HITS.load(std::sync::atomic::Ordering::Relaxed)
52 }52 }
53+
54+/// How many 4-pixel deblocking edge groups [`edge_params`] has actually
55+/// selected for filtering, across every call in the process -- the same
56+/// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
57+/// exercised `apply_deblock` rather than every edge landing on level 0.
58+static DEBLOCK_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
59+
60+/// Current value of [`DEBLOCK_HITS`].
61+pub(crate) fn deblock_hits() -> usize {
62+ DEBLOCK_HITS.load(std::sync::atomic::Ordering::Relaxed)
63+}
53 const SUB_MI: u32 = 4;64 const SUB_MI: u32 = 4;
54 const MI: usize = 4;65 const MI: usize = 4;
55 const SB: usize = 64;66 const SB: usize = 64;
@@ -415,6 +426,18 @@ struct Neighbours {
415 /// mi cell one coded block covers.426 /// mi cell one coded block covers.
416 skip_grid: Vec<bool>,427 skip_grid: Vec<bool>,
417 skip_grid_cols_mi: usize,428 skip_grid_cols_mi: usize,
429+ /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder
430+ /// never splits a coded block's transform below its own size (round 2:
431+ /// `TxMode::Select`/`tx_depth` refused), so a block's own side *is* its
432+ /// transform size, spec 7.14's `get_transform_size`/`get_filter_level`
433+ /// edge-length lookup (`apply_deblock`).
434+ tx_grid: Vec<u8>,
435+ /// Per-4x4-mi `is_inter` flag -- the loop filter's ref/mode delta lookup
436+ /// (spec 7.14.4 `get_filter_level`; every inter block this decoder
437+ /// produces is a single `LAST_FRAME` reference with a non-`GLOBALMV`
438+ /// mode, so `is_inter` alone picks the right `ref_deltas`/`mode_deltas`
439+ /// entry without a separate ref/mode grid).
440+ inter_grid: Vec<bool>,
418 }441 }
419 442
420 impl Neighbours {443 impl Neighbours {
@@ -438,6 +461,27 @@ impl Neighbours {
438 mi_rows,461 mi_rows,
439 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],462 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
440 skip_grid_cols_mi: cols * (SUB / MI),463 skip_grid_cols_mi: cols * (SUB / MI),
464+ tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
465+ inter_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
466+ }
467+ }
468+
469+ /// Marks every 4x4 mi cell a just-decoded coded block covers with its own
470+ /// transform width (in pixels) and `is_inter` flag -- the loop filter's
471+ /// per-edge lookup (`apply_deblock`), filled at the same call sites and
472+ /// units as [`Self::fill_skip_grid`].
473+ fn fill_lf_grid(&mut self, at_mi: (usize, usize), side_mi: usize, tx_px: u8, is_inter: bool) {
474+ let (mi_r, mi_c) = at_mi;
475+ for rr in 0..side_mi {
476+ for cc in 0..side_mi {
477+ let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
478+ if let Some(cell) = self.tx_grid.get_mut(idx) {
479+ *cell = tx_px;
480+ }
481+ if let Some(cell) = self.inter_grid.get_mut(idx) {
482+ *cell = is_inter;
483+ }
484+ }
441 }485 }
442 }486 }
443 487
@@ -464,6 +508,17 @@ impl Neighbours {
464 /// Spec/libaom `is_8x8_block_skip` requires *every* one of the four 4x4508 /// Spec/libaom `is_8x8_block_skip` requires *every* one of the four 4x4
465 /// mi cells the 8x8 covers to be skip (a smaller-than-8x8 partition can509 /// mi cells the 8x8 covers to be skip (a smaller-than-8x8 partition can
466 /// straddle the region with a mix of skip/non-skip blocks).510 /// straddle the region with a mix of skip/non-skip blocks).
511+ /// A single 4x4 mi cell's own `skip` flag, unaggregated (unlike
512+ /// [`Self::is_skip_txfm`]'s 8x8 all-four-cells rule) -- what the loop
513+ /// filter's `curr_skipped`/`pv_skip_txfm` (spec 7.14.2) want, since a
514+ /// filtered edge's two sides are each exactly one coded block wide.
515+ fn skip_at(&self, mi_r: usize, mi_c: usize) -> bool {
516+ self.skip_grid
517+ .get(mi_r * self.skip_grid_cols_mi + mi_c)
518+ .copied()
519+ .unwrap_or(false)
520+ }
521+
467 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {522 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {
468 (0..2).all(|rr| {523 (0..2).all(|rr| {
469 (0..2).all(|cc| {524 (0..2).all(|cc| {
@@ -1096,6 +1151,12 @@ fn decode_block(
1096 }1151 }
1097 neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);1152 neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);
1098 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);1153 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);
1154+ neighbours.fill_lf_grid(
1155+ (r * (SUB / MI), c * (SUB / MI)),
1156+ side / MI,
1157+ side as u8,
1158+ false,
1159+ );
1099 Ok(())1160 Ok(())
1100 }1161 }
1101 1162
@@ -1238,6 +1299,7 @@ fn decode_leaf8(
1238 }1299 }
1239 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);1300 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
1240 neighbours.fill_skip_grid(leaf_mi, 2, skip);1301 neighbours.fill_skip_grid(leaf_mi, 2, skip);
1302+ neighbours.fill_lf_grid(leaf_mi, 2, 8, false);
1241 Ok(mode)1303 Ok(mode)
1242 }1304 }
1243 1305
@@ -1425,6 +1487,462 @@ fn cdef_filter_block(
1425 /// size. `cdef_bits == 0` is this crate's only supported case so far (see the1487 /// size. `cdef_bits == 0` is this crate's only supported case so far (see the
1426 /// refusal in `stream.rs`), so every 64x64 filter block always uses index 0's1488 /// refusal in `stream.rs`), so every 64x64 filter block always uses index 0's
1427 /// strengths -- no per-block `cdef_idx` selection is implemented yet.1489 /// strengths -- no per-block `cdef_idx` selection is implemented yet.
1490+/// Spec 7.14: the in-loop deblocking filter, applied once per frame after
1491+/// tile reconstruction and before [`apply_cdef`]. Uniform-level path only --
1492+/// `stream.rs` already refuses `delta_lf_present`/segmentation upstream, so
1493+/// every block's level comes from [`LoopFilterParams::level`] plus the
1494+/// `ref_deltas`/`mode_deltas` adjustment alone (spec 7.14.4's
1495+/// `get_filter_level`, precomputed per-block here rather than cached in a
1496+/// table the way libaom's `av1_loop_filter_frame_init` does).
1497+///
1498+/// Ported from libaom's `av1/common/av1_loopfilter.c` (edge/level decision)
1499+/// and `aom_dsp/loopfilter.c` (the `aom_lpf_*` pixel kernels).
1500+fn apply_deblock(
1501+ y: &mut PlaneBuf,
1502+ u: &mut PlaneBuf,
1503+ v: &mut PlaneBuf,
1504+ lf: &LoopFilterParams,
1505+ n: &Neighbours,
1506+) {
1507+ if lf.level[0] != 0 || lf.level[1] != 0 {
1508+ deblock_plane(y, 0, lf, n);
1509+ }
1510+ if lf.level[2] != 0 {
1511+ deblock_plane(u, 1, lf, n);
1512+ }
1513+ if lf.level[3] != 0 {
1514+ deblock_plane(v, 2, lf, n);
1515+ }
1516+}
1517+
1518+/// Luma-mi-grid position (row or col) a plane-local pixel coordinate falls
1519+/// in -- `Neighbours::tx_grid`/`inter_grid` are always indexed at the luma
1520+/// 4x4-mi grain, even when `coord` is a chroma coordinate (2 chroma px per
1521+/// mi unit under this decoder's assumed 4:2:0 subsampling).
1522+fn plane_to_mi(chroma: bool, coord: usize) -> usize {
1523+ if chroma { coord / 2 } else { coord / 4 }
1524+}
1525+
1526+/// This plane's own transform width in pixels at the covering block, spec
1527+/// `get_transform_size`'s plane-aware lookup: `tx_grid` stores the luma
1528+/// width directly; chroma halves it (this decoder's UV transform is always
1529+/// half its coded block's luma transform, spec's `av1_get_max_uv_txsize`
1530+/// under 4:2:0 and a block that never splits its own transform).
1531+fn tx_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 {
1532+ let luma_tx = n
1533+ .tx_grid
1534+ .get(mi_r * n.skip_grid_cols_mi + mi_c)
1535+ .copied()
1536+ .unwrap_or(0) as u32;
1537+ if chroma { luma_tx / 2 } else { luma_tx }
1538+}
1539+
1540+/// `tx_size_wide_unit_log2`/`tx_size_high_unit_log2`: `log2(px / 4)`, the
1541+/// index [`tx_dim_to_filter_length`] and the chroma 4-vs-6 choice key on.
1542+fn unit_log2(px: u32) -> i32 {
1543+ if px == 0 {
1544+ 0
1545+ } else {
1546+ px.trailing_zeros() as i32 - 2
1547+ }
1548+}
1549+
1550+/// spec 7.14.4's `get_filter_level`, restricted to this decoder's shapes:
1551+/// every inter block is a single `LAST_FRAME` reference with a non-`GLOBALMV`
1552+/// mode, so `is_inter` alone selects `ref_deltas`/`mode_deltas` (design note
1553+/// on [`Neighbours::inter_grid`]).
1554+fn lf_level(lf: &LoopFilterParams, plane_idx: usize, dir: usize, is_inter: bool) -> i32 {
1555+ let base = i32::from(if plane_idx == 0 {
1556+ lf.level[dir]
1557+ } else if plane_idx == 1 {
1558+ lf.level[2]
1559+ } else {
1560+ lf.level[3]
1561+ });
1562+ if !lf.delta_enabled {
1563+ return base;
1564+ }
1565+ let scale = 1i32 << (base >> 5);
1566+ let ref_idx = usize::from(is_inter);
1567+ let mut lvl = base + i32::from(lf.ref_deltas[ref_idx]) * scale;
1568+ if is_inter {
1569+ lvl += i32::from(lf.mode_deltas[1]) * scale;
1570+ }
1571+ lvl.clamp(0, 63)
1572+}
1573+
1574+/// Spec 7.14.2's `set_lpf_parameters`, restricted to the uniform-level,
1575+/// no-segmentation, no-delta-LF path and to this decoder's own invariant
1576+/// that a coded block's transform is always its own full size -- so a TU
1577+/// edge is always also a PU edge, and the "both sides skipped, not a PU
1578+/// edge" suppression (which only ever fires at a non-PU-edge TU boundary)
1579+/// never applies here, letting this skip the `skip`/`skip_txfm` lookup
1580+/// entirely. Returns `None` when this 4-pixel edge group is not filtered.
1581+fn edge_params(
1582+ lf: &LoopFilterParams,
1583+ n: &Neighbours,
1584+ plane_idx: usize,
1585+ dir: usize,
1586+ chroma: bool,
1587+ x0: usize,
1588+ y0: usize,
1589+) -> Option<(u8, i32)> {
1590+ let (mi_r, mi_c) = (plane_to_mi(chroma, y0), plane_to_mi(chroma, x0));
1591+ let cur_tx = tx_px_at(n, chroma, mi_r, mi_c);
1592+ if cur_tx == 0 || (if dir == 0 { x0 } else { y0 }) % cur_tx as usize != 0 {
1593+ return None;
1594+ }
1595+ let cur_inter = n.inter_grid[mi_r * n.skip_grid_cols_mi + mi_c];
1596+ let (pv_mi_r, pv_mi_c) = if dir == 0 {
1597+ (mi_r, mi_c - 1)
1598+ } else {
1599+ (mi_r - 1, mi_c)
1600+ };
1601+ let pv_tx = tx_px_at(n, chroma, pv_mi_r, pv_mi_c);
1602+ let pv_inter = n.inter_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c];
1603+
1604+ let cur_level = lf_level(lf, plane_idx, dir, cur_inter);
1605+ let pv_level = lf_level(lf, plane_idx, dir, pv_inter);
1606+ if cur_level == 0 && pv_level == 0 {
1607+ return None;
1608+ }
1609+ let dim = unit_log2(cur_tx).min(unit_log2(pv_tx)).clamp(0, 4) as usize;
1610+ let len: u8 = if chroma {
1611+ if dim == 0 { 4 } else { 6 }
1612+ } else {
1613+ [4, 8, 14, 14, 14][dim]
1614+ };
1615+ let level = if cur_level != 0 { cur_level } else { pv_level };
1616+ DEBLOCK_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1617+ Some((len, level))
1618+}
1619+
1620+/// `update_sharpness`'s per-level `(blimit, limit, hev_thr)` triple.
1621+fn deblock_thresholds(level: i32, sharpness: u8) -> (i32, i32, i32) {
1622+ let sharpness = i32::from(sharpness);
1623+ let shift = i32::from(sharpness > 0) + i32::from(sharpness > 4);
1624+ let mut lim = level >> shift;
1625+ if sharpness > 0 {
1626+ lim = lim.min(9 - sharpness);
1627+ }
1628+ lim = lim.max(1);
1629+ (2 * (level + 2) + lim, lim, level >> 4)
1630+}
1631+
1632+fn sclamp(v: i32) -> i32 {
1633+ v.clamp(-128, 127)
1634+}
1635+
1636+fn round_pow2(v: i32, n: u32) -> i32 {
1637+ (v + (1 << (n - 1))) >> n
1638+}
1639+
1640+/// `filter4`: the narrow 4-tap kernel, and every wider kernel's non-flat
1641+/// fallback.
1642+fn filter4(mask: bool, thresh: i32, p1: i32, p0: i32, q0: i32, q1: i32) -> [i32; 4] {
1643+ if !mask {
1644+ return [p1, p0, q0, q1];
1645+ }
1646+ let hev = (p1 - p0).abs() > thresh || (q1 - q0).abs() > thresh;
1647+ let (ps1, ps0, qs0, qs1) = (p1 - 128, p0 - 128, q0 - 128, q1 - 128);
1648+ let outer = if hev { sclamp(ps1 - qs1) } else { 0 };
1649+ let filter = sclamp(outer + 3 * (qs0 - ps0));
1650+ let filter1 = sclamp(filter + 4) >> 3;
1651+ let filter2 = sclamp(filter + 3) >> 3;
1652+ let oq0 = sclamp(qs0 - filter1) + 128;
1653+ let op0 = sclamp(ps0 + filter2) + 128;
1654+ let tap = if hev { 0 } else { round_pow2(filter1, 1) };
1655+ let oq1 = sclamp(qs1 - tap) + 128;
1656+ let op1 = sclamp(ps1 + tap) + 128;
1657+ [op1, op0, oq0, oq1]
1658+}
1659+
1660+/// `filter6`: chroma's flat 5-tap smoothing (spec `[1,2,2,2,1]`) over
1661+/// `filter4`'s narrow taps.
1662+#[allow(clippy::too_many_arguments)]
1663+fn filter6(
1664+ mask: bool,
1665+ thresh: i32,
1666+ flat: bool,
1667+ p2: i32,
1668+ p1: i32,
1669+ p0: i32,
1670+ q0: i32,
1671+ q1: i32,
1672+ q2: i32,
1673+) -> [i32; 4] {
1674+ if flat && mask {
1675+ [
1676+ round_pow2(p2 * 3 + p1 * 2 + p0 * 2 + q0, 3),
1677+ round_pow2(p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1, 3),
1678+ round_pow2(p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2, 3),
1679+ round_pow2(p0 + q0 * 2 + q1 * 2 + q2 * 3, 3),
1680+ ]
1681+ } else {
1682+ filter4(mask, thresh, p1, p0, q0, q1)
1683+ }
1684+}
1685+
1686+/// `filter8`: luma's flat 7-tap smoothing (spec `[1,1,1,2,1,1,1]`).
1687+#[allow(clippy::too_many_arguments)]
1688+fn filter8(
1689+ mask: bool,
1690+ thresh: i32,
1691+ flat: bool,
1692+ p3: i32,
1693+ p2: i32,
1694+ p1: i32,
1695+ p0: i32,
1696+ q0: i32,
1697+ q1: i32,
1698+ q2: i32,
1699+ q3: i32,
1700+) -> [i32; 6] {
1701+ if flat && mask {
1702+ [
1703+ round_pow2(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3),
1704+ round_pow2(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3),
1705+ round_pow2(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3),
1706+ round_pow2(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3),
1707+ round_pow2(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3),
1708+ round_pow2(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3),
1709+ ]
1710+ } else {
1711+ let [op1, op0, oq0, oq1] = filter4(mask, thresh, p1, p0, q0, q1);
1712+ [p2, op1, op0, oq0, oq1, q2]
1713+ }
1714+}
1715+
1716+/// `filter14`: the wide 13-tap smoothing used at 16x16-and-larger transform
1717+/// edges; falls back to [`filter8`] (leaving `op6`/`oq6` untouched either
1718+/// way -- they are only ever taps here, never written).
1719+#[allow(clippy::too_many_arguments)]
1720+fn filter14(
1721+ mask: bool,
1722+ thresh: i32,
1723+ flat: bool,
1724+ flat2: bool,
1725+ p6: i32,
1726+ p5: i32,
1727+ p4: i32,
1728+ p3: i32,
1729+ p2: i32,
1730+ p1: i32,
1731+ p0: i32,
1732+ q0: i32,
1733+ q1: i32,
1734+ q2: i32,
1735+ q3: i32,
1736+ q4: i32,
1737+ q5: i32,
1738+ q6: i32,
1739+) -> [i32; 12] {
1740+ if flat2 && flat && mask {
1741+ [
1742+ round_pow2(p6 * 7 + p5 * 2 + p4 * 2 + p3 + p2 + p1 + p0 + q0, 4),
1743+ round_pow2(
1744+ p6 * 5 + p5 * 2 + p4 * 2 + p3 * 2 + p2 + p1 + p0 + q0 + q1,
1745+ 4,
1746+ ),
1747+ round_pow2(
1748+ p6 * 4 + p5 + p4 * 2 + p3 * 2 + p2 * 2 + p1 + p0 + q0 + q1 + q2,
1749+ 4,
1750+ ),
1751+ round_pow2(
1752+ p6 * 3 + p5 + p4 + p3 * 2 + p2 * 2 + p1 * 2 + p0 + q0 + q1 + q2 + q3,
1753+ 4,
1754+ ),
1755+ round_pow2(
1756+ p6 * 2 + p5 + p4 + p3 + p2 * 2 + p1 * 2 + p0 * 2 + q0 + q1 + q2 + q3 + q4,
1757+ 4,
1758+ ),
1759+ round_pow2(
1760+ p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1 + q2 + q3 + q4 + q5,
1761+ 4,
1762+ ),
1763+ round_pow2(
1764+ p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2 + q3 + q4 + q5 + q6,
1765+ 4,
1766+ ),
1767+ round_pow2(
1768+ p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 + q2 * 2 + q3 + q4 + q5 + q6 * 2,
1769+ 4,
1770+ ),
1771+ round_pow2(
1772+ p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 + q3 * 2 + q4 + q5 + q6 * 3,
1773+ 4,
1774+ ),
1775+ round_pow2(
1776+ p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 + q4 * 2 + q5 + q6 * 4,
1777+ 4,
1778+ ),
1779+ round_pow2(
1780+ p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 + q5 * 2 + q6 * 5,
1781+ 4,
1782+ ),
1783+ round_pow2(p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 + q6 * 7, 4),
1784+ ]
1785+ } else {
1786+ let [op2, op1, op0, oq0, oq1, oq2] =
1787+ filter8(mask, thresh, flat, p3, p2, p1, p0, q0, q1, q2, q3);
1788+ [p5, p4, p3, op2, op1, op0, oq0, oq1, oq2, q3, q4, q5]
1789+ }
1790+}
1791+
1792+/// Filters one 4-pixel edge group: `base` is the plane-local byte offset of
1793+/// the first (`q0`) sample past the edge, `outer_stride` advances to the
1794+/// next of the 4 perpendicular samples, `tap_stride` steps from one tap to
1795+/// the next along the edge's own filtering direction.
1796+#[allow(clippy::too_many_arguments)]
1797+fn filter_edge(
1798+ data: &mut [u8],
1799+ base: usize,
1800+ outer_stride: isize,
1801+ tap_stride: isize,
1802+ len: u8,
1803+ level: i32,
1804+ sharpness: u8,
1805+) {
1806+ let (blimit, limit, hev_thr) = deblock_thresholds(level, sharpness);
1807+ for i in 0..4isize {
1808+ let center = (base as isize + i * outer_stride) as usize;
1809+ let idx = |k: isize| -> usize { (center as isize + k * tap_stride) as usize };
1810+ let px = |k: isize| -> i32 { i32::from(data[idx(k)]) };
1811+ match len {
1812+ 4 => {
1813+ let (p1, p0, q0, q1) = (px(-2), px(-1), px(0), px(1));
1814+ let mask = (p1 - p0).abs() <= limit
1815+ && (q1 - q0).abs() <= limit
1816+ && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit;
1817+ let [op1, op0, oq0, oq1] = filter4(mask, hev_thr, p1, p0, q0, q1);
1818+ data[idx(-2)] = op1.clamp(0, 255) as u8;
1819+ data[idx(-1)] = op0.clamp(0, 255) as u8;
1820+ data[idx(0)] = oq0.clamp(0, 255) as u8;
1821+ data[idx(1)] = oq1.clamp(0, 255) as u8;
1822+ }
1823+ 6 => {
1824+ let (p2, p1, p0, q0, q1, q2) = (px(-3), px(-2), px(-1), px(0), px(1), px(2));
1825+ let mask = (p2 - p1).abs() <= limit
1826+ && (p1 - p0).abs() <= limit
1827+ && (q1 - q0).abs() <= limit
1828+ && (q2 - q1).abs() <= limit
1829+ && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit;
1830+ let flat = (p1 - p0).abs() <= 1
1831+ && (q1 - q0).abs() <= 1
1832+ && (p2 - p0).abs() <= 1
1833+ && (q2 - q0).abs() <= 1;
1834+ let [op1, op0, oq0, oq1] = filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2);
1835+ data[idx(-2)] = op1.clamp(0, 255) as u8;
1836+ data[idx(-1)] = op0.clamp(0, 255) as u8;
1837+ data[idx(0)] = oq0.clamp(0, 255) as u8;
1838+ data[idx(1)] = oq1.clamp(0, 255) as u8;
1839+ }
1840+ 8 => {
1841+ let (p3, p2, p1, p0, q0, q1, q2, q3) =
1842+ (px(-4), px(-3), px(-2), px(-1), px(0), px(1), px(2), px(3));
1843+ let mask = (p3 - p2).abs() <= limit
1844+ && (p2 - p1).abs() <= limit
1845+ && (p1 - p0).abs() <= limit
1846+ && (q1 - q0).abs() <= limit
1847+ && (q2 - q1).abs() <= limit
1848+ && (q3 - q2).abs() <= limit
1849+ && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit;
1850+ let flat = (p1 - p0).abs() <= 1
1851+ && (q1 - q0).abs() <= 1
1852+ && (p2 - p0).abs() <= 1
1853+ && (q2 - q0).abs() <= 1
1854+ && (p3 - p0).abs() <= 1
1855+ && (q3 - q0).abs() <= 1;
1856+ let [op2, op1, op0, oq0, oq1, oq2] =
1857+ filter8(mask, hev_thr, flat, p3, p2, p1, p0, q0, q1, q2, q3);
1858+ data[idx(-3)] = op2.clamp(0, 255) as u8;
1859+ data[idx(-2)] = op1.clamp(0, 255) as u8;
1860+ data[idx(-1)] = op0.clamp(0, 255) as u8;
1861+ data[idx(0)] = oq0.clamp(0, 255) as u8;
1862+ data[idx(1)] = oq1.clamp(0, 255) as u8;
1863+ data[idx(2)] = oq2.clamp(0, 255) as u8;
1864+ }
1865+ _ => {
1866+ let (p6, p5, p4, p3, p2, p1, p0) =
1867+ (px(-7), px(-6), px(-5), px(-4), px(-3), px(-2), px(-1));
1868+ let (q0, q1, q2, q3, q4, q5, q6) =
1869+ (px(0), px(1), px(2), px(3), px(4), px(5), px(6));
1870+ let mask = (p3 - p2).abs() <= limit
1871+ && (p2 - p1).abs() <= limit
1872+ && (p1 - p0).abs() <= limit
1873+ && (q1 - q0).abs() <= limit
1874+ && (q2 - q1).abs() <= limit
1875+ && (q3 - q2).abs() <= limit
1876+ && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit;
1877+ let flat = (p1 - p0).abs() <= 1
1878+ && (q1 - q0).abs() <= 1
1879+ && (p2 - p0).abs() <= 1
1880+ && (q2 - q0).abs() <= 1
1881+ && (p3 - p0).abs() <= 1
1882+ && (q3 - q0).abs() <= 1;
1883+ let flat2 = (p4 - p0).abs() <= 1
1884+ && (q4 - q0).abs() <= 1
1885+ && (p5 - p0).abs() <= 1
1886+ && (q5 - q0).abs() <= 1
1887+ && (p6 - p0).abs() <= 1
1888+ && (q6 - q0).abs() <= 1;
1889+ let out = filter14(
1890+ mask, hev_thr, flat, flat2, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5,
1891+ q6,
1892+ );
1893+ for (k, v) in (-6..=5isize).zip(out) {
1894+ data[idx(k)] = v.clamp(0, 255) as u8;
1895+ }
1896+ }
1897+ }
1898+ }
1899+}
1900+
1901+/// One plane's worth of spec 7.14: every vertical edge across the plane,
1902+/// then every horizontal edge (the order the spec and libaom both use).
1903+fn deblock_plane(plane: &mut PlaneBuf, plane_idx: usize, lf: &LoopFilterParams, n: &Neighbours) {
1904+ let chroma = plane_idx != 0;
1905+ let (tw, th, stride) = (plane.true_width, plane.true_height, plane.width);
1906+ let mut y0 = 0usize;
1907+ while y0 < th {
1908+ let mut x0 = 4usize;
1909+ while x0 < tw {
1910+ if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {
1911+ filter_edge(
1912+ &mut plane.data,
1913+ y0 * stride + x0,
1914+ stride as isize,
1915+ 1,
1916+ len,
1917+ level,
1918+ lf.sharpness,
1919+ );
1920+ }
1921+ x0 += 4;
1922+ }
1923+ y0 += 4;
1924+ }
1925+ let mut x0 = 0usize;
1926+ while x0 < tw {
1927+ let mut y0 = 4usize;
1928+ while y0 < th {
1929+ if let Some((len, level)) = edge_params(lf, n, plane_idx, 1, chroma, x0, y0) {
1930+ filter_edge(
1931+ &mut plane.data,
1932+ y0 * stride + x0,
1933+ 1,
1934+ stride as isize,
1935+ len,
1936+ level,
1937+ lf.sharpness,
1938+ );
1939+ }
1940+ y0 += 4;
1941+ }
1942+ x0 += 4;
1943+ }
1944+}
1945+
1428 fn apply_cdef(1946 fn apply_cdef(
1429 y: &mut PlaneBuf,1947 y: &mut PlaneBuf,
1430 u: &mut PlaneBuf,1948 u: &mut PlaneBuf,
@@ -1558,6 +2076,7 @@ pub fn decode_key_frame_tile(
1558 frame_height: u32,2076 frame_height: u32,
1559 enable_filter_intra: bool,2077 enable_filter_intra: bool,
1560 cdef: &CdefParams,2078 cdef: &CdefParams,
2079+ loop_filter: &LoopFilterParams,
1561 ) -> Result<Picture> {2080 ) -> Result<Picture> {
1562 if mi_cols == 0 || mi_rows == 0 {2081 if mi_cols == 0 || mi_rows == 0 {
1563 return Err(unsupported("a frame with no mode-info grid"));2082 return Err(unsupported("a frame with no mode-info grid"));
@@ -1892,6 +2411,7 @@ pub fn decode_key_frame_tile(
1892 }2411 }
1893 }2412 }
1894 2413
2414+ apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
1895 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);2415 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
1896 2416
1897 let (fw, fh) = (frame_width as usize, frame_height as usize);2417 let (fw, fh) = (frame_width as usize, frame_height as usize);
@@ -2429,6 +2949,12 @@ fn decode_inter_block(
2429 neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]);2949 neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]);
2430 neighbours.record_inter(at, side, skip, is_inter);2950 neighbours.record_inter(at, side, skip, is_inter);
2431 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);2951 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);
2952+ neighbours.fill_lf_grid(
2953+ (r * (SUB / MI), c * (SUB / MI)),
2954+ side / MI,
2955+ side as u8,
2956+ is_inter,
2957+ );
2432 Ok(())2958 Ok(())
2433 }2959 }
2434 2960
@@ -2808,6 +3334,7 @@ fn decode_inter_block8(
2808 }3334 }
2809 }3335 }
2810 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);3336 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
3337+ neighbours.fill_lf_grid(leaf_mi, 2, 8, is_inter);
2811 Ok((skip, is_inter))3338 Ok((skip, is_inter))
2812 }3339 }
2813 3340
@@ -2833,6 +3360,7 @@ pub fn decode_inter_frame_tile(
2833 frame_height: u32,3360 frame_height: u32,
2834 reference: &Picture,3361 reference: &Picture,
2835 cdef: &CdefParams,3362 cdef: &CdefParams,
3363+ loop_filter: &LoopFilterParams,
2836 ) -> Result<Picture> {3364 ) -> Result<Picture> {
2837 if mi_cols == 0 || mi_rows == 0 {3365 if mi_cols == 0 || mi_rows == 0 {
2838 return Err(unsupported("a frame with no mode-info grid"));3366 return Err(unsupported("a frame with no mode-info grid"));
@@ -3096,6 +3624,7 @@ pub fn decode_inter_frame_tile(
3096 }3624 }
3097 }3625 }
3098 3626
3627+ apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
3099 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);3628 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
3100 3629
3101 let (fw, fh) = (frame_width as usize, frame_height as usize);3630 let (fw, fh) = (frame_width as usize, frame_height as usize);
@@ -3141,8 +3670,18 @@ mod tests {
3141 #[test]3670 #[test]
3142 fn a_frame_with_no_mode_info_grid_is_refused() {3671 fn a_frame_with_no_mode_info_grid_is_refused() {
3143 assert!(3672 assert!(
3144- decode_key_frame_tile(&[0u8; 4], 0, 32, 32, 0, 128, false, &CdefParams::default())3673+ decode_key_frame_tile(
3145- .is_err()3674+ &[0u8; 4],
3675+ 0,
3676+ 32,
3677+ 32,
3678+ 0,
3679+ 128,
3680+ false,
3681+ &CdefParams::default(),
3682+ &LoopFilterParams::default()
3683+ )
3684+ .is_err()
3146 );3685 );
3147 }3686 }
3148 3687
@@ -3180,6 +3719,7 @@ mod tests {
3180 h as u32,3719 h as u32,
3181 false,3720 false,
3182 &CdefParams::default(),3721 &CdefParams::default(),
3722+ &LoopFilterParams::default(),
3183 )3723 )
3184 .unwrap();3724 .unwrap();
3185 assert_eq!(decoded.width, w, "{w}x{h}: decoded width");3725 assert_eq!(decoded.width, w, "{w}x{h}: decoded width");
@@ -3251,9 +3791,18 @@ mod tests {
3251 );3791 );
3252 enc.symbol(DC_PRED, &mut cdfs.uv_mode_no_cfl[DC_PRED]);3792 enc.symbol(DC_PRED, &mut cdfs.uv_mode_no_cfl[DC_PRED]);
3253 let data = enc.finish();3793 let data = enc.finish();
3254- let decoded =3794+ let decoded = decode_key_frame_tile(
3255- decode_key_frame_tile(&data, 16, 16, 40, 64, 64, false, &CdefParams::default())3795+ &data,
3256- .unwrap();3796+ 16,
3797+ 16,
3798+ 40,
3799+ 64,
3800+ 64,
3801+ false,
3802+ &CdefParams::default(),
3803+ &LoopFilterParams::default(),
3804+ )
3805+ .unwrap();
3257 assert!(3806 assert!(
3258 decoded.y.iter().all(|&s| s == 128),3807 decoded.y.iter().all(|&s| s == 128),
3259 "a skipped DC_PRED block with no neighbours predicts flat mid-grey"3808 "a skipped DC_PRED block with no neighbours predicts flat mid-grey"
@@ -3434,6 +3983,7 @@ mod tests {
3434 coded_h,3983 coded_h,
3435 false,3984 false,
3436 &CdefParams::default(),3985 &CdefParams::default(),
3986+ &LoopFilterParams::default(),
3437 )3987 )
3438 .unwrap();3988 .unwrap();
3439 assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg");3989 assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg");
@@ -3503,6 +4053,7 @@ mod tests {
3503 height as u32,4053 height as u32,
3504 false,4054 false,
3505 &CdefParams::default(),4055 &CdefParams::default(),
4056+ &LoopFilterParams::default(),
3506 )4057 )
3507 .unwrap();4058 .unwrap();
3508 assert_eq!(4059 assert_eq!(
@@ -3528,6 +4079,7 @@ mod tests {
3528 height as u32,4079 height as u32,
3529 &reference,4080 &reference,
3530 &CdefParams::default(),4081 &CdefParams::default(),
4082+ &LoopFilterParams::default(),
3531 )4083 )
3532 .unwrap();4084 .unwrap();
3533 assert_eq!(4085 assert_eq!(
@@ -3772,6 +4324,7 @@ mod tests {
3772 coded_h,4324 coded_h,
3773 false,4325 false,
3774 &CdefParams::default(),4326 &CdefParams::default(),
4327+ &LoopFilterParams::default(),
3775 )4328 )
3776 .unwrap();4329 .unwrap();
3777 assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg");4330 assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg");
@@ -3786,6 +4339,7 @@ mod tests {
3786 coded_h,4339 coded_h,
3787 &reference,4340 &reference,
3788 &CdefParams::default(),4341 &CdefParams::default(),
4342+ &LoopFilterParams::default(),
3789 )4343 )
3790 .unwrap();4344 .unwrap();
3791 assert_eq!(decoded.y, ffmpeg_frames[i].y, "frame {i} luma vs ffmpeg");4345 assert_eq!(decoded.y, ffmpeg_frames[i].y, "frame {i} luma vs ffmpeg");
crates/ec-av1/src/stream.rsmodified+225 -0
@@ -129,6 +129,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
129 header.frame_height,129 header.frame_height,
130 enable_filter_intra,130 enable_filter_intra,
131 &header.cdef,131 &header.cdef,
132+ &header.loop_filter,
132 )?133 )?
133 } else {134 } else {
134 let reference = reference.as_ref().ok_or_else(|| {135 let reference = reference.as_ref().ok_or_else(|| {
@@ -146,6 +147,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
146 header.frame_height,147 header.frame_height,
147 reference,148 reference,
148 &header.cdef,149 &header.cdef,
150+ &header.loop_filter,
149 )?151 )?
150 };152 };
151 reference = Some(picture.clone());153 reference = Some(picture.clone());
@@ -213,6 +215,7 @@ mod tests {
213 height as u32,215 height as u32,
214 false,216 false,
215 &ec_av1_syntax::CdefParams::default(),217 &ec_av1_syntax::CdefParams::default(),
218+ &ec_av1_syntax::LoopFilterParams::default(),
216 )219 )
217 .unwrap();220 .unwrap();
218 let via_stream = decode_stream(&encoded.stream).unwrap();221 let via_stream = decode_stream(&encoded.stream).unwrap();
@@ -759,6 +762,228 @@ mod tests {
759 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");762 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");
760 }763 }
761 764
765+ /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s
766+ /// harness, but with the deblocking filter left *on* (no
767+ /// `--loopfilter-control=0`) at a crf high enough that libaom actually
768+ /// picks a nonzero level -- proves `apply_deblock` itself, not just that
769+ /// this decoder still works when every edge lands on level 0. CDEF
770+ /// stays off so a pixel mismatch can only come from the loop filter.
771+ #[test]
772+ fn a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact() {
773+ if !have_ffmpeg() {
774+ eprintln!(
775+ "SKIP a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact: no ffmpeg"
776+ );
777+ return;
778+ }
779+ if !have_aomenc() {
780+ eprintln!(
781+ "SKIP a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact: no aomenc at {}",
782+ aomenc_path().display()
783+ );
784+ return;
785+ }
786+ let (width, height) = (64usize, 64usize);
787+ let y4m = Command::new("ffmpeg")
788+ .args([
789+ "-v",
790+ "error",
791+ "-f",
792+ "lavfi",
793+ "-i",
794+ "gradients=size=64x64:seed=42:duration=0.04:rate=25",
795+ "-pix_fmt",
796+ "yuv420p",
797+ "-f",
798+ "yuv4mpegpipe",
799+ "-",
800+ ])
801+ .stdin(Stdio::null())
802+ .stdout(Stdio::piped())
803+ .stderr(Stdio::piped())
804+ .output()
805+ .expect("ffmpeg failed to run");
806+ assert!(
807+ y4m.status.success(),
808+ "ffmpeg fixture: {}",
809+ String::from_utf8_lossy(&y4m.stderr)
810+ );
811+ let mut child = Command::new(aomenc_path())
812+ .args([
813+ "--codec=av1",
814+ "--passes=1",
815+ "--end-usage=q",
816+ "--cq-level=55",
817+ "--cpu-used=0",
818+ "--enable-filter-intra=0",
819+ "--enable-smooth-intra=0",
820+ "--enable-paeth-intra=0",
821+ "--enable-directional-intra=0",
822+ "--enable-angle-delta=0",
823+ "--enable-tx-size-search=0",
824+ "--enable-cdef=0",
825+ "--max-partition-size=32",
826+ "--enable-palette=0",
827+ "--enable-intrabc=0",
828+ "--enable-cfl-intra=0",
829+ "--obu",
830+ "-o",
831+ "-",
832+ "-",
833+ ])
834+ .stdin(Stdio::piped())
835+ .stdout(Stdio::piped())
836+ .stderr(Stdio::piped())
837+ .spawn()
838+ .expect("aomenc failed to start");
839+ child
840+ .stdin
841+ .take()
842+ .expect("aomenc stdin")
843+ .write_all(&y4m.stdout)
844+ .expect("writing y4m to aomenc");
845+ let out = child.wait_with_output().expect("aomenc failed to run");
846+ assert!(
847+ out.status.success(),
848+ "aomenc refused the fixture: {}",
849+ String::from_utf8_lossy(&out.stderr)
850+ );
851+ let stream = out.stdout;
852+ let before = decode::deblock_hits();
853+ let frames = match decode_stream(&stream) {
854+ Ok(frames) => frames,
855+ Err(e) => {
856+ eprintln!(
857+ "SKIP a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact: {e}"
858+ );
859+ return;
860+ }
861+ };
862+ assert!(
863+ decode::deblock_hits() > before,
864+ "no deblocking edge fired decoding this stream -- raise cq-level"
865+ );
866+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
867+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "luma vs ffmpeg");
868+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg");
869+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");
870+ }
871+
872+ /// As above, but a multi-frame inter sequence -- `--lag-in-frames=0
873+ /// --auto-alt-ref=0` keep every non-key frame a simple forward
874+ /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this
875+ /// decoder's inter path does not model), `--kf-max-dist` past the clip's
876+ /// own length keeps frame 0 the only key frame.
877+ #[test]
878+ fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {
879+ if !have_ffmpeg() {
880+ eprintln!(
881+ "SKIP a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact: no ffmpeg"
882+ );
883+ return;
884+ }
885+ if !have_aomenc() {
886+ eprintln!(
887+ "SKIP a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact: no aomenc at {}",
888+ aomenc_path().display()
889+ );
890+ return;
891+ }
892+ let (width, height, frame_count) = (64usize, 64usize, 4usize);
893+ let y4m = Command::new("ffmpeg")
894+ .args([
895+ "-v",
896+ "error",
897+ "-f",
898+ "lavfi",
899+ "-i",
900+ "gradients=size=64x64:seed=42:duration=0.16:rate=25",
901+ "-pix_fmt",
902+ "yuv420p",
903+ "-f",
904+ "yuv4mpegpipe",
905+ "-",
906+ ])
907+ .stdin(Stdio::null())
908+ .stdout(Stdio::piped())
909+ .stderr(Stdio::piped())
910+ .output()
911+ .expect("ffmpeg failed to run");
912+ assert!(
913+ y4m.status.success(),
914+ "ffmpeg fixture: {}",
915+ String::from_utf8_lossy(&y4m.stderr)
916+ );
917+ let mut child = Command::new(aomenc_path())
918+ .args([
919+ "--codec=av1",
920+ "--passes=1",
921+ "--end-usage=q",
922+ "--cq-level=55",
923+ "--cpu-used=0",
924+ "--lag-in-frames=0",
925+ "--auto-alt-ref=0",
926+ "--kf-max-dist=1000",
927+ "--enable-rect-partitions=0",
928+ "--enable-ab-partitions=0",
929+ "--enable-1to4-partitions=0",
930+ "--enable-filter-intra=0",
931+ "--enable-smooth-intra=0",
932+ "--enable-paeth-intra=0",
933+ "--enable-directional-intra=0",
934+ "--enable-angle-delta=0",
935+ "--enable-tx-size-search=0",
936+ "--enable-cdef=0",
937+ "--max-partition-size=32",
938+ "--enable-palette=0",
939+ "--enable-intrabc=0",
940+ "--enable-cfl-intra=0",
941+ "--obu",
942+ "-o",
943+ "-",
944+ "-",
945+ ])
946+ .stdin(Stdio::piped())
947+ .stdout(Stdio::piped())
948+ .stderr(Stdio::piped())
949+ .spawn()
950+ .expect("aomenc failed to start");
951+ child
952+ .stdin
953+ .take()
954+ .expect("aomenc stdin")
955+ .write_all(&y4m.stdout)
956+ .expect("writing y4m to aomenc");
957+ let out = child.wait_with_output().expect("aomenc failed to run");
958+ assert!(
959+ out.status.success(),
960+ "aomenc refused the fixture: {}",
961+ String::from_utf8_lossy(&out.stderr)
962+ );
963+ let stream = out.stdout;
964+ let before = decode::deblock_hits();
965+ let frames = match decode_stream(&stream) {
966+ Ok(frames) => frames,
967+ Err(e) => {
968+ eprintln!(
969+ "SKIP a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact: {e}"
970+ );
971+ return;
972+ }
973+ };
974+ assert!(
975+ decode::deblock_hits() > before,
976+ "no deblocking edge fired decoding this sequence -- raise cq-level"
977+ );
978+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
979+ assert_eq!(frames.len(), frame_count);
980+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
981+ assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg");
982+ assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg");
983+ assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg");
984+ }
985+ }
986+
762 /// scratch: isolate a pinned mismatching stream's first divergent pixel.987 /// scratch: isolate a pinned mismatching stream's first divergent pixel.
763 #[test]988 #[test]
764 #[ignore]989 #[ignore]