forge
Explore
Log in

Don't you dare go Hollow

The frame interpolation filter reaches the pixels, all three kernels ffmpeg-exact

Browse files at this commit

06bd77f0819b407a7c8eb219ecbd1fe80a3a8405Ahmet Kaan GümüşParent: 012b9fc
  • test
    • the frame interpolation filter reaches the pixels, all three kernels ffmpeg-exact
Show full message
test(av1): the frame interpolation filter reaches the pixels, all three kernels ffmpeg-exact
crates/ec-av1/src/encode.rsmodified+81 -4
@@ -1816,12 +1816,38 @@ pub const GOLDEN_SLOT: u8 = 1;
1816 /// reaches the search, the trials and the recon through1816 /// reaches the search, the trials and the recon through
1817 /// `FrameCtx::interp_filter`, so the stream a decoder reads and the1817 /// `FrameCtx::interp_filter`, so the stream a decoder reads and the
1818 /// prediction the search priced are the same one.1818 /// prediction the search priced are the same one.
1819+/// A PROCESS-GLOBAL [`frame_interp_filter`] override that wins over the
1820+/// environment (`u8::MAX` = unset), the shape [`set_inter_tx_search`] has:
1821+/// the witness that has to see a non-REGULAR kernel coded and decoded turns
1822+/// it on through this while holding [`crate::speed::knob_write`].
1823+static INTERP_OVERRIDE: std::sync::atomic::AtomicU8 =
1824+ std::sync::atomic::AtomicU8::new(u8::MAX);
1825+
1826+/// Sets [`INTERP_OVERRIDE`]; `None` clears it.
1827+#[allow(dead_code)] // set only from the `#[cfg(test)]` gates
1828+pub(crate) fn set_frame_interp(filter: Option<ec_av1_syntax::InterpolationFilter>) {
1829+ INTERP_OVERRIDE.store(
1830+ filter.map_or(u8::MAX, |f| f as u8),
1831+ std::sync::atomic::Ordering::Relaxed,
1832+ );
1833+}
1834+
1819 fn frame_interp_filter() -> ec_av1_syntax::InterpolationFilter {1835 fn frame_interp_filter() -> ec_av1_syntax::InterpolationFilter {
1820- match std::env::var("EC_AV1_INTERP").ok().as_deref() {1836+ use ec_av1_syntax::InterpolationFilter as F;
1821- Some("smooth") => ec_av1_syntax::InterpolationFilter::EighttapSmooth,1837+ match INTERP_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) {
1822- Some("sharp") => ec_av1_syntax::InterpolationFilter::EighttapSharp,1838+ 0 => return F::Eighttap,
1823- _ => ec_av1_syntax::InterpolationFilter::Eighttap,1839+ 1 => return F::EighttapSmooth,
1840+ 2 => return F::EighttapSharp,
1841+ _ => {}
1824 }1842 }
1843+ static ENV: std::sync::LazyLock<Option<F>> = std::sync::LazyLock::new(|| {
1844+ crate::envflags::var("EC_AV1_INTERP").ok().map(|v| match v.as_str() {
1845+ "smooth" => F::EighttapSmooth,
1846+ "sharp" => F::EighttapSharp,
1847+ _ => F::Eighttap,
1848+ })
1849+ });
1850+ ENV.unwrap_or(F::Eighttap)
1825 }1851 }
1826 1852
1827 /// The frame header for a shown inter frame that predicts from the single1853 /// The frame header for a shown inter frame that predicts from the single
@@ -16711,4 +16737,55 @@ mod tests {
16711 }16737 }
16712 }16738 }
16713 16739
16740+ /// lane-refs: THE FRAME FILTER REACHES THE PIXELS. `mc::predict` used to
16741+ /// hardwire the REGULAR kernel, so the encoder could not have coded a
16742+ /// SMOOTH or SHARP frame even if the header had said so -- the search,
16743+ /// the trials, the recon and the frame header now all read
16744+ /// `FrameCtx::interp_filter`. Each of the three kernels codes its own
16745+ /// distinct stream (a filter that never reached the prediction would code
16746+ /// the same bytes as REGULAR, class `symbol consumption gap`), and ffmpeg
16747+ /// reconstructs every frame of each of them exactly, which is what proves
16748+ /// the header and the prediction agree.
16749+ #[test]
16750+ fn each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly() {
16751+ let _knobs = crate::speed::knob_write();
16752+ if !have_ffmpeg() {
16753+ eprintln!("SKIP each_frame_interpolation_filter_codes_its_own_stream: no ffmpeg");
16754+ return;
16755+ }
16756+ let (width, height) = (256usize, 128usize);
16757+ // A HALF-PEL pan: an integer-pel one reads no filter tap at all, so
16758+ // all three kernels would code the same bytes and the test would pass
16759+ // on a wiring that does nothing (class `fixture proves the symbol, not
16760+ // the signal`). `panned_test_card` shifts by whole pixels, so the
16761+ // search finds the sub-pel positions off the reconstruction instead:
16762+ // three frames of a slow diagonal pan.
16763+ let pictures: Vec<Picture> = (0..3).map(|i| panned_test_card(width, height, i * 3)).collect();
16764+ let mut streams = Vec::new();
16765+ for filter in [
16766+ ec_av1_syntax::InterpolationFilter::Eighttap,
16767+ ec_av1_syntax::InterpolationFilter::EighttapSmooth,
16768+ ec_av1_syntax::InterpolationFilter::EighttapSharp,
16769+ ] {
16770+ set_frame_interp(Some(filter));
16771+ let fctx = &crate::decode::FrameCtx::for_encoder();
16772+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
16773+ .unwrap_or_else(|e| panic!("{filter:?}: {e}"));
16774+ let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, 3);
16775+ assert_eq!(decoded.len(), 3, "{filter:?}: decoded frame count");
16776+ for (i, (frame, decoded)) in encoded.frames.iter().zip(&decoded).enumerate() {
16777+ assert_eq!(decoded.y, frame.reconstruction.y, "{filter:?} frame {i}: luma");
16778+ assert_eq!(decoded.u, frame.reconstruction.u, "{filter:?} frame {i}: U");
16779+ assert_eq!(decoded.v, frame.reconstruction.v, "{filter:?} frame {i}: V");
16780+ }
16781+ streams.push((filter, encoded.stream));
16782+ }
16783+ set_frame_interp(None);
16784+ for (i, (fa, a)) in streams.iter().enumerate() {
16785+ for (fb, b) in &streams[i + 1..] {
16786+ assert_ne!(a, b, "{fa:?} and {fb:?} coded the same bytes");
16787+ }
16788+ }
16789+ }
16790+
16714 }16791 }