refactor: Use rational numbers for LtcFrame frame rate

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
Chris Frankland-Wright 2025-08-02 12:28:59 +01:00
parent a1da396874
commit 3d6a106f1e

View file

@ -1,10 +1,22 @@
use crate::config::Config;
use chrono::{DateTime, Local, Timelike, Utc};
use num_rational::Ratio;
use regex::Captures;
use std::collections::VecDeque;
const EWMA_ALPHA: f64 = 0.1;
fn get_frame_rate_ratio(rate_str: &str) -> Option<Ratio<i64>> {
match rate_str {
"23.98" => Some(Ratio::new(24000, 1001)),
"24.00" => Some(Ratio::new(24, 1)),
"25.00" => Some(Ratio::new(25, 1)),
"29.97" => Some(Ratio::new(30000, 1001)),
"30.00" => Some(Ratio::new(30, 1)),
_ => None,
}
}
#[derive(Clone, Debug)]
pub struct LtcFrame {
pub status: String,
@ -12,7 +24,7 @@ pub struct LtcFrame {
pub minutes: u32,
pub seconds: u32,
pub frames: u32,
pub frame_rate: f64,
pub frame_rate: Ratio<i64>,
pub timestamp: DateTime<Utc>, // arrival stamp
}
@ -24,7 +36,7 @@ impl LtcFrame {
minutes: caps[3].parse().ok()?,
seconds: caps[4].parse().ok()?,
frames: caps[5].parse().ok()?,
frame_rate: caps[6].parse().ok()?,
frame_rate: get_frame_rate_ratio(&caps[6])?,
timestamp,
})
}