diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 1f9b0364..bf973a8b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2495,33 +2495,6 @@ fn cdef_filter_block( /// /// Ported from libaom's `av1/common/av1_loopfilter.c` (edge/level decision) /// and `aom_dsp/loopfilter.c` (the `aom_lpf_*` pixel kernels). -// r17 bisect scratch: dump this frame's true-extent Y/U/V (same layout as -// aomdec's EC_AV1_PREFILT_DUMP/EC_AV1_POSTFILT_DUMP) to `$var.f$idx` when -// `var` is set. Remove with the rest of the r17 bisect scaffolding. -static R17_DUMP_FRAME_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); -// r17 bisect scratch accessor for stream.rs's own debug prints -- shares the -// same counter block-decode already reads. Remove with the rest of the r17 -// bisect scaffolding. -pub fn r17_dump_frame_idx() -> usize { - R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed) -} -fn r17_dump(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, idx: usize) { - let Ok(base) = std::env::var(var) else { - return; - }; - let mut out = Vec::new(); - for r in 0..y.true_height { - out.extend_from_slice(&y.data[r * y.width..r * y.width + y.true_width]); - } - for r in 0..u.true_height { - out.extend_from_slice(&u.data[r * u.width..r * u.width + u.true_width]); - } - for r in 0..v.true_height { - out.extend_from_slice(&v.data[r * v.width..r * v.width + v.true_width]); - } - let _ = std::fs::write(format!("{base}.f{idx}"), out); -} - fn apply_deblock( y: &mut PlaneBuf, u: &mut PlaneBuf, @@ -3712,21 +3685,9 @@ fn resolve_interp_filter( // `h_kind`/`v_kind` argument order, which is why this function returns // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`). let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound); - if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { - eprintln!( - "IFILTER_RS dir=0 ctx={ctx0} cdf={:?}", - &cdfs.switchable_interp[ctx0][..3] - ); - } let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8; let sym1 = if enable_dual_filter { let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound); - if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { - eprintln!( - "IFILTER_RS dir=1 ctx={ctx1} cdf={:?}", - &cdfs.switchable_interp[ctx1][..3] - ); - } dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u8 } else { sym0 @@ -4340,14 +4301,6 @@ fn decode_inter_block( let (cpx, cpy) = (px / 2, py / 2); let chroma_side = side / 2; - if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { - eprintln!( - "BITPOS_BLK_START mi_row={} mi_col={} bitpos={}", - py / 4, - px / 4, - dec.debug_bitpos() - ); - } let skip_mode_ctx = usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; @@ -4536,8 +4489,8 @@ fn decode_inter_block( // (av1_dist_wtd_convolve_2d_c, convolve.c:402-415) for every // input, and a whole-pel zero-MV compound block (mv0=mv1=(0,0), // the common case a lag-in-frames GOP's hidden altref frames - // hit) reproduces aomdec's own pre-deblock `EC_AV1_PREFILT_DUMP` - // byte-for-byte for several consecutive frames. + // hit) reproduces aomdec's own pre-deblock dump byte-for-byte + // for several consecutive frames. // // The real defect a live gate run isolated (seed 49, // `fixtures/av1blend-r1-mismatch.obu`): decode-order frame 0 @@ -4599,15 +4552,15 @@ fn decode_inter_block( // synced `EC_TOK`/`EC_PART` trace from the instrumented aomdec // build (`/tmp/libaom-src/build/decoder-debug/aomdec`) on // `fixtures/av1blend-r1-mismatch.obu` (seed 45 now, not seed 49) - // -- the pre-deblock `EC_AV1_PREFILT_DUMP` frame-index alignment - // between this crate and that aomdec build is NOT 1:1 on this - // fixture (23 dumps here vs 24 there), so calibrate that first. + // -- the pre-deblock dump frame-index alignment between this + // crate and that aomdec build is NOT 1:1 on this fixture (23 + // dumps here vs 24 there), so calibrate that first. // r3 (this round): pre-deblock buffers were bisected byte-for-byte - // against an instrumented aomdec build (EC_AV1_PREFILT_DUMP, - // frame-index alignment recalibrated via content-hash matching - // rather than the raw dump count -- the keyframe never calls this - // crate's own `r17_dump` at all, since only `decode_inter_frame_ - // tile` does, which is the whole "23 vs 24" gap, not a real bug). + // against an instrumented aomdec build (frame-index alignment + // recalibrated via content-hash matching rather than the raw + // dump count -- the keyframe never calls a pre-deblock dump at + // all, since only `decode_inter_frame_tile` does, which is the + // whole "23 vs 24" gap, not a real bug). // Decode-order frame 3 (`fixtures/av1blend-r1-mismatch.obu`, // seed 45) is still the first divergence: PRE-deblock differs // from aomdec's own pre-deblock dump by up to 1, on ~20% of @@ -4726,25 +4679,7 @@ fn decode_inter_block( ref_order_hints[(ref0 - LAST_FRAME) as usize], ref_order_hints[(ref1 - LAST_FRAME) as usize], ); - if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { - let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprintln!( - "COMPIDX_BLK fidx={fidx} mi_row={} mi_col={} ctx={idx_ctx} cdf0={} \ - ref0={ref0} ref1={ref1}", - py / 4, - px / 4, - cdfs.compound_idx[idx_ctx][0] - ); - } let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); - if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { - eprintln!( - "COMPIDX_VAL mi_row={} mi_col={} decoded={idx} bitpos={}", - py / 4, - px / 4, - dec.debug_bitpos() - ); - } if idx == 1 { (8, 8, 1u8) } else { @@ -4767,28 +4702,6 @@ fn decode_inter_block( // (lane-av1blend r5) from its old position ahead of those reads, // which stole their bits for a Switchable-filter compound block // and desynced every symbol read after it in the tile. - if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { - eprintln!( - "IFILTER_PRE mi_row={} mi_col={} interp_fixed={:?} is_globalmv={is_globalmv}", - py / 4, - px / 4, - interp_fixed - ); - } - if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { - let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprintln!( - "CREF fidx={fidx} mi_row={} mi_col={} side={side} ref0={ref0} ref1={ref1} \ - above_ref={} left_ref={} above_ref1={:?} left_ref1={:?} \ - above_filter_ctx={above_filter_ctx:?} left_filter_ctx={left_filter_ctx:?}", - py / 4, - px / 4, - neighbours.above_ref[c], - neighbours.left_ref[r], - neighbours.above_ref1[c], - neighbours.left_ref1[r], - ); - } let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( dec, cdfs, @@ -4800,14 +4713,6 @@ fn decode_inter_block( true, ); block_filter = resolved_filter; - if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { - let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprintln!( - "CREF_RESOLVED fidx={fidx} mi_row={} mi_col={} resolved={resolved_filter:?}", - py / 4, - px / 4, - ); - } let mut inter0_y = vec![0i32; side * side]; mc::predict_compound_intermediate( @@ -4840,20 +4745,6 @@ fn decode_inter_block( let mut pred_y = vec![0u8; side * side]; mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); - // r17 bisect scratch: dump per-block compound state when this - // block overlaps the pinned fixture's bad quadrant (frame 2, - // rows 32-63 cols 32-63). Remove with the rest of the scaffolding. - if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { - let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprintln!( - "leaf16 fidx={fidx} px={px} py={py} side={side} ref0={ref0} ref1={ref1} \ - mv0={mv0:?} mv1={mv1:?} filter={resolved_filter:?} \ - fwd={fwd_offset} bck={bck_offset} compound_idx={compound_idx} \ - pred_y[0..4]={:?}", - &pred_y[0..4.min(pred_y.len())] - ); - } - let mut inter0_u = vec![0i32; chroma_side * chroma_side]; mc::predict_compound_intermediate( &pu0.data, @@ -5128,20 +5019,6 @@ fn decode_inter_block( } else { [3, 3] }; - if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { - let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprintln!( - "SREF fidx={fidx} mi_row={} mi_col={} side={side} ref_frame={ref_frame} \ - above_ref={} left_ref={} above_ref1={:?} left_ref1={:?} \ - above_filter_ctx={above_filter_ctx:?} left_filter_ctx={left_filter_ctx:?}", - py / 4, - px / 4, - neighbours.above_ref[c], - neighbours.left_ref[r], - neighbours.above_ref1[c], - neighbours.left_ref1[r], - ); - } let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( dec, cdfs, @@ -5152,14 +5029,6 @@ fn decode_inter_block( left_filter_ctx, false, ); - if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { - let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprintln!( - "SREF_RESOLVED fidx={fidx} mi_row={} mi_col={} resolved={resolved_filter:?}", - py / 4, - px / 4, - ); - } block_filter = resolved_filter; globalmv_for_lf = is_globalmv; if std::env::var_os("EC_AV1_TRACE").is_some() { @@ -5763,15 +5632,6 @@ fn decode_inter_block8( let mut pred_y = vec![0u8; SIDE * SIDE]; mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); - if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { - let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprintln!( - "leaf8 fidx={fidx} px={px} py={py} ref0={ref0} ref1={ref1} \ - mv0={mv0:?} mv1={mv1:?} fwd={fwd_offset} bck={bck_offset} \ - compound_idx={compound_idx} pred_y={pred_y:?}" - ); - } - let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; mc::predict_compound_intermediate( &pu0.data, @@ -6453,14 +6313,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( let scan4 = default_scan(TX4); let mut cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx))); - if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { - let idx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); - eprint!("COMPIDX_PRE fidx={} (aomdec fidx={})", idx, idx + 1); - for (c, row) in cdfs.compound_idx.iter().enumerate() { - eprint!(" ctx{c}={}", row[0]); - } - eprintln!(); - } let mut dec = SymbolDecoder::new(data); let mut neighbours = Neighbours::new( cols as usize * 2, @@ -6737,10 +6589,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } } - let r17_idx = R17_DUMP_FRAME_IDX.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - r17_dump("EC_AV1_PREFILT_DUMP", &y, &u, &v, r17_idx); apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); - r17_dump("EC_AV1_POSTFILT_DUMP", &y, &u, &v, r17_idx); apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); let motion_field = build_motion_field( diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 082284b8..345f9842 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -74,7 +74,6 @@ pub fn decode_stream(data: &[u8]) -> Result> { let mut cdf_slots: [Option; NUM_REF_FRAMES] = std::array::from_fn(|_| None); let mut pos = 0usize; - let mut decode_idx = 0u32; while pos < data.len() { let obu = parser.parse_obu(&data[pos..])?; let obu_offset = pos; @@ -115,12 +114,6 @@ pub fn decode_stream(data: &[u8]) -> Result> { picture }; pictures.push(output); - if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { - eprintln!( - "PUSH (show_existing_frame slot {slot}) pictures.len()={}", - pictures.len() - ); - } continue; } let ObuKind::Frame(header, tiles) = obu.kind else { @@ -266,19 +259,6 @@ pub fn decode_stream(data: &[u8]) -> Result> { ec_av1_syntax::InterpolationFilter::Switchable => None, fixed => Some(crate::mc::InterpFilterKind::from_header(fixed)), }; - if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { - eprintln!( - "STREAM_HEADER r17_before={} interpolation_filter={:?} interp_fixed={interp_fixed:?} is_motion_mode_switchable={} enable_interintra_compound={:?} allow_warped_motion={} reference_select={} primary_ref_frame={}", - crate::decode::r17_dump_frame_idx(), - header.interpolation_filter, - header.is_motion_mode_switchable, - parser.sequence_header().map(|s| s.enable_interintra_compound), - header.allow_warped_motion, - header.reference_select, - header.primary_ref_frame, - ); - } - // Spec 7.20 `load_cdfs`: a frame naming a `primary_ref_frame` resumes // from that reference slot's saved CDF state instead of the spec 8.4 // defaults `decode_key/inter_frame_tile_with_cdfs`'s `None` case @@ -307,19 +287,6 @@ pub fn decode_stream(data: &[u8]) -> Result> { let ref_order_hints: [u32; 7] = std::array::from_fn(|i| order_hint_slots[header.ref_frame_idx[i] as usize]); - if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { - eprintln!( - "FRAME decode_idx={decode_idx} type={:?} show={} order_hint={} refresh_frame_flags={:#04x} ref_frame_idx={:?} order_hint_slots={:?}", - header.frame_type, - header.show_frame, - header.order_hint, - header.refresh_frame_flags, - header.ref_frame_idx, - order_hint_slots, - ); - } - decode_idx += 1; - let (picture, end_cdfs, motion_field) = if header.frame_type == FrameType::Key { let (picture, end_cdfs) = decode_key_frame_tile_with_cdfs( tile_bytes, @@ -466,18 +433,6 @@ pub fn decode_stream(data: &[u8]) -> Result> { picture }; pictures.push(output); - if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { - eprintln!( - "PUSH (shown-direct) pictures.len()={} <- decode.rs r17 fidx {}", - pictures.len(), - crate::decode::r17_dump_frame_idx() - ); - } - } else if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { - eprintln!( - "HIDDEN frame decoded, not pushed <- decode.rs r17 fidx {}", - crate::decode::r17_dump_frame_idx() - ); } } Ok(pictures) @@ -3201,11 +3156,8 @@ mod tests { a_real_aomenc_temporal_mv_gate(42, 40); } - /// r17 bisect scratch: decode a pinned stream exactly once, so - /// `decode::r17_dump`'s frame index (a process-wide counter) lines up - /// with `aomdec`'s own per-frame `EC_AV1_PREFILT_DUMP`/ - /// `EC_AV1_POSTFILT_DUMP` numbering. Remove with the rest of the r17 - /// scaffolding. + /// bisect scratch: decode a pinned stream exactly once -- generic + /// pin-repro tool, kept for manual use. #[test] #[ignore] fn scratch_decode_pinned_stream_once() { @@ -3217,46 +3169,6 @@ mod tests { } } - /// scratch: decode a pinned stream end to end and report where/why it - /// refuses, plus `non_last_ref_hits` progression. - #[test] - #[ignore] - fn scratch_decode_pinned_stream() { - let path = std::env::var("EC_AV1_PIN").expect("set EC_AV1_PIN to the .obu path"); - let stream = std::fs::read(&path).expect("read pinned stream"); - let before = decode::non_last_ref_hits(); - match decode_stream(&stream) { - Ok(frames) => eprintln!( - "OK: {} frames, non_last_ref_hits {} -> {}", - frames.len(), - before, - decode::non_last_ref_hits() - ), - Err(e) => eprintln!( - "ERR: {} (non_last_ref_hits {} -> {})", - e, - before, - decode::non_last_ref_hits() - ), - } - // Truncate at each Frame OBU boundary and re-decode from scratch, to - // see which frame index first fails. - let mut p = Av1Parser::new(); - let mut pos = 0usize; - let mut frame_idx = 0; - while pos < stream.len() { - let obu = p.parse_obu(&stream[pos..]).expect("parse"); - pos += obu.total_size; - if matches!(obu.kind, ObuKind::Frame(_, _)) { - match decode_stream(&stream[..pos]) { - Ok(_) => eprintln!("through frame {frame_idx}: OK"), - Err(e) => eprintln!("through frame {frame_idx}: ERR {e}"), - } - frame_idx += 1; - } - } - } - /// scratch: isolate a pinned mismatching stream's first divergent pixel. #[test] #[ignore] @@ -3338,109 +3250,6 @@ mod tests { } } - /// lane-av1blend r4 scratch: decodes the pinned `av1blend-r1-mismatch.obu` - /// (seed 45) with `EC_AV1_COMPIDX_DUMP` set, to compare the pre-tile-decode - /// `compound_idx` CDF state of every frame against an instrumented - /// aomdec's own `COMPIDX_PRE` dump. Errors out at decode-order frame 3 - /// (the still-masked compound path) -- that is expected, the dump lines - /// before the error are what this test is for. Remove with the rest of - /// the r1-r4 scaffolding. - #[test] - #[ignore] - fn scratch_dump_compound_idx_cdf_state() { - let path = concat!( - env!("CARGO_MANIFEST_DIR"), - "/../../fixtures/av1blend-r1-mismatch.obu" - ); - let stream = std::fs::read(path).expect("reading pinned stream"); - let _ = decode_stream(&stream); - } - - /// lane-av1blend r2 scratch: sweep every seed of the compound_references - /// recipe (with the plain-average blend UNMASKED locally) looking for a - /// pixel mismatch, dumping the first one found to `EC_AV1_GATE_DUMP`. - /// Remove with the rest of the r1/r2 scaffolding. - #[test] - #[ignore] - fn scratch_sweep_compound_mismatch() { - if !have_ffmpeg() || !have_aomenc() { - eprintln!("SKIP: missing ffmpeg/aomenc"); - return; - } - let (width, height, frame_count) = (64usize, 64usize, 24usize); - for seed in 42..82u32 { - let duration = frame_count as f64 / 25.0; - let source = - format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25"); - let y4m = Command::new("ffmpeg") - .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", - ]) - .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .output() - .expect("ffmpeg failed to run"); - assert!(y4m.status.success()); - let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=45", "--cpu-used=0", - "--kf-max-dist=1000", "--threads=1", "--row-mt=0", "--auto-alt-ref=1", - "--lag-in-frames=16", "--enable-fwd-kf=0", "--enable-order-hint=1", - "--enable-warped-motion=0", "--enable-obmc=0", "--enable-masked-comp=0", - "--enable-interintra-comp=0", "--enable-onesided-comp=0", - "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", - "--enable-rect-partitions=0", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--enable-filter-intra=0", - "--enable-smooth-intra=0", "--enable-paeth-intra=0", - "--enable-directional-intra=0", "--enable-angle-delta=0", - "--enable-tx-size-search=0", "--enable-cdef=0", "--enable-restoration=0", - "--max-partition-size=32", "--min-partition-size=32", "--enable-palette=0", - "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", - "--obu", "-o", "-", "-", - ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); - assert!(out.status.success()); - let stream = out.stdout; - let frames = match decode_stream(&stream) { - Err(_) => continue, - Ok(frames) => frames, - }; - if frames.len() != frame_count { - continue; - } - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); - let mismatched = frames - .iter() - .zip(&ffmpeg_frames) - .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); - if mismatched { - eprintln!("MISMATCH seed {seed}"); - if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { - std::fs::write(&path, &stream).expect("writing pinned stream"); - eprintln!("wrote {path}"); - } - return; - } else { - eprintln!("seed {seed}: bit-exact"); - } - } - eprintln!("no mismatch found in sweep"); - } - /// Final round of the TX4/tx-class lane's own gate: `--min-partition-size=8 /// --max-partition-size=8` pins every leaf to exactly 8x8 (spec /// 5.11.4's own boundary carve-out aside, which a multiple-of-8 frame