ec-opus conformance: delete decode_speed and encode_speed wall-clock floors (owner rule: no speed gates) and the TIMING lock and CPU-time helpers only they used
Browse files at this commitcd757bd289bc81ae03a5206447fe852483eaaa01Parent: be888451 changed file +1 -200
crates/ec-opus/tests/conformance.rsmodified+1 -200
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | //! RFC 6716 conformance: the official test vectors, the `opus_compare` quality |
| 2 | -//! metric, real-file oracles against ffmpeg, and the decode-speed floor. | |
| 2 | +//! metric, real-file oracles against ffmpeg. | |
| 3 | 3 | //! |
| 4 | 4 | //! All of it lives in one test binary on purpose — a file per feature costs a |
| 5 | 5 | //! serial link-and-run for every build. |
| @@ -454,7 +454,6 @@ fn run_rfc8251(name: &str, reference: &str) -> (usize, usize, f64) { | ||
| 454 | 454 | /// shift) and the `m` set (without it) are both run and both reported. |
| 455 | 455 | #[test] |
| 456 | 456 | fn rfc8251_test_vectors() { |
| 457 | - let _timing = timing_shared(); | |
| 458 | 457 | let mut dec_ok = true; |
| 459 | 458 | let mut m_ok = true; |
| 460 | 459 | for name in VECTORS { |
| @@ -491,7 +490,6 @@ const VECTORS: [&str; 12] = [ | ||
| 491 | 490 | /// MUST stay within the `opus_compare` threshold (quality >= 0). |
| 492 | 491 | #[test] |
| 493 | 492 | fn rfc6716_test_vectors() { |
| 494 | - let _timing = timing_shared(); | |
| 495 | 493 | let mut table = Vec::new(); |
| 496 | 494 | for name in VECTORS { |
| 497 | 495 | let path = |
| @@ -680,7 +678,6 @@ fn tone_power(x: &[f32], channels: usize, ch: usize, freq: f64) -> f64 { | ||
| 680 | 678 | |
| 681 | 679 | #[test] |
| 682 | 680 | fn ogg_opus_fixtures_match_ffmpeg() { |
| 683 | - let _timing = timing_shared(); | |
| 684 | 681 | // Mapping family 1 puts 5.1 in Vorbis order; ffmpeg hands its own order |
| 685 | 682 | // back, so the comparison permutes one into the other. |
| 686 | 683 | const VORBIS_TO_FFMPEG_5_1: [usize; 6] = [0, 2, 1, 4, 5, 3]; |
| @@ -717,7 +714,6 @@ fn ogg_opus_fixtures_match_ffmpeg() { | ||
| 717 | 714 | |
| 718 | 715 | #[test] |
| 719 | 716 | fn five_one_channels_land_in_the_right_places() { |
| 720 | - let _timing = timing_shared(); | |
| 721 | 717 | // The fixture carries one distinct sine per channel, so a channel-order |
| 722 | 718 | // bug shows up as a channel playing the wrong tone. The tones themselves |
| 723 | 719 | // come from the reference decode rather than from an assumption about how |
| @@ -753,115 +749,6 @@ fn five_one_channels_land_in_the_right_places() { | ||
| 753 | 749 | } |
| 754 | 750 | } |
| 755 | 751 | |
| 756 | -/// Every speed-floor test takes this exclusively and every other test in this | |
| 757 | -/// binary takes it shared, so a floor is never measured while another | |
| 758 | -/// conformance test is loading the same host. | |
| 759 | -static TIMING: std::sync::RwLock<()> = std::sync::RwLock::new(()); | |
| 760 | - | |
| 761 | -fn timing_shared() -> std::sync::RwLockReadGuard<'static, ()> { | |
| 762 | - TIMING.read().unwrap_or_else(|e| e.into_inner()) | |
| 763 | -} | |
| 764 | - | |
| 765 | -fn timing_exclusive() -> std::sync::RwLockWriteGuard<'static, ()> { | |
| 766 | - TIMING.write().unwrap_or_else(|e| e.into_inner()) | |
| 767 | -} | |
| 768 | - | |
| 769 | -/// Seconds of CPU time consumed by the calling thread, or `None` where the | |
| 770 | -/// clock is unavailable. Used by the speed floors: a loaded host that | |
| 771 | -/// deschedules the test thread (or runs the other conformance tests beside it) | |
| 772 | -/// must not count against the floor, so the floors measure work, not wall time. | |
| 773 | -fn thread_cpu_secs() -> Option<f64> { | |
| 774 | - #[cfg(target_os = "linux")] | |
| 775 | - { | |
| 776 | - if let Ok(t) = cpu_time::ThreadTime::try_now() { | |
| 777 | - return Some(t.as_duration().as_secs_f64()); | |
| 778 | - } | |
| 779 | - } | |
| 780 | - None | |
| 781 | -} | |
| 782 | - | |
| 783 | -/// Time one run of `f`: thread CPU time where available, wall time elsewhere. | |
| 784 | -fn timed_once<F: FnMut()>(f: &mut F) -> f64 { | |
| 785 | - let cpu0 = thread_cpu_secs(); | |
| 786 | - let wall = std::time::Instant::now(); | |
| 787 | - f(); | |
| 788 | - match (cpu0, thread_cpu_secs()) { | |
| 789 | - (Some(a), Some(b)) => b - a, | |
| 790 | - _ => wall.elapsed().as_secs_f64(), | |
| 791 | - } | |
| 792 | -} | |
| 793 | - | |
| 794 | -/// Best of three runs. The fastest run is the one least disturbed by the host, | |
| 795 | -/// which is the usual benchmark practice for a throughput floor. | |
| 796 | -fn best_of_3<F: FnMut()>(mut f: F) -> f64 { | |
| 797 | - (0..3) | |
| 798 | - .map(|_| timed_once(&mut f)) | |
| 799 | - .fold(f64::INFINITY, f64::min) | |
| 800 | -} | |
| 801 | - | |
| 802 | -#[test] | |
| 803 | -fn decode_speed() { | |
| 804 | - let _timing = timing_exclusive(); | |
| 805 | - if cfg!(debug_assertions) { | |
| 806 | - eprintln!("decode speed is only meaningful in release; skipped"); | |
| 807 | - return; | |
| 808 | - } | |
| 809 | - for (name, channels) in [ | |
| 810 | - ("opus-ogg-stereo-48000.opus", 2usize), | |
| 811 | - ("opus-ogg-5.1-48000.opus", 6), | |
| 812 | - ] { | |
| 813 | - let path = fixture(name); | |
| 814 | - let data = fs::read(&path).unwrap(); | |
| 815 | - let packets = ogg_packets(&data); | |
| 816 | - let head = parse_opus_head(&packets[0]); | |
| 817 | - let audio: Vec<&Vec<u8>> = packets.iter().skip(2).filter(|p| !p.is_empty()).collect(); | |
| 818 | - let mut dec = | |
| 819 | - MultistreamDecoder::with_rate(48000, head.streams, head.coupled, &head.mapping); | |
| 820 | - let mut out = vec![0.0f32; 5760 * channels]; | |
| 821 | - // Warm up, then measure enough passes to cover several seconds of audio. | |
| 822 | - let mut samples = 0usize; | |
| 823 | - for p in &audio { | |
| 824 | - samples += dec.decode_float(p, &mut out).unwrap(); | |
| 825 | - } | |
| 826 | - let passes = 20; | |
| 827 | - let elapsed = best_of_3(|| { | |
| 828 | - for _ in 0..passes { | |
| 829 | - dec.reset(); | |
| 830 | - for p in &audio { | |
| 831 | - dec.decode_float(p, &mut out).unwrap(); | |
| 832 | - } | |
| 833 | - } | |
| 834 | - }); | |
| 835 | - let audio_secs = (samples * passes) as f64 / 48000.0; | |
| 836 | - let realtime = audio_secs / elapsed; | |
| 837 | - println!( | |
| 838 | - "{name}: {realtime:.0}x realtime ({channels} channels, {audio_secs:.1} s in {elapsed:.3} s)" | |
| 839 | - ); | |
| 840 | - let floor = if channels == 6 { 104.0 } else { 135.0 }; | |
| 841 | - assert!( | |
| 842 | - realtime >= floor, | |
| 843 | - "{name}: {realtime:.0}x realtime is below the {floor}x floor" | |
| 844 | - ); | |
| 845 | - } | |
| 846 | - | |
| 847 | - // The fixtures are sine tones, which are cheap; testvector01 is real music | |
| 848 | - // at a high rate and is the honest stereo number. | |
| 849 | - let path = ec_testkit::fixture("vectors/opus-rfc6716/opus_testvectors/testvector01.bit"); | |
| 850 | - let packets = read_vector(&path); | |
| 851 | - let mut out = vec![0.0f32; 5760 * 2]; | |
| 852 | - let mut samples = 0usize; | |
| 853 | - let elapsed = best_of_3(|| { | |
| 854 | - let mut dec = Decoder::new(48000, 2).unwrap(); | |
| 855 | - samples = 0; | |
| 856 | - for p in &packets { | |
| 857 | - samples += dec.decode_float(&p.payload, &mut out).unwrap(); | |
| 858 | - } | |
| 859 | - }); | |
| 860 | - let realtime = samples as f64 / 48000.0 / elapsed; | |
| 861 | - println!("testvector01 (stereo music): {realtime:.0}x realtime"); | |
| 862 | - assert!(realtime >= 135.0, "stereo music decodes at {realtime:.0}x"); | |
| 863 | -} | |
| 864 | - | |
| 865 | 752 | // --------------------------------------------------------------------------- |
| 866 | 753 | // Encoder: self-consistency (range-exact against our own decoder) |
| 867 | 754 | // --------------------------------------------------------------------------- |
| @@ -952,7 +839,6 @@ fn delayed_corr(source: &[f32], decoded: &[f32], channels: usize, delay: usize) | ||
| 952 | 839 | /// the world (the incumbent's exact disease). |
| 953 | 840 | #[test] |
| 954 | 841 | fn encoder_roundtrips_at_every_rate() { |
| 955 | - let _timing = timing_shared(); | |
| 956 | 842 | for channels in [1usize, 2] { |
| 957 | 843 | let pcm = test_signal(channels, 2.0); |
| 958 | 844 | for kbps in [32u32, 64, 96, 128, 160, 165, 192, 256, 320, 510] { |
| @@ -978,7 +864,6 @@ fn encoder_roundtrips_at_every_rate() { | ||
| 978 | 864 | /// It is on by default except for `Application::LowDelay`, as in libopus. |
| 979 | 865 | #[test] |
| 980 | 866 | fn libopus_input_alignment_delays_and_still_decodes() { |
| 981 | - let _timing = timing_shared(); | |
| 982 | 867 | let pcm = test_signal(2, 1.0); |
| 983 | 868 | let mut enc = Encoder::new(48000, 2, Application::Audio).unwrap(); |
| 984 | 869 | enc.set_bitrate(128_000); |
| @@ -1006,7 +891,6 @@ fn libopus_input_alignment_delays_and_still_decodes() { | ||
| 1006 | 891 | // voice/music bandwidth tables blended by voice_est) since lane opus-mode; |
| 1007 | 892 | // matched against ffmpeg libopus on real speech in lanes/opus-mode-r1.sweep.txt. |
| 1008 | 893 | fn encoder_mode_follows_application_bitrate_channels_and_frame_size() { |
| 1009 | - let _timing = timing_shared(); | |
| 1010 | 894 | #[derive(Clone, Copy, Debug)] |
| 1011 | 895 | struct Case { |
| 1012 | 896 | app: Application, |
| @@ -1367,7 +1251,6 @@ fn encoder_mode_follows_application_bitrate_channels_and_frame_size() { | ||
| 1367 | 1251 | /// stays decodable and lands near its target. |
| 1368 | 1252 | #[test] |
| 1369 | 1253 | fn encoder_frame_sizes_and_vbr() { |
| 1370 | - let _timing = timing_shared(); | |
| 1371 | 1254 | let pcm = test_signal(2, 1.0); |
| 1372 | 1255 | for frame in [120usize, 240, 480, 960] { |
| 1373 | 1256 | let mut enc = Encoder::new(48000, 2, Application::Audio).unwrap(); |
| @@ -1488,7 +1371,6 @@ fn temp_path(name: &str) -> PathBuf { | ||
| 1488 | 1371 | /// bars here are correlation >= 0.9 at 96/165/256 kbps. |
| 1489 | 1372 | #[test] |
| 1490 | 1373 | fn oracle_decodes_our_packets_across_the_rate_table() { |
| 1491 | - let _timing = timing_shared(); | |
| 1492 | 1374 | for channels in [1usize, 2] { |
| 1493 | 1375 | let pcm = test_signal(channels, 2.0); |
| 1494 | 1376 | let total = pcm.len() / channels; |
| @@ -1598,7 +1480,6 @@ fn oracle_decodes_our_packets_across_the_rate_table() { | ||
| 1598 | 1480 | /// back in its place (order-preserved) at correlation >= 0.9. |
| 1599 | 1481 | #[test] |
| 1600 | 1482 | fn five_one_encode_end_to_end() { |
| 1601 | - let _timing = timing_shared(); | |
| 1602 | 1483 | const VORBIS_TO_FFMPEG_5_1: [usize; 6] = [0, 2, 1, 4, 5, 3]; |
| 1603 | 1484 | const TONES: [f64; 6] = [220.0, 440.0, 660.0, 55.0, 880.0, 1320.0]; |
| 1604 | 1485 | let total = 96000usize; |
| @@ -1650,7 +1531,6 @@ fn five_one_encode_end_to_end() { | ||
| 1650 | 1531 | /// libopus hands back is exactly the input length. |
| 1651 | 1532 | #[test] |
| 1652 | 1533 | fn ogg_opus_round_trip_duration_is_exact() { |
| 1653 | - let _timing = timing_shared(); | |
| 1654 | 1534 | let pcm = test_signal(2, 2.0); |
| 1655 | 1535 | let total = pcm.len() / 2; |
| 1656 | 1536 | let mut enc = Encoder::new(48000, 2, Application::Audio).unwrap(); |
| @@ -1714,7 +1594,6 @@ fn ogg_opus_round_trip_duration_is_exact() { | ||
| 1714 | 1594 | #[test] |
| 1715 | 1595 | fn steady_state_encode_loop_zero_alloc() { |
| 1716 | 1596 | install_counter(); |
| 1717 | - let _timing = timing_shared(); | |
| 1718 | 1597 | let pcm = test_signal(2, 0.5); |
| 1719 | 1598 | let pcm6 = { |
| 1720 | 1599 | let mono = test_signal(1, 0.5); |
| @@ -1765,80 +1644,11 @@ fn steady_state_encode_loop_zero_alloc() { | ||
| 1765 | 1644 | // those is a separate, much larger effort than this defect's scope. |
| 1766 | 1645 | } |
| 1767 | 1646 | |
| 1768 | -/// The throughput headline: encode speed in multiples of realtime, per | |
| 1769 | -/// configuration, at the product's rates. Floors are deliberately far under | |
| 1770 | -/// the measured numbers — they catch a regression class (an accidental | |
| 1771 | -/// O(n^2), a debug path left on), not machine variance. | |
| 1772 | -#[test] | |
| 1773 | -fn encode_speed() { | |
| 1774 | - let _timing = timing_exclusive(); | |
| 1775 | - if cfg!(debug_assertions) { | |
| 1776 | - eprintln!("encode speed is only meaningful in release; skipped"); | |
| 1777 | - return; | |
| 1778 | - } | |
| 1779 | - let secs = 4.0; | |
| 1780 | - for (name, channels, kbps, floor) in [ | |
| 1781 | - ("mono 96k", 1usize, 96u32, 100.0f64), | |
| 1782 | - ("stereo 128k", 2, 128, 70.0), | |
| 1783 | - ("stereo 256k", 2, 256, 70.0), | |
| 1784 | - ("stereo 510k", 2, 510, 50.0), | |
| 1785 | - ] { | |
| 1786 | - let pcm = test_signal(channels, secs); | |
| 1787 | - let mut enc = Encoder::new(48000, channels, Application::Audio).unwrap(); | |
| 1788 | - enc.set_bitrate(kbps * 1000); | |
| 1789 | - let mut out = vec![0u8; 1500]; | |
| 1790 | - // Warm up one pass, then measure. | |
| 1791 | - for block in pcm.chunks_exact(960 * channels) { | |
| 1792 | - enc.encode_float(block, 960, &mut out).unwrap(); | |
| 1793 | - } | |
| 1794 | - let passes = 4; | |
| 1795 | - let elapsed = best_of_3(|| { | |
| 1796 | - for _ in 0..passes { | |
| 1797 | - for block in pcm.chunks_exact(960 * channels) { | |
| 1798 | - enc.encode_float(block, 960, &mut out).unwrap(); | |
| 1799 | - } | |
| 1800 | - } | |
| 1801 | - }); | |
| 1802 | - let realtime = secs * passes as f64 / elapsed; | |
| 1803 | - println!("{name}: {realtime:.0}x realtime"); | |
| 1804 | - assert!( | |
| 1805 | - realtime >= floor, | |
| 1806 | - "{name}: {realtime:.0}x is below {floor}x" | |
| 1807 | - ); | |
| 1808 | - } | |
| 1809 | - // 5.1 multistream. | |
| 1810 | - let mono = test_signal(1, secs); | |
| 1811 | - let mut pcm6 = Vec::with_capacity(mono.len() * 6); | |
| 1812 | - for &s in &mono { | |
| 1813 | - for c in 0..6 { | |
| 1814 | - pcm6.push(s * (1.0 + c as f32 * 0.01)); | |
| 1815 | - } | |
| 1816 | - } | |
| 1817 | - let mut ms = MultistreamEncoder::surround_5_1(48000).unwrap(); | |
| 1818 | - ms.set_bitrate(384_000); | |
| 1819 | - let mut out = vec![0u8; 8 * 1500]; | |
| 1820 | - for block in pcm6.as_chunks::<{ 960 * 6 }>().0 { | |
| 1821 | - ms.encode_float(block, 960, &mut out).unwrap(); | |
| 1822 | - } | |
| 1823 | - let passes = 4; | |
| 1824 | - let elapsed = best_of_3(|| { | |
| 1825 | - for _ in 0..passes { | |
| 1826 | - for block in pcm6.as_chunks::<{ 960 * 6 }>().0 { | |
| 1827 | - ms.encode_float(block, 960, &mut out).unwrap(); | |
| 1828 | - } | |
| 1829 | - } | |
| 1830 | - }); | |
| 1831 | - let realtime = secs * passes as f64 / elapsed; | |
| 1832 | - println!("5.1 384k: {realtime:.0}x realtime"); | |
| 1833 | - assert!(realtime >= 25.0, "5.1: {realtime:.0}x is below 25x"); | |
| 1834 | -} | |
| 1835 | - | |
| 1836 | 1647 | /// Malformed input must come back as an error, never a panic: the decoders |
| 1837 | 1648 | /// index tables with values the bitstream chooses, so this throws well-formed |
| 1838 | 1649 | /// TOC bytes at random payloads to make sure every mode is actually entered. |
| 1839 | 1650 | #[test] |
| 1840 | 1651 | fn garbage_payloads_never_panic() { |
| 1841 | - let _timing = timing_shared(); | |
| 1842 | 1652 | let mut state = 0x12345678u32; |
| 1843 | 1653 | let mut rand = move || { |
| 1844 | 1654 | state ^= state << 13; |
| @@ -2022,7 +1832,6 @@ fn aligned_corr(reference: &[f32], decoded: &[f32], max_lag: usize) -> (f64, usi | ||
| 2022 | 1832 | |
| 2023 | 1833 | #[test] |
| 2024 | 1834 | fn silk_mono_nb_wb_roundtrip() { |
| 2025 | - let _timing = timing_shared(); | |
| 2026 | 1835 | let wav = fixture("wav16-mono-48000.wav"); |
| 2027 | 1836 | let mut sources = vec![("synthetic", speech_like())]; |
| 2028 | 1837 | let w = read_wav_mono(&wav); |
| @@ -2067,7 +1876,6 @@ fn silk_mono_nb_wb_roundtrip() { | ||
| 2067 | 1876 | |
| 2068 | 1877 | #[test] |
| 2069 | 1878 | fn silk_mediumband_and_10ms_roundtrip() { |
| 2070 | - let _timing = timing_shared(); | |
| 2071 | 1879 | let pcm = speech_like(); |
| 2072 | 1880 | for (tag, bandwidth, frame_ms, config, cutoff, bps, floor) in [ |
| 2073 | 1881 | ( |
| @@ -2103,7 +1911,6 @@ fn silk_mediumband_and_10ms_roundtrip() { | ||
| 2103 | 1911 | |
| 2104 | 1912 | #[test] |
| 2105 | 1913 | fn silk_multiframe_packets_roundtrip() { |
| 2106 | - let _timing = timing_shared(); | |
| 2107 | 1914 | let full = speech_like(); |
| 2108 | 1915 | let pcm = &full[..46_080]; |
| 2109 | 1916 | for (tag, bandwidth, frame_ms, config, cutoff, bps, floor) in [ |
| @@ -2180,7 +1987,6 @@ fn aligned_channel_corr(reference: &[f32], decoded: &[f32], channels: usize, ch: | ||
| 2180 | 1987 | |
| 2181 | 1988 | #[test] |
| 2182 | 1989 | fn silk_stereo_speech_roundtrip() { |
| 2183 | - let _timing = timing_shared(); | |
| 2184 | 1990 | let pcm = stereo_speech_pair(); |
| 2185 | 1991 | let total = pcm.len() / 2; |
| 2186 | 1992 | for (tag, bandwidth, per_channel_bps, cutoff, frame, config, code, frames) in [ |
| @@ -2331,7 +2137,6 @@ fn silk_sources() -> Vec<(&'static str, Vec<f32>)> { | ||
| 2331 | 2137 | /// path it dispatches to. |
| 2332 | 2138 | #[test] |
| 2333 | 2139 | fn silk_packets_track_encoder_bitrate() { |
| 2334 | - let _timing = timing_shared(); | |
| 2335 | 2140 | let pcm = test_signal(1, 2.0); |
| 2336 | 2141 | for kbps_target in [8u32, 12, 16] { |
| 2337 | 2142 | let mut enc = Encoder::new(48000, 1, Application::Voip).unwrap(); |
| @@ -2399,7 +2204,6 @@ fn hybrid_delay(bps: u32) -> usize { | ||
| 2399 | 2204 | |
| 2400 | 2205 | #[test] |
| 2401 | 2206 | fn hybrid_layers_align() { |
| 2402 | - let _timing = timing_shared(); | |
| 2403 | 2207 | let mut click = vec![0f32; 48000]; |
| 2404 | 2208 | // Well inside the stream so both layers' predictors are running. |
| 2405 | 2209 | let at = 960 * 10 + 300; |
| @@ -2438,7 +2242,6 @@ fn hybrid_layers_align() { | ||
| 2438 | 2242 | /// [`Encoder::look_ahead`] of that same configuration, never a constant. |
| 2439 | 2243 | #[test] |
| 2440 | 2244 | fn hybrid_fb_roundtrip() { |
| 2441 | - let _timing = timing_shared(); | |
| 2442 | 2245 | for (name, pcm) in silk_sources() { |
| 2443 | 2246 | let (decoded, packets) = hybrid_roundtrip(&pcm, 32_000, None, (false, false)); |
| 2444 | 2247 | let toc = ec_opus::Toc::new(packets[0][0]); |
| @@ -2528,7 +2331,6 @@ fn hybrid_roundtrip_shape( | ||
| 2528 | 2331 | |
| 2529 | 2332 | #[test] |
| 2530 | 2333 | fn hybrid_shapes_roundtrip() { |
| 2531 | - let _timing = timing_shared(); | |
| 2532 | 2334 | for (tag, channels, frame, bps, bandwidth, config, floor) in [ |
| 2533 | 2335 | ( |
| 2534 | 2336 | "mono-swb10", |
| @@ -2623,7 +2425,6 @@ fn hybrid_shapes_roundtrip() { | ||
| 2623 | 2425 | |
| 2624 | 2426 | #[test] |
| 2625 | 2427 | fn opus_compare_err_pinned_against_c() { |
| 2626 | - let _timing = timing_shared(); | |
| 2627 | 2428 | const N: usize = 48000 * 4; |
| 2628 | 2429 | let t: Vec<f64> = (0..N).map(|i| i as f64 / 48000.0).collect(); |
| 2629 | 2430 |