Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Refactor Windows-specific code and improve error handling

Richie McIlroye0fae9477199
diff --git a/crates/recording/src/capture_pipeline.rs b/crates/recording/src/capture_pipeline.rs
index da50e958e..c308820f7 100644
--- a/crates/recording/src/capture_pipeline.rs
+++ b/crates/recording/src/capture_pipeline.rs
@@ -22,6 +22,13 @@ pub struct EncoderPreferences {
force_software: Arc<AtomicBool>,
}
+#[cfg(windows)]
+impl Default for EncoderPreferences {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
#[cfg(windows)]
impl EncoderPreferences {
pub fn new() -> Self {
diff --git a/crates/recording/src/cursor.rs b/crates/recording/src/cursor.rs
index 7ec86e56d..0f303730d 100644
--- a/crates/recording/src/cursor.rs
+++ b/crates/recording/src/cursor.rs
@@ -3,7 +3,11 @@ use cap_cursor_info::CursorShape;
use cap_project::{CursorClickEvent, CursorEvents, CursorMoveEvent, XY};
use cap_timestamp::Timestamps;
use futures::{FutureExt, future::Shared};
-use std::{collections::HashMap, path::PathBuf, time::Instant};
+use std::{
+ collections::HashMap,
+ path::{Path, PathBuf},
+ time::Instant,
+};
use tokio::sync::oneshot;
use tokio_util::sync::{CancellationToken, DropGuard};
@@ -39,17 +43,19 @@ impl CursorActor {
const CURSOR_FLUSH_INTERVAL_SECS: u64 = 5;
-fn flush_cursor_data(
- output_path: &PathBuf,
- moves: &[CursorMoveEvent],
- clicks: &[CursorClickEvent],
-) {
+fn flush_cursor_data(output_path: &Path, moves: &[CursorMoveEvent], clicks: &[CursorClickEvent]) {
let events = CursorEvents {
clicks: clicks.to_vec(),
moves: moves.to_vec(),
};
if let Ok(json) = serde_json::to_string_pretty(&events) {
- let _ = std::fs::write(output_path, json);
+ if let Err(e) = std::fs::write(output_path, json) {
+ tracing::error!(
+ "Failed to write cursor data to {}: {}",
+ output_path.display(),
+ e
+ );
+ }
}
}
diff --git a/crates/recording/src/feeds/camera.rs b/crates/recording/src/feeds/camera.rs
index 44cdaa5dc..b652c09af 100644
--- a/crates/recording/src/feeds/camera.rs
+++ b/crates/recording/src/feeds/camera.rs
@@ -565,7 +565,7 @@ async fn setup_camera(
if let Ok(buffer) = unsafe { MFCreateMemoryBuffer(data_len as u32) } {
let buffer_ready = {
if let Ok(mut lock) = buffer.lock() {
- lock.copy_from_slice(&*bytes);
+ lock.copy_from_slice(&bytes);
true
} else {
false
diff --git a/crates/recording/src/output_pipeline/win.rs b/crates/recording/src/output_pipeline/win.rs
index b30cac3c8..c06076bfe 100644
--- a/crates/recording/src/output_pipeline/win.rs
+++ b/crates/recording/src/output_pipeline/win.rs
@@ -169,7 +169,7 @@ impl Muxer for WindowsMuxer {
cap_enc_ffmpeg::h264::H264Encoder::builder(video_config)
.with_output_size(fallback_width, fallback_height)
- .and_then(|builder| builder.build(&mut *output_guard))
+ .and_then(|builder| builder.build(&mut output_guard))
.map(either::Right)
.map_err(|e| anyhow!("ScreenSoftwareEncoder/{e}"))
};
@@ -219,7 +219,7 @@ impl Muxer for WindowsMuxer {
};
cap_mediafoundation_ffmpeg::H264StreamMuxer::new(
- &mut *output_guard,
+ &mut output_guard,
cap_mediafoundation_ffmpeg::MuxerConfig {
width,
height,
@@ -548,7 +548,7 @@ impl Muxer for WindowsCameraMuxer {
};
cap_mediafoundation_ffmpeg::H264StreamMuxer::new(
- &mut *output_guard,
+ &mut output_guard,
cap_mediafoundation_ffmpeg::MuxerConfig {
width: output_width,
height: output_height,
@@ -625,7 +625,7 @@ impl Muxer for WindowsCameraMuxer {
return Ok(None);
};
frame_count += 1;
- if frame_count % 30 == 0 {
+ if frame_count.is_multiple_of(30) {
debug!(
"Windows camera encoder: processed {} frames",
frame_count
@@ -639,7 +639,7 @@ impl Muxer for WindowsCameraMuxer {
|output_sample| {
let mut output = output.lock().unwrap();
let _ = muxer
- .write_sample(&output_sample, &mut *output)
+ .write_sample(&output_sample, &mut output)
.map_err(|e| format!("WriteSample: {e}"));
Ok(())
},
diff --git a/crates/recording/src/screenshot.rs b/crates/recording/src/screenshot.rs
index 21754e4ae..f711f5eaa 100644
--- a/crates/recording/src/screenshot.rs
+++ b/crates/recording/src/screenshot.rs
@@ -369,7 +369,7 @@ fn capture_bitmap_with(
let mut data = std::ptr::null_mut();
let bitmap =
- unsafe { CreateDIBSection(Some(mem_dc), &mut info, DIB_RGB_COLORS, &mut data, None, 0) };
+ unsafe { CreateDIBSection(Some(mem_dc), &info, DIB_RGB_COLORS, &mut data, None, 0) };
let bitmap = match bitmap {
Ok(b) if !b.0.is_null() && !data.is_null() => b,
_ => {