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

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

Issue 2420473002: RTCDataChannelStats added. (Closed)
Patch Set: Addressed nit 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" 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
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
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 for (const rtc::scoped_refptr<DataChannel>& data_channel :
247 pc_->sctp_data_channels()) {
248 std::unique_ptr<RTCDataChannelStats> data_channel_stats(
249 new RTCDataChannelStats(
250 "RTCDataChannel_" + rtc::ToString<>(data_channel->id()),
251 timestamp_us));
252 data_channel_stats->label = data_channel->label();
253 data_channel_stats->protocol = data_channel->protocol();
254 data_channel_stats->datachannelid = data_channel->id();
255 data_channel_stats->state =
256 DataStateToRTCDataChannelState(data_channel->state());
257 data_channel_stats->messages_sent = data_channel->messages_sent();
258 data_channel_stats->bytes_sent = data_channel->bytes_sent();
259 data_channel_stats->messages_received = data_channel->messages_received();
260 data_channel_stats->bytes_received = data_channel->bytes_received();
261 report->AddStats(std::move(data_channel_stats));
262 }
263 }
264
221 void RTCStatsCollector::ProduceIceCandidateAndPairStats_s( 265 void RTCStatsCollector::ProduceIceCandidateAndPairStats_s(
222 int64_t timestamp_us, const SessionStats& session_stats, 266 int64_t timestamp_us, const SessionStats& session_stats,
223 RTCStatsReport* report) const { 267 RTCStatsReport* report) const {
224 RTC_DCHECK(signaling_thread_->IsCurrent()); 268 RTC_DCHECK(signaling_thread_->IsCurrent());
225 for (const auto& transport_stats : session_stats.transport_stats) { 269 for (const auto& transport_stats : session_stats.transport_stats) {
226 for (const auto& channel_stats : transport_stats.second.channel_stats) { 270 for (const auto& channel_stats : transport_stats.second.channel_stats) {
227 for (const cricket::ConnectionInfo& info : 271 for (const cricket::ConnectionInfo& info :
228 channel_stats.connection_infos) { 272 channel_stats.connection_infos) {
229 const std::string& id = "RTCIceCandidatePair_" + 273 const std::string& id = "RTCIceCandidatePair_" +
230 info.local_candidate.id() + "_" + info.remote_candidate.id(); 274 info.local_candidate.id() + "_" + info.remote_candidate.id();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // There is always just one |RTCPeerConnectionStats| so its |id| can be a 374 // There is always just one |RTCPeerConnectionStats| so its |id| can be a
331 // constant. 375 // constant.
332 std::unique_ptr<RTCPeerConnectionStats> stats( 376 std::unique_ptr<RTCPeerConnectionStats> stats(
333 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); 377 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
334 stats->data_channels_opened = data_channels_opened; 378 stats->data_channels_opened = data_channels_opened;
335 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - 379 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) -
336 data_channels_opened; 380 data_channels_opened;
337 report->AddStats(std::move(stats)); 381 report->AddStats(std::move(stats));
338 } 382 }
339 383
384 const char* CandidateTypeToRTCIceCandidateTypeForTesting(
385 const std::string& type) {
386 return CandidateTypeToRTCIceCandidateType(type);
387 }
388
389 const char* DataStateToRTCDataChannelStateForTesting(
390 DataChannelInterface::DataState state) {
391 return DataStateToRTCDataChannelState(state);
392 }
393
340 } // namespace webrtc 394 } // 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