OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 if (type == cricket::STUN_PORT_TYPE) | 29 if (type == cricket::STUN_PORT_TYPE) |
30 return RTCIceCandidateType::kSrflx; | 30 return RTCIceCandidateType::kSrflx; |
31 if (type == cricket::PRFLX_PORT_TYPE) | 31 if (type == cricket::PRFLX_PORT_TYPE) |
32 return RTCIceCandidateType::kPrflx; | 32 return RTCIceCandidateType::kPrflx; |
33 if (type == cricket::RELAY_PORT_TYPE) | 33 if (type == cricket::RELAY_PORT_TYPE) |
34 return RTCIceCandidateType::kRelay; | 34 return RTCIceCandidateType::kRelay; |
35 RTC_NOTREACHED(); | 35 RTC_NOTREACHED(); |
36 return nullptr; | 36 return nullptr; |
37 } | 37 } |
38 | 38 |
| 39 const char* DataStateToRTCDataChannelState( |
| 40 DataChannelInterface::DataState state) { |
| 41 switch (state) { |
| 42 case DataChannelInterface::kConnecting: |
| 43 return RTCDataChannelState::kConnecting; |
| 44 case DataChannelInterface::kOpen: |
| 45 return RTCDataChannelState::kOpen; |
| 46 case DataChannelInterface::kClosing: |
| 47 return RTCDataChannelState::kClosing; |
| 48 case DataChannelInterface::kClosed: |
| 49 return RTCDataChannelState::kClosed; |
| 50 default: |
| 51 RTC_NOTREACHED(); |
| 52 return nullptr; |
| 53 } |
| 54 } |
| 55 |
39 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( | 56 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( |
40 PeerConnection* pc, int64_t cache_lifetime_us) { | 57 PeerConnection* pc, int64_t cache_lifetime_us) { |
41 return rtc::scoped_refptr<RTCStatsCollector>( | 58 return rtc::scoped_refptr<RTCStatsCollector>( |
42 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); | 59 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); |
43 } | 60 } |
44 | 61 |
45 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, | 62 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, |
46 int64_t cache_lifetime_us) | 63 int64_t cache_lifetime_us) |
47 : pc_(pc), | 64 : pc_(pc), |
48 signaling_thread_(pc->session()->signaling_thread()), | 65 signaling_thread_(pc->session()->signaling_thread()), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 int64_t timestamp_us) { | 121 int64_t timestamp_us) { |
105 RTC_DCHECK(signaling_thread_->IsCurrent()); | 122 RTC_DCHECK(signaling_thread_->IsCurrent()); |
106 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 123 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
107 | 124 |
108 SessionStats session_stats; | 125 SessionStats session_stats; |
109 if (pc_->session()->GetTransportStats(&session_stats)) { | 126 if (pc_->session()->GetTransportStats(&session_stats)) { |
110 ProduceCertificateStats_s(timestamp_us, session_stats, report.get()); | 127 ProduceCertificateStats_s(timestamp_us, session_stats, report.get()); |
111 ProduceIceCandidateAndPairStats_s(timestamp_us, session_stats, | 128 ProduceIceCandidateAndPairStats_s(timestamp_us, session_stats, |
112 report.get()); | 129 report.get()); |
113 } | 130 } |
| 131 ProduceDataChannelStats_s(timestamp_us, report.get()); |
114 ProducePeerConnectionStats_s(timestamp_us, report.get()); | 132 ProducePeerConnectionStats_s(timestamp_us, report.get()); |
115 | 133 |
116 AddPartialResults(report); | 134 AddPartialResults(report); |
117 } | 135 } |
118 | 136 |
119 void RTCStatsCollector::ProducePartialResultsOnWorkerThread( | 137 void RTCStatsCollector::ProducePartialResultsOnWorkerThread( |
120 int64_t timestamp_us) { | 138 int64_t timestamp_us) { |
121 RTC_DCHECK(worker_thread_->IsCurrent()); | 139 RTC_DCHECK(worker_thread_->IsCurrent()); |
122 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 140 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
123 | 141 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 stats->fingerprint = s->fingerprint; | 229 stats->fingerprint = s->fingerprint; |
212 stats->fingerprint_algorithm = s->fingerprint_algorithm; | 230 stats->fingerprint_algorithm = s->fingerprint_algorithm; |
213 stats->base64_certificate = s->base64_certificate; | 231 stats->base64_certificate = s->base64_certificate; |
214 if (prev_stats) | 232 if (prev_stats) |
215 prev_stats->issuer_certificate_id = stats->id(); | 233 prev_stats->issuer_certificate_id = stats->id(); |
216 report->AddStats(std::unique_ptr<RTCCertificateStats>(stats)); | 234 report->AddStats(std::unique_ptr<RTCCertificateStats>(stats)); |
217 prev_stats = stats; | 235 prev_stats = stats; |
218 } | 236 } |
219 } | 237 } |
220 | 238 |
| 239 void RTCStatsCollector::ProduceDataChannelStats_s( |
| 240 int64_t timestamp_us, RTCStatsReport* report) const { |
| 241 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 242 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = |
| 243 pc_->sctp_data_channels(); |
| 244 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { |
| 245 std::unique_ptr<RTCDataChannelStats> data_channel_stats( |
| 246 new RTCDataChannelStats( |
| 247 "RTCDataChannel_" + rtc::ToString<>(data_channel->id()), |
| 248 timestamp_us)); |
| 249 data_channel_stats->label = data_channel->label(); |
| 250 data_channel_stats->protocol = data_channel->protocol(); |
| 251 data_channel_stats->datachannelid = data_channel->id(); |
| 252 data_channel_stats->state = |
| 253 DataStateToRTCDataChannelState(data_channel->state()); |
| 254 data_channel_stats->messages_sent = data_channel->messages_sent(); |
| 255 data_channel_stats->bytes_sent = data_channel->bytes_sent(); |
| 256 data_channel_stats->messages_received = data_channel->messages_received(); |
| 257 data_channel_stats->bytes_received = data_channel->bytes_received(); |
| 258 report->AddStats(std::move(data_channel_stats)); |
| 259 } |
| 260 } |
| 261 |
221 void RTCStatsCollector::ProduceIceCandidateAndPairStats_s( | 262 void RTCStatsCollector::ProduceIceCandidateAndPairStats_s( |
222 int64_t timestamp_us, const SessionStats& session_stats, | 263 int64_t timestamp_us, const SessionStats& session_stats, |
223 RTCStatsReport* report) const { | 264 RTCStatsReport* report) const { |
224 RTC_DCHECK(signaling_thread_->IsCurrent()); | 265 RTC_DCHECK(signaling_thread_->IsCurrent()); |
225 for (const auto& transport_stats : session_stats.transport_stats) { | 266 for (const auto& transport_stats : session_stats.transport_stats) { |
226 for (const auto& channel_stats : transport_stats.second.channel_stats) { | 267 for (const auto& channel_stats : transport_stats.second.channel_stats) { |
227 for (const cricket::ConnectionInfo& info : | 268 for (const cricket::ConnectionInfo& info : |
228 channel_stats.connection_infos) { | 269 channel_stats.connection_infos) { |
229 const std::string& id = "RTCIceCandidatePair_" + | 270 const std::string& id = "RTCIceCandidatePair_" + |
230 info.local_candidate.id() + "_" + info.remote_candidate.id(); | 271 info.local_candidate.id() + "_" + info.remote_candidate.id(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // constant. | 372 // constant. |
332 std::unique_ptr<RTCPeerConnectionStats> stats( | 373 std::unique_ptr<RTCPeerConnectionStats> stats( |
333 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); | 374 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); |
334 stats->data_channels_opened = data_channels_opened; | 375 stats->data_channels_opened = data_channels_opened; |
335 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - | 376 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - |
336 data_channels_opened; | 377 data_channels_opened; |
337 report->AddStats(std::move(stats)); | 378 report->AddStats(std::move(stats)); |
338 } | 379 } |
339 | 380 |
340 } // namespace webrtc | 381 } // namespace webrtc |
OLD | NEW |