Merge branch 'worktree-agent-a52432e14c89f9202'
Browse files at this commit4 changed files +291 -12
- Cargo.lock +151 -0
- crates/engine/Cargo.toml +18 -3
- crates/engine/src/playback.rs +113 -5
- crates/engine/tests/pgs_bitmaps.rs +9 -4
Cargo.lockmodified+151 -0
| @@ -3372,6 +3372,16 @@ dependencies = [ | |||
| 3372 | "libc", | 3372 | "libc", |
| 3373 | ] | 3373 | ] |
| 3374 | 3374 | ||
| 3375 | +[[package]] | ||
| 3376 | +name = "matrixmultiply" | ||
| 3377 | +version = "0.3.11" | ||
| 3378 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3379 | +checksum = "3f607c237553f086e7043417a51df26b2eb899d3caff94e6a67592ff992fedc7" | ||
| 3380 | +dependencies = [ | ||
| 3381 | + "autocfg", | ||
| 3382 | + "rawpointer", | ||
| 3383 | +] | ||
| 3384 | + | ||
| 3375 | [[package]] | 3385 | [[package]] |
| 3376 | name = "maybe-rayon" | 3386 | name = "maybe-rayon" |
| 3377 | version = "0.1.1" | 3387 | version = "0.1.1" |
| @@ -3538,6 +3548,22 @@ dependencies = [ | |||
| 3538 | "getrandom 0.2.17", | 3548 | "getrandom 0.2.17", |
| 3539 | ] | 3549 | ] |
| 3540 | 3550 | ||
| 3551 | +[[package]] | ||
| 3552 | +name = "ndarray" | ||
| 3553 | +version = "0.17.2" | ||
| 3554 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3555 | +checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d" | ||
| 3556 | +dependencies = [ | ||
| 3557 | + "matrixmultiply", | ||
| 3558 | + "num-complex", | ||
| 3559 | + "num-integer", | ||
| 3560 | + "num-traits", | ||
| 3561 | + "portable-atomic", | ||
| 3562 | + "portable-atomic-util", | ||
| 3563 | + "rawpointer", | ||
| 3564 | + "serde", | ||
| 3565 | +] | ||
| 3566 | + | ||
| 3541 | [[package]] | 3567 | [[package]] |
| 3542 | name = "new_debug_unreachable" | 3568 | name = "new_debug_unreachable" |
| 3543 | version = "1.0.6" | 3569 | version = "1.0.6" |
| @@ -3608,6 +3634,34 @@ dependencies = [ | |||
| 3608 | "memchr", | 3634 | "memchr", |
| 3609 | ] | 3635 | ] |
| 3610 | 3636 | ||
| 3637 | +[[package]] | ||
| 3638 | +name = "non-empty-iter" | ||
| 3639 | +version = "0.3.1" | ||
| 3640 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3641 | +checksum = "ac123b8e4bd1fef3e8e972ba7a07f046ac6b608633ad761c61876b7197313f63" | ||
| 3642 | +dependencies = [ | ||
| 3643 | + "non-zero-size", | ||
| 3644 | +] | ||
| 3645 | + | ||
| 3646 | +[[package]] | ||
| 3647 | +name = "non-empty-slice" | ||
| 3648 | +version = "0.6.0" | ||
| 3649 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3650 | +checksum = "9935c822e11be79ef40f986558b00da0ff176b7c87ddf6d9fb8b9138a6112c20" | ||
| 3651 | +dependencies = [ | ||
| 3652 | + "non-empty-iter", | ||
| 3653 | + "non-zero-size", | ||
| 3654 | + "ownership", | ||
| 3655 | + "serde", | ||
| 3656 | + "thiserror 2.0.20", | ||
| 3657 | +] | ||
| 3658 | + | ||
| 3659 | +[[package]] | ||
| 3660 | +name = "non-zero-size" | ||
| 3661 | +version = "0.2.0" | ||
| 3662 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3663 | +checksum = "401b3a4027292c1c318fd2305783f791d5579d18e7143ef72d653bf0c29e6b36" | ||
| 3664 | + | ||
| 3611 | [[package]] | 3665 | [[package]] |
| 3612 | name = "noop_proc_macro" | 3666 | name = "noop_proc_macro" |
| 3613 | version = "0.3.0" | 3667 | version = "0.3.0" |
| @@ -3672,6 +3726,7 @@ checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" | |||
| 3672 | dependencies = [ | 3726 | dependencies = [ |
| 3673 | "bytemuck", | 3727 | "bytemuck", |
| 3674 | "num-traits", | 3728 | "num-traits", |
| 3729 | + "serde", | ||
| 3675 | ] | 3730 | ] |
| 3676 | 3731 | ||
| 3677 | [[package]] | 3732 | [[package]] |
| @@ -3951,6 +4006,12 @@ dependencies = [ | |||
| 3951 | "pin-project-lite", | 4006 | "pin-project-lite", |
| 3952 | ] | 4007 | ] |
| 3953 | 4008 | ||
| 4009 | +[[package]] | ||
| 4010 | +name = "ownership" | ||
| 4011 | +version = "0.3.0" | ||
| 4012 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 4013 | +checksum = "cfb1aeb68b9f2683ee3f83960c10668b37a8a640224ba1169697ee8fd1e906c1" | ||
| 4014 | + | ||
| 3954 | [[package]] | 4015 | [[package]] |
| 3955 | name = "oxideav-ac3" | 4016 | name = "oxideav-ac3" |
| 3956 | version = "0.0.10" | 4017 | version = "0.0.10" |
| @@ -4279,6 +4340,21 @@ version = "0.2.5" | |||
| 4279 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4340 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4280 | checksum = "5da3b0203fd7ee5720aa0b5e790b591aa5d3f41c3ed2c34a3a393382198af2f7" | 4341 | checksum = "5da3b0203fd7ee5720aa0b5e790b591aa5d3f41c3ed2c34a3a393382198af2f7" |
| 4281 | 4342 | ||
| 4343 | +[[package]] | ||
| 4344 | +name = "portable-atomic" | ||
| 4345 | +version = "1.15.0" | ||
| 4346 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 4347 | +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" | ||
| 4348 | + | ||
| 4349 | +[[package]] | ||
| 4350 | +name = "portable-atomic-util" | ||
| 4351 | +version = "0.2.7" | ||
| 4352 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 4353 | +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" | ||
| 4354 | +dependencies = [ | ||
| 4355 | + "portable-atomic", | ||
| 4356 | +] | ||
| 4357 | + | ||
| 4282 | [[package]] | 4358 | [[package]] |
| 4283 | name = "postage" | 4359 | name = "postage" |
| 4284 | version = "0.5.0" | 4360 | version = "0.5.0" |
| @@ -4324,6 +4400,15 @@ dependencies = [ | |||
| 4324 | "syn 2.0.119", | 4400 | "syn 2.0.119", |
| 4325 | ] | 4401 | ] |
| 4326 | 4402 | ||
| 4403 | +[[package]] | ||
| 4404 | +name = "primal-check" | ||
| 4405 | +version = "0.3.4" | ||
| 4406 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 4407 | +checksum = "dc0d895b311e3af9902528fbb8f928688abbd95872819320517cc24ca6b2bd08" | ||
| 4408 | +dependencies = [ | ||
| 4409 | + "num-integer", | ||
| 4410 | +] | ||
| 4411 | + | ||
| 4327 | [[package]] | 4412 | [[package]] |
| 4328 | name = "proc-macro-crate" | 4413 | name = "proc-macro-crate" |
| 4329 | version = "3.5.0" | 4414 | version = "3.5.0" |
| @@ -4700,6 +4785,12 @@ dependencies = [ | |||
| 4700 | "raw-window-handle", | 4785 | "raw-window-handle", |
| 4701 | ] | 4786 | ] |
| 4702 | 4787 | ||
| 4788 | +[[package]] | ||
| 4789 | +name = "rawpointer" | ||
| 4790 | +version = "0.2.1" | ||
| 4791 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 4792 | +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" | ||
| 4793 | + | ||
| 4703 | [[package]] | 4794 | [[package]] |
| 4704 | name = "rayon" | 4795 | name = "rayon" |
| 4705 | version = "1.12.0" | 4796 | version = "1.12.0" |
| @@ -4731,6 +4822,15 @@ dependencies = [ | |||
| 4731 | "once_cell", | 4822 | "once_cell", |
| 4732 | ] | 4823 | ] |
| 4733 | 4824 | ||
| 4825 | +[[package]] | ||
| 4826 | +name = "realfft" | ||
| 4827 | +version = "3.5.0" | ||
| 4828 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 4829 | +checksum = "f821338fddb99d089116342c46e9f1fbf3828dba077674613e734e01d6ea8677" | ||
| 4830 | +dependencies = [ | ||
| 4831 | + "rustfft", | ||
| 4832 | +] | ||
| 4833 | + | ||
| 4734 | [[package]] | 4834 | [[package]] |
| 4735 | name = "reborrow" | 4835 | name = "reborrow" |
| 4736 | version = "0.5.5" | 4836 | version = "0.5.5" |
| @@ -4869,6 +4969,9 @@ name = "ruopus" | |||
| 4869 | version = "0.1.2" | 4969 | version = "0.1.2" |
| 4870 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4970 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4871 | checksum = "fcfcd963c83fc1ada2180ccdac7f1568d87fb0f2ad7236b266fdc9fb9122fbfd" | 4971 | checksum = "fcfcd963c83fc1ada2180ccdac7f1568d87fb0f2ad7236b266fdc9fb9122fbfd" |
| 4972 | +dependencies = [ | ||
| 4973 | + "spectrograms", | ||
| 4974 | +] | ||
| 4872 | 4975 | ||
| 4873 | [[package]] | 4976 | [[package]] |
| 4874 | name = "rust-embed" | 4977 | name = "rust-embed" |
| @@ -4927,6 +5030,20 @@ dependencies = [ | |||
| 4927 | "semver", | 5030 | "semver", |
| 4928 | ] | 5031 | ] |
| 4929 | 5032 | ||
| 5033 | +[[package]] | ||
| 5034 | +name = "rustfft" | ||
| 5035 | +version = "6.4.1" | ||
| 5036 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 5037 | +checksum = "21db5f9893e91f41798c88680037dba611ca6674703c1a18601b01a72c8adb89" | ||
| 5038 | +dependencies = [ | ||
| 5039 | + "num-complex", | ||
| 5040 | + "num-integer", | ||
| 5041 | + "num-traits", | ||
| 5042 | + "primal-check", | ||
| 5043 | + "strength_reduce", | ||
| 5044 | + "transpose", | ||
| 5045 | +] | ||
| 5046 | + | ||
| 4930 | [[package]] | 5047 | [[package]] |
| 4931 | name = "rustix" | 5048 | name = "rustix" |
| 4932 | version = "0.38.44" | 5049 | version = "0.38.44" |
| @@ -5506,6 +5623,24 @@ dependencies = [ | |||
| 5506 | "windows-sys 0.61.2", | 5623 | "windows-sys 0.61.2", |
| 5507 | ] | 5624 | ] |
| 5508 | 5625 | ||
| 5626 | +[[package]] | ||
| 5627 | +name = "spectrograms" | ||
| 5628 | +version = "2.1.3" | ||
| 5629 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 5630 | +checksum = "3ff1e83612f5a16e413dbfaf0381753b5eee714932fc95db19fe0974d5e6462b" | ||
| 5631 | +dependencies = [ | ||
| 5632 | + "ndarray", | ||
| 5633 | + "non-empty-slice", | ||
| 5634 | + "num-complex", | ||
| 5635 | + "num-traits", | ||
| 5636 | + "once_cell", | ||
| 5637 | + "pkg-config", | ||
| 5638 | + "realfft", | ||
| 5639 | + "regex", | ||
| 5640 | + "rustfft", | ||
| 5641 | + "thiserror 2.0.20", | ||
| 5642 | +] | ||
| 5643 | + | ||
| 5509 | [[package]] | 5644 | [[package]] |
| 5510 | name = "spin" | 5645 | name = "spin" |
| 5511 | version = "0.9.9" | 5646 | version = "0.9.9" |
| @@ -5570,6 +5705,12 @@ version = "1.1.0" | |||
| 5570 | source = "registry+https://github.com/rust-lang/crates.io-index" | 5705 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 5571 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" | 5706 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" |
| 5572 | 5707 | ||
| 5708 | +[[package]] | ||
| 5709 | +name = "strength_reduce" | ||
| 5710 | +version = "0.2.4" | ||
| 5711 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 5712 | +checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82" | ||
| 5713 | + | ||
| 5573 | [[package]] | 5714 | [[package]] |
| 5574 | name = "strict-num" | 5715 | name = "strict-num" |
| 5575 | version = "0.1.1" | 5716 | version = "0.1.1" |
| @@ -6401,6 +6542,16 @@ dependencies = [ | |||
| 6401 | "once_cell", | 6542 | "once_cell", |
| 6402 | ] | 6543 | ] |
| 6403 | 6544 | ||
| 6545 | +[[package]] | ||
| 6546 | +name = "transpose" | ||
| 6547 | +version = "0.2.3" | ||
| 6548 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 6549 | +checksum = "1ad61aed86bc3faea4300c7aee358b4c6d0c8d6ccc36524c96e4c92ccf26e77e" | ||
| 6550 | +dependencies = [ | ||
| 6551 | + "num-integer", | ||
| 6552 | + "strength_reduce", | ||
| 6553 | +] | ||
| 6554 | + | ||
| 6404 | [[package]] | 6555 | [[package]] |
| 6405 | name = "try-lock" | 6556 | name = "try-lock" |
| 6406 | version = "0.2.5" | 6557 | version = "0.2.5" |
crates/engine/Cargo.tomlmodified+18 -3
| @@ -81,8 +81,23 @@ rusty_mp3 = "0.6" | |||
| 81 | # packet. This one does the whole pipeline. Its quirks are measured and worked | 81 | # packet. This one does the whole pipeline. Its quirks are measured and worked |
| 82 | # around in [`crate::export::write_ogg`] -- read that before touching this line. | 82 | # around in [`crate::export::write_ogg`] -- read that before touching this line. |
| 83 | rusty_vorbis = "0.1.1" | 83 | rusty_vorbis = "0.1.1" |
| 84 | -# The Opus decoder: pure Rust, MIT, no C and no FFI, and no dependencies at all | 84 | +# The Opus decoder: pure Rust, MIT, no C and no FFI. |
| 85 | -# without its default features (`spectrograms` is for its own analysis tools). | 85 | +# |
| 86 | +# `spectrograms` is not, as this line long claimed, "for its own analysis tools": | ||
| 87 | +# it is the crate's *FFT backend*, and it is default-on because CELT synthesis is | ||
| 88 | +# an N/4 complex FFT per block. Turned off -- which is what asking for `std` | ||
| 89 | +# alone did -- `celt/mdct.rs` falls back to an O(n²) DFT evaluated in f64, and a | ||
| 90 | +# 5.1 film soundtrack decodes at **0.95x realtime**: slower than playing it. | ||
| 91 | +# With the backend on, the same file decodes at **104x** (7.1: 0.93x -> 112x, | ||
| 92 | +# stereo: 10.4x -> 135x). The cost is fifteen pure-Rust crates (`spectrograms` -> | ||
| 93 | +# `realfft`/`rustfft`, `ndarray`, `regex`), still no C and no `build.rs`. | ||
| 94 | +# The output is *not* bit-identical to the DFT build -- FFT summation order | ||
| 95 | +# differs -- but the two agree to 144 dB SNR (max |Δ| 3.7e-8, half an LSB at | ||
| 96 | +# 24-bit) while *both* sit 93 dB from ffmpeg's own libopus decode of the same | ||
| 97 | +# file. The change is 40 dB below the decoder's existing distance to the | ||
| 98 | +# reference, i.e. inside float noise, and upstream says as much: Opus conformance | ||
| 99 | +# is a quality threshold (`opus_compare`), not bit-exactness, and every | ||
| 100 | +# bitstream-affecting computation stays exact either way. | ||
| 86 | # Symphonia has no Opus at any version -- its feature list stops at vorbis and | 101 | # Symphonia has no Opus at any version -- its feature list stops at vorbis and |
| 87 | # there is no `symphonia-codec-opus` crate -- while both of its containers *read* | 102 | # there is no `symphonia-codec-opus` crate -- while both of its containers *read* |
| 88 | # the format already: `A_OPUS` and `OpusHead` have always mapped to | 103 | # the format already: `A_OPUS` and `OpusHead` have always mapped to |
| @@ -99,7 +114,7 @@ rusty_vorbis = "0.1.1" | |||
| 99 | # where the film is silent. This one matches ffmpeg's own decode of the same file to a | 114 | # where the film is silent. This one matches ffmpeg's own decode of the same file to a |
| 100 | # correlation of 1.0000 on all six channels. Pinned exactly, like `oxideav-ac3` | 115 | # correlation of 1.0000 on all six channels. Pinned exactly, like `oxideav-ac3` |
| 101 | # below, because a decoder is a bit-exactness dependency. | 116 | # below, because a decoder is a bit-exactness dependency. |
| 102 | -ruopus = { version = "=0.1.2", default-features = false, features = ["std"] } | 117 | +ruopus = { version = "=0.1.2", default-features = false, features = ["std", "spectrograms"] } |
| 103 | # The Opus *encoder*, the other half of that pair: a pure-Rust port of libopus | 118 | # The Opus *encoder*, the other half of that pair: a pure-Rust port of libopus |
| 104 | # 1.6, BSD-3, `build.rs`-less and with **no dependencies at all** -- checked, not | 119 | # 1.6, BSD-3, `build.rs`-less and with **no dependencies at all** -- checked, not |
| 105 | # taken from the README (`cargo tree` is two lines; there is not one `.c`, `.h` | 120 | # taken from the README (`cargo tree` is two lines; there is not one `.c`, `.h` |
crates/engine/src/playback.rsmodified+113 -5
| @@ -276,6 +276,17 @@ pub struct PlaybackSession { | |||
| 276 | /// not -- with the single exception `sources` itself has, | 276 | /// not -- with the single exception `sources` itself has, |
| 277 | /// [`Self::remove_source`], which takes the same entry out of both. | 277 | /// [`Self::remove_source`], which takes the same entry out of both. |
| 278 | counts: Vec<u32>, | 278 | counts: Vec<u32>, |
| 279 | + /// Audio headers already read, by the `(path, stream)` they were read for. | ||
| 280 | + /// Every door that checks a file against the timeline asks the same two | ||
| 281 | + /// questions -- what this file's sound is, and what the timeline's first | ||
| 282 | + /// source's is ([`audio_matches`], [`first_audio_of`]) -- and each answer is | ||
| 283 | + /// a container open. Warm that is 5-10 ms; on a film whose pages have been | ||
| 284 | + /// evicted it is **1.7 s** (measured, 3.1 GB HEVC mkv), and both of those | ||
| 285 | + /// are spent on the thread that draws, because placing and importing are | ||
| 286 | + /// what a drag lands on. A header does not change while a session holds the | ||
| 287 | + /// file, so it is read once and remembered. Errors are not kept: a file that | ||
| 288 | + /// failed to open is asked again next time. | ||
| 289 | + probes: std::collections::HashMap<(std::path::PathBuf, usize), Option<crate::AudioProbe>>, | ||
| 279 | /// What each source's own frame rate is against this timeline's, indexed | 290 | /// What each source's own frame rate is against this timeline's, indexed |
| 280 | /// and grown exactly as [`Self::counts`] is (and shortened with it by | 291 | /// and grown exactly as [`Self::counts`] is (and shortened with it by |
| 281 | /// [`Self::remove_source`]). [`Rate::REAL_TIME`] for a file shot at the | 292 | /// [`Self::remove_source`]). [`Rate::REAL_TIME`] for a file shot at the |
| @@ -423,6 +434,7 @@ impl PlaybackSession { | |||
| 423 | audio_disabled, | 434 | audio_disabled, |
| 424 | project, | 435 | project, |
| 425 | counts: vec![meta.frame_count], | 436 | counts: vec![meta.frame_count], |
| 437 | + probes: std::collections::HashMap::new(), | ||
| 426 | // Source 0 *is* the timeline's rate: it defined it. | 438 | // Source 0 *is* the timeline's rate: it defined it. |
| 427 | rates: vec![Rate::REAL_TIME], | 439 | rates: vec![Rate::REAL_TIME], |
| 428 | span_rate: Rate::REAL_TIME, | 440 | span_rate: Rate::REAL_TIME, |
| @@ -534,6 +546,7 @@ impl PlaybackSession { | |||
| 534 | audio_disabled, | 546 | audio_disabled, |
| 535 | project, | 547 | project, |
| 536 | counts: vec![meta.frame_count], | 548 | counts: vec![meta.frame_count], |
| 549 | + probes: std::collections::HashMap::new(), | ||
| 537 | // Source 0 *is* the timeline's rate: it defined it. | 550 | // Source 0 *is* the timeline's rate: it defined it. |
| 538 | rates: vec![Rate::REAL_TIME], | 551 | rates: vec![Rate::REAL_TIME], |
| 539 | span_rate: Rate::REAL_TIME, | 552 | span_rate: Rate::REAL_TIME, |
| @@ -609,6 +622,7 @@ impl PlaybackSession { | |||
| 609 | audio_disabled: None, | 622 | audio_disabled: None, |
| 610 | project, | 623 | project, |
| 611 | counts: vec![meta.frame_count], | 624 | counts: vec![meta.frame_count], |
| 625 | + probes: std::collections::HashMap::new(), | ||
| 612 | // Source 0 *is* the timeline's rate: it defined it. | 626 | // Source 0 *is* the timeline's rate: it defined it. |
| 613 | rates: vec![Rate::REAL_TIME], | 627 | rates: vec![Rate::REAL_TIME], |
| 614 | span_rate: Rate::REAL_TIME, | 628 | span_rate: Rate::REAL_TIME, |
| @@ -902,6 +916,7 @@ impl PlaybackSession { | |||
| 902 | audio_disabled, | 916 | audio_disabled, |
| 903 | project, | 917 | project, |
| 904 | counts, | 918 | counts, |
| 919 | + probes: std::collections::HashMap::new(), | ||
| 905 | rates, | 920 | rates, |
| 906 | span_rate: Rate::REAL_TIME, | 921 | span_rate: Rate::REAL_TIME, |
| 907 | span, | 922 | span, |
| @@ -2055,7 +2070,7 @@ impl PlaybackSession { | |||
| 2055 | let image = crate::is_image(path); | 2070 | let image = crate::is_image(path); |
| 2056 | if !image { | 2071 | if !image { |
| 2057 | let first = self.first_audio()?; | 2072 | let first = self.first_audio()?; |
| 2058 | - audio_matches(&wanted, &first)?; | 2073 | + self.audio_matches_cached(&wanted, &first)?; |
| 2059 | } | 2074 | } |
| 2060 | let rate = self.file_rate(&wanted.path); | 2075 | let rate = self.file_rate(&wanted.path); |
| 2061 | let source = self.project.import(path, stream); | 2076 | let source = self.project.import(path, stream); |
| @@ -2167,8 +2182,44 @@ impl PlaybackSession { | |||
| 2167 | /// What the timeline's audio *is*: the chosen stream of the first source | 2182 | /// What the timeline's audio *is*: the chosen stream of the first source |
| 2168 | /// that could have any ([`audio_source_of`]), probed. Every other source is | 2183 | /// that could have any ([`audio_source_of`]), probed. Every other source is |
| 2169 | /// held to it. | 2184 | /// held to it. |
| 2170 | - fn first_audio(&self) -> crate::Result<Option<crate::AudioProbe>> { | 2185 | + /// |
| 2171 | - first_audio_of(self.project.sources()) | 2186 | + /// Through the session's own memo ([`probes`](Self::probes)), because this |
| 2187 | + /// is asked on the render thread: the free [`first_audio_of`] is the one a | ||
| 2188 | + /// worker with no session to reach for calls. | ||
| 2189 | + fn first_audio(&mut self) -> crate::Result<Option<crate::AudioProbe>> { | ||
| 2190 | + match audio_source_of(self.project.sources()) { | ||
| 2191 | + Some(first) => { | ||
| 2192 | + let (path, stream) = (first.path.clone(), first.audio_stream); | ||
| 2193 | + self.probe_cached(&path, stream) | ||
| 2194 | + } | ||
| 2195 | + None => Ok(None), | ||
| 2196 | + } | ||
| 2197 | + } | ||
| 2198 | + | ||
| 2199 | + /// One audio header, read at most once per session per `(path, stream)`. | ||
| 2200 | + fn probe_cached( | ||
| 2201 | + &mut self, | ||
| 2202 | + path: &Path, | ||
| 2203 | + stream: usize, | ||
| 2204 | + ) -> crate::Result<Option<crate::AudioProbe>> { | ||
| 2205 | + let key = (path.to_path_buf(), stream); | ||
| 2206 | + if let Some(probe) = self.probes.get(&key) { | ||
| 2207 | + return Ok(*probe); | ||
| 2208 | + } | ||
| 2209 | + let probe = AudioSession::probe(path, stream)?; | ||
| 2210 | + self.probes.insert(key, probe); | ||
| 2211 | + Ok(probe) | ||
| 2212 | + } | ||
| 2213 | + | ||
| 2214 | + /// [`audio_matches`] with this session's memo behind the new file's own | ||
| 2215 | + /// header too -- the second of the two opens a place or an import pays. | ||
| 2216 | + fn audio_matches_cached( | ||
| 2217 | + &mut self, | ||
| 2218 | + source: &Source, | ||
| 2219 | + first: &Option<crate::AudioProbe>, | ||
| 2220 | + ) -> crate::Result<()> { | ||
| 2221 | + let probe = self.probe_cached(&source.path, source.audio_stream)?; | ||
| 2222 | + audio_matches_probed(probe, first) | ||
| 2172 | } | 2223 | } |
| 2173 | 2224 | ||
| 2174 | /// Places `clip` on `lane` alone at the playhead, overwriting what it lands | 2225 | /// Places `clip` on `lane` alone at the playhead, overwriting what it lands |
| @@ -2320,7 +2371,7 @@ impl PlaybackSession { | |||
| 2320 | // Stream 0, and there is no other: a standalone audio file carries one | 2371 | // Stream 0, and there is no other: a standalone audio file carries one |
| 2321 | // track (`AudioSession::probe_streams`), so nothing here has a stream | 2372 | // track (`AudioSession::probe_streams`), so nothing here has a stream |
| 2322 | // to pick the way `place_stream_at` does for an mp4. | 2373 | // to pick the way `place_stream_at` does for an mp4. |
| 2323 | - audio_matches(&Source::new(path, 0), &first)?; | 2374 | + self.audio_matches_cached(&Source::new(path, 0), &first)?; |
| 2324 | let frames = audio_frames(path, self.meta.frame_rate)?; | 2375 | let frames = audio_frames(path, self.meta.frame_rate)?; |
| 2325 | let source = self.project.import(path, 0); | 2376 | let source = self.project.import(path, 0); |
| 2326 | self.note_frames(source, frames, Rate::REAL_TIME); | 2377 | self.note_frames(source, frames, Rate::REAL_TIME); |
| @@ -2912,12 +2963,22 @@ fn audio_source_of(sources: &[Source]) -> Option<&Source> { | |||
| 2912 | } | 2963 | } |
| 2913 | 2964 | ||
| 2914 | fn audio_matches(source: &Source, first: &Option<crate::AudioProbe>) -> crate::Result<()> { | 2965 | fn audio_matches(source: &Source, first: &Option<crate::AudioProbe>) -> crate::Result<()> { |
| 2966 | + let probe = AudioSession::probe(&source.path, source.audio_stream)?; | ||
| 2967 | + audio_matches_probed(probe, first) | ||
| 2968 | +} | ||
| 2969 | + | ||
| 2970 | +/// The verdict alone, once the file's own header is in hand: the half a session | ||
| 2971 | +/// with a memo behind it ([`PlaybackSession::audio_matches_cached`]) does not | ||
| 2972 | +/// have to open the file for. | ||
| 2973 | +fn audio_matches_probed( | ||
| 2974 | + probe: Option<crate::AudioProbe>, | ||
| 2975 | + first: &Option<crate::AudioProbe>, | ||
| 2976 | +) -> crate::Result<()> { | ||
| 2915 | // The layout, which the audio worker holds every source to anyway -- and not | 2977 | // The layout, which the audio worker holds every source to anyway -- and not |
| 2916 | // the rate any more: a file written at another one is resampled to the | 2978 | // the rate any more: a file written at another one is resampled to the |
| 2917 | // timeline's at the decoder's door ([`crate::audio::Resample`]), exactly as | 2979 | // timeline's at the decoder's door ([`crate::audio::Resample`]), exactly as |
| 2918 | // a file shot at another frame rate is read through [`Rate`]. Both silent is | 2980 | // a file shot at another frame rate is read through [`Rate`]. Both silent is |
| 2919 | // a match. | 2981 | // a match. |
| 2920 | - let probe = AudioSession::probe(&source.path, source.audio_stream)?; | ||
| 2921 | if probe.map(|p| p.channels) == first.map(|p| p.channels) { | 2982 | if probe.map(|p| p.channels) == first.map(|p| p.channels) { |
| 2922 | return Ok(()); | 2983 | return Ok(()); |
| 2923 | } | 2984 | } |
| @@ -3187,6 +3248,53 @@ mod tests { | |||
| 3187 | assert_eq!(session.sources().len(), session.counts.len()); | 3248 | assert_eq!(session.sources().len(), session.counts.len()); |
| 3188 | } | 3249 | } |
| 3189 | 3250 | ||
| 3251 | + /// The two headers a place reads are read *once*: an mp4 dropped on a lane | ||
| 3252 | + /// used to open its own container and the timeline's first source every | ||
| 3253 | + /// time, both on the thread that draws, and a film whose pages have gone | ||
| 3254 | + /// cold is 1.7 s of that. | ||
| 3255 | + /// | ||
| 3256 | + /// Proved by answering, not by timing: the memo is filled with a layout the | ||
| 3257 | + /// file does not have, and the place is refused. Only a door that read the | ||
| 3258 | + /// remembered header rather than the disk can refuse it. | ||
| 3259 | + #[test] | ||
| 3260 | + fn a_place_reads_each_audio_header_once() { | ||
| 3261 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 3262 | + session.set_gain(0.0); | ||
| 3263 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | ||
| 3264 | + let end = session.timeline_duration(); | ||
| 3265 | + assert!( | ||
| 3266 | + session | ||
| 3267 | + .place_stream_at(end, &asset("test_av2.mp4"), 0, None) | ||
| 3268 | + .expect("a file just imported is on this timeline") | ||
| 3269 | + ); | ||
| 3270 | + assert_eq!( | ||
| 3271 | + session.probes.len(), | ||
| 3272 | + 2, | ||
| 3273 | + "the timeline's first source and the file placed, once each" | ||
| 3274 | + ); | ||
| 3275 | + | ||
| 3276 | + // Now say av2 is 5.1. Nothing on disk changed, so a door that opens the | ||
| 3277 | + // file still matches; one that trusts the memo refuses by layout. | ||
| 3278 | + // Keyed exactly as a [`Source`] names a file -- canonical, symlinks | ||
| 3279 | + // resolved -- which is the key the doors look up. | ||
| 3280 | + let av2 = Source::new(asset("test_av2.mp4"), 0).path; | ||
| 3281 | + session.probes.insert( | ||
| 3282 | + (av2, 0), | ||
| 3283 | + Some(crate::AudioProbe { | ||
| 3284 | + sample_rate: 48_000, | ||
| 3285 | + channels: 6, | ||
| 3286 | + }), | ||
| 3287 | + ); | ||
| 3288 | + let refused = session | ||
| 3289 | + .place_stream_at(end, &asset("test_av2.mp4"), 0, None) | ||
| 3290 | + .expect_err("the remembered layout disagrees with the timeline's"); | ||
| 3291 | + assert!( | ||
| 3292 | + refused.to_string().contains("6 ch"), | ||
| 3293 | + "refused in the layout's own words: {refused}" | ||
| 3294 | + ); | ||
| 3295 | + assert_eq!(session.probes.len(), 2, "and nothing was opened to say so"); | ||
| 3296 | + } | ||
| 3297 | + | ||
| 3190 | #[test] | 3298 | #[test] |
| 3191 | fn boundary_seconds_round_trip_to_their_own_frame() { | 3299 | fn boundary_seconds_round_trip_to_their_own_frame() { |
| 3192 | for f in 0u32..300 { | 3300 | for f in 0u32..300 { |
crates/engine/tests/pgs_bitmaps.rsmodified+9 -4
| @@ -62,12 +62,17 @@ fn the_session_maps_a_pgs_track_onto_the_timeline_and_draws_it() { | |||
| 62 | let drawn = Instant::now(); | 62 | let drawn = Instant::now(); |
| 63 | let image = cues[0].image.as_ref().expect("a picture cue"); | 63 | let image = cues[0].image.as_ref().expect("a picture cue"); |
| 64 | let rgba = image.rgba().expect("the first display set decodes"); | 64 | let rgba = image.rgba().expect("the first display set decodes"); |
| 65 | + let took = drawn.elapsed(); | ||
| 65 | eprintln!( | 66 | eprintln!( |
| 66 | - "cue 0 decoded to {}x{} in {:?}", | 67 | + "cue 0 decoded to {}x{} in {took:?}", |
| 67 | - image.width, | 68 | + image.width, image.height, |
| 68 | - image.height, | ||
| 69 | - drawn.elapsed() | ||
| 70 | ); | 69 | ); |
| 70 | + // The run-length walk is paid once per cue *change* -- the window keeps the | ||
| 71 | + // picture while it is up ([`Player::sub_picture`]) -- so what this holds is | ||
| 72 | + // the cost of the one frame a new line appears on: 247 µs measured on this | ||
| 73 | + // remux, a sixty-eighth of that frame's budget. A whole repaint's worth | ||
| 74 | + // would mean the cache above it had stopped mattering. | ||
| 75 | + assert!(took.as_millis() < 16, "a frame's worth of decode: {took:?}"); | ||
| 71 | assert_eq!(rgba.len(), (image.width * image.height * 4) as usize); | 76 | assert_eq!(rgba.len(), (image.width * image.height * 4) as usize); |
| 72 | let opaque = rgba.chunks_exact(4).filter(|px| px[3] > 0).count(); | 77 | let opaque = rgba.chunks_exact(4).filter(|px| px[3] > 0).count(); |
| 73 | assert!(opaque > 0, "the block decoded to an empty canvas"); | 78 | assert!(opaque > 0, "the block decoded to an empty canvas"); |