fmt: cargo fmt --all

This commit is contained in:
Siavash Sameni
2026-05-12 15:40:02 +04:00
parent dbbab0decf
commit fdfaed5390
9 changed files with 49 additions and 30 deletions

View File

@@ -251,7 +251,8 @@ mod tests {
#[test]
fn quality_profile_backward_compat_old_json() {
// Old JSON emitted before T5.1 has no priority_mode or video fields.
let old_json = r#"{"codec":"Opus24k","fec_ratio":0.2,"frame_duration_ms":20,"frames_per_block":5}"#;
let old_json =
r#"{"codec":"Opus24k","fec_ratio":0.2,"frame_duration_ms":20,"frames_per_block":5}"#;
let parsed: QualityProfile = serde_json::from_str(old_json).unwrap();
assert_eq!(parsed.priority_mode, PriorityMode::AudioFirst);
assert_eq!(parsed.video_bitrate_kbps, None);

View File

@@ -215,7 +215,11 @@ impl AudioScorer {
if self.iat_samples.len() < 10 {
return None;
}
let mean = self.iat_samples.iter().map(|d| d.as_secs_f64()).sum::<f64>()
let mean = self
.iat_samples
.iter()
.map(|d| d.as_secs_f64())
.sum::<f64>()
/ self.iat_samples.len() as f64;
if mean == 0.0 {
return None;
@@ -257,7 +261,11 @@ impl AudioScorer {
if self.q_intervals.len() < 3 {
return None;
}
let mean = self.q_intervals.iter().map(|d| d.as_secs_f64()).sum::<f64>()
let mean = self
.q_intervals
.iter()
.map(|d| d.as_secs_f64())
.sum::<f64>()
/ self.q_intervals.len() as f64;
if mean == 0.0 {
return None;

View File

@@ -7,12 +7,11 @@
//! It operates on FEC-protected packets, managing loss recovery and adaptive
//! quality transitions.
pub mod audio_scorer;
pub mod auth;
pub mod call_registry;
pub mod config;
pub mod audio_scorer;
pub mod conformance;
pub mod response_policy;
pub mod event_log;
pub mod federation;
pub mod handshake;
@@ -21,6 +20,7 @@ pub mod pipeline;
pub mod presence;
pub mod probe;
pub mod relay_link;
pub mod response_policy;
pub mod room;
pub mod route;
pub mod session_mgr;

View File

@@ -60,12 +60,7 @@ impl ResponsePolicy {
///
/// `fingerprint` is the participant's identity string (or IP as fallback).
/// `code` is the specific violation type that triggered the verdict.
pub fn evaluate(
&mut self,
fingerprint: &str,
code: ViolationCode,
verdict: Verdict,
) -> Action {
pub fn evaluate(&mut self, fingerprint: &str, code: ViolationCode, verdict: Verdict) -> Action {
match verdict {
Verdict::Legitimate => Action::Allow,
Verdict::Suspect => Action::Throttle,
@@ -202,9 +197,10 @@ mod tests {
let _ = policy.evaluate("alice", ViolationCode::Bitrate, Verdict::Abusive);
assert_eq!(policy.len(), 1);
// Manually expire by moving cooldown back
policy
.cooldowns
.insert(("alice".to_string(), ViolationCode::Bitrate), Instant::now() - Duration::from_secs(90000));
policy.cooldowns.insert(
("alice".to_string(), ViolationCode::Bitrate),
Instant::now() - Duration::from_secs(90000),
);
policy.prune();
assert!(policy.is_empty());
}

View File

@@ -274,7 +274,9 @@ impl ReceiverState {
}
// Same candidate — check if hysteresis elapsed.
let elapsed = now.saturating_duration_since(self.candidate_since).as_millis() as u64;
let elapsed = now
.saturating_duration_since(self.candidate_since)
.as_millis() as u64;
if elapsed >= LAYER_SWITCH_HYSTERESIS_MS {
self.selected_layer = suggested;
}
@@ -879,11 +881,7 @@ impl RoomManager {
/// Return the selected simulcast layer (0/1/2) for a receiver.
///
/// Defaults to layer 0 (low) if no state has been recorded yet.
pub fn selected_layer(
&self,
room_name: &str,
receiver_id: ParticipantId,
) -> u8 {
pub fn selected_layer(&self, room_name: &str, receiver_id: ParticipantId) -> u8 {
self.receiver_states
.get(&(room_name.to_string(), receiver_id))
.map(|s| s.selected_layer)
@@ -1963,7 +1961,10 @@ mod tests {
let mut rs = ReceiverState::new();
let t0 = std::time::Instant::now();
rs.update(4000, 0, t0);
assert_eq!(rs.selected_layer, 2, ">3 Mbps + 0% loss → high layer immediately");
assert_eq!(
rs.selected_layer, 2,
">3 Mbps + 0% loss → high layer immediately"
);
}
#[test]
@@ -1985,12 +1986,18 @@ mod tests {
// Drop to low-bandwidth — should not switch immediately
let t1 = t0 + std::time::Duration::from_millis(100);
rs.update(100, 0, t1);
assert_eq!(rs.selected_layer, 2, "hysteresis prevents immediate downgrade");
assert_eq!(
rs.selected_layer, 2,
"hysteresis prevents immediate downgrade"
);
// After 3 s — switch should happen
let t2 = t0 + std::time::Duration::from_millis(3100);
rs.update(100, 0, t2);
assert_eq!(rs.selected_layer, 0, "after 3 s hysteresis, downgrade occurs");
assert_eq!(
rs.selected_layer, 0,
"after 3 s hysteresis, downgrade occurs"
);
}
#[test]

View File

@@ -21,10 +21,14 @@ pub use depacketizer::H264Depacketizer;
pub use encoder::{VideoEncoder, VideoError, VideoFrame};
pub use encoder_mode::EncoderMode;
pub use framer::{FramedPacket, H264Framer};
pub use mediacodec::{MediaCodecDecoder, MediaCodecEncoder, MediaCodecHevcDecoder, MediaCodecHevcEncoder};
pub use mediacodec::{
MediaCodecDecoder, MediaCodecEncoder, MediaCodecHevcDecoder, MediaCodecHevcEncoder,
};
pub use nack::{CachedPacket, NackAction, NackReceiver, NackSender};
pub use simulcast::{LayerPacket, LayerTarget, SimulcastEncoder, SimulcastLayer};
pub use videotoolbox::{VideoToolboxDecoder, VideoToolboxEncoder, VideoToolboxHevcDecoder, VideoToolboxHevcEncoder};
pub use videotoolbox::{
VideoToolboxDecoder, VideoToolboxEncoder, VideoToolboxHevcDecoder, VideoToolboxHevcEncoder,
};
#[cfg(test)]
mod tests {

View File

@@ -593,7 +593,9 @@ impl VideoDecoder for MediaCodecHevcDecoder {
format.set_buffer("csd-2", &pps);
let codec = MediaCodec::from_decoder_type("video/hevc").ok_or_else(|| {
VideoError::PlatformError("AMediaCodec_createDecoderByType (HEVC) failed".into())
VideoError::PlatformError(
"AMediaCodec_createDecoderByType (HEVC) failed".into(),
)
})?;
codec

View File

@@ -164,7 +164,6 @@ impl SimulcastEncoder {
}
mask
}
}
#[cfg(test)]
@@ -193,7 +192,9 @@ mod tests {
}
}
fn dummy_factory(stream_counter: &mut u8) -> impl FnMut(u32, u32, u32) -> Result<Box<dyn VideoEncoder>, VideoError> + '_ {
fn dummy_factory(
stream_counter: &mut u8,
) -> impl FnMut(u32, u32, u32) -> Result<Box<dyn VideoEncoder>, VideoError> + '_ {
move |_w, _h, _br| {
let enc = DummyEncoder {
stream_id: *stream_counter,

View File

@@ -7,8 +7,8 @@ use crate::encoder::{VideoEncoder, VideoError, VideoFrame};
mod imp {
pub use shiguredo_video_toolbox::{
CodecConfig, DecodedFrame, Decoder, DecoderCodec, DecoderConfig, EncodeOptions, Encoder,
EncoderConfig, FrameData, H264EncoderConfig, H264EntropyMode, H264Profile, HevcEncoderConfig,
HevcProfile, PixelFormat,
EncoderConfig, FrameData, H264EncoderConfig, H264EntropyMode, H264Profile,
HevcEncoderConfig, HevcProfile, PixelFormat,
};
}