FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
HW1: register the hardware decoders in every desktop run
justjohn12345b999b69f071d
diff --git a/apps/filmcraft/src/main.rs b/apps/filmcraft/src/main.rsindex 541a8275f..ded69eb34 100644--- a/apps/filmcraft/src/main.rs+++ b/apps/filmcraft/src/main.rs@@ -75,7 +75,7 @@ fn main() -> eframe::Result {filmcraft_ui_egui::crash::install(data_dir.clone().or_else(default_data_dir).map(|d| d.join("Logs")));// OS hardware video decoders (VideoToolbox on macOS) in front of our own; Settings ▸ Playback ▸// Hardware decoding switches them off. Unsupported streams and failures use our decoders.- log::info!("hardware decoding: {:?}", filmcraft_platform::register());+ register_hardware_decoders();let options = eframe::NativeOptions {viewport: egui::ViewportBuilder::default().with_title("FilmCraft")@@ -225,6 +225,15 @@ fn open_path(path: &str, reveal: bool) -> Result<(), String> {cmd.spawn().map(|_| ()).map_err(|e| format!("can't open {path}: {e}"))}+/// Put the OS hardware video decoders in front of our own. Registered in a statement of its own:+/// a log macro does not evaluate its arguments while no logger takes its level, which left the+/// hardware decoders out of every run.+fn register_hardware_decoders() -> filmcraft_platform::Availability {+ let hardware = filmcraft_platform::register();+ log::info!("hardware decoding: {hardware:?}");+ hardware+}+/// Local UTC offset at a unix time (auto-save file names and recovery times use local time).fn local_offset(unix: i64) -> i32 {chrono::Local.timestamp_opt(unix, 0).single().map(|d| d.offset().local_minus_utc()).unwrap_or(0)@@ -243,3 +252,15 @@ fn agent_event_loop(agent: bool) -> Option<eframe::EventLoopBuilderHook> {let _ = agent;None}++#[cfg(test)]+mod tests {+ /// Start-up registers the hardware decoders whether or not anything is logged (no logger is+ /// installed here, as in a normal run).+ #[test]+ fn startup_registers_the_hardware_decoders_without_a_logger() {+ assert!(!log::log_enabled!(log::Level::Info));+ let hardware = super::register_hardware_decoders();+ assert_eq!(filmcraft_platform::registered(), cfg!(target_os = "macos"), "{hardware:?}");+ }+}diff --git a/crates/codecs/src/lib.rs b/crates/codecs/src/lib.rsindex bd9710daf..d1598de75 100644--- a/crates/codecs/src/lib.rs+++ b/crates/codecs/src/lib.rs@@ -89,6 +89,11 @@ pub fn register_video_decoder(f: VideoDecoderFactory) {}}+/// Whether `f` is among the registered video decoder factories (startup diagnostics, tests).+pub fn video_decoder_registered(f: VideoDecoderFactory) -> bool {+ factories().read().unwrap_or_else(|e| e.into_inner()).iter().any(|x| std::ptr::fn_addr_eq(*x, f))+}+/// Create a decoder for a sample entry.pub fn make_video_decoder(entry: &filmcraft_isobmff::SampleEntry) -> Result<Box<dyn VideoDecoder>> {let g = factories().read().unwrap_or_else(|e| e.into_inner());diff --git a/crates/platform/src/lib.rs b/crates/platform/src/lib.rsindex 4e73ec5f9..5a2a68026 100644--- a/crates/platform/src/lib.rs+++ b/crates/platform/src/lib.rs@@ -53,6 +53,18 @@ pub fn register() -> Availability {}}+/// Whether [`register`] has put a hardware decoder factory in front of our decoders.+pub fn registered() -> bool {+ #[cfg(target_os = "macos")]+ {+ filmcraft_codecs::video_decoder_registered(videotoolbox_factory)+ }+ #[cfg(not(target_os = "macos"))]+ {+ false+ }+}+/// Whether this system's hardware decoder takes the stream of `entry` (whatever the Hardware/// decoding setting says): diagnostics and tests.pub fn hardware_decoder_for(entry: &filmcraft_isobmff::SampleEntry) -> bool {