fmt: cargo fmt --all
This commit is contained in:
@@ -251,7 +251,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn quality_profile_backward_compat_old_json() {
|
fn quality_profile_backward_compat_old_json() {
|
||||||
// Old JSON emitted before T5.1 has no priority_mode or video fields.
|
// 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();
|
let parsed: QualityProfile = serde_json::from_str(old_json).unwrap();
|
||||||
assert_eq!(parsed.priority_mode, PriorityMode::AudioFirst);
|
assert_eq!(parsed.priority_mode, PriorityMode::AudioFirst);
|
||||||
assert_eq!(parsed.video_bitrate_kbps, None);
|
assert_eq!(parsed.video_bitrate_kbps, None);
|
||||||
|
|||||||
@@ -215,7 +215,11 @@ impl AudioScorer {
|
|||||||
if self.iat_samples.len() < 10 {
|
if self.iat_samples.len() < 10 {
|
||||||
return None;
|
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;
|
/ self.iat_samples.len() as f64;
|
||||||
if mean == 0.0 {
|
if mean == 0.0 {
|
||||||
return None;
|
return None;
|
||||||
@@ -257,7 +261,11 @@ impl AudioScorer {
|
|||||||
if self.q_intervals.len() < 3 {
|
if self.q_intervals.len() < 3 {
|
||||||
return None;
|
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;
|
/ self.q_intervals.len() as f64;
|
||||||
if mean == 0.0 {
|
if mean == 0.0 {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@@ -7,12 +7,11 @@
|
|||||||
//! It operates on FEC-protected packets, managing loss recovery and adaptive
|
//! It operates on FEC-protected packets, managing loss recovery and adaptive
|
||||||
//! quality transitions.
|
//! quality transitions.
|
||||||
|
|
||||||
|
pub mod audio_scorer;
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod call_registry;
|
pub mod call_registry;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod audio_scorer;
|
|
||||||
pub mod conformance;
|
pub mod conformance;
|
||||||
pub mod response_policy;
|
|
||||||
pub mod event_log;
|
pub mod event_log;
|
||||||
pub mod federation;
|
pub mod federation;
|
||||||
pub mod handshake;
|
pub mod handshake;
|
||||||
@@ -21,6 +20,7 @@ pub mod pipeline;
|
|||||||
pub mod presence;
|
pub mod presence;
|
||||||
pub mod probe;
|
pub mod probe;
|
||||||
pub mod relay_link;
|
pub mod relay_link;
|
||||||
|
pub mod response_policy;
|
||||||
pub mod room;
|
pub mod room;
|
||||||
pub mod route;
|
pub mod route;
|
||||||
pub mod session_mgr;
|
pub mod session_mgr;
|
||||||
|
|||||||
@@ -60,12 +60,7 @@ impl ResponsePolicy {
|
|||||||
///
|
///
|
||||||
/// `fingerprint` is the participant's identity string (or IP as fallback).
|
/// `fingerprint` is the participant's identity string (or IP as fallback).
|
||||||
/// `code` is the specific violation type that triggered the verdict.
|
/// `code` is the specific violation type that triggered the verdict.
|
||||||
pub fn evaluate(
|
pub fn evaluate(&mut self, fingerprint: &str, code: ViolationCode, verdict: Verdict) -> Action {
|
||||||
&mut self,
|
|
||||||
fingerprint: &str,
|
|
||||||
code: ViolationCode,
|
|
||||||
verdict: Verdict,
|
|
||||||
) -> Action {
|
|
||||||
match verdict {
|
match verdict {
|
||||||
Verdict::Legitimate => Action::Allow,
|
Verdict::Legitimate => Action::Allow,
|
||||||
Verdict::Suspect => Action::Throttle,
|
Verdict::Suspect => Action::Throttle,
|
||||||
@@ -202,9 +197,10 @@ mod tests {
|
|||||||
let _ = policy.evaluate("alice", ViolationCode::Bitrate, Verdict::Abusive);
|
let _ = policy.evaluate("alice", ViolationCode::Bitrate, Verdict::Abusive);
|
||||||
assert_eq!(policy.len(), 1);
|
assert_eq!(policy.len(), 1);
|
||||||
// Manually expire by moving cooldown back
|
// Manually expire by moving cooldown back
|
||||||
policy
|
policy.cooldowns.insert(
|
||||||
.cooldowns
|
("alice".to_string(), ViolationCode::Bitrate),
|
||||||
.insert(("alice".to_string(), ViolationCode::Bitrate), Instant::now() - Duration::from_secs(90000));
|
Instant::now() - Duration::from_secs(90000),
|
||||||
|
);
|
||||||
policy.prune();
|
policy.prune();
|
||||||
assert!(policy.is_empty());
|
assert!(policy.is_empty());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,7 +274,9 @@ impl ReceiverState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Same candidate — check if hysteresis elapsed.
|
// 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 {
|
if elapsed >= LAYER_SWITCH_HYSTERESIS_MS {
|
||||||
self.selected_layer = suggested;
|
self.selected_layer = suggested;
|
||||||
}
|
}
|
||||||
@@ -879,11 +881,7 @@ impl RoomManager {
|
|||||||
/// Return the selected simulcast layer (0/1/2) for a receiver.
|
/// Return the selected simulcast layer (0/1/2) for a receiver.
|
||||||
///
|
///
|
||||||
/// Defaults to layer 0 (low) if no state has been recorded yet.
|
/// Defaults to layer 0 (low) if no state has been recorded yet.
|
||||||
pub fn selected_layer(
|
pub fn selected_layer(&self, room_name: &str, receiver_id: ParticipantId) -> u8 {
|
||||||
&self,
|
|
||||||
room_name: &str,
|
|
||||||
receiver_id: ParticipantId,
|
|
||||||
) -> u8 {
|
|
||||||
self.receiver_states
|
self.receiver_states
|
||||||
.get(&(room_name.to_string(), receiver_id))
|
.get(&(room_name.to_string(), receiver_id))
|
||||||
.map(|s| s.selected_layer)
|
.map(|s| s.selected_layer)
|
||||||
@@ -1963,7 +1961,10 @@ mod tests {
|
|||||||
let mut rs = ReceiverState::new();
|
let mut rs = ReceiverState::new();
|
||||||
let t0 = std::time::Instant::now();
|
let t0 = std::time::Instant::now();
|
||||||
rs.update(4000, 0, t0);
|
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]
|
#[test]
|
||||||
@@ -1985,12 +1986,18 @@ mod tests {
|
|||||||
// Drop to low-bandwidth — should not switch immediately
|
// Drop to low-bandwidth — should not switch immediately
|
||||||
let t1 = t0 + std::time::Duration::from_millis(100);
|
let t1 = t0 + std::time::Duration::from_millis(100);
|
||||||
rs.update(100, 0, t1);
|
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
|
// After 3 s — switch should happen
|
||||||
let t2 = t0 + std::time::Duration::from_millis(3100);
|
let t2 = t0 + std::time::Duration::from_millis(3100);
|
||||||
rs.update(100, 0, t2);
|
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]
|
#[test]
|
||||||
|
|||||||
@@ -21,10 +21,14 @@ pub use depacketizer::H264Depacketizer;
|
|||||||
pub use encoder::{VideoEncoder, VideoError, VideoFrame};
|
pub use encoder::{VideoEncoder, VideoError, VideoFrame};
|
||||||
pub use encoder_mode::EncoderMode;
|
pub use encoder_mode::EncoderMode;
|
||||||
pub use framer::{FramedPacket, H264Framer};
|
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 nack::{CachedPacket, NackAction, NackReceiver, NackSender};
|
||||||
pub use simulcast::{LayerPacket, LayerTarget, SimulcastEncoder, SimulcastLayer};
|
pub use simulcast::{LayerPacket, LayerTarget, SimulcastEncoder, SimulcastLayer};
|
||||||
pub use videotoolbox::{VideoToolboxDecoder, VideoToolboxEncoder, VideoToolboxHevcDecoder, VideoToolboxHevcEncoder};
|
pub use videotoolbox::{
|
||||||
|
VideoToolboxDecoder, VideoToolboxEncoder, VideoToolboxHevcDecoder, VideoToolboxHevcEncoder,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@@ -593,7 +593,9 @@ impl VideoDecoder for MediaCodecHevcDecoder {
|
|||||||
format.set_buffer("csd-2", &pps);
|
format.set_buffer("csd-2", &pps);
|
||||||
|
|
||||||
let codec = MediaCodec::from_decoder_type("video/hevc").ok_or_else(|| {
|
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
|
codec
|
||||||
|
|||||||
@@ -164,7 +164,6 @@ impl SimulcastEncoder {
|
|||||||
}
|
}
|
||||||
mask
|
mask
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[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| {
|
move |_w, _h, _br| {
|
||||||
let enc = DummyEncoder {
|
let enc = DummyEncoder {
|
||||||
stream_id: *stream_counter,
|
stream_id: *stream_counter,
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ use crate::encoder::{VideoEncoder, VideoError, VideoFrame};
|
|||||||
mod imp {
|
mod imp {
|
||||||
pub use shiguredo_video_toolbox::{
|
pub use shiguredo_video_toolbox::{
|
||||||
CodecConfig, DecodedFrame, Decoder, DecoderCodec, DecoderConfig, EncodeOptions, Encoder,
|
CodecConfig, DecodedFrame, Decoder, DecoderCodec, DecoderConfig, EncodeOptions, Encoder,
|
||||||
EncoderConfig, FrameData, H264EncoderConfig, H264EntropyMode, H264Profile, HevcEncoderConfig,
|
EncoderConfig, FrameData, H264EncoderConfig, H264EntropyMode, H264Profile,
|
||||||
HevcProfile, PixelFormat,
|
HevcEncoderConfig, HevcProfile, PixelFormat,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user