From cd0373f013b5c9672c05e79a48bb1e9fb5f50fa4 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Wed, 24 Feb 2021 11:04:30 +0100 Subject: [PATCH] peerconnection: add was-ever-connected boolean flag and report some metrics only on the first connection state change to connected BUG=webrtc:12383 Change-Id: I32908e23c51aa40730be8e534793829268d4e25e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/208583 Reviewed-by: Harald Alvestrand Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/master@{#33333} --- pc/peer_connection.cc | 8 +++++--- pc/peer_connection.h | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 0411ab2924..a340f9845d 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -1797,9 +1797,11 @@ void PeerConnection::SetConnectionState( connection_state_ = new_state; Observer()->OnConnectionChange(new_state); - // The connection state change to connected usually happens once per - // connection which makes it a good point to report metrics. - if (new_state == PeerConnectionState::kConnected) { + if (new_state == PeerConnectionState::kConnected && !was_ever_connected_) { + was_ever_connected_ = true; + + // The first connection state change to connected happens once per + // connection which makes it a good point to report metrics. // Record bundle-policy from configuration. Done here from // connectionStateChange to limit to actually established connections. BundlePolicyUsage policy = kBundlePolicyUsageMax; diff --git a/pc/peer_connection.h b/pc/peer_connection.h index d81f3c9918..98c5519950 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -707,6 +707,10 @@ class PeerConnection : public PeerConnectionInternal, std::unique_ptr rtp_manager_; rtc::WeakPtrFactory weak_factory_; + + // Did the connectionState ever change to `connected`? + // Used to gather metrics only the first such state change. + bool was_ever_connected_ RTC_GUARDED_BY(signaling_thread()) = false; }; } // namespace webrtc