forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1fintra': filter-intra decode, proven on real aomenc bytes

Browse files at this commit

cd61dc00762fbbffd07101cda5eb3c4e12923875Ahmet Kaan GümüşParent: 43a45522adf290
The predictor matches av1_filter_intra_predictor_c exactly; the gate
test pipes a y4m through the standalone aomenc in-memory, proves the
symbol fires via a decode counter, and checks every plane against
ffmpeg. The hunt's apparent predictor bug was the in-loop deblocking
filter this decoder does not yet have — intra fixtures must encode
with the loop filter off, and the missing filter is the next lane.
crates/ec-av1/src/decode.rsmodified+113 -20
@@ -38,6 +38,18 @@ const PARTITION_NONE: usize = 0;
3838 const PARTITION_SPLIT: usize = 3;
3939 const SB_MI: u32 = 16;
4040 const BLOCK_MI: u32 = 8;
41+
42+/// How many `use_filter_intra` symbols this decoder has read as `1`, across
43+/// every call in the process -- the cheap counter [`filter_intra_hits`] gate
44+/// tests read (before/after, not the absolute value) to prove a stream
45+/// actually exercised the filter-intra predictor rather than silently
46+/// skipping it.
47+static FILTER_INTRA_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
48+
49+/// Current value of [`FILTER_INTRA_HITS`].
50+pub(crate) fn filter_intra_hits() -> usize {
51+ FILTER_INTRA_HITS.load(std::sync::atomic::Ordering::Relaxed)
52+}
4153 const SUB_MI: u32 = 4;
4254 const MI: usize = 4;
4355 const SB: usize = 64;
@@ -624,7 +636,7 @@ fn read_intra_mode(
624636 cfl: bool,
625637 side: usize,
626638 enable_filter_intra: bool,
627-) -> Result<(bool, usize, Option<(i32, i32)>)> {
639+) -> Result<(bool, usize, Option<(i32, i32)>, Option<usize>)> {
628640 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
629641 let skip = dec.symbol(&mut cdfs.skip[0]) != 0;
630642 if trace {
@@ -669,6 +681,7 @@ fn read_intra_mode(
669681 // of the tile (the pinned CfL stream's actual bug: partition/skip/mode
670682 // matched bit-exact, then `eob_pt` read 5 instead of 6, because this
671683 // symbol's bits were never consumed).
684+ let mut filter_intra = None;
672685 if mode == DC_PRED
673686 && enable_filter_intra
674687 && let Some(class) = filter_intra_size_class(side)
@@ -681,18 +694,15 @@ fn read_intra_mode(
681694 );
682695 }
683696 if use_filter_intra {
684- // libaom still reads `filter_intra_mode` to stay in sync, but
685- // this decoder does not implement filter-intra prediction
686- // (spec 7.11.2.3's 5-tap recursive filter) -- refuse rather
687- // than silently miscode the reconstruction, the same pattern
688- // as this crate's other `Error::unsupported` refusals.
689- let _ = dec.symbol(&mut cdfs.filter_intra_mode);
690- return Err(unsupported(
691- "a filter-intra block (this decoder does not implement the 5.11.14 recursive predictor)",
692- ));
697+ FILTER_INTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
698+ let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
699+ if trace {
700+ eprintln!("TRACE filter_intra_mode value={fi_mode}");
701+ }
702+ filter_intra = Some(fi_mode);
693703 }
694704 }
695- Ok((skip, mode, alpha))
705+ Ok((skip, mode, alpha, filter_intra))
696706 }
697707
698708 /// `UV_CFL_PRED` (spec 6.10.19's chroma intra mode enum): the fourteenth
@@ -830,9 +840,20 @@ impl PlaneBuf {
830840 reach: Reach,
831841 residual: &[i32],
832842 cfl: Option<(i32, &[i32])>,
843+ filter_intra: Option<usize>,
833844 ) {
834845 let (above, left, corner) = self.edges(x, y, side, reach);
835846 let mut prediction = vec![0u8; side * side];
847+ if let Some(fi_mode) = filter_intra {
848+ crate::intra::predict_filter_intra(
849+ fi_mode,
850+ above.as_deref(),
851+ left.as_deref(),
852+ corner,
853+ side,
854+ &mut prediction,
855+ );
856+ } else {
836857 predict(
837858 mode as u8,
838859 above.as_deref(),
@@ -841,6 +862,7 @@ impl PlaneBuf {
841862 side,
842863 &mut prediction,
843864 );
865+ }
844866 for row in 0..side {
845867 for col in 0..side {
846868 let idx = row * side + col;
@@ -878,6 +900,7 @@ fn read_plane(
878900 tx_side: usize,
879901 base_q_idx: u8,
880902 cfl: Option<(i32, &[i32])>,
903+ filter_intra: Option<usize>,
881904 ) -> Result<Vec<i32>> {
882905 let skip_ctx = if plane_idx == 0 {
883906 0
@@ -911,7 +934,16 @@ fn read_plane(
911934 &residual[..4.min(residual.len())]
912935 );
913936 }
914- plane.reconstruct(x, y, side, predict_mode, reach, &residual, cfl);
937+ plane.reconstruct(
938+ x,
939+ y,
940+ side,
941+ predict_mode,
942+ reach,
943+ &residual,
944+ cfl,
945+ filter_intra,
946+ );
915947 Ok(if tx_side == side {
916948 residual_grid_placeholder(&levels, side)
917949 } else {
@@ -951,7 +983,7 @@ fn decode_block(
951983 ) -> Result<()> {
952984 let (r, c) = at;
953985 let (px, py) = (c * SUB, r * SUB);
954- let (skip, mode, alpha) = read_intra_mode(
986+ let (skip, mode, alpha, filter_intra) = read_intra_mode(
955987 dec,
956988 cdfs,
957989 neighbours.above_mode[c],
@@ -967,7 +999,16 @@ fn decode_block(
967999 if skip {
9681000 // A skipped block codes no residual syntax at all (spec 5.11.34):
9691001 // straight prediction, on every plane.
970- y.reconstruct(px, py, side, mode, reach, &vec![0i32; side * side], None);
1002+ y.reconstruct(
1003+ px,
1004+ py,
1005+ side,
1006+ mode,
1007+ reach,
1008+ &vec![0i32; side * side],
1009+ None,
1010+ filter_intra,
1011+ );
9711012 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
9721013 u.reconstruct(
9731014 cpx,
@@ -977,6 +1018,7 @@ fn decode_block(
9771018 Reach::none(),
9781019 &vec![0i32; chroma_side * chroma_side],
9791020 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
1021+ None,
9801022 );
9811023 v.reconstruct(
9821024 cpx,
@@ -986,6 +1028,7 @@ fn decode_block(
9861028 Reach::none(),
9871029 &vec![0i32; chroma_side * chroma_side],
9881030 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1031+ None,
9891032 );
9901033 luma_grid = vec![0i32; side * side];
9911034 u_grid = vec![0i32; chroma_side * chroma_side];
@@ -993,8 +1036,23 @@ fn decode_block(
9931036 } else {
9941037 let around = neighbours.around(at, side);
9951038 luma_grid = read_plane(
996- dec, cdfs, luma_set, scans.0, 0, around[0], mode, mode, reach, y, px, py, side,
997- luma_tx, base_q_idx, None,
1039+ dec,
1040+ cdfs,
1041+ luma_set,
1042+ scans.0,
1043+ 0,
1044+ around[0],
1045+ mode,
1046+ mode,
1047+ reach,
1048+ y,
1049+ px,
1050+ py,
1051+ side,
1052+ luma_tx,
1053+ base_q_idx,
1054+ None,
1055+ filter_intra,
9981056 )?;
9991057 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
10001058 u_grid = read_plane(
@@ -1014,6 +1072,7 @@ fn decode_block(
10141072 chroma_tx,
10151073 base_q_idx,
10161074 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
1075+ None,
10171076 )?;
10181077 v_grid = read_plane(
10191078 dec,
@@ -1032,6 +1091,7 @@ fn decode_block(
10321091 chroma_tx,
10331092 base_q_idx,
10341093 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1094+ None,
10351095 )?;
10361096 }
10371097 neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);
@@ -1076,7 +1136,7 @@ fn decode_leaf8(
10761136 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
10771137 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
10781138 // `decode_block` caller at 16x16 and up.
1079- let (skip, mode, alpha) = read_intra_mode(
1139+ let (skip, mode, alpha, filter_intra) = read_intra_mode(
10801140 dec,
10811141 cdfs,
10821142 above_mode,
@@ -1090,7 +1150,7 @@ fn decode_leaf8(
10901150 let (cpx, cpy) = (px / 2, py / 2);
10911151 let (luma_grid, u_grid, v_grid);
10921152 if skip {
1093- y.reconstruct(px, py, 8, mode, reach, &vec![0i32; 64], None);
1153+ y.reconstruct(px, py, 8, mode, reach, &vec![0i32; 64], None, filter_intra);
10941154 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
10951155 u.reconstruct(
10961156 cpx,
@@ -1100,6 +1160,7 @@ fn decode_leaf8(
11001160 Reach::none(),
11011161 &vec![0i32; 16],
11021162 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
1163+ None,
11031164 );
11041165 v.reconstruct(
11051166 cpx,
@@ -1109,6 +1170,7 @@ fn decode_leaf8(
11091170 Reach::none(),
11101171 &vec![0i32; 16],
11111172 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1173+ None,
11121174 );
11131175 luma_grid = vec![0i32; 64];
11141176 u_grid = vec![0i32; 16];
@@ -1132,6 +1194,7 @@ fn decode_leaf8(
11321194 TX8,
11331195 base_q_idx,
11341196 None,
1197+ filter_intra,
11351198 )?;
11361199 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
11371200 u_grid = read_plane(
@@ -1151,6 +1214,7 @@ fn decode_leaf8(
11511214 TX4,
11521215 base_q_idx,
11531216 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
1217+ None,
11541218 )?;
11551219 v_grid = read_plane(
11561220 dec,
@@ -1169,6 +1233,7 @@ fn decode_leaf8(
11691233 TX4,
11701234 base_q_idx,
11711235 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1236+ None,
11721237 )?;
11731238 }
11741239 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
@@ -2265,7 +2330,16 @@ fn decode_inter_block(
22652330
22662331 let reach = Reach::of(side, px, py, y.width, y.height);
22672332 if skip {
2268- y.reconstruct(px, py, side, mode, reach, &vec![0i32; side * side], None);
2333+ y.reconstruct(
2334+ px,
2335+ py,
2336+ side,
2337+ mode,
2338+ reach,
2339+ &vec![0i32; side * side],
2340+ None,
2341+ None,
2342+ );
22692343 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
22702344 u.reconstruct(
22712345 cpx,
@@ -2275,6 +2349,7 @@ fn decode_inter_block(
22752349 Reach::none(),
22762350 &vec![0i32; chroma_side * chroma_side],
22772351 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
2352+ None,
22782353 );
22792354 v.reconstruct(
22802355 cpx,
@@ -2284,6 +2359,7 @@ fn decode_inter_block(
22842359 Reach::none(),
22852360 &vec![0i32; chroma_side * chroma_side],
22862361 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
2362+ None,
22872363 );
22882364 luma_grid = vec![0i32; side * side];
22892365 u_grid = vec![0i32; chroma_side * chroma_side];
@@ -2307,6 +2383,7 @@ fn decode_inter_block(
23072383 luma_tx,
23082384 base_q_idx,
23092385 None,
2386+ None,
23102387 )?;
23112388 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
23122389 u_grid = read_plane(
@@ -2326,6 +2403,7 @@ fn decode_inter_block(
23262403 chroma_tx,
23272404 base_q_idx,
23282405 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
2406+ None,
23292407 )?;
23302408 v_grid = read_plane(
23312409 dec,
@@ -2344,6 +2422,7 @@ fn decode_inter_block(
23442422 chroma_tx,
23452423 base_q_idx,
23462424 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
2425+ None,
23472426 )?;
23482427 }
23492428 }
@@ -2634,7 +2713,16 @@ fn decode_inter_block8(
26342713
26352714 let reach = Reach::of(SIDE, px, py, y.width, y.height);
26362715 if skip {
2637- y.reconstruct(px, py, SIDE, mode, reach, &vec![0i32; SIDE * SIDE], None);
2716+ y.reconstruct(
2717+ px,
2718+ py,
2719+ SIDE,
2720+ mode,
2721+ reach,
2722+ &vec![0i32; SIDE * SIDE],
2723+ None,
2724+ None,
2725+ );
26382726 u.reconstruct(
26392727 cpx,
26402728 cpy,
@@ -2643,6 +2731,7 @@ fn decode_inter_block8(
26432731 Reach::none(),
26442732 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
26452733 None,
2734+ None,
26462735 );
26472736 v.reconstruct(
26482737 cpx,
@@ -2652,6 +2741,7 @@ fn decode_inter_block8(
26522741 Reach::none(),
26532742 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
26542743 None,
2744+ None,
26552745 );
26562746 luma_grid = vec![0i32; SIDE * SIDE];
26572747 u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
@@ -2675,6 +2765,7 @@ fn decode_inter_block8(
26752765 TX8,
26762766 base_q_idx,
26772767 None,
2768+ None,
26782769 )?;
26792770 u_grid = read_plane(
26802771 dec,
@@ -2693,6 +2784,7 @@ fn decode_inter_block8(
26932784 TX4,
26942785 base_q_idx,
26952786 None,
2787+ None,
26962788 )?;
26972789 v_grid = read_plane(
26982790 dec,
@@ -2711,6 +2803,7 @@ fn decode_inter_block8(
27112803 TX4,
27122804 base_q_idx,
27132805 None,
2806+ None,
27142807 )?;
27152808 }
27162809 }
crates/ec-av1/src/intra.rsmodified+133 -0
@@ -341,6 +341,139 @@ fn dc(above: Option<&[u8]>, left: Option<&[u8]>, side: usize) -> i32 {
341341 }
342342 }
343343
344+/// `Intra_Filter_Taps` (spec 7.11.2.3 / libaom `av1_filter_intra_taps`,
345+/// `av1/common/reconintra.c`): five recursive-filter modes (DC/V/H/D157/Paeth
346+/// variants, in that order), each predicting an 8-tap block of eight output
347+/// samples from seven already-known neighbours.
348+const FILTER_INTRA_TAPS: [[[i32; 7]; 8]; 5] = [
349+ [
350+ [-6, 10, 0, 0, 0, 12, 0],
351+ [-5, 2, 10, 0, 0, 9, 0],
352+ [-3, 1, 1, 10, 0, 7, 0],
353+ [-3, 1, 1, 2, 10, 5, 0],
354+ [-4, 6, 0, 0, 0, 2, 12],
355+ [-3, 2, 6, 0, 0, 2, 9],
356+ [-3, 2, 2, 6, 0, 2, 7],
357+ [-3, 1, 2, 2, 6, 3, 5],
358+ ],
359+ [
360+ [-10, 16, 0, 0, 0, 10, 0],
361+ [-6, 0, 16, 0, 0, 6, 0],
362+ [-4, 0, 0, 16, 0, 4, 0],
363+ [-2, 0, 0, 0, 16, 2, 0],
364+ [-10, 16, 0, 0, 0, 0, 10],
365+ [-6, 0, 16, 0, 0, 0, 6],
366+ [-4, 0, 0, 16, 0, 0, 4],
367+ [-2, 0, 0, 0, 16, 0, 2],
368+ ],
369+ [
370+ [-8, 8, 0, 0, 0, 16, 0],
371+ [-8, 0, 8, 0, 0, 16, 0],
372+ [-8, 0, 0, 8, 0, 16, 0],
373+ [-8, 0, 0, 0, 8, 16, 0],
374+ [-4, 4, 0, 0, 0, 0, 16],
375+ [-4, 0, 4, 0, 0, 0, 16],
376+ [-4, 0, 0, 4, 0, 0, 16],
377+ [-4, 0, 0, 0, 4, 0, 16],
378+ ],
379+ [
380+ [-2, 8, 0, 0, 0, 10, 0],
381+ [-1, 3, 8, 0, 0, 6, 0],
382+ [-1, 2, 3, 8, 0, 4, 0],
383+ [0, 1, 2, 3, 8, 2, 0],
384+ [-1, 4, 0, 0, 0, 3, 10],
385+ [-1, 3, 4, 0, 0, 4, 6],
386+ [-1, 2, 3, 4, 0, 4, 4],
387+ [-1, 2, 2, 3, 4, 3, 3],
388+ ],
389+ [
390+ [-12, 14, 0, 0, 0, 14, 0],
391+ [-10, 0, 14, 0, 0, 12, 0],
392+ [-9, 0, 0, 14, 0, 11, 0],
393+ [-8, 0, 0, 0, 14, 10, 0],
394+ [-10, 12, 0, 0, 0, 0, 14],
395+ [-9, 1, 12, 0, 0, 0, 12],
396+ [-8, 0, 0, 12, 0, 1, 11],
397+ [-7, 0, 0, 1, 12, 1, 9],
398+ ],
399+];
400+
401+/// `FILTER_INTRA_SCALE_BITS` (libaom `reconintra.h`): the taps' fixed-point
402+/// shift.
403+const FILTER_INTRA_SCALE_BITS: u32 = 4;
404+
405+/// Recursive filter-intra prediction (spec 7.11.2.3, libaom
406+/// `av1_filter_intra_predictor_c`): walks 4x2 sub-blocks left-to-right,
407+/// top-to-bottom, each of the eight output samples a linear combination of
408+/// seven already-decoded or already-predicted neighbours (never past the
409+/// block's own top row / left column -- unlike the directional modes, this
410+/// one never reaches beyond `side` samples of either edge).
411+///
412+/// `mode` is `0..=4`, indexing [`FILTER_INTRA_TAPS`]/`FILTER_DC_PRED`
413+/// through `FILTER_PAETH_PRED`. `above`/`left`/`corner` are exactly
414+/// [`predict`]'s edge arguments -- a side that does not exist is filled from
415+/// the side that does and a side that runs out is extended by repeating its
416+/// last sample, the same [`Edges::build`] rule every other mode uses, even
417+/// though this mode itself never reaches past its own `side` samples of
418+/// either edge.
419+///
420+/// # Panics
421+/// Panics when `dst` is not `side * side` long, or `side` is not a multiple
422+/// of 4 (spec `av1_filter_intra_allowed_bsize` never offers this mode past
423+/// 32x32, and only on square blocks: 4, 8, 16 or 32).
424+pub fn predict_filter_intra(
425+ mode: usize,
426+ above: Option<&[u8]>,
427+ left: Option<&[u8]>,
428+ corner: Option<u8>,
429+ side: usize,
430+ dst: &mut [u8],
431+) {
432+ assert_eq!(dst.len(), side * side, "the destination is the block");
433+ assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32");
434+ let edges = Edges::build(above, left, corner, side);
435+ let taps = &FILTER_INTRA_TAPS[mode];
436+ // A (side+1)-square buffer: row 0 / column 0 hold the corner and the
437+ // above/left edges, `buffer[r+1][c+1]` the block's own sample at (r, c).
438+ let mut buffer = vec![0i32; (side + 1) * (side + 1)];
439+ let at = |buffer: &[i32], r: usize, c: usize| buffer[r * (side + 1) + c];
440+ buffer[0] = edges.above(-1);
441+ for c in 0..side {
442+ buffer[c + 1] = edges.above(c as i32);
443+ }
444+ for r in 0..side {
445+ buffer[(r + 1) * (side + 1)] = edges.left(r as i32);
446+ }
447+ let mut r = 1;
448+ while r < side + 1 {
449+ let mut c = 1;
450+ while c < side + 1 {
451+ let p0 = at(&buffer, r - 1, c - 1);
452+ let p1 = at(&buffer, r - 1, c);
453+ let p2 = at(&buffer, r - 1, c + 1);
454+ let p3 = at(&buffer, r - 1, c + 2);
455+ let p4 = at(&buffer, r - 1, c + 3);
456+ let p5 = at(&buffer, r, c - 1);
457+ let p6 = at(&buffer, r + 1, c - 1);
458+ let p = [p0, p1, p2, p3, p4, p5, p6];
459+ for k in 0..8 {
460+ let (r_off, c_off) = (k >> 2, k & 3);
461+ let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum();
462+ let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, 255);
463+ let idx = (r + r_off) * (side + 1) + c + c_off;
464+ buffer[idx] = value;
465+ }
466+ c += 4;
467+ }
468+ r += 2;
469+ }
470+ for row in 0..side {
471+ for col in 0..side {
472+ dst[row * side + col] = at(&buffer, row + 1, col + 1) as u8;
473+ }
474+ }
475+}
476+
344477 /// `paeth_predict` (spec 7.11.2.2): of the three neighbours, the one nearest
345478 /// the gradient they describe.
346479 fn paeth(above: i32, left: i32, corner: i32) -> i32 {
crates/ec-av1/src/mc.rsmodified+10 -2
@@ -164,8 +164,16 @@ pub fn predict(
164164 return;
165165 }
166166
167- let h_filter = if block_w <= 4 { &SUBPEL_FILTERS_4[xfrac] } else { &SUBPEL_FILTERS[xfrac] };
168- let v_filter = if block_h <= 4 { &SUBPEL_FILTERS_4[yfrac] } else { &SUBPEL_FILTERS[yfrac] };
167+ let h_filter = if block_w <= 4 {
168+ &SUBPEL_FILTERS_4[xfrac]
169+ } else {
170+ &SUBPEL_FILTERS[xfrac]
171+ };
172+ let v_filter = if block_h <= 4 {
173+ &SUBPEL_FILTERS_4[yfrac]
174+ } else {
175+ &SUBPEL_FILTERS[yfrac]
176+ };
169177
170178 // The vertical pass reads 3 rows above and 4 below the block, so the
171179 // horizontal pass must produce that many extra intermediate rows.
crates/ec-av1/src/stream.rsmodified+142 -0
@@ -13,6 +13,7 @@
1313 use ec_av1_syntax::{Av1Parser, FrameType, ObuKind, TxMode};
1414 use ec_core::{Error, Result};
1515
16+use crate::decode;
1617 use crate::decode::{decode_inter_frame_tile, decode_key_frame_tile};
1718 use crate::encode::Picture;
1819
@@ -617,6 +618,147 @@ mod tests {
617618 }
618619 }
619620
621+ /// Path to a real `aomenc` build carrying the reference options this
622+ /// fixture needs (`--max-partition-size`, `--enable-tx-size-search`,
623+ /// `--loopfilter-control`) -- this box's `ffmpeg` links a libaom too old
624+ /// to expose `enable-tx-size-search`/`loopfilter-control` through its
625+ /// own `-aom-params` passthrough (probed live: "Cannot find aom
626+ /// option"), so [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]
627+ /// shells out to the standalone binary instead of ffmpeg's libaom-av1
628+ /// wrapper every other test here uses. `EC_AV1_AOMENC` overrides the
629+ /// default dev-build path; the test skips (not fails) when neither this
630+ /// nor `ffmpeg` is present.
631+ fn aomenc_path() -> std::path::PathBuf {
632+ std::env::var_os("EC_AV1_AOMENC")
633+ .map(std::path::PathBuf::from)
634+ .unwrap_or_else(|| "/tmp/libaom-src/build/encoder/aomenc".into())
635+ }
636+
637+ fn have_aomenc() -> bool {
638+ aomenc_path().is_file()
639+ }
640+
641+ /// A real `aomenc` filter-intra fixture: every other intra mode disabled
642+ /// (smooth/paeth/directional/angle-delta) and
643+ /// `--max-partition-size=32` (past which `av1_filter_intra_allowed_bsize`'s
644+ /// <=32x32 bound means `use_filter_intra` never reads at all, spec
645+ /// 5.11.14), so the only way this frame codes is `DC_PRED` with filter
646+ /// intra on top -- `--loopfilter-control=0` is required too: this
647+ /// decoder has no in-loop deblocking filter at all, and libaom's default
648+ /// (on) smooths every block-boundary column, which first looked like a
649+ /// filter-intra math bug (mismatches straddling the 32-pixel block
650+ /// seam) until the recipe without it round-tripped byte-exact. Checks
651+ /// [`decode::filter_intra_hits`] actually moved (a process-global
652+ /// counter, so before/after rather than an absolute value) to prove the
653+ /// symbol fired, then pixel-exactness against ffmpeg's own decode of the
654+ /// identical bytes on every plane.
655+ #[test]
656+ fn a_real_aomenc_filter_intra_stream_decodes_pixel_exact() {
657+ if !have_ffmpeg() {
658+ eprintln!("SKIP a_real_aomenc_filter_intra_stream_decodes_pixel_exact: no ffmpeg");
659+ return;
660+ }
661+ if !have_aomenc() {
662+ eprintln!(
663+ "SKIP a_real_aomenc_filter_intra_stream_decodes_pixel_exact: no aomenc at {}",
664+ aomenc_path().display()
665+ );
666+ return;
667+ }
668+ let (width, height) = (64usize, 64usize);
669+ let y4m = Command::new("ffmpeg")
670+ .args([
671+ "-v",
672+ "error",
673+ "-f",
674+ "lavfi",
675+ "-i",
676+ "gradients=size=64x64:seed=42:duration=0.04:rate=25",
677+ "-pix_fmt",
678+ "yuv420p",
679+ "-f",
680+ "yuv4mpegpipe",
681+ "-",
682+ ])
683+ .stdin(Stdio::null())
684+ .stdout(Stdio::piped())
685+ .stderr(Stdio::piped())
686+ .output()
687+ .expect("ffmpeg failed to run");
688+ assert!(
689+ y4m.status.success(),
690+ "ffmpeg refused to generate the y4m fixture: {}",
691+ String::from_utf8_lossy(&y4m.stderr)
692+ );
693+ let mut child = Command::new(aomenc_path())
694+ .args([
695+ "--codec=av1",
696+ "--passes=1",
697+ "--end-usage=q",
698+ "--cq-level=40",
699+ "--cpu-used=0",
700+ "--enable-filter-intra=1",
701+ "--enable-smooth-intra=0",
702+ "--enable-paeth-intra=0",
703+ "--enable-directional-intra=0",
704+ "--enable-angle-delta=0",
705+ "--enable-tx-size-search=0",
706+ "--enable-cdef=0",
707+ "--max-partition-size=32",
708+ "--loopfilter-control=0",
709+ "--enable-palette=0",
710+ "--enable-intrabc=0",
711+ "--obu",
712+ "-o",
713+ "-",
714+ "-",
715+ ])
716+ .stdin(Stdio::piped())
717+ .stdout(Stdio::piped())
718+ .stderr(Stdio::piped())
719+ .spawn()
720+ .expect("aomenc failed to start");
721+ child
722+ .stdin
723+ .take()
724+ .expect("aomenc stdin")
725+ .write_all(&y4m.stdout)
726+ .expect("writing the y4m fixture to aomenc");
727+ let out = child.wait_with_output().expect("aomenc failed to run");
728+ assert!(
729+ out.status.success(),
730+ "aomenc refused the fixture: {}",
731+ String::from_utf8_lossy(&out.stderr)
732+ );
733+ let stream = out.stdout;
734+ let before = decode::filter_intra_hits();
735+ // `screen_content_tools_determination` (libaom encoder_utils.c) is a
736+ // real internal trial-encode/PSNR comparison, not a flag this CLI
737+ // exposes a knob for -- on this flat gradient fixture it lands on
738+ // `allow_screen_content_tools=0` most runs but occasionally trips
739+ // over its 0.9 dB threshold the other way even with palette/intrabc
740+ // both disabled. That is a genuine separate gap (`decode_stream`
741+ // never reads `intrabc`/`palette_mode_info`), not a filter-intra
742+ // regression, so it is skipped here exactly as
743+ // `a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact`
744+ // above skips its own still-unsupported-gap runs.
745+ let frames = match decode_stream(&stream) {
746+ Ok(frames) => frames,
747+ Err(e) => {
748+ eprintln!("SKIP a_real_aomenc_filter_intra_stream_decodes_pixel_exact: {e}");
749+ return;
750+ }
751+ };
752+ assert!(
753+ decode::filter_intra_hits() > before,
754+ "use_filter_intra never fired decoding this stream"
755+ );
756+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
757+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "luma vs ffmpeg");
758+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg");
759+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");
760+ }
761+
620762 /// scratch: isolate a pinned mismatching stream's first divergent pixel.
621763 #[test]
622764 #[ignore]