| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 network_thread_(pc->session()->network_thread()), | 331 network_thread_(pc->session()->network_thread()), |
| 332 num_pending_partial_reports_(0), | 332 num_pending_partial_reports_(0), |
| 333 partial_report_timestamp_us_(0), | 333 partial_report_timestamp_us_(0), |
| 334 cache_timestamp_us_(0), | 334 cache_timestamp_us_(0), |
| 335 cache_lifetime_us_(cache_lifetime_us) { | 335 cache_lifetime_us_(cache_lifetime_us) { |
| 336 RTC_DCHECK(pc_); | 336 RTC_DCHECK(pc_); |
| 337 RTC_DCHECK(signaling_thread_); | 337 RTC_DCHECK(signaling_thread_); |
| 338 RTC_DCHECK(worker_thread_); | 338 RTC_DCHECK(worker_thread_); |
| 339 RTC_DCHECK(network_thread_); | 339 RTC_DCHECK(network_thread_); |
| 340 RTC_DCHECK_GE(cache_lifetime_us_, 0); | 340 RTC_DCHECK_GE(cache_lifetime_us_, 0); |
| 341 pc_->SignalDataChannelCreated.connect( |
| 342 this, &RTCStatsCollector::OnDataChannelCreated); |
| 341 } | 343 } |
| 342 | 344 |
| 343 void RTCStatsCollector::GetStatsReport( | 345 void RTCStatsCollector::GetStatsReport( |
| 344 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) { | 346 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) { |
| 345 RTC_DCHECK(signaling_thread_->IsCurrent()); | 347 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 346 RTC_DCHECK(callback); | 348 RTC_DCHECK(callback); |
| 347 callbacks_.push_back(callback); | 349 callbacks_.push_back(callback); |
| 348 | 350 |
| 349 // "Now" using a monotonically increasing timer. | 351 // "Now" using a monotonically increasing timer. |
| 350 int64_t cache_now_us = rtc::TimeMicros(); | 352 int64_t cache_now_us = rtc::TimeMicros(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 RTC_DCHECK(signaling_thread_->IsCurrent()); | 576 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 575 ProduceMediaStreamAndTrackStats( | 577 ProduceMediaStreamAndTrackStats( |
| 576 timestamp_us, pc_->local_streams(), true, report); | 578 timestamp_us, pc_->local_streams(), true, report); |
| 577 ProduceMediaStreamAndTrackStats( | 579 ProduceMediaStreamAndTrackStats( |
| 578 timestamp_us, pc_->remote_streams(), false, report); | 580 timestamp_us, pc_->remote_streams(), false, report); |
| 579 } | 581 } |
| 580 | 582 |
| 581 void RTCStatsCollector::ProducePeerConnectionStats_s( | 583 void RTCStatsCollector::ProducePeerConnectionStats_s( |
| 582 int64_t timestamp_us, RTCStatsReport* report) const { | 584 int64_t timestamp_us, RTCStatsReport* report) const { |
| 583 RTC_DCHECK(signaling_thread_->IsCurrent()); | 585 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 584 // TODO(hbos): If data channels are removed from the peer connection this will | |
| 585 // yield incorrect counts. Address before closing crbug.com/636818. See | |
| 586 // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*. | |
| 587 uint32_t data_channels_opened = 0; | |
| 588 const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels = | |
| 589 pc_->sctp_data_channels(); | |
| 590 for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) { | |
| 591 if (data_channel->state() == DataChannelInterface::kOpen) | |
| 592 ++data_channels_opened; | |
| 593 } | |
| 594 // There is always just one |RTCPeerConnectionStats| so its |id| can be a | |
| 595 // constant. | |
| 596 std::unique_ptr<RTCPeerConnectionStats> stats( | 586 std::unique_ptr<RTCPeerConnectionStats> stats( |
| 597 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); | 587 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); |
| 598 stats->data_channels_opened = data_channels_opened; | 588 stats->data_channels_opened = internal_record_.data_channels_opened; |
| 599 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - | 589 stats->data_channels_closed = internal_record_.data_channels_closed; |
| 600 data_channels_opened; | |
| 601 report->AddStats(std::move(stats)); | 590 report->AddStats(std::move(stats)); |
| 602 } | 591 } |
| 603 | 592 |
| 604 void RTCStatsCollector::ProduceRTPStreamStats_s( | 593 void RTCStatsCollector::ProduceRTPStreamStats_s( |
| 605 int64_t timestamp_us, const SessionStats& session_stats, | 594 int64_t timestamp_us, const SessionStats& session_stats, |
| 606 RTCStatsReport* report) const { | 595 RTCStatsReport* report) const { |
| 607 RTC_DCHECK(signaling_thread_->IsCurrent()); | 596 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 608 | 597 |
| 609 // Audio | 598 // Audio |
| 610 if (pc_->session()->voice_channel()) { | 599 if (pc_->session()->voice_channel()) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 if (remote_certificate) { | 768 if (remote_certificate) { |
| 780 certificate_stats_pair.remote = remote_certificate->GetStats(); | 769 certificate_stats_pair.remote = remote_certificate->GetStats(); |
| 781 } | 770 } |
| 782 transport_cert_stats.insert( | 771 transport_cert_stats.insert( |
| 783 std::make_pair(transport_stats.second.transport_name, | 772 std::make_pair(transport_stats.second.transport_name, |
| 784 std::move(certificate_stats_pair))); | 773 std::move(certificate_stats_pair))); |
| 785 } | 774 } |
| 786 return transport_cert_stats; | 775 return transport_cert_stats; |
| 787 } | 776 } |
| 788 | 777 |
| 778 void RTCStatsCollector::OnDataChannelCreated(DataChannel* channel) { |
| 779 channel->SignalOpened.connect(this, &RTCStatsCollector::OnDataChannelOpened); |
| 780 channel->SignalClosed.connect(this, &RTCStatsCollector::OnDataChannelClosed); |
| 781 } |
| 782 |
| 783 void RTCStatsCollector::OnDataChannelOpened(DataChannel* channel) { |
| 784 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 785 bool result = internal_record_.opened_data_channels.insert( |
| 786 reinterpret_cast<uintptr_t>(channel)).second; |
| 787 ++internal_record_.data_channels_opened; |
| 788 RTC_DCHECK(result); |
| 789 } |
| 790 |
| 791 void RTCStatsCollector::OnDataChannelClosed(DataChannel* channel) { |
| 792 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 793 // Only channels that have been fully opened (and have increased the |
| 794 // |data_channels_opened_| counter) increase the closed counter. |
| 795 if (internal_record_.opened_data_channels.find( |
| 796 reinterpret_cast<uintptr_t>(channel)) != |
| 797 internal_record_.opened_data_channels.end()) { |
| 798 ++internal_record_.data_channels_closed; |
| 799 } |
| 800 } |
| 801 |
| 789 const char* CandidateTypeToRTCIceCandidateTypeForTesting( | 802 const char* CandidateTypeToRTCIceCandidateTypeForTesting( |
| 790 const std::string& type) { | 803 const std::string& type) { |
| 791 return CandidateTypeToRTCIceCandidateType(type); | 804 return CandidateTypeToRTCIceCandidateType(type); |
| 792 } | 805 } |
| 793 | 806 |
| 794 const char* DataStateToRTCDataChannelStateForTesting( | 807 const char* DataStateToRTCDataChannelStateForTesting( |
| 795 DataChannelInterface::DataState state) { | 808 DataChannelInterface::DataState state) { |
| 796 return DataStateToRTCDataChannelState(state); | 809 return DataStateToRTCDataChannelState(state); |
| 797 } | 810 } |
| 798 | 811 |
| 799 } // namespace webrtc | 812 } // namespace webrtc |
| OLD | NEW |