U3: delete dumpio.rs and every EC_*_DUMP gate that wrote through it (tile, stream, decode-order, final, tables); also the msac symtrace writer/reader trace that used dumpio::pin. Env unset: no output change
Browse files at this commita9468adb9cdbc275045e0c78008765e0efe18173Parent: 85d627111 changed files +0 -1184
- crates/ec-av1/src/decode/block.rs +0 -140
- crates/ec-av1/src/decode/coeffs.rs +0 -23
- crates/ec-av1/src/decode/frame_tile.rs +0 -59
- crates/ec-av1/src/decode/inter_block.rs +0 -5
- crates/ec-av1/src/decode/key_tile.rs +0 -74
- crates/ec-av1/src/dumpio.rs +0 -568
- crates/ec-av1/src/lib.rs +0 -1
- crates/ec-av1/src/msac.rs +0 -181
- crates/ec-av1/src/mvstack.rs +0 -18
- crates/ec-av1/src/stream/mod.rs +0 -103
- crates/ec-av1/src/tile/blocks.rs +0 -12
crates/ec-av1/src/decode/block.rsmodified+0 -140
| @@ -586,146 +586,6 @@ pub(crate) fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { | ||
| 586 | 586 | /// deleted: `PREFILT_PICTURE_IDX` is bumped after this point, not before it, so |
| 587 | 587 | /// the counter that names these files is the per-var map. |
| 588 | 588 | // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. |
| 589 | -#[allow(clippy::too_many_arguments)] | |
| 590 | -pub(super) fn dump_stage16( | |
| 591 | - var: &str, | |
| 592 | - y: &PlaneBuf<'_>, | |
| 593 | - u: &PlaneBuf<'_>, | |
| 594 | - v: &PlaneBuf<'_>, | |
| 595 | - fw: usize, | |
| 596 | - fh: usize, | |
| 597 | - ss_x: usize, | |
| 598 | - ss_y: usize, | |
| 599 | -) { | |
| 600 | - // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by | |
| 601 | - // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed | |
| 602 | - // `.f0` name kept only the LAST frame, so a mid-sequence divergence could | |
| 603 | - // not be read at all. | |
| 604 | - // | |
| 605 | - // lane-unwritten-dep: the chroma extent is PER-AXIS subsampling, not | |
| 606 | - // `div_ceil(2)` on both. The hardcoded pair was a 4:2:0 assumption and it | |
| 607 | - // was load-bearing: on a 64x64 4:2:2 frame (ss_x = 1, ss_y = 0) it wrote | |
| 608 | - // 32x32 chroma per plane where the frame carries 32x64, so HALF of each | |
| 609 | - // chroma plane appeared in NO stage dump at all. A stage bisect that reads | |
| 610 | - // "identical pre-deblock, differs post-deblock" off these dumps is then | |
| 611 | - // measuring the dump's blind spot, not the pipeline's: the samples it could | |
| 612 | - // not see are exactly the region where the 4:2:2 witness's output diverges | |
| 613 | - // (chroma rows 32..63 -- the old `fh.div_ceil(2)` crop wrote 32 of 64 rows, | |
| 614 | - // so everything from row 32 up was invisible; 2048 samples). `round_ss` is | |
| 615 | - // the same rounding the | |
| 616 | - // decoder's own plane extents use, and it matches the oracle's | |
| 617 | - // `uv_crop_width` / `uv_crop_height` per axis. | |
| 618 | - // | |
| 619 | - // ONE file per frame: `dump_stage_idx` advances on every call, so creating | |
| 620 | - // the file inside the plane loop would write three files per frame and | |
| 621 | - // shift every later frame's index. | |
| 622 | - // | |
| 623 | - // lane-av1dumploud: this used to be `let _ = f.write_all(&bytes)` per row, so | |
| 624 | - // a full filesystem left a SHORT file that no reader could tell from a | |
| 625 | - // complete one. `LoudDump` is given the exact expected length this function | |
| 626 | - // knows -- `(fw*fh + 2*cw*ch) * 2`, u16 LE -- and checks it against the file | |
| 627 | - // on disk; a shortfall aborts the decode instead of leaving a plausible | |
| 628 | - // artefact behind. | |
| 629 | - if let Ok(path) = crate::envflags::var(var) { | |
| 630 | - let cw = round_ss(fw, ss_x); | |
| 631 | - let ch = round_ss(fh, ss_y); | |
| 632 | - let expected = (fw * fh + 2 * cw * ch) * 2; | |
| 633 | - let mut d = crate::dumpio::LoudDump::create( | |
| 634 | - var, | |
| 635 | - format!("{path}.f{}", dump_stage_idx(var)), | |
| 636 | - expected, | |
| 637 | - ); | |
| 638 | - for (p, w, h) in [(y, fw, fh), (u, cw, ch), (v, cw, ch)] { | |
| 639 | - for row in 0..h { | |
| 640 | - let mut bytes = Vec::with_capacity(w * 2); | |
| 641 | - for &s in &p.data[row * p.width..][..w] { | |
| 642 | - bytes.extend_from_slice(&s.to_le_bytes()); | |
| 643 | - } | |
| 644 | - d.write(&bytes); | |
| 645 | - } | |
| 646 | - } | |
| 647 | - d.finish(); | |
| 648 | - } | |
| 649 | -} | |
| 650 | - | |
| 651 | -/// Decode-order index of the next [`dump_stage`]/[`dump_stage16`] file for a | |
| 652 | -/// given env var -- lane-cdef r1: both used to write `.f0` unconditionally, so | |
| 653 | -/// every frame overwrote the previous one and only the LAST frame survived, | |
| 654 | -/// which silently defeats any per-frame filter-stage bisection. | |
| 655 | -fn dump_stage_idx(var: &str) -> usize { | |
| 656 | - use std::collections::HashMap; | |
| 657 | - use std::sync::{Mutex, OnceLock}; | |
| 658 | - static IDX: OnceLock<Mutex<HashMap<String, usize>>> = OnceLock::new(); | |
| 659 | - let mut m = IDX | |
| 660 | - .get_or_init(|| Mutex::new(HashMap::new())) | |
| 661 | - .lock() | |
| 662 | - .unwrap(); | |
| 663 | - let e = m.entry(var.to_string()).or_insert(0); | |
| 664 | - let i = *e; | |
| 665 | - *e += 1; | |
| 666 | - i | |
| 667 | -} | |
| 668 | - | |
| 669 | -pub(super) fn dump_stage(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { | |
| 670 | - // lane-av1dumploud: loud on a short write (see [`crate::dumpio::LoudDump`]). | |
| 671 | - // The expected length is the three planes' own data lengths -- the writer | |
| 672 | - // iterates exactly `p.data`, so this is the same extent, not a re-derivation | |
| 673 | - // that could disagree with it. | |
| 674 | - if let Ok(path) = crate::envflags::var(var) { | |
| 675 | - let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() }; | |
| 676 | - crate::dumpio::write_planes( | |
| 677 | - var, | |
| 678 | - format!("{path}.f{}", dump_stage_idx(var)), | |
| 679 | - &[&narrow(y), &narrow(u), &narrow(v)], | |
| 680 | - ); | |
| 681 | - } | |
| 682 | -} | |
| 683 | - | |
| 684 | -/// `EC_AV1_PREFILT_WIDE_DUMP=<prefix>` -> `<prefix>.f<N>`, the pre-loop-filter | |
| 685 | -/// reconstruction cropped to each plane's mi-ALIGNED true extent, byte for | |
| 686 | -/// byte the shape aomdec's own rung 7 writes (`y_width`/`y_height`, | |
| 687 | -/// `uv_width`/`uv_height`), so the two can be diffed directly. | |
| 688 | -/// | |
| 689 | -/// lane-av1444edge: this used to be an inline block in the KEY-frame tile path | |
| 690 | -/// only, with a FUNCTION-LOCAL `static IDX2` as its counter. Both facts were | |
| 691 | -/// measurement traps, and the second one is why the first went unnoticed: | |
| 692 | -/// the inter-frame path (`decode_inter_frame_tile_with_cdfs`) had no wide | |
| 693 | -/// prefilter dump at all, so every 4:4:4 lossy divergence localized to an | |
| 694 | -/// inter frame had no pre-filter rung to compare against and got attributed to | |
| 695 | -/// reconstruction when the oracle could not see it. The `static` also restarted | |
| 696 | -/// per monomorphisation, so every frame after the first overwrote `.f0` -- a | |
| 697 | -/// per-frame bisection silently compared the LAST decoded frame. The counter | |
| 698 | -/// is now the shared per-var [`dump_stage_idx`] map, and the call also sits on | |
| 699 | -/// the inter path (skipped when the filter pipeline is active, which has | |
| 700 | -/// already deblocked by the time the tile tail runs -- same condition | |
| 701 | -/// `capture_filter_replay` guards itself with). | |
| 702 | -pub(super) fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { | |
| 703 | - let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_WIDE_DUMP") else { | |
| 704 | - return; | |
| 705 | - }; | |
| 706 | - // lane-av1dumploud: loud on a short write. Expected length is | |
| 707 | - // `sum(true_width * true_height)` over the three planes -- the crop the | |
| 708 | - // writer itself builds, so the check cannot disagree with the bytes. | |
| 709 | - let idx = dump_stage_idx("EC_AV1_PREFILT_WIDE_DUMP"); | |
| 710 | - let crop = |plane: &PlaneBuf<'_>| -> Vec<u8> { | |
| 711 | - let mut out = Vec::with_capacity(plane.true_width * plane.true_height); | |
| 712 | - for row in 0..plane.true_height { | |
| 713 | - out.extend( | |
| 714 | - plane.data[row * plane.width..][..plane.true_width] | |
| 715 | - .iter() | |
| 716 | - .map(|&s| s as u8), | |
| 717 | - ); | |
| 718 | - } | |
| 719 | - out | |
| 720 | - }; | |
| 721 | - let (cy, cu, cv) = (crop(y), crop(u), crop(v)); | |
| 722 | - crate::dumpio::write_planes( | |
| 723 | - "EC_AV1_PREFILT_WIDE_DUMP", | |
| 724 | - format!("{path}.f{idx}"), | |
| 725 | - &[&cy, &cu, &cv], | |
| 726 | - ); | |
| 727 | -} | |
| 728 | - | |
| 729 | 589 | /// Unwritten samples [`census_unwritten`] has counted since the last |
| 730 | 590 | /// [`take_unwritten_samples`] -- process-global (not thread-local) because the |
| 731 | 591 | /// gate reads it after the decode, from a different thread than the one that |
crates/ec-av1/src/decode/coeffs.rsmodified+0 -23
| @@ -2310,29 +2310,6 @@ impl Neighbours { | ||
| 2310 | 2310 | left |= self.left[mi_r + cell][0].level; |
| 2311 | 2311 | } |
| 2312 | 2312 | let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; |
| 2313 | - if crate::envflags::env_flag!("EC_ECDUMP") { | |
| 2314 | - let ab: Vec<String> = (0..above_mi) | |
| 2315 | - .map(|k| self.above[mi_c + k][0].level.to_string()) | |
| 2316 | - .collect(); | |
| 2317 | - let lf: Vec<String> = (0..left_mi) | |
| 2318 | - .map(|k| self.left[mi_r + k][0].level.to_string()) | |
| 2319 | - .collect(); | |
| 2320 | - // lane-av1mix: the last few msac register states, so the | |
| 2321 | - // byte-position of the `all_zero` read can be matched against | |
| 2322 | - // aomdec's `EC=(value,rng,bytepos)` dump (decodetxb.c) without a | |
| 2323 | - // second run. | |
| 2324 | - let recent = crate::msac::symtrace::ecdump_recent(4) | |
| 2325 | - .iter() | |
| 2326 | - .map(|(_low, value, rng, bytepos)| format!("({value},{rng},{bytepos})")) | |
| 2327 | - .collect::<Vec<_>>() | |
| 2328 | - .join(" "); | |
| 2329 | - eprintln!( | |
| 2330 | - "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},] recentEC=[{}]", | |
| 2331 | - ab.join(","), | |
| 2332 | - lf.join(","), | |
| 2333 | - recent | |
| 2334 | - ); | |
| 2335 | - } | |
| 2336 | 2313 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 2337 | 2314 | eprintln!( |
| 2338 | 2315 | "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}", |
crates/ec-av1/src/decode/frame_tile.rsmodified+0 -59
| @@ -3228,11 +3228,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 3228 | 3228 | ); |
| 3229 | 3229 | } |
| 3230 | 3230 | |
| 3231 | - // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's | |
| 3232 | - // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against | |
| 3233 | - // that isolate whether a decode-order frame's mismatch already exists | |
| 3234 | - // in reconstruction (this dump) vs is introduced by the loop filter | |
| 3235 | - // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). | |
| 3236 | 3231 | // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders. |
| 3237 | 3232 | if crate::envflags::env_flag!("EC_OBMC") |
| 3238 | 3233 | || crate::envflags::env_flag!("EC_TRACE_MODE") |
| @@ -3243,36 +3238,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 3243 | 3238 | PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) |
| 3244 | 3239 | ); |
| 3245 | 3240 | } |
| 3246 | - dump_stage16( | |
| 3247 | - "EC_AV1_PREFILT_DUMP16", | |
| 3248 | - &y, | |
| 3249 | - &u, | |
| 3250 | - &v, | |
| 3251 | - frame_width as usize, | |
| 3252 | - frame_height as usize, | |
| 3253 | - ss_x(fctx), | |
| 3254 | - ss_y(fctx), | |
| 3255 | - ); | |
| 3256 | 3241 | census_unwritten(&y, &u, &v); |
| 3257 | - if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | |
| 3258 | - // lane-av1dumploud: loud on a short write (see the key-frame twin | |
| 3259 | - // above -- same file, same shape, same three planes). | |
| 3260 | - let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | |
| 3261 | - let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() }; | |
| 3262 | - crate::dumpio::write_planes( | |
| 3263 | - "EC_AV1_PREFILT_DUMP", | |
| 3264 | - format!("{path}.f{idx}"), | |
| 3265 | - &[&narrow(&y), &narrow(&u), &narrow(&v)], | |
| 3266 | - ); | |
| 3267 | - } else { | |
| 3268 | - PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | |
| 3269 | - } | |
| 3270 | - // lane-av1444edge: the inter-frame path's mi-aligned pre-loop-filter | |
| 3271 | - // dump, the rung the key-frame path has always had (see | |
| 3272 | - // `dump_prefilter_wide`). Placed beside the padded `EC_AV1_PREFILT_DUMP` | |
| 3273 | - // above, i.e. before the loop filters run, so the two agree on the point | |
| 3274 | - // in the sequence they sample. | |
| 3275 | - dump_prefilter_wide(&y, &u, &v); | |
| 3276 | 3242 | // lane-av1fwd: the encoder scores ~25 filter candidates against this |
| 3277 | 3243 | // same coded tile ([`FilterReplay`]). Capture the reconstruction here, |
| 3278 | 3244 | // before either filter has touched it -- but only on the shape whose |
| @@ -3314,20 +3280,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 3314 | 3280 | plane_snapshot(&v, ss_y(fctx) as u32), |
| 3315 | 3281 | ) |
| 3316 | 3282 | }); |
| 3317 | - // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own | |
| 3318 | - // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter | |
| 3319 | - // dump above these bisect WHICH filter stage introduced a mismatch. | |
| 3320 | - dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); | |
| 3321 | - dump_stage16( | |
| 3322 | - "EC_AV1_POSTDEBLOCK_DUMP16", | |
| 3323 | - &y, | |
| 3324 | - &u, | |
| 3325 | - &v, | |
| 3326 | - frame_width as usize, | |
| 3327 | - frame_height as usize, | |
| 3328 | - ss_x(fctx), | |
| 3329 | - ss_y(fctx), | |
| 3330 | - ); | |
| 3331 | 3283 | apply_cdef( |
| 3332 | 3284 | &mut y, |
| 3333 | 3285 | &mut u, |
| @@ -3339,17 +3291,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 3339 | 3291 | None, |
| 3340 | 3292 | None, |
| 3341 | 3293 | ); |
| 3342 | - dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); | |
| 3343 | - dump_stage16( | |
| 3344 | - "EC_AV1_POSTCDEF_DUMP16", | |
| 3345 | - &y, | |
| 3346 | - &u, | |
| 3347 | - &v, | |
| 3348 | - frame_width as usize, | |
| 3349 | - frame_height as usize, | |
| 3350 | - ss_x(fctx), | |
| 3351 | - ss_y(fctx), | |
| 3352 | - ); | |
| 3353 | 3294 | capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); |
| 3354 | 3295 | // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called |
| 3355 | 3296 | // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`): |
crates/ec-av1/src/decode/inter_block.rsmodified+0 -5
| @@ -2316,11 +2316,6 @@ pub(super) fn decode_inter_block( | ||
| 2316 | 2316 | }; |
| 2317 | 2317 | (mv, false) |
| 2318 | 2318 | }; |
| 2319 | - if crate::msac::symtrace::dir().is_some() { | |
| 2320 | - crate::msac::symtrace::note(&format!( | |
| 2321 | - " MODE mi=({mi_row},{mi_col}) dbg={dbg_mode} mv={mv:?}" | |
| 2322 | - )); | |
| 2323 | - } | |
| 2324 | 2319 | if crate::envflags::env_flag!("EC_TRACE_MODE") { |
| 2325 | 2320 | for (i, e) in stack.entries.iter().enumerate() { |
| 2326 | 2321 | eprintln!( |
crates/ec-av1/src/decode/key_tile.rsmodified+0 -74
| @@ -2750,11 +2750,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 2750 | 2750 | } |
| 2751 | 2751 | crate::timeline::recon_done(); |
| 2752 | 2752 | |
| 2753 | - // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's | |
| 2754 | - // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against | |
| 2755 | - // that isolate whether a decode-order frame's mismatch already exists | |
| 2756 | - // in reconstruction (this dump) vs is introduced by the loop filter | |
| 2757 | - // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). | |
| 2758 | 2753 | // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders. |
| 2759 | 2754 | if crate::envflags::env_flag!("EC_OBMC") |
| 2760 | 2755 | || crate::envflags::env_flag!("EC_TRACE_MODE") |
| @@ -2765,33 +2760,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 2765 | 2760 | PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) |
| 2766 | 2761 | ); |
| 2767 | 2762 | } |
| 2768 | - dump_stage16( | |
| 2769 | - "EC_AV1_PREFILT_DUMP16", | |
| 2770 | - &y, | |
| 2771 | - &u, | |
| 2772 | - &v, | |
| 2773 | - frame_width as usize, | |
| 2774 | - frame_height as usize, | |
| 2775 | - ss_x(fctx), | |
| 2776 | - ss_y(fctx), | |
| 2777 | - ); | |
| 2778 | 2763 | census_unwritten(&y, &u, &v); |
| 2779 | - if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | |
| 2780 | - // lane-av1dumploud: loud on a short write (three discarded | |
| 2781 | - // `write_all` results before). Expected length = the three planes' own | |
| 2782 | - // data lengths: this dump is the PADDED plane, not a crop, so the | |
| 2783 | - // writer's extent is `p.data` itself. | |
| 2784 | - let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | |
| 2785 | - let narrow = |p: &PlaneBuf<'_>| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() }; | |
| 2786 | - crate::dumpio::write_planes( | |
| 2787 | - "EC_AV1_PREFILT_DUMP", | |
| 2788 | - format!("{path}.f{idx}"), | |
| 2789 | - &[&narrow(&y), &narrow(&u), &narrow(&v)], | |
| 2790 | - ); | |
| 2791 | - } else { | |
| 2792 | - PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | |
| 2793 | - } | |
| 2794 | - dump_prefilter_wide(&y, &u, &v); | |
| 2795 | 2764 | // lane-av1fwd: the encoder's filter search re-decodes this same key |
| 2796 | 2765 | // frame tile per candidate -- capture it once (see [`FilterReplay`]), |
| 2797 | 2766 | // on the shape whose tail is the two filter calls and nothing else. |
| @@ -2848,20 +2817,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 2848 | 2817 | plane_snapshot(&v, ss_y(fctx) as u32), |
| 2849 | 2818 | ) |
| 2850 | 2819 | }); |
| 2851 | - // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own | |
| 2852 | - // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter | |
| 2853 | - // dump above these bisect WHICH filter stage introduced a mismatch. | |
| 2854 | - dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); | |
| 2855 | - dump_stage16( | |
| 2856 | - "EC_AV1_POSTDEBLOCK_DUMP16", | |
| 2857 | - &y, | |
| 2858 | - &u, | |
| 2859 | - &v, | |
| 2860 | - frame_width as usize, | |
| 2861 | - frame_height as usize, | |
| 2862 | - ss_x(fctx), | |
| 2863 | - ss_y(fctx), | |
| 2864 | - ); | |
| 2865 | 2820 | apply_cdef( |
| 2866 | 2821 | &mut y, |
| 2867 | 2822 | &mut u, |
| @@ -2873,17 +2828,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 2873 | 2828 | None, |
| 2874 | 2829 | None, |
| 2875 | 2830 | ); |
| 2876 | - dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); | |
| 2877 | - dump_stage16( | |
| 2878 | - "EC_AV1_POSTCDEF_DUMP16", | |
| 2879 | - &y, | |
| 2880 | - &u, | |
| 2881 | - &v, | |
| 2882 | - frame_width as usize, | |
| 2883 | - frame_height as usize, | |
| 2884 | - ss_x(fctx), | |
| 2885 | - ss_y(fctx), | |
| 2886 | - ); | |
| 2887 | 2831 | capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); |
| 2888 | 2832 | // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called |
| 2889 | 2833 | // between `av1_cdef_frame` and `av1_loop_restoration_filter_frame`): |
| @@ -3009,24 +2953,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3009 | 2953 | fctx.last_frame_wide_margin.with(|m| { |
| 3010 | 2954 | *m.borrow_mut() = if true_width > fw || true_height > fh { |
| 3011 | 2955 | let yc = crop(&y, true_width, true_height); |
| 3012 | - if let Ok(path) = crate::envflags::var("EC_AV1_MARGIN_DUMP") { | |
| 3013 | - static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 3014 | - let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | |
| 3015 | - // corner-cut: this diagnostic dump stays 8-bit-narrowed | |
| 3016 | - // regardless of the stream's real bit depth (debug-only, | |
| 3017 | - // never read by a gate); widen if a >8-bit margin dump | |
| 3018 | - // is ever needed. | |
| 3019 | - // | |
| 3020 | - // lane-av1dumploud: loud on a short write. Expected length is | |
| 3021 | - // `true_width * true_height` -- the crop this dump is exactly, | |
| 3022 | - // not a re-derived geometry. | |
| 3023 | - let narrow: Vec<u8> = yc.iter().map(|&s| s as u8).collect(); | |
| 3024 | - crate::dumpio::write_planes( | |
| 3025 | - "EC_AV1_MARGIN_DUMP", | |
| 3026 | - format!("{path}.f{idx}"), | |
| 3027 | - &[&narrow], | |
| 3028 | - ); | |
| 3029 | - } | |
| 3030 | 2956 | Some(Picture { |
| 3031 | 2957 | width: true_width, |
| 3032 | 2958 | height: true_height, |
crates/ec-av1/src/dumpio.rsdeleted+0 -568
| @@ -1,568 +0,0 @@ | ||
| 1 | -//! Loud dump writing: a dump that cannot hold every byte it claims to hold is | |
| 2 | -//! a failure, not a diagnostic artefact. | |
| 3 | -//! | |
| 4 | -//! lane-av1dumploud: every dump site in this crate wrote through | |
| 5 | -//! `let _ = f.write_all(..)`. A full filesystem, an `RLIMIT_FSIZE`, or any other | |
| 6 | -//! `ENOSPC`/`EFBIG` therefore left a SHORT file on disk and nothing said so. | |
| 7 | -//! Measured consequence, twice in one day: a sentinel-vs-plain hash difference | |
| 8 | -//! that read as decoder nondeterminism reproduced bit-for-bit as a truncated | |
| 9 | -//! dump (`lanes/unwritten-dep.report.md`: frames 0..4 complete plus 13 320 192 | |
| 10 | -//! bytes of frame 5, with `EC_AV1_FINAL_DUMP`'s discarded write error), and an | |
| 11 | -//! empty dump read as instability. That artefact started a whole defect class, | |
| 12 | -//! and a silently wrong diagnostic is worse than a loud one, so every dump site | |
| 13 | -//! goes through [`LoudDump`]: the caller states the expected byte count from the | |
| 14 | -//! geometry it already has, the writer checks that count twice -- once against | |
| 15 | -//! the bytes it was handed, once against the file's own length on disk -- and | |
| 16 | -//! any shortfall aborts the decode with the file, the counts, and the OS error. | |
| 17 | -//! | |
| 18 | -//! The success path is byte-identical to the old `write_all` loop: same bytes, | |
| 19 | -//! same order, same file names. | |
| 20 | -//! | |
| 21 | -//! The failure path is a panic, not a returned `Result`: the dump sites sit in | |
| 22 | -//! the middle of `fn decode_*` functions with no error channel for them, and a | |
| 23 | -//! dump that failed IS a decode failure (the run's measurement is void). This | |
| 24 | -//! is a debug instrument -- it only runs when its env var is set -- so the | |
| 25 | -//! panic cannot affect a normal decode. | |
| 26 | - | |
| 27 | -use std::fs::{File, OpenOptions}; | |
| 28 | -use std::io::Write; | |
| 29 | -use std::path::{Path, PathBuf}; | |
| 30 | - | |
| 31 | -/// One dump file, with the byte count it owes accounted for as it goes. | |
| 32 | -pub struct LoudDump { | |
| 33 | - /// Human-readable label for the failure line: the env var, or | |
| 34 | - /// `VAR.suffix` when the file names something the var alone does not. | |
| 35 | - site: String, | |
| 36 | - path: PathBuf, | |
| 37 | - file: Option<File>, | |
| 38 | - written: usize, | |
| 39 | - /// `None` only for a stream whose total length is genuinely unknowable at | |
| 40 | - /// open time (an append-mode text table). Short-write detection still | |
| 41 | - /// applies -- `write_all` reports a short write as `Err` -- but the failure | |
| 42 | - /// line then carries no expected count, because inventing one would be a | |
| 43 | - /// guess. | |
| 44 | - expected: Option<usize>, | |
| 45 | -} | |
| 46 | - | |
| 47 | -impl LoudDump { | |
| 48 | - /// Open `path` for `site`, expecting exactly `expected` bytes in total. | |
| 49 | - /// | |
| 50 | - /// Failing to CREATE is loud too: a requested dump that does not exist is | |
| 51 | - /// the same silent hole as one that is short (the reader sees no file, or | |
| 52 | - /// an empty one), and it is the more common of the two (a missing parent | |
| 53 | - /// directory, a path a sweep reused as a directory). | |
| 54 | - pub fn create(site: &str, path: impl AsRef<Path>, expected: usize) -> Self { | |
| 55 | - let path = path.as_ref().to_path_buf(); | |
| 56 | - let file = File::create(&path).unwrap_or_else(|e| { | |
| 57 | - abort( | |
| 58 | - site, | |
| 59 | - &path, | |
| 60 | - 0, | |
| 61 | - Some(expected), | |
| 62 | - &format!("could not create the dump file: {e}"), | |
| 63 | - ) | |
| 64 | - }); | |
| 65 | - Self { | |
| 66 | - site: site.to_string(), | |
| 67 | - path, | |
| 68 | - file: Some(file), | |
| 69 | - written: 0, | |
| 70 | - expected: Some(expected), | |
| 71 | - } | |
| 72 | - } | |
| 73 | - | |
| 74 | - /// Open `path` for `site` in APPEND mode with no knowable total length -- | |
| 75 | - /// the CDF-table text dump, whose file spans every frame of a run. Write | |
| 76 | - /// errors are still fatal; the length check is simply absent (see | |
| 77 | - /// [`LoudDump::expected`]). | |
| 78 | - pub fn append_unknown(site: &str, path: impl AsRef<Path>) -> Self { | |
| 79 | - let path = path.as_ref().to_path_buf(); | |
| 80 | - let file = OpenOptions::new() | |
| 81 | - .create(true) | |
| 82 | - .append(true) | |
| 83 | - .open(&path) | |
| 84 | - .unwrap_or_else(|e| { | |
| 85 | - abort( | |
| 86 | - site, | |
| 87 | - &path, | |
| 88 | - 0, | |
| 89 | - None, | |
| 90 | - &format!("could not open the dump file: {e}"), | |
| 91 | - ) | |
| 92 | - }); | |
| 93 | - Self { | |
| 94 | - site: site.to_string(), | |
| 95 | - path, | |
| 96 | - file: Some(file), | |
| 97 | - written: 0, | |
| 98 | - expected: None, | |
| 99 | - } | |
| 100 | - } | |
| 101 | - | |
| 102 | - /// Hand `chunk` to the file. Overrunning `expected` is a caller bug (the | |
| 103 | - /// count and the writer disagree) and aborts just as loudly as a short | |
| 104 | - /// write, because one of the two is certainly lying. | |
| 105 | - pub fn write(&mut self, chunk: &[u8]) { | |
| 106 | - if let Some(exp) = self.expected | |
| 107 | - && self.written + chunk.len() > exp | |
| 108 | - { | |
| 109 | - abort( | |
| 110 | - &self.site, | |
| 111 | - &self.path, | |
| 112 | - self.written, | |
| 113 | - Some(exp), | |
| 114 | - &format!( | |
| 115 | - "the writer was handed {} bytes but only {} remained of the {} it declared", | |
| 116 | - chunk.len(), | |
| 117 | - exp - self.written, | |
| 118 | - exp | |
| 119 | - ), | |
| 120 | - ); | |
| 121 | - } | |
| 122 | - let r = self.file.as_mut().expect("live dump").write_all(chunk); | |
| 123 | - if let Err(e) = r { | |
| 124 | - // MEASURED, do not assume: under `RLIMIT_FSIZE` the kernel stores | |
| 125 | - // everything up to the cap and THEN returns `EFBIG` (measured: | |
| 126 | - // a 49 152 B frame under caps of 4 KiB / 10 KiB / 30 KiB left | |
| 127 | - // 4 096 / 10 240 / 30 720 B on disk, with `write_all` confirming | |
| 128 | - // none of it). So "bytes written" on this line is the file's real | |
| 129 | - // length, not the count `write_all` got to acknowledge -- the | |
| 130 | - // acknowledged count rides along in the reason. | |
| 131 | - let f = self.file.as_ref().expect("live dump"); | |
| 132 | - let on_disk = f | |
| 133 | - .metadata() | |
| 134 | - .map(|m| m.len() as usize) | |
| 135 | - .unwrap_or(self.written); | |
| 136 | - abort( | |
| 137 | - &self.site, | |
| 138 | - &self.path, | |
| 139 | - on_disk, | |
| 140 | - self.expected, | |
| 141 | - &format!( | |
| 142 | - "write failed with {} bytes confirmed in hand: {e}", | |
| 143 | - self.written | |
| 144 | - ), | |
| 145 | - ); | |
| 146 | - } | |
| 147 | - self.written += chunk.len(); | |
| 148 | - } | |
| 149 | - | |
| 150 | - /// Close the dump: flush, then check the file's own length on disk. | |
| 151 | - /// | |
| 152 | - /// The on-disk check is not redundant with the write loop. `write_all` | |
| 153 | - /// reports what the FILE ACCEPTED, and the reader's question is what the | |
| 154 | - /// filesystem ended up holding -- a sparse/short final flush, a quota, or a | |
| 155 | - /// filesystem-level reservation failure all land here rather than in | |
| 156 | - /// `write`. | |
| 157 | - pub fn finish(mut self) { | |
| 158 | - let Some(mut file) = self.file.take() else { | |
| 159 | - return; | |
| 160 | - }; | |
| 161 | - if let Err(e) = file.flush() { | |
| 162 | - abort( | |
| 163 | - &self.site, | |
| 164 | - &self.path, | |
| 165 | - self.written, | |
| 166 | - self.expected, | |
| 167 | - &format!("flush failed after {} bytes: {e}", self.written), | |
| 168 | - ); | |
| 169 | - } | |
| 170 | - let Some(exp) = self.expected else { | |
| 171 | - return; | |
| 172 | - }; | |
| 173 | - let on_disk = match file.metadata() { | |
| 174 | - Ok(m) => m.len() as usize, | |
| 175 | - Err(e) => abort( | |
| 176 | - &self.site, | |
| 177 | - &self.path, | |
| 178 | - self.written, | |
| 179 | - Some(exp), | |
| 180 | - &format!("could not stat the finished dump: {e}"), | |
| 181 | - ), | |
| 182 | - }; | |
| 183 | - if on_disk != exp { | |
| 184 | - abort( | |
| 185 | - &self.site, | |
| 186 | - &self.path, | |
| 187 | - on_disk, | |
| 188 | - Some(exp), | |
| 189 | - "the file on disk is not the length the writer declared", | |
| 190 | - ); | |
| 191 | - } | |
| 192 | - } | |
| 193 | -} | |
| 194 | - | |
| 195 | -/// The single failure line every short dump now ends on. `site`, the path, the | |
| 196 | -/// bytes on disk vs the bytes owed, and the reason. | |
| 197 | -fn abort(site: &str, path: &Path, got: usize, expected: Option<usize>, why: &str) -> ! { | |
| 198 | - panic!("{}", failure_line(site, path, got, expected, why)); | |
| 199 | -} | |
| 200 | - | |
| 201 | -/// The failure line itself, so the fatal and the reporting shapes cannot | |
| 202 | -/// drift apart. | |
| 203 | -fn failure_line(site: &str, path: &Path, got: usize, expected: Option<usize>, why: &str) -> String { | |
| 204 | - let owed = match expected { | |
| 205 | - Some(e) => format!("{e}"), | |
| 206 | - None => "an unknown number of".to_string(), | |
| 207 | - }; | |
| 208 | - format!( | |
| 209 | - "ec-av1 dump FAILED [{}] {}: wrote {} of {} bytes: {}", | |
| 210 | - site, | |
| 211 | - path.display(), | |
| 212 | - got, | |
| 213 | - owed, | |
| 214 | - why | |
| 215 | - ) | |
| 216 | -} | |
| 217 | - | |
| 218 | -/// Write `bytes` to `path` as a FATAL pin: [`pin`] IS a wrapper -- three | |
| 219 | -/// [`LoudDump`] calls (`create`/`write`/`finish`), so it inherits the flush and | |
| 220 | -/// the flush-then-stat ordering for free. | |
| 221 | -/// | |
| 222 | -/// lane-av1pinloud: the test-pin sites in `stream.rs` wrote with | |
| 223 | -/// `let _ = std::fs::write(..)` and then named the path in the panic that | |
| 224 | -/// followed ("stream pinned at {}"), so an `ENOSPC`/`EFBIG` left a TRUNCATED | |
| 225 | -/// stream at exactly the path the reader was told to replay -- the same | |
| 226 | -/// silent-truncation class as the dump path, one hop later. Success path is | |
| 227 | -/// byte-identical: same bytes, same path, truncate-then-write. | |
| 228 | -pub fn pin(site: &str, path: impl AsRef<Path>, bytes: &[u8]) { | |
| 229 | - let mut d = LoudDump::create(site, path, bytes.len()); | |
| 230 | - d.write(bytes); | |
| 231 | - d.finish(); | |
| 232 | -} | |
| 233 | - | |
| 234 | -/// [`pin`]'s NON-FATAL twin, for a site that must not die on a failed pin -- a | |
| 235 | -/// gate whose real failure is the assert that comes after the pin attempt, and | |
| 236 | -/// whose comment says so. | |
| 237 | -/// | |
| 238 | -/// This one RE-IMPLEMENTS the check rather than wrapping [`LoudDump`], whose | |
| 239 | -/// failure channel is `panic!`: it cannot report instead of dying. So it does | |
| 240 | -/// `fs::write` + `metadata` itself. Only the failure LINE is shared, via | |
| 241 | -/// [`failure_line`] -- the ordering (flush-then-stat) and the | |
| 242 | -/// write-error-handling are not shared with [`LoudDump`], and a reader must not | |
| 243 | -/// assume they are. | |
| 244 | -/// | |
| 245 | -/// Non-fatal, but not silent: a shortfall comes back as the very same failure | |
| 246 | -/// line [`pin`] would have panicked with, expected-vs-on-disk counts included, | |
| 247 | -/// for the caller to print as a warning. | |
| 248 | -#[cfg(test)] // only the self-test below calls it; keeps the non-test build free of dead code | |
| 249 | -pub fn pin_reporting(site: &str, path: impl AsRef<Path>, bytes: &[u8]) -> Result<(), String> { | |
| 250 | - let path = path.as_ref(); | |
| 251 | - let expected = bytes.len(); | |
| 252 | - if let Err(e) = std::fs::write(path, bytes) { | |
| 253 | - let on_disk = std::fs::metadata(path) | |
| 254 | - .map(|m| m.len() as usize) | |
| 255 | - .unwrap_or(0); | |
| 256 | - return Err(failure_line( | |
| 257 | - site, | |
| 258 | - path, | |
| 259 | - on_disk, | |
| 260 | - Some(expected), | |
| 261 | - &format!("could not write the pin: {e}"), | |
| 262 | - )); | |
| 263 | - } | |
| 264 | - let on_disk = match std::fs::metadata(path) { | |
| 265 | - Ok(m) => m.len() as usize, | |
| 266 | - Err(e) => { | |
| 267 | - return Err(failure_line( | |
| 268 | - site, | |
| 269 | - path, | |
| 270 | - expected, | |
| 271 | - Some(expected), | |
| 272 | - &format!("could not stat the written pin: {e}"), | |
| 273 | - )); | |
| 274 | - } | |
| 275 | - }; | |
| 276 | - if on_disk != expected { | |
| 277 | - return Err(failure_line( | |
| 278 | - site, | |
| 279 | - path, | |
| 280 | - on_disk, | |
| 281 | - Some(expected), | |
| 282 | - "the pinned file on disk is not the length of the stream", | |
| 283 | - )); | |
| 284 | - } | |
| 285 | - Ok(()) | |
| 286 | -} | |
| 287 | - | |
| 288 | -/// Write `planes` (already narrowed to their dump's sample width) as ONE dump | |
| 289 | -/// file, failing loudly on any shortfall. `expected` is the sum of the plane | |
| 290 | -/// lengths -- the same extents the writer iterates, so a plane that is shorter | |
| 291 | -/// than its geometry claims cannot hide here. | |
| 292 | -pub fn write_planes(site: &str, path: impl AsRef<Path>, planes: &[&[u8]]) { | |
| 293 | - let expected: usize = planes.iter().map(|p| p.len()).sum(); | |
| 294 | - let mut d = LoudDump::create(site, path, expected); | |
| 295 | - for p in planes { | |
| 296 | - d.write(p); | |
| 297 | - } | |
| 298 | - d.finish(); | |
| 299 | -} | |
| 300 | - | |
| 301 | -#[cfg(test)] | |
| 302 | -mod tests { | |
| 303 | - use super::*; | |
| 304 | - use std::process::Command; | |
| 305 | - | |
| 306 | - fn scratch(tag: &str) -> PathBuf { | |
| 307 | - let p = std::env::temp_dir().join(format!("ec-av1-dumpio-{tag}-{}", std::process::id())); | |
| 308 | - let _ = std::fs::remove_file(&p); | |
| 309 | - p | |
| 310 | - } | |
| 311 | - | |
| 312 | - fn caught(f: impl FnOnce() + std::panic::UnwindSafe) -> String { | |
| 313 | - let prev = std::panic::take_hook(); | |
| 314 | - std::panic::set_hook(Box::new(|_| {})); | |
| 315 | - let r = std::panic::catch_unwind(f); | |
| 316 | - std::panic::set_hook(prev); | |
| 317 | - let e = r.expect_err("the short dump must abort"); | |
| 318 | - e.downcast_ref::<String>() | |
| 319 | - .cloned() | |
| 320 | - .or_else(|| e.downcast_ref::<&str>().map(|s| (*s).to_string())) | |
| 321 | - .expect("panic payload is a string") | |
| 322 | - } | |
| 323 | - | |
| 324 | - #[test] | |
| 325 | - fn success_path_is_byte_identical_to_the_old_write_all_loop() { | |
| 326 | - let p = scratch("ok"); | |
| 327 | - let planes: [&[u8]; 3] = [b"abc", b"", b"de"]; | |
| 328 | - write_planes("T", &p, &planes); | |
| 329 | - assert_eq!(std::fs::read(&p).unwrap(), b"abcde"); | |
| 330 | - let _ = std::fs::remove_file(&p); | |
| 331 | - } | |
| 332 | - | |
| 333 | - /// `/dev/full` accepts an `open` for write and returns `ENOSPC` from every | |
| 334 | - /// write -- the hermetic stand-in for the full filesystem that produced the | |
| 335 | - /// 13 320 192-byte truncated frame in `lanes/unwritten-dep.report.md`. | |
| 336 | - #[test] | |
| 337 | - #[cfg(unix)] | |
| 338 | - fn full_device_short_write_is_loud() { | |
| 339 | - let msg = caught(|| write_planes("EC_AV1_FINAL_DUMP", "/dev/full", &[b"abc", b"de"])); | |
| 340 | - assert!( | |
| 341 | - msg.starts_with("ec-av1 dump FAILED [EC_AV1_FINAL_DUMP] /dev/full: wrote "), | |
| 342 | - "{msg}" | |
| 343 | - ); | |
| 344 | - assert!(msg.contains("No space left on device"), "{msg}"); | |
| 345 | - // The counts must be there, or the line does not say what was lost. | |
| 346 | - assert!(msg.contains(" of 5 bytes"), "{msg}"); | |
| 347 | - } | |
| 348 | - | |
| 349 | - #[test] | |
| 350 | - fn uncreatable_dump_is_loud() { | |
| 351 | - let p = std::env::temp_dir().join(format!("ec-av1-nodir-{}/x", std::process::id())); | |
| 352 | - let msg = caught(|| write_planes("T", &p, &[b"abc"])); | |
| 353 | - assert!(msg.contains("could not create the dump file"), "{msg}"); | |
| 354 | - } | |
| 355 | - | |
| 356 | - /// A writer that under-declares its own expected length is the same silent | |
| 357 | - /// hole: the reader gets a file the site believes is complete. | |
| 358 | - #[test] | |
| 359 | - fn under_declared_expected_length_is_loud() { | |
| 360 | - let p = scratch("under"); | |
| 361 | - let msg = caught(|| { | |
| 362 | - let mut d = LoudDump::create("T", &p, 2); | |
| 363 | - d.write(b"abcdef"); | |
| 364 | - d.finish(); | |
| 365 | - }); | |
| 366 | - assert!( | |
| 367 | - msg.contains("was handed 6 bytes but only 2 remained of the 2 it declared"), | |
| 368 | - "{msg}" | |
| 369 | - ); | |
| 370 | - let _ = std::fs::remove_file(&p); | |
| 371 | - } | |
| 372 | - | |
| 373 | - #[test] | |
| 374 | - fn append_unknown_takes_no_length_claim() { | |
| 375 | - let p = scratch("append"); | |
| 376 | - { | |
| 377 | - let mut a = LoudDump::append_unknown("T", &p); | |
| 378 | - a.write(b"x"); | |
| 379 | - a.finish(); | |
| 380 | - let mut b = LoudDump::append_unknown("T", &p); | |
| 381 | - b.write(b"y"); | |
| 382 | - b.finish(); | |
| 383 | - } | |
| 384 | - assert_eq!(std::fs::read(&p).unwrap(), b"xy"); | |
| 385 | - let msg = caught(|| { | |
| 386 | - let mut a = LoudDump::append_unknown("T", "/dev/full"); | |
| 387 | - a.write(b"x"); | |
| 388 | - a.finish(); | |
| 389 | - }); | |
| 390 | - assert!(msg.contains("of an unknown number of bytes"), "{msg}"); | |
| 391 | - let _ = std::fs::remove_file(&p); | |
| 392 | - } | |
| 393 | - /// THE reproduction of the incident this module exists for: a real decode, | |
| 394 | - /// a real `RLIMIT_FSIZE`, a real truncated `EC_AV1_FINAL_DUMP` file left | |
| 395 | - /// on disk -- and the run stopping with the bytes-vs-bytes line instead of | |
| 396 | - /// carrying on to a measurement built on the fragment. | |
| 397 | - /// | |
| 398 | - /// `/dev/full` (the unit test above) proves the writer's check works but | |
| 399 | - /// never leaves a partial file behind, because `create` on it succeeds and | |
| 400 | - /// nothing is ever stored. `RLIMIT_FSIZE` is the shape | |
| 401 | - /// `lanes/unwritten-dep.report.md` actually measured: frames 0..4 complete | |
| 402 | - /// plus 13 320 192 bytes of frame 5. `SIGXFSZ` is IGNORED (`trap "" XFSZ`) | |
| 403 | - /// so the limit surfaces as `write`'s `EFBIG` -- exactly what a full | |
| 404 | - /// filesystem's `ENOSPC` does -- instead of killing the child outright. | |
| 405 | - #[test] | |
| 406 | - #[cfg(unix)] | |
| 407 | - fn a_real_decode_under_a_file_size_cap_fails_loudly() { | |
| 408 | - let dir = std::env::temp_dir().join(format!("ec-av1-dumpio-cap-{}", std::process::id())); | |
| 409 | - let _ = std::fs::remove_dir_all(&dir); | |
| 410 | - std::fs::create_dir_all(&dir).unwrap(); | |
| 411 | - let prefix = dir.join("ours"); | |
| 412 | - // 8 blocks of 512 B = 4096 B: far below one 256x128 4:2:0 8-bit frame | |
| 413 | - // (49 152 B), far above the file header, so the write lands and fails | |
| 414 | - // PART way rather than at create. | |
| 415 | - let out = Command::new("bash") | |
| 416 | - .args([ | |
| 417 | - "-c", | |
| 418 | - "ulimit -f 8; trap \"\" XFSZ; exec \"$0\" \"$@\"", | |
| 419 | - // $0 for `bash -c` is the test binary itself. | |
| 420 | - std::env::current_exe().unwrap().to_str().unwrap(), | |
| 421 | - "--exact", | |
| 422 | - "dumpio::tests::dumpio_child_decode", | |
| 423 | - "--nocapture", | |
| 424 | - ]) | |
| 425 | - .env("EC_AV1_DUMPLOUD_CHILD", "1") | |
| 426 | - .env("EC_AV1_FINAL_DUMP", &prefix) | |
| 427 | - // One thread, so the dump panic lands on the main thread and the | |
| 428 | - // child's exit status is the decode's own. | |
| 429 | - .env("EC_AV1_THREADS", "1") | |
| 430 | - .output() | |
| 431 | - .expect("spawning the capped child"); | |
| 432 | - let stderr = String::from_utf8_lossy(&out.stderr); | |
| 433 | - assert!( | |
| 434 | - !out.status.success(), | |
| 435 | - "the decode must FAIL under a file-size cap, not finish with a truncated dump\n{stderr}" | |
| 436 | - ); | |
| 437 | - assert!( | |
| 438 | - stderr.contains("ec-av1 dump FAILED [EC_AV1_FINAL_DUMP]"), | |
| 439 | - "the failure line must name the dump site\n{stderr}" | |
| 440 | - ); | |
| 441 | - assert!( | |
| 442 | - stderr.contains("File too large"), | |
| 443 | - "the failure line must carry the OS error\n{stderr}" | |
| 444 | - ); | |
| 445 | - // One 256x128 4:2:0 8-bit frame is 256*128*3/2 = 49 152 B, and the | |
| 446 | - // failure line's "wrote N of 49152" must name the file's REAL length, | |
| 447 | - // not the count `write_all` managed to acknowledge: a line that | |
| 448 | - // under-reports is a line that sends the reader back to the dump to | |
| 449 | - // measure it themselves. | |
| 450 | - let frag = std::fs::metadata(format!("{}.f0", prefix.display())) | |
| 451 | - .unwrap() | |
| 452 | - .len(); | |
| 453 | - assert!( | |
| 454 | - frag < 49152, | |
| 455 | - "the capped child left a {frag}-byte frame where 49152 B was owed" | |
| 456 | - ); | |
| 457 | - assert!( | |
| 458 | - stderr.contains(&format!("wrote {frag} of 49152 bytes")), | |
| 459 | - "the failure line's written count must be the file's actual length ({frag})\n{stderr}" | |
| 460 | - ); | |
| 461 | - let _ = std::fs::remove_dir_all(&dir); | |
| 462 | - } | |
| 463 | - | |
| 464 | - /// Child half of [`a_real_decode_under_a_file_size_cap_fails_loudly`]. It is | |
| 465 | - /// not a gate: with no `EC_AV1_DUMPLOUD_CHILD` guard it decodes nothing and | |
| 466 | - /// asserts nothing, so a plain `cargo test` run is unaffected. | |
| 467 | - #[test] | |
| 468 | - fn dumpio_child_decode() { | |
| 469 | - if std::env::var("EC_AV1_DUMPLOUD_CHILD").is_err() { | |
| 470 | - return; | |
| 471 | - } | |
| 472 | - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 473 | - .join("fixtures/420_mixll_256x128_6f.obu"); | |
| 474 | - let bytes = std::fs::read(&path).expect("the pinned fixture"); | |
| 475 | - let _ = crate::stream::decode_stream(&bytes); | |
| 476 | - } | |
| 477 | - | |
| 478 | - #[test] | |
| 479 | - fn pin_success_path_is_byte_identical() { | |
| 480 | - let p = scratch("pin-ok"); | |
| 481 | - pin("TEST_PIN", &p, b"stream bytes"); | |
| 482 | - assert_eq!(std::fs::read(&p).unwrap(), b"stream bytes"); | |
| 483 | - let _ = std::fs::remove_file(&p); | |
| 484 | - } | |
| 485 | - | |
| 486 | - #[test] | |
| 487 | - #[cfg(unix)] | |
| 488 | - fn pin_to_a_full_device_is_loud() { | |
| 489 | - let msg = caught(|| pin("TEST_PIN", "/dev/full", b"stream bytes")); | |
| 490 | - assert!( | |
| 491 | - msg.starts_with("ec-av1 dump FAILED [TEST_PIN] /dev/full: wrote "), | |
| 492 | - "{msg}" | |
| 493 | - ); | |
| 494 | - assert!(msg.contains("No space left on device"), "{msg}"); | |
| 495 | - assert!(msg.contains(" of 12 bytes"), "{msg}"); | |
| 496 | - } | |
| 497 | - | |
| 498 | - /// The reporting shape: same failure line, returned instead of panicked, | |
| 499 | - /// so a gate whose real failure is the assert after the pin keeps that | |
| 500 | - /// assert -- but the reader still learns the pin is short. | |
| 501 | - #[test] | |
| 502 | - #[cfg(unix)] | |
| 503 | - fn pin_reporting_is_loud_but_not_fatal() { | |
| 504 | - let line = pin_reporting("TEST_PIN", "/dev/full", b"stream bytes").unwrap_err(); | |
| 505 | - assert!( | |
| 506 | - line.contains("ec-av1 dump FAILED [TEST_PIN] /dev/full"), | |
| 507 | - "{line}" | |
| 508 | - ); | |
| 509 | - assert!(line.contains(" of 12 bytes"), "{line}"); | |
| 510 | - let p = scratch("pin-reporting-ok"); | |
| 511 | - pin_reporting("TEST_PIN", &p, b"stream bytes").expect("a healthy pin reports nothing"); | |
| 512 | - assert_eq!(std::fs::read(&p).unwrap(), b"stream bytes"); | |
| 513 | - let _ = std::fs::remove_file(&p); | |
| 514 | - } | |
| 515 | - | |
| 516 | - /// The pin path's own reproduction: a real `RLIMIT_FSIZE` leaves a real | |
| 517 | - /// truncated stream at the path the panic names. Without the check the | |
| 518 | - /// reader replays the fragment and blames the decoder. | |
| 519 | - #[test] | |
| 520 | - #[cfg(unix)] | |
| 521 | - fn a_pin_under_a_file_size_cap_fails_loudly() { | |
| 522 | - let dir = std::env::temp_dir().join(format!("ec-av1-pin-cap-{}", std::process::id())); | |
| 523 | - let _ = std::fs::remove_dir_all(&dir); | |
| 524 | - std::fs::create_dir_all(&dir).unwrap(); | |
| 525 | - let out = Command::new("bash") | |
| 526 | - .args([ | |
| 527 | - "-c", | |
| 528 | - "ulimit -f 8; trap \"\" XFSZ; exec \"$0\" \"$@\"", | |
| 529 | - std::env::current_exe().unwrap().to_str().unwrap(), | |
| 530 | - "--exact", | |
| 531 | - "dumpio::tests::pin_child_under_cap", | |
| 532 | - "--nocapture", | |
| 533 | - ]) | |
| 534 | - .env("EC_AV1_PINLOUD_CHILD", &dir) | |
| 535 | - .output() | |
| 536 | - .expect("spawning the capped child"); | |
| 537 | - let stderr = String::from_utf8_lossy(&out.stderr); | |
| 538 | - assert!(!out.status.success(), "a short pin must fail\n{stderr}"); | |
| 539 | - assert!(stderr.contains("ec-av1 dump FAILED [TEST_PIN]"), "{stderr}"); | |
| 540 | - assert!(stderr.contains("File too large"), "{stderr}"); | |
| 541 | - let frag = std::fs::metadata(dir.join("cap-pinned.obu")).unwrap().len(); | |
| 542 | - assert!( | |
| 543 | - frag < 32768, | |
| 544 | - "the capped child left {frag} bytes where 32768 B was owed" | |
| 545 | - ); | |
| 546 | - assert!( | |
| 547 | - stderr.contains(&format!("wrote {frag} of 32768 bytes")), | |
| 548 | - "{stderr}" | |
| 549 | - ); | |
| 550 | - let _ = std::fs::remove_dir_all(&dir); | |
| 551 | - } | |
| 552 | - | |
| 553 | - /// Child half of [`a_pin_under_a_file_size_cap_fails_loudly`]. Not a gate: | |
| 554 | - /// with no `EC_AV1_PINLOUD_CHILD` set it writes nothing and asserts nothing. | |
| 555 | - #[test] | |
| 556 | - fn pin_child_under_cap() { | |
| 557 | - let Ok(dir) = std::env::var("EC_AV1_PINLOUD_CHILD") else { | |
| 558 | - return; | |
| 559 | - }; | |
| 560 | - // `ulimit -f 8` is 8 KiB, so 4x that is guaranteed to run PAST the cap | |
| 561 | - // (a write of exactly the cap size succeeds) and land a fragment. | |
| 562 | - pin( | |
| 563 | - "TEST_PIN", | |
| 564 | - Path::new(&dir).join("cap-pinned.obu"), | |
| 565 | - &[7u8; 32768], | |
| 566 | - ); | |
| 567 | - } | |
| 568 | -} |
crates/ec-av1/src/lib.rsmodified+0 -1
| @@ -28,7 +28,6 @@ pub mod census; | ||
| 28 | 28 | mod compound; |
| 29 | 29 | pub mod decode; |
| 30 | 30 | pub mod encode; |
| 31 | -mod dumpio; | |
| 32 | 31 | pub mod encoder; |
| 33 | 32 | #[doc(hidden)] |
| 34 | 33 | pub mod fault; |
crates/ec-av1/src/msac.rsmodified+0 -181
| @@ -144,9 +144,6 @@ impl SymbolEncoder { | ||
| 144 | 144 | /// shorter than a two-symbol alphabet's three entries. |
| 145 | 145 | pub fn symbol_fixed(&mut self, symbol: usize, cdf: &[u16]) { |
| 146 | 146 | assert!(cdf.len() >= 3, "a CDF covers at least two symbols"); |
| 147 | - if !self.pricing && symtrace::dir().is_some() { | |
| 148 | - symtrace::push(symbol, cdf.len() - 1, cdf[0]); | |
| 149 | - } | |
| 150 | 147 | let nsyms = cdf.len() - 1; |
| 151 | 148 | assert!(symbol < nsyms, "symbol {symbol} is outside the alphabet"); |
| 152 | 149 | |
| @@ -204,7 +201,6 @@ impl SymbolEncoder { | ||
| 204 | 201 | /// payload end on a byte boundary with no terminator. |
| 205 | 202 | pub fn finish(mut self) -> Vec<u8> { |
| 206 | 203 | assert!(!self.pricing, "a pricer holds no bytes to flush"); |
| 207 | - symtrace::flush('w'); | |
| 208 | 204 | // Round the interval's low end up to a value with 14 low zero bits, |
| 209 | 205 | // then set bit 14: the result is inside the interval (the interval is |
| 210 | 206 | // at least 2^15 wide before normalisation) and its tail bits are all |
| @@ -317,7 +313,6 @@ pub struct SymbolDecoder<'a> { | ||
| 317 | 313 | |
| 318 | 314 | impl Drop for SymbolDecoder<'_> { |
| 319 | 315 | fn drop(&mut self) { |
| 320 | - symtrace::flush('r'); | |
| 321 | 316 | } |
| 322 | 317 | } |
| 323 | 318 | |
| @@ -517,20 +512,12 @@ impl<'a> SymbolDecoder<'a> { | ||
| 517 | 512 | /// [`SymbolEncoder::symbol_fixed`]. |
| 518 | 513 | #[inline] |
| 519 | 514 | pub fn symbol_fixed(&mut self, cdf: &[u16]) -> usize { |
| 520 | - if symtrace::dir().is_some() { | |
| 521 | - let s = self.symbol_fixed_raw(cdf); | |
| 522 | - symtrace::push(s, cdf.len() - 1, cdf[0]); | |
| 523 | - return s; | |
| 524 | - } | |
| 525 | 515 | self.symbol_fixed_raw(cdf) |
| 526 | 516 | } |
| 527 | 517 | |
| 528 | 518 | #[inline] |
| 529 | 519 | fn symbol_fixed_raw(&mut self, cdf: &[u16]) -> usize { |
| 530 | 520 | let nsyms = cdf.len() - 1; |
| 531 | - if symtrace::ecdump_armed() { | |
| 532 | - symtrace::ecdump(0, self.value, self.range, self.bit as i64); | |
| 533 | - } | |
| 534 | 521 | // Two-symbol alphabets are most of the stream (every flag, every bit of |
| 535 | 522 | // a literal), and their walk has exactly one boundary: computing it |
| 536 | 523 | // straight skips the loop and its bounds work. |
| @@ -627,9 +614,6 @@ impl<'a> SymbolDecoder<'a> { | ||
| 627 | 614 | // the range multiply is a shift. |
| 628 | 615 | let cur = ((self.range >> 8) << 7) + EC_MIN_PROB; |
| 629 | 616 | let bit = self.bool_cur(cur); |
| 630 | - if symtrace::dir().is_some() { | |
| 631 | - symtrace::push(bit, 2, EQUIPROBABLE[0]); | |
| 632 | - } | |
| 633 | 617 | v = (v << 1) | bit as u32; |
| 634 | 618 | } |
| 635 | 619 | v |
| @@ -982,168 +966,3 @@ pub(crate) mod tests { | ||
| 982 | 966 | } |
| 983 | 967 | } |
| 984 | 968 | |
| 985 | -/// Symbol-by-symbol writer/reader trace (`EC_AV1_SYMTRACE=<dir>`), the | |
| 986 | -/// instrument a desync between OUR writer and OUR reader is bisected with: | |
| 987 | -/// every non-pricing [`SymbolEncoder`] and every [`SymbolDecoder`] dumps one | |
| 988 | -/// line per symbol (`index value nsyms cdf0`) into `<dir>/w-<n>.txt` / | |
| 989 | -/// `<dir>/r-<n>.txt`, and the first line where the two differ names the | |
| 990 | -/// divergent symbol. `EC_AV1_SYMTRACE_AT=<index>` additionally prints a | |
| 991 | -/// backtrace at that index on both sides, which names the syntax element. | |
| 992 | -/// Off (the variable unset) this is one relaxed load per symbol. | |
| 993 | -pub(crate) mod symtrace { | |
| 994 | - use std::cell::RefCell; | |
| 995 | - use std::collections::VecDeque; | |
| 996 | - use std::sync::OnceLock; | |
| 997 | - | |
| 998 | - static DIR: OnceLock<Option<String>> = OnceLock::new(); | |
| 999 | - static AT: OnceLock<Option<(usize, usize)>> = OnceLock::new(); | |
| 1000 | - static SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 1001 | - | |
| 1002 | - thread_local! { | |
| 1003 | - static BUF: RefCell<(String, usize)> = const { RefCell::new((String::new(), 0)) }; | |
| 1004 | - static ECD: RefCell<VecDeque<(u32, u32, u32, u32)>> = const { RefCell::new(VecDeque::new()) }; | |
| 1005 | - // lane-av1dumploud: the file's PATH travels with it, so a short write | |
| 1006 | - // can name the file it truncated instead of reconstructing a name. | |
| 1007 | - static ECD_READER: RefCell<Option<(std::fs::File, String)>> = const { RefCell::new(None) }; | |
| 1008 | - static ECD_IDX: RefCell<usize> = const { RefCell::new(0) }; | |
| 1009 | - } | |
| 1010 | - | |
| 1011 | - /// lane-av1mix: `(low, value, rng, bitpos)` state register dump, one line | |
| 1012 | - /// per symbol read, byte-for-byte diffable against libaom's `EC_ECDUMP` | |
| 1013 | - /// (`decodetxb.c`, `r->ec.dif` masked to 16 bits / `r->ec.rng` / | |
| 1014 | - /// `od_ec_dec_tell`). Reader-only, `EC_AV1_ECDUMP=<dir>`: each reader | |
| 1015 | - /// writes `<dir>/ecdump-<n>.txt`. | |
| 1016 | - pub(crate) fn ecdump(low: u32, value: u32, rng: u32, bitpos: i64) { | |
| 1017 | - if !ecdump_armed() { | |
| 1018 | - return; | |
| 1019 | - } | |
| 1020 | - let dir = std::env::var("EC_AV1_ECDUMP").unwrap_or_else(|_| "/tmp".to_string()); | |
| 1021 | - let idx = ECD_IDX.with(|c| { | |
| 1022 | - let mut g = c.borrow_mut(); | |
| 1023 | - let n = *g; | |
| 1024 | - *g += 1; | |
| 1025 | - n | |
| 1026 | - }); | |
| 1027 | - let _ = idx; | |
| 1028 | - let line = format!("{idx} ({low},{value},{rng},{bitpos})\n"); | |
| 1029 | - ECD_READER.with(|f| { | |
| 1030 | - use std::io::Write; | |
| 1031 | - let mut slot = f.borrow_mut(); | |
| 1032 | - if slot.is_none() { | |
| 1033 | - let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 1034 | - let path = format!("{dir}/ecdump-{seq:05}.txt"); | |
| 1035 | - eprintln!("ECDUMP -> {path}"); | |
| 1036 | - *slot = Some((std::fs::File::create(&path).expect("ecdump file"), path)); | |
| 1037 | - } | |
| 1038 | - // lane-av1dumploud: loud on a short write. This file is one line | |
| 1039 | - // per symbol for a whole run, so its total length is unknowable at | |
| 1040 | - // open time -- the failure line says "an unknown number of" rather | |
| 1041 | - // than declaring a length it would have to invent. | |
| 1042 | - let (file, path) = slot.as_mut().expect("just opened"); | |
| 1043 | - if let Err(e) = file.write_all(line.as_bytes()) { | |
| 1044 | - panic!( | |
| 1045 | - "ec-av1 dump FAILED [EC_AV1_ECDUMP] {path}: \ | |
| 1046 | - write failed after a partial line of {} bytes: {e}", | |
| 1047 | - line.len() | |
| 1048 | - ); | |
| 1049 | - } | |
| 1050 | - }); | |
| 1051 | - ECD.with(|q| { | |
| 1052 | - let mut q = q.borrow_mut(); | |
| 1053 | - q.push_back((low, value, rng, bitpos as u32)); | |
| 1054 | - if q.len() > 512 { | |
| 1055 | - q.pop_front(); | |
| 1056 | - } | |
| 1057 | - }); | |
| 1058 | - } | |
| 1059 | - | |
| 1060 | - /// lane-av1mix: the last `n` dumped register states (most recent last). | |
| 1061 | - #[allow(dead_code)] // diagnostic helper for lane sessions | |
| 1062 | - pub(crate) fn ecdump_recent(n: usize) -> Vec<(u32, u32, u32, u32)> { | |
| 1063 | - if std::env::var_os("EC_AV1_ECDUMP").is_none() { | |
| 1064 | - return Vec::new(); | |
| 1065 | - } | |
| 1066 | - ECD.with(|q| { | |
| 1067 | - let q = q.borrow(); | |
| 1068 | - let skip = q.len().saturating_sub(n); | |
| 1069 | - q.iter().skip(skip).copied().collect() | |
| 1070 | - }) | |
| 1071 | - } | |
| 1072 | - | |
| 1073 | - pub(crate) fn dir() -> Option<&'static str> { | |
| 1074 | - DIR.get_or_init(|| { | |
| 1075 | - crate::envflags::var("EC_AV1_SYMTRACE") | |
| 1076 | - .ok() | |
| 1077 | - .filter(|v| !v.is_empty()) | |
| 1078 | - }) | |
| 1079 | - .as_deref() | |
| 1080 | - } | |
| 1081 | - | |
| 1082 | - /// lane-av1mix: `EC_AV1_ECDUMP=<dir>` arms the decoder state-register dump. | |
| 1083 | - pub(crate) fn ecdump_armed() -> bool { | |
| 1084 | - static ARMED: std::sync::LazyLock<bool> = | |
| 1085 | - std::sync::LazyLock::new(|| std::env::var_os("EC_AV1_ECDUMP").is_some()); | |
| 1086 | - *ARMED | |
| 1087 | - } | |
| 1088 | - | |
| 1089 | - /// `EC_AV1_SYMTRACE_AT=<i>` or `=<from>:<to>` (inclusive). | |
| 1090 | - fn at() -> Option<(usize, usize)> { | |
| 1091 | - *AT.get_or_init(|| { | |
| 1092 | - let v = crate::envflags::var("EC_AV1_SYMTRACE_AT").ok()?; | |
| 1093 | - let (a, b) = v.split_once(':').unwrap_or((v.as_str(), v.as_str())); | |
| 1094 | - Some((a.parse().ok()?, b.parse().ok()?)) | |
| 1095 | - }) | |
| 1096 | - } | |
| 1097 | - | |
| 1098 | - /// A caller's own annotation, interleaved with this coder's symbol lines | |
| 1099 | - /// (`# ...`) so the writer/reader diff shows the state around a desync. | |
| 1100 | - pub(crate) fn note(line: &str) { | |
| 1101 | - if dir().is_none() { | |
| 1102 | - return; | |
| 1103 | - } | |
| 1104 | - BUF.with(|b| { | |
| 1105 | - let (buf, _) = &mut *b.borrow_mut(); | |
| 1106 | - buf.push_str("# "); | |
| 1107 | - buf.push_str(line); | |
| 1108 | - buf.push('\n'); | |
| 1109 | - }); | |
| 1110 | - } | |
| 1111 | - | |
| 1112 | - pub(crate) fn push(value: usize, nsyms: usize, cdf0: u16) { | |
| 1113 | - BUF.with(|b| { | |
| 1114 | - let (buf, n) = &mut *b.borrow_mut(); | |
| 1115 | - if at().is_some_and(|(a, b)| (a..=b).contains(n)) { | |
| 1116 | - eprintln!( | |
| 1117 | - "SYMTRACE at {n}: {}", | |
| 1118 | - std::backtrace::Backtrace::force_capture() | |
| 1119 | - ); | |
| 1120 | - } | |
| 1121 | - buf.push_str(&format!("{n} {value} {nsyms} {cdf0}\n")); | |
| 1122 | - *n += 1; | |
| 1123 | - }); | |
| 1124 | - } | |
| 1125 | - | |
| 1126 | - /// Flushes this coder's lines as `<dir>/<side>-<n>.txt` and starts the | |
| 1127 | - /// next coder's trace. | |
| 1128 | - pub(crate) fn flush(side: char) { | |
| 1129 | - let Some(dir) = dir() else { return }; | |
| 1130 | - BUF.with(|b| { | |
| 1131 | - let (buf, n) = &mut *b.borrow_mut(); | |
| 1132 | - if !buf.is_empty() { | |
| 1133 | - // lane-av1dumploud: loud on a short write. `std::fs::write` | |
| 1134 | - // returned a `Result` this used to discard, and the check was | |
| 1135 | - // hand-rolled against the buffer length only; lane-av1pinloud | |
| 1136 | - // folded it into the shared writer so this site also gets the | |
| 1137 | - // on-disk length check the dump path already had. | |
| 1138 | - let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 1139 | - crate::dumpio::pin( | |
| 1140 | - "EC_AV1_SYMTRACE", | |
| 1141 | - format!("{dir}/{side}-{seq:05}.txt"), | |
| 1142 | - buf.as_bytes(), | |
| 1143 | - ); | |
| 1144 | - } | |
| 1145 | - buf.clear(); | |
| 1146 | - *n = 0; | |
| 1147 | - }); | |
| 1148 | - } | |
| 1149 | -} |
crates/ec-av1/src/mvstack.rsmodified+0 -18
| @@ -1863,24 +1863,6 @@ pub fn find_mv_stack_with_sign_bias( | ||
| 1863 | 1863 | .checked_sub(1) |
| 1864 | 1864 | .is_some_and(|c| grid.skip_at(mi_row, c)); |
| 1865 | 1865 | |
| 1866 | - // lane-sb128b: the writer/reader stack diff instrument (`EC_AV1_MVDBG=1`) | |
| 1867 | - // -- one line per built stack, in build order, so the two sides' logs | |
| 1868 | - // diff to the first block whose candidate list differs. | |
| 1869 | - if crate::msac::symtrace::dir().is_some() { | |
| 1870 | - crate::msac::symtrace::note(&format!( | |
| 1871 | - "MVDBG mi=({mi_row},{mi_col}) b=({bw4}x{bh4}) ref={ref_frame} n={} mv={:?}", | |
| 1872 | - candidates.len(), | |
| 1873 | - candidates.iter().map(|e| (e.mv, e.weight)).collect::<Vec<_>>(), | |
| 1874 | - )); | |
| 1875 | - let row = mi_row.checked_sub(1).map(|r| { | |
| 1876 | - (mi_col..mi_col + bw4).map(|c| grid.get(r, c).map(|m| (m.ref_frame, m.mv))).collect::<Vec<_>>() | |
| 1877 | - }); | |
| 1878 | - let col = mi_col.checked_sub(1).map(|c| { | |
| 1879 | - (mi_row..mi_row + bh4).map(|r| grid.get(r, c).map(|m| (m.ref_frame, m.mv))).collect::<Vec<_>>() | |
| 1880 | - }); | |
| 1881 | - crate::msac::symtrace::note(&format!(" above={row:?}")); | |
| 1882 | - crate::msac::symtrace::note(&format!(" left={col:?}")); | |
| 1883 | - } | |
| 1884 | 1866 | MvStack { |
| 1885 | 1867 | entries: candidates, |
| 1886 | 1868 | nearest_mv, |
crates/ec-av1/src/stream/mod.rsmodified+0 -103
| @@ -36,29 +36,7 @@ fn no_grain() -> bool { | ||
| 36 | 36 | std::env::var_os("EC_AV1_NO_GRAIN").is_some() |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -// lane-hidden r1: where `EC_AV1_FINAL_DUMP`'s per-frame dump goes for the | |
| 40 | -// current thread, overriding the environment variable. Every ffmpeg/aomdec | |
| 41 | -// pixel gate in this repo compares SHOWN frames only (class | |
| 42 | -// gate-blind-to-hidden-frames), so the hidden alt-ref frames a real aomenc | |
| 43 | -// stream carries were never compared at all; the gate that does compare | |
| 44 | -// them needs a dump path that cannot race a sibling test's decode on | |
| 45 | -// another thread, which a process-global env var cannot give. | |
| 46 | -thread_local! { | |
| 47 | - static FINAL_DUMP_PREFIX: std::cell::RefCell<Option<String>> = | |
| 48 | - const { std::cell::RefCell::new(None) }; | |
| 49 | -} | |
| 50 | - | |
| 51 | -/// Sets (or with `None` clears) this thread's `EC_AV1_FINAL_DUMP` prefix. | |
| 52 | -#[allow(dead_code)] | |
| 53 | -pub(crate) fn set_final_dump_prefix(prefix: Option<String>) { | |
| 54 | - FINAL_DUMP_PREFIX.with(|c| *c.borrow_mut() = prefix); | |
| 55 | -} | |
| 56 | 39 | |
| 57 | -fn final_dump_prefix() -> Option<String> { | |
| 58 | - FINAL_DUMP_PREFIX | |
| 59 | - .with(|c| c.borrow().clone()) | |
| 60 | - .or_else(|| std::env::var("EC_AV1_FINAL_DUMP").ok()) | |
| 61 | -} | |
| 62 | 40 | |
| 63 | 41 | /// 32x32-level 1:4 strip counters, for `decode_probe`'s fixture search: |
| 64 | 42 | /// (HORZ_4 strips, VERT_4 strips, strips that read coefficients). |
| @@ -855,7 +833,6 @@ fn collect_one( | ||
| 855 | 833 | /// A persistent AV1 stream decoder: feed it temporal units in decode order. |
| 856 | 834 | pub struct StreamDecoder { |
| 857 | 835 | threads: usize, |
| 858 | - final_dump: Option<String>, | |
| 859 | 836 | parser: Av1Parser, |
| 860 | 837 | pictures_shown: usize, |
| 861 | 838 | pictures_decoded: usize, |
| @@ -935,7 +912,6 @@ impl StreamDecoder { | ||
| 935 | 912 | let (tx, rx) = std::sync::mpsc::channel::<LeafResult>(); |
| 936 | 913 | Self { |
| 937 | 914 | threads, |
| 938 | - final_dump: final_dump_prefix(), | |
| 939 | 915 | parser: Av1Parser::new(), |
| 940 | 916 | pictures_shown: 0, |
| 941 | 917 | pictures_decoded: 0, |
| @@ -995,7 +971,6 @@ impl StreamDecoder { | ||
| 995 | 971 | let mut pending_tiles = std::mem::take(&mut self.pending_tiles); |
| 996 | 972 | let threads = self.threads; |
| 997 | 973 | let StreamDecoder { |
| 998 | - final_dump, | |
| 999 | 974 | parser, |
| 1000 | 975 | ref_slots, |
| 1001 | 976 | motion_field_slots, |
| @@ -1328,7 +1303,6 @@ impl StreamDecoder { | ||
| 1328 | 1303 | pictures_shown += 1; |
| 1329 | 1304 | } |
| 1330 | 1305 | let tx = tx.clone(); |
| 1331 | - let dump = final_dump.clone(); | |
| 1332 | 1306 | crate::timeline::submit(decode_idx, if shown { 'P' } else { 'A' }, shown); |
| 1333 | 1307 | // The job outlives this call, so it owns its tile bytes (a copy of |
| 1334 | 1308 | // this frame's compressed tiles) instead of borrowing `data`. |
| @@ -1490,7 +1464,6 @@ impl StreamDecoder { | ||
| 1490 | 1464 | snap, |
| 1491 | 1465 | decode_idx, |
| 1492 | 1466 | shown_idx, |
| 1493 | - dump.as_deref(), | |
| 1494 | 1467 | // lane-twostage publishes a frame's meta at its tile |
| 1495 | 1468 | // boundary instead of after its filters, so a consumer |
| 1496 | 1469 | // parses over its producer's filter tail. It is ON by |
| @@ -1602,7 +1575,6 @@ impl StreamDecoder { | ||
| 1602 | 1575 | snap, |
| 1603 | 1576 | pictures_decoded, |
| 1604 | 1577 | pictures_shown, |
| 1605 | - final_dump.as_deref(), | |
| 1606 | 1578 | None, |
| 1607 | 1579 | )?; |
| 1608 | 1580 | let motion_field = motion_field.expect("the inline path passes no stage-1 sink"); |
| @@ -1909,7 +1881,6 @@ fn decode_frame( | ||
| 1909 | 1881 | snap: RefSnapshot<'_>, |
| 1910 | 1882 | decode_idx: usize, |
| 1911 | 1883 | shown_idx: usize, |
| 1912 | - final_dump: Option<&str>, | |
| 1913 | 1884 | // lane-twostage: see `decode_inter_frame_tile_with_cdfs`'s own `stage1`. |
| 1914 | 1885 | stage1: Option<&dyn Fn(Cdfs, crate::motion_field::MotionField, usize, usize)>, |
| 1915 | 1886 | ) -> Result<FrameOutput> { |
| @@ -2533,54 +2504,6 @@ fn decode_frame( | ||
| 2533 | 2504 | // *initial* table into the slots it refreshes, not the adapted |
| 2534 | 2505 | // end-of-tile one. |
| 2535 | 2506 | let stored_cdfs = stored_cdfs_for(header, end_cdfs, started_from); |
| 2536 | - if let Ok(path) = std::env::var("EC_AV1_DUMP_TABLES") { | |
| 2537 | - // lane-av1dumploud: loud on a short write. This one is APPEND-mode and | |
| 2538 | - // spans every frame of a run, so there is no total length to declare | |
| 2539 | - // (`append_unknown` says so on the failure line rather than guessing | |
| 2540 | - // one); the per-line writes are still checked, so an ENOSPC halfway | |
| 2541 | - // through a table no longer passes as a complete one. | |
| 2542 | - let mut f = crate::dumpio::LoudDump::append_unknown("EC_AV1_DUMP_TABLES", &path); | |
| 2543 | - let mut line = |s: String| f.write(s.as_bytes()); | |
| 2544 | - line(format!("=== frame idx={shown_idx} ===\n")); | |
| 2545 | - line(format!("partition_w64 {:?}\n", stored_cdfs.partition_w64)); | |
| 2546 | - line(format!("partition_w32 {:?}\n", stored_cdfs.partition_w32)); | |
| 2547 | - line(format!("partition_w16 {:?}\n", stored_cdfs.partition_w16)); | |
| 2548 | - line(format!("skip {:?}\n", stored_cdfs.skip)); | |
| 2549 | - line(format!("new_mv {:?}\n", stored_cdfs.new_mv)); | |
| 2550 | - line(format!("zero_mv {:?}\n", stored_cdfs.zero_mv)); | |
| 2551 | - line(format!("ref_mv {:?}\n", stored_cdfs.ref_mv)); | |
| 2552 | - line(format!("mv_joint {:?}\n", stored_cdfs.mv_joint)); | |
| 2553 | - f.finish(); | |
| 2554 | - } | |
| 2555 | - // lane-comppin r3: decode-order (not display-order) dump of every | |
| 2556 | - // frame's own post-deblock buffer -- the pre-existing pixel diff | |
| 2557 | - // (`scratch_isolate_pinned_mismatch`) only ever compares *shown* | |
| 2558 | - // frames, so a hidden reference (altref/bwdref) that DPB-corrupts a | |
| 2559 | - // later shown frame is otherwise invisible; diff this byte-for-byte | |
| 2560 | - // against `EC_AV1_POSTDEBLOCK_DUMP.fN` from the instrumented aomdec build | |
| 2561 | - // (rung 6, `scripts/instrument-aom-oracle.sh`; 1 byte per sample, so it is | |
| 2562 | - // byte-comparable only at 8-bit -- for HBD use rung 12 `EC_AV1_FINAL_DUMP`) | |
| 2563 | - // to isolate whether the defect is in a hidden frame's own | |
| 2564 | - // reconstruction or downstream of it. | |
| 2565 | - if let Ok(path) = std::env::var("EC_AV1_DECODE_ORDER_DUMP") { | |
| 2566 | - // lane-hbd r4: debug dump narrows to u8 -- this diagnostic | |
| 2567 | - // predates 10-bit support and is an 8-bit-oracle comparison | |
| 2568 | - // only (aomdec's own dump is 8-bit here too). | |
| 2569 | - // | |
| 2570 | - // lane-av1dumploud: loud on a short write; expected length is the three | |
| 2571 | - // planes' own lengths (narrowing is 1 byte per sample, so the count is | |
| 2572 | - // unchanged). | |
| 2573 | - let narrow = |v: &[u16]| -> Vec<u8> { v.iter().map(|&s| s as u8).collect() }; | |
| 2574 | - crate::dumpio::write_planes( | |
| 2575 | - "EC_AV1_DECODE_ORDER_DUMP", | |
| 2576 | - format!("{path}.f{decode_idx}"), | |
| 2577 | - &[ | |
| 2578 | - &narrow(&picture.y), | |
| 2579 | - &narrow(&picture.u), | |
| 2580 | - &narrow(&picture.v), | |
| 2581 | - ], | |
| 2582 | - ); | |
| 2583 | - } | |
| 2584 | 2507 | // lane-hidden r1: the frame exactly as it is about to be stored into |
| 2585 | 2508 | // the reference slots -- after deblock/CDEF/LR/superres, in DECODE |
| 2586 | 2509 | // order, hidden (`show_frame == 0`) alt-ref frames included, and |
| @@ -2621,32 +2544,6 @@ fn decode_frame( | ||
| 2621 | 2544 | // caller receives is censused by `decode::census_unwritten_grained`, at |
| 2622 | 2545 | // `apply_grain`'s own return, over its own counters. |
| 2623 | 2546 | decode::census_unwritten_final(&picture.y, &picture.u, &picture.v); |
| 2624 | - if let Some(prefix) = final_dump { | |
| 2625 | - // lane-av1dumploud: this is the site that produced the 13 320 192-byte | |
| 2626 | - // truncated frame in `lanes/unwritten-dep.report.md` -- `let _ = | |
| 2627 | - // f.write_all(&buf)` swallowed the ENOSPC. Expected length is derived | |
| 2628 | - // from the PLANES and the sample width, independently of `buf`, so a | |
| 2629 | - // writer that builds the wrong buffer still gets caught. | |
| 2630 | - let sample_width = if bit_depth == 8 { 1 } else { 2 }; | |
| 2631 | - let expected = (picture.y.len() + picture.u.len() + picture.v.len()) * sample_width; | |
| 2632 | - let mut f = crate::dumpio::LoudDump::create( | |
| 2633 | - "EC_AV1_FINAL_DUMP", | |
| 2634 | - format!("{prefix}.f{decode_idx}"), | |
| 2635 | - expected, | |
| 2636 | - ); | |
| 2637 | - for plane in [&picture.y, &picture.u, &picture.v] { | |
| 2638 | - if bit_depth == 8 { | |
| 2639 | - f.write(&plane.iter().map(|&s| s as u8).collect::<Vec<u8>>()); | |
| 2640 | - } else { | |
| 2641 | - let mut row = Vec::with_capacity(plane.len() * 2); | |
| 2642 | - for &s in plane { | |
| 2643 | - row.extend_from_slice(&s.to_le_bytes()); | |
| 2644 | - } | |
| 2645 | - f.write(&row); | |
| 2646 | - } | |
| 2647 | - } | |
| 2648 | - f.finish(); | |
| 2649 | - } | |
| 2650 | 2547 | if let Some(why) = fctx.corrupt.get() { |
| 2651 | 2548 | return Err(Error::corrupt(format!("AV1 frame {decode_idx}: {why}"))); |
| 2652 | 2549 | } |
crates/ec-av1/src/tile/blocks.rsmodified+0 -12
| @@ -2771,12 +2771,6 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 2771 | 2771 | mi_rows as usize, |
| 2772 | 2772 | ); |
| 2773 | 2773 | let (mv, is_new_mv) = write_inter_mode(&mut enc, cdfs, info, &stack)?; |
| 2774 | - if crate::msac::symtrace::dir().is_some() { | |
| 2775 | - crate::msac::symtrace::note(&format!( | |
| 2776 | - " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}", | |
| 2777 | - info.mode, info.ref_mv_idx, info.mv | |
| 2778 | - )); | |
| 2779 | - } | |
| 2780 | 2774 | (mv, (0, 0), is_new_mv) |
| 2781 | 2775 | }; |
| 2782 | 2776 | for dr in 0..SB_MI as usize { |
| @@ -3202,12 +3196,6 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 3202 | 3196 | ); |
| 3203 | 3197 | |
| 3204 | 3198 | let (mv, is_new_mv) = write_inter_mode(&mut enc, cdfs, info, &stack)?; |
| 3205 | - if crate::msac::symtrace::dir().is_some() { | |
| 3206 | - crate::msac::symtrace::note(&format!( | |
| 3207 | - " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}", | |
| 3208 | - info.mode, info.ref_mv_idx, info.mv | |
| 3209 | - )); | |
| 3210 | - } | |
| 3211 | 3199 | grid.set( |
| 3212 | 3200 | mi_row, |
| 3213 | 3201 | mi_col, |