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 |
11 #include "webrtc/api/rtcstatscollector.h" | 11 #include "webrtc/api/rtcstatscollector.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/api/peerconnection.h" | 17 #include "webrtc/api/peerconnection.h" |
18 #include "webrtc/api/webrtcsession.h" | 18 #include "webrtc/api/webrtcsession.h" |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/sslidentity.h" | 20 #include "webrtc/base/sslidentity.h" |
21 #include "webrtc/p2p/base/candidate.h" | 21 #include "webrtc/p2p/base/candidate.h" |
22 #include "webrtc/p2p/base/port.h" | 22 #include "webrtc/p2p/base/port.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 | 25 |
26 namespace { | |
27 | |
26 const char* CandidateTypeToRTCIceCandidateType(const std::string& type) { | 28 const char* CandidateTypeToRTCIceCandidateType(const std::string& type) { |
27 if (type == cricket::LOCAL_PORT_TYPE) | 29 if (type == cricket::LOCAL_PORT_TYPE) |
28 return RTCIceCandidateType::kHost; | 30 return RTCIceCandidateType::kHost; |
29 if (type == cricket::STUN_PORT_TYPE) | 31 if (type == cricket::STUN_PORT_TYPE) |
30 return RTCIceCandidateType::kSrflx; | 32 return RTCIceCandidateType::kSrflx; |
31 if (type == cricket::PRFLX_PORT_TYPE) | 33 if (type == cricket::PRFLX_PORT_TYPE) |
32 return RTCIceCandidateType::kPrflx; | 34 return RTCIceCandidateType::kPrflx; |
33 if (type == cricket::RELAY_PORT_TYPE) | 35 if (type == cricket::RELAY_PORT_TYPE) |
34 return RTCIceCandidateType::kRelay; | 36 return RTCIceCandidateType::kRelay; |
35 RTC_NOTREACHED(); | 37 RTC_NOTREACHED(); |
36 return nullptr; | 38 return nullptr; |
37 } | 39 } |
38 | 40 |
41 const char* DataStateToRTCDataChannelState( | |
42 DataChannelInterface::DataState state) { | |
43 switch (state) { | |
44 case DataChannelInterface::kConnecting: | |
45 return RTCDataChannelState::kConnecting; | |
46 case DataChannelInterface::kOpen: | |
47 return RTCDataChannelState::kOpen; | |
48 case DataChannelInterface::kClosing: | |
49 return RTCDataChannelState::kClosing; | |
50 case DataChannelInterface::kClosed: | |
51 return RTCDataChannelState::kClosed; | |
52 default: | |
53 RTC_NOTREACHED(); | |
54 return nullptr; | |
55 } | |
56 } | |
57 | |
58 } // namespace | |
59 | |
39 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( | 60 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( |
40 PeerConnection* pc, int64_t cache_lifetime_us) { | 61 PeerConnection* pc, int64_t cache_lifetime_us) { |
41 return rtc::scoped_refptr<RTCStatsCollector>( | 62 return rtc::scoped_refptr<RTCStatsCollector>( |
42 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); | 63 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); |
43 } | 64 } |
44 | 65 |
45 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, | 66 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, |
46 int64_t cache_lifetime_us) | 67 int64_t cache_lifetime_us) |
47 : pc_(pc), | 68 : pc_(pc), |
48 signaling_thread_(pc->session()->signaling_thread()), | 69 signaling_thread_(pc->session()->signaling_thread()), |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 int64_t timestamp_us) { | 125 int64_t timestamp_us) { |
105 RTC_DCHECK(signaling_thread_->IsCurrent()); | 126 RTC_DCHECK(signaling_thread_->IsCurrent()); |
106 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 127 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
107 | 128 |
108 SessionStats session_stats; | 129 SessionStats session_stats; |
109 if (pc_->session()->GetTransportStats(&session_stats)) { | 130 if (pc_->session()->GetTransportStats(&session_stats)) { |
110 ProduceCertificateStats_s(timestamp_us, session_stats, report.get()); | 131 ProduceCertificateStats_s(timestamp_us, session_stats, report.get()); |
111 ProduceIceCandidateAndPairStats_s(timestamp_us, session_stats, | 132 ProduceIceCandidateAndPairStats_s(timestamp_us, session_stats, |
112 report.get()); | 133 report.get()); |
113 } | 134 } |
135 ProduceDataChannelStats_s(timestamp_us, report.get()); | |
114 ProducePeerConnectionStats_s(timestamp_us, report.get()); | 136 ProducePeerConnectionStats_s(timestamp_us, report.get()); |
115 | 137 |
116 AddPartialResults(report); | 138 AddPartialResults(report); |
117 } | 139 } |
118 | 140 |
119 void RTCStatsCollector::ProducePartialResultsOnWorkerThread( | 141 void RTCStatsCollector::ProducePartialResultsOnWorkerThread( |
120 int64_t timestamp_us) { | 142 int64_t timestamp_us) { |
121 RTC_DCHECK(worker_thread_->IsCurrent()); | 143 RTC_DCHECK(worker_thread_->IsCurrent()); |
122 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 144 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
123 | 145 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 stats->fingerprint = s->fingerprint; | 233 stats->fingerprint = s->fingerprint; |
212 stats->fingerprint_algorithm = s->fingerprint_algorithm; | 234 stats->fingerprint_algorithm = s->fingerprint_algorithm; |
213 stats->base64_certificate = s->base64_certificate; | 235 stats->base64_certificate = s->base64_certificate; |
214 if (prev_stats) | 236 if (prev_stats) |
215 prev_stats->issuer_certificate_id = stats->id(); | 237 prev_stats->issuer_certificate_id = stats->id(); |
216 report->AddStats(std::unique_ptr<RTCCertificateStats>(stats)); | 238 report->AddStats(std::unique_ptr<RTCCertificateStats>(stats)); |
217 prev_stats = stats; | 239 prev_stats = stats; |
218 } | 240 } |
219 } | 241 } |
220 | 242 |
243 void RTCStatsCollector::ProduceDataChannelStats_s( | |
244 int64_t timestamp_us, RTCStatsReport* report) const { | |
245 RTC_DCHECK(signaling_thread_->IsCurrent()); | |
246 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = | |
Taylor Brandstetter
2016/10/18 17:28:11
nit: Don't need this temporary variable, could jus
hbos
2016/10/18 19:13:37
Done.
| |
247 pc_->sctp_data_channels(); | |
248 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { | |
249 std::unique_ptr<RTCDataChannelStats> data_channel_stats( | |
250 new RTCDataChannelStats( | |
251 "RTCDataChannel_" + rtc::ToString<>(data_channel->id()), | |
252 timestamp_us)); | |
253 data_channel_stats->label = data_channel->label(); | |
254 data_channel_stats->protocol = data_channel->protocol(); | |
255 data_channel_stats->datachannelid = data_channel->id(); | |
256 data_channel_stats->state = | |
257 DataStateToRTCDataChannelState(data_channel->state()); | |
258 data_channel_stats->messages_sent = data_channel->messages_sent(); | |
259 data_channel_stats->bytes_sent = data_channel->bytes_sent(); | |
260 data_channel_stats->messages_received = data_channel->messages_received(); | |
261 data_channel_stats->bytes_received = data_channel->bytes_received(); | |
262 report->AddStats(std::move(data_channel_stats)); | |
263 } | |
264 } | |
265 | |
221 void RTCStatsCollector::ProduceIceCandidateAndPairStats_s( | 266 void RTCStatsCollector::ProduceIceCandidateAndPairStats_s( |
222 int64_t timestamp_us, const SessionStats& session_stats, | 267 int64_t timestamp_us, const SessionStats& session_stats, |
223 RTCStatsReport* report) const { | 268 RTCStatsReport* report) const { |
224 RTC_DCHECK(signaling_thread_->IsCurrent()); | 269 RTC_DCHECK(signaling_thread_->IsCurrent()); |
225 for (const auto& transport_stats : session_stats.transport_stats) { | 270 for (const auto& transport_stats : session_stats.transport_stats) { |
226 for (const auto& channel_stats : transport_stats.second.channel_stats) { | 271 for (const auto& channel_stats : transport_stats.second.channel_stats) { |
227 for (const cricket::ConnectionInfo& info : | 272 for (const cricket::ConnectionInfo& info : |
228 channel_stats.connection_infos) { | 273 channel_stats.connection_infos) { |
229 const std::string& id = "RTCIceCandidatePair_" + | 274 const std::string& id = "RTCIceCandidatePair_" + |
230 info.local_candidate.id() + "_" + info.remote_candidate.id(); | 275 info.local_candidate.id() + "_" + info.remote_candidate.id(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 // There is always just one |RTCPeerConnectionStats| so its |id| can be a | 375 // There is always just one |RTCPeerConnectionStats| so its |id| can be a |
331 // constant. | 376 // constant. |
332 std::unique_ptr<RTCPeerConnectionStats> stats( | 377 std::unique_ptr<RTCPeerConnectionStats> stats( |
333 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); | 378 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); |
334 stats->data_channels_opened = data_channels_opened; | 379 stats->data_channels_opened = data_channels_opened; |
335 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - | 380 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - |
336 data_channels_opened; | 381 data_channels_opened; |
337 report->AddStats(std::move(stats)); | 382 report->AddStats(std::move(stats)); |
338 } | 383 } |
339 | 384 |
385 const char* CandidateTypeToRTCIceCandidateTypeForTesting( | |
386 const std::string& type) { | |
387 return CandidateTypeToRTCIceCandidateType(type); | |
388 } | |
389 | |
390 const char* DataStateToRTCDataChannelStateForTesting( | |
391 DataChannelInterface::DataState state) { | |
392 return DataStateToRTCDataChannelState(state); | |
393 } | |
394 | |
340 } // namespace webrtc | 395 } // namespace webrtc |
OLD | NEW |