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 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 | 224 |
225 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, | 225 RTCStatsCollector::RTCStatsCollector(PeerConnection* pc, |
226 int64_t cache_lifetime_us) | 226 int64_t cache_lifetime_us) |
227 : pc_(pc), | 227 : pc_(pc), |
228 signaling_thread_(pc->session()->signaling_thread()), | 228 signaling_thread_(pc->session()->signaling_thread()), |
229 worker_thread_(pc->session()->worker_thread()), | 229 worker_thread_(pc->session()->worker_thread()), |
230 network_thread_(pc->session()->network_thread()), | 230 network_thread_(pc->session()->network_thread()), |
231 num_pending_partial_reports_(0), | 231 num_pending_partial_reports_(0), |
232 partial_report_timestamp_us_(0), | 232 partial_report_timestamp_us_(0), |
233 cache_timestamp_us_(0), | 233 cache_timestamp_us_(0), |
234 cache_lifetime_us_(cache_lifetime_us) { | 234 cache_lifetime_us_(cache_lifetime_us), |
235 data_channels_opened_(0), | |
236 data_channels_closed_(0) { | |
235 RTC_DCHECK(pc_); | 237 RTC_DCHECK(pc_); |
236 RTC_DCHECK(signaling_thread_); | 238 RTC_DCHECK(signaling_thread_); |
237 RTC_DCHECK(worker_thread_); | 239 RTC_DCHECK(worker_thread_); |
238 RTC_DCHECK(network_thread_); | 240 RTC_DCHECK(network_thread_); |
239 RTC_DCHECK_GE(cache_lifetime_us_, 0); | 241 RTC_DCHECK_GE(cache_lifetime_us_, 0); |
240 } | 242 } |
241 | 243 |
242 void RTCStatsCollector::GetStatsReport( | 244 void RTCStatsCollector::GetStatsReport( |
243 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) { | 245 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) { |
244 RTC_DCHECK(signaling_thread_->IsCurrent()); | 246 RTC_DCHECK(signaling_thread_->IsCurrent()); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 | 465 |
464 report->AddStats(std::move(candidate_pair_stats)); | 466 report->AddStats(std::move(candidate_pair_stats)); |
465 } | 467 } |
466 } | 468 } |
467 } | 469 } |
468 } | 470 } |
469 | 471 |
470 void RTCStatsCollector::ProducePeerConnectionStats_s( | 472 void RTCStatsCollector::ProducePeerConnectionStats_s( |
471 int64_t timestamp_us, RTCStatsReport* report) const { | 473 int64_t timestamp_us, RTCStatsReport* report) const { |
472 RTC_DCHECK(signaling_thread_->IsCurrent()); | 474 RTC_DCHECK(signaling_thread_->IsCurrent()); |
473 // TODO(hbos): If data channels are removed from the peer connection this will | |
474 // yield incorrect counts. Address before closing crbug.com/636818. See | |
475 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*. | |
476 uint32_t data_channels_opened = 0; | |
477 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = | |
478 pc_->sctp_data_channels(); | |
479 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { | |
480 if (data_channel->state() == DataChannelInterface::kOpen) | |
481 ++data_channels_opened; | |
482 } | |
483 // There is always just one |RTCPeerConnectionStats| so its |id| can be a | |
484 // constant. | |
485 std::unique_ptr<RTCPeerConnectionStats> stats( | 475 std::unique_ptr<RTCPeerConnectionStats> stats( |
486 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); | 476 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); |
487 stats->data_channels_opened = data_channels_opened; | 477 stats->data_channels_opened = data_channels_opened_; |
488 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - | 478 stats->data_channels_closed = data_channels_closed_; |
489 data_channels_opened; | |
490 report->AddStats(std::move(stats)); | 479 report->AddStats(std::move(stats)); |
491 } | 480 } |
492 | 481 |
493 void RTCStatsCollector::ProduceRTPStreamStats_s( | 482 void RTCStatsCollector::ProduceRTPStreamStats_s( |
494 int64_t timestamp_us, const SessionStats& session_stats, | 483 int64_t timestamp_us, const SessionStats& session_stats, |
495 RTCStatsReport* report) const { | 484 RTCStatsReport* report) const { |
496 RTC_DCHECK(signaling_thread_->IsCurrent()); | 485 RTC_DCHECK(signaling_thread_->IsCurrent()); |
497 | 486 |
498 // Audio | 487 // Audio |
499 if (pc_->session()->voice_channel()) { | 488 if (pc_->session()->voice_channel()) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 if (remote_certificate) { | 657 if (remote_certificate) { |
669 certificate_stats_pair.remote = remote_certificate->GetStats(); | 658 certificate_stats_pair.remote = remote_certificate->GetStats(); |
670 } | 659 } |
671 transport_cert_stats.insert( | 660 transport_cert_stats.insert( |
672 std::make_pair(transport_stats.second.transport_name, | 661 std::make_pair(transport_stats.second.transport_name, |
673 std::move(certificate_stats_pair))); | 662 std::move(certificate_stats_pair))); |
674 } | 663 } |
675 return transport_cert_stats; | 664 return transport_cert_stats; |
676 } | 665 } |
677 | 666 |
667 void RTCStatsCollector::OnDataChannelOpened(DataChannel* channel) { | |
668 RTC_DCHECK(signaling_thread_->IsCurrent()); | |
669 if (opened_data_channels_.insert(channel).second) { | |
670 ++data_channels_opened_; | |
hta-webrtc
2016/11/03 13:49:58
Isn't this equvalent to
bool result = opened_data
hbos
2016/11/03 15:02:02
Done.
| |
671 } else { | |
672 RTC_NOTREACHED(); | |
673 } | |
674 } | |
675 | |
676 void RTCStatsCollector::OnDataChannelClosed(DataChannel* channel) { | |
677 RTC_DCHECK(signaling_thread_->IsCurrent()); | |
678 // Only channels that have been fully opened (and have increased the | |
679 // |data_channels_opened_| counter) increase the closed counter. | |
680 if (opened_data_channels_.find(channel) != opened_data_channels_.end()) { | |
681 ++data_channels_closed_; | |
hta-webrtc
2016/11/03 13:49:58
Is it possible to get into the state where a chann
hbos
2016/11/03 15:02:02
From looking at the code I think this would happen
Taylor Brandstetter
2016/11/09 00:32:48
Yes, this is definitely legal. Any kind of underly
| |
682 } | |
683 } | |
684 | |
685 void RTCStatsCollector::OnDataChannelOpenedForTesting(DataChannel* channel) { | |
686 OnDataChannelOpened(channel); | |
687 } | |
688 | |
689 void RTCStatsCollector::OnDataChannelClosedForTesting(DataChannel* channel) { | |
690 OnDataChannelClosed(channel); | |
691 } | |
692 | |
678 const char* CandidateTypeToRTCIceCandidateTypeForTesting( | 693 const char* CandidateTypeToRTCIceCandidateTypeForTesting( |
679 const std::string& type) { | 694 const std::string& type) { |
680 return CandidateTypeToRTCIceCandidateType(type); | 695 return CandidateTypeToRTCIceCandidateType(type); |
681 } | 696 } |
682 | 697 |
683 const char* DataStateToRTCDataChannelStateForTesting( | 698 const char* DataStateToRTCDataChannelStateForTesting( |
684 DataChannelInterface::DataState state) { | 699 DataChannelInterface::DataState state) { |
685 return DataStateToRTCDataChannelState(state); | 700 return DataStateToRTCDataChannelState(state); |
686 } | 701 } |
687 | 702 |
688 } // namespace webrtc | 703 } // namespace webrtc |
OLD | NEW |