diff --git a/crates/ec-av1/fixtures/superres_alltools_sb128_320x180.obu b/crates/ec-av1/fixtures/superres_alltools_sb128_320x180.obu new file mode 100644 index 0000000000000000000000000000000000000000..8c64cbbcce38b3ebcc9264274c84316fefce494b GIT binary patch literal 17478 zcmV(~K+nGt0168L000C${>|F^fIu>eClCV2KmcKg5Qu^xfC2&vqUxe%?qr)w;`Dku z&Oa#0fq}U#f3lw^MHXbn_+fsi**MXlGG19+z3GDym zF%-O>-b#>)HVCu8a{(qJ;Jkli9uAp}Xn((f{n%G=E>v-|gdM;f&0_vz>rcHitwwlm z7Z4!*d1eB5jMA!2MK33YF80C!F<|pFi%QqGMqeoM?KtP!zE2zFY4~!BoC4CzqV8gi(JO&eV`WMRLy90W30ME zbR7(>Qe-y`RmuIsl9YmR@Z&`G1P$ge7kht-DwYK1NxzhX1X-7w#ny@`lg&u-FC3NE zUvxtR<)c7+B?vl{f}zJ`iNxngF7p|?T$^N9w_NfQjW>k=)_Ib- zw~X%a2`8y&Dq;PME!b zf5peSm2O2IW|<2QYMM#UPlKwxok~YTPlMk%@s@dZL>tB=s7CbbOWvdht*WJq4-3R$ zxX+WeONF(RRik#&snm&7tLDz|rf)@YCDanD#78%z0L!9jQ%G*!c&JJcQLB`w>tzF^ zo&=Z&s~G=#JT(kqf<^qB2Z5(PyJ#!(170ho{o$0}0r}$)QaF;~8YkP8X#S~Mreesy zHI?|qKh^&{?G!2bEmz2{8)*|n;2ms=7oT%4c(AY(8dQ74i8{pIPj|TXd}vkdZiK#R zRa659DmD*l8O|1V624k>c%oPM5fF|p@4)3S|6)$;c1H=n9`e3B8*_OnodzxMmNe?^^pG3 zk>U=Xu{W?W9mtV{YBfa>$q!{z9-2|R1k^s8(=0FzEAny!jA{~)h$As4wxy4P$XIss1y`EUF zf|_(HxigxF2Dn?efWY!!`8WuAX?=-0{(#@0(89};0!uR%j0EXbWeVQzm_%#^pL?G} z*GneZ!}8rZNDj>+kr>t@;Yh96tG%tz6hHv^_|EbVfCPl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uykg5UQBa#$K?LWs3+=5YXMG zvg>^fldOIC`N@!(X{QyGgFeAy{Yd?z4@&;94nQDTT35S;M17wSVCfX?oETP@|67Ve VL-GIYuo}8kG(p$PCbl|^CfIh*(Bc39 literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/superres_kf_cdef_lr_64x64.obu b/crates/ec-av1/fixtures/superres_kf_cdef_lr_64x64.obu new file mode 100644 index 0000000000000000000000000000000000000000..d9d0e610217ea1ecb0857cf9fc83a6692c74b006 GIT binary patch literal 1167 zcmV;A1aSKj0165K00087|DXSG2r~W%5CX{n0gfP|0Tk;%(R32dlCNs&i0gv7QhbDK zAOoHI*PMVpP*@lQ82gK62u32T*QFr(u_>0g`=>IgEglkOPug3Y_?(C*7k567H)N%1 zZ?41Lsgg6t@qb7;}CJ#_pW zOR_$ZS;J*x95m(Mqd%aDVH8U7#Or=)(sf1gnIpB$gjQTU1|?RZ=GkWDzK1ku$3%T# zqh_y#s>Fme4Rz`@$=E4&0_&vCW#`>J!t zzh9W0>T1V}k4$5L^2$JF8a@E`g$p$=-1J8&j@9K$9yu`%`k&_lP{RRe4@DlKG&!LW zL08N(yZcwDTqC4@b>!~kIewADX@gbXe!e0+Woe(Djd@9efZi;*$mb?eI9|#3){gMVbdh~2dM}b zNi_6IcteAk{a8gXFu5}|VsH>G$=k%C%X12q^pwA#WII~If|VAc*n@>+)rJO?XOpNv zl74rT8N9MUtyap-G`2){w3^~B}?V9dSnB+Yuw@&sTGkB z)9K=G*L9vLx(hbl@uiI~+>nzXU>1aMKl?sfd&!x2g%WNIWS>cW)%LOE8SmR{3S1XC zb?|?IKsb^I$Va!o5p05WmMB$pk#g}0EU$!m$Sc&GzD6f`s#jBVJAlN#zT`L!kRccU z*ihhB{@5=2$r02l;ImC2j8cG!p+h~h@$r^!4+s>OIPFmLXttN&ov8g$yW2!EK_m1a z0ShVB@csH+%3fZJd_d=!fDw0DXgIe&X+PHy2Jkjdpo{u%uPf`+;(%C*BBnqbqNlOu zGtd{&YKArav&twEmmq5Ev$GVbes2P*T_vslDb55b0@2Z?ZXVL+v>+>`L82jBH@pwJ zM0cpgXZL^{ehg@<;dw@&wd2kv&nlZ{gNXBh6=lus8 u8 { pub(crate) fn set_bit_depth(bit_depth: u8) { BIT_DEPTH.with(|c| c.set(bit_depth)); } + +thread_local! { + /// This frame's superres state: `(upscaled_width, superres_denom)`, or + /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs + /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid, + /// `read_lr`'s unit corners and the pixel filters themselves -- works in + /// UPSCALED coordinates while deblock and CDEF work in downscaled ones + /// (libaom `av1_superres_upscale` in `decodeframe.c`, and + /// `av1_loop_restoration_corners_in_sb`'s own `mi_to_num_x`/`denom_x` + /// superres arms). Set once per frame from [`crate::stream`]'s decode + /// loop, like [`BIT_DEPTH`], and reset to `(0, 8)` on an unscaled frame + /// so a later frame never inherits it. + static SUPERRES: std::cell::Cell<(u32, u32)> = const { std::cell::Cell::new((0, 8)) }; +} + +/// Sets [`SUPERRES`] for the current thread. `upscaled_width` is 0 (and +/// `denom` 8) for a frame that is not superres-scaled. +pub(crate) fn set_superres(upscaled_width: u32, denom: u32) { + SUPERRES.with(|c| c.set((upscaled_width, denom))); +} + +/// `(upscaled_width, superres_denom)` when this frame is superres-scaled +/// (libaom `av1_superres_scaled`), else `None`. +pub(crate) fn superres() -> Option<(u32, u32)> { + let (w, d) = SUPERRES.with(std::cell::Cell::get); + (w > 0 && d != 8).then_some((w, d)) +} // Whether this superblock's single CDEF unit (this decoder has no 128x128 // SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal // read -- reset to `false` at the top of each superblock in the two tile @@ -16940,7 +16967,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( mi_cols as usize, mi_rows as usize, ); - let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height); + // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is + // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width -- + // loop restoration runs after the superres upscale. + let mut lr_grid = crate::restoration::RestorationGrid::new( + lr, + superres().map_or(frame_width, |(w, _)| w), + frame_height, + ); // lane-tiles r2: each tile gets its own fresh `SymbolDecoder` over its // own byte range and its own fresh copy of the frame's initial CDFs @@ -18835,12 +18869,57 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( ); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called + // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`): + // the horizontal upscale runs HERE -- after CDEF, before loop + // restoration, not after the whole filter chain. Both the post-CDEF + // frame and the post-deblock frame that LR substitutes at its stripe + // boundaries are upscaled (`save_deblock_boundary_lines` runs + // `av1_upscale_normative_rows` over its saved rows when the frame is + // scaled), so every LR coordinate from here on is in upscaled space. + let (mut deblocked_y, mut deblocked_u, mut deblocked_v) = + (deblocked_y, deblocked_u, deblocked_v); + let mut lr_w = frame_width as usize; + if let Some((upscaled_w, _)) = superres() { + let bd = u32::from(bit_depth()); + let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize); + let up = |p: &PlaneBuf, in_w: usize, in_h: usize, out_w: usize| PlaneBuf { + data: crate::superres::upscale_plane_strided( + &p.data, p.width, in_w, in_h, p.true_width, out_w, bd, + ), + width: out_w, + height: in_h, + true_width: out_w, + true_height: in_h, + tile_x0: 0, + tile_y0: 0, + tile_x1: out_w, + tile_y1: in_h, + }; + let (cw, ch, cuw) = (fw.div_ceil(2), fh.div_ceil(2), uw.div_ceil(2)); + y = up(&y, fw, fh, uw); + u = up(&u, cw, ch, cuw); + v = up(&v, cw, ch, cuw); + deblocked_y = up(&deblocked_y, fw, fh, uw); + deblocked_u = up(&deblocked_u, cw, ch, cuw); + deblocked_v = up(&deblocked_v, cw, ch, cuw); + lr_w = uw; + crate::superres::note_upscaled_picture(); + } apply_loop_restoration( &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid, - (frame_width as usize, frame_height as usize), + (lr_w, frame_height as usize), ); - let (fw, fh) = (frame_width as usize, frame_height as usize); + let (fw, fh) = (lr_w, frame_height as usize); + // An upscaled frame is already at its final size with no mi-aligned + // margin beyond it (the upscale consumed those columns), so the + // wide-margin stash below has nothing left to hand out. + let (true_width, true_height) = if superres().is_some() { + (fw, fh) + } else { + (true_width, true_height) + }; if fw == width && fh == height { LAST_FRAME_WIDE_MARGIN.with(|m| *m.borrow_mut() = None); return Ok(( @@ -28297,7 +28376,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( mi_rows as usize, ); let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); - let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height); + // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is + // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width -- + // loop restoration runs after the superres upscale. + let mut lr_grid = crate::restoration::RestorationGrid::new( + lr, + superres().map_or(frame_width, |(w, _)| w), + frame_height, + ); // lane-tiles r6: mirrors decode_key_frame_tile_with_cdfs's own per-tile // loop (spec 5.11.2 decode_tile / 7.20 exit_symbol) -- each tile gets @@ -30792,9 +30878,46 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); + // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called + // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`): + // the horizontal upscale runs HERE -- after CDEF, before loop + // restoration, not after the whole filter chain. Both the post-CDEF + // frame and the post-deblock frame that LR substitutes at its stripe + // boundaries are upscaled (`save_deblock_boundary_lines` runs + // `av1_upscale_normative_rows` over its saved rows when the frame is + // scaled), so every LR coordinate from here on is in upscaled space. + let (mut deblocked_y, mut deblocked_u, mut deblocked_v) = + (deblocked_y, deblocked_u, deblocked_v); + let mut lr_w = frame_width as usize; + if let Some((upscaled_w, _)) = superres() { + let bd = u32::from(bit_depth()); + let (uw, fw, fh) = (upscaled_w as usize, frame_width as usize, frame_height as usize); + let up = |p: &PlaneBuf, in_w: usize, in_h: usize, out_w: usize| PlaneBuf { + data: crate::superres::upscale_plane_strided( + &p.data, p.width, in_w, in_h, p.true_width, out_w, bd, + ), + width: out_w, + height: in_h, + true_width: out_w, + true_height: in_h, + tile_x0: 0, + tile_y0: 0, + tile_x1: out_w, + tile_y1: in_h, + }; + let (cw, ch, cuw) = (fw.div_ceil(2), fh.div_ceil(2), uw.div_ceil(2)); + y = up(&y, fw, fh, uw); + u = up(&u, cw, ch, cuw); + v = up(&v, cw, ch, cuw); + deblocked_y = up(&deblocked_y, fw, fh, uw); + deblocked_u = up(&deblocked_u, cw, ch, cuw); + deblocked_v = up(&deblocked_v, cw, ch, cuw); + lr_w = uw; + crate::superres::note_upscaled_picture(); + } apply_loop_restoration( &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid, - (frame_width as usize, frame_height as usize), + (lr_w, frame_height as usize), ); let motion_field = build_motion_field( @@ -30806,7 +30929,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ref_order_hints, ); - let (fw, fh) = (frame_width as usize, frame_height as usize); + let (fw, fh) = (lr_w, frame_height as usize); + // An upscaled frame is already at its final size with no mi-aligned + // margin beyond it (the upscale consumed those columns), so the + // wide-margin stash below has nothing left to hand out. + let (true_width, true_height) = if superres().is_some() { + (fw, fh) + } else { + (true_width, true_height) + }; if fw == width && fh == height { LAST_FRAME_WIDE_MARGIN.with(|m| *m.borrow_mut() = None); return Ok(( diff --git a/crates/ec-av1/src/restoration.rs b/crates/ec-av1/src/restoration.rs index a5c38bee..f159dad0 100644 --- a/crates/ec-av1/src/restoration.rs +++ b/crates/ec-av1/src/restoration.rs @@ -340,8 +340,17 @@ pub(crate) fn read_lr( let unit_size = lr.loop_restoration_size[plane]; let horz_units = grid.horz_units[plane] as u32; let vert_units = grid.vert_units[plane] as u32; - let rcol0 = ceil_div(mi_col * mi_size, unit_size); - let rcol1 = ceil_div((mi_col + sb_mi) * mi_size, unit_size).min(horz_units); + // `av1_loop_restoration_corners_in_sb` (restoration.c:1314): under + // superres the mi column is in DOWNSCALED units while the unit grid + // is in upscaled ones, so the column division scales by + // `superres_denom / SCALE_NUMERATOR` (`mi_to_num_x`/`denom_x`). Rows + // are never scaled (spec 7.16 widens columns only). + let (num_x, denom_x) = match crate::decode::superres() { + Some((_, denom)) => (mi_size * denom, unit_size * 8), + None => (mi_size, unit_size), + }; + let rcol0 = ceil_div(mi_col * num_x, denom_x); + let rcol1 = ceil_div((mi_col + sb_mi) * num_x, denom_x).min(horz_units); let rrow0 = ceil_div(mi_row * mi_size, unit_size); let rrow1 = ceil_div((mi_row + sb_mi) * mi_size, unit_size).min(vert_units); let chroma = plane != 0; diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 6091122c..9e70e600 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -701,6 +701,14 @@ pub fn decode_stream_with( )); } crate::decode::set_bit_depth(bit_depth); + // spec 7.16: this frame's superres state, for the filter chain -- + // `decode.rs` upscales between CDEF and loop restoration and sizes + // the LR unit grid in upscaled coordinates. Cleared (0, 8) on an + // unscaled frame so a later frame never inherits it. + crate::decode::set_superres( + if header.use_superres { header.upscaled_width } else { 0 }, + u32::from(header.superres_denom), + ); // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits. let enable_masked_compound = parser .sequence_header() @@ -802,25 +810,6 @@ pub fn decode_stream_with( header.allow_intrabc, header.delta, )?; - // lane-superres stage 3, spec 7.16: upscale AFTER deblock+CDEF - // (both already applied inside `decode_key_frame_tile_with_cdfs`) - // and BEFORE this picture is stored as a reference or handed to - // the caller -- loop restoration is not yet ported, so there is - // no LR step here for the upscale to precede. - // r3: the real decoded margin beyond `frame_width` (set by the - // call above, right before anything else can overwrite it) -- - // see `decode::take_last_frame_wide_margin`'s doc. - let wide_margin = crate::decode::take_last_frame_wide_margin(); - let picture = if header.use_superres { - crate::superres::upscale_picture( - &picture, - header.upscaled_width as usize, - wide_margin.as_ref(), - bit_depth as u32, - ) - } else { - picture - }; // A key frame codes no inter blocks -- its own saved motion // field has no cells set, matching libaom's own "intra frame // contributes nothing to a later projection" behaviour, but @@ -932,25 +921,6 @@ pub fn decode_stream_with( header.delta, enable_filter_intra, )?; - // lane-superres r10: mirrors the key-frame branch above -- - // `decode_inter_frame_tile_with_cdfs` decodes at the downscaled - // `frame_width`/`frame_height` and crops to it; upscale AFTER - // (deblock/CDEF/LR already applied inside that call) BEFORE this - // picture is stored as a reference or shown, same margin - // mechanism (`take_last_frame_wide_margin`, read immediately - // after the call, before any other frame decode can overwrite - // it). - let wide_margin = crate::decode::take_last_frame_wide_margin(); - let picture = if header.use_superres { - crate::superres::upscale_picture( - &picture, - header.upscaled_width as usize, - wide_margin.as_ref(), - bit_depth as u32, - ) - } else { - picture - }; (picture, end_cdfs, motion_field) }; // lane-lr r4: the Wiener/self-guided pixel filters are wired @@ -4823,6 +4793,107 @@ mod tests { eprintln!("{NAME}: pixel-exact, grain_hits={}", crate::film_grain::grain_hits()); } + /// lane-t900 r29: `fixtures/superres_kf_cdef_lr_64x64.obu` is a real + /// aomenc key frame (64x64 upscaled from a coded 43x64, + /// `--superres-mode=1 --superres-denominator=12 --cpu-used=0 --sb-size=64 + /// --enable-cdef=1 --enable-restoration=1 --cq-level=32`) -- the first + /// stream in this repo that runs BOTH in-loop filters under superres. + /// + /// The defect it pins: spec 7.16's upscale runs between CDEF and loop + /// restoration (libaom `superres_post_decode`, `decodeframe.c`, called + /// between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`), + /// but this decoder ran the whole filter chain on the DOWNSCALED frame + /// and upscaled last, in `stream.rs`. Loop restoration therefore filtered + /// downscaled pixels with a unit grid sized from the downscaled width + /// (1873 wrong samples, max 7, on this very stream). Class + /// `wrong-stage-width`: every plane width in the filter chain is either + /// the downscaled one (deblock, CDEF, and the mi grid all three walk) or + /// the upscaled one (loop restoration's `av1_get_upsampled_plane_size` + /// unit grid, `av1_loop_restoration_corners_in_sb`'s `mi_to_num_x` + /// superres arm, and the pixel filters themselves); the sweep is every + /// caller of `apply_deblock`/`apply_cdef`/`apply_loop_restoration` plus + /// `RestorationGrid::new` and `read_lr`. + #[test] + fn a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact() { + const NAME: &str = + "a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/superres_kf_cdef_lr_64x64.obu"); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); + let (width, height) = (64usize, 64usize); + let before_lr = crate::restoration::wiener_hits() + crate::restoration::sgrproj_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), + }; + assert_eq!(frames.len(), 1, "{NAME}: one key frame"); + assert_eq!((frames[0].width, frames[0].height), (width, height)); + // class `gate-blind-to-feature`: the stream must actually upscale and + // actually run a real restoration filter, or this gate proves nothing. + assert!( + crate::superres::superres_hits() > 0, + "{NAME}: zero superres_hits -- the frame was never upscaled" + ); + assert!( + crate::restoration::wiener_hits() + crate::restoration::sgrproj_hits() > before_lr, + "{NAME}: zero restoration units fired -- LR never ran under superres" + ); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); + } + + /// lane-t900 r29 RESIDUAL, ignored: `fixtures/superres_alltools_sb128_320x180.obu` + /// is 10 frames of `--cpu-used=4 --sb-size=128 --superres-mode=1 + /// --superres-denominator=12 --cq-level=32` with every tool aomenc turns + /// on by default (CDEF, loop restoration, OBMC, compound, warp). + /// + /// FIRST BAD (measured 2026-09-04, after the r29 upscale-before-LR fix): + /// display frame 2, plane U, (x=88, y=21), delta 1; the mismatch is + /// CHROMA ONLY and grows with the reference chain (frame 9: 280 U + 331 + /// V samples, max 9). LUMA IS EXACT IN ALL 10 FRAMES. It is NOT the + /// filter chain: re-encoding the same recipe with `--enable-cdef=0 + /// --enable-restoration=0` still mismatches (359 samples, max 5, first + /// bad display frame 4 plane V (115, 31)), and the r29 fix took the + /// filters-on numbers from 37315 samples/max 171 down to 1620/max 11. + /// So the residual is a scaled-reference CHROMA prediction defect at + /// sb128/cpu-used=4 block shapes, not superres filtering -- next round's + /// ladder starts at `EC_AV1_PREFILT_DUMP16` on decode-order frame 4 of + /// the filters-off arm. + #[test] + #[ignore = "lane-t900 r29 residual: scaled-reference chroma prediction, frame 2 U (88,21)"] + fn a_superres_all_tools_sb128_stream_decodes_pixel_exact() { + const NAME: &str = "a_superres_all_tools_sb128_stream_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/superres_alltools_sb128_320x180.obu"); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); + let (width, height, count) = (320usize, 180usize, 10usize); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), + }; + assert_eq!(frames.len(), count, "{NAME}: frame count"); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, count); + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg"); + assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); + assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg"); + } + } + /// lane-golomb r1: THE FILM ITSELF. `crates/ec-av1/fixtures/reelb_head_key_frame.obu` /// is the first frame of the user's ReelB AV1 release (3840x1608 /// yuv420p10le, `ffmpeg -i -c copy -frames:v 1 -f obu`, 147 bytes) -- diff --git a/crates/ec-av1/src/superres.rs b/crates/ec-av1/src/superres.rs index d49f2196..b8c06dae 100644 --- a/crates/ec-av1/src/superres.rs +++ b/crates/ec-av1/src/superres.rs @@ -145,91 +145,46 @@ pub(crate) fn upscale_row( } } -/// Spec 7.16, applied to a whole plane: `av1_upscale_normative_rows` -/// widened to every row (`height2 == height`, no vertical scaling -- the -/// spec only widens columns). `rows` is the plane's row-major byte buffer -/// at `in_width`; returns a new buffer at `out_width`. -pub(crate) fn upscale_plane( - rows: &[u16], - height: usize, - in_width: usize, - out_width: usize, - margin: Option<(&[u16], usize)>, +/// Every row of one decoded plane, upscaled by spec 7.16 from `in_w` to +/// `out_w` (`av1_upscale_normative_rows`; the process is horizontal-only, +/// so the row count is unchanged). `data`/`stride` are the decoder's own +/// reconstruction buffer, whose columns `[in_w, true_w)` hold the real +/// decoded samples of the coding block straddling the frame edge -- libaom's +/// border extension replicates from that last real column, so they are +/// handed to [`upscale_row`] as its right margin (see its doc). +pub(crate) fn upscale_plane_strided( + data: &[u16], + stride: usize, + in_w: usize, + in_h: usize, + true_w: usize, + out_w: usize, bit_depth: u32, ) -> Vec { - debug_assert_eq!(rows.len(), height * in_width); - let mut out = vec![0u16; height * out_width]; - for r in 0..height { - let src = &rows[r * in_width..(r + 1) * in_width]; - let dst = &mut out[r * out_width..(r + 1) * out_width]; - let real_right = match margin { - Some((margin_rows, margin_width)) if margin_width > in_width => { - &margin_rows[r * margin_width + in_width..(r + 1) * margin_width] - } - _ => &[], - }; - upscale_row(src, real_right, out_width, dst, bit_depth); + let mut out = vec![0u16; in_h * out_w]; + for r in 0..in_h { + let row = &data[r * stride..r * stride + in_w]; + let margin = &data[r * stride + in_w..r * stride + true_w.max(in_w)]; + upscale_row(row, margin, out_w, &mut out[r * out_w..(r + 1) * out_w], bit_depth); } out } thread_local! { /// Firing count for the superres gate (class `gate-blind-to-feature`): - /// how many whole pictures actually ran through [`upscale_plane`]. + /// how many whole pictures actually ran through [`upscale_plane_strided`]. static SUPERRES_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// Current value of [`SUPERRES_HITS`]. +#[allow(dead_code)] pub(crate) fn superres_hits() -> usize { SUPERRES_HITS.with(|c| c.get()) } -/// A whole [`crate::encode::Picture`]'s Y/U/V planes, upscaled from -/// `frame_width`/`frame_height` (4:2:0 chroma) to `upscaled_width` at the -/// same height -- spec 7.16 is horizontal-only. Increments -/// [`SUPERRES_HITS`] once per call. `margin`, when set (r3, from -/// `decode::take_last_frame_wide_margin`), is the real decoded pixels -/// beyond `picture`'s own width out to the mi-aligned `true_width` -- see -/// [`upscale_row`]'s doc for why the right-edge padding needs it. -pub(crate) fn upscale_picture( - picture: &crate::encode::Picture, - upscaled_width: usize, - margin: Option<&crate::encode::Picture>, - bit_depth: u32, -) -> crate::encode::Picture { +/// Counts one whole upscaled picture (all three planes) for [`SUPERRES_HITS`]. +pub(crate) fn note_upscaled_picture() { SUPERRES_HITS.with(|c| c.set(c.get() + 1)); - let height = picture.height; - let chroma_in_w = picture.width.div_ceil(2); - let chroma_out_w = upscaled_width.div_ceil(2); - let chroma_h = height.div_ceil(2); - crate::encode::Picture { - width: upscaled_width, - height, - y: upscale_plane( - &picture.y, - height, - picture.width, - upscaled_width, - margin.map(|m| (m.y.as_slice(), m.width)), - bit_depth, - ), - u: upscale_plane( - &picture.u, - chroma_h, - chroma_in_w, - chroma_out_w, - margin.map(|m| (m.u.as_slice(), m.width.div_ceil(2))), - bit_depth, - ), - v: upscale_plane( - &picture.v, - chroma_h, - chroma_in_w, - chroma_out_w, - margin.map(|m| (m.v.as_slice(), m.width.div_ceil(2))), - bit_depth, - ), - } } #[cfg(test)]