Merge branch 'lane-av1cmpaudit'
Browse files at this commit7 changed files +4637 -1989
- crates/ec-av1/examples/dump_yuv.rs +7 -0
- crates/ec-av1/src/encode.rs +3574 -1835
- crates/ec-av1/src/encoder.rs +478 -139
- crates/ec-av1/src/stream.rs +280 -15
- crates/ec-h264/tests/conformance.rs +53 -0
- crates/ec-vp9/tests/intraonly_exact.rs +5 -0
- lanes/av1cmpaudit.report.md +240 -0
crates/ec-av1/examples/dump_yuv.rsmodified+7 -0
| @@ -36,6 +36,13 @@ fn main() { | |||
| 36 | buf.extend_from_slice(&s.to_le_bytes()); | 36 | buf.extend_from_slice(&s.to_le_bytes()); |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | + // `i` indexes `decode_stream`'s output, which is DISPLAY order and | ||
| 40 | + // SHOWN frames only -- hidden alt-refs are never emitted. Every other | ||
| 41 | + // `.f{N}` in this crate (EC_AV1_FINAL_DUMP, EC_AV1_DECODE_ORDER_DUMP, | ||
| 42 | + // EC_AV1_PREFILT_DUMP) uses a DECODE index, so this file does NOT line | ||
| 43 | + // up with an aomdec dump past frame 0 on a stream with altref. Compare | ||
| 44 | + // against ffmpeg rawvideo, or against aomdec via | ||
| 45 | + // `decode_all_frames_vs_oracle`. | ||
| 39 | let name = format!("{out}.f{i}.yuv"); | 46 | let name = format!("{out}.f{i}.yuv"); |
| 40 | if let Err(e) = std::fs::write(&name, &buf) { | 47 | if let Err(e) = std::fs::write(&name, &buf) { |
| 41 | eprintln!("{name}: {e}"); | 48 | eprintln!("{name}: {e}"); |
crates/ec-av1/src/encode.rsmodified+3574 -1835
Diff too large; view file
| @@ -40,12 +40,12 @@ use crate::sequence::sequence_header_obu; | |||
| 40 | use crate::tile::{ | 40 | use crate::tile::{ |
| 41 | BlockCoeffs, Coeff, INTRA_MODE_CTX, InterInfo, InterMode, Quadrant, Superblock, partition_bits, | 41 | BlockCoeffs, Coeff, INTRA_MODE_CTX, InterInfo, InterMode, Quadrant, Superblock, partition_bits, |
| 42 | }; | 42 | }; |
| 43 | +#[cfg(test)] | ||
| 44 | +use crate::transform::forward_and_quantize; | ||
| 43 | use crate::transform::{ | 45 | use crate::transform::{ |
| 44 | TxType, dequant_and_inverse_typed_wh, forward_and_quantize_typed, | 46 | TxType, dequant_and_inverse_typed_wh, forward_and_quantize_typed, |
| 45 | forward_and_quantize_typed_scaled, | 47 | forward_and_quantize_typed_scaled, |
| 46 | }; | 48 | }; |
| 47 | -#[cfg(test)] | ||
| 48 | -use crate::transform::forward_and_quantize; | ||
| 49 | 49 | ||
| 50 | /// The side of the larger of the two luma blocks this encoder codes, in | 50 | /// The side of the larger of the two luma blocks this encoder codes, in |
| 51 | /// samples. | 51 | /// samples. |
| @@ -153,7 +153,10 @@ const HIDDEN_LAMBDA_FACTOR: f64 = 1.0; | |||
| 153 | 153 | ||
| 154 | /// [`HIDDEN_LAMBDA_FACTOR`], swept by `EC_AV1_LAMBDA_HIDDEN` in any build. | 154 | /// [`HIDDEN_LAMBDA_FACTOR`], swept by `EC_AV1_LAMBDA_HIDDEN` in any build. |
| 155 | fn hidden_lambda_factor() -> f64 { | 155 | fn hidden_lambda_factor() -> f64 { |
| 156 | - match std::env::var("EC_AV1_LAMBDA_HIDDEN").ok().and_then(|v| v.parse().ok()) { | 156 | + match std::env::var("EC_AV1_LAMBDA_HIDDEN") |
| 157 | + .ok() | ||
| 158 | + .and_then(|v| v.parse().ok()) | ||
| 159 | + { | ||
| 157 | Some(f) => f, | 160 | Some(f) => f, |
| 158 | None => HIDDEN_LAMBDA_FACTOR, | 161 | None => HIDDEN_LAMBDA_FACTOR, |
| 159 | } | 162 | } |
| @@ -200,7 +203,10 @@ const KEY_LAMBDA_FACTOR: f64 = 1.0; | |||
| 200 | 203 | ||
| 201 | /// [`KEY_LAMBDA_FACTOR`], or what `EC_AV1_LAMBDA_KEY` names in a test build. | 204 | /// [`KEY_LAMBDA_FACTOR`], or what `EC_AV1_LAMBDA_KEY` names in a test build. |
| 202 | fn key_lambda_factor() -> f64 { | 205 | fn key_lambda_factor() -> f64 { |
| 203 | - match std::env::var("EC_AV1_LAMBDA_KEY").ok().and_then(|v| v.parse::<f64>().ok()) { | 206 | + match std::env::var("EC_AV1_LAMBDA_KEY") |
| 207 | + .ok() | ||
| 208 | + .and_then(|v| v.parse::<f64>().ok()) | ||
| 209 | + { | ||
| 204 | Some(k) if cfg!(test) => k, | 210 | Some(k) if cfg!(test) => k, |
| 205 | _ => KEY_LAMBDA_FACTOR, | 211 | _ => KEY_LAMBDA_FACTOR, |
| 206 | } | 212 | } |
| @@ -290,21 +296,13 @@ pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] | |||
| 290 | TxType::Idtx, | 296 | TxType::Idtx, |
| 291 | ]; | 297 | ]; |
| 292 | match set { | 298 | match set { |
| 293 | - TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4 | 299 | + TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4 if intra_tx_search_on(screen) => &INTRA2, |
| 294 | - if intra_tx_search_on(screen) => | ||
| 295 | - { | ||
| 296 | - &INTRA2 | ||
| 297 | - } | ||
| 298 | // lane-txi: a `reduced_tx_set == 0` frame's intra 8x8/4x4 reads the | 300 | // lane-txi: a `reduced_tx_set == 0` frame's intra 8x8/4x4 reads the |
| 299 | // SEVEN-type `TX_SET_INTRA_1` (`decode::txbset_for`'s `Luma{8,4}Set1`; | 301 | // SEVEN-type `TX_SET_INTRA_1` (`decode::txbset_for`'s `Luma{8,4}Set1`; |
| 300 | // 16x16 stays `TX_SET_INTRA_2`, there is no `Luma16Set1`). The two | 302 | // 16x16 stays `TX_SET_INTRA_2`, there is no `Luma16Set1`). The two |
| 301 | // extra members are the 1-D DCTs, and the order is the reader's own | 303 | // extra members are the 1-D DCTs, and the order is the reader's own |
| 302 | // map (`decode::tx_type_from_symbol`, 8-wide CDF). | 304 | // map (`decode::tx_type_from_symbol`, 8-wide CDF). |
| 303 | - TxbSet::Luma8Set1 | TxbSet::Luma4Set1 | 305 | + TxbSet::Luma8Set1 | TxbSet::Luma4Set1 if intra_tx_search_on(screen) => &INTRA1, |
| 304 | - if intra_tx_search_on(screen) => | ||
| 305 | - { | ||
| 306 | - &INTRA1 | ||
| 307 | - } | ||
| 308 | _ => &DCT, | 306 | _ => &DCT, |
| 309 | } | 307 | } |
| 310 | } | 308 | } |
| @@ -375,11 +373,13 @@ pub(crate) fn wide_tx_set(screen: bool) -> bool { | |||
| 375 | _ => {} | 373 | _ => {} |
| 376 | } | 374 | } |
| 377 | static ENV: std::sync::LazyLock<Option<InterTxSearch>> = std::sync::LazyLock::new(|| { | 375 | static ENV: std::sync::LazyLock<Option<InterTxSearch>> = std::sync::LazyLock::new(|| { |
| 378 | - crate::envflags::var("EC_AV1_TXSET_WIDE").ok().map(|v| match v.as_str() { | 376 | + crate::envflags::var("EC_AV1_TXSET_WIDE") |
| 379 | - "0" | "off" => InterTxSearch::Off, | 377 | + .ok() |
| 380 | - "screen" => InterTxSearch::Screen, | 378 | + .map(|v| match v.as_str() { |
| 381 | - _ => InterTxSearch::All, | 379 | + "0" | "off" => InterTxSearch::Off, |
| 382 | - }) | 380 | + "screen" => InterTxSearch::Screen, |
| 381 | + _ => InterTxSearch::All, | ||
| 382 | + }) | ||
| 383 | }); | 383 | }); |
| 384 | match ENV.unwrap_or(if crate::speed::at(&crate::speed::WIDE_TX_SET) { | 384 | match ENV.unwrap_or(if crate::speed::at(&crate::speed::WIDE_TX_SET) { |
| 385 | InterTxSearch::Screen | 385 | InterTxSearch::Screen |
| @@ -397,8 +397,7 @@ pub(crate) fn wide_tx_set(screen: bool) -> bool { | |||
| 397 | /// [`set_inter_tx_search`] has: the lever is OFF at every preset, so the | 397 | /// [`set_inter_tx_search`] has: the lever is OFF at every preset, so the |
| 398 | /// witness that has to see the wider alphabets turns it on through this while | 398 | /// witness that has to see the wider alphabets turns it on through this while |
| 399 | /// holding [`crate::speed::knob_write`]. | 399 | /// holding [`crate::speed::knob_write`]. |
| 400 | -static WIDE_TX_OVERRIDE: std::sync::atomic::AtomicU8 = | 400 | +static WIDE_TX_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX); |
| 401 | - std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 402 | 401 | ||
| 403 | /// Sets [`WIDE_TX_OVERRIDE`]; `None` clears it. | 402 | /// Sets [`WIDE_TX_OVERRIDE`]; `None` clears it. |
| 404 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates | 403 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates |
| @@ -414,11 +413,7 @@ pub(crate) fn set_wide_tx_set(on: Option<bool>) { | |||
| 414 | /// [`crate::cdf_state::Cdfs`], but the trial that prices a type has to read | 413 | /// [`crate::cdf_state::Cdfs`], but the trial that prices a type has to read |
| 415 | /// the same alphabet or the two disagree on what a `tx_type` symbol costs. | 414 | /// the same alphabet or the two disagree on what a `tx_type` symbol costs. |
| 416 | pub(crate) fn luma_set_for(set: TxbSet, screen: bool) -> TxbSet { | 415 | pub(crate) fn luma_set_for(set: TxbSet, screen: bool) -> TxbSet { |
| 417 | - if wide_tx_set(screen) { | 416 | + if wide_tx_set(screen) { set.wide() } else { set } |
| 418 | - set.wide() | ||
| 419 | - } else { | ||
| 420 | - set | ||
| 421 | - } | ||
| 422 | } | 417 | } |
| 423 | 418 | ||
| 424 | #[derive(Clone, Copy, PartialEq)] | 419 | #[derive(Clone, Copy, PartialEq)] |
| @@ -435,8 +430,7 @@ pub(crate) enum InterTxSearch { | |||
| 435 | /// [`set_deltaq_res`] has: the lever is OFF at every preset, so the witness | 430 | /// [`set_deltaq_res`] has: the lever is OFF at every preset, so the witness |
| 436 | /// that has to see a non-`DCT_DCT` inter unit turns it on through this while | 431 | /// that has to see a non-`DCT_DCT` inter unit turns it on through this while |
| 437 | /// holding [`crate::speed::knob_write`]. | 432 | /// holding [`crate::speed::knob_write`]. |
| 438 | -static INTER_TX_OVERRIDE: std::sync::atomic::AtomicU8 = | 433 | +static INTER_TX_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX); |
| 439 | - std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 440 | 434 | ||
| 441 | /// Sets [`INTER_TX_OVERRIDE`]; `None` clears it. | 435 | /// Sets [`INTER_TX_OVERRIDE`]; `None` clears it. |
| 442 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates | 436 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates |
| @@ -454,12 +448,14 @@ fn inter_tx_type_search() -> InterTxSearch { | |||
| 454 | _ => {} | 448 | _ => {} |
| 455 | } | 449 | } |
| 456 | static ENV: std::sync::LazyLock<Option<InterTxSearch>> = std::sync::LazyLock::new(|| { | 450 | static ENV: std::sync::LazyLock<Option<InterTxSearch>> = std::sync::LazyLock::new(|| { |
| 457 | - crate::envflags::var("EC_AV1_TXSET_INTER").ok().map(|v| match v.as_str() { | 451 | + crate::envflags::var("EC_AV1_TXSET_INTER") |
| 458 | - "0" | "off" => InterTxSearch::Off, | 452 | + .ok() |
| 459 | - "screen" => InterTxSearch::Screen, | 453 | + .map(|v| match v.as_str() { |
| 460 | - "le16" => InterTxSearch::Le16, | 454 | + "0" | "off" => InterTxSearch::Off, |
| 461 | - _ => InterTxSearch::All, | 455 | + "screen" => InterTxSearch::Screen, |
| 462 | - }) | 456 | + "le16" => InterTxSearch::Le16, |
| 457 | + _ => InterTxSearch::All, | ||
| 458 | + }) | ||
| 463 | }); | 459 | }); |
| 464 | ENV.unwrap_or_else(|| { | 460 | ENV.unwrap_or_else(|| { |
| 465 | if crate::speed::at(&crate::speed::TX_TYPE_SEARCH_INTER) { | 461 | if crate::speed::at(&crate::speed::TX_TYPE_SEARCH_INTER) { |
| @@ -525,8 +521,7 @@ fn intra_tx_search_on(screen: bool) -> bool { | |||
| 525 | 521 | ||
| 526 | /// A PROCESS-GLOBAL [`intra_tx_search_on`] override (`u8::MAX` = unset), the | 522 | /// A PROCESS-GLOBAL [`intra_tx_search_on`] override (`u8::MAX` = unset), the |
| 527 | /// shape [`set_inter_tx_search`] has. | 523 | /// shape [`set_inter_tx_search`] has. |
| 528 | -static INTRA_TX_OVERRIDE: std::sync::atomic::AtomicU8 = | 524 | +static INTRA_TX_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX); |
| 529 | - std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 530 | 525 | ||
| 531 | /// Sets [`INTRA_TX_OVERRIDE`]; `None` clears it. | 526 | /// Sets [`INTRA_TX_OVERRIDE`]; `None` clears it. |
| 532 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates | 527 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates |
| @@ -542,9 +537,8 @@ pub(crate) fn set_intra_tx_search(on: Option<bool>) { | |||
| 542 | /// content gate [`tx_type_candidates`] ships behind. Any other value keeps | 537 | /// content gate [`tx_type_candidates`] ships behind. Any other value keeps |
| 543 | /// the gate (`0`/`off` still switches the search off entirely). | 538 | /// the gate (`0`/`off` still switches the search off entirely). |
| 544 | fn intra_tx_all_frames() -> bool { | 539 | fn intra_tx_all_frames() -> bool { |
| 545 | - static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { | 540 | + static ENV: std::sync::LazyLock<bool> = |
| 546 | - crate::envflags::var("EC_AV1_TXSET").is_ok_and(|v| v == "all") | 541 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_TXSET").is_ok_and(|v| v == "all")); |
| 547 | - }); | ||
| 548 | *ENV | 542 | *ENV |
| 549 | } | 543 | } |
| 550 | 544 | ||
| @@ -731,7 +725,9 @@ pub fn take_b64_root_hits() -> usize { | |||
| 731 | /// what the SIZE costs from what the 128x128 BLOCK buys. | 725 | /// what the SIZE costs from what the 128x128 BLOCK buys. |
| 732 | fn b128_root() -> bool { | 726 | fn b128_root() -> bool { |
| 733 | static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { | 727 | static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { |
| 734 | - crate::envflags::var("EC_AV1_B128").ok().is_none_or(|v| v != "0") | 728 | + crate::envflags::var("EC_AV1_B128") |
| 729 | + .ok() | ||
| 730 | + .is_none_or(|v| v != "0") | ||
| 735 | }); | 731 | }); |
| 736 | *ENV | 732 | *ENV |
| 737 | } | 733 | } |
| @@ -758,7 +754,9 @@ fn b128_root() -> bool { | |||
| 758 | /// defect flag. | 754 | /// defect flag. |
| 759 | fn b128_residual() -> bool { | 755 | fn b128_residual() -> bool { |
| 760 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 756 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 761 | - crate::envflags::var("EC_AV1_B128RES").ok().map(|v| v != "0") | 757 | + crate::envflags::var("EC_AV1_B128RES") |
| 758 | + .ok() | ||
| 759 | + .map(|v| v != "0") | ||
| 762 | }); | 760 | }); |
| 763 | (ENV.unwrap_or(false) || FORCE_B128_RESIDUAL.load(std::sync::atomic::Ordering::Relaxed)) | 761 | (ENV.unwrap_or(false) || FORCE_B128_RESIDUAL.load(std::sync::atomic::Ordering::Relaxed)) |
| 764 | && b128_root() | 762 | && b128_root() |
| @@ -799,8 +797,7 @@ pub(crate) fn force_b128_rectres(on: bool) { | |||
| 799 | /// How many rect/AB pieces the search left WITH a residual rather than | 797 | /// How many rect/AB pieces the search left WITH a residual rather than |
| 800 | /// skipped, since the last [`take_b128_rectres_hits`] (class | 798 | /// skipped, since the last [`take_b128_rectres_hits`] (class |
| 801 | /// `gate-blind-to-feature`). | 799 | /// `gate-blind-to-feature`). |
| 802 | -static B128_RECTRES_HITS: std::sync::atomic::AtomicUsize = | 800 | +static B128_RECTRES_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 803 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 804 | 801 | ||
| 805 | /// The rect/AB-piece-residual count since the last call, and zero it. | 802 | /// The rect/AB-piece-residual count since the last call, and zero it. |
| 806 | pub fn take_b128_rectres_hits() -> usize { | 803 | pub fn take_b128_rectres_hits() -> usize { |
| @@ -816,15 +813,16 @@ pub fn take_b128_rectres_hits() -> usize { | |||
| 816 | /// names a second reference). | 813 | /// names a second reference). |
| 817 | fn b128_compound() -> bool { | 814 | fn b128_compound() -> bool { |
| 818 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 815 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 819 | - crate::envflags::var("EC_AV1_B128COMP").ok().map(|v| v != "0") | 816 | + crate::envflags::var("EC_AV1_B128COMP") |
| 817 | + .ok() | ||
| 818 | + .map(|v| v != "0") | ||
| 820 | }); | 819 | }); |
| 821 | ENV.unwrap_or(true) && b128_root() | 820 | ENV.unwrap_or(true) && b128_root() |
| 822 | } | 821 | } |
| 823 | 822 | ||
| 824 | /// How many 128 roots came out COMPOUND since the last | 823 | /// How many 128 roots came out COMPOUND since the last |
| 825 | /// [`take_b128_compound_hits`] (class `gate-blind-to-feature`). | 824 | /// [`take_b128_compound_hits`] (class `gate-blind-to-feature`). |
| 826 | -static B128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = | 825 | +static B128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 827 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 828 | 826 | ||
| 829 | /// The compound-128 count since the last call, and zero it. | 827 | /// The compound-128 count since the last call, and zero it. |
| 830 | pub fn take_b128_compound_hits() -> usize { | 828 | pub fn take_b128_compound_hits() -> usize { |
| @@ -837,9 +835,8 @@ pub fn take_b128_compound_hits() -> usize { | |||
| 837 | /// halved ([`search_root_128_rect`], `crate::tile::write_inter_block_128_rect`). | 835 | /// halved ([`search_root_128_rect`], `crate::tile::write_inter_block_128_rect`). |
| 838 | /// `EC_AV1_B128HV=0` is this arm's attribution control. | 836 | /// `EC_AV1_B128HV=0` is this arm's attribution control. |
| 839 | fn b128_rect() -> bool { | 837 | fn b128_rect() -> bool { |
| 840 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 838 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 841 | - crate::envflags::var("EC_AV1_B128HV").ok().map(|v| v != "0") | 839 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_B128HV").ok().map(|v| v != "0")); |
| 842 | - }); | ||
| 843 | ENV.unwrap_or(true) && b128_root() | 840 | ENV.unwrap_or(true) && b128_root() |
| 844 | } | 841 | } |
| 845 | 842 | ||
| @@ -848,9 +845,8 @@ fn b128_rect() -> bool { | |||
| 848 | /// attribution control (the pre-lane pricing, where a 128 rect root and the | 845 | /// attribution control (the pre-lane pricing, where a 128 rect root and the |
| 849 | /// four-superblock arm were both priced as if the group were free). | 846 | /// four-superblock arm were both priced as if the group were free). |
| 850 | fn rectdq() -> bool { | 847 | fn rectdq() -> bool { |
| 851 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 848 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 852 | - crate::envflags::var("EC_AV1_RECTDQ").ok().map(|v| v != "0") | 849 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_RECTDQ").ok().map(|v| v != "0")); |
| 853 | - }); | ||
| 854 | ENV.unwrap_or(true) | 850 | ENV.unwrap_or(true) |
| 855 | } | 851 | } |
| 856 | 852 | ||
| @@ -978,9 +974,8 @@ pub(crate) fn force_b128_rect(which: u8) { | |||
| 978 | /// 64x64 pieces could carry the 64 root's residual, which is where libaom's | 974 | /// 64x64 pieces could carry the 64 root's residual, which is where libaom's |
| 979 | /// AB shapes earn their keep) or a cheaper partition price. | 975 | /// AB shapes earn their keep) or a cheaper partition price. |
| 980 | fn b128_ab() -> bool { | 976 | fn b128_ab() -> bool { |
| 981 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 977 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 982 | - crate::envflags::var("EC_AV1_B128AB").ok().map(|v| v != "0") | 978 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_B128AB").ok().map(|v| v != "0")); |
| 983 | - }); | ||
| 984 | ENV.unwrap_or(false) && b128_root() | 979 | ENV.unwrap_or(false) && b128_root() |
| 985 | } | 980 | } |
| 986 | 981 | ||
| @@ -1043,8 +1038,7 @@ static FORCE_B128_RESIDUAL: std::sync::atomic::AtomicBool = | |||
| 1043 | /// the 128 root whenever it produced a candidate at all, whatever its four | 1038 | /// the 128 root whenever it produced a candidate at all, whatever its four |
| 1044 | /// cells cost, so a witness codes the block it is about rather than waiting | 1039 | /// cells cost, so a witness codes the block it is about rather than waiting |
| 1045 | /// for content on which the root also wins its own comparison. | 1040 | /// for content on which the root also wins its own comparison. |
| 1046 | -static FORCE_B128_ROOT: std::sync::atomic::AtomicBool = | 1041 | +static FORCE_B128_ROOT: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); |
| 1047 | - std::sync::atomic::AtomicBool::new(false); | ||
| 1048 | 1042 | ||
| 1049 | /// Arms [`FORCE_B128_RESIDUAL`] -- and with it [`FORCE_B128_ROOT`], since a | 1043 | /// Arms [`FORCE_B128_RESIDUAL`] -- and with it [`FORCE_B128_ROOT`], since a |
| 1050 | /// forced residual block only reaches the writer if its root is taken. | 1044 | /// forced residual block only reaches the writer if its root is taken. |
| @@ -1062,8 +1056,7 @@ pub(crate) fn force_b128_root(on: bool) { | |||
| 1062 | 1056 | ||
| 1063 | /// How many 128 roots came out cheaper WITH a residual than skipped, since | 1057 | /// How many 128 roots came out cheaper WITH a residual than skipped, since |
| 1064 | /// the last [`take_b128_residual_hits`] (class `gate-blind-to-feature`). | 1058 | /// the last [`take_b128_residual_hits`] (class `gate-blind-to-feature`). |
| 1065 | -static B128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = | 1059 | +static B128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 1066 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 1067 | 1060 | ||
| 1068 | /// The 128-residual count since the last call, and zero it. | 1061 | /// The 128-residual count since the last call, and zero it. |
| 1069 | pub fn take_b128_residual_hits() -> usize { | 1062 | pub fn take_b128_residual_hits() -> usize { |
| @@ -1087,9 +1080,8 @@ pub fn take_b128_none_hits() -> usize { | |||
| 1087 | /// `EC_AV1_RDOQ=0` in any build restores the plain deadzone quantiser -- | 1080 | /// `EC_AV1_RDOQ=0` in any build restores the plain deadzone quantiser -- |
| 1088 | /// which is what the byte pins are taken under when they name it. | 1081 | /// which is what the byte pins are taken under when they name it. |
| 1089 | fn rdoq_on() -> bool { | 1082 | fn rdoq_on() -> bool { |
| 1090 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 1083 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 1091 | - crate::envflags::var("EC_AV1_RDOQ").ok().map(|v| v != "0") | 1084 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_RDOQ").ok().map(|v| v != "0")); |
| 1092 | - }); | ||
| 1093 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::RDOQ)) | 1085 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::RDOQ)) |
| 1094 | } | 1086 | } |
| 1095 | 1087 | ||
| @@ -1143,9 +1135,8 @@ fn rdoq_lambda() -> f64 { | |||
| 1143 | 1135 | ||
| 1144 | /// [`B64_ROOT`], or what `EC_AV1_B64` names. | 1136 | /// [`B64_ROOT`], or what `EC_AV1_B64` names. |
| 1145 | fn b64_root() -> bool { | 1137 | fn b64_root() -> bool { |
| 1146 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 1138 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 1147 | - crate::envflags::var("EC_AV1_B64").ok().map(|v| v != "0") | 1139 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_B64").ok().map(|v| v != "0")); |
| 1148 | - }); | ||
| 1149 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::B64_ROOT)) | 1140 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::B64_ROOT)) |
| 1150 | } | 1141 | } |
| 1151 | 1142 | ||
| @@ -1189,9 +1180,8 @@ pub fn take_i64_root_hits() -> [usize; 3] { | |||
| 1189 | 1180 | ||
| 1190 | /// [`I64_ROOT`], or what `EC_AV1_I64` names. | 1181 | /// [`I64_ROOT`], or what `EC_AV1_I64` names. |
| 1191 | fn i64_root() -> bool { | 1182 | fn i64_root() -> bool { |
| 1192 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 1183 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 1193 | - crate::envflags::var("EC_AV1_I64").ok().map(|v| v != "0") | 1184 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_I64").ok().map(|v| v != "0")); |
| 1194 | - }); | ||
| 1195 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::I64_ROOT)) | 1185 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::I64_ROOT)) |
| 1196 | } | 1186 | } |
| 1197 | 1187 | ||
| @@ -1230,9 +1220,8 @@ fn i64_root() -> bool { | |||
| 1230 | /// transforms per superblock: a root that wins is four quadrant searches that | 1220 | /// transforms per superblock: a root that wins is four quadrant searches that |
| 1231 | /// never run. | 1221 | /// never run. |
| 1232 | fn b64_residual() -> bool { | 1222 | fn b64_residual() -> bool { |
| 1233 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 1223 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 1234 | - crate::envflags::var("EC_AV1_B64RES").ok().map(|v| v != "0") | 1224 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_B64RES").ok().map(|v| v != "0")); |
| 1235 | - }); | ||
| 1236 | ENV.unwrap_or(true) && b64_root() | 1225 | ENV.unwrap_or(true) && b64_root() |
| 1237 | } | 1226 | } |
| 1238 | 1227 | ||
| @@ -1258,7 +1247,9 @@ pub fn take_b64_residual_hits() -> usize { | |||
| 1258 | /// Off by `EC_AV1_B64COMP=0`, so both arms measure on one build. | 1247 | /// Off by `EC_AV1_B64COMP=0`, so both arms measure on one build. |
| 1259 | fn b64_compound() -> bool { | 1248 | fn b64_compound() -> bool { |
| 1260 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 1249 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 1261 | - crate::envflags::var("EC_AV1_B64COMP").ok().map(|v| v != "0") | 1250 | + crate::envflags::var("EC_AV1_B64COMP") |
| 1251 | + .ok() | ||
| 1252 | + .map(|v| v != "0") | ||
| 1262 | }); | 1253 | }); |
| 1263 | ENV.unwrap_or(true) && b64_root() | 1254 | ENV.unwrap_or(true) && b64_root() |
| 1264 | } | 1255 | } |
| @@ -1282,7 +1273,9 @@ pub fn take_b64_compound_hits() -> usize { | |||
| 1282 | /// Off by `EC_AV1_B64VARTX=0`. | 1273 | /// Off by `EC_AV1_B64VARTX=0`. |
| 1283 | fn b64_var_tx() -> bool { | 1274 | fn b64_var_tx() -> bool { |
| 1284 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 1275 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 1285 | - crate::envflags::var("EC_AV1_B64VARTX").ok().map(|v| v != "0") | 1276 | + crate::envflags::var("EC_AV1_B64VARTX") |
| 1277 | + .ok() | ||
| 1278 | + .map(|v| v != "0") | ||
| 1286 | }); | 1279 | }); |
| 1287 | ENV.unwrap_or(true) && b64_root() | 1280 | ENV.unwrap_or(true) && b64_root() |
| 1288 | } | 1281 | } |
| @@ -1315,7 +1308,9 @@ fn b64_edge() -> bool { | |||
| 1315 | /// but is gated by [`i64_root`]. | 1308 | /// but is gated by [`i64_root`]. |
| 1316 | fn edge_root_enabled() -> bool { | 1309 | fn edge_root_enabled() -> bool { |
| 1317 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 1310 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 1318 | - crate::envflags::var("EC_AV1_B64EDGE").ok().map(|v| v != "0") | 1311 | + crate::envflags::var("EC_AV1_B64EDGE") |
| 1312 | + .ok() | ||
| 1313 | + .map(|v| v != "0") | ||
| 1319 | }); | 1314 | }); |
| 1320 | ENV.unwrap_or(true) | 1315 | ENV.unwrap_or(true) |
| 1321 | } | 1316 | } |
| @@ -1388,7 +1383,9 @@ pub(crate) const SPLIT_RD_THRESHOLD: f64 = 0.125; | |||
| 1388 | /// [`SPLIT_RD_THRESHOLD`], swept by `EC_AV1_SPLIT_RD` in any build. | 1383 | /// [`SPLIT_RD_THRESHOLD`], swept by `EC_AV1_SPLIT_RD` in any build. |
| 1389 | fn split_rd_threshold() -> f64 { | 1384 | fn split_rd_threshold() -> f64 { |
| 1390 | static ENV: std::sync::LazyLock<Option<f64>> = std::sync::LazyLock::new(|| { | 1385 | static ENV: std::sync::LazyLock<Option<f64>> = std::sync::LazyLock::new(|| { |
| 1391 | - crate::envflags::var("EC_AV1_SPLIT_RD").ok().and_then(|v| v.parse().ok()) | 1386 | + crate::envflags::var("EC_AV1_SPLIT_RD") |
| 1387 | + .ok() | ||
| 1388 | + .and_then(|v| v.parse().ok()) | ||
| 1392 | }); | 1389 | }); |
| 1393 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::SPLIT_RD)) | 1390 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::SPLIT_RD)) |
| 1394 | } | 1391 | } |
| @@ -1674,7 +1671,8 @@ fn intra_predict_u8( | |||
| 1674 | bh: usize, | 1671 | bh: usize, |
| 1675 | enable_edge_filter: bool, | 1672 | enable_edge_filter: bool, |
| 1676 | smooth_neighbor: bool, | 1673 | smooth_neighbor: bool, |
| 1677 | - dst: &mut [u8], fctx: &crate::decode::FrameCtx, | 1674 | + dst: &mut [u8], |
| 1675 | + fctx: &crate::decode::FrameCtx, | ||
| 1678 | ) { | 1676 | ) { |
| 1679 | // Three heap allocations per call became three stack buffers: this runs | 1677 | // Three heap allocations per call became three stack buffers: this runs |
| 1680 | // once per mode per trial, and an edge is at most `bw + bh` samples while | 1678 | // once per mode per trial, and an edge is at most `bw + bh` samples while |
| @@ -1713,7 +1711,8 @@ fn intra_predict_u8( | |||
| 1713 | bh, | 1711 | bh, |
| 1714 | enable_edge_filter, | 1712 | enable_edge_filter, |
| 1715 | smooth_neighbor, | 1713 | smooth_neighbor, |
| 1716 | - dst16, fctx, | 1714 | + dst16, |
| 1715 | + fctx, | ||
| 1717 | ); | 1716 | ); |
| 1718 | for (d, &s) in dst.iter_mut().zip(dst16.iter()) { | 1717 | for (d, &s) in dst.iter_mut().zip(dst16.iter()) { |
| 1719 | *d = s as u8; | 1718 | *d = s as u8; |
| @@ -1740,7 +1739,8 @@ fn filter_intra_predict_u8( | |||
| 1740 | left: Option<&[u8]>, | 1739 | left: Option<&[u8]>, |
| 1741 | corner: Option<u8>, | 1740 | corner: Option<u8>, |
| 1742 | side: usize, | 1741 | side: usize, |
| 1743 | - dst: &mut [u8], fctx: &crate::decode::FrameCtx, | 1742 | + dst: &mut [u8], |
| 1743 | + fctx: &crate::decode::FrameCtx, | ||
| 1744 | ) { | 1744 | ) { |
| 1745 | let mut above_buf = [0u16; 2 * BLOCK]; | 1745 | let mut above_buf = [0u16; 2 * BLOCK]; |
| 1746 | let mut left_buf = [0u16; 2 * BLOCK]; | 1746 | let mut left_buf = [0u16; 2 * BLOCK]; |
| @@ -1764,7 +1764,8 @@ fn filter_intra_predict_u8( | |||
| 1764 | corner.map(u16::from), | 1764 | corner.map(u16::from), |
| 1765 | side, | 1765 | side, |
| 1766 | side, | 1766 | side, |
| 1767 | - &mut dst16[..n], fctx, | 1767 | + &mut dst16[..n], |
| 1768 | + fctx, | ||
| 1768 | ); | 1769 | ); |
| 1769 | for (d, &v) in dst.iter_mut().zip(dst16[..n].iter()) { | 1770 | for (d, &v) in dst.iter_mut().zip(dst16[..n].iter()) { |
| 1770 | *d = v as u8; | 1771 | *d = v as u8; |
| @@ -2354,8 +2355,7 @@ pub const GOLDEN_SLOT: u8 = 1; | |||
| 2354 | /// environment (`u8::MAX` = unset), the shape [`set_inter_tx_search`] has: | 2355 | /// environment (`u8::MAX` = unset), the shape [`set_inter_tx_search`] has: |
| 2355 | /// the witness that has to see a non-REGULAR kernel coded and decoded turns | 2356 | /// the witness that has to see a non-REGULAR kernel coded and decoded turns |
| 2356 | /// it on through this while holding [`crate::speed::knob_write`]. | 2357 | /// it on through this while holding [`crate::speed::knob_write`]. |
| 2357 | -static INTERP_OVERRIDE: std::sync::atomic::AtomicU8 = | 2358 | +static INTERP_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX); |
| 2358 | - std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 2359 | 2359 | ||
| 2360 | /// Sets [`INTERP_OVERRIDE`]; `None` clears it. | 2360 | /// Sets [`INTERP_OVERRIDE`]; `None` clears it. |
| 2361 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates | 2361 | #[allow(dead_code)] // set only from the `#[cfg(test)]` gates |
| @@ -2375,11 +2375,13 @@ fn frame_interp_filter() -> ec_av1_syntax::InterpolationFilter { | |||
| 2375 | _ => {} | 2375 | _ => {} |
| 2376 | } | 2376 | } |
| 2377 | static ENV: std::sync::LazyLock<Option<F>> = std::sync::LazyLock::new(|| { | 2377 | static ENV: std::sync::LazyLock<Option<F>> = std::sync::LazyLock::new(|| { |
| 2378 | - crate::envflags::var("EC_AV1_INTERP").ok().map(|v| match v.as_str() { | 2378 | + crate::envflags::var("EC_AV1_INTERP") |
| 2379 | - "smooth" => F::EighttapSmooth, | 2379 | + .ok() |
| 2380 | - "sharp" => F::EighttapSharp, | 2380 | + .map(|v| match v.as_str() { |
| 2381 | - _ => F::Eighttap, | 2381 | + "smooth" => F::EighttapSmooth, |
| 2382 | - }) | 2382 | + "sharp" => F::EighttapSharp, |
| 2383 | + _ => F::Eighttap, | ||
| 2384 | + }) | ||
| 2383 | }); | 2385 | }); |
| 2384 | ENV.unwrap_or(F::Eighttap) | 2386 | ENV.unwrap_or(F::Eighttap) |
| 2385 | } | 2387 | } |
| @@ -2398,7 +2400,9 @@ pub fn inter_frame_headers( | |||
| 2398 | order_hint: u32, | 2400 | order_hint: u32, |
| 2399 | last_slot: u8, | 2401 | last_slot: u8, |
| 2400 | ) -> Result<(SequenceHeader, FrameHeader)> { | 2402 | ) -> Result<(SequenceHeader, FrameHeader)> { |
| 2401 | - inter_frame_headers_slots(width, height, base_q_idx, order_hint, last_slot, last_slot, last_slot) | 2403 | + inter_frame_headers_slots( |
| 2404 | + width, height, base_q_idx, order_hint, last_slot, last_slot, last_slot, | ||
| 2405 | + ) | ||
| 2402 | } | 2406 | } |
| 2403 | 2407 | ||
| 2404 | /// [`inter_frame_headers`] with the three slots named apart: the one read as | 2408 | /// [`inter_frame_headers`] with the three slots named apart: the one read as |
| @@ -2472,8 +2476,7 @@ pub fn inter_frame_headers_slots( | |||
| 2472 | // `allow_warped_motion` besides -- which is what makes an eligible | 2476 | // `allow_warped_motion` besides -- which is what makes an eligible |
| 2473 | // block read the 3-symbol `motion_mode_cdf` alphabet instead of the | 2477 | // block read the 3-symbol `motion_mode_cdf` alphabet instead of the |
| 2474 | // 2-symbol `obmc_cdf` one (libaom `motion_mode_allowed`). | 2478 | // 2-symbol `obmc_cdf` one (libaom `motion_mode_allowed`). |
| 2475 | - is_motion_mode_switchable: crate::envflags::env_flag!("EC_AV1_OBMC") | 2479 | + is_motion_mode_switchable: crate::envflags::env_flag!("EC_AV1_OBMC") || warp_on(), |
| 2476 | - || warp_on(), | ||
| 2477 | allow_warped_motion: warp_on(), | 2480 | allow_warped_motion: warp_on(), |
| 2478 | use_ref_frame_mvs: false, | 2481 | use_ref_frame_mvs: false, |
| 2479 | // Forces `get_tx_set` (spec 5.11.48) to the two-symbol | 2482 | // Forces `get_tx_set` (spec 5.11.48) to the two-symbol |
| @@ -2546,8 +2549,11 @@ struct CoefCtxMap { | |||
| 2546 | /// padding-inclusive score the search used before lane-sse, which is how the | 2549 | /// padding-inclusive score the search used before lane-sse, which is how the |
| 2547 | /// before/after arms of the straddling gate rows are read off ONE binary. | 2550 | /// before/after arms of the straddling gate rows are read off ONE binary. |
| 2548 | fn edge_sse() -> bool { | 2551 | fn edge_sse() -> bool { |
| 2549 | - static ENV: std::sync::LazyLock<Option<bool>> = | 2552 | + static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 2550 | - std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_EDGESSE").ok().map(|v| v != "0")); | 2553 | + crate::envflags::var("EC_AV1_EDGESSE") |
| 2554 | + .ok() | ||
| 2555 | + .map(|v| v != "0") | ||
| 2556 | + }); | ||
| 2551 | ENV.unwrap_or(true) | 2557 | ENV.unwrap_or(true) |
| 2552 | } | 2558 | } |
| 2553 | 2559 | ||
| @@ -2558,8 +2564,9 @@ fn edge_sse() -> bool { | |||
| 2558 | /// `gate-blind-to-feature` -- both gate films are superblock-aligned, so | 2564 | /// `gate-blind-to-feature` -- both gate films are superblock-aligned, so |
| 2559 | /// without this census no gate row can say the clip fires at all). | 2565 | /// without this census no gate row can say the clip fires at all). |
| 2560 | fn edge_census() -> bool { | 2566 | fn edge_census() -> bool { |
| 2561 | - static ENV: std::sync::LazyLock<bool> = | 2567 | + static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { |
| 2562 | - std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_EDGE_CENSUS").ok().as_deref() == Some("1")); | 2568 | + crate::envflags::var("EC_AV1_EDGE_CENSUS").ok().as_deref() == Some("1") |
| 2569 | + }); | ||
| 2563 | *ENV | 2570 | *ENV |
| 2564 | } | 2571 | } |
| 2565 | 2572 | ||
| @@ -2698,8 +2705,7 @@ impl Plane<'_> { | |||
| 2698 | let down = down.min(self.tile_y1); | 2705 | let down = down.min(self.tile_y1); |
| 2699 | let above_n = (y > self.tile_y0 && across > x).then(|| across - x); | 2706 | let above_n = (y > self.tile_y0 && across > x).then(|| across - x); |
| 2700 | if let Some(n) = above_n { | 2707 | if let Some(n) = above_n { |
| 2701 | - above_buf[..n] | 2708 | + above_buf[..n].copy_from_slice(&self.reconstruction[(y - 1) * self.width + x..][..n]); |
| 2702 | - .copy_from_slice(&self.reconstruction[(y - 1) * self.width + x..][..n]); | ||
| 2703 | } | 2709 | } |
| 2704 | let left_n = (x > self.tile_x0 && down > y).then(|| down - y); | 2710 | let left_n = (x > self.tile_x0 && down > y).then(|| down - y); |
| 2705 | if let Some(n) = left_n { | 2711 | if let Some(n) = left_n { |
| @@ -2719,8 +2725,24 @@ impl Plane<'_> { | |||
| 2719 | /// Codes one block under one mode without committing it: hands back the | 2725 | /// Codes one block under one mode without committing it: hands back the |
| 2720 | /// levels, the block the decoder would reconstruct, the squared error | 2726 | /// levels, the block the decoder would reconstruct, the squared error |
| 2721 | /// against the source and an estimate of what the levels cost in bits. | 2727 | /// against the source and an estimate of what the levels cost in bits. |
| 2722 | - fn trial(&self, at: At, mode: u8, angle_delta: i32, base_q_idx: u8, deadzone: f64, fctx: &crate::decode::FrameCtx) -> Trial { | 2728 | + fn trial( |
| 2723 | - self.trial_typed(at, mode, angle_delta, base_q_idx, deadzone, TxType::DctDct, fctx) | 2729 | + &self, |
| 2730 | + at: At, | ||
| 2731 | + mode: u8, | ||
| 2732 | + angle_delta: i32, | ||
| 2733 | + base_q_idx: u8, | ||
| 2734 | + deadzone: f64, | ||
| 2735 | + fctx: &crate::decode::FrameCtx, | ||
| 2736 | + ) -> Trial { | ||
| 2737 | + self.trial_typed( | ||
| 2738 | + at, | ||
| 2739 | + mode, | ||
| 2740 | + angle_delta, | ||
| 2741 | + base_q_idx, | ||
| 2742 | + deadzone, | ||
| 2743 | + TxType::DctDct, | ||
| 2744 | + fctx, | ||
| 2745 | + ) | ||
| 2724 | } | 2746 | } |
| 2725 | 2747 | ||
| 2726 | /// [`Self::trial`] under a named transform type -- what an intra chroma | 2748 | /// [`Self::trial`] under a named transform type -- what an intra chroma |
| @@ -2785,8 +2807,10 @@ impl Plane<'_> { | |||
| 2785 | let (mut inside, mut whole) = (0u64, 0u64); | 2807 | let (mut inside, mut whole) = (0u64, 0u64); |
| 2786 | for row in 0..side { | 2808 | for row in 0..side { |
| 2787 | let source = &self.source[(y + row) * self.width + x..][..side]; | 2809 | let source = &self.source[(y + row) * self.width + x..][..side]; |
| 2788 | - for (col, (&s, &r)) in | 2810 | + for (col, (&s, &r)) in source |
| 2789 | - source.iter().zip(&reconstruction[row * side..][..side]).enumerate() | 2811 | + .iter() |
| 2812 | + .zip(&reconstruction[row * side..][..side]) | ||
| 2813 | + .enumerate() | ||
| 2790 | { | 2814 | { |
| 2791 | let d = u64::from(u32::from(s.abs_diff(r)).pow(2)); | 2815 | let d = u64::from(u32::from(s.abs_diff(r)).pow(2)); |
| 2792 | whole += d; | 2816 | whole += d; |
| @@ -2834,7 +2858,8 @@ impl Plane<'_> { | |||
| 2834 | side, | 2858 | side, |
| 2835 | false, | 2859 | false, |
| 2836 | false, | 2860 | false, |
| 2837 | - prediction, fctx, | 2861 | + prediction, |
| 2862 | + fctx, | ||
| 2838 | ); | 2863 | ); |
| 2839 | 2864 | ||
| 2840 | let mut residual = [0i32; BLOCK * BLOCK]; | 2865 | let mut residual = [0i32; BLOCK * BLOCK]; |
| @@ -2853,18 +2878,35 @@ impl Plane<'_> { | |||
| 2853 | // grid this trial would really code. | 2878 | // grid this trial would really code. |
| 2854 | let (levels, rdoq_bits) = if rdoq_on() { | 2879 | let (levels, rdoq_bits) = if rdoq_on() { |
| 2855 | let (mut levels, scaled) = forward_and_quantize_typed_scaled( | 2880 | let (mut levels, scaled) = forward_and_quantize_typed_scaled( |
| 2856 | - residual, side, 8, i32::from(base_q_idx), deadzone, tx_type, | 2881 | + residual, |
| 2882 | + side, | ||
| 2883 | + 8, | ||
| 2884 | + i32::from(base_q_idx), | ||
| 2885 | + deadzone, | ||
| 2886 | + tx_type, | ||
| 2857 | ); | 2887 | ); |
| 2858 | let (skip_ctx, sign_ctx) = self.coef_ctx(x, y, side, at.set); | 2888 | let (skip_ctx, sign_ctx) = self.coef_ctx(x, y, side, at.set); |
| 2859 | let bits = crate::tile::rdoq( | 2889 | let bits = crate::tile::rdoq( |
| 2860 | - &mut levels, &scaled, side, base_q_idx, at.set, skip_ctx, sign_ctx, rdoq_lambda(), | 2890 | + &mut levels, |
| 2891 | + &scaled, | ||
| 2892 | + side, | ||
| 2893 | + base_q_idx, | ||
| 2894 | + at.set, | ||
| 2895 | + skip_ctx, | ||
| 2896 | + sign_ctx, | ||
| 2897 | + rdoq_lambda(), | ||
| 2861 | tx_type, | 2898 | tx_type, |
| 2862 | ); | 2899 | ); |
| 2863 | (levels, Some(bits)) | 2900 | (levels, Some(bits)) |
| 2864 | } else { | 2901 | } else { |
| 2865 | ( | 2902 | ( |
| 2866 | forward_and_quantize_typed( | 2903 | forward_and_quantize_typed( |
| 2867 | - residual, side, 8, i32::from(base_q_idx), deadzone, tx_type, | 2904 | + residual, |
| 2905 | + side, | ||
| 2906 | + 8, | ||
| 2907 | + i32::from(base_q_idx), | ||
| 2908 | + deadzone, | ||
| 2909 | + tx_type, | ||
| 2868 | ), | 2910 | ), |
| 2869 | None, | 2911 | None, |
| 2870 | ) | 2912 | ) |
| @@ -2877,7 +2919,15 @@ impl Plane<'_> { | |||
| 2877 | // residual reconstructs to the prediction itself -- `clamp(p + 0)` is | 2919 | // residual reconstructs to the prediction itself -- `clamp(p + 0)` is |
| 2878 | // `p` for a `u8`, so the bytes are the same. | 2920 | // `p` for a `u8`, so the bytes are the same. |
| 2879 | let coded = dequant_and_inverse_typed_wh( | 2921 | let coded = dequant_and_inverse_typed_wh( |
| 2880 | - &levels, side, side, 8, i32::from(base_q_idx), 0, 0, tx_type, None, | 2922 | + &levels, |
| 2923 | + side, | ||
| 2924 | + side, | ||
| 2925 | + 8, | ||
| 2926 | + i32::from(base_q_idx), | ||
| 2927 | + 0, | ||
| 2928 | + 0, | ||
| 2929 | + tx_type, | ||
| 2930 | + None, | ||
| 2881 | ); | 2931 | ); |
| 2882 | #[cfg(test)] | 2932 | #[cfg(test)] |
| 2883 | stage_since(2, t); | 2933 | stage_since(2, t); |
| @@ -2952,7 +3002,15 @@ impl Plane<'_> { | |||
| 2952 | set: TxbSet, | 3002 | set: TxbSet, |
| 2953 | ) -> Trial { | 3003 | ) -> Trial { |
| 2954 | self.code_from_prediction_typed( | 3004 | self.code_from_prediction_typed( |
| 2955 | - x, y, side, prediction, skip, base_q_idx, deadzone, set, TxType::DctDct, | 3005 | + x, |
| 3006 | + y, | ||
| 3007 | + side, | ||
| 3008 | + prediction, | ||
| 3009 | + skip, | ||
| 3010 | + base_q_idx, | ||
| 3011 | + deadzone, | ||
| 3012 | + set, | ||
| 3013 | + TxType::DctDct, | ||
| 2956 | ) | 3014 | ) |
| 2957 | } | 3015 | } |
| 2958 | 3016 | ||
| @@ -3007,20 +3065,36 @@ impl Plane<'_> { | |||
| 3007 | let t = stage_start(); | 3065 | let t = stage_start(); |
| 3008 | // lane-rdoq, as in [`Self::trial_typed`]. | 3066 | // lane-rdoq, as in [`Self::trial_typed`]. |
| 3009 | let (levels, rdoq_bits) = if rdoq_on() { | 3067 | let (levels, rdoq_bits) = if rdoq_on() { |
| 3010 | - let (mut levels, scaled) = | 3068 | + let (mut levels, scaled) = forward_and_quantize_typed_scaled( |
| 3011 | - forward_and_quantize_typed_scaled( | 3069 | + residual, |
| 3012 | - residual, side, 8, i32::from(base_q_idx), deadzone, tx_type, | 3070 | + side, |
| 3013 | - ); | 3071 | + 8, |
| 3072 | + i32::from(base_q_idx), | ||
| 3073 | + deadzone, | ||
| 3074 | + tx_type, | ||
| 3075 | + ); | ||
| 3014 | let (skip_ctx, sign_ctx) = self.coef_ctx(x, y, side, set); | 3076 | let (skip_ctx, sign_ctx) = self.coef_ctx(x, y, side, set); |
| 3015 | let bits = crate::tile::rdoq( | 3077 | let bits = crate::tile::rdoq( |
| 3016 | - &mut levels, &scaled, side, base_q_idx, set, skip_ctx, sign_ctx, rdoq_lambda(), | 3078 | + &mut levels, |
| 3079 | + &scaled, | ||
| 3080 | + side, | ||
| 3081 | + base_q_idx, | ||
| 3082 | + set, | ||
| 3083 | + skip_ctx, | ||
| 3084 | + sign_ctx, | ||
| 3085 | + rdoq_lambda(), | ||
| 3017 | tx_type, | 3086 | tx_type, |
| 3018 | ); | 3087 | ); |
| 3019 | (levels, Some(bits)) | 3088 | (levels, Some(bits)) |
| 3020 | } else { | 3089 | } else { |
| 3021 | ( | 3090 | ( |
| 3022 | forward_and_quantize_typed( | 3091 | forward_and_quantize_typed( |
| 3023 | - residual, side, 8, i32::from(base_q_idx), deadzone, tx_type, | 3092 | + residual, |
| 3093 | + side, | ||
| 3094 | + 8, | ||
| 3095 | + i32::from(base_q_idx), | ||
| 3096 | + deadzone, | ||
| 3097 | + tx_type, | ||
| 3024 | ), | 3098 | ), |
| 3025 | None, | 3099 | None, |
| 3026 | ) | 3100 | ) |
| @@ -3113,9 +3187,12 @@ impl Plane<'_> { | |||
| 3113 | // per unit (decode.rs `decode_block`, `push_intra_rect`'s | 3187 | // per unit (decode.rs `decode_block`, `push_intra_rect`'s |
| 3114 | // `filter_intra`), not once over the whole block. | 3188 | // `filter_intra`), not once over the whole block. |
| 3115 | filter_intra: Option<u8>, | 3189 | filter_intra: Option<u8>, |
| 3116 | - search: &Search, fctx: &crate::decode::FrameCtx, | 3190 | + search: &Search, |
| 3191 | + fctx: &crate::decode::FrameCtx, | ||
| 3117 | ) -> (Vec<i32>, f64, f64, Vec<TxType>) { | 3192 | ) -> (Vec<i32>, f64, f64, Vec<TxType>) { |
| 3118 | - let At { x, y, side, reach, .. } = at; | 3193 | + let At { |
| 3194 | + x, y, side, reach, .. | ||
| 3195 | + } = at; | ||
| 3119 | let tx = side >> depth; | 3196 | let tx = side >> depth; |
| 3120 | let n = 1usize << depth; | 3197 | let n = 1usize << depth; |
| 3121 | let set = luma_set_for( | 3198 | let set = luma_set_for( |
| @@ -3150,9 +3227,16 @@ impl Plane<'_> { | |||
| 3150 | }; | 3227 | }; |
| 3151 | let trial = match filter_intra { | 3228 | let trial = match filter_intra { |
| 3152 | Some(fi) => { | 3229 | Some(fi) => { |
| 3153 | - let (mut above_buf, mut left_buf) = ([0u8; 2 * SUPERBLOCK], [0u8; 2 * SUPERBLOCK]); | 3230 | + let (mut above_buf, mut left_buf) = |
| 3154 | - let (above, left, corner) = | 3231 | + ([0u8; 2 * SUPERBLOCK], [0u8; 2 * SUPERBLOCK]); |
| 3155 | - self.edges_into(tu.x, tu.y, tx, tu.reach, &mut above_buf, &mut left_buf); | 3232 | + let (above, left, corner) = self.edges_into( |
| 3233 | + tu.x, | ||
| 3234 | + tu.y, | ||
| 3235 | + tx, | ||
| 3236 | + tu.reach, | ||
| 3237 | + &mut above_buf, | ||
| 3238 | + &mut left_buf, | ||
| 3239 | + ); | ||
| 3156 | let mut prediction = vec![0u8; tx * tx]; | 3240 | let mut prediction = vec![0u8; tx * tx]; |
| 3157 | filter_intra_predict_u8( | 3241 | filter_intra_predict_u8( |
| 3158 | usize::from(fi), | 3242 | usize::from(fi), |
| @@ -3182,8 +3266,13 @@ impl Plane<'_> { | |||
| 3182 | let mut best: Option<(f64, TxType, Trial)> = None; | 3266 | let mut best: Option<(f64, TxType, Trial)> = None; |
| 3183 | for &tx_type in tx_type_candidates(set, search.screen) { | 3267 | for &tx_type in tx_type_candidates(set, search.screen) { |
| 3184 | let candidate = self.trial_typed( | 3268 | let candidate = self.trial_typed( |
| 3185 | - tu, mode, angle_delta, search.base_q_idx, search.deadzone, | 3269 | + tu, |
| 3186 | - tx_type, fctx, | 3270 | + mode, |
| 3271 | + angle_delta, | ||
| 3272 | + search.base_q_idx, | ||
| 3273 | + search.deadzone, | ||
| 3274 | + tx_type, | ||
| 3275 | + fctx, | ||
| 3187 | ); | 3276 | ); |
| 3188 | // lane-txi: a non-`DCT_DCT` type is charged its | 3277 | // lane-txi: a non-`DCT_DCT` type is charged its |
| 3189 | // bits at `EC_AV1_TXRD_LAMBDA` times the mode | 3278 | // bits at `EC_AV1_TXRD_LAMBDA` times the mode |
| @@ -3201,8 +3290,7 @@ impl Plane<'_> { | |||
| 3201 | best = Some((cost, tx_type, candidate)); | 3290 | best = Some((cost, tx_type, candidate)); |
| 3202 | } | 3291 | } |
| 3203 | } | 3292 | } |
| 3204 | - let (_, tx_type, trial) = | 3293 | + let (_, tx_type, trial) = best.expect("the candidate list is never empty"); |
| 3205 | - best.expect("the candidate list is never empty"); | ||
| 3206 | tx_types[tu_row * n + tu_col] = tx_type; | 3294 | tx_types[tu_row * n + tu_col] = tx_type; |
| 3207 | TX_TYPE_HITS[tx_type as usize] | 3295 | TX_TYPE_HITS[tx_type as usize] |
| 3208 | .fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 3296 | .fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| @@ -3343,8 +3431,7 @@ impl Plane<'_> { | |||
| 3343 | fn source_block_rect(&self, x: usize, y: usize, w: usize, h: usize) -> Vec<u8> { | 3431 | fn source_block_rect(&self, x: usize, y: usize, w: usize, h: usize) -> Vec<u8> { |
| 3344 | let mut out = vec![0u8; w * h]; | 3432 | let mut out = vec![0u8; w * h]; |
| 3345 | for row in 0..h { | 3433 | for row in 0..h { |
| 3346 | - out[row * w..][..w] | 3434 | + out[row * w..][..w].copy_from_slice(&self.source[(y + row) * self.width + x..][..w]); |
| 3347 | - .copy_from_slice(&self.source[(y + row) * self.width + x..][..w]); | ||
| 3348 | } | 3435 | } |
| 3349 | out | 3436 | out |
| 3350 | } | 3437 | } |
| @@ -3403,7 +3490,8 @@ impl Plane<'_> { | |||
| 3403 | at: At, | 3490 | at: At, |
| 3404 | modes: &[u8], | 3491 | modes: &[u8], |
| 3405 | mode_bits: &[f64; 13], | 3492 | mode_bits: &[f64; 13], |
| 3406 | - lambda: f64, fctx: &crate::decode::FrameCtx, | 3493 | + lambda: f64, |
| 3494 | + fctx: &crate::decode::FrameCtx, | ||
| 3407 | ) -> Vec<(f64, u8)> { | 3495 | ) -> Vec<(f64, u8)> { |
| 3408 | let At { | 3496 | let At { |
| 3409 | x, y, side, reach, .. | 3497 | x, y, side, reach, .. |
| @@ -3425,7 +3513,8 @@ impl Plane<'_> { | |||
| 3425 | side, | 3513 | side, |
| 3426 | false, | 3514 | false, |
| 3427 | false, | 3515 | false, |
| 3428 | - &mut prediction, fctx, | 3516 | + &mut prediction, |
| 3517 | + fctx, | ||
| 3429 | ); | 3518 | ); |
| 3430 | let sad = self.block_sad(x, y, side, &prediction); | 3519 | let sad = self.block_sad(x, y, side, &prediction); |
| 3431 | (sad + lambda * mode_bits[usize::from(mode)], mode) | 3520 | (sad + lambda * mode_bits[usize::from(mode)], mode) |
| @@ -3447,7 +3536,8 @@ impl Plane<'_> { | |||
| 3447 | &mut self, | 3536 | &mut self, |
| 3448 | at: At, | 3537 | at: At, |
| 3449 | search: &Search, | 3538 | search: &Search, |
| 3450 | - mode_bits: &[f64; 13], fctx: &crate::decode::FrameCtx, | 3539 | + mode_bits: &[f64; 13], |
| 3540 | + fctx: &crate::decode::FrameCtx, | ||
| 3451 | ) -> (Vec<Coeff>, u8, i32, f64, TxType) { | 3541 | ) -> (Vec<Coeff>, u8, i32, f64, TxType) { |
| 3452 | let At { | 3542 | let At { |
| 3453 | x, y, side, reach, .. | 3543 | x, y, side, reach, .. |
| @@ -3475,7 +3565,8 @@ impl Plane<'_> { | |||
| 3475 | side, | 3565 | side, |
| 3476 | false, | 3566 | false, |
| 3477 | false, | 3567 | false, |
| 3478 | - &mut prediction, fctx, | 3568 | + &mut prediction, |
| 3569 | + fctx, | ||
| 3479 | ); | 3570 | ); |
| 3480 | let sad = if want_sad { | 3571 | let sad = if want_sad { |
| 3481 | self.block_sad(x, y, side, &prediction) | 3572 | self.block_sad(x, y, side, &prediction) |
| @@ -3505,7 +3596,10 @@ impl Plane<'_> { | |||
| 3505 | } | 3596 | } |
| 3506 | } | 3597 | } |
| 3507 | let ranking: Vec<(f64, u8)> = if census_on() { | 3598 | let ranking: Vec<(f64, u8)> = if census_on() { |
| 3508 | - scored.iter().map(|&(score, mode, _)| (score, mode)).collect() | 3599 | + scored |
| 3600 | + .iter() | ||
| 3601 | + .map(|&(score, mode, _)| (score, mode)) | ||
| 3602 | + .collect() | ||
| 3509 | } else { | 3603 | } else { |
| 3510 | Vec::new() | 3604 | Vec::new() |
| 3511 | }; | 3605 | }; |
| @@ -3563,7 +3657,8 @@ impl Plane<'_> { | |||
| 3563 | side, | 3657 | side, |
| 3564 | false, | 3658 | false, |
| 3565 | false, | 3659 | false, |
| 3566 | - &mut prediction, fctx, | 3660 | + &mut prediction, |
| 3661 | + fctx, | ||
| 3567 | ); | 3662 | ); |
| 3568 | let candidate = self.code_from_prediction( | 3663 | let candidate = self.code_from_prediction( |
| 3569 | x, | 3664 | x, |
| @@ -3575,8 +3670,9 @@ impl Plane<'_> { | |||
| 3575 | search.deadzone, | 3670 | search.deadzone, |
| 3576 | at.set, | 3671 | at.set, |
| 3577 | ); | 3672 | ); |
| 3578 | - let bits = symbol_bits(row, (crate::tile::ANGLE_DELTA_ZERO as i32 + delta) as usize) | 3673 | + let bits = |
| 3579 | - - zero_bits; | 3674 | + symbol_bits(row, (crate::tile::ANGLE_DELTA_ZERO as i32 + delta) as usize) |
| 3675 | + - zero_bits; | ||
| 3580 | let cost_d = candidate.sse | 3676 | let cost_d = candidate.sse |
| 3581 | + search.lambda * (candidate.bits + mode_bits[usize::from(mode)] + bits); | 3677 | + search.lambda * (candidate.bits + mode_bits[usize::from(mode)] + bits); |
| 3582 | if cost_d < cost { | 3678 | if cost_d < cost { |
| @@ -3594,7 +3690,13 @@ impl Plane<'_> { | |||
| 3594 | let mut tx_type = TxType::DctDct; | 3690 | let mut tx_type = TxType::DctDct; |
| 3595 | for &candidate_type in tx_type_candidates(at.set, search.screen).iter().skip(1) { | 3691 | for &candidate_type in tx_type_candidates(at.set, search.screen).iter().skip(1) { |
| 3596 | let candidate = self.trial_typed( | 3692 | let candidate = self.trial_typed( |
| 3597 | - at, mode, angle_delta, search.base_q_idx, search.deadzone, candidate_type, fctx, | 3693 | + at, |
| 3694 | + mode, | ||
| 3695 | + angle_delta, | ||
| 3696 | + search.base_q_idx, | ||
| 3697 | + search.deadzone, | ||
| 3698 | + candidate_type, | ||
| 3699 | + fctx, | ||
| 3598 | ); | 3700 | ); |
| 3599 | let cost_t = | 3701 | let cost_t = |
| 3600 | candidate.sse + search.lambda * (candidate.bits + mode_bits[usize::from(mode)]); | 3702 | candidate.sse + search.lambda * (candidate.bits + mode_bits[usize::from(mode)]); |
| @@ -3615,7 +3717,13 @@ impl Plane<'_> { | |||
| 3615 | self.commit(x, y, side, &trial); | 3717 | self.commit(x, y, side, &trial); |
| 3616 | // A 64-point transform codes only its top-left 32x32 corner, which is | 3718 | // A 64-point transform codes only its top-left 32x32 corner, which is |
| 3617 | // the grid `code_from_prediction` hands back (lane-i64). | 3719 | // the grid `code_from_prediction` hands back (lane-i64). |
| 3618 | - (coeffs(&trial.levels, side.min(BLOCK)), mode, angle_delta, cost, tx_type) | 3720 | + ( |
| 3721 | + coeffs(&trial.levels, side.min(BLOCK)), | ||
| 3722 | + mode, | ||
| 3723 | + angle_delta, | ||
| 3724 | + cost, | ||
| 3725 | + tx_type, | ||
| 3726 | + ) | ||
| 3619 | } | 3727 | } |
| 3620 | } | 3728 | } |
| 3621 | 3729 | ||
| @@ -3662,7 +3770,6 @@ const HAS_TOP_RIGHT: [&[u8]; 4] = [ | |||
| 3662 | 255, 255, 85, 85, 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, 255, 127, 85, 85, | 3770 | 255, 255, 85, 85, 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, 255, 127, 85, 85, |
| 3663 | 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, | 3771 | 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, |
| 3664 | ], | 3772 | ], |
| 3665 | - | ||
| 3666 | // has_tr_4x4 (libaom av1/common/reconintra.c, transcribed verbatim) -- | 3773 | // has_tr_4x4 (libaom av1/common/reconintra.c, transcribed verbatim) -- |
| 3667 | // table_stride(4) == 32 (128 / 4), so 32 bits per row, 32 rows, 128 | 3774 | // table_stride(4) == 32 (128 / 4), so 32 bits per row, 32 rows, 128 |
| 3668 | // bytes. Sub-8x8 leaves (lane-sub8) are the only blocks that reach here | 3775 | // bytes. Sub-8x8 leaves (lane-sub8) are the only blocks that reach here |
| @@ -3691,7 +3798,6 @@ const HAS_BOTTOM_LEFT: [&[u8]; 4] = [ | |||
| 3691 | 84, 85, 16, 17, 84, 85, 0, 1, 84, 85, 16, 17, 84, 85, 0, 0, 84, 85, 16, 17, 84, 85, 0, 1, | 3798 | 84, 85, 16, 17, 84, 85, 0, 1, 84, 85, 16, 17, 84, 85, 0, 0, 84, 85, 16, 17, 84, 85, 0, 1, |
| 3692 | 84, 85, 16, 17, 84, 85, 0, 0, | 3799 | 84, 85, 16, 17, 84, 85, 0, 0, |
| 3693 | ], | 3800 | ], |
| 3694 | - | ||
| 3695 | // has_bl_4x4 (same source, same order). | 3801 | // has_bl_4x4 (same source, same order). |
| 3696 | &[ | 3802 | &[ |
| 3697 | 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85, 16, 17, 17, 17, | 3803 | 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85, 16, 17, 17, 17, |
| @@ -3770,21 +3876,42 @@ impl Drop for VertAbGuard { | |||
| 3770 | /// 10 of the 21 reachable superblock positions for above-right and 7 for | 3876 | /// 10 of the 21 reachable superblock positions for above-right and 7 for |
| 3771 | /// below-left. | 3877 | /// below-left. |
| 3772 | /// `has_tr_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). | 3878 | /// `has_tr_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). |
| 3773 | -const HAS_TR_4X8: [u8; 64] = [255, 255, 255, 255, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 255, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119]; | 3879 | +const HAS_TR_4X8: [u8; 64] = [ |
| 3880 | + 255, 255, 255, 255, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, | ||
| 3881 | + 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 255, 255, 127, 119, 119, | ||
| 3882 | + 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, | ||
| 3883 | + 127, 127, 127, 119, 119, 119, 119, | ||
| 3884 | +]; | ||
| 3774 | /// `has_bl_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). | 3885 | /// `has_bl_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). |
| 3775 | -const HAS_BL_4X8: [u8; 64] = [16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0]; | 3886 | +const HAS_BL_4X8: [u8; 64] = [ |
| 3887 | + 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, | ||
| 3888 | + 17, 0, 0, 0, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, | ||
| 3889 | + 1, 1, 16, 17, 17, 17, 0, 0, 0, 0, | ||
| 3890 | +]; | ||
| 3776 | /// `has_tr_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). | 3891 | /// `has_tr_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). |
| 3777 | -const HAS_TR_8X4: [u8; 64] = [255, 255, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 255, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0]; | 3892 | +const HAS_TR_8X4: [u8; 64] = [ |
| 3893 | + 255, 255, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, | ||
| 3894 | + 119, 0, 0, 85, 85, 0, 0, 255, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, | ||
| 3895 | + 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, | ||
| 3896 | +]; | ||
| 3778 | /// `has_bl_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). | 3897 | /// `has_bl_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). |
| 3779 | -const HAS_BL_8X4: [u8; 64] = [254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0]; | 3898 | +const HAS_BL_8X4: [u8; 64] = [ |
| 3899 | + 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, | ||
| 3900 | + 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, | ||
| 3901 | + 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, | ||
| 3902 | +]; | ||
| 3780 | /// `has_tr_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). | 3903 | /// `has_tr_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). |
| 3781 | -const HAS_TR_8X16: [u8; 16] = [255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119, 119]; | 3904 | +const HAS_TR_8X16: [u8; 16] = [ |
| 3905 | + 255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119, 119, | ||
| 3906 | +]; | ||
| 3782 | /// `has_bl_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). | 3907 | /// `has_bl_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). |
| 3783 | const HAS_BL_8X16: [u8; 16] = [16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0]; | 3908 | const HAS_BL_8X16: [u8; 16] = [16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0]; |
| 3784 | /// `has_tr_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). | 3909 | /// `has_tr_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). |
| 3785 | const HAS_TR_16X8: [u8; 16] = [255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0]; | 3910 | const HAS_TR_16X8: [u8; 16] = [255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0]; |
| 3786 | /// `has_bl_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). | 3911 | /// `has_bl_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). |
| 3787 | -const HAS_BL_16X8: [u8; 16] = [254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0]; | 3912 | +const HAS_BL_16X8: [u8; 16] = [ |
| 3913 | + 254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0, | ||
| 3914 | +]; | ||
| 3788 | /// `has_tr_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). | 3915 | /// `has_tr_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). |
| 3789 | const HAS_TR_16X32: [u8; 4] = [255, 119, 127, 119]; | 3916 | const HAS_TR_16X32: [u8; 4] = [255, 119, 127, 119]; |
| 3790 | /// `has_bl_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). | 3917 | /// `has_bl_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). |
| @@ -3802,13 +3929,24 @@ const HAS_TR_64X32: [u8; 1] = [19]; | |||
| 3802 | /// `has_bl_64x32` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 2 bits (`128 / 64`). | 3929 | /// `has_bl_64x32` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 2 bits (`128 / 64`). |
| 3803 | const HAS_BL_64X32: [u8; 1] = [34]; | 3930 | const HAS_BL_64X32: [u8; 1] = [34]; |
| 3804 | /// `has_tr_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). | 3931 | /// `has_tr_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). |
| 3805 | -const HAS_TR_4X16: [u8; 32] = [255, 255, 255, 255, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127, 255, 255, 255, 127, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127]; | 3932 | +const HAS_TR_4X16: [u8; 32] = [ |
| 3933 | + 255, 255, 255, 255, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127, 255, 255, 255, | ||
| 3934 | + 127, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127, | ||
| 3935 | +]; | ||
| 3806 | /// `has_bl_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). | 3936 | /// `has_bl_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). |
| 3807 | -const HAS_BL_4X16: [u8; 32] = [0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0]; | 3937 | +const HAS_BL_4X16: [u8; 32] = [ |
| 3938 | + 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, | ||
| 3939 | +]; | ||
| 3808 | /// `has_tr_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). | 3940 | /// `has_tr_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). |
| 3809 | -const HAS_TR_16X4: [u8; 32] = [255, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0, 127, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0]; | 3941 | +const HAS_TR_16X4: [u8; 32] = [ |
| 3942 | + 255, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0, 127, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, | ||
| 3943 | + 85, 0, 0, 0, | ||
| 3944 | +]; | ||
| 3810 | /// `has_bl_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). | 3945 | /// `has_bl_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). |
| 3811 | -const HAS_BL_16X4: [u8; 32] = [254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0, 254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0]; | 3946 | +const HAS_BL_16X4: [u8; 32] = [ |
| 3947 | + 254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0, 254, 254, 254, 84, | ||
| 3948 | + 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0, | ||
| 3949 | +]; | ||
| 3812 | /// `has_tr_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). | 3950 | /// `has_tr_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). |
| 3813 | const HAS_TR_8X32: [u8; 8] = [255, 255, 127, 127, 255, 127, 127, 127]; | 3951 | const HAS_TR_8X32: [u8; 8] = [255, 255, 127, 127, 255, 127, 127, 127]; |
| 3814 | /// `has_bl_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). | 3952 | /// `has_bl_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). |
| @@ -3911,7 +4049,14 @@ impl Reach { | |||
| 3911 | 4049 | ||
| 3912 | /// What a block of `side` samples at `(x, y)` may read past its own edges, | 4050 | /// What a block of `side` samples at `(x, y)` may read past its own edges, |
| 3913 | /// in a frame of `width` by `height`. | 4051 | /// in a frame of `width` by `height`. |
| 3914 | - pub(crate) fn of(side: usize, x: usize, y: usize, width: usize, height: usize, fctx: &crate::decode::FrameCtx) -> Self { | 4052 | + pub(crate) fn of( |
| 4053 | + side: usize, | ||
| 4054 | + x: usize, | ||
| 4055 | + y: usize, | ||
| 4056 | + width: usize, | ||
| 4057 | + height: usize, | ||
| 4058 | + fctx: &crate::decode::FrameCtx, | ||
| 4059 | + ) -> Self { | ||
| 3915 | Self { | 4060 | Self { |
| 3916 | above_right: y > 0 && x + side < width && Self::top_right(side, x, y, fctx), | 4061 | above_right: y > 0 && x + side < width && Self::top_right(side, x, y, fctx), |
| 3917 | below_left: x > 0 && y + side < height && Self::bottom_left(side, x, y, fctx), | 4062 | below_left: x > 0 && y + side < height && Self::bottom_left(side, x, y, fctx), |
| @@ -3929,7 +4074,8 @@ impl Reach { | |||
| 3929 | x: usize, | 4074 | x: usize, |
| 3930 | y: usize, | 4075 | y: usize, |
| 3931 | width: usize, | 4076 | width: usize, |
| 3932 | - height: usize, fctx: &crate::decode::FrameCtx, | 4077 | + height: usize, |
| 4078 | + fctx: &crate::decode::FrameCtx, | ||
| 3933 | ) -> Self { | 4079 | ) -> Self { |
| 3934 | Self { | 4080 | Self { |
| 3935 | above_right: y > 0 && x + bw < width && Self::top_right_rect(bw, bh, x, y, fctx), | 4081 | above_right: y > 0 && x + bw < width && Self::top_right_rect(bw, bh, x, y, fctx), |
| @@ -3948,10 +4094,16 @@ impl Reach { | |||
| 3948 | /// no 4x4 row at all (`has_tr_vert_tables[BLOCK_4X4]` is NULL), so a TX4 | 4094 | /// no 4x4 row at all (`has_tr_vert_tables[BLOCK_4X4]` is NULL), so a TX4 |
| 3949 | /// unit inside an 8x8 square of a `PARTITION_VERT_A`/`_B` panicked on a | 4095 | /// unit inside an 8x8 square of a `PARTITION_VERT_A`/`_B` panicked on a |
| 3950 | /// real `--enable-tx-size-search=1` stream (lane-ab16 r2). | 4096 | /// real `--enable-tx-size-search=1` stream (lane-ab16 r2). |
| 3951 | - /// libaom `has_top_right` at block granularity (`row_off`/`col_off` 0, | 4097 | + /// libaom `has_top_right` at block granularity (`row_off`/`col_off` 0, |
| 3952 | /// the transform covering the whole block, luma): everything before the | 4098 | /// the transform covering the whole block, luma): everything before the |
| 3953 | /// table lookup is that function's own early-exit ladder. | 4099 | /// table lookup is that function's own early-exit ladder. |
| 3954 | - fn top_right_rect(bw: usize, bh: usize, x: usize, y: usize, fctx: &crate::decode::FrameCtx) -> bool { | 4100 | + fn top_right_rect( |
| 4101 | + bw: usize, | ||
| 4102 | + bh: usize, | ||
| 4103 | + x: usize, | ||
| 4104 | + y: usize, | ||
| 4105 | + fctx: &crate::decode::FrameCtx, | ||
| 4106 | + ) -> bool { | ||
| 3955 | let sb_mi: usize = reach_sb_px(fctx) / 4; | 4107 | let sb_mi: usize = reach_sb_px(fctx) / 4; |
| 3956 | let (mi_row, mi_col) = (y / 4, x / 4); | 4108 | let (mi_row, mi_col) = (y / 4, x / 4); |
| 3957 | let bw_log2 = (bw / 4).trailing_zeros() as usize; | 4109 | let bw_log2 = (bw / 4).trailing_zeros() as usize; |
| @@ -3984,7 +4136,13 @@ impl Reach { | |||
| 3984 | } | 4136 | } |
| 3985 | 4137 | ||
| 3986 | /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`]. | 4138 | /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`]. |
| 3987 | - fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize, fctx: &crate::decode::FrameCtx) -> bool { | 4139 | + fn bottom_left_rect( |
| 4140 | + bw: usize, | ||
| 4141 | + bh: usize, | ||
| 4142 | + x: usize, | ||
| 4143 | + y: usize, | ||
| 4144 | + fctx: &crate::decode::FrameCtx, | ||
| 4145 | + ) -> bool { | ||
| 3988 | let sb_mi: usize = reach_sb_px(fctx) / 4; | 4146 | let sb_mi: usize = reach_sb_px(fctx) / 4; |
| 3989 | let (mi_row, mi_col) = (y / 4, x / 4); | 4147 | let (mi_row, mi_col) = (y / 4, x / 4); |
| 3990 | let bw_log2 = (bw / 4).trailing_zeros() as usize; | 4148 | let bw_log2 = (bw / 4).trailing_zeros() as usize; |
| @@ -4054,7 +4212,9 @@ impl Reach { | |||
| 4054 | // position inside the superblock and is what the bit index below | 4212 | // position inside the superblock and is what the bit index below |
| 4055 | // steps by (a merge that shadowed it desynced every block size). | 4213 | // steps by (a merge that shadowed it desynced every block size). |
| 4056 | let table_row = Self::table(side); | 4214 | let table_row = Self::table(side); |
| 4057 | - let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) && table_row < HAS_TOP_RIGHT_VERT.len() { | 4215 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) |
| 4216 | + && table_row < HAS_TOP_RIGHT_VERT.len() | ||
| 4217 | + { | ||
| 4058 | HAS_TOP_RIGHT_VERT[table_row] | 4218 | HAS_TOP_RIGHT_VERT[table_row] |
| 4059 | } else { | 4219 | } else { |
| 4060 | HAS_TOP_RIGHT[table_row] | 4220 | HAS_TOP_RIGHT[table_row] |
| @@ -4089,7 +4249,9 @@ impl Reach { | |||
| 4089 | // position inside the superblock and is what the bit index below | 4249 | // position inside the superblock and is what the bit index below |
| 4090 | // steps by (a merge that shadowed it desynced every block size). | 4250 | // steps by (a merge that shadowed it desynced every block size). |
| 4091 | let table_row = Self::table(side); | 4251 | let table_row = Self::table(side); |
| 4092 | - let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) && table_row < HAS_BOTTOM_LEFT_VERT.len() { | 4252 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) |
| 4253 | + && table_row < HAS_BOTTOM_LEFT_VERT.len() | ||
| 4254 | + { | ||
| 4093 | HAS_BOTTOM_LEFT_VERT[table_row] | 4255 | HAS_BOTTOM_LEFT_VERT[table_row] |
| 4094 | } else { | 4256 | } else { |
| 4095 | HAS_BOTTOM_LEFT[table_row] | 4257 | HAS_BOTTOM_LEFT[table_row] |
| @@ -4102,7 +4264,12 @@ impl Reach { | |||
| 4102 | 4264 | ||
| 4103 | /// Where a block sits inside its superblock, in blocks of its own size, | 4265 | /// Where a block sits inside its superblock, in blocks of its own size, |
| 4104 | /// and how many of them a superblock is across. | 4266 | /// and how many of them a superblock is across. |
| 4105 | - fn position(side: usize, x: usize, y: usize, fctx: &crate::decode::FrameCtx) -> (usize, usize, usize) { | 4267 | + fn position( |
| 4268 | + side: usize, | ||
| 4269 | + x: usize, | ||
| 4270 | + y: usize, | ||
| 4271 | + fctx: &crate::decode::FrameCtx, | ||
| 4272 | + ) -> (usize, usize, usize) { | ||
| 4106 | let sb = reach_sb_px(fctx); | 4273 | let sb = reach_sb_px(fctx); |
| 4107 | ((y % sb) / side, (x % sb) / side, sb / side) | 4274 | ((y % sb) / side, (x % sb) / side, sb / side) |
| 4108 | } | 4275 | } |
| @@ -4147,7 +4314,9 @@ impl Reach { | |||
| 4147 | /// bits -- back off for an A/B on one build. | 4314 | /// bits -- back off for an A/B on one build. |
| 4148 | pub(crate) fn warp_on() -> bool { | 4315 | pub(crate) fn warp_on() -> bool { |
| 4149 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 4316 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 4150 | - crate::envflags::var("EC_AV1_WARP").ok().map(|v| !matches!(v.as_str(), "0" | "off")) | 4317 | + crate::envflags::var("EC_AV1_WARP") |
| 4318 | + .ok() | ||
| 4319 | + .map(|v| !matches!(v.as_str(), "0" | "off")) | ||
| 4151 | }); | 4320 | }); |
| 4152 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::WARP)) | 4321 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::WARP)) |
| 4153 | } | 4322 | } |
| @@ -4400,12 +4569,9 @@ fn warp_prediction( | |||
| 4400 | /// was LAST+GOLDEN or LAST+ALTREF: `comp_bwdref[0][0] = 1` prices a BWDREF or | 4569 | /// was LAST+GOLDEN or LAST+ALTREF: `comp_bwdref[0][0] = 1` prices a BWDREF or |
| 4401 | /// ALTREF2 partner as ALTREF and drops its `p6` symbol entirely, and the | 4570 | /// ALTREF2 partner as ALTREF and drops its `p6` symbol entirely, and the |
| 4402 | /// `uni_comp_ref` leaves price a LAST+LAST2 pair as LAST+GOLDEN. | 4571 | /// `uni_comp_ref` leaves price a LAST+LAST2 pair as LAST+GOLDEN. |
| 4403 | -pub(crate) fn compound_ref_bits( | 4572 | +pub(crate) fn compound_ref_bits((ref0, ref1): (i8, i8), stack: &crate::mvstack::MvStack) -> f64 { |
| 4404 | - (ref0, ref1): (i8, i8), | ||
| 4405 | - stack: &crate::mvstack::MvStack, | ||
| 4406 | -) -> f64 { | ||
| 4407 | use crate::mvstack::{ | 4573 | use crate::mvstack::{ |
| 4408 | - ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, | 4574 | + ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, |
| 4409 | comp_reference_type_ctx, is_uni_comp_ref, single_ref_p1_ctx, single_ref_p2_ctx, | 4575 | comp_reference_type_ctx, is_uni_comp_ref, single_ref_p1_ctx, single_ref_p2_ctx, |
| 4410 | single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, | 4576 | single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, |
| 4411 | uni_comp_ref_p1_ctx, | 4577 | uni_comp_ref_p1_ctx, |
| @@ -4526,7 +4692,7 @@ fn comp_mode_single_bits(stack: &crate::mvstack::MvStack) -> f64 { | |||
| 4526 | /// paid nothing at all, so compound was overcharged by the whole symbol. | 4692 | /// paid nothing at all, so compound was overcharged by the whole symbol. |
| 4527 | pub(crate) fn single_ref_bits(ref_frame: i8, stack: &crate::mvstack::MvStack) -> f64 { | 4693 | pub(crate) fn single_ref_bits(ref_frame: i8, stack: &crate::mvstack::MvStack) -> f64 { |
| 4528 | use crate::mvstack::{ | 4694 | use crate::mvstack::{ |
| 4529 | - ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, | 4695 | + ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, |
| 4530 | single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, | 4696 | single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, |
| 4531 | single_ref_p5_ctx, single_ref_p6_ctx, | 4697 | single_ref_p5_ctx, single_ref_p6_ctx, |
| 4532 | }; | 4698 | }; |
| @@ -4557,20 +4723,23 @@ pub(crate) fn single_ref_bits(ref_frame: i8, stack: &crate::mvstack::MvStack) -> | |||
| 4557 | }; | 4723 | }; |
| 4558 | } | 4724 | } |
| 4559 | let far = ref_frame == LAST3_FRAME || ref_frame == GOLDEN_FRAME; | 4725 | let far = ref_frame == LAST3_FRAME || ref_frame == GOLDEN_FRAME; |
| 4560 | - comp_mode + p1 + symbol_bits( | 4726 | + comp_mode |
| 4561 | - &cdf::SINGLE_REF[single_ref_p3_ctx(a, a1, l, l1)][2], | 4727 | + + p1 |
| 4562 | - usize::from(far), | 4728 | + + symbol_bits( |
| 4563 | - ) + if far { | 4729 | + &cdf::SINGLE_REF[single_ref_p3_ctx(a, a1, l, l1)][2], |
| 4564 | - symbol_bits( | 4730 | + usize::from(far), |
| 4565 | - &cdf::SINGLE_REF[single_ref_p5_ctx(a, a1, l, l1)][4], | ||
| 4566 | - usize::from(ref_frame == GOLDEN_FRAME), | ||
| 4567 | - ) | ||
| 4568 | - } else { | ||
| 4569 | - symbol_bits( | ||
| 4570 | - &cdf::SINGLE_REF[single_ref_p4_ctx(a, a1, l, l1)][3], | ||
| 4571 | - usize::from(ref_frame == LAST2_FRAME), | ||
| 4572 | ) | 4731 | ) |
| 4573 | - } | 4732 | + + if far { |
| 4733 | + symbol_bits( | ||
| 4734 | + &cdf::SINGLE_REF[single_ref_p5_ctx(a, a1, l, l1)][4], | ||
| 4735 | + usize::from(ref_frame == GOLDEN_FRAME), | ||
| 4736 | + ) | ||
| 4737 | + } else { | ||
| 4738 | + symbol_bits( | ||
| 4739 | + &cdf::SINGLE_REF[single_ref_p4_ctx(a, a1, l, l1)][3], | ||
| 4740 | + usize::from(ref_frame == LAST2_FRAME), | ||
| 4741 | + ) | ||
| 4742 | + } | ||
| 4574 | } | 4743 | } |
| 4575 | 4744 | ||
| 4576 | pub(crate) fn symbol_bits(cdf: &[u16], symbol: usize) -> f64 { | 4745 | pub(crate) fn symbol_bits(cdf: &[u16], symbol: usize) -> f64 { |
| @@ -4698,7 +4867,11 @@ fn split_census( | |||
| 4698 | } else { | 4867 | } else { |
| 4699 | 6 | 4868 | 6 |
| 4700 | }; | 4869 | }; |
| 4701 | - let (win, lose) = if split_won { (split, flat) } else { (flat, split) }; | 4870 | + let (win, lose) = if split_won { |
| 4871 | + (split, flat) | ||
| 4872 | + } else { | ||
| 4873 | + (flat, split) | ||
| 4874 | + }; | ||
| 4702 | add(off, (win.0 * 64.0).max(0.0) as u64); | 4875 | add(off, (win.0 * 64.0).max(0.0) as u64); |
| 4703 | add(off + 1, win.1.max(0.0) as u64); | 4876 | add(off + 1, win.1.max(0.0) as u64); |
| 4704 | add(off + 2, (lose.0 * 64.0).max(0.0) as u64); | 4877 | add(off + 2, (lose.0 * 64.0).max(0.0) as u64); |
| @@ -4831,7 +5004,10 @@ fn newmv_census_block( | |||
| 4831 | } else { | 5004 | } else { |
| 4832 | add(4, (new_cost - other_cost).max(0.0) as u64); | 5005 | add(4, (new_cost - other_cost).max(0.0) as u64); |
| 4833 | } | 5006 | } |
| 4834 | - add(5, ((mv.0 - nearest.0).unsigned_abs() + (mv.1 - nearest.1).unsigned_abs()) as u64); | 5007 | + add( |
| 5008 | + 5, | ||
| 5009 | + ((mv.0 - nearest.0).unsigned_abs() + (mv.1 - nearest.1).unsigned_abs()) as u64, | ||
| 5010 | + ); | ||
| 4835 | if mv == nearest { | 5011 | if mv == nearest { |
| 4836 | add(6, 1); | 5012 | add(6, 1); |
| 4837 | } | 5013 | } |
| @@ -4886,8 +5062,16 @@ pub(crate) fn dump_newmv_census() { | |||
| 4886 | g[2], | 5062 | g[2], |
| 4887 | 100.0 * g[3] as f64 / g[2].max(1) as f64, | 5063 | 100.0 * g[3] as f64 / g[2].max(1) as f64, |
| 4888 | ); | 5064 | ); |
| 4889 | - let [calls, evals, _subpel, rounds, near_pred, unmoved, widest, widest_moves] = | 5065 | + let [ |
| 4890 | - crate::motion::take_census(); | 5066 | + calls, |
| 5067 | + evals, | ||
| 5068 | + _subpel, | ||
| 5069 | + rounds, | ||
| 5070 | + near_pred, | ||
| 5071 | + unmoved, | ||
| 5072 | + widest, | ||
| 5073 | + widest_moves, | ||
| 5074 | + ] = crate::motion::take_census(); | ||
| 4891 | let per = |n: u64| n as f64 / calls.max(1) as f64; | 5075 | let per = |n: u64| n as f64 / calls.max(1) as f64; |
| 4892 | eprintln!( | 5076 | eprintln!( |
| 4893 | "NEWMVCENSUS search: {calls} calls, {:.1} evals/call, {:.2} integer rounds/call; \ | 5077 | "NEWMVCENSUS search: {calls} calls, {:.1} evals/call, {:.2} integer rounds/call; \ |
| @@ -5019,7 +5203,9 @@ static INTER_TX_SPLIT_HITS: [std::sync::atomic::AtomicUsize; 8] = | |||
| 5019 | /// cannot pay for it (class `gate-blind-to-feature`). `EC_AV1_TX32_DEPTH`. | 5203 | /// cannot pay for it (class `gate-blind-to-feature`). `EC_AV1_TX32_DEPTH`. |
| 5020 | fn tx32_depth_search() -> bool { | 5204 | fn tx32_depth_search() -> bool { |
| 5021 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 5205 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 5022 | - crate::envflags::var("EC_AV1_TX32_DEPTH").ok().map(|v| !matches!(v.as_str(), "0" | "off")) | 5206 | + crate::envflags::var("EC_AV1_TX32_DEPTH") |
| 5207 | + .ok() | ||
| 5208 | + .map(|v| !matches!(v.as_str(), "0" | "off")) | ||
| 5023 | }); | 5209 | }); |
| 5024 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX32_DEPTH)) | 5210 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX32_DEPTH)) |
| 5025 | } | 5211 | } |
| @@ -5034,7 +5220,9 @@ fn tx32_depth_search() -> bool { | |||
| 5034 | /// `EC_AV1_COMP_VARTX`. | 5220 | /// `EC_AV1_COMP_VARTX`. |
| 5035 | fn compound_var_tx() -> bool { | 5221 | fn compound_var_tx() -> bool { |
| 5036 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 5222 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 5037 | - crate::envflags::var("EC_AV1_COMP_VARTX").ok().map(|v| !matches!(v.as_str(), "0" | "off")) | 5223 | + crate::envflags::var("EC_AV1_COMP_VARTX") |
| 5224 | + .ok() | ||
| 5225 | + .map(|v| !matches!(v.as_str(), "0" | "off")) | ||
| 5038 | }); | 5226 | }); |
| 5039 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::COMPOUND_VAR_TX)) | 5227 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::COMPOUND_VAR_TX)) |
| 5040 | } | 5228 | } |
| @@ -5112,18 +5300,44 @@ fn recode_inter_chroma( | |||
| 5112 | fctx: &crate::decode::FrameCtx, | 5300 | fctx: &crate::decode::FrameCtx, |
| 5113 | ) -> Option<[Trial; 2]> { | 5301 | ) -> Option<[Trial; 2]> { |
| 5114 | let c = side / 2; | 5302 | let c = side / 2; |
| 5115 | - let tx = crate::decode::reduce_inherited_chroma_tx_type(luma_tx_type, c.min(32), c.min(32), fctx); | 5303 | + let tx = |
| 5304 | + crate::decode::reduce_inherited_chroma_tx_type(luma_tx_type, c.min(32), c.min(32), fctx); | ||
| 5116 | if tx == TxType::DctDct { | 5305 | if tx == TxType::DctDct { |
| 5117 | return None; | 5306 | return None; |
| 5118 | } | 5307 | } |
| 5119 | Some([0usize, 1].map(|p| match second { | 5308 | Some([0usize, 1].map(|p| match second { |
| 5120 | Some((mv1, r1)) => mc_trial_compound_typed( | 5309 | Some((mv1, r1)) => mc_trial_compound_typed( |
| 5121 | - &chroma[p], x / 2, y / 2, c, (mv, mv1), false, refs[p], r1[p], search.base_q_idx, | 5310 | + &chroma[p], |
| 5122 | - search.deadzone, set, tx, fctx, | 5311 | + x / 2, |
| 5312 | + y / 2, | ||
| 5313 | + c, | ||
| 5314 | + (mv, mv1), | ||
| 5315 | + false, | ||
| 5316 | + refs[p], | ||
| 5317 | + r1[p], | ||
| 5318 | + search.base_q_idx, | ||
| 5319 | + search.deadzone, | ||
| 5320 | + set, | ||
| 5321 | + tx, | ||
| 5322 | + fctx, | ||
| 5123 | ), | 5323 | ), |
| 5124 | None => mc_trial_typed( | 5324 | None => mc_trial_typed( |
| 5125 | - &chroma[p], x / 2, y / 2, c, mv, false, refs[p].0, refs[p].1, refs[p].2, refs[p].3, | 5325 | + &chroma[p], |
| 5126 | - false, search.base_q_idx, search.deadzone, set, tx, fctx, | 5326 | + x / 2, |
| 5327 | + y / 2, | ||
| 5328 | + c, | ||
| 5329 | + mv, | ||
| 5330 | + false, | ||
| 5331 | + refs[p].0, | ||
| 5332 | + refs[p].1, | ||
| 5333 | + refs[p].2, | ||
| 5334 | + refs[p].3, | ||
| 5335 | + false, | ||
| 5336 | + search.base_q_idx, | ||
| 5337 | + search.deadzone, | ||
| 5338 | + set, | ||
| 5339 | + tx, | ||
| 5340 | + fctx, | ||
| 5127 | ), | 5341 | ), |
| 5128 | })) | 5342 | })) |
| 5129 | } | 5343 | } |
| @@ -5172,9 +5386,7 @@ fn commit_inter_luma( | |||
| 5172 | // seven-type candidate list below reachable -- and prices every | 5386 | // seven-type candidate list below reachable -- and prices every |
| 5173 | // candidate, `IDTX` included, in the alphabet its symbol is really | 5387 | // candidate, `IDTX` included, in the alphabet its symbol is really |
| 5174 | // coded into. | 5388 | // coded into. |
| 5175 | - if let Some(fset) = | 5389 | + if let Some(fset) = inter_luma_set(side).map(|set| luma_set_for(set, search.screen)) { |
| 5176 | - inter_luma_set(side).map(|set| luma_set_for(set, search.screen)) | ||
| 5177 | - { | ||
| 5178 | let lambda = search.lambda * tx_type_lambda_mult(); | 5390 | let lambda = search.lambda * tx_type_lambda_mult(); |
| 5179 | let cost = |t: &Trial| t.sse + lambda * t.bits; | 5391 | let cost = |t: &Trial| t.sse + lambda * t.bits; |
| 5180 | for &tx_type in inter_tx_type_candidates(fset, search.screen) { | 5392 | for &tx_type in inter_tx_type_candidates(fset, search.screen) { |
| @@ -5183,12 +5395,36 @@ fn commit_inter_luma( | |||
| 5183 | } | 5395 | } |
| 5184 | let candidate = match second { | 5396 | let candidate = match second { |
| 5185 | Some((mv1, ref1)) => mc_trial_compound_typed( | 5397 | Some((mv1, ref1)) => mc_trial_compound_typed( |
| 5186 | - luma, x, y, side, (mv, mv1), true, reference, ref1, search.base_q_idx, | 5398 | + luma, |
| 5187 | - search.deadzone, fset, tx_type, fctx, | 5399 | + x, |
| 5400 | + y, | ||
| 5401 | + side, | ||
| 5402 | + (mv, mv1), | ||
| 5403 | + true, | ||
| 5404 | + reference, | ||
| 5405 | + ref1, | ||
| 5406 | + search.base_q_idx, | ||
| 5407 | + search.deadzone, | ||
| 5408 | + fset, | ||
| 5409 | + tx_type, | ||
| 5410 | + fctx, | ||
| 5188 | ), | 5411 | ), |
| 5189 | None => mc_trial_typed( | 5412 | None => mc_trial_typed( |
| 5190 | - luma, x, y, side, mv, true, reference.0, reference.1, reference.2, | 5413 | + luma, |
| 5191 | - reference.3, false, search.base_q_idx, search.deadzone, fset, tx_type, | 5414 | + x, |
| 5415 | + y, | ||
| 5416 | + side, | ||
| 5417 | + mv, | ||
| 5418 | + true, | ||
| 5419 | + reference.0, | ||
| 5420 | + reference.1, | ||
| 5421 | + reference.2, | ||
| 5422 | + reference.3, | ||
| 5423 | + false, | ||
| 5424 | + search.base_q_idx, | ||
| 5425 | + search.deadzone, | ||
| 5426 | + fset, | ||
| 5427 | + tx_type, | ||
| 5192 | fctx, | 5428 | fctx, |
| 5193 | ), | 5429 | ), |
| 5194 | }; | 5430 | }; |
| @@ -5223,13 +5459,37 @@ fn commit_inter_luma( | |||
| 5223 | if let Some(fset) = inter_luma_set(side) { | 5459 | if let Some(fset) = inter_luma_set(side) { |
| 5224 | let here = match second { | 5460 | let here = match second { |
| 5225 | Some((mv1, ref1)) => mc_trial_compound_typed( | 5461 | Some((mv1, ref1)) => mc_trial_compound_typed( |
| 5226 | - luma, x, y, side, (mv, mv1), true, reference, ref1, search.base_q_idx, | 5462 | + luma, |
| 5227 | - search.deadzone, fset, TxType::DctDct, fctx, | 5463 | + x, |
| 5464 | + y, | ||
| 5465 | + side, | ||
| 5466 | + (mv, mv1), | ||
| 5467 | + true, | ||
| 5468 | + reference, | ||
| 5469 | + ref1, | ||
| 5470 | + search.base_q_idx, | ||
| 5471 | + search.deadzone, | ||
| 5472 | + fset, | ||
| 5473 | + TxType::DctDct, | ||
| 5474 | + fctx, | ||
| 5228 | ), | 5475 | ), |
| 5229 | None => mc_trial_typed( | 5476 | None => mc_trial_typed( |
| 5230 | - luma, x, y, side, mv, true, reference.0, reference.1, reference.2, | 5477 | + luma, |
| 5231 | - reference.3, false, search.base_q_idx, search.deadzone, fset, | 5478 | + x, |
| 5232 | - TxType::DctDct, fctx, | 5479 | + y, |
| 5480 | + side, | ||
| 5481 | + mv, | ||
| 5482 | + true, | ||
| 5483 | + reference.0, | ||
| 5484 | + reference.1, | ||
| 5485 | + reference.2, | ||
| 5486 | + reference.3, | ||
| 5487 | + false, | ||
| 5488 | + search.base_q_idx, | ||
| 5489 | + search.deadzone, | ||
| 5490 | + fset, | ||
| 5491 | + TxType::DctDct, | ||
| 5492 | + fctx, | ||
| 5233 | ), | 5493 | ), |
| 5234 | }; | 5494 | }; |
| 5235 | TXRD_STATS[5].fetch_add(here.sse as u64, Relaxed); | 5495 | TXRD_STATS[5].fetch_add(here.sse as u64, Relaxed); |
| @@ -5241,16 +5501,21 @@ fn commit_inter_luma( | |||
| 5241 | "TXRD block {n} at ({x},{y}) side={side} compound={} mv={mv:?} \ | 5501 | "TXRD block {n} at ({x},{y}) side={side} compound={} mv={mv:?} \ |
| 5242 | flat sse={:.0} bits={:.1} | here sse={:.0} bits={:.1} | chosen {flat_type:?} \ | 5502 | flat sse={:.0} bits={:.1} | here sse={:.0} bits={:.1} | chosen {flat_type:?} \ |
| 5243 | sse={:.0} bits={:.1}", | 5503 | sse={:.0} bits={:.1}", |
| 5244 | - second.is_some(), flat.sse, flat.bits, here.sse, here.bits, | 5504 | + second.is_some(), |
| 5245 | - flat_ref.sse, flat_ref.bits, | 5505 | + flat.sse, |
| 5506 | + flat.bits, | ||
| 5507 | + here.sse, | ||
| 5508 | + here.bits, | ||
| 5509 | + flat_ref.sse, | ||
| 5510 | + flat_ref.bits, | ||
| 5246 | ); | 5511 | ); |
| 5247 | } | 5512 | } |
| 5248 | } | 5513 | } |
| 5249 | } | 5514 | } |
| 5250 | // What the caller's already-counted `flat` cost has to be corrected by | 5515 | // What the caller's already-counted `flat` cost has to be corrected by |
| 5251 | // when a non-`DCT_DCT` type won it, the same way the split delta below is. | 5516 | // when a non-`DCT_DCT` type won it, the same way the split delta below is. |
| 5252 | - let flat_gain = (flat_ref.sse + search.lambda * flat_ref.bits) | 5517 | + let flat_gain = |
| 5253 | - - (flat.sse + search.lambda * flat.bits); | 5518 | + (flat_ref.sse + search.lambda * flat_ref.bits) - (flat.sse + search.lambda * flat.bits); |
| 5254 | let eligible = tx_select() | 5519 | let eligible = tx_select() |
| 5255 | && tx_select_inter() | 5520 | && tx_select_inter() |
| 5256 | && !skip | 5521 | && !skip |
| @@ -5291,14 +5556,39 @@ fn commit_inter_luma( | |||
| 5291 | let (tu_x, tu_y) = (x + tu_col * tx, y + tu_row * tx); | 5556 | let (tu_x, tu_y) = (x + tu_col * tx, y + tu_row * tx); |
| 5292 | let unit = |tx_type: TxType| match second { | 5557 | let unit = |tx_type: TxType| match second { |
| 5293 | Some((mv1, ref1)) => mc_trial_compound_typed( | 5558 | Some((mv1, ref1)) => mc_trial_compound_typed( |
| 5294 | - luma, tu_x, tu_y, tx, (mv, mv1), true, reference, ref1, | 5559 | + luma, |
| 5295 | - search.base_q_idx, search.deadzone, set, tx_type, fctx, | 5560 | + tu_x, |
| 5561 | + tu_y, | ||
| 5562 | + tx, | ||
| 5563 | + (mv, mv1), | ||
| 5564 | + true, | ||
| 5565 | + reference, | ||
| 5566 | + ref1, | ||
| 5567 | + search.base_q_idx, | ||
| 5568 | + search.deadzone, | ||
| 5569 | + set, | ||
| 5570 | + tx_type, | ||
| 5571 | + fctx, | ||
| 5296 | ), | 5572 | ), |
| 5297 | None => mc_trial_typed( | 5573 | None => mc_trial_typed( |
| 5298 | - luma, tu_x, tu_y, tx, mv, true, reference.0, reference.1, reference.2, | 5574 | + luma, |
| 5299 | - reference.3, false, search.base_q_idx, search.deadzone, set, tx_type, fctx, | 5575 | + tu_x, |
| 5300 | - ), | 5576 | + tu_y, |
| 5301 | - }; | 5577 | + tx, |
| 5578 | + mv, | ||
| 5579 | + true, | ||
| 5580 | + reference.0, | ||
| 5581 | + reference.1, | ||
| 5582 | + reference.2, | ||
| 5583 | + reference.3, | ||
| 5584 | + false, | ||
| 5585 | + search.base_q_idx, | ||
| 5586 | + search.deadzone, | ||
| 5587 | + set, | ||
| 5588 | + tx_type, | ||
| 5589 | + fctx, | ||
| 5590 | + ), | ||
| 5591 | + }; | ||
| 5302 | let mut best: Option<(f64, TxType, Trial)> = None; | 5592 | let mut best: Option<(f64, TxType, Trial)> = None; |
| 5303 | for &tx_type in inter_tx_type_candidates(set, search.screen) { | 5593 | for &tx_type in inter_tx_type_candidates(set, search.screen) { |
| 5304 | let candidate = unit(tx_type); | 5594 | let candidate = unit(tx_type); |
| @@ -5324,7 +5614,14 @@ fn commit_inter_luma( | |||
| 5324 | let split_cost = sse + search.lambda * split_lambda_mult() * split_rate; | 5614 | let split_cost = sse + search.lambda * split_lambda_mult() * split_rate; |
| 5325 | let flat_cost = flat_ref.sse + search.lambda * flat_rate; | 5615 | let flat_cost = flat_ref.sse + search.lambda * flat_rate; |
| 5326 | if split_census_on() { | 5616 | if split_census_on() { |
| 5327 | - split_census(1, false, side, split_cost < flat_cost, (split_rate, sse), (flat_rate, flat_ref.sse)); | 5617 | + split_census( |
| 5618 | + 1, | ||
| 5619 | + false, | ||
| 5620 | + side, | ||
| 5621 | + split_cost < flat_cost, | ||
| 5622 | + (split_rate, sse), | ||
| 5623 | + (flat_rate, flat_ref.sse), | ||
| 5624 | + ); | ||
| 5328 | } | 5625 | } |
| 5329 | let class = usize::from(side == BLOCK) * 4 + usize::from(second.is_some()) * 2; | 5626 | let class = usize::from(side == BLOCK) * 4 + usize::from(second.is_some()) * 2; |
| 5330 | // The depth census has a leaf row and a 32x32 row and no 64 one, so the | 5627 | // The depth census has a leaf row and a 32x32 row and no 64 one, so the |
| @@ -5384,7 +5681,9 @@ fn palette_candidates(block: &[u8]) -> Vec<crate::tile::PaletteY> { | |||
| 5384 | for &v in block { | 5681 | for &v in block { |
| 5385 | histogram[usize::from(v)] += 1; | 5682 | histogram[usize::from(v)] += 1; |
| 5386 | } | 5683 | } |
| 5387 | - let present: Vec<u16> = (0..256u16).filter(|&v| histogram[usize::from(v)] > 0).collect(); | 5684 | + let present: Vec<u16> = (0..256u16) |
| 5685 | + .filter(|&v| histogram[usize::from(v)] > 0) | ||
| 5686 | + .collect(); | ||
| 5388 | if present.len() < 2 { | 5687 | if present.len() < 2 { |
| 5389 | return Vec::new(); | 5688 | return Vec::new(); |
| 5390 | } | 5689 | } |
| @@ -5402,7 +5701,11 @@ fn palette_candidates(block: &[u8]) -> Vec<crate::tile::PaletteY> { | |||
| 5402 | .expect("a palette holds at least two colours") | 5701 | .expect("a palette holds at least two colours") |
| 5403 | }) | 5702 | }) |
| 5404 | .collect(); | 5703 | .collect(); |
| 5405 | - crate::tile::PaletteY { size: colors.len() as u8, colors: base, map } | 5704 | + crate::tile::PaletteY { |
| 5705 | + size: colors.len() as u8, | ||
| 5706 | + colors: base, | ||
| 5707 | + map, | ||
| 5708 | + } | ||
| 5406 | }; | 5709 | }; |
| 5407 | if present.len() <= 8 { | 5710 | if present.len() <= 8 { |
| 5408 | return vec![exact(&present)]; | 5711 | return vec![exact(&present)]; |
| @@ -5410,10 +5713,7 @@ fn palette_candidates(block: &[u8]) -> Vec<crate::tile::PaletteY> { | |||
| 5410 | if present.len() > palette_max_colors() { | 5713 | if present.len() > palette_max_colors() { |
| 5411 | return Vec::new(); | 5714 | return Vec::new(); |
| 5412 | } | 5715 | } |
| 5413 | - let (lo, hi) = ( | 5716 | + let (lo, hi) = (i32::from(present[0]), i32::from(present[present.len() - 1])); |
| 5414 | - i32::from(present[0]), | ||
| 5415 | - i32::from(present[present.len() - 1]), | ||
| 5416 | - ); | ||
| 5417 | let mut out = Vec::with_capacity(2); | 5717 | let mut out = Vec::with_capacity(2); |
| 5418 | for n in [8usize, 4] { | 5718 | for n in [8usize, 4] { |
| 5419 | // Even seeding across the block's own range, then four Lloyd passes | 5719 | // Even seeding across the block's own range, then four Lloyd passes |
| @@ -5595,7 +5895,10 @@ fn intrabc_worth_it(y: &[u8], width: usize, true_width: usize, true_height: usiz | |||
| 5595 | while bx + IBC_HASH <= true_width { | 5895 | while bx + IBC_HASH <= true_width { |
| 5596 | total += 1; | 5896 | total += 1; |
| 5597 | if let Some(hits) = table.get(&ibc_hash(y, width, bx, by)) { | 5897 | if let Some(hits) = table.get(&ibc_hash(y, width, bx, by)) { |
| 5598 | - if hits.iter().any(|&(hx, hy)| (hx as usize, hy as usize) != (bx, by)) { | 5898 | + if hits |
| 5899 | + .iter() | ||
| 5900 | + .any(|&(hx, hy)| (hx as usize, hy as usize) != (bx, by)) | ||
| 5901 | + { | ||
| 5599 | matched += 1; | 5902 | matched += 1; |
| 5600 | } | 5903 | } |
| 5601 | } | 5904 | } |
| @@ -5603,7 +5906,11 @@ fn intrabc_worth_it(y: &[u8], width: usize, true_width: usize, true_height: usiz | |||
| 5603 | } | 5906 | } |
| 5604 | by += IBC_HASH; | 5907 | by += IBC_HASH; |
| 5605 | } | 5908 | } |
| 5606 | - let share = if total == 0 { 0.0 } else { matched as f64 / total as f64 }; | 5909 | + let share = if total == 0 { |
| 5910 | + 0.0 | ||
| 5911 | + } else { | ||
| 5912 | + matched as f64 / total as f64 | ||
| 5913 | + }; | ||
| 5607 | (share * 100.0 >= intrabc_pct() as f64, share) | 5914 | (share * 100.0 >= intrabc_pct() as f64, share) |
| 5608 | } | 5915 | } |
| 5609 | 5916 | ||
| @@ -5637,7 +5944,13 @@ struct Ibc { | |||
| 5637 | impl Ibc { | 5944 | impl Ibc { |
| 5638 | fn new(tile: (usize, usize, usize, usize), source: &[u8], width: usize) -> Self { | 5945 | fn new(tile: (usize, usize, usize, usize), source: &[u8], width: usize) -> Self { |
| 5639 | let mut table = std::collections::HashMap::new(); | 5946 | let mut table = std::collections::HashMap::new(); |
| 5640 | - ibc_index(&mut table, source, width, (tile.0, tile.1), (tile.2, tile.3)); | 5947 | + ibc_index( |
| 5948 | + &mut table, | ||
| 5949 | + source, | ||
| 5950 | + width, | ||
| 5951 | + (tile.0, tile.1), | ||
| 5952 | + (tile.2, tile.3), | ||
| 5953 | + ); | ||
| 5641 | Self { | 5954 | Self { |
| 5642 | table, | 5955 | table, |
| 5643 | tile, | 5956 | tile, |
| @@ -5677,7 +5990,11 @@ impl Ibc { | |||
| 5677 | // Counting 64s under a 128 superblock let the search take a source | 5990 | // Counting 64s under a 128 superblock let the search take a source |
| 5678 | // from a 64 row the 128 visit order had not reconstructed yet. | 5991 | // from a 64 row the 128 visit order had not reconstructed yet. |
| 5679 | let sb_log2 = if crate::encode::sb128_on() { 7 } else { 6 }; | 5992 | let sb_log2 = if crate::encode::sb128_on() { 7 } else { 6 }; |
| 5680 | - let delay: i32 = if sb_log2 == 7 { INTRABC_DELAY_SB64 / 2 } else { INTRABC_DELAY_SB64 }; | 5993 | + let delay: i32 = if sb_log2 == 7 { |
| 5994 | + INTRABC_DELAY_SB64 / 2 | ||
| 5995 | + } else { | ||
| 5996 | + INTRABC_DELAY_SB64 | ||
| 5997 | + }; | ||
| 5681 | let active_sb_row = (y as i32 - ty0) >> sb_log2; | 5998 | let active_sb_row = (y as i32 - ty0) >> sb_log2; |
| 5682 | let active_sb_col = (x as i32 - tx0) >> sb_log2; | 5999 | let active_sb_col = (x as i32 - tx0) >> sb_log2; |
| 5683 | let src_sb_row = (sy + h - 1 - ty0) >> sb_log2; | 6000 | let src_sb_row = (sy + h - 1 - ty0) >> sb_log2; |
| @@ -5705,7 +6022,10 @@ static IBC_SEARCH: [std::sync::atomic::AtomicUsize; 3] = | |||
| 5705 | 6022 | ||
| 5706 | impl Drop for Ibc { | 6023 | impl Drop for Ibc { |
| 5707 | fn drop(&mut self) { | 6024 | fn drop(&mut self) { |
| 5708 | - for (slot, n) in [self.lookups, self.found, self.hits].into_iter().enumerate() { | 6025 | + for (slot, n) in [self.lookups, self.found, self.hits] |
| 6026 | + .into_iter() | ||
| 6027 | + .enumerate() | ||
| 6028 | + { | ||
| 5709 | IBC_SEARCH[slot].fetch_add(n, std::sync::atomic::Ordering::Relaxed); | 6029 | IBC_SEARCH[slot].fetch_add(n, std::sync::atomic::Ordering::Relaxed); |
| 5710 | } | 6030 | } |
| 5711 | } | 6031 | } |
| @@ -5850,19 +6170,17 @@ fn ibc_search( | |||
| 5850 | ) -> Option<((i32, i32), f64, (usize, usize))> { | 6170 | ) -> Option<((i32, i32), f64, (usize, usize))> { |
| 5851 | let pred = ibc.last_dv.unwrap_or((0, -(64 + 256) * 8)); | 6171 | let pred = ibc.last_dv.unwrap_or((0, -(64 + 256) * 8)); |
| 5852 | let mut best: Option<((i32, i32), f64, (usize, usize))> = None; | 6172 | let mut best: Option<((i32, i32), f64, (usize, usize))> = None; |
| 5853 | - let consider = |ibc: &Ibc, sx: usize, sy: usize, best: &mut Option<((i32, i32), f64, (usize, usize))>| { | 6173 | + let consider = |
| 5854 | - let dv = ( | 6174 | + |ibc: &Ibc, sx: usize, sy: usize, best: &mut Option<((i32, i32), f64, (usize, usize))>| { |
| 5855 | - (sy as i32 - y as i32) * 8, | 6175 | + let dv = ((sy as i32 - y as i32) * 8, (sx as i32 - x as i32) * 8); |
| 5856 | - (sx as i32 - x as i32) * 8, | 6176 | + if !ibc.dv_valid(x, y, side, side, dv) { |
| 5857 | - ); | 6177 | + return; |
| 5858 | - if !ibc.dv_valid(x, y, side, side, dv) { | 6178 | + } |
| 5859 | - return; | 6179 | + let cost = ibc_sse(luma, chroma, (x, y), (sx, sy), side) + lambda * dv_bits(dv, pred); |
| 5860 | - } | 6180 | + if best.as_ref().is_none_or(|b| cost < b.1) { |
| 5861 | - let cost = ibc_sse(luma, chroma, (x, y), (sx, sy), side) + lambda * dv_bits(dv, pred); | 6181 | + *best = Some((dv, cost, (sx, sy))); |
| 5862 | - if best.as_ref().is_none_or(|b| cost < b.1) { | 6182 | + } |
| 5863 | - *best = Some((dv, cost, (sx, sy))); | 6183 | + }; |
| 5864 | - } | ||
| 5865 | - }; | ||
| 5866 | ibc.lookups += 1; | 6184 | ibc.lookups += 1; |
| 5867 | let key = ibc_hash(luma.source, luma.width, x, y); | 6185 | let key = ibc_hash(luma.source, luma.width, x, y); |
| 5868 | // The table is filled in raster order, so the entries BEFORE this block's | 6186 | // The table is filled in raster order, so the entries BEFORE this block's |
| @@ -5984,13 +6302,19 @@ fn code_square( | |||
| 5984 | let cost_d = sse + search.lambda * split_lambda_mult() * rate; | 6302 | let cost_d = sse + search.lambda * split_lambda_mult() * rate; |
| 5985 | if census_flat.is_some() { | 6303 | if census_flat.is_some() { |
| 5986 | let c = (bits + tx_depth_bits(side, depth), sse); | 6304 | let c = (bits + tx_depth_bits(side, depth), sse); |
| 5987 | - if census_split.is_none_or(|b| sse + search.lambda * rate < b.1 + search.lambda * b.0) | 6305 | + if census_split |
| 6306 | + .is_none_or(|b| sse + search.lambda * rate < b.1 + search.lambda * b.0) | ||
| 5988 | { | 6307 | { |
| 5989 | census_split = Some(c); | 6308 | census_split = Some(c); |
| 5990 | } | 6309 | } |
| 5991 | } | 6310 | } |
| 5992 | if cost_d < best.0 { | 6311 | if cost_d < best.0 { |
| 5993 | - best = (cost_d, depth, luma.snapshot(x, y, side), coeffs(&levels, side)); | 6312 | + best = ( |
| 6313 | + cost_d, | ||
| 6314 | + depth, | ||
| 6315 | + luma.snapshot(x, y, side), | ||
| 6316 | + coeffs(&levels, side), | ||
| 6317 | + ); | ||
| 5994 | best_types = types; | 6318 | best_types = types; |
| 5995 | } | 6319 | } |
| 5996 | } | 6320 | } |
| @@ -6050,7 +6374,11 @@ fn code_square( | |||
| 6050 | * (trial.bits | 6374 | * (trial.bits |
| 6051 | + mode_bits[DC_PRED as usize] | 6375 | + mode_bits[DC_PRED as usize] |
| 6052 | + crate::tile::palette_bits(&pal, side, on) | 6376 | + crate::tile::palette_bits(&pal, side, on) |
| 6053 | - + if tx_select { tx_depth_bits(side, 0) } else { 0.0 }); | 6377 | + + if tx_select { |
| 6378 | + tx_depth_bits(side, 0) | ||
| 6379 | + } else { | ||
| 6380 | + 0.0 | ||
| 6381 | + }); | ||
| 6054 | if cost_p < cost { | 6382 | if cost_p < cost { |
| 6055 | cost = cost_p; | 6383 | cost = cost_p; |
| 6056 | mode = DC_PRED as u8; | 6384 | mode = DC_PRED as u8; |
| @@ -6101,7 +6429,11 @@ fn code_square( | |||
| 6101 | } | 6429 | } |
| 6102 | let one_bits = symbol_bits(row, 1); | 6430 | let one_bits = symbol_bits(row, 1); |
| 6103 | let kept = luma.snapshot(x, y, side); | 6431 | let kept = luma.snapshot(x, y, side); |
| 6104 | - let max_depth = if tx_select && search.screen { max_tx_depth(side) } else { 0 }; | 6432 | + let max_depth = if tx_select && search.screen { |
| 6433 | + max_tx_depth(side) | ||
| 6434 | + } else { | ||
| 6435 | + 0 | ||
| 6436 | + }; | ||
| 6105 | let mut best: Option<(f64, u8, usize, (Vec<u8>, Vec<CoefCtx>), Vec<Coeff>)> = None; | 6437 | let mut best: Option<(f64, u8, usize, (Vec<u8>, Vec<CoefCtx>), Vec<Coeff>)> = None; |
| 6106 | for fi in 0..5u8 { | 6438 | for fi in 0..5u8 { |
| 6107 | for depth in 0..=max_depth { | 6439 | for depth in 0..=max_depth { |
| @@ -6116,7 +6448,11 @@ fn code_square( | |||
| 6116 | + mode_bits[DC_PRED as usize] | 6448 | + mode_bits[DC_PRED as usize] |
| 6117 | + one_bits | 6449 | + one_bits |
| 6118 | + symbol_bits(&cdf::FILTER_INTRA_MODE, usize::from(fi)) | 6450 | + symbol_bits(&cdf::FILTER_INTRA_MODE, usize::from(fi)) |
| 6119 | - + if tx_select { tx_depth_bits(side, depth) } else { 0.0 }); | 6451 | + + if tx_select { |
| 6452 | + tx_depth_bits(side, depth) | ||
| 6453 | + } else { | ||
| 6454 | + 0.0 | ||
| 6455 | + }); | ||
| 6120 | if cost_f < cost && best.as_ref().is_none_or(|b| cost_f < b.0) { | 6456 | if cost_f < cost && best.as_ref().is_none_or(|b| cost_f < b.0) { |
| 6121 | best = Some(( | 6457 | best = Some(( |
| 6122 | cost_f, | 6458 | cost_f, |
| @@ -6214,8 +6550,8 @@ const CHROMA_MODES: [u8; 7] = [ | |||
| 6214 | /// The thirteen intra mode names, for the chroma fire count's print. | 6550 | /// The thirteen intra mode names, for the chroma fire count's print. |
| 6215 | #[cfg(test)] | 6551 | #[cfg(test)] |
| 6216 | const UV_MODE_NAMES: [&str; 14] = [ | 6552 | const UV_MODE_NAMES: [&str; 14] = [ |
| 6217 | - "DC", "V", "H", "D45", "D135", "D113", "D157", "D203", "D67", "SMOOTH", "SMOOTH_V", | 6553 | + "DC", "V", "H", "D45", "D135", "D113", "D157", "D203", "D67", "SMOOTH", "SMOOTH_V", "SMOOTH_H", |
| 6218 | - "SMOOTH_H", "PAETH", "CFL", | 6554 | + "PAETH", "CFL", |
| 6219 | ]; | 6555 | ]; |
| 6220 | 6556 | ||
| 6221 | /// How many blocks each chroma mode has won, indexed by the mode itself -- | 6557 | /// How many blocks each chroma mode has won, indexed by the mode itself -- |
| @@ -6253,18 +6589,16 @@ pub(crate) fn take_angle_delta_hits() -> [usize; 7] { | |||
| 6253 | /// Whether the luma search refines a directional winner's `angle_delta_y` | 6589 | /// Whether the luma search refines a directional winner's `angle_delta_y` |
| 6254 | /// (`EC_AV1_ANGLE=0` switches it off, the lane's own on/off pair). | 6590 | /// (`EC_AV1_ANGLE=0` switches it off, the lane's own on/off pair). |
| 6255 | fn angle_delta_on() -> bool { | 6591 | fn angle_delta_on() -> bool { |
| 6256 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 6592 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 6257 | - crate::envflags::var("EC_AV1_ANGLE").ok().map(|v| v != "0") | 6593 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_ANGLE").ok().map(|v| v != "0")); |
| 6258 | - }); | ||
| 6259 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::ANGLE)) | 6594 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::ANGLE)) |
| 6260 | } | 6595 | } |
| 6261 | 6596 | ||
| 6262 | /// Whether the chroma search offers `UV_CFL_PRED` at all (`EC_AV1_CFL=0` | 6597 | /// Whether the chroma search offers `UV_CFL_PRED` at all (`EC_AV1_CFL=0` |
| 6263 | /// switches it off, which is how the lane measured its own on/off pair). | 6598 | /// switches it off, which is how the lane measured its own on/off pair). |
| 6264 | fn cfl_on() -> bool { | 6599 | fn cfl_on() -> bool { |
| 6265 | - static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 6600 | + static ENV: std::sync::LazyLock<Option<bool>> = |
| 6266 | - crate::envflags::var("EC_AV1_CFL").ok().map(|v| v != "0") | 6601 | + std::sync::LazyLock::new(|| crate::envflags::var("EC_AV1_CFL").ok().map(|v| v != "0")); |
| 6267 | - }); | ||
| 6268 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::CFL)) | 6602 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::CFL)) |
| 6269 | } | 6603 | } |
| 6270 | 6604 | ||
| @@ -6347,7 +6681,9 @@ pub(crate) fn filter_intra_on() -> bool { | |||
| 6347 | return forced; | 6681 | return forced; |
| 6348 | } | 6682 | } |
| 6349 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | 6683 | static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { |
| 6350 | - crate::envflags::var("EC_AV1_FILTER_INTRA").ok().map(|v| v != "0") | 6684 | + crate::envflags::var("EC_AV1_FILTER_INTRA") |
| 6685 | + .ok() | ||
| 6686 | + .map(|v| v != "0") | ||
| 6351 | }); | 6687 | }); |
| 6352 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::FILTER_INTRA)) | 6688 | ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::FILTER_INTRA)) |
| 6353 | } | 6689 | } |
| @@ -6470,8 +6806,24 @@ fn search_chroma( | |||
| 6470 | } else { | 6806 | } else { |
| 6471 | crate::decode::default_intra_tx_type(mode) | 6807 | crate::decode::default_intra_tx_type(mode) |
| 6472 | }; | 6808 | }; |
| 6473 | - let u = chroma[0].trial_typed(at, mode, 0, search.base_q_idx, search.deadzone, tx_type, fctx); | 6809 | + let u = chroma[0].trial_typed( |
| 6474 | - let v = chroma[1].trial_typed(at, mode, 0, search.base_q_idx, search.deadzone, tx_type, fctx); | 6810 | + at, |
| 6811 | + mode, | ||
| 6812 | + 0, | ||
| 6813 | + search.base_q_idx, | ||
| 6814 | + search.deadzone, | ||
| 6815 | + tx_type, | ||
| 6816 | + fctx, | ||
| 6817 | + ); | ||
| 6818 | + let v = chroma[1].trial_typed( | ||
| 6819 | + at, | ||
| 6820 | + mode, | ||
| 6821 | + 0, | ||
| 6822 | + search.base_q_idx, | ||
| 6823 | + search.deadzone, | ||
| 6824 | + tx_type, | ||
| 6825 | + fctx, | ||
| 6826 | + ); | ||
| 6475 | let cost = u.sse + v.sse + search.lambda * (bits + u.bits + v.bits); | 6827 | let cost = u.sse + v.sse + search.lambda * (bits + u.bits + v.bits); |
| 6476 | if best.as_ref().is_none_or(|(b, ..)| cost < *b) { | 6828 | if best.as_ref().is_none_or(|(b, ..)| cost < *b) { |
| 6477 | best = Some((cost, mode, u, v)); | 6829 | best = Some((cost, mode, u, v)); |
| @@ -6543,10 +6895,24 @@ fn search_chroma( | |||
| 6543 | }; | 6895 | }; |
| 6544 | let (pu, pv) = (predict(&candidate.u_colors), predict(&candidate.v_colors)); | 6896 | let (pu, pv) = (predict(&candidate.u_colors), predict(&candidate.v_colors)); |
| 6545 | let u_trial = chroma[0].code_from_prediction( | 6897 | let u_trial = chroma[0].code_from_prediction( |
| 6546 | - at.x, at.y, at.side, &pu, false, search.base_q_idx, search.deadzone, set, | 6898 | + at.x, |
| 6899 | + at.y, | ||
| 6900 | + at.side, | ||
| 6901 | + &pu, | ||
| 6902 | + false, | ||
| 6903 | + search.base_q_idx, | ||
| 6904 | + search.deadzone, | ||
| 6905 | + set, | ||
| 6547 | ); | 6906 | ); |
| 6548 | let v_trial = chroma[1].code_from_prediction( | 6907 | let v_trial = chroma[1].code_from_prediction( |
| 6549 | - at.x, at.y, at.side, &pv, false, search.base_q_idx, search.deadzone, set, | 6908 | + at.x, |
| 6909 | + at.y, | ||
| 6910 | + at.side, | ||
| 6911 | + &pv, | ||
| 6912 | + false, | ||
| 6913 | + search.base_q_idx, | ||
| 6914 | + search.deadzone, | ||
| 6915 | + set, | ||
| 6550 | ); | 6916 | ); |
| 6551 | let cost_p = u_trial.sse | 6917 | let cost_p = u_trial.sse |
| 6552 | + v_trial.sse | 6918 | + v_trial.sse |
| @@ -6583,7 +6949,16 @@ fn search_chroma( | |||
| 6583 | plane.edges_into(at.x, at.y, at.side, at.reach, &mut above_buf, &mut left_buf); | 6949 | plane.edges_into(at.x, at.y, at.side, at.reach, &mut above_buf, &mut left_buf); |
| 6584 | let mut prediction = vec![0u8; at.side * at.side]; | 6950 | let mut prediction = vec![0u8; at.side * at.side]; |
| 6585 | intra_predict_u8( | 6951 | intra_predict_u8( |
| 6586 | - DC_PRED, 0, above, left, corner, at.side, at.side, false, false, &mut prediction, | 6952 | + DC_PRED, |
| 6953 | + 0, | ||
| 6954 | + above, | ||
| 6955 | + left, | ||
| 6956 | + corner, | ||
| 6957 | + at.side, | ||
| 6958 | + at.side, | ||
| 6959 | + false, | ||
| 6960 | + false, | ||
| 6961 | + &mut prediction, | ||
| 6587 | fctx, | 6962 | fctx, |
| 6588 | ); | 6963 | ); |
| 6589 | prediction | 6964 | prediction |
| @@ -6660,11 +7035,7 @@ fn search_chroma( | |||
| 6660 | }; | 7035 | }; |
| 6661 | // At least one alpha must be nonzero: `cfl_alpha_signs` has no | 7036 | // At least one alpha must be nonzero: `cfl_alpha_signs` has no |
| 6662 | // (ZERO, ZERO) joint value ([`crate::tile::cfl_joint_sign`]). | 7037 | // (ZERO, ZERO) joint value ([`crate::tile::cfl_joint_sign`]). |
| 6663 | - let combos: [(i32, i32); 3] = [ | 7038 | + let combos: [(i32, i32); 3] = [(picked[0], picked[1]), (picked[0], 0), (0, picked[1])]; |
| 6664 | - (picked[0], picked[1]), | ||
| 6665 | - (picked[0], 0), | ||
| 6666 | - (0, picked[1]), | ||
| 6667 | - ]; | ||
| 6668 | for &(alpha_u, alpha_v) in &combos { | 7039 | for &(alpha_u, alpha_v) in &combos { |
| 6669 | if (alpha_u, alpha_v) == (0, 0) { | 7040 | if (alpha_u, alpha_v) == (0, 0) { |
| 6670 | continue; | 7041 | continue; |
| @@ -6752,9 +7123,17 @@ fn leaf_compound_stacks<'a>( | |||
| 6752 | r, | 7123 | r, |
| 6753 | p, | 7124 | p, |
| 6754 | crate::mvstack::find_mv_stack_compound( | 7125 | crate::mvstack::find_mv_stack_compound( |
| 6755 | - grid, mi_row, mi_col, bw4, bh4, | 7126 | + grid, |
| 6756 | - (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows, | 7127 | + mi_row, |
| 6757 | - grid.sign_bias_table(), &[(0, 0); 7], None, | 7128 | + mi_col, |
| 7129 | + bw4, | ||
| 7130 | + bh4, | ||
| 7131 | + (crate::mvstack::LAST_FRAME, r), | ||
| 7132 | + mi_cols, | ||
| 7133 | + mi_rows, | ||
| 7134 | + grid.sign_bias_table(), | ||
| 7135 | + &[(0, 0); 7], | ||
| 7136 | + None, | ||
| 6758 | ), | 7137 | ), |
| 6759 | ) | 7138 | ) |
| 6760 | }) | 7139 | }) |
| @@ -6945,7 +7324,8 @@ fn code_square_inter( | |||
| 6945 | false, | 7324 | false, |
| 6946 | search.base_q_idx, | 7325 | search.base_q_idx, |
| 6947 | search.deadzone, | 7326 | search.deadzone, |
| 6948 | - luma_set, fctx, | 7327 | + luma_set, |
| 7328 | + fctx, | ||
| 6949 | ); | 7329 | ); |
| 6950 | let u = mc_trial( | 7330 | let u = mc_trial( |
| 6951 | &chroma[0], | 7331 | &chroma[0], |
| @@ -6961,7 +7341,8 @@ fn code_square_inter( | |||
| 6961 | false, | 7341 | false, |
| 6962 | search.base_q_idx, | 7342 | search.base_q_idx, |
| 6963 | search.deadzone, | 7343 | search.deadzone, |
| 6964 | - chroma_set, fctx, | 7344 | + chroma_set, |
| 7345 | + fctx, | ||
| 6965 | ); | 7346 | ); |
| 6966 | let v = mc_trial( | 7347 | let v = mc_trial( |
| 6967 | &chroma[1], | 7348 | &chroma[1], |
| @@ -6977,7 +7358,8 @@ fn code_square_inter( | |||
| 6977 | false, | 7358 | false, |
| 6978 | search.base_q_idx, | 7359 | search.base_q_idx, |
| 6979 | search.deadzone, | 7360 | search.deadzone, |
| 6980 | - chroma_set, fctx, | 7361 | + chroma_set, |
| 7362 | + fctx, | ||
| 6981 | ); | 7363 | ); |
| 6982 | let skip = luma_trial.levels.iter().all(|&l| l == 0) | 7364 | let skip = luma_trial.levels.iter().all(|&l| l == 0) |
| 6983 | && u.levels.iter().all(|&l| l == 0) | 7365 | && u.levels.iter().all(|&l| l == 0) |
| @@ -7055,7 +7437,8 @@ fn code_square_inter( | |||
| 7055 | side, | 7437 | side, |
| 7056 | stack.pred_mv, | 7438 | stack.pred_mv, |
| 7057 | &seeds[..seed_n], | 7439 | &seeds[..seed_n], |
| 7058 | - search.lambda, fctx, | 7440 | + search.lambda, |
| 7441 | + fctx, | ||
| 7059 | 1, | 7442 | 1, |
| 7060 | ); | 7443 | ); |
| 7061 | let new_mv = round_to_valid_mv(found.mv, stack.pred_mv); | 7444 | let new_mv = round_to_valid_mv(found.mv, stack.pred_mv); |
| @@ -7063,7 +7446,15 @@ fn code_square_inter( | |||
| 7063 | let mv_residual = mv_residual_bits(new_mv, stack.pred_mv); | 7446 | let mv_residual = mv_residual_bits(new_mv, stack.pred_mv); |
| 7064 | if mv_residual.is_none() { | 7447 | if mv_residual.is_none() { |
| 7065 | // lane-newmv: a vector the writer cannot name never reaches RD. | 7448 | // lane-newmv: a vector the writer cannot name never reaches RD. |
| 7066 | - newmv_census_block(side, false, f64::INFINITY, best.0, new_mv, stack.nearest_mv, 0.0); | 7449 | + newmv_census_block( |
| 7450 | + side, | ||
| 7451 | + false, | ||
| 7452 | + f64::INFINITY, | ||
| 7453 | + best.0, | ||
| 7454 | + new_mv, | ||
| 7455 | + stack.nearest_mv, | ||
| 7456 | + 0.0, | ||
| 7457 | + ); | ||
| 7067 | } | 7458 | } |
| 7068 | if let Some(mv_bits) = mv_residual { | 7459 | if let Some(mv_bits) = mv_residual { |
| 7069 | searched_new = Some(new_mv); | 7460 | searched_new = Some(new_mv); |
| @@ -7074,17 +7465,54 @@ fn code_square_inter( | |||
| 7074 | } else { | 7465 | } else { |
| 7075 | ( | 7466 | ( |
| 7076 | mc_trial( | 7467 | mc_trial( |
| 7077 | - luma, x, y, side, new_mv, true, ref_luma.0, ref_luma.1, ref_luma.2, | 7468 | + luma, |
| 7078 | - ref_luma.3, false, search.base_q_idx, search.deadzone, luma_set, fctx, | 7469 | + x, |
| 7470 | + y, | ||
| 7471 | + side, | ||
| 7472 | + new_mv, | ||
| 7473 | + true, | ||
| 7474 | + ref_luma.0, | ||
| 7475 | + ref_luma.1, | ||
| 7476 | + ref_luma.2, | ||
| 7477 | + ref_luma.3, | ||
| 7478 | + false, | ||
| 7479 | + search.base_q_idx, | ||
| 7480 | + search.deadzone, | ||
| 7481 | + luma_set, | ||
| 7482 | + fctx, | ||
| 7079 | ), | 7483 | ), |
| 7080 | mc_trial( | 7484 | mc_trial( |
| 7081 | - &chroma[0], x / 2, y / 2, side / 2, new_mv, false, ref_u.0, ref_u.1, | 7485 | + &chroma[0], |
| 7082 | - ref_u.2, ref_u.3, false, search.base_q_idx, search.deadzone, chroma_set, | 7486 | + x / 2, |
| 7487 | + y / 2, | ||
| 7488 | + side / 2, | ||
| 7489 | + new_mv, | ||
| 7490 | + false, | ||
| 7491 | + ref_u.0, | ||
| 7492 | + ref_u.1, | ||
| 7493 | + ref_u.2, | ||
| 7494 | + ref_u.3, | ||
| 7495 | + false, | ||
| 7496 | + search.base_q_idx, | ||
| 7497 | + search.deadzone, | ||
| 7498 | + chroma_set, | ||
| 7083 | fctx, | 7499 | fctx, |
| 7084 | ), | 7500 | ), |
| 7085 | mc_trial( | 7501 | mc_trial( |
| 7086 | - &chroma[1], x / 2, y / 2, side / 2, new_mv, false, ref_v.0, ref_v.1, | 7502 | + &chroma[1], |
| 7087 | - ref_v.2, ref_v.3, false, search.base_q_idx, search.deadzone, chroma_set, | 7503 | + x / 2, |
| 7504 | + y / 2, | ||
| 7505 | + side / 2, | ||
| 7506 | + new_mv, | ||
| 7507 | + false, | ||
| 7508 | + ref_v.0, | ||
| 7509 | + ref_v.1, | ||
| 7510 | + ref_v.2, | ||
| 7511 | + ref_v.3, | ||
| 7512 | + false, | ||
| 7513 | + search.base_q_idx, | ||
| 7514 | + search.deadzone, | ||
| 7515 | + chroma_set, | ||
| 7088 | fctx, | 7516 | fctx, |
| 7089 | ), | 7517 | ), |
| 7090 | ) | 7518 | ) |
| @@ -7113,7 +7541,15 @@ fn code_square_inter( | |||
| 7113 | } else { | 7541 | } else { |
| 7114 | luma_new.bits + u_new.bits + v_new.bits | 7542 | luma_new.bits + u_new.bits + v_new.bits |
| 7115 | }); | 7543 | }); |
| 7116 | - newmv_census_block(side, true, cost_new, best.0, new_mv, stack.nearest_mv, mv_bits); | 7544 | + newmv_census_block( |
| 7545 | + side, | ||
| 7546 | + true, | ||
| 7547 | + cost_new, | ||
| 7548 | + best.0, | ||
| 7549 | + new_mv, | ||
| 7550 | + stack.nearest_mv, | ||
| 7551 | + mv_bits, | ||
| 7552 | + ); | ||
| 7117 | if cost_new < best.0 { | 7553 | if cost_new < best.0 { |
| 7118 | single_syntax = intra_inter_bits(true) | 7554 | single_syntax = intra_inter_bits(true) |
| 7119 | + single_ref_bits | 7555 | + single_ref_bits |
| @@ -7154,13 +7590,15 @@ fn code_square_inter( | |||
| 7154 | // above stay. | 7590 | // above stay. |
| 7155 | arfmode_hit(2); | 7591 | arfmode_hit(2); |
| 7156 | } | 7592 | } |
| 7157 | - for (ref1, g, cstack) in compound.iter().filter(|_| leaf_compound() && search.arf_leaf_compound) { | 7593 | + for (ref1, g, cstack) in compound |
| 7594 | + .iter() | ||
| 7595 | + .filter(|_| leaf_compound() && search.arf_leaf_compound) | ||
| 7596 | + { | ||
| 7158 | let (ref1, g) = (*ref1, *g); | 7597 | let (ref1, g) = (*ref1, *g); |
| 7159 | // The whole `comp_mode` + reference-pair tree at the writer's own | 7598 | // The whole `comp_mode` + reference-pair tree at the writer's own |
| 7160 | // contexts, for THIS pair (lane-ctx). | 7599 | // contexts, for THIS pair (lane-ctx). |
| 7161 | let pair_bits = compound_ref_bits((crate::mvstack::LAST_FRAME, ref1), stack); | 7600 | let pair_bits = compound_ref_bits((crate::mvstack::LAST_FRAME, ref1), stack); |
| 7162 | - let mode_ctx = | 7601 | + let mode_ctx = cdf::COMPOUND_MODE_CTX_MAP[cstack.ref_mv_ctx >> 1][cstack.new_mv_ctx.min(4)]; |
| 7163 | - cdf::COMPOUND_MODE_CTX_MAP[cstack.ref_mv_ctx >> 1][cstack.new_mv_ctx.min(4)]; | ||
| 7164 | let mode_bits_of = | 7602 | let mode_bits_of = |
| 7165 | |mode: usize| pair_bits + symbol_bits(&cdf::INTER_COMPOUND_MODE[mode_ctx], mode); | 7603 | |mode: usize| pair_bits + symbol_bits(&cdf::INTER_COMPOUND_MODE[mode_ctx], mode); |
| 7166 | let mut ccands: Vec<(((i32, i32), (i32, i32)), f64, InterInfo)> = vec![ | 7604 | let mut ccands: Vec<(((i32, i32), (i32, i32)), f64, InterInfo)> = vec![ |
| @@ -7213,8 +7651,19 @@ fn code_square_inter( | |||
| 7213 | let skip = margin > 0.0 | 7651 | let skip = margin > 0.0 |
| 7214 | && searched_new_cost.is_some_and(|last| { | 7652 | && searched_new_cost.is_some_and(|last| { |
| 7215 | motion::cost_at( | 7653 | motion::cost_at( |
| 7216 | - &g.y, g.width, luma.true_width, luma.true_height, &source_block, x, y, | 7654 | + &g.y, |
| 7217 | - side, side, cstack.nearest_mv.1, cbase.1, search.lambda, fctx, | 7655 | + g.width, |
| 7656 | + luma.true_width, | ||
| 7657 | + luma.true_height, | ||
| 7658 | + &source_block, | ||
| 7659 | + x, | ||
| 7660 | + y, | ||
| 7661 | + side, | ||
| 7662 | + side, | ||
| 7663 | + cstack.nearest_mv.1, | ||
| 7664 | + cbase.1, | ||
| 7665 | + search.lambda, | ||
| 7666 | + fctx, | ||
| 7218 | ) * margin | 7667 | ) * margin |
| 7219 | <= last | 7668 | <= last |
| 7220 | }); | 7669 | }); |
| @@ -7229,8 +7678,20 @@ fn code_square_inter( | |||
| 7229 | seed_n += 1; | 7678 | seed_n += 1; |
| 7230 | } | 7679 | } |
| 7231 | let found = motion::search( | 7680 | let found = motion::search( |
| 7232 | - &g.y, g.width, luma.true_width, luma.true_height, &source_block, x, y, side, | 7681 | + &g.y, |
| 7233 | - side, cbase.1, &seeds[..seed_n], search.lambda, fctx, ref_distance(ref1), | 7682 | + g.width, |
| 7683 | + luma.true_width, | ||
| 7684 | + luma.true_height, | ||
| 7685 | + &source_block, | ||
| 7686 | + x, | ||
| 7687 | + y, | ||
| 7688 | + side, | ||
| 7689 | + side, | ||
| 7690 | + cbase.1, | ||
| 7691 | + &seeds[..seed_n], | ||
| 7692 | + search.lambda, | ||
| 7693 | + fctx, | ||
| 7694 | + ref_distance(ref1), | ||
| 7234 | ); | 7695 | ); |
| 7235 | second_new = Some(round_to_valid_mv(found.mv, cbase.1)); | 7696 | second_new = Some(round_to_valid_mv(found.mv, cbase.1)); |
| 7236 | } | 7697 | } |
| @@ -7302,19 +7763,46 @@ fn code_square_inter( | |||
| 7302 | ); | 7763 | ); |
| 7303 | for (mvs, bits, info) in ccands { | 7764 | for (mvs, bits, info) in ccands { |
| 7304 | let luma_c = mc_trial_compound( | 7765 | let luma_c = mc_trial_compound( |
| 7305 | - luma, x, y, side, mvs, true, | 7766 | + luma, |
| 7306 | - (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), g_luma, | 7767 | + x, |
| 7307 | - search.base_q_idx, search.deadzone, luma_set, fctx, | 7768 | + y, |
| 7769 | + side, | ||
| 7770 | + mvs, | ||
| 7771 | + true, | ||
| 7772 | + (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), | ||
| 7773 | + g_luma, | ||
| 7774 | + search.base_q_idx, | ||
| 7775 | + search.deadzone, | ||
| 7776 | + luma_set, | ||
| 7777 | + fctx, | ||
| 7308 | ); | 7778 | ); |
| 7309 | let u_c = mc_trial_compound( | 7779 | let u_c = mc_trial_compound( |
| 7310 | - &chroma[0], x / 2, y / 2, side / 2, mvs, false, | 7780 | + &chroma[0], |
| 7311 | - (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3), g_u, | 7781 | + x / 2, |
| 7312 | - search.base_q_idx, search.deadzone, chroma_set, fctx, | 7782 | + y / 2, |
| 7783 | + side / 2, | ||
| 7784 | + mvs, | ||
| 7785 | + false, | ||
| 7786 | + (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3), | ||
| 7787 | + g_u, | ||
| 7788 | + search.base_q_idx, | ||
| 7789 | + search.deadzone, | ||
| 7790 | + chroma_set, | ||
| 7791 | + fctx, | ||
| 7313 | ); | 7792 | ); |
| 7314 | let v_c = mc_trial_compound( | 7793 | let v_c = mc_trial_compound( |
| 7315 | - &chroma[1], x / 2, y / 2, side / 2, mvs, false, | 7794 | + &chroma[1], |
| 7316 | - (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3), g_v, | 7795 | + x / 2, |
| 7317 | - search.base_q_idx, search.deadzone, chroma_set, fctx, | 7796 | + y / 2, |
| 7797 | + side / 2, | ||
| 7798 | + mvs, | ||
| 7799 | + false, | ||
| 7800 | + (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3), | ||
| 7801 | + g_v, | ||
| 7802 | + search.base_q_idx, | ||
| 7803 | + search.deadzone, | ||
| 7804 | + chroma_set, | ||
| 7805 | + fctx, | ||
| 7318 | ); | 7806 | ); |
| 7319 | let skip_c = luma_c.levels.iter().all(|&l| l == 0) | 7807 | let skip_c = luma_c.levels.iter().all(|&l| l == 0) |
| 7320 | && u_c.levels.iter().all(|&l| l == 0) | 7808 | && u_c.levels.iter().all(|&l| l == 0) |
| @@ -7326,7 +7814,11 @@ fn code_square_inter( | |||
| 7326 | * (skip_bits(skip_c) | 7814 | * (skip_bits(skip_c) |
| 7327 | + intra_inter_bits(true) | 7815 | + intra_inter_bits(true) |
| 7328 | + bits | 7816 | + bits |
| 7329 | - + if skip_c { 0.0 } else { luma_c.bits + u_c.bits + v_c.bits }); | 7817 | + + if skip_c { |
| 7818 | + 0.0 | ||
| 7819 | + } else { | ||
| 7820 | + luma_c.bits + u_c.bits + v_c.bits | ||
| 7821 | + }); | ||
| 7330 | if cost_c < best.0 { | 7822 | if cost_c < best.0 { |
| 7331 | best = (cost_c, Some((luma_c, u_c, v_c, skip_c, info))); | 7823 | best = (cost_c, Some((luma_c, u_c, v_c, skip_c, info))); |
| 7332 | } | 7824 | } |
| @@ -7409,14 +7901,33 @@ fn code_square_inter( | |||
| 7409 | } | 7901 | } |
| 7410 | for (motion, pred) in candidates { | 7902 | for (motion, pred) in candidates { |
| 7411 | let luma_o = luma.code_from_prediction( | 7903 | let luma_o = luma.code_from_prediction( |
| 7412 | - x, y, side, &pred[0], false, search.base_q_idx, search.deadzone, luma_set, | 7904 | + x, |
| 7905 | + y, | ||
| 7906 | + side, | ||
| 7907 | + &pred[0], | ||
| 7908 | + false, | ||
| 7909 | + search.base_q_idx, | ||
| 7910 | + search.deadzone, | ||
| 7911 | + luma_set, | ||
| 7413 | ); | 7912 | ); |
| 7414 | let u_o = chroma[0].code_from_prediction( | 7913 | let u_o = chroma[0].code_from_prediction( |
| 7415 | - x / 2, y / 2, side / 2, &pred[1], false, search.base_q_idx, search.deadzone, | 7914 | + x / 2, |
| 7915 | + y / 2, | ||
| 7916 | + side / 2, | ||
| 7917 | + &pred[1], | ||
| 7918 | + false, | ||
| 7919 | + search.base_q_idx, | ||
| 7920 | + search.deadzone, | ||
| 7416 | chroma_set, | 7921 | chroma_set, |
| 7417 | ); | 7922 | ); |
| 7418 | let v_o = chroma[1].code_from_prediction( | 7923 | let v_o = chroma[1].code_from_prediction( |
| 7419 | - x / 2, y / 2, side / 2, &pred[2], false, search.base_q_idx, search.deadzone, | 7924 | + x / 2, |
| 7925 | + y / 2, | ||
| 7926 | + side / 2, | ||
| 7927 | + &pred[2], | ||
| 7928 | + false, | ||
| 7929 | + search.base_q_idx, | ||
| 7930 | + search.deadzone, | ||
| 7420 | chroma_set, | 7931 | chroma_set, |
| 7421 | ); | 7932 | ); |
| 7422 | let skip_o = luma_o.levels.iter().all(|&l| l == 0) | 7933 | let skip_o = luma_o.levels.iter().all(|&l| l == 0) |
| @@ -7429,7 +7940,11 @@ fn code_square_inter( | |||
| 7429 | * (skip_bits(skip_o) | 7940 | * (skip_bits(skip_o) |
| 7430 | + single_syntax | 7941 | + single_syntax |
| 7431 | + mm(motion) | 7942 | + mm(motion) |
| 7432 | - + if skip_o { 0.0 } else { luma_o.bits + u_o.bits + v_o.bits }); | 7943 | + + if skip_o { |
| 7944 | + 0.0 | ||
| 7945 | + } else { | ||
| 7946 | + luma_o.bits + u_o.bits + v_o.bits | ||
| 7947 | + }); | ||
| 7433 | // The incumbent pays the motion_mode symbol IT would code, so | 7948 | // The incumbent pays the motion_mode symbol IT would code, so |
| 7434 | // both sides of the comparison carry that syntax. | 7949 | // both sides of the comparison carry that syntax. |
| 7435 | if cost_o < best.0 + search.lambda * mm(motion_won) { | 7950 | if cost_o < best.0 + search.lambda * mm(motion_won) { |
| @@ -7487,22 +8002,31 @@ fn code_square_inter( | |||
| 7487 | ) | 8002 | ) |
| 7488 | }) | 8003 | }) |
| 7489 | }); | 8004 | }); |
| 7490 | - let (levels, tx_depth, dcost, luma_tx_types) = if motion_won != 0 | 8005 | + let (levels, tx_depth, dcost, luma_tx_types) = |
| 7491 | - || (info.ref1.is_some() && second.is_none()) | 8006 | + if motion_won != 0 || (info.ref1.is_some() && second.is_none()) { |
| 7492 | - { | 8007 | + luma.commit(x, y, side, &luma_new); |
| 7493 | - luma.commit(x, y, side, &luma_new); | 8008 | + (luma_new.levels.clone(), 0, 0.0, Vec::new()) |
| 7494 | - (luma_new.levels.clone(), 0, 0.0, Vec::new()) | 8009 | + } else { |
| 7495 | - } else { | 8010 | + commit_inter_luma( |
| 7496 | - commit_inter_luma( | 8011 | + luma, |
| 7497 | - luma, (x, y), side, info.mv, | 8012 | + (x, y), |
| 7498 | - (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), | 8013 | + side, |
| 7499 | - search, &luma_new, skip_new, second, fctx, | 8014 | + info.mv, |
| 7500 | - ) | 8015 | + (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), |
| 7501 | - }; | 8016 | + search, |
| 8017 | + &luma_new, | ||
| 8018 | + skip_new, | ||
| 8019 | + second, | ||
| 8020 | + fctx, | ||
| 8021 | + ) | ||
| 8022 | + }; | ||
| 7502 | // lane-txrd: chroma follows the luma type the search just chose. | 8023 | // lane-txrd: chroma follows the luma type the search just chose. |
| 7503 | let [u_new, v_new] = match luma_tx_types.first().copied() { | 8024 | let [u_new, v_new] = match luma_tx_types.first().copied() { |
| 7504 | Some(t) => recode_inter_chroma( | 8025 | Some(t) => recode_inter_chroma( |
| 7505 | - chroma, (x, y), side, info.mv, | 8026 | + chroma, |
| 8027 | + (x, y), | ||
| 8028 | + side, | ||
| 8029 | + info.mv, | ||
| 7506 | [ | 8030 | [ |
| 7507 | (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3), | 8031 | (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3), |
| 7508 | (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3), | 8032 | (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3), |
| @@ -7512,13 +8036,26 @@ fn code_square_inter( | |||
| 7512 | ( | 8036 | ( |
| 7513 | info.mv1, | 8037 | info.mv1, |
| 7514 | [ | 8038 | [ |
| 7515 | - (g.u.as_slice(), g.width / 2, chroma[0].true_width, chroma[0].true_height), | 8039 | + ( |
| 7516 | - (g.v.as_slice(), g.width / 2, chroma[1].true_width, chroma[1].true_height), | 8040 | + g.u.as_slice(), |
| 8041 | + g.width / 2, | ||
| 8042 | + chroma[0].true_width, | ||
| 8043 | + chroma[0].true_height, | ||
| 8044 | + ), | ||
| 8045 | + ( | ||
| 8046 | + g.v.as_slice(), | ||
| 8047 | + g.width / 2, | ||
| 8048 | + chroma[1].true_width, | ||
| 8049 | + chroma[1].true_height, | ||
| 8050 | + ), | ||
| 7517 | ], | 8051 | ], |
| 7518 | ) | 8052 | ) |
| 7519 | }) | 8053 | }) |
| 7520 | }), | 8054 | }), |
| 7521 | - search, chroma_set, t, fctx, | 8055 | + search, |
| 8056 | + chroma_set, | ||
| 8057 | + t, | ||
| 8058 | + fctx, | ||
| 7522 | ) | 8059 | ) |
| 7523 | .unwrap_or([u_new, v_new]), | 8060 | .unwrap_or([u_new, v_new]), |
| 7524 | None => [u_new, v_new], | 8061 | None => [u_new, v_new], |
| @@ -7539,7 +8076,7 @@ fn code_square_inter( | |||
| 7539 | eight: None, | 8076 | eight: None, |
crates/ec-av1/src/encoder.rsmodified+478 -139
| @@ -205,7 +205,14 @@ struct LevelPlan { | |||
| 205 | 205 | ||
| 206 | impl LevelPlan { | 206 | impl LevelPlan { |
| 207 | fn new(slot: usize, offset: i16, weight: f64) -> Self { | 207 | fn new(slot: usize, offset: i16, weight: f64) -> Self { |
| 208 | - Self { slot, offset, weight, left: weight, bound: false, rate: 0.0 } | 208 | + Self { |
| 209 | + slot, | ||
| 210 | + offset, | ||
| 211 | + weight, | ||
| 212 | + left: weight, | ||
| 213 | + bound: false, | ||
| 214 | + rate: 0.0, | ||
| 215 | + } | ||
| 209 | } | 216 | } |
| 210 | } | 217 | } |
| 211 | 218 | ||
| @@ -325,9 +332,8 @@ impl RateLoop { | |||
| 325 | }; | 332 | }; |
| 326 | let (hidden, leaves) = gop_shape(p, gop); | 333 | let (hidden, leaves) = gop_shape(p, gop); |
| 327 | let key = KEY_WEIGHT * w(p.key_q_offset); | 334 | let key = KEY_WEIGHT * w(p.key_q_offset); |
| 328 | - let total: f64 = key | 335 | + let total: f64 = |
| 329 | - + leaves as f64 | 336 | + key + leaves as f64 + hidden.iter().map(|&(o, n)| n as f64 * w(o)).sum::<f64>(); |
| 330 | - + hidden.iter().map(|&(o, n)| n as f64 * w(o)).sum::<f64>(); | ||
| 331 | // One leaf's byte target: the run is worth `gop` frame targets and | 337 | // One leaf's byte target: the run is worth `gop` frame targets and |
| 332 | // `total` leaves. | 338 | // `total` leaves. |
| 333 | let scale = target_bytes * gop.max(1) as f64 / total.max(f64::EPSILON); | 339 | let scale = target_bytes * gop.max(1) as f64 / total.max(f64::EPSILON); |
| @@ -441,7 +447,10 @@ impl RateLoop { | |||
| 441 | }; | 447 | }; |
| 442 | self.q[slot] = (self.q[slot] + step).clamp(0.0, 255.0); | 448 | self.q[slot] = (self.q[slot] + step).clamp(0.0, 255.0); |
| 443 | let bound = !(1..=255).contains(&raw_q); | 449 | let bound = !(1..=255).contains(&raw_q); |
| 444 | - if let Some(plan) = self.plan_of(slot, offset).and_then(|i| self.plans[i].as_mut()) { | 450 | + if let Some(plan) = self |
| 451 | + .plan_of(slot, offset) | ||
| 452 | + .and_then(|i| self.plans[i].as_mut()) | ||
| 453 | + { | ||
| 445 | plan.bound = bound; | 454 | plan.bound = bound; |
| 446 | plan.rate = actual_bytes as f64 / frame_weight.max(f64::EPSILON); | 455 | plan.rate = actual_bytes as f64 / frame_weight.max(f64::EPSILON); |
| 447 | } | 456 | } |
| @@ -478,7 +487,14 @@ impl RateLoop { | |||
| 478 | /// clamped proportional step, the re-plan only moves the TARGET the next | 487 | /// clamped proportional step, the re-plan only moves the TARGET the next |
| 479 | /// frame is measured against, and every key frame resets the whole plan, | 488 | /// frame is measured against, and every key frame resets the whole plan, |
| 480 | /// so no debt outlives one run. | 489 | /// so no debt outlives one run. |
| 481 | - fn replan(&mut self, level: Level, slot: usize, offset: i16, frame_weight: f64, actual_bytes: f64) { | 490 | + fn replan( |
| 491 | + &mut self, | ||
| 492 | + level: Level, | ||
| 493 | + slot: usize, | ||
| 494 | + offset: i16, | ||
| 495 | + frame_weight: f64, | ||
| 496 | + actual_bytes: f64, | ||
| 497 | + ) { | ||
| 482 | if !self.per_level { | 498 | if !self.per_level { |
| 483 | return; | 499 | return; |
| 484 | } | 500 | } |
| @@ -491,7 +507,10 @@ impl RateLoop { | |||
| 491 | } | 507 | } |
| 492 | self.left_weight -= frame_weight; | 508 | self.left_weight -= frame_weight; |
| 493 | self.left_bytes -= actual_bytes; | 509 | self.left_bytes -= actual_bytes; |
| 494 | - if let Some(plan) = self.plan_of(slot, offset).and_then(|i| self.plans[i].as_mut()) { | 510 | + if let Some(plan) = self |
| 511 | + .plan_of(slot, offset) | ||
| 512 | + .and_then(|i| self.plans[i].as_mut()) | ||
| 513 | + { | ||
| 495 | plan.left = (plan.left - frame_weight).max(0.0); | 514 | plan.left = (plan.left - frame_weight).max(0.0); |
| 496 | } | 515 | } |
| 497 | // The tail of a run is not re-planned: under a leaf's worth of weight | 516 | // The tail of a run is not re-planned: under a leaf's worth of weight |
| @@ -526,8 +545,10 @@ impl RateLoop { | |||
| 526 | // Every movable level is spent: nothing left to re-solve over. | 545 | // Every movable level is spent: nothing left to re-solve over. |
| 527 | return; | 546 | return; |
| 528 | } | 547 | } |
| 529 | - let scale = (bytes / weight) | 548 | + let scale = (bytes / weight).clamp( |
| 530 | - .clamp(self.scale0 * Self::REPLAN_FLOOR, self.scale0 * Self::REPLAN_CLAMP); | 549 | + self.scale0 * Self::REPLAN_FLOOR, |
| 550 | + self.scale0 * Self::REPLAN_CLAMP, | ||
| 551 | + ); | ||
| 531 | self.target = [scale * self.key_weight, scale, scale]; | 552 | self.target = [scale * self.key_weight, scale, scale]; |
| 532 | } | 553 | } |
| 533 | } | 554 | } |
| @@ -759,8 +780,14 @@ impl Pyramid { | |||
| 759 | } | 780 | } |
| 760 | Some(Self { | 781 | Some(Self { |
| 761 | mini_gop, | 782 | mini_gop, |
| 762 | - arf_q_offset: f.next().and_then(|v| v.parse().ok()).unwrap_or(d.arf_q_offset), | 783 | + arf_q_offset: f |
| 763 | - leaf_q_offset: f.next().and_then(|v| v.parse().ok()).unwrap_or(d.leaf_q_offset), | 784 | + .next() |
| 785 | + .and_then(|v| v.parse().ok()) | ||
| 786 | + .unwrap_or(d.arf_q_offset), | ||
| 787 | + leaf_q_offset: f | ||
| 788 | + .next() | ||
| 789 | + .and_then(|v| v.parse().ok()) | ||
| 790 | + .unwrap_or(d.leaf_q_offset), | ||
| 764 | // A fourth field is the mid-level offset; the literal `off` asks | 791 | // A fourth field is the mid-level offset; the literal `off` asks |
| 765 | // for the two-level pyramid at the same shape (the A/B arm the | 792 | // for the two-level pyramid at the same shape (the A/B arm the |
| 766 | // sweep needs), and no field at all keeps the default's. | 793 | // sweep needs), and no field at all keeps the default's. |
| @@ -770,7 +797,10 @@ impl Pyramid { | |||
| 770 | Some(v) => v.parse().ok().or(d.mid_q_offset), | 797 | Some(v) => v.parse().ok().or(d.mid_q_offset), |
| 771 | }, | 798 | }, |
| 772 | // A fifth field is the key frame's own offset. | 799 | // A fifth field is the key frame's own offset. |
| 773 | - key_q_offset: f.next().and_then(|v| v.parse().ok()).unwrap_or(d.key_q_offset), | 800 | + key_q_offset: f |
| 801 | + .next() | ||
| 802 | + .and_then(|v| v.parse().ok()) | ||
| 803 | + .unwrap_or(d.key_q_offset), | ||
| 774 | // A sixth field is the quarter level's offset, `off` for none. | 804 | // A sixth field is the quarter level's offset, `off` for none. |
| 775 | quarter_q_offset: match f.next() { | 805 | quarter_q_offset: match f.next() { |
| 776 | None => d.quarter_q_offset, | 806 | None => d.quarter_q_offset, |
| @@ -1128,8 +1158,7 @@ fn last2() -> bool { | |||
| 1128 | /// this crate's tests never call `set_var` (`crate::envflags`), so the | 1158 | /// this crate's tests never call `set_var` (`crate::envflags`), so the |
| 1129 | /// witness turns the lever on through this while holding | 1159 | /// witness turns the lever on through this while holding |
| 1130 | /// [`crate::speed::knob_write`]. | 1160 | /// [`crate::speed::knob_write`]. |
| 1131 | -static LAST2_OVERRIDE: std::sync::atomic::AtomicU8 = | 1161 | +static LAST2_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX); |
| 1132 | - std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 1133 | 1162 | ||
| 1134 | /// Sets [`LAST2_OVERRIDE`]; `None` clears it. | 1163 | /// Sets [`LAST2_OVERRIDE`]; `None` clears it. |
| 1135 | #[allow(dead_code)] // set only from the `#[cfg(test)]` witness | 1164 | #[allow(dead_code)] // set only from the `#[cfg(test)]` witness |
| @@ -1256,8 +1285,7 @@ pub(crate) fn arf_tf_window_future() -> usize { | |||
| 1256 | /// [`set_last2`] has (this crate's tests never call `set_var`); `u8::MAX` / | 1285 | /// [`set_last2`] has (this crate's tests never call `set_var`); `u8::MAX` / |
| 1257 | /// `usize::MAX` is unset, and a witness holds [`crate::speed::knob_write`] | 1286 | /// `usize::MAX` is unset, and a witness holds [`crate::speed::knob_write`] |
| 1258 | /// while it uses them. | 1287 | /// while it uses them. |
| 1259 | -static LOOKAHEAD_OVERRIDE: std::sync::atomic::AtomicU8 = | 1288 | +static LOOKAHEAD_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX); |
| 1260 | - std::sync::atomic::AtomicU8::new(u8::MAX); | ||
| 1261 | static ARF_TF_FUT_OVERRIDE: std::sync::atomic::AtomicUsize = | 1289 | static ARF_TF_FUT_OVERRIDE: std::sync::atomic::AtomicUsize = |
| 1262 | std::sync::atomic::AtomicUsize::new(usize::MAX); | 1290 | std::sync::atomic::AtomicUsize::new(usize::MAX); |
| 1263 | static TPL_FUT_OVERRIDE: std::sync::atomic::AtomicUsize = | 1291 | static TPL_FUT_OVERRIDE: std::sync::atomic::AtomicUsize = |
| @@ -1275,13 +1303,19 @@ pub(crate) fn set_lookahead(on: Option<bool>) { | |||
| 1275 | /// Sets [`ARF_TF_FUT_OVERRIDE`]; `None` clears it. | 1303 | /// Sets [`ARF_TF_FUT_OVERRIDE`]; `None` clears it. |
| 1276 | #[allow(dead_code)] // set only from the `#[cfg(test)]` witness | 1304 | #[allow(dead_code)] // set only from the `#[cfg(test)]` witness |
| 1277 | pub(crate) fn set_arf_tf_future(n: Option<usize>) { | 1305 | pub(crate) fn set_arf_tf_future(n: Option<usize>) { |
| 1278 | - ARF_TF_FUT_OVERRIDE.store(n.unwrap_or(usize::MAX), std::sync::atomic::Ordering::Relaxed); | 1306 | + ARF_TF_FUT_OVERRIDE.store( |
| 1307 | + n.unwrap_or(usize::MAX), | ||
| 1308 | + std::sync::atomic::Ordering::Relaxed, | ||
| 1309 | + ); | ||
| 1279 | } | 1310 | } |
| 1280 | 1311 | ||
| 1281 | /// Sets [`TPL_FUT_OVERRIDE`]; `None` clears it. | 1312 | /// Sets [`TPL_FUT_OVERRIDE`]; `None` clears it. |
| 1282 | #[allow(dead_code)] // set only from the `#[cfg(test)]` witness | 1313 | #[allow(dead_code)] // set only from the `#[cfg(test)]` witness |
| 1283 | pub(crate) fn set_tpl_fut(n: Option<usize>) { | 1314 | pub(crate) fn set_tpl_fut(n: Option<usize>) { |
| 1284 | - TPL_FUT_OVERRIDE.store(n.unwrap_or(usize::MAX), std::sync::atomic::Ordering::Relaxed); | 1315 | + TPL_FUT_OVERRIDE.store( |
| 1316 | + n.unwrap_or(usize::MAX), | ||
| 1317 | + std::sync::atomic::Ordering::Relaxed, | ||
| 1318 | + ); | ||
| 1285 | } | 1319 | } |
| 1286 | 1320 | ||
| 1287 | /// lane-tplfut: which window the TOP ARF's temporal lambda map propagates | 1321 | /// lane-tplfut: which window the TOP ARF's temporal lambda map propagates |
| @@ -1816,7 +1850,10 @@ impl Av1Encoder { | |||
| 1816 | None, | 1850 | None, |
| 1817 | &self.fctx, | 1851 | &self.fctx, |
| 1818 | None, | 1852 | None, |
| 1819 | - &lookahead.iter().map(|n| n.padded_to(SUPERBLOCK)).collect::<Vec<_>>(), | 1853 | + &lookahead |
| 1854 | + .iter() | ||
| 1855 | + .map(|n| n.padded_to(SUPERBLOCK)) | ||
| 1856 | + .collect::<Vec<_>>(), | ||
| 1820 | )? | 1857 | )? |
| 1821 | }; | 1858 | }; |
| 1822 | 1859 | ||
| @@ -1892,15 +1929,18 @@ impl Av1Encoder { | |||
| 1892 | let mut collected = encoder.collected.take().expect("collecting"); | 1929 | let mut collected = encoder.collected.take().expect("collecting"); |
| 1893 | // Every source picture is coded exactly once, so a frame's display | 1930 | // Every source picture is coded exactly once, so a frame's display |
| 1894 | // order IS its index once the list is sorted by it. | 1931 | // order IS its index once the list is sorted by it. |
| 1895 | - let coding_order: Vec<usize> = | 1932 | + let coding_order: Vec<usize> = collected.iter().map(|(order, _)| *order as usize).collect(); |
| 1896 | - collected.iter().map(|(order, _)| *order as usize).collect(); | ||
| 1897 | collected.sort_by_key(|(order, _)| *order); | 1933 | collected.sort_by_key(|(order, _)| *order); |
| 1898 | let frames: Vec<Encoded> = collected.into_iter().map(|(_, encoded)| encoded).collect(); | 1934 | let frames: Vec<Encoded> = collected.into_iter().map(|(_, encoded)| encoded).collect(); |
| 1899 | assert!( | 1935 | assert!( |
| 1900 | coding_order.iter().all(|&i| i < frames.len()), | 1936 | coding_order.iter().all(|&i| i < frames.len()), |
| 1901 | "a coded frame's display position is outside the sequence" | 1937 | "a coded frame's display position is outside the sequence" |
| 1902 | ); | 1938 | ); |
| 1903 | - Ok(crate::encode::EncodedSequence { stream, frames, coding_order }) | 1939 | + Ok(crate::encode::EncodedSequence { |
| 1940 | + stream, | ||
| 1941 | + frames, | ||
| 1942 | + coding_order, | ||
| 1943 | + }) | ||
| 1904 | } | 1944 | } |
| 1905 | 1945 | ||
| 1906 | /// Stamps a packet with its display and coding positions and advances the | 1946 | /// Stamps a packet with its display and coding positions and advances the |
| @@ -1938,7 +1978,9 @@ impl Av1Encoder { | |||
| 1938 | let base = self | 1978 | let base = self |
| 1939 | .rate_loop | 1979 | .rate_loop |
| 1940 | .as_ref() | 1980 | .as_ref() |
| 1941 | - .map_or(i16::from(self.config.base_q_idx), |r| i16::from(r.q_idx(Level::Key))); | 1981 | + .map_or(i16::from(self.config.base_q_idx), |r| { |
| 1982 | + i16::from(r.q_idx(Level::Key)) | ||
| 1983 | + }); | ||
| 1942 | let offset = self.pyramid.map_or(0, |p| p.key_q_offset); | 1984 | let offset = self.pyramid.map_or(0, |p| p.key_q_offset); |
| 1943 | let base_q_idx = (base + offset).clamp(1, 255) as u8; | 1985 | let base_q_idx = (base + offset).clamp(1, 255) as u8; |
| 1944 | let encoded = encode_key_frame_inner( | 1986 | let encoded = encode_key_frame_inner( |
| @@ -2030,8 +2072,7 @@ impl Av1Encoder { | |||
| 2030 | // A LAST2 slot only counts when it holds a picture that is not the | 2072 | // A LAST2 slot only counts when it holds a picture that is not the |
| 2031 | // one `LAST_FRAME` already names; otherwise the frame codes the | 2073 | // one `LAST_FRAME` already names; otherwise the frame codes the |
| 2032 | // reference set it always did. | 2074 | // reference set it always did. |
| 2033 | - let last2_slot = last2_slot | 2075 | + let last2_slot = last2_slot.filter(|&s| s != last_slot && self.dpb[s as usize].is_some()); |
| 2034 | - .filter(|&s| s != last_slot && self.dpb[s as usize].is_some()); | ||
| 2035 | let slots = [ | 2076 | let slots = [ |
| 2036 | last_slot, | 2077 | last_slot, |
| 2037 | last2_slot.unwrap_or(last_slot), | 2078 | last2_slot.unwrap_or(last_slot), |
| @@ -2055,14 +2096,26 @@ impl Av1Encoder { | |||
| 2055 | .as_ref() | 2096 | .as_ref() |
| 2056 | .map(|s| s.picture.clone()) | 2097 | .map(|s| s.picture.clone()) |
| 2057 | .ok_or_else(|| { | 2098 | .ok_or_else(|| { |
| 2058 | - Error::unsupported("AV1 encode", "an inter frame needs a previous reconstruction") | 2099 | + Error::unsupported( |
| 2100 | + "AV1 encode", | ||
| 2101 | + "an inter frame needs a previous reconstruction", | ||
| 2102 | + ) | ||
| 2059 | })?; | 2103 | })?; |
| 2060 | - let last2 = last2_slot.and_then(|s| self.dpb[s as usize].as_ref().map(|d| d.picture.clone())); | 2104 | + let last2 = |
| 2061 | - let golden = self.dpb[GOLDEN_SLOT as usize].as_ref().map(|s| s.picture.clone()); | 2105 | + last2_slot.and_then(|s| self.dpb[s as usize].as_ref().map(|d| d.picture.clone())); |
| 2106 | + let golden = self.dpb[GOLDEN_SLOT as usize] | ||
| 2107 | + .as_ref() | ||
| 2108 | + .map(|s| s.picture.clone()); | ||
| 2062 | let altref = (altref_slot != GOLDEN_SLOT) | 2109 | let altref = (altref_slot != GOLDEN_SLOT) |
| 2063 | - .then(|| self.dpb[altref_slot as usize].as_ref().map(|s| s.picture.clone())) | 2110 | + .then(|| { |
| 2111 | + self.dpb[altref_slot as usize] | ||
| 2112 | + .as_ref() | ||
| 2113 | + .map(|s| s.picture.clone()) | ||
| 2114 | + }) | ||
| 2064 | .flatten(); | 2115 | .flatten(); |
| 2065 | - let start_cdfs = self.dpb[last_slot as usize].as_ref().map(|s| s.cdfs.0.clone()); | 2116 | + let start_cdfs = self.dpb[last_slot as usize] |
| 2117 | + .as_ref() | ||
| 2118 | + .map(|s| s.cdfs.0.clone()); | ||
| 2066 | // lane-arfpred: the top ARF is coded from a TEMPORALLY FILTERED | 2119 | // lane-arfpred: the top ARF is coded from a TEMPORALLY FILTERED |
| 2067 | // source when `speed::ARF_TF` is non-zero -- the grain it would | 2120 | // source when `speed::ARF_TF` is non-zero -- the grain it would |
| 2068 | // otherwise spend its residual on is averaged out against the | 2121 | // otherwise spend its residual on is averaged out against the |
| @@ -2097,33 +2150,35 @@ impl Av1Encoder { | |||
| 2097 | } | 2150 | } |
| 2098 | false => source, | 2151 | false => source, |
| 2099 | }; | 2152 | }; |
| 2100 | - let encoded = || -> Result<Encoded> { encode_inter_frame( | 2153 | + let encoded = || -> Result<Encoded> { |
| 2101 | - &source, | 2154 | + encode_inter_frame( |
| 2102 | - &reference, | 2155 | + &source, |
| 2103 | - base_q_idx, | 2156 | + &reference, |
| 2104 | - DEADZONE, | 2157 | + base_q_idx, |
| 2105 | - order_hint, | 2158 | + DEADZONE, |
| 2106 | - order_hints, | 2159 | + order_hint, |
| 2107 | - render, | 2160 | + order_hints, |
| 2108 | - start_cdfs.as_ref(), | 2161 | + render, |
| 2109 | - golden.as_ref(), | 2162 | + start_cdfs.as_ref(), |
| 2110 | - altref.as_ref(), | 2163 | + golden.as_ref(), |
| 2111 | - last2.as_ref(), | 2164 | + altref.as_ref(), |
| 2112 | - &self.fctx, | 2165 | + last2.as_ref(), |
| 2113 | - Some(crate::encode::PyramidFrame { | 2166 | + &self.fctx, |
| 2114 | - last_slot, | 2167 | + Some(crate::encode::PyramidFrame { |
| 2115 | - self_slot, | 2168 | + last_slot, |
| 2116 | - altref_slot, | 2169 | + self_slot, |
| 2117 | - last2_slot, | 2170 | + altref_slot, |
| 2118 | - show_frame, | 2171 | + last2_slot, |
| 2119 | - sign_bias, | 2172 | + show_frame, |
| 2120 | - dq_level, | 2173 | + sign_bias, |
| 2121 | - }), | 2174 | + dq_level, |
| 2122 | - // lane-arfcen: the group's own sources ARE this frame's window | 2175 | + }), |
| 2123 | - // (`tpl_window`); it was `&[]` here, which switched the temporal | 2176 | + // lane-arfcen: the group's own sources ARE this frame's window |
| 2124 | - // lambda map off on every frame the default stream codes. | 2177 | + // (`tpl_window`); it was `&[]` here, which switched the temporal |
| 2125 | - lookahead, | 2178 | + // lambda map off on every frame the default stream codes. |
| 2126 | - ) }(); | 2179 | + lookahead, |
| 2180 | + ) | ||
| 2181 | + }(); | ||
| 2127 | // Name the pyramid position in any failure: an error out of the tile | 2182 | // Name the pyramid position in any failure: an error out of the tile |
| 2128 | // writer or the filter search is otherwise indistinguishable between | 2183 | // writer or the filter search is otherwise indistinguishable between |
| 2129 | // the hidden frame and the leaves that read it. | 2184 | // the hidden frame and the leaves that read it. |
| @@ -2212,14 +2267,20 @@ impl Av1Encoder { | |||
| 2212 | false => group[pos + 1..].iter().map(|(_, p)| p).collect(), | 2267 | false => group[pos + 1..].iter().map(|(_, p)| p).collect(), |
| 2213 | true => group[..pos].iter().rev().map(|(_, p)| p).collect(), | 2268 | true => group[..pos].iter().rev().map(|(_, p)| p).collect(), |
| 2214 | }; | 2269 | }; |
| 2215 | - window.into_iter().take(depth - 1).map(|p| p.padded_to(SUPERBLOCK)).collect() | 2270 | + window |
| 2271 | + .into_iter() | ||
| 2272 | + .take(depth - 1) | ||
| 2273 | + .map(|p| p.padded_to(SUPERBLOCK)) | ||
| 2274 | + .collect() | ||
| 2216 | }; | 2275 | }; |
| 2217 | // lane-last2: the slot a frame reading `last_slot` as `LAST_FRAME` | 2276 | // lane-last2: the slot a frame reading `last_slot` as `LAST_FRAME` |
| 2218 | // names as `LAST2_FRAME` -- the most recent shown leaf that is not | 2277 | // names as `LAST2_FRAME` -- the most recent shown leaf that is not |
| 2219 | // the one it already reads. `None` with the lever off, or before two | 2278 | // the one it already reads. `None` with the lever off, or before two |
| 2220 | // distinct past pictures exist. | 2279 | // distinct past pictures exist. |
| 2221 | let last2_of = |hist: &[u8], last_slot: u8| -> Option<u8> { | 2280 | let last2_of = |hist: &[u8], last_slot: u8| -> Option<u8> { |
| 2222 | - last2().then(|| hist.iter().copied().find(|&s| s != last_slot)).flatten() | 2281 | + last2() |
| 2282 | + .then(|| hist.iter().copied().find(|&s| s != last_slot)) | ||
| 2283 | + .flatten() | ||
| 2223 | }; | 2284 | }; |
| 2224 | let anchor_slot = ANCHOR_SLOTS[self.anchor]; | 2285 | let anchor_slot = ANCHOR_SLOTS[self.anchor]; |
| 2225 | let next_anchor_slot = ANCHOR_SLOTS[1 - self.anchor]; | 2286 | let next_anchor_slot = ANCHOR_SLOTS[1 - self.anchor]; |
| @@ -2263,7 +2324,11 @@ impl Av1Encoder { | |||
| 2263 | // `n` of the buffered display-future sources, nearest first, padded | 2324 | // `n` of the buffered display-future sources, nearest first, padded |
| 2264 | // like the frame being coded. | 2325 | // like the frame being coded. |
| 2265 | let arf_tpl_future = |n: usize| -> Vec<Picture> { | 2326 | let arf_tpl_future = |n: usize| -> Vec<Picture> { |
| 2266 | - future.iter().take(n).map(|(_, p)| p.padded_to(SUPERBLOCK)).collect() | 2327 | + future |
| 2328 | + .iter() | ||
| 2329 | + .take(n) | ||
| 2330 | + .map(|(_, p)| p.padded_to(SUPERBLOCK)) | ||
| 2331 | + .collect() | ||
| 2267 | }; | 2332 | }; |
| 2268 | let arf_tpl: Vec<Picture> = { | 2333 | let arf_tpl: Vec<Picture> = { |
| 2269 | let depth = crate::encode::tpl_depth(); | 2334 | let depth = crate::encode::tpl_depth(); |
| @@ -2332,10 +2397,13 @@ impl Av1Encoder { | |||
| 2332 | // third level is switched on by the RUN's length, not by the group's: | 2397 | // third level is switched on by the RUN's length, not by the group's: |
| 2333 | // the same GOP-length dependence `group_target` itself was built for. | 2398 | // the same GOP-length dependence `group_target` itself was built for. |
| 2334 | let long_run = self.config.gop > pyramid.mini_gop + pyramid.mini_gop / 2; | 2399 | let long_run = self.config.gop > pyramid.mini_gop + pyramid.mini_gop / 2; |
| 2335 | - let mid = pyramid.mid_q_offset.filter(|_| leaves >= 3 && long_run).map(|offset| { | 2400 | + let mid = pyramid |
| 2336 | - let at = (leaves - 1) / 2; | 2401 | + .mid_q_offset |
| 2337 | - (at, offset) | 2402 | + .filter(|_| leaves >= 3 && long_run) |
| 2338 | - }); | 2403 | + .map(|offset| { |
| 2404 | + let at = (leaves - 1) / 2; | ||
| 2405 | + (at, offset) | ||
| 2406 | + }); | ||
| 2339 | if let Some((at, offset)) = mid { | 2407 | if let Some((at, offset)) = mid { |
| 2340 | let (order, picture) = group[at].clone(); | 2408 | let (order, picture) = group[at].clone(); |
| 2341 | packets.push(self.encode_pyramid_inter( | 2409 | packets.push(self.encode_pyramid_inter( |
| @@ -2571,8 +2639,7 @@ mod tests { | |||
| 2571 | tile_rows_log2: 0, | 2639 | tile_rows_log2: 0, |
| 2572 | }; | 2640 | }; |
| 2573 | let rate = RateTarget::BytesPerFrame(2_000); | 2641 | let rate = RateTarget::BytesPerFrame(2_000); |
| 2574 | - let mut enc = | 2642 | + let mut enc = Av1Encoder::with_pyramid_and_rate_target(config, pyramid, rate).unwrap(); |
| 2575 | - Av1Encoder::with_pyramid_and_rate_target(config, pyramid, rate).unwrap(); | ||
| 2576 | let packets = encode_all(&mut enc, &pictures[..gop]); | 2643 | let packets = encode_all(&mut enc, &pictures[..gop]); |
| 2577 | let coded = |level: Level| packets.iter().filter(|p| p.level == level).count(); | 2644 | let coded = |level: Level| packets.iter().filter(|p| p.level == level).count(); |
| 2578 | let (hidden, leaves) = gop_shape(pyramid, gop); | 2645 | let (hidden, leaves) = gop_shape(pyramid, gop); |
| @@ -2592,8 +2659,12 @@ mod tests { | |||
| 2592 | let target_bytes = 2_000.0; | 2659 | let target_bytes = 2_000.0; |
| 2593 | let loop_ = RateLoop::new(target_bytes, 100.0, Some(pyramid), gop); | 2660 | let loop_ = RateLoop::new(target_bytes, 100.0, Some(pyramid), gop); |
| 2594 | let planned = loop_.target[0] | 2661 | let planned = loop_.target[0] |
| 2595 | - + loop_.target[2] * (leaves as f64 | 2662 | + + loop_.target[2] |
| 2596 | - + hidden.iter().map(|&(o, n)| n as f64 * loop_.weight(o)).sum::<f64>()); | 2663 | + * (leaves as f64 |
| 2664 | + + hidden | ||
| 2665 | + .iter() | ||
| 2666 | + .map(|&(o, n)| n as f64 * loop_.weight(o)) | ||
| 2667 | + .sum::<f64>()); | ||
| 2597 | assert!( | 2668 | assert!( |
| 2598 | (planned - target_bytes * gop as f64).abs() < 1.0, | 2669 | (planned - target_bytes * gop as f64).abs() < 1.0, |
| 2599 | "gop {gop}: plan {planned:.0} bytes against a {:.0} byte run", | 2670 | "gop {gop}: plan {planned:.0} bytes against a {:.0} byte run", |
| @@ -2646,7 +2717,8 @@ mod tests { | |||
| 2646 | "leaf target {:.3} is not the exact remainder {want:.3} (naive division would \ | 2717 | "leaf target {:.3} is not the exact remainder {want:.3} (naive division would \ |
| 2647 | give {:.3})", | 2718 | give {:.3})", |
| 2648 | rl.target[2], | 2719 | rl.target[2], |
| 2649 | - (run_bytes - key_bytes - arf_bytes) / (leaves as f64 + hidden_weight - rl.weight(offset)) | 2720 | + (run_bytes - key_bytes - arf_bytes) |
| 2721 | + / (leaves as f64 + hidden_weight - rl.weight(offset)) | ||
| 2650 | ); | 2722 | ); |
| 2651 | // And the re-plan stays BOUNDED: hidden levels that spend nothing at | 2723 | // And the re-plan stays BOUNDED: hidden levels that spend nothing at |
| 2652 | // all cannot run the leaves' target away. | 2724 | // all cannot run the leaves' target away. |
| @@ -2758,7 +2830,11 @@ mod tests { | |||
| 2758 | let tail = enc.flush().unwrap(); | 2830 | let tail = enc.flush().unwrap(); |
| 2759 | assert_eq!(tail.len() as u64, delay, "flush yields the whole queue"); | 2831 | assert_eq!(tail.len() as u64, delay, "flush yields the whole queue"); |
| 2760 | for (i, p) in tail.iter().enumerate() { | 2832 | for (i, p) in tail.iter().enumerate() { |
| 2761 | - assert_eq!(p.order, pictures - delay + i as u64, "flushed packet {i}: order"); | 2833 | + assert_eq!( |
| 2834 | + p.order, | ||
| 2835 | + pictures - delay + i as u64, | ||
| 2836 | + "flushed packet {i}: order" | ||
| 2837 | + ); | ||
| 2762 | assert!(!p.data.is_empty(), "flushed packet {i}: empty"); | 2838 | assert!(!p.data.is_empty(), "flushed packet {i}: empty"); |
| 2763 | } | 2839 | } |
| 2764 | assert!(enc.flush().unwrap().is_empty(), "nothing is held twice"); | 2840 | assert!(enc.flush().unwrap().is_empty(), "nothing is held twice"); |
| @@ -2808,9 +2884,7 @@ mod tests { | |||
| 2808 | }); | 2884 | }); |
| 2809 | let screen: Vec<Picture> = (0..frames).map(|t| screen_card(64, 64, t)).collect(); | 2885 | let screen: Vec<Picture> = (0..frames).map(|t| screen_card(64, 64, t)).collect(); |
| 2810 | let pyramid = Pyramid::from_env().expect("the pyramid is this build's default"); | 2886 | let pyramid = Pyramid::from_env().expect("the pyramid is this build's default"); |
| 2811 | - for (content, pictures, is_screen) in | 2887 | + for (content, pictures, is_screen) in [("film", &film, false), ("screen", &screen, true)] { |
| 2812 | - [("film", &film, false), ("screen", &screen, true)] | ||
| 2813 | - { | ||
| 2814 | let (width, height) = (pictures[0].width, pictures[0].height); | 2888 | let (width, height) = (pictures[0].width, pictures[0].height); |
| 2815 | for q in [150u8, 60] { | 2889 | for q in [150u8, 60] { |
| 2816 | let config = EncoderConfig { | 2890 | let config = EncoderConfig { |
| @@ -2838,7 +2912,10 @@ mod tests { | |||
| 2838 | ); | 2912 | ); |
| 2839 | let sequence = crate::encode::encode_sequence(pictures, q, DEADZONE).unwrap(); | 2913 | let sequence = crate::encode::encode_sequence(pictures, q, DEADZONE).unwrap(); |
| 2840 | assert_eq!( | 2914 | assert_eq!( |
| 2841 | - (packets.iter().map(|p| p.data.len()).sum::<usize>(), concat(&packets)), | 2915 | + ( |
| 2916 | + packets.iter().map(|p| p.data.len()).sum::<usize>(), | ||
| 2917 | + concat(&packets) | ||
| 2918 | + ), | ||
| 2842 | (sequence.stream.len(), sequence.stream.clone()), | 2919 | (sequence.stream.len(), sequence.stream.clone()), |
| 2843 | "{content} q={q}: the facade's stream is not the sequence path's" | 2920 | "{content} q={q}: the facade's stream is not the sequence path's" |
| 2844 | ); | 2921 | ); |
| @@ -2848,7 +2925,11 @@ mod tests { | |||
| 2848 | "{content} q={q}: one entry per picture, in display order" | 2925 | "{content} q={q}: one entry per picture, in display order" |
| 2849 | ); | 2926 | ); |
| 2850 | if is_screen { | 2927 | if is_screen { |
| 2851 | - assert_eq!(packets.len(), frames, "{content} q={q}: one packet per picture"); | 2928 | + assert_eq!( |
| 2929 | + packets.len(), | ||
| 2930 | + frames, | ||
| 2931 | + "{content} q={q}: one packet per picture" | ||
| 2932 | + ); | ||
| 2852 | for (i, (packet, coded)) in packets.iter().zip(&sequence.frames).enumerate() { | 2933 | for (i, (packet, coded)) in packets.iter().zip(&sequence.frames).enumerate() { |
| 2853 | let cropped = crate::encode::crop_encoded(coded, width, height); | 2934 | let cropped = crate::encode::crop_encoded(coded, width, height); |
| 2854 | assert_eq!( | 2935 | assert_eq!( |
| @@ -2894,7 +2975,11 @@ mod tests { | |||
| 2894 | let flat_packets = encode_all(&mut flat, &pictures); | 2975 | let flat_packets = encode_all(&mut flat, &pictures); |
| 2895 | let mut gated = Av1Encoder::with_pyramid(config, Pyramid::default()).unwrap(); | 2976 | let mut gated = Av1Encoder::with_pyramid(config, Pyramid::default()).unwrap(); |
| 2896 | let gated_packets = encode_all(&mut gated, &pictures); | 2977 | let gated_packets = encode_all(&mut gated, &pictures); |
| 2897 | - assert_eq!(gated.pyramid(), None, "the gate left a screen stream on the pyramid"); | 2978 | + assert_eq!( |
| 2979 | + gated.pyramid(), | ||
| 2980 | + None, | ||
| 2981 | + "the gate left a screen stream on the pyramid" | ||
| 2982 | + ); | ||
| 2898 | assert_eq!( | 2983 | assert_eq!( |
| 2899 | concat(&gated_packets), | 2984 | concat(&gated_packets), |
| 2900 | concat(&flat_packets), | 2985 | concat(&flat_packets), |
| @@ -2903,7 +2988,11 @@ mod tests { | |||
| 2903 | crate::encode::force_screen(Some(false)); | 2988 | crate::encode::force_screen(Some(false)); |
| 2904 | let mut kept = Av1Encoder::with_pyramid(config, Pyramid::default()).unwrap(); | 2989 | let mut kept = Av1Encoder::with_pyramid(config, Pyramid::default()).unwrap(); |
| 2905 | let kept_packets = encode_all(&mut kept, &pictures); | 2990 | let kept_packets = encode_all(&mut kept, &pictures); |
| 2906 | - assert_eq!(kept.pyramid(), Some(Pyramid::default()), "the gate ate a film stream"); | 2991 | + assert_eq!( |
| 2992 | + kept.pyramid(), | ||
| 2993 | + Some(Pyramid::default()), | ||
| 2994 | + "the gate ate a film stream" | ||
| 2995 | + ); | ||
| 2907 | assert!( | 2996 | assert!( |
| 2908 | kept_packets.iter().any(|p| p.level == Level::Arf), | 2997 | kept_packets.iter().any(|p| p.level == Level::Arf), |
| 2909 | "a non-screen stream coded no hidden frame" | 2998 | "a non-screen stream coded no hidden frame" |
| @@ -3203,8 +3292,14 @@ mod tests { | |||
| 3203 | width, | 3292 | width, |
| 3204 | height, | 3293 | height, |
| 3205 | y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), | 3294 | y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), |
| 3206 | - u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | 3295 | + u: bytes[luma..luma + chroma] |
| 3207 | - v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | 3296 | + .iter() |
| 3297 | + .map(|&v| u16::from(v)) | ||
| 3298 | + .collect(), | ||
| 3299 | + v: bytes[luma + chroma..] | ||
| 3300 | + .iter() | ||
| 3301 | + .map(|&v| u16::from(v)) | ||
| 3302 | + .collect(), | ||
| 3208 | } | 3303 | } |
| 3209 | }) | 3304 | }) |
| 3210 | .collect(), | 3305 | .collect(), |
| @@ -3270,7 +3365,9 @@ mod tests { | |||
| 3270 | let _knobs = crate::speed::knob_read(); | 3365 | let _knobs = crate::speed::knob_read(); |
| 3271 | let (width, height, frames) = (640usize, 384usize, 48usize); | 3366 | let (width, height, frames) = (640usize, 384usize, 48usize); |
| 3272 | let Some(pictures) = h264_clip_frames(width, height, frames) else { | 3367 | let Some(pictures) = h264_clip_frames(width, height, frames) else { |
| 3273 | - eprintln!("SKIP bitrate_target_lands_within_5_percent_over_48_frames: no ffmpeg/fixture"); | 3368 | + eprintln!( |
| 3369 | + "SKIP bitrate_target_lands_within_5_percent_over_48_frames: no ffmpeg/fixture" | ||
| 3370 | + ); | ||
| 3274 | return; | 3371 | return; |
| 3275 | }; | 3372 | }; |
| 3276 | let fps = 24.0; | 3373 | let fps = 24.0; |
| @@ -3522,7 +3619,10 @@ mod tests { | |||
| 3522 | for packet in encode_all(&mut enc, &sources) { | 3619 | for packet in encode_all(&mut enc, &sources) { |
| 3523 | stream.extend_from_slice(&packet.data); | 3620 | stream.extend_from_slice(&packet.data); |
| 3524 | } | 3621 | } |
| 3525 | - eprintln!("{NAME}: {} cut colour-index maps written", crate::tile::palette_cut_maps_written()); | 3622 | + eprintln!( |
| 3623 | + "{NAME}: {} cut colour-index maps written", | ||
| 3624 | + crate::tile::palette_cut_maps_written() | ||
| 3625 | + ); | ||
| 3526 | assert!( | 3626 | assert!( |
| 3527 | crate::tile::palette_cut_maps_written() > 0, | 3627 | crate::tile::palette_cut_maps_written() > 0, |
| 3528 | "{NAME}: no palette block is cut by the frame edge here -- the gate would pass blind" | 3628 | "{NAME}: no palette block is cut by the frame edge here -- the gate would pass blind" |
| @@ -3536,11 +3636,7 @@ mod tests { | |||
| 3536 | let theirs = ffmpeg_decode_planes(&stream, width, height); | 3636 | let theirs = ffmpeg_decode_planes(&stream, width, height); |
| 3537 | assert_eq!(theirs.len(), sources.len(), "{NAME}: ffmpeg's frames"); | 3637 | assert_eq!(theirs.len(), sources.len(), "{NAME}: ffmpeg's frames"); |
| 3538 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 3638 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| 3539 | - for (plane, got, want) in [ | 3639 | + for (plane, got, want) in [("luma", &a.y, &b.0), ("U", &a.u, &b.1), ("V", &a.v, &b.2)] { |
| 3540 | - ("luma", &a.y, &b.0), | ||
| 3541 | - ("U", &a.u, &b.1), | ||
| 3542 | - ("V", &a.v, &b.2), | ||
| 3543 | - ] { | ||
| 3544 | let got: Vec<u8> = got.iter().map(|&v| v as u8).collect(); | 3640 | let got: Vec<u8> = got.iter().map(|&v| v as u8).collect(); |
| 3545 | if let Some(at) = got.iter().zip(want).position(|(x, y)| x != y) { | 3641 | if let Some(at) = got.iter().zip(want).position(|(x, y)| x != y) { |
| 3546 | let w = if plane == "luma" { width } else { width / 2 }; | 3642 | let w = if plane == "luma" { width } else { width / 2 }; |
| @@ -3552,6 +3648,13 @@ mod tests { | |||
| 3552 | want[at], | 3648 | want[at], |
| 3553 | ); | 3649 | ); |
| 3554 | } | 3650 | } |
| 3651 | + assert_eq!( | ||
| 3652 | + got.len(), | ||
| 3653 | + want.len(), | ||
| 3654 | + "{NAME}: frame {i} {plane} is {} samples, ffmpeg's is {}", | ||
| 3655 | + got.len(), | ||
| 3656 | + want.len() | ||
| 3657 | + ); | ||
| 3555 | } | 3658 | } |
| 3556 | } | 3659 | } |
| 3557 | } | 3660 | } |
| @@ -3573,7 +3676,14 @@ mod tests { | |||
| 3573 | // our read (seen once: LAST 0 GOLDEN 0 ALTREF 0), so this takes the | 3676 | // our read (seen once: LAST 0 GOLDEN 0 ALTREF 0), so this takes the |
| 3574 | // exclusive lock. | 3677 | // exclusive lock. |
| 3575 | let _knobs = crate::speed::knob_write(); | 3678 | let _knobs = crate::speed::knob_write(); |
| 3576 | - pyramid_round_trip(Pyramid { mini_gop: 4, mid_q_offset: None, ..Pyramid::default() }, 2); | 3679 | + pyramid_round_trip( |
| 3680 | + Pyramid { | ||
| 3681 | + mini_gop: 4, | ||
| 3682 | + mid_q_offset: None, | ||
| 3683 | + ..Pyramid::default() | ||
| 3684 | + }, | ||
| 3685 | + 2, | ||
| 3686 | + ); | ||
| 3577 | } | 3687 | } |
| 3578 | 3688 | ||
| 3579 | /// The same round trip over a THREE-level group (`mid_q_offset`): each | 3689 | /// The same round trip over a THREE-level group (`mid_q_offset`): each |
| @@ -3586,7 +3696,11 @@ mod tests { | |||
| 3586 | fn a_three_level_pyramid_stream_decodes_in_display_order() { | 3696 | fn a_three_level_pyramid_stream_decodes_in_display_order() { |
| 3587 | let _knobs = crate::speed::knob_write(); | 3697 | let _knobs = crate::speed::knob_write(); |
| 3588 | pyramid_round_trip( | 3698 | pyramid_round_trip( |
| 3589 | - Pyramid { mini_gop: 8, mid_q_offset: Some(-8), ..Pyramid::default() }, | 3699 | + Pyramid { |
| 3700 | + mini_gop: 8, | ||
| 3701 | + mid_q_offset: Some(-8), | ||
| 3702 | + ..Pyramid::default() | ||
| 3703 | + }, | ||
| 3590 | 2, | 3704 | 2, |
| 3591 | ); | 3705 | ); |
| 3592 | } | 3706 | } |
| @@ -3631,15 +3745,24 @@ mod tests { | |||
| 3631 | tile_cols_log2: 0, | 3745 | tile_cols_log2: 0, |
| 3632 | tile_rows_log2: 0, | 3746 | tile_rows_log2: 0, |
| 3633 | }; | 3747 | }; |
| 3634 | - let pyramid = Pyramid { key_q_offset: offset, ..Pyramid::default() }; | 3748 | + let pyramid = Pyramid { |
| 3749 | + key_q_offset: offset, | ||
| 3750 | + ..Pyramid::default() | ||
| 3751 | + }; | ||
| 3635 | let mut enc = Av1Encoder::with_pyramid(config, pyramid).unwrap(); | 3752 | let mut enc = Av1Encoder::with_pyramid(config, pyramid).unwrap(); |
| 3636 | let packets = enc.encode_frames(&test_card(128, 128, 0)).unwrap(); | 3753 | let packets = enc.encode_frames(&test_card(128, 128, 0)).unwrap(); |
| 3637 | - let key = packets.iter().find(|p| p.level == Level::Key).expect("key frame"); | 3754 | + let key = packets |
| 3755 | + .iter() | ||
| 3756 | + .find(|p| p.level == Level::Key) | ||
| 3757 | + .expect("key frame"); | ||
| 3638 | key.data.len() | 3758 | key.data.len() |
| 3639 | }; | 3759 | }; |
| 3640 | let (base, finer) = (key_bytes(0), key_bytes(-48)); | 3760 | let (base, finer) = (key_bytes(0), key_bytes(-48)); |
| 3641 | eprintln!("key at base q {base} bytes, at base q - 48 {finer} bytes"); | 3761 | eprintln!("key at base q {base} bytes, at base q - 48 {finer} bytes"); |
| 3642 | - assert!(finer > base, "key_q_offset -48 did not reach the key frame ({finer} <= {base})"); | 3762 | + assert!( |
| 3763 | + finer > base, | ||
| 3764 | + "key_q_offset -48 did not reach the key frame ({finer} <= {base})" | ||
| 3765 | + ); | ||
| 3643 | } | 3766 | } |
| 3644 | 3767 | ||
| 3645 | /// lane-last2's witness: a clip whose pictures ALTERNATE between two | 3768 | /// lane-last2's witness: a clip whose pictures ALTERNATE between two |
| @@ -3658,8 +3781,9 @@ mod tests { | |||
| 3658 | let _knobs = crate::speed::knob_write(); | 3781 | let _knobs = crate::speed::knob_write(); |
| 3659 | crate::encode::force_screen(Some(false)); | 3782 | crate::encode::force_screen(Some(false)); |
| 3660 | let (width, height) = (128usize, 128usize); | 3783 | let (width, height) = (128usize, 128usize); |
| 3661 | - let sources: Vec<Picture> = | 3784 | + let sources: Vec<Picture> = (0..9) |
| 3662 | - (0..9).map(|t| test_card(width, height, (t % 2) * 24)).collect(); | 3785 | + .map(|t| test_card(width, height, (t % 2) * 24)) |
| 3786 | + .collect(); | ||
| 3663 | let run = |on: bool| -> ([usize; 8], Vec<u8>, Vec<Packet>) { | 3787 | let run = |on: bool| -> ([usize; 8], Vec<u8>, Vec<Packet>) { |
| 3664 | set_last2(Some(on)); | 3788 | set_last2(Some(on)); |
| 3665 | let config = EncoderConfig { | 3789 | let config = EncoderConfig { |
| @@ -3671,7 +3795,11 @@ mod tests { | |||
| 3671 | tile_cols_log2: 0, | 3795 | tile_cols_log2: 0, |
| 3672 | tile_rows_log2: 0, | 3796 | tile_rows_log2: 0, |
| 3673 | }; | 3797 | }; |
| 3674 | - let pyramid = Pyramid { mini_gop: 4, mid_q_offset: None, ..Pyramid::default() }; | 3798 | + let pyramid = Pyramid { |
| 3799 | + mini_gop: 4, | ||
| 3800 | + mid_q_offset: None, | ||
| 3801 | + ..Pyramid::default() | ||
| 3802 | + }; | ||
| 3675 | let mut enc = Av1Encoder::with_pyramid(config, pyramid).unwrap(); | 3803 | let mut enc = Av1Encoder::with_pyramid(config, pyramid).unwrap(); |
| 3676 | let _ = crate::encode::take_ref_frame_hits(); | 3804 | let _ = crate::encode::take_ref_frame_hits(); |
| 3677 | let mut packets = Vec::new(); | 3805 | let mut packets = Vec::new(); |
| @@ -3688,8 +3816,16 @@ mod tests { | |||
| 3688 | eprintln!( | 3816 | eprintln!( |
| 3689 | "LAST2 off: LAST {} LAST2 {} GOLDEN {} ALTREF {} ({} B); \ | 3817 | "LAST2 off: LAST {} LAST2 {} GOLDEN {} ALTREF {} ({} B); \ |
| 3690 | on: LAST {} LAST2 {} GOLDEN {} ALTREF {} ({} B)", | 3818 | on: LAST {} LAST2 {} GOLDEN {} ALTREF {} ({} B)", |
| 3691 | - off_hits[1], off_hits[2], off_hits[4], off_hits[7], off_stream.len(), | 3819 | + off_hits[1], |
| 3692 | - on_hits[1], on_hits[2], on_hits[4], on_hits[7], stream.len(), | 3820 | + off_hits[2], |
| 3821 | + off_hits[4], | ||
| 3822 | + off_hits[7], | ||
| 3823 | + off_stream.len(), | ||
| 3824 | + on_hits[1], | ||
| 3825 | + on_hits[2], | ||
| 3826 | + on_hits[4], | ||
| 3827 | + on_hits[7], | ||
| 3828 | + stream.len(), | ||
| 3693 | ); | 3829 | ); |
| 3694 | assert_eq!(off_hits[2], 0, "LAST2 was coded with the lever OFF"); | 3830 | assert_eq!(off_hits[2], 0, "LAST2 was coded with the lever OFF"); |
| 3695 | assert!( | 3831 | assert!( |
| @@ -3701,7 +3837,11 @@ mod tests { | |||
| 3701 | // Display order and sample-exactness, both decoders (the same shape | 3837 | // Display order and sample-exactness, both decoders (the same shape |
| 3702 | // `pyramid_round_trip` gates the hidden frames with). | 3838 | // `pyramid_round_trip` gates the hidden frames with). |
| 3703 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 3839 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 3704 | - assert_eq!(ours.len(), sources.len(), "our decoder's display-order count"); | 3840 | + assert_eq!( |
| 3841 | + ours.len(), | ||
| 3842 | + sources.len(), | ||
| 3843 | + "our decoder's display-order count" | ||
| 3844 | + ); | ||
| 3705 | if !have_ffmpeg() { | 3845 | if !have_ffmpeg() { |
| 3706 | eprintln!("SKIP the ffmpeg half of the LAST2 witness: no ffmpeg"); | 3846 | eprintln!("SKIP the ffmpeg half of the LAST2 witness: no ffmpeg"); |
| 3707 | return; | 3847 | return; |
| @@ -3722,7 +3862,10 @@ mod tests { | |||
| 3722 | } | 3862 | } |
| 3723 | } | 3863 | } |
| 3724 | // The reordering itself is unchanged by the second leaf slot. | 3864 | // The reordering itself is unchanged by the second leaf slot. |
| 3725 | - let shown = packets.iter().filter(|p| p.level == Level::ShowExisting).count(); | 3865 | + let shown = packets |
| 3866 | + .iter() | ||
| 3867 | + .filter(|p| p.level == Level::ShowExisting) | ||
| 3868 | + .count(); | ||
| 3726 | let arfs = packets.iter().filter(|p| p.level == Level::Arf).count(); | 3869 | let arfs = packets.iter().filter(|p| p.level == Level::Arf).count(); |
| 3727 | assert_eq!(shown, arfs, "one show_existing_frame per hidden frame"); | 3870 | assert_eq!(shown, arfs, "one show_existing_frame per hidden frame"); |
| 3728 | } | 3871 | } |
| @@ -3826,14 +3969,27 @@ mod tests { | |||
| 3826 | held.len(), | 3969 | held.len(), |
| 3827 | "{n} pictures at gop {gop}: the lookahead changed the stream LENGTH" | 3970 | "{n} pictures at gop {gop}: the lookahead changed the stream LENGTH" |
| 3828 | ); | 3971 | ); |
| 3829 | - assert!(flat == held, "{n} pictures at gop {gop}: the stream is not byte-identical"); | 3972 | + assert!( |
| 3973 | + flat == held, | ||
| 3974 | + "{n} pictures at gop {gop}: the stream is not byte-identical" | ||
| 3975 | + ); | ||
| 3830 | assert_eq!( | 3976 | assert_eq!( |
| 3831 | - packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(), | 3977 | + packets |
| 3832 | - flat_packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(), | 3978 | + .iter() |
| 3979 | + .map(|p| (p.order, p.key, p.level)) | ||
| 3980 | + .collect::<Vec<_>>(), | ||
| 3981 | + flat_packets | ||
| 3982 | + .iter() | ||
| 3983 | + .map(|p| (p.order, p.key, p.level)) | ||
| 3984 | + .collect::<Vec<_>>(), | ||
| 3833 | "{n} pictures at gop {gop}: coding order/levels moved" | 3985 | "{n} pictures at gop {gop}: coding order/levels moved" |
| 3834 | ); | 3986 | ); |
| 3835 | let ours = crate::stream::decode_stream(&held).expect("our decoder"); | 3987 | let ours = crate::stream::decode_stream(&held).expect("our decoder"); |
| 3836 | - assert_eq!(ours.len(), n, "{n} pictures at gop {gop}: our decoder's count"); | 3988 | + assert_eq!( |
| 3989 | + ours.len(), | ||
| 3990 | + n, | ||
| 3991 | + "{n} pictures at gop {gop}: our decoder's count" | ||
| 3992 | + ); | ||
| 3837 | if !have_ffmpeg() { | 3993 | if !have_ffmpeg() { |
| 3838 | continue; | 3994 | continue; |
| 3839 | } | 3995 | } |
| @@ -3870,7 +4026,10 @@ mod tests { | |||
| 3870 | assert_eq!(theirs.len(), 17, "the symmetric arm's ffmpeg count"); | 4026 | assert_eq!(theirs.len(), 17, "the symmetric arm's ffmpeg count"); |
| 3871 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 4027 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| 3872 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); | 4028 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); |
| 3873 | - assert!(got == *b, "symmetric arm, display frame {i}: ours differs from ffmpeg"); | 4029 | + assert!( |
| 4030 | + got == *b, | ||
| 4031 | + "symmetric arm, display frame {i}: ours differs from ffmpeg" | ||
| 4032 | + ); | ||
| 3874 | } | 4033 | } |
| 3875 | } | 4034 | } |
| 3876 | crate::speed::set_speed(was); | 4035 | crate::speed::set_speed(was); |
| @@ -3921,17 +4080,31 @@ mod tests { | |||
| 3921 | for mode in [1usize, 2, 3] { | 4080 | for mode in [1usize, 2, 3] { |
| 3922 | let (on, packets) = run(n, gop, mode); | 4081 | let (on, packets) = run(n, gop, mode); |
| 3923 | assert_eq!( | 4082 | assert_eq!( |
| 3924 | - packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(), | 4083 | + packets |
| 3925 | - off_packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(), | 4084 | + .iter() |
| 4085 | + .map(|p| (p.order, p.key, p.level)) | ||
| 4086 | + .collect::<Vec<_>>(), | ||
| 4087 | + off_packets | ||
| 4088 | + .iter() | ||
| 4089 | + .map(|p| (p.order, p.key, p.level)) | ||
| 4090 | + .collect::<Vec<_>>(), | ||
| 3926 | "{n} pictures at gop {gop} mode {mode}: coding order/levels moved" | 4091 | "{n} pictures at gop {gop} mode {mode}: coding order/levels moved" |
| 3927 | ); | 4092 | ); |
| 3928 | let ours = crate::stream::decode_stream(&on).expect("our decoder"); | 4093 | let ours = crate::stream::decode_stream(&on).expect("our decoder"); |
| 3929 | - assert_eq!(ours.len(), n, "{n} pictures at gop {gop} mode {mode}: our count"); | 4094 | + assert_eq!( |
| 4095 | + ours.len(), | ||
| 4096 | + n, | ||
| 4097 | + "{n} pictures at gop {gop} mode {mode}: our count" | ||
| 4098 | + ); | ||
| 3930 | if !have_ffmpeg() { | 4099 | if !have_ffmpeg() { |
| 3931 | continue; | 4100 | continue; |
| 3932 | } | 4101 | } |
| 3933 | let theirs = ffmpeg_decode_luma(&on, width, height); | 4102 | let theirs = ffmpeg_decode_luma(&on, width, height); |
| 3934 | - assert_eq!(theirs.len(), n, "{n} pictures at gop {gop} mode {mode}: ffmpeg count"); | 4103 | + assert_eq!( |
| 4104 | + theirs.len(), | ||
| 4105 | + n, | ||
| 4106 | + "{n} pictures at gop {gop} mode {mode}: ffmpeg count" | ||
| 4107 | + ); | ||
| 3935 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 4108 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| 3936 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); | 4109 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); |
| 3937 | assert!( | 4110 | assert!( |
| @@ -4028,13 +4201,22 @@ mod tests { | |||
| 4028 | }; | 4201 | }; |
| 4029 | let (off, off_packets) = run(None); | 4202 | let (off, off_packets) = run(None); |
| 4030 | let (explicit_off, _) = run(Some(0)); | 4203 | let (explicit_off, _) = run(Some(0)); |
| 4031 | - assert_eq!(off, explicit_off, "mode 0 is not bit-exact with the default"); | 4204 | + assert_eq!( |
| 4205 | + off, explicit_off, | ||
| 4206 | + "mode 0 is not bit-exact with the default" | ||
| 4207 | + ); | ||
| 4032 | for (mode, arm) in [(1u8, 0usize), (2, 1), (4, 2)] { | 4208 | for (mode, arm) in [(1u8, 0usize), (2, 1), (4, 2)] { |
| 4033 | let (on, packets) = run(Some(mode)); | 4209 | let (on, packets) = run(Some(mode)); |
| 4034 | let hits = crate::encode::take_arfmode_hits(); | 4210 | let hits = crate::encode::take_arfmode_hits(); |
| 4035 | assert_eq!( | 4211 | assert_eq!( |
| 4036 | - packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(), | 4212 | + packets |
| 4037 | - off_packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(), | 4213 | + .iter() |
| 4214 | + .map(|p| (p.order, p.key, p.level)) | ||
| 4215 | + .collect::<Vec<_>>(), | ||
| 4216 | + off_packets | ||
| 4217 | + .iter() | ||
| 4218 | + .map(|p| (p.order, p.key, p.level)) | ||
| 4219 | + .collect::<Vec<_>>(), | ||
| 4038 | "mode {mode}: coding order/levels moved" | 4220 | "mode {mode}: coding order/levels moved" |
| 4039 | ); | 4221 | ); |
| 4040 | assert!( | 4222 | assert!( |
| @@ -4047,7 +4229,11 @@ mod tests { | |||
| 4047 | "mode {mode} left the stream byte-identical despite {} firing hits", | 4229 | "mode {mode} left the stream byte-identical despite {} firing hits", |
| 4048 | hits[arm], | 4230 | hits[arm], |
| 4049 | ); | 4231 | ); |
| 4050 | - eprintln!("mode {mode}: {} -> {} B, hits {hits:?}", off.len(), on.len()); | 4232 | + eprintln!( |
| 4233 | + "mode {mode}: {} -> {} B, hits {hits:?}", | ||
| 4234 | + off.len(), | ||
| 4235 | + on.len() | ||
| 4236 | + ); | ||
| 4051 | let ours = crate::stream::decode_stream(&on).expect("our decoder"); | 4237 | let ours = crate::stream::decode_stream(&on).expect("our decoder"); |
| 4052 | assert_eq!(ours.len(), 17, "mode {mode}: our decoder's picture count"); | 4238 | assert_eq!(ours.len(), 17, "mode {mode}: our decoder's picture count"); |
| 4053 | if !have_ffmpeg() { | 4239 | if !have_ffmpeg() { |
| @@ -4057,7 +4243,10 @@ mod tests { | |||
| 4057 | assert_eq!(theirs.len(), 17, "mode {mode}: ffmpeg's picture count"); | 4243 | assert_eq!(theirs.len(), 17, "mode {mode}: ffmpeg's picture count"); |
| 4058 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 4244 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| 4059 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); | 4245 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); |
| 4060 | - assert!(got == *b, "mode {mode}, frame {i}: ours differs from ffmpeg"); | 4246 | + assert!( |
| 4247 | + got == *b, | ||
| 4248 | + "mode {mode}, frame {i}: ours differs from ffmpeg" | ||
| 4249 | + ); | ||
| 4061 | } | 4250 | } |
| 4062 | } | 4251 | } |
| 4063 | crate::encode::set_arfmode(None); | 4252 | crate::encode::set_arfmode(None); |
| @@ -4098,9 +4287,16 @@ mod tests { | |||
| 4098 | .collect(); | 4287 | .collect(); |
| 4099 | let mut sorted = coded.clone(); | 4288 | let mut sorted = coded.clone(); |
| 4100 | sorted.sort_unstable(); | 4289 | sorted.sort_unstable(); |
| 4101 | - assert_eq!(sorted, (0..9).collect::<Vec<u64>>(), "one packet per picture"); | 4290 | + assert_eq!( |
| 4291 | + sorted, | ||
| 4292 | + (0..9).collect::<Vec<u64>>(), | ||
| 4293 | + "one packet per picture" | ||
| 4294 | + ); | ||
| 4102 | assert_ne!(coded, sorted, "the pyramid never reordered anything"); | 4295 | assert_ne!(coded, sorted, "the pyramid never reordered anything"); |
| 4103 | - let shown = packets.iter().filter(|p| p.level == Level::ShowExisting).count(); | 4296 | + let shown = packets |
| 4297 | + .iter() | ||
| 4298 | + .filter(|p| p.level == Level::ShowExisting) | ||
| 4299 | + .count(); | ||
| 4104 | assert_eq!(shown, hidden, "one show_existing_frame per hidden frame"); | 4300 | assert_eq!(shown, hidden, "one show_existing_frame per hidden frame"); |
| 4105 | for (i, p) in packets.iter().enumerate() { | 4301 | for (i, p) in packets.iter().enumerate() { |
| 4106 | assert_eq!(p.dts, i as u64, "packet {i}: dts is the coding position"); | 4302 | assert_eq!(p.dts, i as u64, "packet {i}: dts is the coding position"); |
| @@ -4133,7 +4329,11 @@ mod tests { | |||
| 4133 | 4329 | ||
| 4134 | let stream = concat(&packets); | 4330 | let stream = concat(&packets); |
| 4135 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 4331 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 4136 | - assert_eq!(ours.len(), sources.len(), "our decoder's display-order count"); | 4332 | + assert_eq!( |
| 4333 | + ours.len(), | ||
| 4334 | + sources.len(), | ||
| 4335 | + "our decoder's display-order count" | ||
| 4336 | + ); | ||
| 4137 | if !have_ffmpeg() { | 4337 | if !have_ffmpeg() { |
| 4138 | eprintln!("SKIP the ffmpeg half of the pyramid round trip: no ffmpeg"); | 4338 | eprintln!("SKIP the ffmpeg half of the pyramid round trip: no ffmpeg"); |
| 4139 | return; | 4339 | return; |
| @@ -4286,6 +4486,13 @@ mod tests { | |||
| 4286 | b[at], | 4486 | b[at], |
| 4287 | ); | 4487 | ); |
| 4288 | } | 4488 | } |
| 4489 | + assert_eq!( | ||
| 4490 | + got.len(), | ||
| 4491 | + b.len(), | ||
| 4492 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 4493 | + got.len(), | ||
| 4494 | + b.len() | ||
| 4495 | + ); | ||
| 4289 | } | 4496 | } |
| 4290 | } | 4497 | } |
| 4291 | 4498 | ||
| @@ -4356,6 +4563,13 @@ mod tests { | |||
| 4356 | b[at], | 4563 | b[at], |
| 4357 | ); | 4564 | ); |
| 4358 | } | 4565 | } |
| 4566 | + assert_eq!( | ||
| 4567 | + got.len(), | ||
| 4568 | + b.len(), | ||
| 4569 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 4570 | + got.len(), | ||
| 4571 | + b.len() | ||
| 4572 | + ); | ||
| 4359 | } | 4573 | } |
| 4360 | } | 4574 | } |
| 4361 | 4575 | ||
| @@ -4389,7 +4603,10 @@ mod tests { | |||
| 4389 | stream.extend_from_slice(&packet.data); | 4603 | stream.extend_from_slice(&packet.data); |
| 4390 | } | 4604 | } |
| 4391 | let edges = crate::encode::take_b64_edge_hits(); | 4605 | let edges = crate::encode::take_b64_edge_hits(); |
| 4392 | - assert!(edges > 0, "no 64x64 root was taken at a superblock the frame edge cuts"); | 4606 | + assert!( |
| 4607 | + edges > 0, | ||
| 4608 | + "no 64x64 root was taken at a superblock the frame edge cuts" | ||
| 4609 | + ); | ||
| 4393 | eprintln!("edge 64x64 roots: {edges}"); | 4610 | eprintln!("edge 64x64 roots: {edges}"); |
| 4394 | 4611 | ||
| 4395 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 4612 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| @@ -4411,6 +4628,13 @@ mod tests { | |||
| 4411 | theirs_i[at], | 4628 | theirs_i[at], |
| 4412 | ); | 4629 | ); |
| 4413 | } | 4630 | } |
| 4631 | + assert_eq!( | ||
| 4632 | + got.len(), | ||
| 4633 | + theirs_i.len(), | ||
| 4634 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 4635 | + got.len(), | ||
| 4636 | + theirs_i.len() | ||
| 4637 | + ); | ||
| 4414 | } | 4638 | } |
| 4415 | } | 4639 | } |
| 4416 | 4640 | ||
| @@ -4461,6 +4685,13 @@ mod tests { | |||
| 4461 | theirs_i[at], | 4685 | theirs_i[at], |
| 4462 | ); | 4686 | ); |
| 4463 | } | 4687 | } |
| 4688 | + assert_eq!( | ||
| 4689 | + got.len(), | ||
| 4690 | + theirs_i.len(), | ||
| 4691 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 4692 | + got.len(), | ||
| 4693 | + theirs_i.len() | ||
| 4694 | + ); | ||
| 4464 | } | 4695 | } |
| 4465 | } | 4696 | } |
| 4466 | 4697 | ||
| @@ -4527,6 +4758,13 @@ mod tests { | |||
| 4527 | theirs_i[at], | 4758 | theirs_i[at], |
| 4528 | ); | 4759 | ); |
| 4529 | } | 4760 | } |
| 4761 | + assert_eq!( | ||
| 4762 | + got.len(), | ||
| 4763 | + theirs_i.len(), | ||
| 4764 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 4765 | + got.len(), | ||
| 4766 | + theirs_i.len() | ||
| 4767 | + ); | ||
| 4530 | } | 4768 | } |
| 4531 | } | 4769 | } |
| 4532 | 4770 | ||
| @@ -4570,7 +4808,10 @@ mod tests { | |||
| 4570 | stream.extend_from_slice(&packet.data); | 4808 | stream.extend_from_slice(&packet.data); |
| 4571 | } | 4809 | } |
| 4572 | let compound = crate::encode::take_b64_compound_hits(); | 4810 | let compound = crate::encode::take_b64_compound_hits(); |
| 4573 | - assert!(compound > 0, "a crossfade clip coded no COMPOUND 64x64 root at all"); | 4811 | + assert!( |
| 4812 | + compound > 0, | ||
| 4813 | + "a crossfade clip coded no COMPOUND 64x64 root at all" | ||
| 4814 | + ); | ||
| 4574 | eprintln!("compound 64x64 roots on a crossfade clip: {compound}"); | 4815 | eprintln!("compound 64x64 roots on a crossfade clip: {compound}"); |
| 4575 | 4816 | ||
| 4576 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 4817 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| @@ -4592,6 +4833,13 @@ mod tests { | |||
| 4592 | theirs_i[at], | 4833 | theirs_i[at], |
| 4593 | ); | 4834 | ); |
| 4594 | } | 4835 | } |
| 4836 | + assert_eq!( | ||
| 4837 | + got.len(), | ||
| 4838 | + theirs_i.len(), | ||
| 4839 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 4840 | + got.len(), | ||
| 4841 | + theirs_i.len() | ||
| 4842 | + ); | ||
| 4595 | } | 4843 | } |
| 4596 | } | 4844 | } |
| 4597 | 4845 | ||
| @@ -4715,8 +4963,7 @@ mod tests { | |||
| 4715 | let x0 = 32 + t * 32; | 4963 | let x0 = 32 + t * 32; |
| 4716 | for y in 128..256 { | 4964 | for y in 128..256 { |
| 4717 | for x in x0..x0 + 128 { | 4965 | for x in x0..x0 + 128 { |
| 4718 | - p.y[y * width + x] = | 4966 | + p.y[y * width + x] = if (x / 2 + y / 3) % 2 == 0 { 40 } else { 210 }; |
| 4719 | - if (x / 2 + y / 3) % 2 == 0 { 40 } else { 210 }; | ||
| 4720 | } | 4967 | } |
| 4721 | } | 4968 | } |
| 4722 | p | 4969 | p |
| @@ -4749,7 +4996,10 @@ mod tests { | |||
| 4749 | "the quantizer grid was flat ({levels} level(s)): no delta_qindex was coded" | 4996 | "the quantizer grid was flat ({levels} level(s)): no delta_qindex was coded" |
| 4750 | ); | 4997 | ); |
| 4751 | } else { | 4998 | } else { |
| 4752 | - eprintln!("SKIP the fire count at preset {}: no tpl map", crate::speed::speed()); | 4999 | + eprintln!( |
| 5000 | + "SKIP the fire count at preset {}: no tpl map", | ||
| 5001 | + crate::speed::speed() | ||
| 5002 | + ); | ||
| 4753 | } | 5003 | } |
| 4754 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 5004 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 4755 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | 5005 | assert_eq!(ours.len(), sources.len(), "our decoder's frames"); |
| @@ -4767,12 +5017,22 @@ mod tests { | |||
| 4767 | b[at], | 5017 | b[at], |
| 4768 | ); | 5018 | ); |
| 4769 | } | 5019 | } |
| 5020 | + assert_eq!( | ||
| 5021 | + got.len(), | ||
| 5022 | + b.len(), | ||
| 5023 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 5024 | + got.len(), | ||
| 5025 | + b.len() | ||
| 5026 | + ); | ||
| 4770 | } | 5027 | } |
| 4771 | } else { | 5028 | } else { |
| 4772 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); | 5029 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); |
| 4773 | } | 5030 | } |
| 4774 | crate::encode::set_deltaq_res(None); | 5031 | crate::encode::set_deltaq_res(None); |
| 4775 | - eprintln!("delta_q witness: {levels} quantizer levels, {} bytes", stream.len()); | 5032 | + eprintln!( |
| 5033 | + "delta_q witness: {levels} quantizer levels, {} bytes", | ||
| 5034 | + stream.len() | ||
| 5035 | + ); | ||
| 4776 | } | 5036 | } |
| 4777 | 5037 | ||
| 4778 | /// lane-txset's witness: a clip of hard directional edges makes the intra | 5038 | /// lane-txset's witness: a clip of hard directional edges makes the intra |
| @@ -4837,8 +5097,8 @@ mod tests { | |||
| 4837 | // still has to reach SOME non-`DCT_DCT` type -- that is the | 5097 | // still has to reach SOME non-`DCT_DCT` type -- that is the |
| 4838 | // "reachable at all" statement, class `gate-blind-to-feature`. | 5098 | // "reachable at all" statement, class `gate-blind-to-feature`. |
| 4839 | if crate::speed::at(&crate::speed::TX_TYPE_SEARCH) { | 5099 | if crate::speed::at(&crate::speed::TX_TYPE_SEARCH) { |
| 4840 | - let non_dct: usize = hits.iter().sum::<usize>() | 5100 | + let non_dct: usize = |
| 4841 | - - hits[crate::transform::TxType::DctDct as usize]; | 5101 | + hits.iter().sum::<usize>() - hits[crate::transform::TxType::DctDct as usize]; |
| 4842 | assert!( | 5102 | assert!( |
| 4843 | non_dct > 0, | 5103 | non_dct > 0, |
| 4844 | "every luma transform unit took DCT_DCT: {hits:?}" | 5104 | "every luma transform unit took DCT_DCT: {hits:?}" |
| @@ -4879,6 +5139,13 @@ mod tests { | |||
| 4879 | b[at], | 5139 | b[at], |
| 4880 | ); | 5140 | ); |
| 4881 | } | 5141 | } |
| 5142 | + assert_eq!( | ||
| 5143 | + got.len(), | ||
| 5144 | + b.len(), | ||
| 5145 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 5146 | + got.len(), | ||
| 5147 | + b.len() | ||
| 5148 | + ); | ||
| 4882 | } | 5149 | } |
| 4883 | } else { | 5150 | } else { |
| 4884 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); | 5151 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); |
| @@ -4964,11 +5231,21 @@ mod tests { | |||
| 4964 | b[at], | 5231 | b[at], |
| 4965 | ); | 5232 | ); |
| 4966 | } | 5233 | } |
| 5234 | + assert_eq!( | ||
| 5235 | + got.len(), | ||
| 5236 | + b.len(), | ||
| 5237 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 5238 | + got.len(), | ||
| 5239 | + b.len() | ||
| 5240 | + ); | ||
| 4967 | } | 5241 | } |
| 4968 | } else { | 5242 | } else { |
| 4969 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); | 5243 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); |
| 4970 | } | 5244 | } |
| 4971 | - eprintln!("inter tx_type witness: hits {hits:?}, {} bytes", stream.len()); | 5245 | + eprintln!( |
| 5246 | + "inter tx_type witness: hits {hits:?}, {} bytes", | ||
| 5247 | + stream.len() | ||
| 5248 | + ); | ||
| 4972 | } | 5249 | } |
| 4973 | 5250 | ||
| 4974 | /// lane-txi's witness: a `reduced_tx_set = 0` frame codes the WIDER | 5251 | /// lane-txi's witness: a `reduced_tx_set = 0` frame codes the WIDER |
| @@ -5035,7 +5312,10 @@ mod tests { | |||
| 5035 | crate::encode::set_wide_tx_set(None); | 5312 | crate::encode::set_wide_tx_set(None); |
| 5036 | crate::encode::set_inter_tx_search(None); | 5313 | crate::encode::set_inter_tx_search(None); |
| 5037 | crate::encode::set_intra_tx_search(None); | 5314 | crate::encode::set_intra_tx_search(None); |
| 5038 | - eprintln!("wide tx_type witness: intra {intra:?} inter {inter:?}, {} bytes", stream.len()); | 5315 | + eprintln!( |
| 5316 | + "wide tx_type witness: intra {intra:?} inter {inter:?}, {} bytes", | ||
| 5317 | + stream.len() | ||
| 5318 | + ); | ||
| 5039 | // The fire count is preset 0's, for the reason the five-type witness | 5319 | // The fire count is preset 0's, for the reason the five-type witness |
| 5040 | // spells out: a faster preset prunes the modes and partitions a type | 5320 | // spells out: a faster preset prunes the modes and partitions a type |
| 5041 | // wins on before it is ever priced (class `gate-blind-to-feature`). | 5321 | // wins on before it is ever priced (class `gate-blind-to-feature`). |
| @@ -5081,6 +5361,13 @@ mod tests { | |||
| 5081 | b[at], | 5361 | b[at], |
| 5082 | ); | 5362 | ); |
| 5083 | } | 5363 | } |
| 5364 | + assert_eq!( | ||
| 5365 | + got.len(), | ||
| 5366 | + b.len(), | ||
| 5367 | + "frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 5368 | + got.len(), | ||
| 5369 | + b.len() | ||
| 5370 | + ); | ||
| 5084 | } | 5371 | } |
| 5085 | } else { | 5372 | } else { |
| 5086 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); | 5373 | eprintln!("SKIP the ffmpeg half: no ffmpeg"); |
| @@ -5167,9 +5454,11 @@ mod tests { | |||
| 5167 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | 5454 | assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); |
| 5168 | let (cw, ch) = (width / 2, height / 2); | 5455 | let (cw, ch) = (width / 2, height / 2); |
| 5169 | for (i, (a, (y, u, v))) in ours.iter().zip(&theirs).enumerate() { | 5456 | for (i, (a, (y, u, v))) in ours.iter().zip(&theirs).enumerate() { |
| 5170 | - for (name, got16, want, w) in | 5457 | + for (name, got16, want, w) in [ |
| 5171 | - [("y", &a.y, y, width), ("u", &a.u, u, cw), ("v", &a.v, v, ch)] | 5458 | + ("y", &a.y, y, width), |
| 5172 | - { | 5459 | + ("u", &a.u, u, cw), |
| 5460 | + ("v", &a.v, v, ch), | ||
| 5461 | + ] { | ||
| 5173 | let got: Vec<u8> = got16.iter().map(|&s| s as u8).collect(); | 5462 | let got: Vec<u8> = got16.iter().map(|&s| s as u8).collect(); |
| 5174 | assert_eq!(got.len(), want.len(), "frame {i} {name} plane size"); | 5463 | assert_eq!(got.len(), want.len(), "frame {i} {name} plane size"); |
| 5175 | if let Some(at) = got.iter().zip(want.iter()).position(|(x, y)| x != y) { | 5464 | if let Some(at) = got.iter().zip(want.iter()).position(|(x, y)| x != y) { |
| @@ -5223,10 +5512,18 @@ mod tests { | |||
| 5223 | stream.extend_from_slice(&packet.data); | 5512 | stream.extend_from_slice(&packet.data); |
| 5224 | } | 5513 | } |
| 5225 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | 5514 | let ours = crate::stream::decode_stream(&stream).expect("our decoder"); |
| 5226 | - assert_eq!(ours.len(), sources.len(), "speed {speed}: our decoder's frames"); | 5515 | + assert_eq!( |
| 5516 | + ours.len(), | ||
| 5517 | + sources.len(), | ||
| 5518 | + "speed {speed}: our decoder's frames" | ||
| 5519 | + ); | ||
| 5227 | if have_ffmpeg() { | 5520 | if have_ffmpeg() { |
| 5228 | let theirs = ffmpeg_decode_luma(&stream, width, height); | 5521 | let theirs = ffmpeg_decode_luma(&stream, width, height); |
| 5229 | - assert_eq!(theirs.len(), sources.len(), "speed {speed}: ffmpeg's frames"); | 5522 | + assert_eq!( |
| 5523 | + theirs.len(), | ||
| 5524 | + sources.len(), | ||
| 5525 | + "speed {speed}: ffmpeg's frames" | ||
| 5526 | + ); | ||
| 5230 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | 5527 | for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { |
| 5231 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); | 5528 | let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect(); |
| 5232 | if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) { | 5529 | if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) { |
| @@ -5239,6 +5536,13 @@ mod tests { | |||
| 5239 | b[at], | 5536 | b[at], |
| 5240 | ); | 5537 | ); |
| 5241 | } | 5538 | } |
| 5539 | + assert_eq!( | ||
| 5540 | + got.len(), | ||
| 5541 | + b.len(), | ||
| 5542 | + "speed {speed} frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 5543 | + got.len(), | ||
| 5544 | + b.len() | ||
| 5545 | + ); | ||
| 5242 | } | 5546 | } |
| 5243 | } else { | 5547 | } else { |
| 5244 | eprintln!("SKIP the ffmpeg half of speed {speed}: no ffmpeg"); | 5548 | eprintln!("SKIP the ffmpeg half of speed {speed}: no ffmpeg"); |
| @@ -5368,7 +5672,13 @@ mod tests { | |||
| 5368 | #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"] | 5672 | #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"] |
| 5369 | fn tile_search_wall_1080p() { | 5673 | fn tile_search_wall_1080p() { |
| 5370 | let _knobs = crate::speed::knob_write(); | 5674 | let _knobs = crate::speed::knob_write(); |
| 5371 | - tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]); | 5675 | + tile_search_wall( |
| 5676 | + 1920, | ||
| 5677 | + 1080, | ||
| 5678 | + 12, | ||
| 5679 | + &[(0, 0), (1, 0), (1, 1), (2, 1)], | ||
| 5680 | + &[1, 2, 4, 8], | ||
| 5681 | + ); | ||
| 5372 | } | 5682 | } |
| 5373 | 5683 | ||
| 5374 | /// The same table at the 4K frame size the editor exports (3840x1608), | 5684 | /// The same table at the 4K frame size the editor exports (3840x1608), |
| @@ -5413,7 +5723,11 @@ mod tests { | |||
| 5413 | // One tile, so only the filter stage can differ between these. | 5723 | // One tile, so only the filter stage can differ between these. |
| 5414 | let one = coded(1); | 5724 | let one = coded(1); |
| 5415 | for threads in [2usize, 4, 8] { | 5725 | for threads in [2usize, 4, 8] { |
| 5416 | - assert_eq!(one, coded(threads), "the filter stage moved at {threads} threads"); | 5726 | + assert_eq!( |
| 5727 | + one, | ||
| 5728 | + coded(threads), | ||
| 5729 | + "the filter stage moved at {threads} threads" | ||
| 5730 | + ); | ||
| 5417 | } | 5731 | } |
| 5418 | crate::par::set_tile_threads(1); | 5732 | crate::par::set_tile_threads(1); |
| 5419 | } | 5733 | } |
| @@ -5493,8 +5807,7 @@ mod tests { | |||
| 5493 | // 320x160 crops (its coding surface is one superblock row taller); | 5807 | // 320x160 crops (its coding surface is one superblock row taller); |
| 5494 | // 320x192 is a whole number of superblocks. | 5808 | // 320x192 is a whole number of superblocks. |
| 5495 | for (width, height) in [(320usize, 160usize), (320, 192)] { | 5809 | for (width, height) in [(320usize, 160usize), (320, 192)] { |
| 5496 | - let sources: Vec<Picture> = | 5810 | + let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect(); |
| 5497 | - (0..4).map(|t| test_card(width, height, t * 3)).collect(); | ||
| 5498 | run(&sources, width, height, (0, 0)); | 5811 | run(&sources, width, height, (0, 0)); |
| 5499 | } | 5812 | } |
| 5500 | // Real gate content, where the CDEF preset search actually chooses | 5813 | // Real gate content, where the CDEF preset search actually chooses |
| @@ -5649,7 +5962,12 @@ mod tests { | |||
| 5649 | for _pass in 0..2 { | 5962 | for _pass in 0..2 { |
| 5650 | for (i, &((c, r), t)) in cells.iter().enumerate() { | 5963 | for (i, &((c, r), t)) in cells.iter().enumerate() { |
| 5651 | let got = run(c, r, t); | 5964 | let got = run(c, r, t); |
| 5652 | - assert!(got.1 > 0, "{}x{} tiles at {t} threads: empty stream", 1 << c, 1 << r); | 5965 | + assert!( |
| 5966 | + got.1 > 0, | ||
| 5967 | + "{}x{} tiles at {t} threads: empty stream", | ||
| 5968 | + 1 << c, | ||
| 5969 | + 1 << r | ||
| 5970 | + ); | ||
| 5653 | if best[i].is_none_or(|(w, _)| got.0 < w) { | 5971 | if best[i].is_none_or(|(w, _)| got.0 < w) { |
| 5654 | best[i] = Some(got); | 5972 | best[i] = Some(got); |
| 5655 | } | 5973 | } |
| @@ -5681,7 +5999,10 @@ mod tests { | |||
| 5681 | .map(|i| best[i].expect("cell").0.as_secs_f64()); | 5999 | .map(|i| best[i].expect("cell").0.as_secs_f64()); |
| 5682 | let Some(one) = one else { continue }; | 6000 | let Some(one) = one else { continue }; |
| 5683 | for &t in &threads[1..] { | 6001 | for &t in &threads[1..] { |
| 5684 | - let i = cells.iter().position(|&(l, tt)| l == (c, r) && tt == t).expect("cell"); | 6002 | + let i = cells |
| 6003 | + .iter() | ||
| 6004 | + .position(|&(l, tt)| l == (c, r) && tt == t) | ||
| 6005 | + .expect("cell"); | ||
| 5685 | let secs = best[i].expect("cell").0.as_secs_f64(); | 6006 | let secs = best[i].expect("cell").0.as_secs_f64(); |
| 5686 | let workers = (t.min(1 << (c + r))) as f64 / threads[0] as f64; | 6007 | let workers = (t.min(1 << (c + r))) as f64 / threads[0] as f64; |
| 5687 | let speedup = one / secs; | 6008 | let speedup = one / secs; |
| @@ -5709,7 +6030,9 @@ mod tests { | |||
| 5709 | ) { | 6030 | ) { |
| 5710 | let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | 6031 | let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) |
| 5711 | .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4"); | 6032 | .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4"); |
| 5712 | - let listed = Command::new("ffmpeg").args(["-hide_banner", "-encoders"]).output(); | 6033 | + let listed = Command::new("ffmpeg") |
| 6034 | + .args(["-hide_banner", "-encoders"]) | ||
| 6035 | + .output(); | ||
| 5713 | let has_rav1e = listed | 6036 | let has_rav1e = listed |
| 5714 | .map(|o| String::from_utf8_lossy(&o.stdout).contains("librav1e")) | 6037 | .map(|o| String::from_utf8_lossy(&o.stdout).contains("librav1e")) |
| 5715 | .unwrap_or(false); | 6038 | .unwrap_or(false); |
| @@ -5720,7 +6043,8 @@ mod tests { | |||
| 5720 | eprintln!("| rav1e layout | threads | wall | fps | bytes |"); | 6043 | eprintln!("| rav1e layout | threads | wall | fps | bytes |"); |
| 5721 | for &(c, r) in layouts { | 6044 | for &(c, r) in layouts { |
| 5722 | for &t in threads { | 6045 | for &t in threads { |
| 5723 | - let out = std::env::temp_dir().join(format!("ec-av1-rav1e-{}.ivf", std::process::id())); | 6046 | + let out = |
| 6047 | + std::env::temp_dir().join(format!("ec-av1-rav1e-{}.ivf", std::process::id())); | ||
| 5724 | let params = format!( | 6048 | let params = format!( |
| 5725 | "speed=6:quantizer=100:tile_cols={}:tile_rows={}:threads={t}", | 6049 | "speed=6:quantizer=100:tile_cols={}:tile_rows={}:threads={t}", |
| 5726 | 1 << c, | 6050 | 1 << c, |
| @@ -5737,7 +6061,15 @@ mod tests { | |||
| 5737 | .expect("ffmpeg failed to run"); | 6061 | .expect("ffmpeg failed to run"); |
| 5738 | let secs = start.elapsed().as_secs_f64(); | 6062 | let secs = start.elapsed().as_secs_f64(); |
| 5739 | if !status.status.success() { | 6063 | if !status.status.success() { |
| 5740 | - eprintln!("| {}x{} | {t} | FAILED: {} |", 1 << c, 1 << r, String::from_utf8_lossy(&status.stderr).lines().last().unwrap_or("")); | 6064 | + eprintln!( |
| 6065 | + "| {}x{} | {t} | FAILED: {} |", | ||
| 6066 | + 1 << c, | ||
| 6067 | + 1 << r, | ||
| 6068 | + String::from_utf8_lossy(&status.stderr) | ||
| 6069 | + .lines() | ||
| 6070 | + .last() | ||
| 6071 | + .unwrap_or("") | ||
| 6072 | + ); | ||
| 5741 | continue; | 6073 | continue; |
| 5742 | } | 6074 | } |
| 5743 | let bytes = std::fs::metadata(&out).map(|m| m.len()).unwrap_or(0); | 6075 | let bytes = std::fs::metadata(&out).map(|m| m.len()).unwrap_or(0); |
| @@ -5798,6 +6130,13 @@ mod tests { | |||
| 5798 | at / width | 6130 | at / width |
| 5799 | ); | 6131 | ); |
| 5800 | } | 6132 | } |
| 6133 | + assert_eq!( | ||
| 6134 | + got.len(), | ||
| 6135 | + b.len(), | ||
| 6136 | + "1080p {layout} frame {i}: luma is {} samples, ffmpeg's is {}", | ||
| 6137 | + got.len(), | ||
| 6138 | + b.len() | ||
| 6139 | + ); | ||
| 5801 | } | 6140 | } |
| 5802 | eprintln!("1080p {layout}: {} bytes, sample-exact", stream.len()); | 6141 | eprintln!("1080p {layout}: {} bytes, sample-exact", stream.len()); |
| 5803 | } | 6142 | } |
crates/ec-av1/src/stream.rsmodified+280 -15
| @@ -3523,6 +3523,15 @@ pub(crate) mod tests { | |||
| 3523 | bad, 0, | 3523 | bad, 0, |
| 3524 | "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ" | 3524 | "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ" |
| 3525 | ); | 3525 | ); |
| 3526 | + assert_eq!( | ||
| 3527 | + g.len(), | ||
| 3528 | + r.len(), | ||
| 3529 | + "{NAME}: arm {extra:?} frame {i} plane {plane}: ours has {} samples, \ | ||
| 3530 | + ffmpeg's has {} -- a short plane would zip-truncate the compare above \ | ||
| 3531 | + and hide a chroma-span defect", | ||
| 3532 | + g.len(), | ||
| 3533 | + r.len() | ||
| 3534 | + ); | ||
| 3526 | } | 3535 | } |
| 3527 | } | 3536 | } |
| 3528 | assert!( | 3537 | assert!( |
| @@ -6043,6 +6052,14 @@ pub(crate) mod tests { | |||
| 6043 | ({int_mv_inter} force_integer_mv inter frames in this stream)", | 6052 | ({int_mv_inter} force_integer_mv inter frames in this stream)", |
| 6044 | first.unwrap() | 6053 | first.unwrap() |
| 6045 | ); | 6054 | ); |
| 6055 | + assert_eq!( | ||
| 6056 | + l.len(), | ||
| 6057 | + r.len(), | ||
| 6058 | + "frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a short \ | ||
| 6059 | + plane would zip-truncate the compare above and hide a chroma-span defect", | ||
| 6060 | + l.len(), | ||
| 6061 | + r.len() | ||
| 6062 | + ); | ||
| 6046 | } | 6063 | } |
| 6047 | } | 6064 | } |
| 6048 | } | 6065 | } |
| @@ -6147,6 +6164,14 @@ pub(crate) mod tests { | |||
| 6147 | "frame {i} plane {plane} differs from ffmpeg at sample {}", | 6164 | "frame {i} plane {plane} differs from ffmpeg at sample {}", |
| 6148 | first.unwrap() | 6165 | first.unwrap() |
| 6149 | ); | 6166 | ); |
| 6167 | + assert_eq!( | ||
| 6168 | + l.len(), | ||
| 6169 | + r.len(), | ||
| 6170 | + "frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a short \ | ||
| 6171 | + plane would zip-truncate the compare above and hide a chroma-span defect", | ||
| 6172 | + l.len(), | ||
| 6173 | + r.len() | ||
| 6174 | + ); | ||
| 6150 | } | 6175 | } |
| 6151 | } | 6176 | } |
| 6152 | } | 6177 | } |
| @@ -6251,6 +6276,15 @@ pub(crate) mod tests { | |||
| 6251 | bad, 0, | 6276 | bad, 0, |
| 6252 | "{NAME}: frame {i} plane {plane}: {bad} samples differ" | 6277 | "{NAME}: frame {i} plane {plane}: {bad} samples differ" |
| 6253 | ); | 6278 | ); |
| 6279 | + assert_eq!( | ||
| 6280 | + g.len(), | ||
| 6281 | + r.len(), | ||
| 6282 | + "{NAME}: frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a \ | ||
| 6283 | + short plane would zip-truncate the compare above and hide a chroma-span \ | ||
| 6284 | + defect", | ||
| 6285 | + g.len(), | ||
| 6286 | + r.len() | ||
| 6287 | + ); | ||
| 6254 | } | 6288 | } |
| 6255 | } | 6289 | } |
| 6256 | } | 6290 | } |
| @@ -6425,6 +6459,15 @@ pub(crate) mod tests { | |||
| 6425 | bad, 0, | 6459 | bad, 0, |
| 6426 | "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ" | 6460 | "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ" |
| 6427 | ); | 6461 | ); |
| 6462 | + assert_eq!( | ||
| 6463 | + g.len(), | ||
| 6464 | + r.len(), | ||
| 6465 | + "{NAME} [{tag}]: frame {i} plane {plane}: ours has {} samples, ffmpeg's has \ | ||
| 6466 | + {} -- a short plane would zip-truncate the compare above and hide a \ | ||
| 6467 | + chroma-span defect", | ||
| 6468 | + g.len(), | ||
| 6469 | + r.len() | ||
| 6470 | + ); | ||
| 6428 | } | 6471 | } |
| 6429 | } | 6472 | } |
| 6430 | } | 6473 | } |
| @@ -6664,6 +6707,15 @@ pub(crate) mod tests { | |||
| 6664 | bad, 0, | 6707 | bad, 0, |
| 6665 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ" | 6708 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ" |
| 6666 | ); | 6709 | ); |
| 6710 | + assert_eq!( | ||
| 6711 | + plane.len(), | ||
| 6712 | + want.len(), | ||
| 6713 | + "{NAME}: aomdec frame {i} plane {p}: ours has {} samples, the oracle's \ | ||
| 6714 | + has {} -- a short plane would zip-truncate the compare above and hide \ | ||
| 6715 | + a chroma-span defect", | ||
| 6716 | + plane.len(), | ||
| 6717 | + want.len() | ||
| 6718 | + ); | ||
| 6667 | } | 6719 | } |
| 6668 | } | 6720 | } |
| 6669 | } else { | 6721 | } else { |
| @@ -6686,6 +6738,15 @@ pub(crate) mod tests { | |||
| 6686 | bad, 0, | 6738 | bad, 0, |
| 6687 | "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" | 6739 | "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" |
| 6688 | ); | 6740 | ); |
| 6741 | + assert_eq!( | ||
| 6742 | + g.len(), | ||
| 6743 | + r.len(), | ||
| 6744 | + "{NAME}: ffmpeg frame {i} plane {p}: ours has {} samples, ffmpeg's has {} \ | ||
| 6745 | + -- a short plane would zip-truncate the compare above and hide a \ | ||
| 6746 | + chroma-span defect", | ||
| 6747 | + g.len(), | ||
| 6748 | + r.len() | ||
| 6749 | + ); | ||
| 6689 | } | 6750 | } |
| 6690 | } | 6751 | } |
| 6691 | } else { | 6752 | } else { |
| @@ -6899,6 +6960,15 @@ pub(crate) mod tests { | |||
| 6899 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ | 6960 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ |
| 6900 | (class obmc-ss-blind-chroma-above)" | 6961 | (class obmc-ss-blind-chroma-above)" |
| 6901 | ); | 6962 | ); |
| 6963 | + assert_eq!( | ||
| 6964 | + plane.len(), | ||
| 6965 | + want.len(), | ||
| 6966 | + "{NAME}: aomdec frame {i} plane {p}: ours has {} samples, the oracle's \ | ||
| 6967 | + has {} -- a short plane would zip-truncate the compare above and hide \ | ||
| 6968 | + a chroma-span defect", | ||
| 6969 | + plane.len(), | ||
| 6970 | + want.len() | ||
| 6971 | + ); | ||
| 6902 | } | 6972 | } |
| 6903 | } | 6973 | } |
| 6904 | } else { | 6974 | } else { |
| @@ -6921,6 +6991,15 @@ pub(crate) mod tests { | |||
| 6921 | bad, 0, | 6991 | bad, 0, |
| 6922 | "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" | 6992 | "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" |
| 6923 | ); | 6993 | ); |
| 6994 | + assert_eq!( | ||
| 6995 | + g.len(), | ||
| 6996 | + r.len(), | ||
| 6997 | + "{NAME}: ffmpeg frame {i} plane {p}: ours has {} samples, ffmpeg's has {} \ | ||
| 6998 | + -- a short plane would zip-truncate the compare above and hide a \ | ||
| 6999 | + chroma-span defect", | ||
| 7000 | + g.len(), | ||
| 7001 | + r.len() | ||
| 7002 | + ); | ||
| 6924 | } | 7003 | } |
| 6925 | } | 7004 | } |
| 6926 | } else { | 7005 | } else { |
| @@ -7075,6 +7154,15 @@ pub(crate) mod tests { | |||
| 7075 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ | 7154 | "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ |
| 7076 | (class 444-128rect-chroma-span)" | 7155 | (class 444-128rect-chroma-span)" |
| 7077 | ); | 7156 | ); |
| 7157 | + assert_eq!( | ||
| 7158 | + plane.len(), | ||
| 7159 | + want.len(), | ||
| 7160 | + "{NAME}: aomdec frame {i} plane {p}: ours has {} samples, the oracle's \ | ||
| 7161 | + has {} -- a short plane would zip-truncate the compare above and hide \ | ||
| 7162 | + a chroma-span defect", | ||
| 7163 | + plane.len(), | ||
| 7164 | + want.len() | ||
| 7165 | + ); | ||
| 7078 | } | 7166 | } |
| 7079 | } | 7167 | } |
| 7080 | } else { | 7168 | } else { |
| @@ -7098,6 +7186,15 @@ pub(crate) mod tests { | |||
| 7098 | bad, 0, | 7186 | bad, 0, |
| 7099 | "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" | 7187 | "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" |
| 7100 | ); | 7188 | ); |
| 7189 | + assert_eq!( | ||
| 7190 | + g.len(), | ||
| 7191 | + r.len(), | ||
| 7192 | + "{NAME}: ffmpeg frame {i} plane {p}: ours has {} samples, ffmpeg's has {} \ | ||
| 7193 | + -- a short plane would zip-truncate the compare above and hide a \ | ||
| 7194 | + chroma-span defect", | ||
| 7195 | + g.len(), | ||
| 7196 | + r.len() | ||
| 7197 | + ); | ||
| 7101 | } | 7198 | } |
| 7102 | } | 7199 | } |
| 7103 | } else { | 7200 | } else { |
| @@ -7534,6 +7631,15 @@ pub(crate) mod tests { | |||
| 7534 | "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \ | 7631 | "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \ |
| 7535 | {bad} samples differ (class lr-band-release)" | 7632 | {bad} samples differ (class lr-band-release)" |
| 7536 | ); | 7633 | ); |
| 7634 | + assert_eq!( | ||
| 7635 | + plane.len(), | ||
| 7636 | + want.len(), | ||
| 7637 | + "{NAME}: aomdec frame {i} plane {p}: ours has {} samples, the oracle's \ | ||
| 7638 | + has {} -- a short plane would zip-truncate the compare above and hide \ | ||
| 7639 | + a chroma-span defect", | ||
| 7640 | + plane.len(), | ||
| 7641 | + want.len() | ||
| 7642 | + ); | ||
| 7537 | } | 7643 | } |
| 7538 | } | 7644 | } |
| 7539 | } else { | 7645 | } else { |
| @@ -7555,6 +7661,15 @@ pub(crate) mod tests { | |||
| 7555 | "{NAME}: ffmpeg frame {i} plane {p} THROUGH THE PIPELINE: \ | 7661 | "{NAME}: ffmpeg frame {i} plane {p} THROUGH THE PIPELINE: \ |
| 7556 | {bad} samples differ" | 7662 | {bad} samples differ" |
| 7557 | ); | 7663 | ); |
| 7664 | + assert_eq!( | ||
| 7665 | + g.len(), | ||
| 7666 | + r.len(), | ||
| 7667 | + "{NAME}: ffmpeg frame {i} plane {p}: ours has {} samples, ffmpeg's has {} \ | ||
| 7668 | + -- a short plane would zip-truncate the compare above and hide a \ | ||
| 7669 | + chroma-span defect", | ||
| 7670 | + g.len(), | ||
| 7671 | + r.len() | ||
| 7672 | + ); | ||
| 7558 | } | 7673 | } |
| 7559 | } | 7674 | } |
| 7560 | } else { | 7675 | } else { |
| @@ -7881,7 +7996,7 @@ pub(crate) mod tests { | |||
| 7881 | return; | 7996 | return; |
| 7882 | } | 7997 | } |
| 7883 | let refs = ffmpeg_decode_sequence(&stream, w, h, frames); | 7998 | let refs = ffmpeg_decode_sequence(&stream, w, h, frames); |
| 7884 | - assert_eq!(ours.len(), frames, "{NAME}: decode-order frame count"); | 7999 | + assert_eq!(ours.len(), frames, "{NAME}: shown/display frame count"); |
| 7885 | for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() { | 8000 | for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() { |
| 7886 | for (plane, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | 8001 | for (plane, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] |
| 7887 | .iter() | 8002 | .iter() |
| @@ -7892,6 +8007,15 @@ pub(crate) mod tests { | |||
| 7892 | bad, 0, | 8007 | bad, 0, |
| 7893 | "{NAME}: frame {i} plane {plane}: {bad} samples differ from ffmpeg" | 8008 | "{NAME}: frame {i} plane {plane}: {bad} samples differ from ffmpeg" |
| 7894 | ); | 8009 | ); |
| 8010 | + assert_eq!( | ||
| 8011 | + g.len(), | ||
| 8012 | + r.len(), | ||
| 8013 | + "{NAME}: frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a \ | ||
| 8014 | + short plane would zip-truncate the compare above and hide a chroma-span \ | ||
| 8015 | + defect", | ||
| 8016 | + g.len(), | ||
| 8017 | + r.len() | ||
| 8018 | + ); | ||
| 7895 | } | 8019 | } |
| 7896 | } | 8020 | } |
| 7897 | eprintln!("{NAME}: {frames} frames sample-exact, intra128_lossless hits {hits}"); | 8021 | eprintln!("{NAME}: {frames} frames sample-exact, intra128_lossless hits {hits}"); |
| @@ -8025,6 +8149,15 @@ pub(crate) mod tests { | |||
| 8025 | bad, 0, | 8149 | bad, 0, |
| 8026 | "{NAME}: arm {arm} plane {plane}: {bad} samples differ from ffmpeg" | 8150 | "{NAME}: arm {arm} plane {plane}: {bad} samples differ from ffmpeg" |
| 8027 | ); | 8151 | ); |
| 8152 | + assert_eq!( | ||
| 8153 | + g.len(), | ||
| 8154 | + r.len(), | ||
| 8155 | + "{NAME}: arm {arm} plane {plane}: ours has {} samples, ffmpeg's has {} -- a \ | ||
| 8156 | + short plane would zip-truncate the compare above and hide a chroma-span \ | ||
| 8157 | + defect", | ||
| 8158 | + g.len(), | ||
| 8159 | + r.len() | ||
| 8160 | + ); | ||
| 8028 | } | 8161 | } |
| 8029 | } | 8162 | } |
| 8030 | eprintln!("{NAME}: 2 arms full-frame exact, {clips_total} chroma units clipped"); | 8163 | eprintln!("{NAME}: 2 arms full-frame exact, {clips_total} chroma units clipped"); |
| @@ -8094,6 +8227,14 @@ pub(crate) mod tests { | |||
| 8094 | bad, 0, | 8227 | bad, 0, |
| 8095 | "{NAME}: plane {plane}: {bad} samples differ from ffmpeg" | 8228 | "{NAME}: plane {plane}: {bad} samples differ from ffmpeg" |
| 8096 | ); | 8229 | ); |
| 8230 | + assert_eq!( | ||
| 8231 | + g.len(), | ||
| 8232 | + r.len(), | ||
| 8233 | + "{NAME}: plane {plane}: ours has {} samples, ffmpeg's has {} -- a short plane \ | ||
| 8234 | + would zip-truncate the compare above and hide a chroma-span defect", | ||
| 8235 | + g.len(), | ||
| 8236 | + r.len() | ||
| 8237 | + ); | ||
| 8097 | } | 8238 | } |
| 8098 | eprintln!( | 8239 | eprintln!( |
| 8099 | "{NAME}: full-frame exact, {resets} band resets, \ | 8240 | "{NAME}: full-frame exact, {resets} band resets, \ |
| @@ -8329,6 +8470,15 @@ pub(crate) mod tests { | |||
| 8329 | "{NAME}: frame {i} plane {plane} differs from ffmpeg at sample {}", | 8470 | "{NAME}: frame {i} plane {plane} differs from ffmpeg at sample {}", |
| 8330 | first.unwrap() | 8471 | first.unwrap() |
| 8331 | ); | 8472 | ); |
| 8473 | + assert_eq!( | ||
| 8474 | + l.len(), | ||
| 8475 | + r.len(), | ||
| 8476 | + "{NAME}: frame {i} plane {plane}: ours has {} samples, ffmpeg's has {} -- a \ | ||
| 8477 | + short plane would zip-truncate the compare above and hide a chroma-span \ | ||
| 8478 | + defect", | ||
| 8479 | + l.len(), | ||
| 8480 | + r.len() | ||
| 8481 | + ); | ||
| 8332 | } | 8482 | } |
| 8333 | } | 8483 | } |
| 8334 | } | 8484 | } |
| @@ -9764,11 +9914,10 @@ pub(crate) mod tests { | |||
| 9764 | assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); | 9914 | assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); |
| 9765 | let ffmpeg_frames = | 9915 | let ffmpeg_frames = |
| 9766 | ffmpeg_decode_sequence(&stream, width, height, frames.len()); | 9916 | ffmpeg_decode_sequence(&stream, width, height, frames.len()); |
| 9767 | - assert_eq!( | 9917 | + // No frame-count assert here: `ffmpeg_decode_sequence` was |
| 9768 | - frames.len(), | 9918 | + // handed `frames.len()` as its frame budget, so |
| 9769 | - ffmpeg_frames.len(), | 9919 | + // `ffmpeg_frames.len() == frames.len()` holds by |
| 9770 | - "{NAME}: {arm} frame count" | 9920 | + // construction and the assert was tautological. |
| 9771 | - ); | ||
| 9772 | // EVERY frame is compared; an arm whose decode never hit an | 9921 | // EVERY frame is compared; an arm whose decode never hit an |
| 9773 | // intrabc block proves nothing about the DV/prediction path, | 9922 | // intrabc block proves nothing about the DV/prediction path, |
| 9774 | // so it is counted OUT OF SCOPE -- but a mismatch there is | 9923 | // so it is counted OUT OF SCOPE -- but a mismatch there is |
| @@ -11346,7 +11495,29 @@ pub(crate) mod tests { | |||
| 11346 | let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); | 11495 | let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); |
| 11347 | assert_eq!(frames.len(), theirs.len(), "{NAME}: frame count"); | 11496 | assert_eq!(frames.len(), theirs.len(), "{NAME}: frame count"); |
| 11348 | let mut mismatched = 0usize; | 11497 | let mut mismatched = 0usize; |
| 11349 | - for (ours, ref_frame) in frames.iter().zip(theirs.iter()) { | 11498 | + for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { |
| 11499 | + // A size mismatch makes every number this ladder prints | ||
| 11500 | + // meaningless -- the `zip` walks below would truncate to the | ||
| 11501 | + // shorter plane and report a clean ladder over what is | ||
| 11502 | + // really a plane-shape defect -- so it is LOUD. A PIXEL | ||
| 11503 | + // mismatch stays report-only: this gate deliberately | ||
| 11504 | + // tolerates the pinned second defect (see the doc comment). | ||
| 11505 | + for (plane, a, b) in [ | ||
| 11506 | + ("Y", &ours.y, &ref_frame.y), | ||
| 11507 | + ("U", &ours.u, &ref_frame.u), | ||
| 11508 | + ("V", &ours.v, &ref_frame.v), | ||
| 11509 | + ] { | ||
| 11510 | + assert_eq!( | ||
| 11511 | + a.len(), | ||
| 11512 | + b.len(), | ||
| 11513 | + "{NAME}: frame {i} plane {plane}: ours has {} samples, ffmpeg's has \ | ||
| 11514 | + {} -- a size mismatch makes this whole diagnostic ladder \ | ||
| 11515 | + meaningless, so it is loud while a pixel mismatch stays \ | ||
| 11516 | + report-only", | ||
| 11517 | + a.len(), | ||
| 11518 | + b.len() | ||
| 11519 | + ); | ||
| 11520 | + } | ||
| 11350 | mismatched += ours | 11521 | mismatched += ours |
| 11351 | .y | 11522 | .y |
| 11352 | .iter() | 11523 | .iter() |
| @@ -11894,11 +12065,10 @@ pub(crate) mod tests { | |||
| 11894 | } else { | 12065 | } else { |
| 11895 | ffmpeg_decode_sequence(&stream, width, height, frames.len()) | 12066 | ffmpeg_decode_sequence(&stream, width, height, frames.len()) |
| 11896 | }; | 12067 | }; |
| 11897 | - assert_eq!( | 12068 | + // No frame-count assert here: `ffmpeg_decode_sequence{,_10bit}` |
| 11898 | - frames.len(), | 12069 | + // was handed `frames.len()` as its frame budget, so |
| 11899 | - ffmpeg_frames.len(), | 12070 | + // `ffmpeg_frames.len() == frames.len()` holds by construction |
| 11900 | - "{NAME}: {arm} at {depth}-bit -- frame count" | 12071 | + // and the assert was tautological. |
| 11901 | - ); | ||
| 11902 | assert!( | 12072 | assert!( |
| 11903 | !frames.is_empty(), | 12073 | !frames.is_empty(), |
| 11904 | "{NAME}: {arm} at {depth}-bit decoded no frame" | 12074 | "{NAME}: {arm} at {depth}-bit decoded no frame" |
| @@ -13636,6 +13806,15 @@ pub(crate) mod tests { | |||
| 13636 | if let Some(d) = first_diff(a, b, w) { | 13806 | if let Some(d) = first_diff(a, b, w) { |
| 13637 | panic!("{name}: seed {seed} frame {i} plane {plane}: {d} [{fired}]"); | 13807 | panic!("{name}: seed {seed} frame {i} plane {plane}: {d} [{fired}]"); |
| 13638 | } | 13808 | } |
| 13809 | + assert_eq!( | ||
| 13810 | + a.len(), | ||
| 13811 | + b.len(), | ||
| 13812 | + "{name}: seed {seed} frame {i} plane {plane}: ours has {} samples, \ | ||
| 13813 | + ffmpeg's has {} -- a short plane would zip-truncate the walk above \ | ||
| 13814 | + and hide a chroma-span defect", | ||
| 13815 | + a.len(), | ||
| 13816 | + b.len() | ||
| 13817 | + ); | ||
| 13639 | } | 13818 | } |
| 13640 | } | 13819 | } |
| 13641 | compared += 1; | 13820 | compared += 1; |
| @@ -28889,6 +29068,22 @@ pub(crate) mod tests { | |||
| 28889 | "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} frame \ | 29068 | "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} frame \ |
| 28890 | {i} differs from ffmpeg" | 29069 | {i} differs from ffmpeg" |
| 28891 | ); | 29070 | ); |
| 29071 | + for (plane, a, b) in [ | ||
| 29072 | + ("Y", &ours.y, &theirs.y), | ||
| 29073 | + ("U", &ours.u, &theirs.u), | ||
| 29074 | + ("V", &ours.v, &theirs.v), | ||
| 29075 | + ] { | ||
| 29076 | + assert_eq!( | ||
| 29077 | + a.len(), | ||
| 29078 | + b.len(), | ||
| 29079 | + "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ | ||
| 29080 | + frame {i} plane {plane}: ours has {} samples, ffmpeg's has \ | ||
| 29081 | + {} -- a short plane would zip-truncate the diff count \ | ||
| 29082 | + above and hide a chroma-span defect", | ||
| 29083 | + a.len(), | ||
| 29084 | + b.len() | ||
| 29085 | + ); | ||
| 29086 | + } | ||
| 28892 | } | 29087 | } |
| 28893 | // Every compared attempt must carry the case, so no | 29088 | // Every compared attempt must carry the case, so no |
| 28894 | // compared attempt is out of scope and | 29089 | // compared attempt is out of scope and |
| @@ -29754,8 +29949,11 @@ pub(crate) mod tests { | |||
| 29754 | ffmpeg_decode_sequence(&stream, width, height, frame_count) | 29949 | ffmpeg_decode_sequence(&stream, width, height, frame_count) |
| 29755 | }; | 29950 | }; |
| 29756 | assert_eq!(frames.len(), frame_count); | 29951 | assert_eq!(frames.len(), frame_count); |
| 29757 | - // EVERY decode-order frame compared, never just the shown ones | 29952 | + // Every SHOWN/display frame `decode_stream` returned is compared -- |
| 29758 | - // (class [[gate-blind-to-hidden-frames]]). | 29953 | + // that is decode_stream's whole output, and nothing else is. |
| 29954 | + // HIDDEN frames are NOT covered here: they are never emitted as | ||
| 29955 | + // pictures, so no ffmpeg picture corresponds to them (class | ||
| 29956 | + // [[gate-blind-to-hidden-frames]]). | ||
| 29759 | for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | 29957 | for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { |
| 29760 | assert_eq!( | 29958 | assert_eq!( |
| 29761 | got.y, want.y, | 29959 | got.y, want.y, |
| @@ -29919,7 +30117,20 @@ pub(crate) mod tests { | |||
| 29919 | .unwrap_or(4); | 30117 | .unwrap_or(4); |
| 29920 | let frames = decode_stream(&stream).expect("our decode"); | 30118 | let frames = decode_stream(&stream).expect("our decode"); |
| 29921 | let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | 30119 | let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); |
| 29922 | - for f in 0..frame_count.min(frames.len()).min(ffmpeg_frames.len()) { | 30120 | + // The `.min()` chain below is a scratch diagnostic that tolerates a |
| 30121 | + // pinned stream whose counts disagree, but a SILENT shortfall reads as | ||
| 30122 | + // "these frames matched" for frames nobody compared. Say how many are | ||
| 30123 | + // actually walked. | ||
| 30124 | + let walked = frame_count.min(frames.len()).min(ffmpeg_frames.len()); | ||
| 30125 | + if walked < frame_count { | ||
| 30126 | + eprintln!( | ||
| 30127 | + "pinned stream: asked for {frame_count} frames (EC_AV1_PIN_N), we show {}, ffmpeg \ | ||
| 30128 | + shows {} -- comparing the first {walked} only", | ||
| 30129 | + frames.len(), | ||
| 30130 | + ffmpeg_frames.len() | ||
| 30131 | + ); | ||
| 30132 | + } | ||
| 30133 | + for f in 0..walked { | ||
| 29923 | let ours = &frames[f]; | 30134 | let ours = &frames[f]; |
| 29924 | let theirs = &ffmpeg_frames[f]; | 30135 | let theirs = &ffmpeg_frames[f]; |
| 29925 | for (plane_name, a, b, w) in [ | 30136 | for (plane_name, a, b, w) in [ |
| @@ -29927,6 +30138,15 @@ pub(crate) mod tests { | |||
| 29927 | ("u", &ours.u, &theirs.u, width / 2), | 30138 | ("u", &ours.u, &theirs.u, width / 2), |
| 29928 | ("v", &ours.v, &theirs.v, width / 2), | 30139 | ("v", &ours.v, &theirs.v, width / 2), |
| 29929 | ] { | 30140 | ] { |
| 30141 | + // A short plane would zip-truncate the walk below and report | ||
| 30142 | + // MATCH over the prefix the two share. | ||
| 30143 | + assert_eq!( | ||
| 30144 | + a.len(), | ||
| 30145 | + b.len(), | ||
| 30146 | + "frame {f} plane {plane_name}: ours has {} samples, ffmpeg's has {}", | ||
| 30147 | + a.len(), | ||
| 30148 | + b.len() | ||
| 30149 | + ); | ||
| 29930 | let mut first = None; | 30150 | let mut first = None; |
| 29931 | let mut count = 0; | 30151 | let mut count = 0; |
| 29932 | let mut worst = 0i32; | 30152 | let mut worst = 0i32; |
| @@ -33995,6 +34215,15 @@ pub(crate) mod tests { | |||
| 33995 | first.map(|k| a[k]), | 34215 | first.map(|k| a[k]), |
| 33996 | first.map(|k| b[k]), | 34216 | first.map(|k| b[k]), |
| 33997 | ); | 34217 | ); |
| 34218 | + assert_eq!( | ||
| 34219 | + a.len(), | ||
| 34220 | + b.len(), | ||
| 34221 | + "{NAME} frame {i} {name} vs ffmpeg (seed {seed}): ours has {} samples, \ | ||
| 34222 | + ffmpeg's has {} -- a short plane would zip-truncate the walk above \ | ||
| 34223 | + and hide a chroma-span defect", | ||
| 34224 | + a.len(), | ||
| 34225 | + b.len() | ||
| 34226 | + ); | ||
| 33998 | } | 34227 | } |
| 33999 | } | 34228 | } |
| 34000 | let hits = crate::decode::part128_none_hits() - before; | 34229 | let hits = crate::decode::part128_none_hits() - before; |
| @@ -35589,6 +35818,15 @@ pub(crate) mod tests { | |||
| 35589 | b[d] | 35818 | b[d] |
| 35590 | ); | 35819 | ); |
| 35591 | } | 35820 | } |
| 35821 | + assert_eq!( | ||
| 35822 | + a.len(), | ||
| 35823 | + b.len(), | ||
| 35824 | + "{name}: {tag} frame {i} plane {plane}: ours has {} samples, \ | ||
| 35825 | + ffmpeg's has {} -- a short plane would zip-truncate the walk above \ | ||
| 35826 | + and hide a chroma-span defect", | ||
| 35827 | + a.len(), | ||
| 35828 | + b.len() | ||
| 35829 | + ); | ||
| 35592 | } | 35830 | } |
| 35593 | } | 35831 | } |
| 35594 | compared += 1; | 35832 | compared += 1; |
| @@ -42549,6 +42787,15 @@ pub(crate) mod tests { | |||
| 42549 | b[i], | 42787 | b[i], |
| 42550 | ); | 42788 | ); |
| 42551 | } | 42789 | } |
| 42790 | + assert_eq!( | ||
| 42791 | + a.len(), | ||
| 42792 | + b.len(), | ||
| 42793 | + "{NAME}: segmented {w}x{h} crf {crf}, frame {f} plane {plane}: ours \ | ||
| 42794 | + has {} samples, ffmpeg's has {} -- a short plane would \ | ||
| 42795 | + zip-truncate the walk above and hide a chroma-span defect", | ||
| 42796 | + a.len(), | ||
| 42797 | + b.len() | ||
| 42798 | + ); | ||
| 42552 | } | 42799 | } |
| 42553 | } | 42800 | } |
| 42554 | eprintln!("{NAME}: segmented {w}x{h} crf {crf} exact, block q span {lo}..{hi}"); | 42801 | eprintln!("{NAME}: segmented {w}x{h} crf {crf} exact, block q span {lo}..{hi}"); |
| @@ -42662,6 +42909,15 @@ pub(crate) mod tests { | |||
| 42662 | b[i], | 42909 | b[i], |
| 42663 | ); | 42910 | ); |
| 42664 | } | 42911 | } |
| 42912 | + assert_eq!( | ||
| 42913 | + a.len(), | ||
| 42914 | + b.len(), | ||
| 42915 | + "{NAME}: {encoder} {point} at {w}x{h}, frame {f} plane {plane}: \ | ||
| 42916 | + ours has {} samples, ffmpeg's has {} -- a short plane would \ | ||
| 42917 | + zip-truncate the walk above and hide a chroma-span defect", | ||
| 42918 | + a.len(), | ||
| 42919 | + b.len() | ||
| 42920 | + ); | ||
| 42665 | } | 42921 | } |
| 42666 | } | 42922 | } |
| 42667 | checked += 1; | 42923 | checked += 1; |
| @@ -42772,6 +43028,15 @@ pub(crate) mod tests { | |||
| 42772 | b[i], | 43028 | b[i], |
| 42773 | ); | 43029 | ); |
| 42774 | } | 43030 | } |
| 43031 | + assert_eq!( | ||
| 43032 | + a.len(), | ||
| 43033 | + b.len(), | ||
| 43034 | + "{NAME}: frame {f} plane {plane}: ours has {} samples, ffmpeg's has {} -- a \ | ||
| 43035 | + short plane would zip-truncate the walk above and hide a chroma-span \ | ||
| 43036 | + defect", | ||
| 43037 | + a.len(), | ||
| 43038 | + b.len() | ||
| 43039 | + ); | ||
| 42775 | } | 43040 | } |
| 42776 | } | 43041 | } |
| 42777 | // The property is asserted, not hoped for: without more than one | 43042 | // The property is asserted, not hoped for: without more than one |
crates/ec-h264/tests/conformance.rsmodified+53 -0
| @@ -275,6 +275,13 @@ fn compare_sequence(stream: &Path) -> Result<usize, String> { | |||
| 275 | a[pos], b[pos] | 275 | a[pos], b[pos] |
| 276 | )); | 276 | )); |
| 277 | } | 277 | } |
| 278 | + assert_eq!( | ||
| 279 | + a.len(), | ||
| 280 | + b.len(), | ||
| 281 | + "frame {i} is {} samples, ffmpeg gave {}", | ||
| 282 | + a.len(), | ||
| 283 | + b.len() | ||
| 284 | + ); | ||
| 278 | } | 285 | } |
| 279 | Ok(ours.len()) | 286 | Ok(ours.len()) |
| 280 | } | 287 | } |
| @@ -319,6 +326,12 @@ fn jvt_cavlc_first_idr_bit_exact() { | |||
| 319 | ); | 326 | ); |
| 320 | ok = false; | 327 | ok = false; |
| 321 | } | 328 | } |
| 329 | + assert_eq!( | ||
| 330 | + ours.len(), | ||
| 331 | + frame_len, | ||
| 332 | + "{name}: frame is {} samples ({w}x{h}), the reference frame is {frame_len}", | ||
| 333 | + ours.len() | ||
| 334 | + ); | ||
| 322 | } else { | 335 | } else { |
| 323 | eprintln!("WARN {name}: no reference YUV, ffmpeg only"); | 336 | eprintln!("WARN {name}: no reference YUV, ffmpeg only"); |
| 324 | } | 337 | } |
| @@ -332,6 +345,12 @@ fn jvt_cavlc_first_idr_bit_exact() { | |||
| 332 | ); | 345 | ); |
| 333 | ok = false; | 346 | ok = false; |
| 334 | } | 347 | } |
| 348 | + assert_eq!( | ||
| 349 | + ours.len(), | ||
| 350 | + frame_len, | ||
| 351 | + "{name}: frame is {} samples ({w}x{h}), the ffmpeg frame is {frame_len}", | ||
| 352 | + ours.len() | ||
| 353 | + ); | ||
| 335 | } | 354 | } |
| 336 | if ok { | 355 | if ok { |
| 337 | passed.push(name.to_string()); | 356 | passed.push(name.to_string()); |
| @@ -692,6 +711,13 @@ fn round_trip(dir: &Path, tag: &str, size: &str, extra: &[&str]) -> Result<usize | |||
| 692 | expected.len() | 711 | expected.len() |
| 693 | )); | 712 | )); |
| 694 | } | 713 | } |
| 714 | + if ours.len() < expected.len() { | ||
| 715 | + return Err(format!( | ||
| 716 | + "{tag}: {w}x{h} decoded to {} bytes, ffmpeg gave {}", | ||
| 717 | + ours.len(), | ||
| 718 | + expected.len() | ||
| 719 | + )); | ||
| 720 | + } | ||
| 695 | Ok(ours | 721 | Ok(ours |
| 696 | .iter() | 722 | .iter() |
| 697 | .zip(&expected[..ours.len()]) | 723 | .zip(&expected[..ours.len()]) |
| @@ -1082,6 +1108,12 @@ fn jvt_full_sequence_bit_exact() { | |||
| 1082 | bad = Some((i, pos)); | 1108 | bad = Some((i, pos)); |
| 1083 | break; | 1109 | break; |
| 1084 | } | 1110 | } |
| 1111 | + assert_eq!( | ||
| 1112 | + f.len(), | ||
| 1113 | + len, | ||
| 1114 | + "{name}: frame {i} is {} samples, {len} expected", | ||
| 1115 | + f.len() | ||
| 1116 | + ); | ||
| 1085 | } | 1117 | } |
| 1086 | match bad { | 1118 | match bad { |
| 1087 | None if frames.len() == want => { | 1119 | None if frames.len() == want => { |
| @@ -1301,6 +1333,13 @@ fn output_is_display_order_and_the_reorder_is_real() { | |||
| 1301 | first_diff(a, b).is_none(), | 1333 | first_diff(a, b).is_none(), |
| 1302 | "display-order frame {i} differs from ffmpeg" | 1334 | "display-order frame {i} differs from ffmpeg" |
| 1303 | ); | 1335 | ); |
| 1336 | + assert_eq!( | ||
| 1337 | + a.len(), | ||
| 1338 | + b.len(), | ||
| 1339 | + "display-order frame {i} is {} samples, ffmpeg gave {}", | ||
| 1340 | + a.len(), | ||
| 1341 | + b.len() | ||
| 1342 | + ); | ||
| 1304 | } | 1343 | } |
| 1305 | // Every decode-order frame is somewhere in the display-order set: the two | 1344 | // Every decode-order frame is somewhere in the display-order set: the two |
| 1306 | // are permutations of one another, not different pictures. | 1345 | // are permutations of one another, not different pictures. |
| @@ -2011,6 +2050,13 @@ fn packet_entry_surface_reorders_and_carries_timestamps() { | |||
| 2011 | first_diff(ours, theirs).is_none(), | 2050 | first_diff(ours, theirs).is_none(), |
| 2012 | "packet-path frame {i} differs from ffmpeg" | 2051 | "packet-path frame {i} differs from ffmpeg" |
| 2013 | ); | 2052 | ); |
| 2053 | + assert_eq!( | ||
| 2054 | + ours.len(), | ||
| 2055 | + theirs.len(), | ||
| 2056 | + "packet-path frame {i} is {} samples, ffmpeg gave {}", | ||
| 2057 | + ours.len(), | ||
| 2058 | + theirs.len() | ||
| 2059 | + ); | ||
| 2014 | } | 2060 | } |
| 2015 | // Each packet was tagged with its own index in *decode* order, so the tag | 2061 | // Each packet was tagged with its own index in *decode* order, so the tag |
| 2016 | // that comes back on a picture says which packet produced it. Decoding the | 2062 | // that comes back on a picture says which packet produced it. Decoding the |
| @@ -2026,6 +2072,13 @@ fn packet_entry_surface_reorders_and_carries_timestamps() { | |||
| 2026 | "output position {position} carries the timestamp of packet {tag}, \ | 2072 | "output position {position} carries the timestamp of packet {tag}, \ |
| 2027 | but its pixels are a different picture" | 2073 | but its pixels are a different picture" |
| 2028 | ); | 2074 | ); |
| 2075 | + assert_eq!( | ||
| 2076 | + pixels.len(), | ||
| 2077 | + by_decode_order[tag].len(), | ||
| 2078 | + "output position {position} is {} samples, decode-order frame {tag} is {}", | ||
| 2079 | + pixels.len(), | ||
| 2080 | + by_decode_order[tag].len() | ||
| 2081 | + ); | ||
| 2029 | } | 2082 | } |
| 2030 | let order: Vec<i64> = out.iter().map(|(pts, _)| *pts).collect(); | 2083 | let order: Vec<i64> = out.iter().map(|(pts, _)| *pts).collect(); |
| 2031 | assert_ne!( | 2084 | assert_ne!( |
crates/ec-vp9/tests/intraonly_exact.rsmodified+5 -0
| @@ -80,6 +80,11 @@ fn intra_only_frame_and_its_successors_match_ffmpeg() { | |||
| 80 | got.extend(pic.y.iter().map(|&v| v as u8)); | 80 | got.extend(pic.y.iter().map(|&v| v as u8)); |
| 81 | got.extend(pic.u.iter().map(|&v| v as u8)); | 81 | got.extend(pic.u.iter().map(|&v| v as u8)); |
| 82 | got.extend(pic.v.iter().map(|&v| v as u8)); | 82 | got.extend(pic.v.iter().map(|&v| v as u8)); |
| 83 | + assert_eq!( | ||
| 84 | + got.len(), | ||
| 85 | + frame_bytes, | ||
| 86 | + "frame {i}: our planes are {w}x{h} I420" | ||
| 87 | + ); | ||
| 83 | let diff = got.iter().zip(want).position(|(a, b)| a != b); | 88 | let diff = got.iter().zip(want).position(|(a, b)| a != b); |
| 84 | assert!( | 89 | assert!( |
| 85 | diff.is_none(), | 90 | diff.is_none(), |
lanes/av1cmpaudit.report.mdadded+240 -0
| @@ -0,0 +1,240 @@ | |||
| 1 | +# lane-av1cmpaudit — ours-vs-oracle compare honesty sweep | ||
| 2 | + | ||
| 3 | +## The class | ||
| 4 | + | ||
| 5 | +An ours-vs-oracle compare that walks `got.iter().zip(want)` **without first asserting | ||
| 6 | +equal lengths** reports EXACT for any defect outside the compared prefix: `zip` stops at | ||
| 7 | +the shorter operand, so the walk is silently truncated and the `filter(|(a, b)| a != b) | ||
| 8 | +.count() == 0` form returns a PASS. Measured in this repo before the sweep: a comparator | ||
| 9 | +hardcoded to a 128x96 geometry zipped 36864 samples against a 98304-byte oracle dump and | ||
| 10 | +declared a 256x128 witness byte-exact while the divergence sat at x>=108. | ||
| 11 | + | ||
| 12 | +A frame-count assert (`ours.len() == sources.len()`) does **not** protect a plane compare. | ||
| 13 | +The canonical SAFE shape already in the tree is `crates/ec-av1/src/stream.rs`'s | ||
| 14 | +`decode_all_frames_vs_oracle` (~8129-8145): assert the frame counts, assert the byte | ||
| 15 | +lengths, then walk. | ||
| 16 | + | ||
| 17 | +Second class, same inventory: **decode-order vs display-order indexing.** The instrumented | ||
| 18 | +aomdec's `EC_AV1_FINAL_DUMP` writes one file per DECODED frame in DECODE order (7 files | ||
| 19 | +for a 6-picture encode); `ffmpeg -f rawvideo` emits DISPLAY order (6). Indexing one | ||
| 20 | +against the other fakes a divergence on a byte-exact stream. | ||
| 21 | + | ||
| 22 | +## Fix rule used everywhere | ||
| 23 | + | ||
| 24 | +A length assert is inserted **after** the existing diff/panic assert, on the same buffers. | ||
| 25 | +That keeps every change behaviour-preserving: a real sample divergence still fails for the | ||
| 26 | +same reason with the same message, and only the previously-silent "our side is short and | ||
| 27 | +the compared prefix matches" case becomes a new loud failure. Frame-count asserts that | ||
| 28 | +guard a loop over frames go **before** the loop, because with unequal counts the loop body | ||
| 29 | +compares a mis-paired set and there is no "same reason" failure to preserve. | ||
| 30 | + | ||
| 31 | +## Inventory | ||
| 32 | + | ||
| 33 | +106 ours-vs-oracle compare sites. SAFE = a length assert (or a whole-slice `==`/`!=` | ||
| 34 | +compare, which is length-aware) on the SAME buffers in the same block. UNSAFE = the walk | ||
| 35 | +with no such assert. N/A = a zip that is not an ours-vs-oracle compare (production DSP, | ||
| 36 | +iterator plumbing, ours-vs-ours). No site is SKIPPED-by-env: every gate is fixture | ||
| 37 | +presence or an ffmpeg/aomdec binary check, and every one is exercisable in a normal run. | ||
| 38 | + | ||
| 39 | +| crate / file | sites | SAFE | UNSAFE | N/A | | ||
| 40 | +|---|---|---|---|---| | ||
| 41 | +| `crates/ec-av1/src/stream.rs` | 44 | 13 | 26 | 5 | | ||
| 42 | +| `crates/ec-av1/src/encoder.rs` | 17 | 4 | 13 | 0 | | ||
| 43 | +| `crates/ec-av1/src/encode.rs` | 22 | 2 | 20 | 0 | | ||
| 44 | +| `crates/ec-h264/tests/conformance.rs` | 11 | 2 | 8 | 1 | | ||
| 45 | +| `crates/ec-vp9/tests/*.rs` | 4 | 3 | 1 | 0 | | ||
| 46 | +| `crates/ec-h265/tests/conformance.rs` | 8 | 8 | 0 | 0 | | ||
| 47 | +| `crates/ec-alac/tests/*.rs` | 2 | 2 | 0 | 0 | | ||
| 48 | +| `crates/ec-flac/tests/*.rs` | 2 | 2 | 0 | 0 | | ||
| 49 | +| `tools/oracle/src/main.rs` | 1 | 1 | 0 | 0 | | ||
| 50 | +| `crates/ec-aac/tests/*.rs`, `crates/ec-ac3/tests/*.rs` | 13 | 1 | 0 | 12 | | ||
| 51 | +| **total** | **124** | **38** | **68** | **18** | | ||
| 52 | + | ||
| 53 | +`scripts/**` holds no ours-vs-oracle byte compare: `lr-sgr-pin-harness.c` and | ||
| 54 | +`superres-pin-harness.c` are oracle-side instrumentation the instrumented aomdec calls, | ||
| 55 | +`instrument-aom-oracle.sh` only patches oracle sources, and the `aac-tables/*.py` scripts | ||
| 56 | +probe the reference decoder with an error-string oracle, not a sample compare. | ||
| 57 | + | ||
| 58 | +### The UNSAFE sites, by shape | ||
| 59 | + | ||
| 60 | +**`filter(|(a, b)| a != b).count() == 0` is the ONLY pixel check** — a short plane gives | ||
| 61 | +0 and the gate passes. `stream.rs` 3522, 6181, 6355, 6616, 6742, 6919, 7083, 7421, 7554, | ||
| 62 | +7623, 6590, 6715, 6891, 7058; `encode.rs` 17386, 17471, 17560, 17630, 17702, 17781, 17848, | ||
| 63 | +17938, 18029, 18090. | ||
| 64 | + | ||
| 65 | +**`position(|(x, y)| x != y)` diff reporter with only a frame-count assert** — | ||
| 66 | +`stream.rs` 5971, 6076, 7857, 12932, 33237, 34820, 41790, 41903, 42014, 28107; | ||
| 67 | +`encoder.rs` 3545, 4280, 4350, 4405, 4455, 4521, 4586, 4761, 4873, 4958, 5075, 5232, 5794; | ||
| 68 | +`ec-h264/tests/conformance.rs` 272, 314, 328, 1081, 1301, 2011, 2025; | ||
| 69 | +`ec-vp9/tests/intraonly_exact.rs` 83. | ||
| 70 | + | ||
| 71 | +**A helper that returns `None` for "exact" with no length guard** — | ||
| 72 | +`encode.rs::first_difference` (16565). Contrast `first_plane_mismatch` (19161), which | ||
| 73 | +checks length after the zip and so cannot yield a false `None`; that is the model. | ||
| 74 | + | ||
| 75 | +**A one-sided length check** — `ec-h264/tests/conformance.rs::round_trip` (688): only | ||
| 76 | +`if ours.len() > expected.len()` was rejected, so a SHORT frame zipped over | ||
| 77 | +`&expected[..ours.len()]` and returned 0. Four call sites print "bit-exact" on `Ok(0)`. | ||
| 78 | + | ||
| 79 | +**A three-way `.min()` that truncates silently** — `stream.rs:29369` | ||
| 80 | +(`frame_count.min(frames.len()).min(ffmpeg_frames.len())`), the only | ||
| 81 | +decode-order/display-order-shaped site in the crate. | ||
| 82 | + | ||
| 83 | +**Frame pairing with no count assert on either side** — `encode.rs` 15617, 15622 (and the | ||
| 84 | +nine `encoded.frames` vs `ffmpeg_decode_sequence` loops at 17396/17481/17565/17640/17712/ | ||
| 85 | +17786/17853/17943/18034 plus 17282). | ||
| 86 | + | ||
| 87 | +### Deliberately left alone | ||
| 88 | + | ||
| 89 | +- `ec-h264/tests/conformance.rs:157` `fn first_diff` — the primitive itself. Its two | ||
| 90 | + streamed call sites (1646, 1769) are already SAFE via `reference.resize(frame.len(), 0)` | ||
| 91 | + + `read_exact`; the seven loose call sites are fixed instead. | ||
| 92 | +- `ec-h264/tests/conformance.rs:1313` — ours-vs-ours (decode order vs display order), an | ||
| 93 | + anti-vacuity claim (`moved > 0`), not an oracle compare. | ||
| 94 | +- `stream.rs:10704-10718` `mismatched` — a PIXEL mismatch here stays report-only by design | ||
| 95 | + (the gate deliberately tolerates a pinned second defect). The PLANE SIZE now asserts | ||
| 96 | + loudly: with a size mismatch every number the ladder prints is meaningless, and that is | ||
| 97 | + not the defect the gate tolerates. | ||
| 98 | +- `stream.rs:9298, 11248` — `assert_eq!(frames.len(), ffmpeg_frames.len(), ...)` was | ||
| 99 | + tautological (`ffmpeg_decode_sequence` was handed `frames.len()` as its budget). Deleted | ||
| 100 | + and replaced by a comment naming the tautology; the helper's own byte-length assert is | ||
| 101 | + the real guard. | ||
| 102 | +- `ec-aac`, `ec-ac3` — Pearson/lag-correlation and RMS thresholds. A correlation claim is | ||
| 103 | + not an exactness claim, and shortening an operand changes a threshold result, it does | ||
| 104 | + not fake a PASS. Their one genuine exactness claim | ||
| 105 | + (`ec-aac/tests/oracle.rs:617`) is a full `assert_eq!(ours, theirs, ...)`. | ||
| 106 | +- The ~250 remaining ffmpeg pairings in `stream.rs` — SAFE-DISP: `decode_stream` returns | ||
| 107 | + shown frames in display order and ffmpeg rawvideo is display order, and | ||
| 108 | + `ffmpeg_decode_sequence` hard-asserts `stdout.len() == frame_bytes * frames`, so passing | ||
| 109 | + our own `frames.len()` is still a real count assertion against ffmpeg's measured output. | ||
| 110 | + | ||
| 111 | +### Truthfulness fixes (no logic change) | ||
| 112 | + | ||
| 113 | +- `stream.rs:29006` claimed `// EVERY decode-order frame compared, never just the shown | ||
| 114 | + ones (class [[gate-blind-to-hidden-frames]])` directly above a loop over | ||
| 115 | + `decode_stream`'s output, which is the shown/display frames. The gate is exactly the | ||
| 116 | + class it claimed to cover. Rewritten to say what it covers and that hidden frames are | ||
| 117 | + NOT covered. | ||
| 118 | +- `stream.rs:7415` — `"{NAME}: decode-order frame count"` on a shown-frame count. Message | ||
| 119 | + corrected; the assert itself is unchanged. | ||
| 120 | +- `crates/ec-av1/examples/dump_yuv.rs:39` — writes `<out>.f{i}.yuv` where `i` is a DISPLAY | ||
| 121 | + index, wearing the `.f{N}` name that means DECODE index everywhere else in the crate. | ||
| 122 | + A comment now says so and points at `decode_all_frames_vs_oracle`. | ||
| 123 | + | ||
| 124 | +### Stale-dump hazard | ||
| 125 | + | ||
| 126 | +Already handled at the one in-tree site that reads dump files: | ||
| 127 | +`decode_all_frames_vs_oracle` `remove_dir_all`s its scratch dir (~8087) before writing | ||
| 128 | +both sides' `aom.f{i}` and `ours.f{i}`, so no `ours.f*` can survive from a previous run | ||
| 129 | +next to a fresh `aom.f*`. The three other decode-order dump rungs | ||
| 130 | +(`EC_AV1_DECODE_ORDER_DUMP`, `EC_AV1_PREFILT_DUMP`) have no in-repo consumer — the whole | ||
| 131 | +hazard there lives in the manual procedure, not in a gate. Nothing to fix. | ||
| 132 | + | ||
| 133 | +## Proofs | ||
| 134 | + | ||
| 135 | +Every fix is a pure insertion, so the red proof is a counterfactual on the SAME code: drop | ||
| 136 | +our side's last sample, run the gate. Red = the new length assert fires. Then revert only | ||
| 137 | +the fix (scoped `git checkout -- <file>`) and re-run the identical mutated code: the gate | ||
| 138 | +PASSES. That pass is the false PASS the fix kills. | ||
| 139 | + | ||
| 140 | +**`crates/ec-av1/src/stream.rs`** — `stream::tests::a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands` | ||
| 141 | +(0.64s, not `#[ignore]`d). Mutation in `decode.rs:34785`: `probe_plane.pop()` on the | ||
| 142 | +key-frame luma. | ||
| 143 | +- red: `panicked at crates/ec-av1/src/stream.rs:7768: assertion 'left == right' failed: | ||
| 144 | + a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands: plane 0: ours has 77439 | ||
| 145 | + samples, ffmpeg's has 77440 -- a short plane would zip-truncate the compare above and | ||
| 146 | + hide a chroma-span defect` / `left: 77439 right: 77440` / `FAILED. 0 passed; 1 failed`. | ||
| 147 | + The pre-existing `bad == 0` assert did NOT fire — that is the hole. | ||
| 148 | +- false pass: same mutation, `stream.rs` reverted → `a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands: | ||
| 149 | + full-frame exact, 1 band resets, 3 skipped intrabc chroma predictions` / `ok`. | ||
| 150 | + | ||
| 151 | +**`crates/ec-av1/src/encoder.rs`** — `encoder::tests::a_static_clip_codes_64x64_roots_and_decodes_sample_exact` | ||
| 152 | +(site 4280). Mutation: `g.pop()` on the luma collect. | ||
| 153 | +- red: `panicked at crates/ec-av1/src/encoder.rs:4296: assertion 'left == right' failed: | ||
| 154 | + frame 0: luma is 32767 samples, ffmpeg's is 32768` / `FAILED. 0 passed; 1 failed; 702 | ||
| 155 | + filtered out`. | ||
| 156 | +- restored: `ok`. | ||
| 157 | + | ||
| 158 | +**`crates/ec-av1/src/encode.rs`** — `encode::tests::every_mode_decodes_to_what_the_encoder_predicted` | ||
| 159 | +(the `first_difference` helper fix). Mutation: `let ours = &ours[..ours.len() - 1];`. | ||
| 160 | +- red: `panicked at crates/ec-av1/src/encode.rs:16620: 128x96 mode 0, luma: no sample in the | ||
| 161 | + shared prefix differs, but ours is 12287 samples and theirs is 12288` / `FAILED`. | ||
| 162 | +- restored: `ok`. | ||
| 163 | + | ||
| 164 | +**`crates/ec-vp9/tests/intraonly_exact.rs`** — `intra_only_frame_and_its_successors_match_ffmpeg`. | ||
| 165 | +Mutation: `got.pop()`. | ||
| 166 | +- red: `panicked at crates/ec-vp9/tests/intraonly_exact.rs:84: frame 0: our planes are | ||
| 167 | + 320x240 I420 / left: 115199 / right: 115200` / `FAILED. 0 passed; 1 failed`. | ||
| 168 | +- false pass: same mutation, fix reverted → `ok ... 1 passed` — a 115199-vs-115200 | ||
| 169 | + truncation reported EXACT for all 10 shown frames. | ||
| 170 | +- restored: `ok`. | ||
| 171 | + | ||
| 172 | +**`crates/ec-h264/tests/conformance.rs`** — all seven sites proven red and all seven | ||
| 173 | +proven to pass without the fix (each mutation truncated our frame or the oracle's by one | ||
| 174 | +sample; the reverted runs printed `bit-exact` / `12 frames bit-exact` / `ok`). | ||
| 175 | +- `jvt_scaling_matrices_decode_bit_exact` / `round_trip`: red `conformance.rs:865: cqm-jvt: | ||
| 176 | + 176x144 decoded to 38015 bytes, ffmpeg gave 38016`; false pass `cqm=jvt scaling matrices | ||
| 177 | + bit-exact`. | ||
| 178 | +- `jvt_cavlc_first_idr_bit_exact` (two arms): red `conformance.rs:332: AUD_MW_E: frame is | ||
| 179 | + 38015 samples (176x144), the reference frame is 38016`; false pass `PASS table (26 | ||
| 180 | + bit-exact, 9 refused by name)`. | ||
| 181 | +- `jvt_full_sequence_bit_exact`: red `conformance.rs:1118: AUD_MW_E: frame 1 is 38015 | ||
| 182 | + samples, 38016 expected`; false pass `ok`. | ||
| 183 | +- `p_only_gop_matches_ffmpeg_every_frame` / `compare_sequence`: red `conformance.rs:282: | ||
| 184 | + frame 1 is 38016 samples, ffmpeg gave 38015`; false pass `cavlc-p: 12 frames bit-exact` / | ||
| 185 | + `cabac-p: 12 frames bit-exact`. | ||
| 186 | +- `output_is_display_order_and_the_reorder_is_real`: red `conformance.rs:1340: display-order | ||
| 187 | + frame 1 is 38016 samples, ffmpeg gave 38015`. Note a mid-sequence truncation of OUR | ||
| 188 | + display frames is already caught pre-fix by the unrelated ours-vs-ours membership check | ||
| 189 | + at 1313, so the isolation mutation truncates the ORACLE frame. | ||
| 190 | +- `packet_entry_surface_reorders_and_carries_timestamps` (two sites): red | ||
| 191 | + `conformance.rs:2062`; false pass `ok`. | ||
| 192 | + | ||
| 193 | +### Live green, after restore | ||
| 194 | + | ||
| 195 | +``` | ||
| 196 | +cargo test -p ec-av1 --release --lib -- stream::tests::a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands \ | ||
| 197 | + encoder::tests::a_static_clip_codes_64x64_roots_and_decodes_sample_exact \ | ||
| 198 | + encode::tests::every_mode_decodes_to_what_the_encoder_predicted | ||
| 199 | + test result: ok. 3 passed; 0 failed; 0 ignored; 700 filtered out; finished in 3.56s | ||
| 200 | +cargo test -p ec-vp9 --test intraonly_exact --test inter_pixels_exact | ||
| 201 | + intra_only_frame_and_its_successors_match_ffmpeg ... ok (1 passed) | ||
| 202 | + inter_gop_matches_ffmpeg / inter_gop_with_tile_columns_matches_ffmpeg / corpus_1080p_60fps_matches_ffmpeg_past_frame_72 ... ok (3 passed) | ||
| 203 | +cargo test -p ec-h264 --test conformance | ||
| 204 | + jvt_scaling_matrices_decode_bit_exact ok 0.17s; p_only_gop_matches_ffmpeg_every_frame ok | ||
| 205 | + 0.31s; output_is_display_order_and_the_reorder_is_real ok 0.23s; | ||
| 206 | + packet_entry_surface_reorders_and_carries_timestamps ok 0.22s; | ||
| 207 | + jvt_cavlc_first_idr_bit_exact ok 1.68s; jvt_full_sequence_bit_exact ok 5.77s | ||
| 208 | +cargo check -p ec-av1 --lib --tests -> Finished, no errors, no warnings | ||
| 209 | +cargo check -p ec-h264 -p ec-vp9 --tests -> Finished (5 pre-existing ec-vp9 lib warnings) | ||
| 210 | +``` | ||
| 211 | + | ||
| 212 | +Not executed live: the ~30 UNSAFE sites inside `#[ignore]`d ec-av1 gates (they need an | ||
| 213 | +explicit `--ignored` run and aomenc-driven sweeps) and the `EC_AV1_PIN` scratch diagnostic | ||
| 214 | +at `stream.rs:29369`. They are fixed by the identical insertion; the red proof is carried | ||
| 215 | +by a non-`#[ignore]`d sibling in the same file exercising the same assert shape. | ||
| 216 | + | ||
| 217 | +## Notes for the parent | ||
| 218 | + | ||
| 219 | +- The repo's cargo target runner (`scripts/memguard-runner.sh`, wired in | ||
| 220 | + `.cargo/config.toml`) fails in this container with `Unit run-p...scope was already loaded | ||
| 221 | + or has a fragment file`. Pre-existing, unrelated to the diff; `EC_NOMEMGUARD=1` is the | ||
| 222 | + runner's own documented escape hatch and was used for every run above. | ||
| 223 | +- A scratch `worktree/fixtures -> main checkout fixtures` symlink (untracked, gitignored) | ||
| 224 | + was needed to make the JVT-vector tests run in the worktree. It is not part of the diff. | ||
| 225 | +- Nothing is pushed. The main checkout at `/home/user/Documents/Code/Rust/edith_codecs` | ||
| 226 | + is clean (`git status --porcelain` empty). | ||
| 227 | + | ||
| 228 | +## Reviewing this commit | ||
| 229 | + | ||
| 230 | +`core.hooksPath` points at `~/.omp/agent/hooks/git`, whose `pre-commit` runs | ||
| 231 | +`format-staged.py` over the staged tree. That hook re-flowed `encode.rs` and `encoder.rs` | ||
| 232 | +wholesale at commit time (the reflow is line-BREAK churn, so `git diff -w` does not hide | ||
| 233 | +it: the semantic diff is the ~68 `assert_eq!` insertions, the `first_difference` rewrite, | ||
| 234 | + the three comment/message corrections and the `examples/dump_yuv.rs` note). Per skill | ||
| 235 | + `edith-format-churn-commit-hook` the committed, hook-formatted version is the canonical | ||
| 236 | + tree and is NOT reverted. The hook ran rustfmt with this workspace's edition: the | ||
| 237 | + committed tree still compiles clean | ||
| 238 | + (`cargo check -p ec-av1 --lib --tests` -> Finished, no errors, no warnings) and the three | ||
| 239 | + named green tests above still pass on the committed blobs | ||
| 240 | + (`test result: ok. 3 passed; 0 failed; 0 ignored; 700 filtered out`). | ||