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

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

Issue 2384143002: RTCIceCandidateStats added. (Closed)
Patch Set: 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
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): RTCIceCandidatePairStats referencing the resulting pair.
hta-webrtc 2016/10/04 14:12:45 Complete sentence: "TODO(hbos): Produce RTCIceCand
hbos 2016/10/05 10:16:30 Done.
229 // crbug.com/633550
230 ProduceIceCandidateStats_s(
231 timestamp_us, info.local_candidate, true, report);
232 ProduceIceCandidateStats_s(
233 timestamp_us, info.remote_candidate, false, report);
234 }
235 }
236 }
237 }
238
239 const std::string& RTCStatsCollector::ProduceIceCandidateStats_s(
240 int64_t timestamp_us, const cricket::Candidate& candidate, bool is_local,
241 RTCStatsReport* report) const {
242 RTC_DCHECK(signaling_thread_->IsCurrent());
243 std::string id = "RTCIceCandidate_" + candidate.id();
hta-webrtc 2016/10/04 14:12:45 This uses the same namespace for local and remote
hbos 2016/10/05 10:16:30 Since the ID should be based on the object that pr
hta-webrtc 2016/10/05 11:17:14 DCHECK seems good. What I'm not sure about is wher
hbos 2016/10/06 08:07:27 +deadbeef
244 const RTCStats* s = report->Get(id);
hta-webrtc 2016/10/04 14:12:45 Bad variable name.
hbos 2016/10/05 10:16:30 Done.
245 if (!s) {
246 std::unique_ptr<RTCIceCandidateStats> candidate_stats;
247 if (is_local) {
248 candidate_stats.reset(
249 new RTCLocalIceCandidateStats(std::move(id), timestamp_us));
250 } else {
251 candidate_stats.reset(
252 new RTCRemoteIceCandidateStats(std::move(id), timestamp_us));
253 }
254 candidate_stats->ip = candidate.address().ipaddr().ToString();
255 candidate_stats->port = static_cast<int32_t>(candidate.address().port());
256 candidate_stats->protocol = candidate.protocol();
257 candidate_stats->candidate_type = CandidateTypeToRTCIceCandidateType(
258 candidate.type());
259 candidate_stats->priority = static_cast<int32_t>(candidate.priority());
260 // TODO(hbos): Define candidate_stats->url. crbug.com/632723
261
262 s = candidate_stats.get();
263 report->AddStats(std::move(candidate_stats));
264 }
hta-webrtc 2016/10/04 14:12:45 What's the "else"? Is it an error to have duplicat
hbos 2016/10/05 10:16:30 It means we encountered the same candidate twice,
hta-webrtc 2016/10/05 11:17:14 Adding a reviewer who knows the cricket::Candidate
hbos 2016/10/06 08:07:27 +deadbeef
Taylor Brandstetter 2016/10/06 19:09:07 The same candidate can't be both a local and remot
hbos 2016/10/07 08:37:52 Acknowledged. Changing stats ID back to "RTCIceCan
265 return s->id();
266 }
267
204 void RTCStatsCollector::ProducePeerConnectionStats_s( 268 void RTCStatsCollector::ProducePeerConnectionStats_s(
205 int64_t timestamp_us, RTCStatsReport* report) const { 269 int64_t timestamp_us, RTCStatsReport* report) const {
206 RTC_DCHECK(signaling_thread_->IsCurrent()); 270 RTC_DCHECK(signaling_thread_->IsCurrent());
207 // TODO(hbos): If data channels are removed from the peer connection this will 271 // TODO(hbos): If data channels are removed from the peer connection this will
208 // yield incorrect counts. Address before closing crbug.com/636818. See 272 // yield incorrect counts. Address before closing crbug.com/636818. See
209 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*. 273 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*.
210 uint32_t data_channels_opened = 0; 274 uint32_t data_channels_opened = 0;
211 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = 275 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels =
212 pc_->sctp_data_channels(); 276 pc_->sctp_data_channels();
213 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { 277 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) {
214 if (data_channel->state() == DataChannelInterface::kOpen) 278 if (data_channel->state() == DataChannelInterface::kOpen)
215 ++data_channels_opened; 279 ++data_channels_opened;
216 } 280 }
217 // There is always just one |RTCPeerConnectionStats| so its |id| can be a 281 // There is always just one |RTCPeerConnectionStats| so its |id| can be a
218 // constant. 282 // constant.
219 std::unique_ptr<RTCPeerConnectionStats> stats( 283 std::unique_ptr<RTCPeerConnectionStats> stats(
220 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); 284 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
221 stats->data_channels_opened = data_channels_opened; 285 stats->data_channels_opened = data_channels_opened;
222 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - 286 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) -
223 data_channels_opened; 287 data_channels_opened;
224 report->AddStats(std::move(stats)); 288 report->AddStats(std::move(stats));
225 } 289 }
226 290
227 } // namespace webrtc 291 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698