Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

clippy

Richie McIlroy774596a01462
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index ecccce3df..b9fd0d031 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -795,7 +795,7 @@ impl ShowCapWindow {
"InProgressRecording window.show() result: {:?}",
show_result
);
- let _ = window.set_focus();
+ window.set_focus().ok();
fake_window::spawn_fake_window_listener(app.clone(), window.clone());
}
diff --git a/crates/recording/src/output_pipeline/win_segmented_camera.rs b/crates/recording/src/output_pipeline/win_segmented_camera.rs
index 7b0fd44b4..334a540d9 100644
--- a/crates/recording/src/output_pipeline/win_segmented_camera.rs
+++ b/crates/recording/src/output_pipeline/win_segmented_camera.rs
@@ -271,10 +271,15 @@ impl WindowsSegmentedCameraMuxer {
};
let manifest_path = self.base_path.join("manifest.json");
- let _ = std::fs::write(
- manifest_path,
+ if let Err(e) = std::fs::write(
+ &manifest_path,
serde_json::to_string_pretty(&manifest).unwrap_or_default(),
- );
+ ) {
+ warn!(
+ "Failed to write final manifest to {}: {e}",
+ manifest_path.display()
+ );
+ }
}
fn create_segment(&mut self, first_frame: &NativeCameraFrame) -> anyhow::Result<()> {
@@ -409,10 +414,14 @@ impl WindowsSegmentedCameraMuxer {
},
|output_sample| {
let mut output = output_clone.lock().unwrap();
- let _ = muxer
+ muxer
.write_sample(&output_sample, &mut output)
- .map_err(|e| format!("WriteSample: {e}"));
- Ok(())
+ .map_err(|e| {
+ windows::core::Error::new(
+ windows::core::HRESULT(-1),
+ format!("WriteSample: {e}"),
+ )
+ })
},
)
.context("run camera encoder for segment")
@@ -449,7 +458,12 @@ impl WindowsSegmentedCameraMuxer {
let start = std::time::Instant::now();
loop {
if handle.is_finished() {
- let _ = handle.join();
+ if let Err(panic_payload) = handle.join() {
+ warn!(
+ "Camera encoder thread panicked during rotation: {:?}",
+ panic_payload
+ );
+ }
break;
}
if start.elapsed() > timeout {
diff --git a/crates/rendering/src/cpu_yuv.rs b/crates/rendering/src/cpu_yuv.rs
index 95d7461f0..df278ce8d 100644
--- a/crates/rendering/src/cpu_yuv.rs
+++ b/crates/rendering/src/cpu_yuv.rs
@@ -116,6 +116,57 @@ pub fn nv12_to_rgba_simd(
let y_stride_usize = y_stride as usize;
let uv_stride_usize = uv_stride as usize;
+ if width_usize == 0 || height_usize == 0 {
+ return;
+ }
+
+ let y_required = (height_usize - 1)
+ .saturating_mul(y_stride_usize)
+ .saturating_add(width_usize);
+
+ let uv_height = height_usize.div_ceil(2);
+ let uv_width_bytes = width_usize.div_ceil(2) * 2;
+ let uv_required = uv_height
+ .saturating_sub(1)
+ .saturating_mul(uv_stride_usize)
+ .saturating_add(uv_width_bytes);
+
+ let output_required = width_usize.saturating_mul(height_usize).saturating_mul(4);
+
+ let strides_valid = y_stride_usize >= width_usize && uv_stride_usize >= uv_width_bytes;
+
+ if !strides_valid
+ || y_data.len() < y_required
+ || uv_data.len() < uv_required
+ || output.len() < output_required
+ {
+ return nv12_to_rgba(y_data, uv_data, width, height, y_stride, uv_stride, output);
+ }
+
+ debug_assert!(
+ y_stride_usize >= width_usize,
+ "Y stride ({y_stride_usize}) must be >= width ({width_usize})"
+ );
+ debug_assert!(
+ uv_stride_usize >= uv_width_bytes,
+ "UV stride ({uv_stride_usize}) must be >= UV width bytes ({uv_width_bytes})"
+ );
+ debug_assert!(
+ y_data.len() >= y_required,
+ "Y buffer too small: {} < {y_required}",
+ y_data.len()
+ );
+ debug_assert!(
+ uv_data.len() >= uv_required,
+ "UV buffer too small: {} < {uv_required}",
+ uv_data.len()
+ );
+ debug_assert!(
+ output.len() >= output_required,
+ "Output buffer too small: {} < {output_required}",
+ output.len()
+ );
+
let simd_width = (width_usize / 8) * 8;
unsafe {
@@ -258,6 +309,65 @@ pub fn yuv420p_to_rgba_simd(
let y_stride_usize = y_stride as usize;
let uv_stride_usize = uv_stride as usize;
+ if width_usize == 0 || height_usize == 0 {
+ return;
+ }
+
+ let y_required = (height_usize - 1)
+ .saturating_mul(y_stride_usize)
+ .saturating_add(width_usize);
+
+ let uv_height = height_usize.div_ceil(2);
+ let uv_width = width_usize.div_ceil(2);
+ let uv_required = uv_height
+ .saturating_sub(1)
+ .saturating_mul(uv_stride_usize)
+ .saturating_add(uv_width);
+
+ let output_required = width_usize.saturating_mul(height_usize).saturating_mul(4);
+
+ let strides_valid = y_stride_usize >= width_usize && uv_stride_usize >= uv_width;
+
+ if !strides_valid
+ || y_data.len() < y_required
+ || u_data.len() < uv_required
+ || v_data.len() < uv_required
+ || output.len() < output_required
+ {
+ return yuv420p_to_rgba(
+ y_data, u_data, v_data, width, height, y_stride, uv_stride, output,
+ );
+ }
+
+ debug_assert!(
+ y_stride_usize >= width_usize,
+ "Y stride ({y_stride_usize}) must be >= width ({width_usize})"
+ );
+ debug_assert!(
+ uv_stride_usize >= uv_width,
+ "UV stride ({uv_stride_usize}) must be >= UV width ({uv_width})"
+ );
+ debug_assert!(
+ y_data.len() >= y_required,
+ "Y buffer too small: {} < {y_required}",
+ y_data.len()
+ );
+ debug_assert!(
+ u_data.len() >= uv_required,
+ "U buffer too small: {} < {uv_required}",
+ u_data.len()
+ );
+ debug_assert!(
+ v_data.len() >= uv_required,
+ "V buffer too small: {} < {uv_required}",
+ v_data.len()
+ );
+ debug_assert!(
+ output.len() >= output_required,
+ "Output buffer too small: {} < {output_required}",
+ output.len()
+ );
+
let simd_width = (width_usize / 8) * 8;
unsafe {
@@ -286,8 +396,8 @@ pub fn yuv420p_to_rgba_simd(
let y16 = _mm_unpacklo_epi8(y8, zero);
let y_adj = _mm_sub_epi16(y16, c16);
- let u4 = _mm_set_epi32(0, 0, 0, *(u_ptr as *const i32));
- let v4 = _mm_set_epi32(0, 0, 0, *(v_ptr as *const i32));
+ let u4 = _mm_cvtsi32_si128(std::ptr::read_unaligned(u_ptr as *const i32));
+ let v4 = _mm_cvtsi32_si128(std::ptr::read_unaligned(v_ptr as *const i32));
let u_dup = _mm_unpacklo_epi8(u4, u4);
let v_dup = _mm_unpacklo_epi8(v4, v4);
diff --git a/crates/rendering/src/yuv_converter.rs b/crates/rendering/src/yuv_converter.rs
index f97841158..f26f4d580 100644
--- a/crates/rendering/src/yuv_converter.rs
+++ b/crates/rendering/src/yuv_converter.rs
@@ -692,7 +692,9 @@ impl YuvToRgbaConverter {
self.d3d11_staging_height = height;
}
- let staging_texture = self.d3d11_staging_texture.as_ref().unwrap();
+ let staging_texture = self.d3d11_staging_texture.as_ref().ok_or_else(|| {
+ YuvConversionError::D3D11Error("D3D11 staging texture not initialized".to_string())
+ })?;
unsafe {
d3d11_context.CopyResource(staging_texture, nv12_texture);