Skip to content

Commit 740f181

Browse files
saxrainliu
authored andcommitted
Copy fields when grabbing ice gatherer stats
1 parent d3444be commit 740f181

File tree

2 files changed

+106
-37
lines changed

2 files changed

+106
-37
lines changed

src/ice_transport/ice_gatherer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::ice_transport::ice_parameters::RTCIceParameters;
77
use crate::ice_transport::ice_server::RTCIceServer;
88
use crate::peer_connection::policy::ice_transport_policy::RTCIceTransportPolicy;
99
use crate::stats::stats_collector::StatsCollector;
10+
use crate::stats::SourceStatsType::*;
1011
use crate::stats::StatsReportType;
1112

1213
use ice::agent::Agent;
@@ -316,15 +317,15 @@ impl RTCIceGatherer {
316317
let mut reports = vec![];
317318

318319
for stats in agent.get_candidate_pairs_stats().await {
319-
reports.push(StatsReportType::from(stats));
320+
reports.push(StatsReportType::from(CandidatePair(stats)));
320321
}
321322

322323
for stats in agent.get_local_candidates_stats().await {
323-
reports.push(StatsReportType::from(stats));
324+
reports.push(StatsReportType::from(LocalCandidate(stats)));
324325
}
325326

326327
for stats in agent.get_remote_candidates_stats().await {
327-
reports.push(StatsReportType::from(stats));
328+
reports.push(StatsReportType::from(RemoteCandidate(stats)));
328329
}
329330

330331
let mut lock = collector.try_lock().unwrap();

src/stats/mod.rs

Lines changed: 102 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
11
use ice::agent::agent_stats::{CandidatePairStats, CandidateStats};
2+
use ice::candidate::{CandidatePairState, CandidateType};
3+
use ice::network_type::NetworkType;
24
use stats_collector::StatsCollector;
35

46
use std::sync::Arc;
57
use tokio::sync::Mutex;
8+
use tokio::time::Instant;
69

710
pub mod stats_collector;
811

9-
pub enum StatsType {
10-
CSRC,
11-
CandidatePair,
12-
Certificate,
13-
Codec,
14-
DataChannel,
15-
InboundRTP,
16-
LocalCandidate,
17-
OutboundRTP,
18-
PeerConnection,
19-
Receiver,
20-
RemoteCandidate,
21-
RemoteInboundRTP,
22-
RemoteOutboundRTP,
23-
Sender,
24-
Stream,
25-
Track,
26-
Transport,
12+
pub enum SourceStatsType {
13+
CandidatePair(CandidatePairStats),
14+
LocalCandidate(CandidateStats),
15+
RemoteCandidate(CandidateStats),
2716
}
2817

2918
pub enum StatsReportType {
30-
StatsType(ICECandidatePairStats),
19+
CandidatePair(ICECandidatePairStats),
20+
LocalCandidate(ICECandidateStats),
21+
RemoteCandidate(ICECandidateStats),
3122
}
3223

33-
impl From<CandidatePairStats> for StatsReportType {
34-
fn from(stats: CandidatePairStats) -> Self {
35-
StatsReportType::StatsType(stats.into())
36-
}
37-
}
38-
39-
impl From<CandidateStats> for StatsReportType {
40-
fn from(stats: CandidateStats) -> Self {
41-
StatsReportType::StatsType(stats.into())
24+
impl From<SourceStatsType> for StatsReportType {
25+
fn from(stats: SourceStatsType) -> Self {
26+
match stats {
27+
SourceStatsType::CandidatePair(stats) => StatsReportType::CandidatePair(stats.into()),
28+
SourceStatsType::LocalCandidate(stats) => StatsReportType::LocalCandidate(stats.into()),
29+
SourceStatsType::RemoteCandidate(stats) => {
30+
StatsReportType::RemoteCandidate(stats.into())
31+
}
32+
}
4233
}
4334
}
4435

@@ -50,16 +41,93 @@ impl From<Arc<Mutex<StatsCollector>>> for StatsReport {
5041
}
5142
}
5243

53-
pub struct ICECandidatePairStats {}
44+
pub struct ICECandidatePairStats {
45+
timestamp: Instant,
46+
// id: String,
47+
local_candidate_id: String,
48+
remote_candidate_id: String,
49+
state: CandidatePairState,
50+
nominated: bool,
51+
packets_sent: u32,
52+
packets_received: u32,
53+
bytes_sent: u64,
54+
bytes_received: u64,
55+
last_packet_sent_timestamp: Instant,
56+
last_packet_received_timstamp: Instant,
57+
first_request_timestamp: Instant,
58+
last_request_timestamp: Instant,
59+
total_round_trip_time: f64,
60+
current_round_trip_time: f64,
61+
available_outgoing_bitrate: f64,
62+
available_incoming_bitrate: f64,
63+
circuit_breaker_trigger_count: u32,
64+
requests_received: u64,
65+
requests_sent: u64,
66+
responses_received: u64,
67+
responses_sent: u64,
68+
retransmissions_sent: u64,
69+
consent_requests_sent: u64,
70+
consent_expired_timestamp: Instant,
71+
}
5472

5573
impl From<CandidatePairStats> for ICECandidatePairStats {
56-
fn from(_stats: CandidatePairStats) -> Self {
57-
ICECandidatePairStats {}
74+
fn from(stats: CandidatePairStats) -> Self {
75+
ICECandidatePairStats {
76+
timestamp: stats.timestamp,
77+
local_candidate_id: stats.local_candidate_id,
78+
remote_candidate_id: stats.remote_candidate_id,
79+
state: stats.state,
80+
nominated: stats.nominated,
81+
packets_sent: stats.packets_sent,
82+
packets_received: stats.packets_received,
83+
bytes_sent: stats.bytes_sent,
84+
bytes_received: stats.bytes_received,
85+
last_packet_sent_timestamp: stats.last_packet_sent_timestamp,
86+
last_packet_received_timstamp: stats.last_packet_received_timestamp,
87+
first_request_timestamp: stats.first_request_timestamp,
88+
last_request_timestamp: stats.last_request_timestamp,
89+
total_round_trip_time: stats.total_round_trip_time,
90+
current_round_trip_time: stats.current_round_trip_time,
91+
available_outgoing_bitrate: stats.available_outgoing_bitrate,
92+
available_incoming_bitrate: stats.available_incoming_bitrate,
93+
circuit_breaker_trigger_count: stats.circuit_breaker_trigger_count,
94+
requests_received: stats.requests_received,
95+
requests_sent: stats.requests_sent,
96+
responses_received: stats.responses_received,
97+
responses_sent: stats.responses_sent,
98+
retransmissions_sent: stats.retransmissions_sent,
99+
consent_requests_sent: stats.consent_requests_sent,
100+
consent_expired_timestamp: stats.consent_expired_timestamp,
101+
}
58102
}
59103
}
60104

61-
impl From<CandidateStats> for ICECandidatePairStats {
62-
fn from(_stats: CandidateStats) -> Self {
63-
ICECandidatePairStats {}
105+
pub struct ICECandidateStats {
106+
timestamp: Instant,
107+
// id: String,
108+
candidate_type: CandidateType,
109+
deleted: bool,
110+
ip: String,
111+
network_type: NetworkType,
112+
port: u16,
113+
priority: u32,
114+
relay_protocol: String,
115+
url: String,
116+
}
117+
118+
impl From<CandidateStats> for ICECandidateStats {
119+
fn from(stats: CandidateStats) -> Self {
120+
ICECandidateStats {
121+
timestamp: stats.timestamp,
122+
// id: String,
123+
network_type: stats.network_type,
124+
ip: stats.ip,
125+
port: stats.port,
126+
candidate_type: stats.candidate_type,
127+
priority: stats.priority,
128+
url: stats.url,
129+
relay_protocol: stats.relay_protocol,
130+
deleted: stats.deleted,
131+
}
64132
}
65133
}

0 commit comments

Comments
 (0)