blob: dc2b1896cc0ad1ad44630c1cbc8ccc1225e69338 [file] [log] [blame]
hbosd565b732016-08-30 14:04:35 -07001/*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
hbos74e1a4f2016-09-15 23:33:01 -070011#include "webrtc/api/rtcstatscollector.h"
hbosd565b732016-08-30 14:04:35 -070012
13#include <memory>
14#include <utility>
15#include <vector>
16
17#include "webrtc/api/peerconnection.h"
hbos6ab97ce2016-10-03 14:16:56 -070018#include "webrtc/api/webrtcsession.h"
hbosd565b732016-08-30 14:04:35 -070019#include "webrtc/base/checks.h"
hbosab9f6e42016-10-07 02:18:47 -070020#include "webrtc/p2p/base/candidate.h"
hbos2fa7c672016-10-24 04:00:05 -070021#include "webrtc/p2p/base/p2pconstants.h"
hbosab9f6e42016-10-07 02:18:47 -070022#include "webrtc/p2p/base/port.h"
hbosd565b732016-08-30 14:04:35 -070023
24namespace webrtc {
25
hboscc555c52016-10-18 12:48:31 -070026namespace {
27
hbos2fa7c672016-10-24 04:00:05 -070028std::string RTCCertificateIDFromFingerprint(const std::string& fingerprint) {
29 return "RTCCertificate_" + fingerprint;
30}
31
32std::string RTCIceCandidatePairStatsIDFromConnectionInfo(
33 const cricket::ConnectionInfo& info) {
34 return "RTCIceCandidatePair_" + info.local_candidate.id() + "_" +
35 info.remote_candidate.id();
36}
37
38std::string RTCTransportStatsIDFromTransportChannel(
39 const std::string& transport_name, int channel_component) {
40 return "RTCTransport_" + transport_name + "_" +
41 rtc::ToString<>(channel_component);
42}
43
hbosab9f6e42016-10-07 02:18:47 -070044const char* CandidateTypeToRTCIceCandidateType(const std::string& type) {
45 if (type == cricket::LOCAL_PORT_TYPE)
46 return RTCIceCandidateType::kHost;
47 if (type == cricket::STUN_PORT_TYPE)
48 return RTCIceCandidateType::kSrflx;
49 if (type == cricket::PRFLX_PORT_TYPE)
50 return RTCIceCandidateType::kPrflx;
51 if (type == cricket::RELAY_PORT_TYPE)
52 return RTCIceCandidateType::kRelay;
53 RTC_NOTREACHED();
54 return nullptr;
55}
56
hboscc555c52016-10-18 12:48:31 -070057const char* DataStateToRTCDataChannelState(
58 DataChannelInterface::DataState state) {
59 switch (state) {
60 case DataChannelInterface::kConnecting:
61 return RTCDataChannelState::kConnecting;
62 case DataChannelInterface::kOpen:
63 return RTCDataChannelState::kOpen;
64 case DataChannelInterface::kClosing:
65 return RTCDataChannelState::kClosing;
66 case DataChannelInterface::kClosed:
67 return RTCDataChannelState::kClosed;
68 default:
69 RTC_NOTREACHED();
70 return nullptr;
71 }
72}
73
hbos02ba2112016-10-28 05:14:53 -070074void ProduceCertificateStatsFromSSLCertificateStats(
75 int64_t timestamp_us, const rtc::SSLCertificateStats& certificate_stats,
76 RTCStatsReport* report) {
77 RTCCertificateStats* prev_certificate_stats = nullptr;
78 for (const rtc::SSLCertificateStats* s = &certificate_stats; s;
79 s = s->issuer.get()) {
80 RTCCertificateStats* certificate_stats = new RTCCertificateStats(
81 RTCCertificateIDFromFingerprint(s->fingerprint), timestamp_us);
82 certificate_stats->fingerprint = s->fingerprint;
83 certificate_stats->fingerprint_algorithm = s->fingerprint_algorithm;
84 certificate_stats->base64_certificate = s->base64_certificate;
85 if (prev_certificate_stats)
86 prev_certificate_stats->issuer_certificate_id = certificate_stats->id();
87 report->AddStats(std::unique_ptr<RTCCertificateStats>(certificate_stats));
88 prev_certificate_stats = certificate_stats;
89 }
90}
91
92const std::string& ProduceIceCandidateStats(
93 int64_t timestamp_us, const cricket::Candidate& candidate, bool is_local,
94 RTCStatsReport* report) {
95 const std::string& id = "RTCIceCandidate_" + candidate.id();
96 const RTCStats* stats = report->Get(id);
97 if (!stats) {
98 std::unique_ptr<RTCIceCandidateStats> candidate_stats;
99 if (is_local)
100 candidate_stats.reset(new RTCLocalIceCandidateStats(id, timestamp_us));
101 else
102 candidate_stats.reset(new RTCRemoteIceCandidateStats(id, timestamp_us));
103 candidate_stats->ip = candidate.address().ipaddr().ToString();
104 candidate_stats->port = static_cast<int32_t>(candidate.address().port());
105 candidate_stats->protocol = candidate.protocol();
106 candidate_stats->candidate_type = CandidateTypeToRTCIceCandidateType(
107 candidate.type());
108 candidate_stats->priority = static_cast<int32_t>(candidate.priority());
109
110 stats = candidate_stats.get();
111 report->AddStats(std::move(candidate_stats));
112 }
113 RTC_DCHECK_EQ(stats->type(), is_local ? RTCLocalIceCandidateStats::kType
114 : RTCRemoteIceCandidateStats::kType);
115 return stats->id();
116}
117
hboscc555c52016-10-18 12:48:31 -0700118} // namespace
119
hbosc82f2e12016-09-05 01:36:50 -0700120rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create(
121 PeerConnection* pc, int64_t cache_lifetime_us) {
122 return rtc::scoped_refptr<RTCStatsCollector>(
123 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us));
124}
125
126RTCStatsCollector::RTCStatsCollector(PeerConnection* pc,
127 int64_t cache_lifetime_us)
hbosd565b732016-08-30 14:04:35 -0700128 : pc_(pc),
hbosc82f2e12016-09-05 01:36:50 -0700129 signaling_thread_(pc->session()->signaling_thread()),
130 worker_thread_(pc->session()->worker_thread()),
131 network_thread_(pc->session()->network_thread()),
132 num_pending_partial_reports_(0),
133 partial_report_timestamp_us_(0),
hbos0e6758d2016-08-31 07:57:36 -0700134 cache_timestamp_us_(0),
135 cache_lifetime_us_(cache_lifetime_us) {
hbosd565b732016-08-30 14:04:35 -0700136 RTC_DCHECK(pc_);
hbosc82f2e12016-09-05 01:36:50 -0700137 RTC_DCHECK(signaling_thread_);
138 RTC_DCHECK(worker_thread_);
139 RTC_DCHECK(network_thread_);
hbos0e6758d2016-08-31 07:57:36 -0700140 RTC_DCHECK_GE(cache_lifetime_us_, 0);
hbosd565b732016-08-30 14:04:35 -0700141}
142
hbosc82f2e12016-09-05 01:36:50 -0700143void RTCStatsCollector::GetStatsReport(
144 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) {
145 RTC_DCHECK(signaling_thread_->IsCurrent());
146 RTC_DCHECK(callback);
147 callbacks_.push_back(callback);
148
hbos0e6758d2016-08-31 07:57:36 -0700149 // "Now" using a monotonically increasing timer.
150 int64_t cache_now_us = rtc::TimeMicros();
151 if (cached_report_ &&
152 cache_now_us - cache_timestamp_us_ <= cache_lifetime_us_) {
hbosc82f2e12016-09-05 01:36:50 -0700153 // We have a fresh cached report to deliver.
154 DeliverCachedReport();
155 } else if (!num_pending_partial_reports_) {
156 // Only start gathering stats if we're not already gathering stats. In the
157 // case of already gathering stats, |callback_| will be invoked when there
158 // are no more pending partial reports.
159
160 // "Now" using a system clock, relative to the UNIX epoch (Jan 1, 1970,
161 // UTC), in microseconds. The system clock could be modified and is not
162 // necessarily monotonically increasing.
nissecdf37a92016-09-13 23:41:47 -0700163 int64_t timestamp_us = rtc::TimeUTCMicros();
hbosc82f2e12016-09-05 01:36:50 -0700164
165 num_pending_partial_reports_ = 3;
166 partial_report_timestamp_us_ = cache_now_us;
167 invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_,
168 rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnSignalingThread,
169 rtc::scoped_refptr<RTCStatsCollector>(this), timestamp_us));
170 invoker_.AsyncInvoke<void>(RTC_FROM_HERE, worker_thread_,
171 rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnWorkerThread,
172 rtc::scoped_refptr<RTCStatsCollector>(this), timestamp_us));
173 invoker_.AsyncInvoke<void>(RTC_FROM_HERE, network_thread_,
174 rtc::Bind(&RTCStatsCollector::ProducePartialResultsOnNetworkThread,
175 rtc::scoped_refptr<RTCStatsCollector>(this), timestamp_us));
hbos0e6758d2016-08-31 07:57:36 -0700176 }
hbosd565b732016-08-30 14:04:35 -0700177}
178
179void RTCStatsCollector::ClearCachedStatsReport() {
hbosc82f2e12016-09-05 01:36:50 -0700180 RTC_DCHECK(signaling_thread_->IsCurrent());
hbosd565b732016-08-30 14:04:35 -0700181 cached_report_ = nullptr;
182}
183
hbosc82f2e12016-09-05 01:36:50 -0700184void RTCStatsCollector::ProducePartialResultsOnSignalingThread(
185 int64_t timestamp_us) {
186 RTC_DCHECK(signaling_thread_->IsCurrent());
perkj7eaa8362016-10-31 23:52:25 -0700187 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
hbosc82f2e12016-09-05 01:36:50 -0700188
hbos6ab97ce2016-10-03 14:16:56 -0700189 SessionStats session_stats;
190 if (pc_->session()->GetTransportStats(&session_stats)) {
hbos2fa7c672016-10-24 04:00:05 -0700191 std::map<std::string, CertificateStatsPair> transport_cert_stats =
192 PrepareTransportCertificateStats_s(session_stats);
193
194 ProduceCertificateStats_s(
195 timestamp_us, transport_cert_stats, report.get());
196 ProduceIceCandidateAndPairStats_s(
197 timestamp_us, session_stats, report.get());
198 ProduceTransportStats_s(
199 timestamp_us, session_stats, transport_cert_stats, report.get());
hbos6ab97ce2016-10-03 14:16:56 -0700200 }
hboscc555c52016-10-18 12:48:31 -0700201 ProduceDataChannelStats_s(timestamp_us, report.get());
hbos6ab97ce2016-10-03 14:16:56 -0700202 ProducePeerConnectionStats_s(timestamp_us, report.get());
hbosc82f2e12016-09-05 01:36:50 -0700203
204 AddPartialResults(report);
205}
206
207void RTCStatsCollector::ProducePartialResultsOnWorkerThread(
208 int64_t timestamp_us) {
209 RTC_DCHECK(worker_thread_->IsCurrent());
perkj7eaa8362016-10-31 23:52:25 -0700210 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
hbosc82f2e12016-09-05 01:36:50 -0700211
212 // TODO(hbos): Gather stats on worker thread.
213
214 AddPartialResults(report);
215}
216
217void RTCStatsCollector::ProducePartialResultsOnNetworkThread(
218 int64_t timestamp_us) {
219 RTC_DCHECK(network_thread_->IsCurrent());
perkj7eaa8362016-10-31 23:52:25 -0700220 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
hbosc82f2e12016-09-05 01:36:50 -0700221
222 // TODO(hbos): Gather stats on network thread.
223
224 AddPartialResults(report);
225}
226
227void RTCStatsCollector::AddPartialResults(
228 const rtc::scoped_refptr<RTCStatsReport>& partial_report) {
229 if (!signaling_thread_->IsCurrent()) {
230 invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_,
231 rtc::Bind(&RTCStatsCollector::AddPartialResults_s,
232 rtc::scoped_refptr<RTCStatsCollector>(this),
233 partial_report));
234 return;
235 }
236 AddPartialResults_s(partial_report);
237}
238
239void RTCStatsCollector::AddPartialResults_s(
240 rtc::scoped_refptr<RTCStatsReport> partial_report) {
241 RTC_DCHECK(signaling_thread_->IsCurrent());
242 RTC_DCHECK_GT(num_pending_partial_reports_, 0);
243 if (!partial_report_)
244 partial_report_ = partial_report;
245 else
246 partial_report_->TakeMembersFrom(partial_report);
247 --num_pending_partial_reports_;
248 if (!num_pending_partial_reports_) {
249 cache_timestamp_us_ = partial_report_timestamp_us_;
250 cached_report_ = partial_report_;
251 partial_report_ = nullptr;
252 DeliverCachedReport();
253 }
254}
255
256void RTCStatsCollector::DeliverCachedReport() {
257 RTC_DCHECK(signaling_thread_->IsCurrent());
258 RTC_DCHECK(!callbacks_.empty());
259 RTC_DCHECK(cached_report_);
260 for (const rtc::scoped_refptr<RTCStatsCollectorCallback>& callback :
261 callbacks_) {
262 callback->OnStatsDelivered(cached_report_);
263 }
264 callbacks_.clear();
hbosd565b732016-08-30 14:04:35 -0700265}
266
hbos6ab97ce2016-10-03 14:16:56 -0700267void RTCStatsCollector::ProduceCertificateStats_s(
hbos2fa7c672016-10-24 04:00:05 -0700268 int64_t timestamp_us,
269 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
hbos6ab97ce2016-10-03 14:16:56 -0700270 RTCStatsReport* report) const {
271 RTC_DCHECK(signaling_thread_->IsCurrent());
hbos02ba2112016-10-28 05:14:53 -0700272 for (const auto& transport_cert_stats_pair : transport_cert_stats) {
273 if (transport_cert_stats_pair.second.local) {
274 ProduceCertificateStatsFromSSLCertificateStats(
275 timestamp_us, *transport_cert_stats_pair.second.local.get(), report);
hbos6ab97ce2016-10-03 14:16:56 -0700276 }
hbos02ba2112016-10-28 05:14:53 -0700277 if (transport_cert_stats_pair.second.remote) {
278 ProduceCertificateStatsFromSSLCertificateStats(
279 timestamp_us, *transport_cert_stats_pair.second.remote.get(), report);
hbos6ab97ce2016-10-03 14:16:56 -0700280 }
281 }
282}
283
hboscc555c52016-10-18 12:48:31 -0700284void RTCStatsCollector::ProduceDataChannelStats_s(
285 int64_t timestamp_us, RTCStatsReport* report) const {
286 RTC_DCHECK(signaling_thread_->IsCurrent());
287 for (const rtc::scoped_refptr<DataChannel>& data_channel :
288 pc_->sctp_data_channels()) {
289 std::unique_ptr<RTCDataChannelStats> data_channel_stats(
290 new RTCDataChannelStats(
291 "RTCDataChannel_" + rtc::ToString<>(data_channel->id()),
292 timestamp_us));
293 data_channel_stats->label = data_channel->label();
294 data_channel_stats->protocol = data_channel->protocol();
295 data_channel_stats->datachannelid = data_channel->id();
296 data_channel_stats->state =
297 DataStateToRTCDataChannelState(data_channel->state());
298 data_channel_stats->messages_sent = data_channel->messages_sent();
299 data_channel_stats->bytes_sent = data_channel->bytes_sent();
300 data_channel_stats->messages_received = data_channel->messages_received();
301 data_channel_stats->bytes_received = data_channel->bytes_received();
302 report->AddStats(std::move(data_channel_stats));
303 }
304}
305
hbosab9f6e42016-10-07 02:18:47 -0700306void RTCStatsCollector::ProduceIceCandidateAndPairStats_s(
307 int64_t timestamp_us, const SessionStats& session_stats,
308 RTCStatsReport* report) const {
309 RTC_DCHECK(signaling_thread_->IsCurrent());
hbosc47a0c32016-10-11 14:54:49 -0700310 for (const auto& transport_stats : session_stats.transport_stats) {
311 for (const auto& channel_stats : transport_stats.second.channel_stats) {
312 for (const cricket::ConnectionInfo& info :
313 channel_stats.connection_infos) {
hbosc47a0c32016-10-11 14:54:49 -0700314 std::unique_ptr<RTCIceCandidatePairStats> candidate_pair_stats(
hbos2fa7c672016-10-24 04:00:05 -0700315 new RTCIceCandidatePairStats(
316 RTCIceCandidatePairStatsIDFromConnectionInfo(info),
317 timestamp_us));
hbosc47a0c32016-10-11 14:54:49 -0700318
hbosab9f6e42016-10-07 02:18:47 -0700319 // TODO(hbos): There could be other candidates that are not paired with
320 // anything. We don't have a complete list. Local candidates come from
321 // Port objects, and prflx candidates (both local and remote) are only
322 // stored in candidate pairs. crbug.com/632723
hbos02ba2112016-10-28 05:14:53 -0700323 candidate_pair_stats->local_candidate_id = ProduceIceCandidateStats(
hbosab9f6e42016-10-07 02:18:47 -0700324 timestamp_us, info.local_candidate, true, report);
hbos02ba2112016-10-28 05:14:53 -0700325 candidate_pair_stats->remote_candidate_id = ProduceIceCandidateStats(
hbosab9f6e42016-10-07 02:18:47 -0700326 timestamp_us, info.remote_candidate, false, report);
hbosc47a0c32016-10-11 14:54:49 -0700327
hbosc47a0c32016-10-11 14:54:49 -0700328 // TODO(hbos): This writable is different than the spec. It goes to
329 // false after a certain amount of time without a response passes.
330 // crbug.com/633550
331 candidate_pair_stats->writable = info.writable;
hbosc47a0c32016-10-11 14:54:49 -0700332 candidate_pair_stats->bytes_sent =
333 static_cast<uint64_t>(info.sent_total_bytes);
334 candidate_pair_stats->bytes_received =
335 static_cast<uint64_t>(info.recv_total_bytes);
hbosc47a0c32016-10-11 14:54:49 -0700336 // TODO(hbos): The |info.rtt| measurement is smoothed. It shouldn't be
337 // smoothed according to the spec. crbug.com/633550. See
338 // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatepairstats-currentrtt
339 candidate_pair_stats->current_rtt =
perkj7eaa8362016-10-31 23:52:25 -0700340 static_cast<double>(info.rtt) / 1000.0;
hbosc47a0c32016-10-11 14:54:49 -0700341 candidate_pair_stats->requests_sent =
342 static_cast<uint64_t>(info.sent_ping_requests_total);
343 candidate_pair_stats->responses_received =
344 static_cast<uint64_t>(info.recv_ping_responses);
345 candidate_pair_stats->responses_sent =
346 static_cast<uint64_t>(info.sent_ping_responses);
hbosc47a0c32016-10-11 14:54:49 -0700347
348 report->AddStats(std::move(candidate_pair_stats));
hbosab9f6e42016-10-07 02:18:47 -0700349 }
350 }
351 }
352}
353
hbos6ab97ce2016-10-03 14:16:56 -0700354void RTCStatsCollector::ProducePeerConnectionStats_s(
355 int64_t timestamp_us, RTCStatsReport* report) const {
hbosc82f2e12016-09-05 01:36:50 -0700356 RTC_DCHECK(signaling_thread_->IsCurrent());
hbosd565b732016-08-30 14:04:35 -0700357 // TODO(hbos): If data channels are removed from the peer connection this will
358 // yield incorrect counts. Address before closing crbug.com/636818. See
359 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*.
360 uint32_t data_channels_opened = 0;
361 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels =
362 pc_->sctp_data_channels();
363 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) {
364 if (data_channel->state() == DataChannelInterface::kOpen)
365 ++data_channels_opened;
366 }
367 // There is always just one |RTCPeerConnectionStats| so its |id| can be a
368 // constant.
369 std::unique_ptr<RTCPeerConnectionStats> stats(
hbos0e6758d2016-08-31 07:57:36 -0700370 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
hbosd565b732016-08-30 14:04:35 -0700371 stats->data_channels_opened = data_channels_opened;
372 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) -
373 data_channels_opened;
hbos6ab97ce2016-10-03 14:16:56 -0700374 report->AddStats(std::move(stats));
hbosd565b732016-08-30 14:04:35 -0700375}
376
hbos2fa7c672016-10-24 04:00:05 -0700377void RTCStatsCollector::ProduceTransportStats_s(
378 int64_t timestamp_us, const SessionStats& session_stats,
379 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
380 RTCStatsReport* report) const {
381 RTC_DCHECK(signaling_thread_->IsCurrent());
382 for (const auto& transport : session_stats.transport_stats) {
383 // Get reference to RTCP channel, if it exists.
384 std::string rtcp_transport_stats_id;
385 for (const auto& channel_stats : transport.second.channel_stats) {
386 if (channel_stats.component ==
387 cricket::ICE_CANDIDATE_COMPONENT_RTCP) {
388 rtcp_transport_stats_id = RTCTransportStatsIDFromTransportChannel(
389 transport.second.transport_name, channel_stats.component);
390 break;
391 }
392 }
393
394 // Get reference to local and remote certificates of this transport, if they
395 // exist.
396 const auto& certificate_stats_it = transport_cert_stats.find(
397 transport.second.transport_name);
398 RTC_DCHECK(certificate_stats_it != transport_cert_stats.cend());
399 std::string local_certificate_id;
400 if (certificate_stats_it->second.local) {
401 local_certificate_id = RTCCertificateIDFromFingerprint(
402 certificate_stats_it->second.local->fingerprint);
403 }
404 std::string remote_certificate_id;
405 if (certificate_stats_it->second.remote) {
406 remote_certificate_id = RTCCertificateIDFromFingerprint(
407 certificate_stats_it->second.remote->fingerprint);
408 }
409
410 // There is one transport stats for each channel.
411 for (const auto& channel_stats : transport.second.channel_stats) {
412 std::unique_ptr<RTCTransportStats> transport_stats(
413 new RTCTransportStats(
414 RTCTransportStatsIDFromTransportChannel(
415 transport.second.transport_name, channel_stats.component),
416 timestamp_us));
417 transport_stats->bytes_sent = 0;
418 transport_stats->bytes_received = 0;
419 transport_stats->active_connection = false;
420 for (const cricket::ConnectionInfo& info :
421 channel_stats.connection_infos) {
422 *transport_stats->bytes_sent += info.sent_total_bytes;
423 *transport_stats->bytes_received += info.recv_total_bytes;
424 if (info.best_connection) {
425 transport_stats->active_connection = true;
426 transport_stats->selected_candidate_pair_id =
427 RTCIceCandidatePairStatsIDFromConnectionInfo(info);
428 }
429 }
430 if (channel_stats.component != cricket::ICE_CANDIDATE_COMPONENT_RTCP &&
431 !rtcp_transport_stats_id.empty()) {
432 transport_stats->rtcp_transport_stats_id = rtcp_transport_stats_id;
433 }
434 if (!local_certificate_id.empty())
435 transport_stats->local_certificate_id = local_certificate_id;
436 if (!remote_certificate_id.empty())
437 transport_stats->remote_certificate_id = remote_certificate_id;
438 report->AddStats(std::move(transport_stats));
439 }
440 }
441}
442
443std::map<std::string, RTCStatsCollector::CertificateStatsPair>
444RTCStatsCollector::PrepareTransportCertificateStats_s(
445 const SessionStats& session_stats) const {
446 RTC_DCHECK(signaling_thread_->IsCurrent());
447 std::map<std::string, CertificateStatsPair> transport_cert_stats;
448 for (const auto& transport_stats : session_stats.transport_stats) {
449 CertificateStatsPair certificate_stats_pair;
450 rtc::scoped_refptr<rtc::RTCCertificate> local_certificate;
451 if (pc_->session()->GetLocalCertificate(
452 transport_stats.second.transport_name, &local_certificate)) {
453 certificate_stats_pair.local =
454 local_certificate->ssl_certificate().GetStats();
455 }
456 std::unique_ptr<rtc::SSLCertificate> remote_certificate =
457 pc_->session()->GetRemoteSSLCertificate(
458 transport_stats.second.transport_name);
459 if (remote_certificate) {
460 certificate_stats_pair.remote = remote_certificate->GetStats();
461 }
462 transport_cert_stats.insert(
463 std::make_pair(transport_stats.second.transport_name,
464 std::move(certificate_stats_pair)));
465 }
466 return transport_cert_stats;
467}
468
hboscc555c52016-10-18 12:48:31 -0700469const char* CandidateTypeToRTCIceCandidateTypeForTesting(
470 const std::string& type) {
471 return CandidateTypeToRTCIceCandidateType(type);
472}
473
474const char* DataStateToRTCDataChannelStateForTesting(
475 DataChannelInterface::DataState state) {
476 return DataStateToRTCDataChannelState(state);
477}
478
hbosd565b732016-08-30 14:04:35 -0700479} // namespace webrtc