Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(editor): sample zoom springs in playback and scrub paths

Richie McIlroy77e8325145ab
diff --git a/apps/cli/src/selftest/playback.rs b/apps/cli/src/selftest/playback.rs
index 44ec08293..6dd63c71e 100644
--- a/apps/cli/src/selftest/playback.rs
+++ b/apps/cli/src/selftest/playback.rs
@@ -392,9 +392,9 @@ async fn measure_playback(
let epoch = Instant::now();
let video_events: Arc<Mutex<Vec<(f64, f64)>>> = Arc::new(Mutex::new(Vec::new()));
- let frame_cb: Box<dyn FnMut(EditorFrameOutput) + Send> = Box::new({
+ let frame_cb: cap_editor::EditorFrameCallback = Box::new({
let video_events = video_events.clone();
- move |output| {
+ move |output, _layout| {
let now = Instant::now();
if let EditorFrameOutput::Rgba(frame) = output {
if let Some(luma) = mean_center_luma_rgba(
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs
index c09303784..3e9bdc945 100644
--- a/crates/editor/src/editor_instance.rs
+++ b/crates/editor/src/editor_instance.rs
@@ -8,8 +8,7 @@ use cap_project::{
};
use cap_rendering::{
ProjectRecordingsMeta, ProjectUniforms, RecordingSegmentDecoders, RenderVideoConstants,
- SegmentVideoPaths, SharedWgpuDevice, Video, ZoomFocusInterpolator, get_duration,
- spring_mass_damper::SpringMassDamperSimulationConfig,
+ SegmentVideoPaths, SharedWgpuDevice, Video, ZoomTransformTimeline, get_duration,
};
use std::{
path::{Path, PathBuf},
@@ -113,7 +112,7 @@ impl EditorInstance {
pub async fn new(
project_path: PathBuf,
on_state_change: impl Fn(&EditorState) + Send + Sync + 'static,
- frame_cb: Box<dyn FnMut(editor::EditorFrameOutput) + Send>,
+ frame_cb: editor::EditorFrameCallback,
shared_device: Option<SharedWgpuDevice>,
) -> Result<Arc<Self>, String> {
Self::new_with_audio_output(
@@ -132,7 +131,7 @@ impl EditorInstance {
pub async fn new_with_audio_output(
project_path: PathBuf,
on_state_change: impl Fn(&EditorState) + Send + Sync + 'static,
- frame_cb: Box<dyn FnMut(editor::EditorFrameOutput) + Send>,
+ frame_cb: editor::EditorFrameCallback,
shared_device: Option<SharedWgpuDevice>,
audio_output: Arc<crate::AudioOutput>,
) -> Result<Arc<Self>, String> {
@@ -612,22 +611,17 @@ impl EditorInstance {
.map(|t| t.duration())
.unwrap_or(0.0);
- let cursor_smoothing = (!project.cursor.raw).then_some(
- SpringMassDamperSimulationConfig {
- tension: project.cursor.tension,
- mass: project.cursor.mass,
- friction: project.cursor.friction,
- },
- );
-
- let zoom_focus_interpolator = ZoomFocusInterpolator::new_arc(
- segment_medias.cursor.clone(),
- cursor_smoothing,
- project.cursor.click_spring_config(),
- project.screen_movement_spring,
+ // Scrub renders sample the same precomputed spring
+ // timeline playback and export use (the old focus
+ // interpolator was never precomputed here and fell
+ // back to a divergent direct interpolation).
+ let mut zoom_timeline = ZoomTransformTimeline::from_project(
+ &project,
+ &segment_medias.cursor,
total_duration,
- project.timeline.as_ref().map(|t| t.zoom_segments.as_slice()).unwrap_or(&[]),
);
+ zoom_timeline
+ .ensure_precomputed_until((frame_number as f32 + 1.0) / fps as f32);
let mut next_segment_frames = segment_frames_opt;
let mut rendered = false;
@@ -646,7 +640,7 @@ impl EditorInstance {
&segment_medias.cursor,
&segment_frames,
total_duration,
- &zoom_focus_interpolator,
+ &zoom_timeline,
);
if self
diff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rs
index 18b8693f9..422f5899c 100644
--- a/crates/editor/src/playback.rs
+++ b/crates/editor/src/playback.rs
@@ -1,7 +1,7 @@
use cap_project::{ProjectConfiguration, XY};
use cap_rendering::{
DecodedSegmentFrames, PrecomputedCursorTimeline, ProjectUniforms, RenderVideoConstants,
- ZoomFocusInterpolator, spring_mass_damper::SpringMassDamperSimulationConfig,
+ ZoomTransformTimeline, spring_mass_damper::SpringMassDamperSimulationConfig,
};
use futures::stream::{FuturesUnordered, StreamExt};
use lru::LruCache;
@@ -576,40 +576,18 @@ impl Playback {
.collect()
};
- let build_zoom_interpolators =
- |project: &ProjectConfiguration,
- cursor_timelines: &[Arc<PrecomputedCursorTimeline>]|
- -> Vec<ZoomFocusInterpolator> {
+ let build_zoom_timelines =
+ |project: &ProjectConfiguration| -> Vec<ZoomTransformTimeline> {
self.segment_medias
.iter()
- .zip(cursor_timelines.iter())
- .map(|(seg, precomputed)| {
- let cursor_smoothing =
- (!project.cursor.raw).then_some(SpringMassDamperSimulationConfig {
- tension: project.cursor.tension,
- mass: project.cursor.mass,
- friction: project.cursor.friction,
- });
- ZoomFocusInterpolator::new_arc_with_precomputed_cursor(
- seg.cursor.clone(),
- cursor_smoothing,
- project.cursor.click_spring_config(),
- project.screen_movement_spring,
- duration,
- project
- .timeline
- .as_ref()
- .map(|t| t.zoom_segments.as_slice())
- .unwrap_or(&[]),
- Some(precomputed.clone()),
- )
+ .map(|seg| {
+ ZoomTransformTimeline::from_project(project, &seg.cursor, duration)
})
.collect()
};
let mut cursor_timelines = build_cursor_timelines(&cached_project);
- let mut zoom_interpolators =
- build_zoom_interpolators(&cached_project, &cursor_timelines);
+ let mut zoom_timelines = build_zoom_timelines(&cached_project);
if !*stop_rx.borrow()
&& let Some(prefetched_idx) = prefetch_buffer
@@ -625,24 +603,23 @@ impl Playback {
let segment_frames = Arc::new(prefetched.segment_frames);
let zoom_until = (frame_number as f32 + 1.0) / fps as f32;
- if let Some(interp) = zoom_interpolators.get_mut(segment_index as usize) {
- interp.ensure_precomputed_until(zoom_until);
+ if let Some(timeline) = zoom_timelines.get_mut(segment_index as usize) {
+ timeline.ensure_precomputed_until(zoom_until);
}
- let zoom_focus_interpolator = zoom_interpolators.get(segment_index as usize);
+ let zoom_timeline = zoom_timelines.get(segment_index as usize);
- let empty_interp;
- let zoom_ref = match zoom_focus_interpolator {
- Some(interp) => interp,
+ let empty_timeline;
+ let zoom_ref = match zoom_timeline {
+ Some(timeline) => timeline,
None => {
- empty_interp = ZoomFocusInterpolator::new_arc(
- segment_media.cursor.clone(),
+ empty_timeline = ZoomTransformTimeline::new(
+ &[],
None,
- cached_project.cursor.click_spring_config(),
+ &segment_media.cursor,
cached_project.screen_movement_spring,
duration,
- &[],
);
- &empty_interp
+ &empty_timeline
}
};
@@ -752,8 +729,7 @@ impl Playback {
if self.project.has_changed().unwrap_or(false) {
cached_project = self.project.borrow_and_update().clone();
cursor_timelines = build_cursor_timelines(&cached_project);
- zoom_interpolators =
- build_zoom_interpolators(&cached_project, &cursor_timelines);
+ zoom_timelines = build_zoom_timelines(&cached_project);
}
let frame_offset = frame_number.saturating_sub(self.start_frame_number) as f64;
@@ -1041,24 +1017,23 @@ impl Playback {
}
let zoom_until = (frame_number as f32 + 1.0) / fps as f32;
- if let Some(interp) = zoom_interpolators.get_mut(segment_index as usize) {
- interp.ensure_precomputed_until(zoom_until);
+ if let Some(timeline) = zoom_timelines.get_mut(segment_index as usize) {
+ timeline.ensure_precomputed_until(zoom_until);
}
- let zoom_focus_interpolator = zoom_interpolators.get(segment_index as usize);
+ let zoom_timeline = zoom_timelines.get(segment_index as usize);
- let empty_interp;
- let zoom_ref = match zoom_focus_interpolator {
- Some(interp) => interp,
+ let empty_timeline;
+ let zoom_ref = match zoom_timeline {
+ Some(timeline) => timeline,
None => {
- empty_interp = ZoomFocusInterpolator::new_arc(
- segment_media.cursor.clone(),
+ empty_timeline = ZoomTransformTimeline::new(
+ &[],
None,
- cached_project.cursor.click_spring_config(),
+ &segment_media.cursor,
cached_project.screen_movement_spring,
duration,
- &[],
);
- &empty_interp
+ &empty_timeline
}
};