Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 44d0dff

Browse files
Harald AlvestrandCommit Bot
authored andcommitted
Move the PeerConnection's usage pattern concept to its own file.
This makes it easier to use it from multiple other modules. Bug: webrtc:11995 Change-Id: Id23843ae4600ebe46aed7465e873d107089fd50b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/187347 Reviewed-by: Mirko Bonadei <[email protected]> Commit-Queue: Harald Alvestrand <[email protected]> Cr-Commit-Position: refs/heads/master@{#32361}
1 parent 7d214ed commit 44d0dff

File tree

7 files changed

+243
-239
lines changed

7 files changed

+243
-239
lines changed

pc/BUILD.gn

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ rtc_library("peerconnection") {
230230
":rtp_sender",
231231
":rtp_transceiver",
232232
":stats_collector_interface",
233+
":usage_pattern",
233234
":video_track_source",
234235
"../api:array_view",
235236
"../api:audio_options_api",
@@ -305,6 +306,18 @@ rtc_library("peer_connection_message_handler") {
305306
]
306307
}
307308

309+
rtc_library("usage_pattern") {
310+
sources = [
311+
"usage_pattern.cc",
312+
"usage_pattern.h",
313+
]
314+
deps = [
315+
"../api:libjingle_peerconnection_api",
316+
"../rtc_base:logging",
317+
"../system_wrappers:metrics",
318+
]
319+
}
320+
308321
rtc_library("rtp_transceiver") {
309322
sources = [
310323
"rtp_transceiver.cc",
@@ -745,6 +758,7 @@ if (rtc_include_tests) {
745758
":rtp_receiver",
746759
":rtp_sender",
747760
":rtp_transceiver",
761+
":usage_pattern",
748762
":video_track_source",
749763
"../api:array_view",
750764
"../api:audio_options_api",

pc/peer_connection.cc

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,33 +3066,11 @@ void PeerConnection::ReportIceCandidateCollected(
30663066

30673067
void PeerConnection::NoteUsageEvent(UsageEvent event) {
30683068
RTC_DCHECK_RUN_ON(signaling_thread());
3069-
usage_event_accumulator_ |= static_cast<int>(event);
3069+
usage_pattern_.NoteUsageEvent(event);
30703070
}
30713071

30723072
void PeerConnection::ReportUsagePattern() const {
3073-
RTC_DLOG(LS_INFO) << "Usage signature is " << usage_event_accumulator_;
3074-
RTC_HISTOGRAM_ENUMERATION_SPARSE("WebRTC.PeerConnection.UsagePattern",
3075-
usage_event_accumulator_,
3076-
static_cast<int>(UsageEvent::MAX_VALUE));
3077-
const int bad_bits =
3078-
static_cast<int>(UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED) |
3079-
static_cast<int>(UsageEvent::CANDIDATE_COLLECTED);
3080-
const int good_bits =
3081-
static_cast<int>(UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED) |
3082-
static_cast<int>(UsageEvent::REMOTE_CANDIDATE_ADDED) |
3083-
static_cast<int>(UsageEvent::ICE_STATE_CONNECTED);
3084-
if ((usage_event_accumulator_ & bad_bits) == bad_bits &&
3085-
(usage_event_accumulator_ & good_bits) == 0) {
3086-
// If called after close(), we can't report, because observer may have
3087-
// been deallocated, and therefore pointer is null. Write to log instead.
3088-
if (observer_) {
3089-
Observer()->OnInterestingUsage(usage_event_accumulator_);
3090-
} else {
3091-
RTC_LOG(LS_INFO) << "Interesting usage signature "
3092-
<< usage_event_accumulator_
3093-
<< " observed after observer shutdown";
3094-
}
3095-
}
3073+
usage_pattern_.ReportUsagePattern(observer_);
30963074
}
30973075

30983076
bool PeerConnection::SrtpRequired() const {

pc/peer_connection.h

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "pc/stats_collector.h"
3737
#include "pc/stream_collection.h"
3838
#include "pc/transceiver_list.h"
39+
#include "pc/usage_pattern.h"
3940
#include "pc/webrtc_session_description_factory.h"
4041
#include "rtc_base/experiments/field_trial_parser.h"
4142
#include "rtc_base/operations_chain.h"
@@ -70,53 +71,6 @@ class PeerConnection : public PeerConnectionInternal,
7071
public RtpSenderBase::SetStreamsObserver,
7172
public sigslot::has_slots<> {
7273
public:
73-
// A bit in the usage pattern is registered when its defining event occurs at
74-
// least once.
75-
enum class UsageEvent : int {
76-
TURN_SERVER_ADDED = 0x01,
77-
STUN_SERVER_ADDED = 0x02,
78-
DATA_ADDED = 0x04,
79-
AUDIO_ADDED = 0x08,
80-
VIDEO_ADDED = 0x10,
81-
// |SetLocalDescription| returns successfully.
82-
SET_LOCAL_DESCRIPTION_SUCCEEDED = 0x20,
83-
// |SetRemoteDescription| returns successfully.
84-
SET_REMOTE_DESCRIPTION_SUCCEEDED = 0x40,
85-
// A local candidate (with type host, server-reflexive, or relay) is
86-
// collected.
87-
CANDIDATE_COLLECTED = 0x80,
88-
// A remote candidate is successfully added via |AddIceCandidate|.
89-
ADD_ICE_CANDIDATE_SUCCEEDED = 0x100,
90-
ICE_STATE_CONNECTED = 0x200,
91-
CLOSE_CALLED = 0x400,
92-
// A local candidate with private IP is collected.
93-
PRIVATE_CANDIDATE_COLLECTED = 0x800,
94-
// A remote candidate with private IP is added, either via AddiceCandidate
95-
// or from the remote description.
96-
REMOTE_PRIVATE_CANDIDATE_ADDED = 0x1000,
97-
// A local mDNS candidate is collected.
98-
MDNS_CANDIDATE_COLLECTED = 0x2000,
99-
// A remote mDNS candidate is added, either via AddIceCandidate or from the
100-
// remote description.
101-
REMOTE_MDNS_CANDIDATE_ADDED = 0x4000,
102-
// A local candidate with IPv6 address is collected.
103-
IPV6_CANDIDATE_COLLECTED = 0x8000,
104-
// A remote candidate with IPv6 address is added, either via AddIceCandidate
105-
// or from the remote description.
106-
REMOTE_IPV6_CANDIDATE_ADDED = 0x10000,
107-
// A remote candidate (with type host, server-reflexive, or relay) is
108-
// successfully added, either via AddIceCandidate or from the remote
109-
// description.
110-
REMOTE_CANDIDATE_ADDED = 0x20000,
111-
// An explicit host-host candidate pair is selected, i.e. both the local and
112-
// the remote candidates have the host type. This does not include candidate
113-
// pairs formed with equivalent prflx remote candidates, e.g. a host-prflx
114-
// pair where the prflx candidate has the same base as a host candidate of
115-
// the remote peer.
116-
DIRECT_CONNECTION_SELECTED = 0x40000,
117-
MAX_VALUE = 0x80000,
118-
};
119-
12074
explicit PeerConnection(PeerConnectionFactory* factory,
12175
std::unique_ptr<RtcEventLog> event_log,
12276
std::unique_ptr<Call> call);
@@ -873,7 +827,7 @@ class PeerConnection : public PeerConnectionInternal,
873827
cricket::AudioOptions audio_options_ RTC_GUARDED_BY(signaling_thread());
874828
cricket::VideoOptions video_options_ RTC_GUARDED_BY(signaling_thread());
875829

876-
int usage_event_accumulator_ RTC_GUARDED_BY(signaling_thread()) = 0;
830+
UsagePattern usage_pattern_ RTC_GUARDED_BY(signaling_thread());
877831
bool return_histogram_very_quickly_ RTC_GUARDED_BY(signaling_thread()) =
878832
false;
879833

0 commit comments

Comments
 (0)