Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
test(verify): cover turbo export seams, fallback and cancellation
Richie McIlroy3032bdeb9eb1
diff --git a/crates/verify/tests/common/mod.rs b/crates/verify/tests/common/mod.rsindex 78b5c7666..85ca09d7a 100644--- a/crates/verify/tests/common/mod.rs+++ b/crates/verify/tests/common/mod.rs@@ -133,6 +133,12 @@ pub fn add_transition(config: &mut ProjectConfiguration, segment_index: u32, dur#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub enum Format {Mp4,+ /// MP4 through the turbo export split into `chunks`. With a failing+ /// chunk, the export has to fall back to the standard pipeline.+ Mp4Turbo {+ chunks: usize,+ failing_chunk: Option<usize>,+ },Gif,Mov,}@@ -279,6 +285,42 @@ pub async fn export(out: &Path,) -> Result<PathBuf, String> {let force = run.decoder == Decoder::Ffmpeg;+ let resolution_base = XY::new(run.resolution.0, run.resolution.1);+ if let Format::Mp4Turbo {+ chunks,+ failing_chunk,+ } = run.format+ {+ let mut base = cap_export::ExporterBase::builder(project.path.clone())+ .with_config(config)+ .with_force_ffmpeg_decoder(force)+ .with_output_path(out.to_path_buf())+ .build_for_mp4(std::sync::Arc::new(std::sync::atomic::AtomicBool::new(+ false,+ )))+ .await+ .map_err(|e| format!("exporter build: {e}"))?;+ if let Some(chunk) = failing_chunk {+ base.fail_turbo_chunk(chunk);+ }+ return cap_export::mp4::Mp4ExportSettings {+ fps: run.fps,+ resolution_base,+ compression: cap_export::mp4::ExportCompression::Social,+ custom_bpp: run.custom_bpp,+ force_ffmpeg_decoder: force,+ optimize_filesize: false,+ }+ .export_prepared_turbo(+ base,+ cap_export::mp4::turbo::TurboOptions {+ chunks: Some(chunks),+ strict: failing_chunk.is_none(),+ },+ |_| true,+ )+ .await;+ }let base = cap_export::ExporterBase::builder(project.path.clone()).with_config(config).with_force_ffmpeg_decoder(force)@@ -286,9 +328,8 @@ pub async fn export(.build().await.map_err(|e| format!("exporter build: {e}"))?;- let resolution_base = XY::new(run.resolution.0, run.resolution.1);match run.format {- Format::Mp4 => {+ Format::Mp4 | Format::Mp4Turbo { .. } => {cap_export::mp4::Mp4ExportSettings {fps: run.fps,resolution_base,diff --git a/crates/verify/tests/export.rs b/crates/verify/tests/export.rsindex a06af620f..79d13b636 100644--- a/crates/verify/tests/export.rs+++ b/crates/verify/tests/export.rs@@ -21,6 +21,11 @@ fn no_edit(_: &mut ProjectConfiguration) {}fn case_id(fixture: &str, edit: &str, format: Format, fps: u32, decoder: Decoder) -> String {let format = match format {Format::Mp4 => "mp4",+ Format::Mp4Turbo {+ failing_chunk: None,+ ..+ } => "mp4-turbo",+ Format::Mp4Turbo { .. } => "mp4-turbo-fallback",Format::Gif => "gif",Format::Mov => "mov",};@@ -75,7 +80,7 @@ fn run_project(let ext = match format {Format::Gif => "gif",Format::Mov => "mov",- Format::Mp4 => "mp4",+ Format::Mp4 | Format::Mp4Turbo { .. } => "mp4",};let run = ExportRun {custom_bpp: None,@@ -104,7 +109,7 @@ fn run_project(&frames,&path,fps,- format == Format::Mp4,+ matches!(format, Format::Mp4 | Format::Mp4Turbo { .. }),);if determinism {let second = dir.path().join(format!("b.{ext}"));@@ -268,6 +273,171 @@ fn basic() {common::assert_passed(failures);}+/// The turbo export split into three chunks, so chunk seams land inside+/// cuts, speed changes, transitions, scene changes and held frames.+#[test]+fn turbo() {+ let turbo = Format::Mp4Turbo {+ chunks: 3,+ failing_chunk: None,+ };+ let fallback = Format::Mp4Turbo {+ chunks: 3,+ failing_chunk: Some(2),+ };+ let mut failures: Vec<String> = Vec::new();+ failures.extend(run(+ catalog::basic(report::tier()),+ &[+ Variant {+ edit: "full",+ apply: no_edit,+ },+ Variant {+ edit: "cuts-speeds-reorder",+ apply: cuts_speeds_reorder,+ },+ Variant {+ edit: "transition",+ apply: transition,+ },+ Variant {+ edit: "hide-camera-scene",+ apply: hide_camera_scene,+ },+ ],+ &[(turbo, 30), (turbo, 60)],+ &Decoder::all(),+ RES,+ false,+ ));+ failures.extend(run(+ catalog::vfr_holds(report::tier()),+ &[Variant {+ edit: "full",+ apply: no_edit,+ }],+ &[(turbo, 60)],+ &Decoder::all(),+ RES,+ false,+ ));+ failures.extend(run(+ catalog::basic(report::tier()),+ &[Variant {+ edit: "cuts-speeds-reorder",+ apply: cuts_speeds_reorder,+ }],+ &[(fallback, 30)],+ &[Decoder::Default],+ RES,+ false,+ ));+ failures.extend(turbo_cancellation());+ common::assert_passed(failures);+}++fn turbo_spool_files() -> Vec<std::path::PathBuf> {+ std::fs::read_dir(std::env::temp_dir())+ .map(|entries| {+ entries+ .flatten()+ .map(|entry| entry.path())+ .filter(|path| {+ path.file_name()+ .and_then(|name| name.to_str())+ .is_some_and(|name| name.starts_with("cap-turbo-"))+ })+ .collect()+ })+ .unwrap_or_default()+}++/// Stopping a turbo export from the progress callback or the user's cancel+/// flag ends every chunk, leaves no output and removes the chunk spools.+fn turbo_cancellation() -> Vec<String> {+ use std::sync::{+ Arc,+ atomic::{AtomicBool, Ordering},+ };+ let spec = catalog::vfr_holds(report::tier());+ let mut failures = Vec::new();+ for by_flag in [false, true] {+ let id = format!(+ "export/{}/turbo-cancel-{}",+ spec.name,+ if by_flag { "flag" } else { "progress" }+ );+ if !report::selected(&id) {+ continue;+ }+ let project = common::project(&spec);+ let Some(mut case) = common::begin(&id, &project, Decoder::Default) else {+ continue;+ };+ let dir = common::scratch_dir(&id);+ let out = dir.path().join("cancelled.mp4");+ let spools_before = turbo_spool_files();+ let cancel = Arc::new(AtomicBool::new(false));+ let flag = cancel.clone();+ let result = common::runtime().block_on(async {+ let base = cap_export::ExporterBase::builder(project.path.clone())+ .with_config(project.config())+ .with_output_path(out.clone())+ .build_for_mp4(cancel)+ .await+ .map_err(|e| format!("exporter build: {e}"))?;+ cap_export::mp4::Mp4ExportSettings {+ fps: 60,+ resolution_base: XY::new(RES.0, RES.1),+ compression: cap_export::mp4::ExportCompression::Social,+ custom_bpp: None,+ force_ffmpeg_decoder: false,+ optimize_filesize: false,+ }+ .export_prepared_turbo(+ base,+ cap_export::mp4::turbo::TurboOptions {+ chunks: Some(3),+ strict: true,+ },+ move |frame| {+ if frame < 60 {+ return true;+ }+ if by_flag {+ flag.store(true, Ordering::Relaxed);+ true+ } else {+ false+ }+ },+ )+ .await+ });+ if result.as_ref().map_err(String::as_str) != Err("Export cancelled") {+ case.problem("error", format!("cancelled export returned {result:?}"));+ }+ if out.exists() {+ case.problem("error", "cancelled export left an output file");+ }+ let leftover: Vec<_> = turbo_spool_files()+ .into_iter()+ .filter(|path| !spools_before.contains(path))+ .collect();+ if !leftover.is_empty() {+ case.problem(+ "error",+ format!("cancelled export left spools {leftover:?}"),+ );+ }+ if let Err(message) = report::settle(case) {+ failures.push(message);+ }+ }+ failures+}+#[test]fn gif() {let mut failures: Vec<String> = Vec::new();diff --git a/scripts/verify/suites.json b/scripts/verify/suites.jsonindex 8283185d0..18cae0eaf 100644--- a/scripts/verify/suites.json+++ b/scripts/verify/suites.json@@ -29,6 +29,7 @@"macos": ["export/*/ffmpeg", "export/backward-hold/*/mp430/*"],"windows": ["export/*/mp460/*",+ "export/*/mp4-turbo60/*","export/backward-hold/*","export/jitter-camera-*","export/*/uhd-*"