diff --git a/crates/ec-av1/src/decode/cdef.rs b/crates/ec-av1/src/decode/cdef.rs index b03c8644..173ebd96 100644 --- a/crates/ec-av1/src/decode/cdef.rs +++ b/crates/ec-av1/src/decode/cdef.rs @@ -35,9 +35,9 @@ fn cdef_msb(x: i32) -> i32 { 31 - x.leading_zeros() as i32 } +#[cfg(test)] /// Spec 7.15.3's `constrain`: how much of a neighbour's difference from the /// centre sample a filter tap is allowed to contribute. -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn cdef_constrain(diff: i32, threshold: i32, damping: i32) -> i32 { if threshold == 0 { return 0; diff --git a/crates/ec-av1/src/decode/coeffs.rs b/crates/ec-av1/src/decode/coeffs.rs index 47658cb8..6301eb0d 100644 --- a/crates/ec-av1/src/decode/coeffs.rs +++ b/crates/ec-av1/src/decode/coeffs.rs @@ -712,7 +712,6 @@ pub(super) struct Neighbours { pub(super) tile_col0_mi: usize, } -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates impl Neighbours { /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's /// true (unpadded) size in 4x4 mode-info units. @@ -1534,6 +1533,7 @@ impl Neighbours { self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT); } + #[cfg(test)] /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next /// block that reads it as a neighbour -- [`crate::tile`]'s /// `record_inter`. `filter` is `[3, 3]` for an intra block (spec @@ -1541,7 +1541,6 @@ impl Neighbours { /// "no neighbour"). `ref_frame` is `-1` for an intra block, else the /// `1..=7` reference it coded (lane-av1refs's `single_ref_p*_ctx` needs /// the real value, not just `is_inter`). - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] @@ -1558,13 +1557,13 @@ impl Neighbours { self.record_inter_rect(at, side, side, skip, is_inter, ref_frame, filter, skip_mode); } + #[cfg(test)] /// [`Self::record_inter`] with independent above (`w_sub`, [`SUB`]-grid /// columns) / left (`h_sub`, [`SUB`]-grid rows) extents -- lane-partitions /// r1: a true rectangular strip's above-context span (its own width) and /// left-context span (its own height) differ, unlike every caller before /// this round (class neighbour-votes-all-its-fields). #[allow(clippy::too_many_arguments)] - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn record_inter_rect( &mut self, at: (usize, usize), @@ -1653,6 +1652,7 @@ impl Neighbours { self.left_filter[r..r + h_mi].fill(filter); } + #[cfg(test)] /// Overwrites [`Self::record_inter`]'s ALTREF-special-case default with /// a real compound block's own `comp_group_idx`/`compound_idx` bits /// (libaom `has_second_ref(mbmi)` branch of `get_comp_group_idx_context`/ @@ -1663,7 +1663,6 @@ impl Neighbours { /// this is the one caller that actually knows it) -- so the next block's /// [`NeighbourRef`](crate::mvstack::NeighbourRef) sees a real compound /// neighbour instead of `record_inter`'s single-ref default. - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn record_compound_ctx( &mut self, at: (usize, usize), @@ -1675,10 +1674,10 @@ impl Neighbours { self.record_compound_ctx_rect(at, side, side, ref1, comp_group_idx, compound_idx); } + #[cfg(test)] /// [`Self::record_compound_ctx`] with independent above/left extents, /// mirroring [`Self::record_inter_rect`] (lane-partitions r1). #[allow(clippy::too_many_arguments)] - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn record_compound_ctx_rect( &mut self, at: (usize, usize), @@ -3378,26 +3377,11 @@ pub(super) fn read_tx_size( max_tx >> depth } -/// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's -/// `txfm_split` context -- a category from the block's own largest square -/// transform and whether this unit already sits below it, times three, plus -/// the two neighbour terms (whether the transform last written above/left of -/// this unit is narrower/shorter than the unit itself). -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(super) fn txfm_partition_ctx( - above_px: u8, - left_px: u8, - blk_max_px: usize, - tx_px: usize, -) -> usize { - txfm_partition_ctx_rect(above_px, left_px, blk_max_px, tx_px, tx_px) -} - -/// [`txfm_partition_ctx`] for a *rectangular* transform (lane-inter4 r2): +/// `txfm_partition_context` for a *rectangular* transform (lane-inter4 r2): /// libaom's `txfm_partition_context` compares the above context against /// `tx_size_wide` and the left one against `tx_size_high`, and takes its /// category from `txsize_sqr_up_map[tx_size]` -- all three collapse to one -/// side for a square transform, which is why the square form above is a +/// side for a square transform, which is why the square form is a /// special case of this one. pub(crate) fn txfm_partition_ctx_rect( above_px: u8, @@ -3418,20 +3402,7 @@ pub(crate) fn txfm_partition_ctx_rect( category * 3 + above + left } -/// `txfm_partition_update` (libaom `av1_common_int.h`): once a var-tx unit -/// resolves, every mi cell its *parent* unit (`txb_px`) spans records the -/// resolved transform's own size. -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(super) fn txfm_partition_update( - n: &mut Neighbours, - at_mi: (usize, usize), - tx_px: usize, - txb_px: usize, -) { - txfm_partition_update_rect(n, at_mi, (tx_px, tx_px), (txb_px, txb_px)); -} - -/// [`txfm_partition_update`] for a rectangular transform (lane-inter4 r2): +/// `txfm_partition_update` for a rectangular transform (lane-inter4 r2): /// the left column records `tx_size_high` over the parent's own height and /// the above row records `tx_size_wide` over its width. /// libaom `set_txfm_ctxs` + `txfm_partition_update` (`decodeframe.c`, end of diff --git a/crates/ec-av1/src/decode/deblock.rs b/crates/ec-av1/src/decode/deblock.rs index 651a9dc9..14b6171d 100644 --- a/crates/ec-av1/src/decode/deblock.rs +++ b/crates/ec-av1/src/decode/deblock.rs @@ -15,14 +15,6 @@ fn deblock_thresholds(level: i32, sharpness: u8) -> (i32, i32, i32) { (2 * (level + 2) + lim, lim, level >> 4) } -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(super) fn sclamp(v: i32, fctx: &crate::decode::FrameCtx) -> i32 { - // libaom's `signed_char_clamp_high`: the clamp range scales with - // `128 << (bit_depth - 8)` alongside the centering constant below. - let scale = 1i32 << (bit_depth(fctx) - 8); - v.clamp(-128 * scale, 128 * scale - 1) -} - fn round_pow2(v: i32, n: u32) -> i32 { (v + (1 << (n - 1))) >> n } @@ -711,7 +703,7 @@ pub(super) const SCRATCH_CAP: usize = 32; /// luma-sized allocation (every pooled buffer would drift to the largest /// size otherwise). `None` when the pool is empty. fn scratch_take(n: usize) -> Option> { - let mut p = PLANE_SCRATCH.lock().unwrap(); + let mut p = PLANE_SCRATCH.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if p.is_empty() { return None; } diff --git a/crates/ec-av1/src/decode/deblock_simd.rs b/crates/ec-av1/src/decode/deblock_simd.rs index 764339f9..c52b5143 100644 --- a/crates/ec-av1/src/decode/deblock_simd.rs +++ b/crates/ec-av1/src/decode/deblock_simd.rs @@ -96,21 +96,6 @@ const W8: [[i16; 8]; 6] = [ [0, 0, 1, 1, 1, 2, 1, 2], [0, 0, 0, 1, 1, 1, 2, 3], ]; -#[allow(dead_code)] // superseded by the running-sum rows; kept as the weights' statement -const W14: [[i16; 14]; 12] = [ - [7, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], - [5, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], - [4, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0], - [3, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0], - [2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0], - [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1], - [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2], - [0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 3], - [0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 4], - [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 5], - [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 7], -]; /// One weighted tap sum, rounded by `shift` (3 for the divide-by-8 rows, /// 4 for `filter14`'s divide-by-16 ones). The sum is non-negative and diff --git a/crates/ec-av1/src/decode/frame_tile.rs b/crates/ec-av1/src/decode/frame_tile.rs index 5113eced..87ded993 100644 --- a/crates/ec-av1/src/decode/frame_tile.rs +++ b/crates/ec-av1/src/decode/frame_tile.rs @@ -4,6 +4,7 @@ use super::*; +#[cfg(test)] /// Decodes the payload [`crate::tile::sb_coeff_inter_frame_tile`] writes, /// against `reference` (the previous frame's own decoded picture, at this /// frame's true size -- a decoder's single-slot DPB, matching what this @@ -17,7 +18,6 @@ use super::*; /// or when `reference` is not this frame's own true size, or when the tile /// codes a 16x16 leaf whose own true edge cuts through it (round 2, same /// refusal [`crate::tile`]'s writer gives its encoder). -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] @@ -88,6 +88,7 @@ pub(crate) fn decode_inter_frame_tile( ) } +#[cfg(test)] /// [`decode_inter_frame_tile`] with this frame header's own `lr_params`, the /// inter sibling of [`decode_key_frame_tile_lr`]. #[allow(clippy::too_many_arguments)] diff --git a/crates/ec-av1/src/decode/inter_shapes.rs b/crates/ec-av1/src/decode/inter_shapes.rs index 25806e0a..298d6dbb 100644 --- a/crates/ec-av1/src/decode/inter_shapes.rs +++ b/crates/ec-av1/src/decode/inter_shapes.rs @@ -266,20 +266,10 @@ pub(crate) const INTER_BLOCK_SHAPES: [(usize, usize, usize); 18] = [ (128, 64, 128), ]; -/// Bit 31 of [`inter_block_shape_mask`]: a `(side, write_w, write_h)` triple -/// outside [`INTER_BLOCK_SHAPES`]. -pub const INTER_BLOCK_SHAPE_UNLISTED: u32 = 1 << 31; - thread_local! { pub(super) static INTER_BLOCK_SHAPE_MASK: std::cell::Cell = const { std::cell::Cell::new(0) }; } -/// Which of [`INTER_BLOCK_SHAPES`] this THREAD has decoded (thread-local, so a -/// gate reading it sees only the streams it decoded itself). -pub fn inter_block_shape_mask() -> u32 { - INTER_BLOCK_SHAPE_MASK.with(std::cell::Cell::get) -} - /// The luma coefficient/`tx_type` table set of a whole-block rectangular /// INTER transform unit (lane-inter4 r3). `av1_get_ext_tx_set_type` splits /// the two shapes: a 32x16/16x32 unit has `tx_size_sqr_up == TX_32X32`, so diff --git a/crates/ec-av1/src/decode/key_tile.rs b/crates/ec-av1/src/decode/key_tile.rs index 5676b659..23eff624 100644 --- a/crates/ec-av1/src/decode/key_tile.rs +++ b/crates/ec-av1/src/decode/key_tile.rs @@ -2,6 +2,7 @@ use super::*; +#[cfg(test)] /// [`decode_key_frame_tile`] with this frame header's own `lr_params` (spec /// 5.9.20) instead of the no-restoration default -- the per-unit filters /// themselves live in the tile payload, so the header is all this needs. @@ -183,18 +184,6 @@ thread_local! { pub(crate) static MU_CHUNK_INTRA_IN_INTER_UNITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } -/// Current value of [`MU_CHUNK_COMPOUND_UNITS`], for a gate's before/after -/// delta. -pub fn mu_chunk_compound_units() -> usize { - MU_CHUNK_COMPOUND_UNITS.with(std::cell::Cell::get) -} - -/// Current value of [`MU_CHUNK_INTRA_IN_INTER_UNITS`], for a gate's -/// before/after delta. -pub fn mu_chunk_intra_in_inter_units() -> usize { - MU_CHUNK_INTRA_IN_INTER_UNITS.with(std::cell::Cell::get) -} - thread_local! { /// lane-av1h5: chunk-major chroma WALKS run for a 128-root plane block -- /// one per 64x64 mu chunk. libaom codes exactly 4 per unsplit 128x128 root diff --git a/crates/ec-av1/src/decode/mod.rs b/crates/ec-av1/src/decode/mod.rs index 80a8c7fe..85ee533e 100644 --- a/crates/ec-av1/src/decode/mod.rs +++ b/crates/ec-av1/src/decode/mod.rs @@ -79,7 +79,7 @@ mod cdef; use cdef::*; mod inter_shapes; -pub use inter_shapes::*; +pub(crate) use inter_shapes::*; mod deblock; pub(crate) use deblock::*; @@ -91,7 +91,7 @@ mod replay; pub(crate) use replay::*; mod key_tile; -pub use key_tile::*; +pub(crate) use key_tile::*; mod inter_ctx; pub(crate) use inter_ctx::*; @@ -126,7 +126,6 @@ pub(crate) struct FilterStages { /// Takes whatever the last capturing decode left (see /// [`FrameCtx::capture_stages`]). -#[allow(dead_code)] // read from the encoder's loop restoration search pub(crate) fn take_filter_stages(fctx: &FrameCtx) -> Option { fctx.stages.borrow_mut().take() } @@ -391,10 +390,12 @@ use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables}; use crate::encode::{Picture, Reach}; use crate::intra::predict; use crate::mc; +#[cfg(test)] +use crate::mvstack::NO_SIGN_BIAS; use crate::msac::SymbolDecoder; use crate::mvstack::{ ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME, - MiGrid, MiInfo, NO_REF1, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx, + MiGrid, MiInfo, NO_REF1, NeighbourRef, SignBiasTable, comp_reference_type_ctx, find_mv_stack_with_sign_bias, mv16, mv32, reference_mode_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx, @@ -2276,11 +2277,6 @@ thread_local! { static UV_LEFT_SS_Y_READS: std::cell::Cell = const { std::cell::Cell::new(0) }; } -/// Current value of [`UV_LEFT_SS_Y_READS`]. -pub fn uv_left_ss_y_reads() -> usize { - UV_LEFT_SS_Y_READS.with(|c| c.get()) -} - // lane-av1leftwit: the per-tile epoch `uv_owner` cells are stamped with. // Bumped in `Neighbours::start_tile`; never read by decode logic. thread_local! { @@ -2458,17 +2454,6 @@ thread_local! { static CDEF_MIXED_SKIP_UNITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } -/// Current value of `CDEF_MIXED_SKIP_UNITS`. -pub fn cdef_mixed_skip_units() -> usize { - CDEF_MIXED_SKIP_UNITS.with(|c| c.get()) -} - -/// How many 8x8 CDEF units [`apply_cdef`] visited whose skip band no coded -/// block wrote this frame -- a writer gap, always a defect (lane-cdefstrip r1). -pub fn cdef_unwritten_skip_units() -> usize { - CDEF_UNWRITTEN_SKIP_UNITS.with(|c| c.get()) -} - // Which plane the in-flight INTRA reconstruction is writing (0=Y, 1=U, 2=V). // lane-av1cmpaudit: aomdec's `EC_PREDOUT8`/`EC_PREDND` print `plane=`, and // without the same field on our side an `EC_PREDOUT8` vs `OUR_PRED` diff of a @@ -3221,6 +3206,7 @@ fn is_smooth_mode(mode: usize) -> bool { (crate::intra::SMOOTH_PRED as usize..=crate::intra::SMOOTH_H_PRED as usize).contains(&mode) } +#[cfg(test)] /// Decodes the payload [`crate::tile::sb_coeff_key_frame_tile`] writes, /// returning the picture it reconstructs to. /// @@ -3239,7 +3225,6 @@ fn is_smooth_mode(mode: usize) -> bool { /// 16x16, a directional mode's angle delta other than zero, chroma-from-luma), /// or when the tile payload runs out of the symbols this decode expects (a /// genuinely foreign stream). -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] diff --git a/crates/ec-av1/src/decode/replay.rs b/crates/ec-av1/src/decode/replay.rs index 732747c9..c0b7594d 100644 --- a/crates/ec-av1/src/decode/replay.rs +++ b/crates/ec-av1/src/decode/replay.rs @@ -395,7 +395,7 @@ pub(super) fn crop_owned(plane: PlaneBuf<'_>, w: usize, h: usize) -> Vec { /// Over [`SCRATCH_CAP`] the buffer is dropped (freed) instead -- the cap is /// what keeps a pool shared by every thread from being an unbounded stash. pub(super) fn scratch_return(v: Vec) { - let mut p = PLANE_SCRATCH.lock().unwrap(); + let mut p = PLANE_SCRATCH.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if p.len() < SCRATCH_CAP { p.push(v); } diff --git a/crates/ec-av1/src/lib.rs b/crates/ec-av1/src/lib.rs index 360a6707..506075e7 100644 --- a/crates/ec-av1/src/lib.rs +++ b/crates/ec-av1/src/lib.rs @@ -25,7 +25,7 @@ mod autothreads; pub mod cdf; mod cdf_state; mod compound; -pub mod decode; +mod decode; pub mod encode; pub mod encoder; #[doc(hidden)]