Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

clippy

Richie McIlroy9e958e40147d
diff --git a/crates/recording/src/test_sources/config.rs b/crates/recording/src/test_sources/config.rs
index a96894b76..53d315001 100644
--- a/crates/recording/src/test_sources/config.rs
+++ b/crates/recording/src/test_sources/config.rs
@@ -128,23 +128,22 @@ impl VideoTestConfig {
}
}
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TestPattern {
SmpteColorBars,
ColorGradient,
+ #[default]
FrameCounter,
TimestampOverlay,
Checkerboard,
- SolidColor { r: u8, g: u8, b: u8 },
+ SolidColor {
+ r: u8,
+ g: u8,
+ b: u8,
+ },
Random,
}
-impl Default for TestPattern {
- fn default() -> Self {
- Self::FrameCounter
- }
-}
-
#[derive(Debug, Clone)]
pub struct AudioTestConfig {
pub sample_rate: u32,
diff --git a/crates/recording/src/test_sources/validation.rs b/crates/recording/src/test_sources/validation.rs
index 805608114..c3ecb45dd 100644
--- a/crates/recording/src/test_sources/validation.rs
+++ b/crates/recording/src/test_sources/validation.rs
@@ -176,31 +176,23 @@ impl RecordingValidator {
let tolerance_frames =
(result.expected_frames as f64 * self.config.frame_count_tolerance) as u64;
- let frame_diff = if result.actual_frames > result.expected_frames {
- result.actual_frames - result.expected_frames
- } else {
- result.expected_frames - result.actual_frames
- };
+ let frame_diff = result.actual_frames.abs_diff(result.expected_frames);
result.frame_count_ok = frame_diff <= tolerance_frames.max(2);
if result.actual_frames < result.expected_frames {
result.dropped_frames = result.expected_frames - result.actual_frames;
}
- let duration_diff = if result.actual_duration > self.expected_duration {
- result.actual_duration - self.expected_duration
- } else {
- self.expected_duration - result.actual_duration
- };
+ let duration_diff = result.actual_duration.abs_diff(self.expected_duration);
result.duration_ok = duration_diff <= self.config.duration_tolerance;
- if let Some(expected) = &self.expected_video_info {
- if video_info.width != expected.width || video_info.height != expected.height {
- result.errors.push(format!(
- "Resolution mismatch: expected {}x{}, got {}x{}",
- expected.width, expected.height, video_info.width, video_info.height
- ));
- }
+ if let Some(expected) = &self.expected_video_info
+ && (video_info.width != expected.width || video_info.height != expected.height)
+ {
+ result.errors.push(format!(
+ "Resolution mismatch: expected {}x{}, got {}x{}",
+ expected.width, expected.height, video_info.width, video_info.height
+ ));
}
} else if self.expected_video_info.is_some() {
result.errors.push("No video stream found".to_string());
@@ -208,11 +200,7 @@ impl RecordingValidator {
result.frame_count_ok = true;
result.actual_duration = probe.duration;
- let duration_diff = if result.actual_duration > self.expected_duration {
- result.actual_duration - self.expected_duration
- } else {
- self.expected_duration - result.actual_duration
- };
+ let duration_diff = result.actual_duration.abs_diff(self.expected_duration);
result.duration_ok = duration_diff <= self.config.duration_tolerance;
}
@@ -246,10 +234,10 @@ impl RecordingValidator {
for entry in entries {
let entry = entry?;
let path = entry.path();
- if let Some(ext) = path.extension() {
- if ext == "m4s" {
- fragments.push(path);
- }
+ if let Some(ext) = path.extension()
+ && ext == "m4s"
+ {
+ fragments.push(path);
}
}
@@ -258,10 +246,10 @@ impl RecordingValidator {
result.fragments_checked = fragments.len();
for fragment in &fragments {
- if let Ok(metadata) = std::fs::metadata(fragment) {
- if metadata.len() > 0 {
- result.fragments_valid += 1;
- }
+ if let Ok(metadata) = std::fs::metadata(fragment)
+ && metadata.len() > 0
+ {
+ result.fragments_valid += 1;
}
}
@@ -284,11 +272,7 @@ impl RecordingValidator {
result.dropped_frames = result.expected_frames - result.actual_frames;
}
- let duration_diff = if result.actual_duration > self.expected_duration {
- result.actual_duration - self.expected_duration
- } else {
- self.expected_duration - result.actual_duration
- };
+ let duration_diff = result.actual_duration.abs_diff(self.expected_duration);
result.duration_ok = duration_diff <= self.config.duration_tolerance;
let _ = std::fs::remove_file(&combined_path);
@@ -373,52 +357,50 @@ async fn probe_media_file(path: &Path) -> anyhow::Result<MediaProbeResult> {
match codec.medium() {
ffmpeg::media::Type::Video => {
- if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec) {
- if let Ok(video) = decoder.decoder().video() {
- result.video_info = Some(VideoInfo {
- pixel_format: video.format(),
- width: video.width(),
- height: video.height(),
- time_base: stream.time_base(),
- frame_rate: stream.avg_frame_rate(),
- });
-
- result.video_frame_count = stream.frames() as u64;
- video_stream_index = Some(stream.index());
- video_time_base = stream.time_base();
- }
+ if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec)
+ && let Ok(video) = decoder.decoder().video()
+ {
+ result.video_info = Some(VideoInfo {
+ pixel_format: video.format(),
+ width: video.width(),
+ height: video.height(),
+ time_base: stream.time_base(),
+ frame_rate: stream.avg_frame_rate(),
+ });
+
+ result.video_frame_count = stream.frames() as u64;
+ video_stream_index = Some(stream.index());
+ video_time_base = stream.time_base();
}
}
ffmpeg::media::Type::Audio => {
- if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec) {
- if let Ok(audio) = decoder.decoder().audio() {
- if let Ok(info) = AudioInfo::from_decoder(&audio) {
- result.audio_info = Some(info);
- }
- }
+ if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec)
+ && let Ok(audio) = decoder.decoder().audio()
+ && let Ok(info) = AudioInfo::from_decoder(&audio)
+ {
+ result.audio_info = Some(info);
}
}
_ => {}
}
}
- if result.video_frame_count == 0 {
- if let Some(video_idx) = video_stream_index {
- let mut last_pts: Option<i64> = None;
- for (stream, packet) in input.packets() {
- if stream.index() == video_idx {
- result.video_frame_count += 1;
- if let Some(pts) = packet.pts() {
- last_pts = Some(pts);
- }
+ if result.video_frame_count == 0
+ && let Some(video_idx) = video_stream_index
+ {
+ let mut last_pts: Option<i64> = None;
+ for (stream, packet) in input.packets() {
+ if stream.index() == video_idx {
+ result.video_frame_count += 1;
+ if let Some(pts) = packet.pts() {
+ last_pts = Some(pts);
}
}
+ }
- if let Some(pts) = last_pts {
- let duration_secs =
- pts as f64 * video_time_base.0 as f64 / video_time_base.1 as f64;
- result.duration = Duration::from_secs_f64(duration_secs.max(0.0));
- }
+ if let Some(pts) = last_pts {
+ let duration_secs = pts as f64 * video_time_base.0 as f64 / video_time_base.1 as f64;
+ result.duration = Duration::from_secs_f64(duration_secs.max(0.0));
}
}
diff --git a/crates/recording/src/test_sources/video.rs b/crates/recording/src/test_sources/video.rs
index 760059079..dfd7465d3 100644
--- a/crates/recording/src/test_sources/video.rs
+++ b/crates/recording/src/test_sources/video.rs
@@ -347,7 +347,7 @@ fn fill_checkerboard(frame: &mut ffmpeg::frame::Video, info: &VideoInfo, frame_n
for x in 0..width {
let check_x = (x + offset) / check_size;
let check_y = y / check_size;
- let is_white = (check_x + check_y) % 2 == 0;
+ let is_white = (check_x + check_y).is_multiple_of(2);
let val = if is_white { 255 } else { 0 };
let pixel_offset = y * stride + x * 4;
@@ -564,7 +564,7 @@ fn fill_nv12_checkerboard(
for x in 0..width {
let check_x = (x + offset) / check_size;
let check_y = y / check_size;
- let is_white = (check_x + check_y) % 2 == 0;
+ let is_white = (check_x + check_y).is_multiple_of(2);
let val = if is_white { 235 } else { 16 };
let y_offset = y * y_stride + x;