mirror of
https://github.com/storytold/filmcraft.git
synced 2026-10-28 03:59:26 -06:00
`Format::Hevc` is available only where a hardware HEVC session can be created, and `hardware_encode::hevc_available` finds out by creating a small one on the first question. That question comes from the first draw of Export mode's format list, on the UI thread, and the session takes about 0.1 s (88-100 ms in seven of eight fresh processes on an Apple M1, 222 ms in the first): the app stalls for that long the first time Export is opened. `register()` now starts the probe on a thread of its own (`warm_hevc_probe`, once however many times `register` is called). Whoever asks while it runs waits for the same `OnceLock` answer, no longer than asking first; a thread that cannot start, or a probe that panics (caught), leaves the question to the first caller as before. `hevc_probed()` says whether the answer exists, for diagnostics and tests. Test: `tests/hevc_probe.rs` registers, never calls `hevc_available`, and waits for `hevc_probed()` (it fails after 60 s without the call in `register`). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
30 lines
1.1 KiB
Rust
30 lines
1.1 KiB
Rust
//! `register()` answers the HEVC availability probe in the background, so the first draw of the
|
|
//! format list does not create a hardware session on the UI thread. One test in this file on
|
|
//! purpose: anything else that asked `hevc_available()` first would make the wait below meaningless.
|
|
#![cfg(target_os = "macos")]
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
use filmcraft_platform::hardware_encode::{hevc_available, hevc_probed, warm_hevc_probe};
|
|
|
|
#[test]
|
|
fn register_answers_the_hevc_probe_in_the_background() {
|
|
assert!(!hevc_probed(), "nothing has asked yet");
|
|
|
|
filmcraft_platform::register();
|
|
|
|
// nobody calls `hevc_available()` here: only the thread `register` started can answer
|
|
let t0 = Instant::now();
|
|
while !hevc_probed() {
|
|
assert!(t0.elapsed() < Duration::from_secs(60), "register() did not start the probe");
|
|
std::thread::sleep(Duration::from_millis(5));
|
|
}
|
|
|
|
// asking again, or registering again, changes nothing
|
|
let answer = hevc_available();
|
|
warm_hevc_probe();
|
|
filmcraft_platform::register();
|
|
assert_eq!(hevc_available(), answer);
|
|
assert!(hevc_probed());
|
|
}
|