Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

coderabbit

Richie McIlroy5dd6696ce953
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index a223e0f72..552eae2a6 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -288,8 +288,12 @@ impl ShowCapWindow {
#[cfg(windows)]
{
use tauri::LogicalSize;
- let _ = window.set_size(LogicalSize::new(600.0, 600.0));
- let _ = window.center();
+ if let Err(e) = window.set_size(LogicalSize::new(600.0, 600.0)) {
+ warn!("Failed to set Setup window size on Windows: {}", e);
+ }
+ if let Err(e) = window.center() {
+ warn!("Failed to center Setup window on Windows: {}", e);
+ }
}
window
@@ -458,8 +462,12 @@ impl ShowCapWindow {
#[cfg(windows)]
{
use tauri::LogicalSize;
- let _ = window.set_size(LogicalSize::new(600.0, 465.0));
- let _ = window.center();
+ if let Err(e) = window.set_size(LogicalSize::new(600.0, 465.0)) {
+ warn!("Failed to set Settings window size on Windows: {}", e);
+ }
+ if let Err(e) = window.center() {
+ warn!("Failed to center Settings window on Windows: {}", e);
+ }
}
window
@@ -483,8 +491,12 @@ impl ShowCapWindow {
#[cfg(windows)]
{
use tauri::LogicalSize;
- let _ = window.set_size(LogicalSize::new(1275.0, 800.0));
- let _ = window.center();
+ if let Err(e) = window.set_size(LogicalSize::new(1275.0, 800.0)) {
+ warn!("Failed to set Editor window size on Windows: {}", e);
+ }
+ if let Err(e) = window.center() {
+ warn!("Failed to center Editor window on Windows: {}", e);
+ }
}
window
@@ -508,8 +520,15 @@ impl ShowCapWindow {
#[cfg(windows)]
{
use tauri::LogicalSize;
- let _ = window.set_size(LogicalSize::new(1240.0, 800.0));
- let _ = window.center();
+ if let Err(e) = window.set_size(LogicalSize::new(1240.0, 800.0)) {
+ warn!(
+ "Failed to set ScreenshotEditor window size on Windows: {}",
+ e
+ );
+ }
+ if let Err(e) = window.center() {
+ warn!("Failed to center ScreenshotEditor window on Windows: {}", e);
+ }
}
window
@@ -534,8 +553,12 @@ impl ShowCapWindow {
#[cfg(windows)]
{
use tauri::LogicalSize;
- let _ = window.set_size(LogicalSize::new(950.0, 850.0));
- let _ = window.center();
+ if let Err(e) = window.set_size(LogicalSize::new(950.0, 850.0)) {
+ warn!("Failed to set Upgrade window size on Windows: {}", e);
+ }
+ if let Err(e) = window.center() {
+ warn!("Failed to center Upgrade window on Windows: {}", e);
+ }
}
window
@@ -560,8 +583,12 @@ impl ShowCapWindow {
#[cfg(windows)]
{
use tauri::LogicalSize;
- let _ = window.set_size(LogicalSize::new(580.0, 340.0));
- let _ = window.center();
+ if let Err(e) = window.set_size(LogicalSize::new(580.0, 340.0)) {
+ warn!("Failed to set ModeSelect window size on Windows: {}", e);
+ }
+ if let Err(e) = window.center() {
+ warn!("Failed to center ModeSelect window on Windows: {}", e);
+ }
}
window
diff --git a/crates/enc-mediafoundation/src/video/hevc.rs b/crates/enc-mediafoundation/src/video/hevc.rs
index 2b4a72ec0..948f80abb 100644
--- a/crates/enc-mediafoundation/src/video/hevc.rs
+++ b/crates/enc-mediafoundation/src/video/hevc.rs
@@ -427,7 +427,10 @@ impl HevcEncoder {
}
}
_ => {
- panic!("Unknown media event type: {}", event_type.0);
+ eprintln!(
+ "[cap-enc-mediafoundation] Ignoring unknown media event type: {}",
+ event_type.0
+ );
}
}
}
diff --git a/crates/frame-converter/src/d3d11.rs b/crates/frame-converter/src/d3d11.rs
index 36e69371e..670d04cce 100644
--- a/crates/frame-converter/src/d3d11.rs
+++ b/crates/frame-converter/src/d3d11.rs
@@ -1147,12 +1147,16 @@ impl Drop for D3D11Resources {
unsafe {
if let Some(handle) = self.input_shared_handle.take() {
if !handle.is_invalid() {
- let _ = CloseHandle(handle);
+ if let Err(e) = CloseHandle(handle) {
+ tracing::error!("Failed to close input shared handle: {:?}", e);
+ }
}
}
if let Some(handle) = self.output_shared_handle.take() {
if !handle.is_invalid() {
- let _ = CloseHandle(handle);
+ if let Err(e) = CloseHandle(handle) {
+ tracing::error!("Failed to close output shared handle: {:?}", e);
+ }
}
}
}
diff --git a/crates/recording/examples/camera-benchmark.rs b/crates/recording/examples/camera-benchmark.rs
index 5ad07ad52..8d99d5a4e 100644
--- a/crates/recording/examples/camera-benchmark.rs
+++ b/crates/recording/examples/camera-benchmark.rs
@@ -292,12 +292,16 @@ async fn run_camera_encoding_benchmark(
let encode_start = Instant::now();
let timestamp = Duration::from_micros(converted.frame.pts().unwrap_or(0) as u64);
- if let Ok(()) =
- encoder.queue_preconverted_frame(converted.frame, timestamp, &mut output)
- {
- let encode_duration = encode_start.elapsed();
- let pipeline_latency = converted.submit_time.elapsed();
- metrics.record_frame_encoded(encode_duration, pipeline_latency);
+ match encoder.queue_preconverted_frame(converted.frame, timestamp, &mut output) {
+ Ok(()) => {
+ let encode_duration = encode_start.elapsed();
+ let pipeline_latency = converted.submit_time.elapsed();
+ metrics.record_frame_encoded(encode_duration, pipeline_latency);
+ }
+ Err(e) => {
+ warn!("Encode error during drain: {}", e);
+ metrics.record_dropped_output();
+ }
}
} else {
break;
diff --git a/crates/recording/src/output_pipeline/win.rs b/crates/recording/src/output_pipeline/win.rs
index 78d173ded..0bf6a0435 100644
--- a/crates/recording/src/output_pipeline/win.rs
+++ b/crates/recording/src/output_pipeline/win.rs
@@ -287,9 +287,9 @@ impl Muxer for WindowsMuxer {
|output_sample| {
let mut output = output.lock().unwrap();
- let _ = muxer
- .write_sample(&output_sample, &mut output)
- .map_err(|e| format!("WriteSample: {e}"));
+ if let Err(e) = muxer.write_sample(&output_sample, &mut output) {
+ tracing::error!("WriteSample failed: {e}");
+ }
Ok(())
},
@@ -707,9 +707,10 @@ impl Muxer for WindowsCameraMuxer {
},
|output_sample| {
let mut output = output.lock().unwrap();
- let _ = muxer
- .write_sample(&output_sample, &mut output)
- .map_err(|e| format!("WriteSample: {e}"));
+ if let Err(e) = muxer.write_sample(&output_sample, &mut output)
+ {
+ tracing::error!("Camera WriteSample failed: {e}");
+ }
Ok(())
},
);
diff --git a/crates/recording/src/output_pipeline/win_segmented.rs b/crates/recording/src/output_pipeline/win_segmented.rs
index c83e64b73..5c98f790a 100644
--- a/crates/recording/src/output_pipeline/win_segmented.rs
+++ b/crates/recording/src/output_pipeline/win_segmented.rs
@@ -520,11 +520,20 @@ impl WindowsSegmentedMuxer {
Ok(Some((frame.texture().clone(), frame_time)))
},
|output_sample| {
- let mut output = output_clone.lock().unwrap();
+ let mut output = match output_clone.lock() {
+ Ok(guard) => guard,
+ Err(e) => {
+ error!("Failed to lock output mutex: {e}");
+ return Err(windows::core::Error::new(
+ windows::core::HRESULT(0x80004005u32 as i32),
+ format!("Mutex poisoned: {e}"),
+ ));
+ }
+ };
- let _ = muxer
- .write_sample(&output_sample, &mut output)
- .map_err(|e| format!("WriteSample: {e}"));
+ if let Err(e) = muxer.write_sample(&output_sample, &mut output) {
+ warn!("WriteSample failed: {e}");
+ }
Ok(())
},
diff --git a/crates/recording/src/output_pipeline/win_segmented_camera.rs b/crates/recording/src/output_pipeline/win_segmented_camera.rs
index 36ec47c86..5fcae0747 100644
--- a/crates/recording/src/output_pipeline/win_segmented_camera.rs
+++ b/crates/recording/src/output_pipeline/win_segmented_camera.rs
@@ -587,6 +587,12 @@ impl WindowsSegmentedCameraMuxer {
}
}
+ if let Ok(mut output_guard) = output_clone.lock() {
+ if let Err(e) = encoder.flush(&mut output_guard) {
+ warn!("Failed to flush software encoder: {e}");
+ }
+ }
+
Ok(())
}
}
diff --git a/crates/recording/tests/hardware_compat.rs b/crates/recording/tests/hardware_compat.rs
index 6900012e6..53d7bdb72 100644
--- a/crates/recording/tests/hardware_compat.rs
+++ b/crates/recording/tests/hardware_compat.rs
@@ -738,10 +738,12 @@ fn test_hardware_compatibility_summary() {
}
fn truncate_string(s: &str, max_len: usize) -> String {
- if s.len() <= max_len {
+ if s.chars().count() <= max_len {
s.to_string()
} else {
- format!("{}...", &s[..max_len - 3])
+ let truncate_at = max_len.saturating_sub(3);
+ let truncated: String = s.chars().take(truncate_at).collect();
+ format!("{truncated}...")
}
}
diff --git a/crates/rendering/src/decoder/ffmpeg.rs b/crates/rendering/src/decoder/ffmpeg.rs
index 8504f14b8..961e4cec2 100644
--- a/crates/rendering/src/decoder/ffmpeg.rs
+++ b/crates/rendering/src/decoder/ffmpeg.rs
@@ -149,8 +149,12 @@ impl FfmpegDecoder {
std::thread::spawn(move || {
let hw_device_type = if cfg!(target_os = "macos") {
Some(AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX)
- } else {
+ } else if cfg!(target_os = "linux") {
+ Some(AVHWDeviceType::AV_HWDEVICE_TYPE_VAAPI)
+ } else if cfg!(target_os = "windows") {
Some(AVHWDeviceType::AV_HWDEVICE_TYPE_DXVA2)
+ } else {
+ None
};
let mut this = match cap_video_decode::FFmpegDecoder::new(path.clone(), hw_device_type)
diff --git a/crates/scap-ffmpeg/src/direct3d.rs b/crates/scap-ffmpeg/src/direct3d.rs
index 047e5d4e3..fcfdd34fa 100644
--- a/crates/scap-ffmpeg/src/direct3d.rs
+++ b/crates/scap-ffmpeg/src/direct3d.rs
@@ -12,8 +12,24 @@ fn copy_frame_data(
row_length: usize,
height: usize,
) {
+ debug_assert!(height > 0, "height must be positive");
+ debug_assert!(
+ src_bytes.len()
+ >= (height - 1)
+ .saturating_mul(src_stride)
+ .saturating_add(row_length),
+ "source buffer too small"
+ );
+ debug_assert!(
+ dest_bytes.len()
+ >= (height - 1)
+ .saturating_mul(dest_stride)
+ .saturating_add(row_length),
+ "destination buffer too small"
+ );
+
if src_stride == row_length && dest_stride == row_length {
- let total_bytes = row_length * height;
+ let total_bytes = row_length.saturating_mul(height);
unsafe {
std::ptr::copy_nonoverlapping(src_bytes.as_ptr(), dest_bytes.as_mut_ptr(), total_bytes);
}