use crate::rtp_transceiver::rtp_sender::RtpCodecKind;
use crate::statistics::stats::media::audio_source::RTCAudioSourceStats;
use crate::statistics::stats::media::media_source::RTCMediaSourceStats;
use crate::statistics::stats::media::video_source::RTCVideoSourceStats;
use crate::statistics::stats::{RTCStats, RTCStatsType};
use std::time::Instant;
#[derive(Debug, Default)]
pub struct MediaSourceStatsAccumulator {
pub track_id: String,
pub kind: RtpCodecKind,
pub audio_level: Option<f64>,
pub total_audio_energy: Option<f64>,
pub total_samples_duration: Option<f64>,
pub echo_return_loss: Option<f64>,
pub echo_return_loss_enhancement: Option<f64>,
pub width: Option<u32>,
pub height: Option<u32>,
pub frames: Option<u32>,
pub frames_per_second: Option<f64>,
}
impl MediaSourceStatsAccumulator {
pub fn snapshot(&self, now: Instant, id: &str) -> RTCMediaSourceStats {
RTCMediaSourceStats {
stats: RTCStats {
timestamp: now,
typ: RTCStatsType::MediaSource,
id: id.to_string(),
},
track_id: self.track_id.clone(),
kind: self.kind,
}
}
pub fn snapshot_audio(&self, now: Instant, id: &str) -> RTCAudioSourceStats {
RTCAudioSourceStats {
media_source_stats: self.snapshot(now, id),
audio_level: self.audio_level.unwrap_or(0.0),
total_audio_energy: self.total_audio_energy.unwrap_or(0.0),
total_samples_duration: self.total_samples_duration.unwrap_or(0.0),
echo_return_loss: self.echo_return_loss.unwrap_or(0.0),
echo_return_loss_enhancement: self.echo_return_loss_enhancement.unwrap_or(0.0),
}
}
pub fn snapshot_video(&self, now: Instant, id: &str) -> RTCVideoSourceStats {
RTCVideoSourceStats {
media_source_stats: self.snapshot(now, id),
width: self.width.unwrap_or(0),
height: self.height.unwrap_or(0),
frames: self.frames.unwrap_or(0),
frames_per_second: self.frames_per_second.unwrap_or(0.0),
}
}
}