diff --git a/crates/wzp-proto/src/codec_id.rs b/crates/wzp-proto/src/codec_id.rs index 99e4a26..1587609 100644 --- a/crates/wzp-proto/src/codec_id.rs +++ b/crates/wzp-proto/src/codec_id.rs @@ -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); diff --git a/crates/wzp-relay/src/audio_scorer.rs b/crates/wzp-relay/src/audio_scorer.rs index 8f46b5c..c7abb47 100644 --- a/crates/wzp-relay/src/audio_scorer.rs +++ b/crates/wzp-relay/src/audio_scorer.rs @@ -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::() + let mean = self + .iat_samples + .iter() + .map(|d| d.as_secs_f64()) + .sum::() / 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::() + let mean = self + .q_intervals + .iter() + .map(|d| d.as_secs_f64()) + .sum::() / self.q_intervals.len() as f64; if mean == 0.0 { return None; diff --git a/crates/wzp-relay/src/lib.rs b/crates/wzp-relay/src/lib.rs index 9b98f78..53505ba 100644 --- a/crates/wzp-relay/src/lib.rs +++ b/crates/wzp-relay/src/lib.rs @@ -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; diff --git a/crates/wzp-relay/src/response_policy.rs b/crates/wzp-relay/src/response_policy.rs index 7b51c77..e990d63 100644 --- a/crates/wzp-relay/src/response_policy.rs +++ b/crates/wzp-relay/src/response_policy.rs @@ -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()); } diff --git a/crates/wzp-relay/src/room.rs b/crates/wzp-relay/src/room.rs index fa32eb6..11553b5 100644 --- a/crates/wzp-relay/src/room.rs +++ b/crates/wzp-relay/src/room.rs @@ -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] diff --git a/crates/wzp-video/src/lib.rs b/crates/wzp-video/src/lib.rs index 713c50e..08c9513 100644 --- a/crates/wzp-video/src/lib.rs +++ b/crates/wzp-video/src/lib.rs @@ -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 { diff --git a/crates/wzp-video/src/mediacodec.rs b/crates/wzp-video/src/mediacodec.rs index bd771b4..303d0cd 100644 --- a/crates/wzp-video/src/mediacodec.rs +++ b/crates/wzp-video/src/mediacodec.rs @@ -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 diff --git a/crates/wzp-video/src/simulcast.rs b/crates/wzp-video/src/simulcast.rs index 624261a..fe38f55 100644 --- a/crates/wzp-video/src/simulcast.rs +++ b/crates/wzp-video/src/simulcast.rs @@ -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, VideoError> + '_ { + fn dummy_factory( + stream_counter: &mut u8, + ) -> impl FnMut(u32, u32, u32) -> Result, VideoError> + '_ { move |_w, _h, _br| { let enc = DummyEncoder { stream_id: *stream_counter, diff --git a/crates/wzp-video/src/videotoolbox.rs b/crates/wzp-video/src/videotoolbox.rs index 7c0f572..450a626 100644 --- a/crates/wzp-video/src/videotoolbox.rs +++ b/crates/wzp-video/src/videotoolbox.rs @@ -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, }; }