Skip to content

Commit 9e958e4

Browse files
committed
clippy
1 parent 6e840e9 commit 9e958e4

3 files changed

Lines changed: 60 additions & 79 deletions

File tree

crates/recording/src/test_sources/config.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,22 @@ impl VideoTestConfig {
128128
}
129129
}
130130

131-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
131+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
132132
pub enum TestPattern {
133133
SmpteColorBars,
134134
ColorGradient,
135+
#[default]
135136
FrameCounter,
136137
TimestampOverlay,
137138
Checkerboard,
138-
SolidColor { r: u8, g: u8, b: u8 },
139+
SolidColor {
140+
r: u8,
141+
g: u8,
142+
b: u8,
143+
},
139144
Random,
140145
}
141146

142-
impl Default for TestPattern {
143-
fn default() -> Self {
144-
Self::FrameCounter
145-
}
146-
}
147-
148147
#[derive(Debug, Clone)]
149148
pub struct AudioTestConfig {
150149
pub sample_rate: u32,

crates/recording/src/test_sources/validation.rs

Lines changed: 51 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -176,43 +176,31 @@ impl RecordingValidator {
176176

177177
let tolerance_frames =
178178
(result.expected_frames as f64 * self.config.frame_count_tolerance) as u64;
179-
let frame_diff = if result.actual_frames > result.expected_frames {
180-
result.actual_frames - result.expected_frames
181-
} else {
182-
result.expected_frames - result.actual_frames
183-
};
179+
let frame_diff = result.actual_frames.abs_diff(result.expected_frames);
184180
result.frame_count_ok = frame_diff <= tolerance_frames.max(2);
185181

186182
if result.actual_frames < result.expected_frames {
187183
result.dropped_frames = result.expected_frames - result.actual_frames;
188184
}
189185

190-
let duration_diff = if result.actual_duration > self.expected_duration {
191-
result.actual_duration - self.expected_duration
192-
} else {
193-
self.expected_duration - result.actual_duration
194-
};
186+
let duration_diff = result.actual_duration.abs_diff(self.expected_duration);
195187
result.duration_ok = duration_diff <= self.config.duration_tolerance;
196188

197-
if let Some(expected) = &self.expected_video_info {
198-
if video_info.width != expected.width || video_info.height != expected.height {
199-
result.errors.push(format!(
200-
"Resolution mismatch: expected {}x{}, got {}x{}",
201-
expected.width, expected.height, video_info.width, video_info.height
202-
));
203-
}
189+
if let Some(expected) = &self.expected_video_info
190+
&& (video_info.width != expected.width || video_info.height != expected.height)
191+
{
192+
result.errors.push(format!(
193+
"Resolution mismatch: expected {}x{}, got {}x{}",
194+
expected.width, expected.height, video_info.width, video_info.height
195+
));
204196
}
205197
} else if self.expected_video_info.is_some() {
206198
result.errors.push("No video stream found".to_string());
207199
} else {
208200
result.frame_count_ok = true;
209201
result.actual_duration = probe.duration;
210202

211-
let duration_diff = if result.actual_duration > self.expected_duration {
212-
result.actual_duration - self.expected_duration
213-
} else {
214-
self.expected_duration - result.actual_duration
215-
};
203+
let duration_diff = result.actual_duration.abs_diff(self.expected_duration);
216204
result.duration_ok = duration_diff <= self.config.duration_tolerance;
217205
}
218206

@@ -246,10 +234,10 @@ impl RecordingValidator {
246234
for entry in entries {
247235
let entry = entry?;
248236
let path = entry.path();
249-
if let Some(ext) = path.extension() {
250-
if ext == "m4s" {
251-
fragments.push(path);
252-
}
237+
if let Some(ext) = path.extension()
238+
&& ext == "m4s"
239+
{
240+
fragments.push(path);
253241
}
254242
}
255243

@@ -258,10 +246,10 @@ impl RecordingValidator {
258246
result.fragments_checked = fragments.len();
259247

260248
for fragment in &fragments {
261-
if let Ok(metadata) = std::fs::metadata(fragment) {
262-
if metadata.len() > 0 {
263-
result.fragments_valid += 1;
264-
}
249+
if let Ok(metadata) = std::fs::metadata(fragment)
250+
&& metadata.len() > 0
251+
{
252+
result.fragments_valid += 1;
265253
}
266254
}
267255

@@ -284,11 +272,7 @@ impl RecordingValidator {
284272
result.dropped_frames = result.expected_frames - result.actual_frames;
285273
}
286274

287-
let duration_diff = if result.actual_duration > self.expected_duration {
288-
result.actual_duration - self.expected_duration
289-
} else {
290-
self.expected_duration - result.actual_duration
291-
};
275+
let duration_diff = result.actual_duration.abs_diff(self.expected_duration);
292276
result.duration_ok = duration_diff <= self.config.duration_tolerance;
293277

294278
let _ = std::fs::remove_file(&combined_path);
@@ -373,52 +357,50 @@ async fn probe_media_file(path: &Path) -> anyhow::Result<MediaProbeResult> {
373357

374358
match codec.medium() {
375359
ffmpeg::media::Type::Video => {
376-
if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec) {
377-
if let Ok(video) = decoder.decoder().video() {
378-
result.video_info = Some(VideoInfo {
379-
pixel_format: video.format(),
380-
width: video.width(),
381-
height: video.height(),
382-
time_base: stream.time_base(),
383-
frame_rate: stream.avg_frame_rate(),
384-
});
385-
386-
result.video_frame_count = stream.frames() as u64;
387-
video_stream_index = Some(stream.index());
388-
video_time_base = stream.time_base();
389-
}
360+
if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec)
361+
&& let Ok(video) = decoder.decoder().video()
362+
{
363+
result.video_info = Some(VideoInfo {
364+
pixel_format: video.format(),
365+
width: video.width(),
366+
height: video.height(),
367+
time_base: stream.time_base(),
368+
frame_rate: stream.avg_frame_rate(),
369+
});
370+
371+
result.video_frame_count = stream.frames() as u64;
372+
video_stream_index = Some(stream.index());
373+
video_time_base = stream.time_base();
390374
}
391375
}
392376
ffmpeg::media::Type::Audio => {
393-
if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec) {
394-
if let Ok(audio) = decoder.decoder().audio() {
395-
if let Ok(info) = AudioInfo::from_decoder(&audio) {
396-
result.audio_info = Some(info);
397-
}
398-
}
377+
if let Ok(decoder) = ffmpeg::codec::context::Context::from_parameters(codec)
378+
&& let Ok(audio) = decoder.decoder().audio()
379+
&& let Ok(info) = AudioInfo::from_decoder(&audio)
380+
{
381+
result.audio_info = Some(info);
399382
}
400383
}
401384
_ => {}
402385
}
403386
}
404387

405-
if result.video_frame_count == 0 {
406-
if let Some(video_idx) = video_stream_index {
407-
let mut last_pts: Option<i64> = None;
408-
for (stream, packet) in input.packets() {
409-
if stream.index() == video_idx {
410-
result.video_frame_count += 1;
411-
if let Some(pts) = packet.pts() {
412-
last_pts = Some(pts);
413-
}
388+
if result.video_frame_count == 0
389+
&& let Some(video_idx) = video_stream_index
390+
{
391+
let mut last_pts: Option<i64> = None;
392+
for (stream, packet) in input.packets() {
393+
if stream.index() == video_idx {
394+
result.video_frame_count += 1;
395+
if let Some(pts) = packet.pts() {
396+
last_pts = Some(pts);
414397
}
415398
}
399+
}
416400

417-
if let Some(pts) = last_pts {
418-
let duration_secs =
419-
pts as f64 * video_time_base.0 as f64 / video_time_base.1 as f64;
420-
result.duration = Duration::from_secs_f64(duration_secs.max(0.0));
421-
}
401+
if let Some(pts) = last_pts {
402+
let duration_secs = pts as f64 * video_time_base.0 as f64 / video_time_base.1 as f64;
403+
result.duration = Duration::from_secs_f64(duration_secs.max(0.0));
422404
}
423405
}
424406

crates/recording/src/test_sources/video.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn fill_checkerboard(frame: &mut ffmpeg::frame::Video, info: &VideoInfo, frame_n
347347
for x in 0..width {
348348
let check_x = (x + offset) / check_size;
349349
let check_y = y / check_size;
350-
let is_white = (check_x + check_y) % 2 == 0;
350+
let is_white = (check_x + check_y).is_multiple_of(2);
351351
let val = if is_white { 255 } else { 0 };
352352

353353
let pixel_offset = y * stride + x * 4;
@@ -564,7 +564,7 @@ fn fill_nv12_checkerboard(
564564
for x in 0..width {
565565
let check_x = (x + offset) / check_size;
566566
let check_y = y / check_size;
567-
let is_white = (check_x + check_y) % 2 == 0;
567+
let is_white = (check_x + check_y).is_multiple_of(2);
568568
let val = if is_white { 235 } else { 16 };
569569

570570
let y_offset = y * y_stride + x;

0 commit comments

Comments
 (0)