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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/api/rtcstatscollector.cc
diff --git a/webrtc/api/rtcstatscollector.cc b/webrtc/api/rtcstatscollector.cc
index b14b39670e61ce8d08bd71118c7b296ca3c5d7e7..e6c26dcf152fae82637d93c71df0ada01825a06f 100644
--- a/webrtc/api/rtcstatscollector.cc
+++ b/webrtc/api/rtcstatscollector.cc
@@ -470,23 +470,10 @@ void RTCStatsCollector::ProduceIceCandidateAndPairStats_s(
void RTCStatsCollector::ProducePeerConnectionStats_s(
int64_t timestamp_us, RTCStatsReport* report) const {
RTC_DCHECK(signaling_thread_->IsCurrent());
- // TODO(hbos): If data channels are removed from the peer connection this will
- // yield incorrect counts. Address before closing crbug.com/636818. See
- // https://w3c.github.io/webrtc-stats/webrtc-stats.html#pcstats-dict*.
- uint32_t data_channels_opened = 0;
- const std::vector<rtc::scoped_refptr<DataChannel>>& data_channels =
- pc_->sctp_data_channels();
- for (const rtc::scoped_refptr<DataChannel>& data_channel : data_channels) {
- if (data_channel->state() == DataChannelInterface::kOpen)
- ++data_channels_opened;
- }
- // There is always just one |RTCPeerConnectionStats| so its |id| can be a
- // constant.
std::unique_ptr<RTCPeerConnectionStats> stats(
new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us));
- stats->data_channels_opened = data_channels_opened;
- stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) -
- data_channels_opened;
+ stats->data_channels_opened = internal_record_.data_channels_opened;
+ stats->data_channels_closed = internal_record_.data_channels_closed;
report->AddStats(std::move(stats));
}
@@ -675,6 +662,33 @@ RTCStatsCollector::PrepareTransportCertificateStats_s(
return transport_cert_stats;
}
+void RTCStatsCollector::OnDataChannelOpened(DataChannel* channel) {
+ RTC_DCHECK(signaling_thread_->IsCurrent());
+ bool result = internal_record_.opened_data_channels.insert(
+ reinterpret_cast<uintptr_t>(channel)).second;
+ ++internal_record_.data_channels_opened;
+ RTC_DCHECK(result);
+}
+
+void RTCStatsCollector::OnDataChannelClosed(DataChannel* channel) {
+ RTC_DCHECK(signaling_thread_->IsCurrent());
+ // Only channels that have been fully opened (and have increased the
+ // |data_channels_opened_| counter) increase the closed counter.
+ if (internal_record_.opened_data_channels.find(
+ reinterpret_cast<uintptr_t>(channel)) !=
+ internal_record_.opened_data_channels.end()) {
+ ++internal_record_.data_channels_closed;
+ }
+}
+
+void RTCStatsCollector::OnDataChannelOpenedForTesting(DataChannel* channel) {
+ OnDataChannelOpened(channel);
+}
+
+void RTCStatsCollector::OnDataChannelClosedForTesting(DataChannel* channel) {
+ OnDataChannelClosed(channel);
+}
+
const char* CandidateTypeToRTCIceCandidateTypeForTesting(
const std::string& type) {
return CandidateTypeToRTCIceCandidateType(type);

Powered by Google App Engine
This is Rietveld 408576698