Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: webrtc/api/rtcstatscollector.cc

Issue 2384143002: RTCIceCandidateStats added. (Closed)
Patch Set: Addressed comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/rtcstatscollector.h ('k') | webrtc/api/rtcstatscollector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
22 #include "webrtc/p2p/base/port.h"
21 23
22 namespace webrtc { 24 namespace webrtc {
23 25
26 const char* CandidateTypeToRTCIceCandidateType(const std::string& type) {
27 if (type == cricket::LOCAL_PORT_TYPE)
28 return RTCIceCandidateType::kHost;
29 if (type == cricket::STUN_PORT_TYPE)
30 return RTCIceCandidateType::kSrflx;
31 if (type == cricket::PRFLX_PORT_TYPE)
32 return RTCIceCandidateType::kPrflx;
33 if (type == cricket::RELAY_PORT_TYPE)
34 return RTCIceCandidateType::kRelay;
35 RTC_NOTREACHED();
36 return nullptr;
37 }
38
24 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create( 39 rtc::scoped_refptr<RTCStatsCollector> RTCStatsCollector::Create(
25 PeerConnection* pc, int64_t cache_lifetime_us) { 40 PeerConnection* pc, int64_t cache_lifetime_us) {
26 return rtc::scoped_refptr<RTCStatsCollector>( 41 return rtc::scoped_refptr<RTCStatsCollector>(
27 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us)); 42 new rtc::RefCountedObject<RTCStatsCollector>(pc, cache_lifetime_us));
28 } 43 }
29 44
30 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, 45 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc,
31 int64_t cache_lifetime_us) 46 int64_t cache_lifetime_us)
32 : pc_(pc), 47 : pc_(pc),
33 signaling_thread_(pc->session()->signaling_thread()), 48 signaling_thread_(pc->session()->signaling_thread()),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 101 }
87 102
88 void RTCStatsCollector::ProducePartialResultsOnSignalingThread( 103 void RTCStatsCollector::ProducePartialResultsOnSignalingThread(
89 int64_t timestamp_us) { 104 int64_t timestamp_us) {
90 RTC_DCHECK(signaling_thread_->IsCurrent()); 105 RTC_DCHECK(signaling_thread_->IsCurrent());
91 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); 106 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
92 107
93 SessionStats session_stats; 108 SessionStats session_stats;
94 if (pc_->session()->GetTransportStats(&session_stats)) { 109 if (pc_->session()->GetTransportStats(&session_stats)) {
95 ProduceCertificateStats_s(timestamp_us, session_stats, report.get()); 110 ProduceCertificateStats_s(timestamp_us, session_stats, report.get());
111 ProduceIceCandidateAndPairStats_s(timestamp_us, session_stats,
112 report.get());
96 } 113 }
97 ProducePeerConnectionStats_s(timestamp_us, report.get()); 114 ProducePeerConnectionStats_s(timestamp_us, report.get());
98 115
99 AddPartialResults(report); 116 AddPartialResults(report);
100 } 117 }
101 118
102 void RTCStatsCollector::ProducePartialResultsOnWorkerThread( 119 void RTCStatsCollector::ProducePartialResultsOnWorkerThread(
103 int64_t timestamp_us) { 120 int64_t timestamp_us) {
104 RTC_DCHECK(worker_thread_->IsCurrent()); 121 RTC_DCHECK(worker_thread_->IsCurrent());
105 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); 122 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 stats->fingerprint = s->fingerprint; 211 stats->fingerprint = s->fingerprint;
195 stats->fingerprint_algorithm = s->fingerprint_algorithm; 212 stats->fingerprint_algorithm = s->fingerprint_algorithm;
196 stats->base64_certificate = s->base64_certificate; 213 stats->base64_certificate = s->base64_certificate;
197 if (prev_stats) 214 if (prev_stats)
198 prev_stats->issuer_certificate_id = stats->id(); 215 prev_stats->issuer_certificate_id = stats->id();
199 report->AddStats(std::unique_ptr<RTCCertificateStats>(stats)); 216 report->AddStats(std::unique_ptr<RTCCertificateStats>(stats));
200 prev_stats = stats; 217 prev_stats = stats;
201 } 218 }
202 } 219 }
203 220
221 void RTCStatsCollector::ProduceIceCandidateAndPairStats_s(
222 int64_t timestamp_us, const SessionStats& session_stats,
223 RTCStatsReport* report) const {
224 RTC_DCHECK(signaling_thread_->IsCurrent());
225 for (const auto& transport : session_stats.transport_stats) {
226 for (const auto& channel : transport.second.channel_stats) {
227 for (const cricket::ConnectionInfo& info : channel.connection_infos) {
228 // TODO(hbos): Produce |RTCIceCandidatePairStats| referencing the
229 // resulting |RTCIceCandidateStats| pair. crbug.com/633550
230 // TODO(hbos): There could be other candidates that are not paired with
231 // anything. We don't have a complete list. Local candidates come from
232 // Port objects, and prflx candidates (both local and remote) are only
233 // stored in candidate pairs. crbug.com/632723
234 ProduceIceCandidateStats_s(
235 timestamp_us, info.local_candidate, true, report);
236 ProduceIceCandidateStats_s(
237 timestamp_us, info.remote_candidate, false, report);
238 }
239 }
240 }
241 }
242
243 const std::string& RTCStatsCollector::ProduceIceCandidateStats_s(
244 int64_t timestamp_us, const cricket::Candidate& candidate, bool is_local,
245 RTCStatsReport* report) const {
246 RTC_DCHECK(signaling_thread_->IsCurrent());
247 const std::string& id = "RTCIceCandidate_" + candidate.id();
248 const RTCStats* stats = report->Get(id);
249 if (!stats) {
250 std::unique_ptr<RTCIceCandidateStats> candidate_stats;
251 if (is_local) {
252 candidate_stats.reset(
253 new RTCLocalIceCandidateStats(id, timestamp_us));
254 } else {
255 candidate_stats.reset(
256 new RTCRemoteIceCandidateStats(id, timestamp_us));
257 }
258 candidate_stats->ip = candidate.address().ipaddr().ToString();
259 candidate_stats->port = static_cast<int32_t>(candidate.address().port());
260 candidate_stats->protocol = candidate.protocol();
261 candidate_stats->candidate_type = CandidateTypeToRTCIceCandidateType(
262 candidate.type());
263 candidate_stats->priority = static_cast<int32_t>(candidate.priority());
264 // TODO(hbos): Define candidate_stats->url. crbug.com/632723
265
266 stats = candidate_stats.get();
267 report->AddStats(std::move(candidate_stats));
268 }
269 RTC_DCHECK_EQ(stats->type(), is_local ? RTCLocalIceCandidateStats::kType
270 : RTCRemoteIceCandidateStats::kType);
271 return stats->id();
272 }
273
204 void RTCStatsCollector::ProducePeerConnectionStats_s( 274 void RTCStatsCollector::ProducePeerConnectionStats_s(
205 int64_t timestamp_us, RTCStatsReport* report) const { 275 int64_t timestamp_us, RTCStatsReport* report) const {
206 RTC_DCHECK(signaling_thread_->IsCurrent()); 276 RTC_DCHECK(signaling_thread_->IsCurrent());
207 // TODO(hbos): If data channels are removed from the peer connection this will 277 // TODO(hbos): If data channels are removed from the peer connection this will
208 // yield incorrect counts. Address before closing crbug.com/636818. See 278 // yield incorrect counts. Address before closing crbug.com/636818. See
209 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*. 279 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*.
210 uint32_t data_channels_opened = 0; 280 uint32_t data_channels_opened = 0;
211 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = 281 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels =
212 pc_->sctp_data_channels(); 282 pc_->sctp_data_channels();
213 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { 283 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) {
214 if (data_channel->state() == DataChannelInterface::kOpen) 284 if (data_channel->state() == DataChannelInterface::kOpen)
215 ++data_channels_opened; 285 ++data_channels_opened;
216 } 286 }
217 // There is always just one |RTCPeerConnectionStats| so its |id| can be a 287 // There is always just one |RTCPeerConnectionStats| so its |id| can be a
218 // constant. 288 // constant.
219 std::unique_ptr<RTCPeerConnectionStats> stats( 289 std::unique_ptr<RTCPeerConnectionStats> stats(
220 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); 290 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
221 stats->data_channels_opened = data_channels_opened; 291 stats->data_channels_opened = data_channels_opened;
222 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - 292 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) -
223 data_channels_opened; 293 data_channels_opened;
224 report->AddStats(std::move(stats)); 294 report->AddStats(std::move(stats));
225 } 295 }
226 296
227 } // namespace webrtc 297 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/rtcstatscollector.h ('k') | webrtc/api/rtcstatscollector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698