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

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

Issue 2472113002: Correct stats for RTCPeerConnectionStats.dataChannels[Opened/Closed]. (Closed)
Patch Set: Addressed hta's comments Created 4 years, 1 month 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
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 report->AddStats(std::move(candidate_pair_stats)); 464 report->AddStats(std::move(candidate_pair_stats));
465 } 465 }
466 } 466 }
467 } 467 }
468 } 468 }
469 469
470 void RTCStatsCollector::ProducePeerConnectionStats_s( 470 void RTCStatsCollector::ProducePeerConnectionStats_s(
471 int64_t timestamp_us, RTCStatsReport* report) const { 471 int64_t timestamp_us, RTCStatsReport* report) const {
472 RTC_DCHECK(signaling_thread_->IsCurrent()); 472 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( 473 std::unique_ptr<RTCPeerConnectionStats> stats(
486 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); 474 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
487 stats->data_channels_opened = data_channels_opened; 475 stats->data_channels_opened = internal_record_.data_channels_opened;
488 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - 476 stats->data_channels_closed = internal_record_.data_channels_closed;
489 data_channels_opened;
490 report->AddStats(std::move(stats)); 477 report->AddStats(std::move(stats));
491 } 478 }
492 479
493 void RTCStatsCollector::ProduceRTPStreamStats_s( 480 void RTCStatsCollector::ProduceRTPStreamStats_s(
494 int64_t timestamp_us, const SessionStats& session_stats, 481 int64_t timestamp_us, const SessionStats& session_stats,
495 RTCStatsReport* report) const { 482 RTCStatsReport* report) const {
496 RTC_DCHECK(signaling_thread_->IsCurrent()); 483 RTC_DCHECK(signaling_thread_->IsCurrent());
497 484
498 // Audio 485 // Audio
499 if (pc_->session()->voice_channel()) { 486 if (pc_->session()->voice_channel()) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 if (remote_certificate) { 655 if (remote_certificate) {
669 certificate_stats_pair.remote = remote_certificate->GetStats(); 656 certificate_stats_pair.remote = remote_certificate->GetStats();
670 } 657 }
671 transport_cert_stats.insert( 658 transport_cert_stats.insert(
672 std::make_pair(transport_stats.second.transport_name, 659 std::make_pair(transport_stats.second.transport_name,
673 std::move(certificate_stats_pair))); 660 std::move(certificate_stats_pair)));
674 } 661 }
675 return transport_cert_stats; 662 return transport_cert_stats;
676 } 663 }
677 664
665 void RTCStatsCollector::OnDataChannelOpened(DataChannel* channel) {
666 RTC_DCHECK(signaling_thread_->IsCurrent());
667 bool result = internal_record_.opened_data_channels.insert(
668 reinterpret_cast<uintptr_t>(channel)).second;
669 ++internal_record_.data_channels_opened;
670 RTC_DCHECK(result);
671 }
672
673 void RTCStatsCollector::OnDataChannelClosed(DataChannel* channel) {
674 RTC_DCHECK(signaling_thread_->IsCurrent());
675 // Only channels that have been fully opened (and have increased the
676 // |data_channels_opened_| counter) increase the closed counter.
677 if (internal_record_.opened_data_channels.find(
678 reinterpret_cast<uintptr_t>(channel)) !=
679 internal_record_.opened_data_channels.end()) {
680 ++internal_record_.data_channels_closed;
681 }
682 }
683
684 void RTCStatsCollector::OnDataChannelOpenedForTesting(DataChannel* channel) {
685 OnDataChannelOpened(channel);
686 }
687
688 void RTCStatsCollector::OnDataChannelClosedForTesting(DataChannel* channel) {
689 OnDataChannelClosed(channel);
690 }
691
678 const char* CandidateTypeToRTCIceCandidateTypeForTesting( 692 const char* CandidateTypeToRTCIceCandidateTypeForTesting(
679 const std::string& type) { 693 const std::string& type) {
680 return CandidateTypeToRTCIceCandidateType(type); 694 return CandidateTypeToRTCIceCandidateType(type);
681 } 695 }
682 696
683 const char* DataStateToRTCDataChannelStateForTesting( 697 const char* DataStateToRTCDataChannelStateForTesting(
684 DataChannelInterface::DataState state) { 698 DataChannelInterface::DataState state) {
685 return DataStateToRTCDataChannelState(state); 699 return DataStateToRTCDataChannelState(state);
686 } 700 }
687 701
688 } // namespace webrtc 702 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698