Skip to content

Commit

Permalink
Merge branch 'main' into omar/cap-179-add-support-for-custom-s3-servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Jan 31, 2025
2 parents b229ac5 + 265ed8b commit f4794bd
Show file tree
Hide file tree
Showing 41 changed files with 1,208 additions and 953 deletions.
12 changes: 10 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ anyhow = "1.0.86"
# This includes a currently-unreleased fix that ensures the audio stream is actually
# stopped and released on drop on macOS
cpal = { git = "https://github.com/RustAudio/cpal", rev = "f43d36e55494993bbbde3299af0c53e5cdf4d4cf" }
ffmpeg = { package = "ffmpeg-next", git = "https://github.com/CapSoftware/rust-ffmpeg", rev = "91b29d09a8c7cb4f5659c38f1f0924b980a30cba" }
ffmpeg = { package = "ffmpeg-next", git = "https://github.com/CapSoftware/rust-ffmpeg", rev = "29433c248bcd" }
ffmpeg-sys-next = "7.1.0"
tokio = { version = "1.39.3", features = [
"macros",
Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Export {
.unwrap(),
);

let segments = create_segments(&meta);
let segments = create_segments(&meta).await.unwrap();

let fps = meta.content.max_fps();
let project_output_path = self.project_path.join("output/result.mp4");
Expand All @@ -180,6 +180,7 @@ impl Export {
XY::new(1920, 1080),
true,
)
.await
.unwrap();

exporter.export_with_custom_muxer().await.unwrap();
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@solidjs/start": "^1.0.6",
"@tanstack/solid-query": "^5.51.21",
"@tauri-apps/api": "^2.1.1",
"@tauri-apps/plugin-clipboard-manager": "^2.2.1",
"@tauri-apps/plugin-deep-link": "^2.2.0",
"@tauri-apps/plugin-dialog": "2.0.1",
"@tauri-apps/plugin-fs": "2.0.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/scripts/stripDebugSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function main() {
await exec(
`dsymutil "${binaryPath}" -o "${path.join(targetDir, releaseFile)}.dSYM"`
);
await exec(`strip "${binaryPath}"`);
// await exec(`strip "${binaryPath}"`);
} else if (process.platform === "win32") {
// TODO
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cap-desktop"
version = "0.3.16"
version = "0.3.18"
description = "Beautiful screen recordings, owned by you."
authors = ["you"]
edition = "2021"
Expand Down
5 changes: 3 additions & 2 deletions apps/desktop/src-tauri/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub async fn export_video(
.unwrap_or(screen_metadata.duration),
);

let editor_instance = upsert_editor_instance(&app, video_id.clone()).await;
let editor_instance = upsert_editor_instance(&app, video_id.clone()).await?;
let total_frames = editor_instance.get_total_frames(fps);

let output_path = editor_instance.meta().output_path();
Expand Down Expand Up @@ -94,6 +94,7 @@ pub async fn export_video(
resolution_base,
is_upgraded,
)
.await
.map_err(|e| {
sentry::capture_message(&e.to_string(), sentry::Level::Error);
e.to_string()
Expand Down Expand Up @@ -136,7 +137,7 @@ pub async fn get_export_estimates(
.await
.ok();

let editor_instance = upsert_editor_instance(&app, video_id.clone()).await;
let editor_instance = upsert_editor_instance(&app, video_id.clone()).await?;
let total_frames = editor_instance.get_total_frames(fps);

let raw_duration = screen_metadata.duration.max(
Expand Down
69 changes: 49 additions & 20 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ async fn create_thumbnail(input: PathBuf, output: PathBuf, size: (u32, u32)) ->
}

async fn get_rendered_video_path(app: AppHandle, video_id: String) -> Result<PathBuf, String> {
let editor_instance = upsert_editor_instance(&app, video_id.clone()).await;
let editor_instance = upsert_editor_instance(&app, video_id.clone()).await?;
let output_path = editor_instance.meta().output_path();

// If the file doesn't exist, return an error to trigger the progress-enabled path
Expand Down Expand Up @@ -877,9 +877,14 @@ impl EditorStateChanged {

#[tauri::command]
#[specta::specta]
async fn start_playback(app: AppHandle, video_id: String, fps: u32, resolution_base: XY<u32>) {
async fn start_playback(
app: AppHandle,
video_id: String,
fps: u32,
resolution_base: XY<u32>,
) -> Result<(), String> {
upsert_editor_instance(&app, video_id)
.await
.await?
.start_playback(
fps,
resolution_base,
Expand All @@ -889,19 +894,23 @@ async fn start_playback(app: AppHandle, video_id: String, fps: u32, resolution_b
.map(|s| s.is_upgraded())
.unwrap_or(false),
)
.await
.await;

Ok(())
}

#[tauri::command]
#[specta::specta]
async fn stop_playback(app: AppHandle, video_id: String) {
let editor_instance = upsert_editor_instance(&app, video_id).await;
async fn stop_playback(app: AppHandle, video_id: String) -> Result<(), String> {
let editor_instance = upsert_editor_instance(&app, video_id).await?;

let mut state = editor_instance.state.lock().await;

if let Some(handle) = state.playback_task.take() {
handle.stop();
}

Ok(())
}

#[derive(Serialize, Type, Debug)]
Expand All @@ -921,7 +930,7 @@ async fn create_editor_instance(
app: AppHandle,
video_id: String,
) -> Result<SerializedEditorInstance, String> {
let editor_instance = upsert_editor_instance(&app, video_id).await;
let editor_instance = upsert_editor_instance(&app, video_id).await?;

// Load the RecordingMeta to get the pretty name
let meta = RecordingMeta::load_for_project(&editor_instance.project_path)
Expand Down Expand Up @@ -1113,24 +1122,36 @@ pub enum RenderProgress {

#[tauri::command]
#[specta::specta]
async fn set_playhead_position(app: AppHandle, video_id: String, frame_number: u32) {
let editor_instance = upsert_editor_instance(&app, video_id).await;
async fn set_playhead_position(
app: AppHandle,
video_id: String,
frame_number: u32,
) -> Result<(), String> {
let editor_instance = upsert_editor_instance(&app, video_id).await?;

editor_instance
.modify_and_emit_state(|state| {
state.playhead_position = frame_number;
})
.await;

Ok(())
}

#[tauri::command]
#[specta::specta]
async fn set_project_config(app: AppHandle, video_id: String, config: ProjectConfiguration) {
let editor_instance = upsert_editor_instance(&app, video_id).await;
async fn set_project_config(
app: AppHandle,
video_id: String,
config: ProjectConfiguration,
) -> Result<(), String> {
let editor_instance = upsert_editor_instance(&app, video_id).await?;

config.write(&editor_instance.project_path).unwrap();

editor_instance.project_config.0.send(config).ok();

Ok(())
}

#[tauri::command]
Expand Down Expand Up @@ -1868,14 +1889,16 @@ async fn is_camera_window_open(app: AppHandle) -> bool {

#[tauri::command]
#[specta::specta]
async fn seek_to(app: AppHandle, video_id: String, frame_number: u32) {
let editor_instance = upsert_editor_instance(&app, video_id).await;
async fn seek_to(app: AppHandle, video_id: String, frame_number: u32) -> Result<(), String> {
let editor_instance = upsert_editor_instance(&app, video_id).await?;

editor_instance
.modify_and_emit_state(|state| {
state.playhead_position = frame_number;
})
.await;

Ok(())
}

// keep this async otherwise opening windows may hang on windows
Expand Down Expand Up @@ -2356,7 +2379,10 @@ pub async fn remove_editor_instance(
}
}

pub async fn upsert_editor_instance(app: &AppHandle, video_id: String) -> Arc<EditorInstance> {
pub async fn upsert_editor_instance(
app: &AppHandle,
video_id: String,
) -> Result<Arc<EditorInstance>, String> {
let map = match app.try_state::<EditorInstancesState>() {
Some(s) => (*s).clone(),
None => {
Expand All @@ -2369,17 +2395,20 @@ pub async fn upsert_editor_instance(app: &AppHandle, video_id: String) -> Arc<Ed
let mut map = map.lock().await;

use std::collections::hash_map::Entry;
match map.entry(video_id.clone()) {
Ok(match map.entry(video_id.clone()) {
Entry::Occupied(o) => o.get().clone(),
Entry::Vacant(v) => {
let instance = create_editor_instance_impl(app, video_id).await;
let instance = create_editor_instance_impl(app, video_id).await?;
v.insert(instance.clone());
instance
}
}
})
}

async fn create_editor_instance_impl(app: &AppHandle, video_id: String) -> Arc<EditorInstance> {
async fn create_editor_instance_impl(
app: &AppHandle,
video_id: String,
) -> Result<Arc<EditorInstance>, String> {
let app = app.clone();

let instance = EditorInstance::new(
Expand All @@ -2402,7 +2431,7 @@ async fn create_editor_instance_impl(app: &AppHandle, video_id: String) -> Arc<E
}
},
)
.await;
.await?;

RenderFrameEvent::listen_any(&app, {
let preview_tx = instance.preview_tx.clone();
Expand All @@ -2417,7 +2446,7 @@ async fn create_editor_instance_impl(app: &AppHandle, video_id: String) -> Arc<E
}
});

instance
Ok(instance)
}

// use EditorInstance.project_path instead of this
Expand Down
Loading

0 comments on commit f4794bd

Please sign in to comment.