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/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/base/sslidentity.h" |
19 | 21 |
20 namespace webrtc { | 22 namespace webrtc { |
21 | 23 |
22 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( | 24 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( |
23 PeerConnection* pc, int64_t cache_lifetime_us) { | 25 PeerConnection* pc, int64_t cache_lifetime_us) { |
24 return rtc::scoped_refptr<RTCStatsCollector>( | 26 return rtc::scoped_refptr<RTCStatsCollector>( |
25 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); | 27 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); |
26 } | 28 } |
27 | 29 |
28 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, | 30 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 void RTCStatsCollector::ClearCachedStatsReport() { | 83 void RTCStatsCollector::ClearCachedStatsReport() { |
82 RTC_DCHECK(signaling_thread_->IsCurrent()); | 84 RTC_DCHECK(signaling_thread_->IsCurrent()); |
83 cached_report_ = nullptr; | 85 cached_report_ = nullptr; |
84 } | 86 } |
85 | 87 |
86 void RTCStatsCollector::ProducePartialResultsOnSignalingThread( | 88 void RTCStatsCollector::ProducePartialResultsOnSignalingThread( |
87 int64_t timestamp_us) { | 89 int64_t timestamp_us) { |
88 RTC_DCHECK(signaling_thread_->IsCurrent()); | 90 RTC_DCHECK(signaling_thread_->IsCurrent()); |
89 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 91 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
90 | 92 |
91 report->AddStats(ProducePeerConnectionStats_s(timestamp_us)); | 93 SessionStats session_stats; |
| 94 if (pc_->session()->GetTransportStats(&session_stats)) { |
| 95 ProduceCertificateStats_s(timestamp_us, session_stats, report.get()); |
| 96 } |
| 97 ProducePeerConnectionStats_s(timestamp_us, report.get()); |
92 | 98 |
93 AddPartialResults(report); | 99 AddPartialResults(report); |
94 } | 100 } |
95 | 101 |
96 void RTCStatsCollector::ProducePartialResultsOnWorkerThread( | 102 void RTCStatsCollector::ProducePartialResultsOnWorkerThread( |
97 int64_t timestamp_us) { | 103 int64_t timestamp_us) { |
98 RTC_DCHECK(worker_thread_->IsCurrent()); | 104 RTC_DCHECK(worker_thread_->IsCurrent()); |
99 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 105 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
100 | 106 |
101 // TODO(hbos): Gather stats on worker thread. | 107 // TODO(hbos): Gather stats on worker thread. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 RTC_DCHECK(signaling_thread_->IsCurrent()); | 152 RTC_DCHECK(signaling_thread_->IsCurrent()); |
147 RTC_DCHECK(!callbacks_.empty()); | 153 RTC_DCHECK(!callbacks_.empty()); |
148 RTC_DCHECK(cached_report_); | 154 RTC_DCHECK(cached_report_); |
149 for (const rtc::scoped_refptr<RTCStatsCollectorCallback>& callback : | 155 for (const rtc::scoped_refptr<RTCStatsCollectorCallback>& callback : |
150 callbacks_) { | 156 callbacks_) { |
151 callback->OnStatsDelivered(cached_report_); | 157 callback->OnStatsDelivered(cached_report_); |
152 } | 158 } |
153 callbacks_.clear(); | 159 callbacks_.clear(); |
154 } | 160 } |
155 | 161 |
156 std::unique_ptr<RTCPeerConnectionStats> | 162 void RTCStatsCollector::ProduceCertificateStats_s( |
157 RTCStatsCollector::ProducePeerConnectionStats_s(int64_t timestamp_us) const { | 163 int64_t timestamp_us, const SessionStats& session_stats, |
| 164 RTCStatsReport* report) const { |
| 165 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 166 for (const auto& transport : session_stats.transport_stats) { |
| 167 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate; |
| 168 if (pc_->session()->GetLocalCertificate( |
| 169 transport.second.transport_name, &local_certificate)) { |
| 170 ProduceCertificateStatsFromSSLCertificateAndChain_s( |
| 171 timestamp_us, &local_certificate->ssl_certificate(), report); |
| 172 } |
| 173 std::unique_ptr<rtc::SSLCertificate> remote_certificate = |
| 174 pc_->session()->GetRemoteSSLCertificate( |
| 175 transport.second.transport_name); |
| 176 if (remote_certificate) { |
| 177 ProduceCertificateStatsFromSSLCertificateAndChain_s( |
| 178 timestamp_us, remote_certificate.get(), report); |
| 179 } |
| 180 } |
| 181 } |
| 182 |
| 183 void RTCStatsCollector::ProduceCertificateStatsFromSSLCertificateAndChain_s( |
| 184 int64_t timestamp_us, const rtc::SSLCertificate* certificate, |
| 185 RTCStatsReport* report) const { |
| 186 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 187 std::unique_ptr<rtc::SSLCertificateStats> ssl_stats = |
| 188 certificate->GetStats(); |
| 189 RTCCertificateStats* prev_stats = nullptr; |
| 190 for (rtc::SSLCertificateStats* s = ssl_stats.get(); s; |
| 191 s = s->issuer.get()) { |
| 192 RTCCertificateStats* stats = new RTCCertificateStats( |
| 193 "RTCCertificate_" + s->fingerprint, timestamp_us); |
| 194 stats->fingerprint = s->fingerprint; |
| 195 stats->fingerprint_algorithm = s->fingerprint_algorithm; |
| 196 stats->base64_certificate = s->base64_certificate; |
| 197 if (prev_stats) |
| 198 prev_stats->issuer_certificate_id = stats->id(); |
| 199 report->AddStats(std::unique_ptr<RTCCertificateStats>(stats)); |
| 200 prev_stats = stats; |
| 201 } |
| 202 } |
| 203 |
| 204 void RTCStatsCollector::ProducePeerConnectionStats_s( |
| 205 int64_t timestamp_us, RTCStatsReport* report) const { |
158 RTC_DCHECK(signaling_thread_->IsCurrent()); | 206 RTC_DCHECK(signaling_thread_->IsCurrent()); |
159 // TODO(hbos): If data channels are removed from the peer connection this will | 207 // TODO(hbos): If data channels are removed from the peer connection this will |
160 // yield incorrect counts. Address before closing crbug.com/636818. See | 208 // yield incorrect counts. Address before closing crbug.com/636818. See |
161 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*. | 209 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*. |
162 uint32_t data_channels_opened = 0; | 210 uint32_t data_channels_opened = 0; |
163 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = | 211 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = |
164 pc_->sctp_data_channels(); | 212 pc_->sctp_data_channels(); |
165 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { | 213 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { |
166 if (data_channel->state() == DataChannelInterface::kOpen) | 214 if (data_channel->state() == DataChannelInterface::kOpen) |
167 ++data_channels_opened; | 215 ++data_channels_opened; |
168 } | 216 } |
169 // There is always just one |RTCPeerConnectionStats| so its |id| can be a | 217 // There is always just one |RTCPeerConnectionStats| so its |id| can be a |
170 // constant. | 218 // constant. |
171 std::unique_ptr<RTCPeerConnectionStats> stats( | 219 std::unique_ptr<RTCPeerConnectionStats> stats( |
172 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); | 220 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); |
173 stats->data_channels_opened = data_channels_opened; | 221 stats->data_channels_opened = data_channels_opened; |
174 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - | 222 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - |
175 data_channels_opened; | 223 data_channels_opened; |
176 return stats; | 224 report->AddStats(std::move(stats)); |
177 } | 225 } |
178 | 226 |
179 } // namespace webrtc | 227 } // namespace webrtc |
OLD | NEW |