hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_RTC_STATS_COLLECTOR_H_ |
| 12 | #define PC_RTC_STATS_COLLECTOR_H_ |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 13 | |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 14 | #include <map> |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 15 | #include <memory> |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 16 | #include <set> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 17 | #include <string> |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 18 | #include <vector> |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 19 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 21 | #include "api/scoped_refptr.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "api/stats/rtc_stats_collector_callback.h" |
| 23 | #include "api/stats/rtc_stats_report.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "api/stats/rtcstats_objects.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "call/call.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "media/base/media_channel.h" |
| 27 | #include "pc/data_channel.h" |
| 28 | #include "pc/peer_connection_internal.h" |
| 29 | #include "pc/track_media_info_map.h" |
Henrik Boström | 40b030e | 2019-02-28 09:49:31 +0100 | [diff] [blame] | 30 | #include "rtc_base/event.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "rtc_base/ref_count.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 32 | #include "rtc_base/ssl_identity.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 33 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 34 | #include "rtc_base/time_utils.h" |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 35 | |
| 36 | namespace webrtc { |
| 37 | |
Henrik Boström | 5b3541f | 2018-03-19 13:52:56 +0100 | [diff] [blame] | 38 | class RtpSenderInternal; |
| 39 | class RtpReceiverInternal; |
| 40 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 41 | // All public methods of the collector are to be called on the signaling thread. |
| 42 | // Stats are gathered on the signaling, worker and network threads |
| 43 | // asynchronously. The callback is invoked on the signaling thread. Resulting |
| 44 | // reports are cached for |cache_lifetime_| ms. |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 45 | class RTCStatsCollector : public virtual rtc::RefCountInterface, |
| 46 | public sigslot::has_slots<> { |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 47 | public: |
| 48 | static rtc::scoped_refptr<RTCStatsCollector> Create( |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 49 | PeerConnectionInternal* pc, |
hbos | 0e6758d | 2016-08-31 07:57:36 -0700 | [diff] [blame] | 50 | int64_t cache_lifetime_us = 50 * rtc::kNumMicrosecsPerMillisec); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 51 | |
| 52 | // Gets a recent stats report. If there is a report cached that is still fresh |
| 53 | // it is returned, otherwise new stats are gathered and returned. A report is |
| 54 | // considered fresh for |cache_lifetime_| ms. const RTCStatsReports are safe |
| 55 | // to use across multiple threads and may be destructed on any thread. |
Henrik Boström | 5b3541f | 2018-03-19 13:52:56 +0100 | [diff] [blame] | 56 | // If the optional selector argument is used, stats are filtered according to |
| 57 | // stats selection algorithm before delivery. |
| 58 | // https://w3c.github.io/webrtc-pc/#dfn-stats-selection-algorithm |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 59 | void GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback> callback); |
Henrik Boström | 5b3541f | 2018-03-19 13:52:56 +0100 | [diff] [blame] | 60 | // If |selector| is null the selection algorithm is still applied (interpreted |
| 61 | // as: no RTP streams are sent by selector). The result is empty. |
| 62 | void GetStatsReport(rtc::scoped_refptr<RtpSenderInternal> selector, |
| 63 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback); |
| 64 | // If |selector| is null the selection algorithm is still applied (interpreted |
| 65 | // as: no RTP streams are received by selector). The result is empty. |
| 66 | void GetStatsReport(rtc::scoped_refptr<RtpReceiverInternal> selector, |
| 67 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 68 | // Clears the cache's reference to the most recent stats report. Subsequently |
| 69 | // calling |GetStatsReport| guarantees fresh stats. |
| 70 | void ClearCachedStatsReport(); |
| 71 | |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 72 | // If there is a |GetStatsReport| requests in-flight, waits until it has been |
| 73 | // completed. Must be called on the signaling thread. |
| 74 | void WaitForPendingRequest(); |
| 75 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 76 | protected: |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 77 | RTCStatsCollector(PeerConnectionInternal* pc, int64_t cache_lifetime_us); |
hbos | b78306a | 2016-12-19 05:06:57 -0800 | [diff] [blame] | 78 | ~RTCStatsCollector(); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 79 | |
Henrik Boström | 40b030e | 2019-02-28 09:49:31 +0100 | [diff] [blame] | 80 | struct CertificateStatsPair { |
| 81 | std::unique_ptr<rtc::SSLCertificateStats> local; |
| 82 | std::unique_ptr<rtc::SSLCertificateStats> remote; |
| 83 | }; |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 84 | |
Henrik Boström | 40b030e | 2019-02-28 09:49:31 +0100 | [diff] [blame] | 85 | // Stats gathering on a particular thread. Virtual for the sake of testing. |
| 86 | virtual void ProducePartialResultsOnSignalingThreadImpl( |
| 87 | int64_t timestamp_us, |
| 88 | RTCStatsReport* partial_report); |
| 89 | virtual void ProducePartialResultsOnNetworkThreadImpl( |
| 90 | int64_t timestamp_us, |
| 91 | const std::map<std::string, cricket::TransportStats>& |
| 92 | transport_stats_by_name, |
| 93 | const std::map<std::string, CertificateStatsPair>& transport_cert_stats, |
| 94 | RTCStatsReport* partial_report); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 95 | |
| 96 | private: |
Henrik Boström | 5b3541f | 2018-03-19 13:52:56 +0100 | [diff] [blame] | 97 | class RequestInfo { |
| 98 | public: |
| 99 | enum class FilterMode { kAll, kSenderSelector, kReceiverSelector }; |
| 100 | |
| 101 | // Constructs with FilterMode::kAll. |
| 102 | explicit RequestInfo( |
| 103 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback); |
| 104 | // Constructs with FilterMode::kSenderSelector. The selection algorithm is |
| 105 | // applied even if |selector| is null, resulting in an empty report. |
| 106 | RequestInfo(rtc::scoped_refptr<RtpSenderInternal> selector, |
| 107 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback); |
| 108 | // Constructs with FilterMode::kReceiverSelector. The selection algorithm is |
| 109 | // applied even if |selector| is null, resulting in an empty report. |
| 110 | RequestInfo(rtc::scoped_refptr<RtpReceiverInternal> selector, |
| 111 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback); |
| 112 | |
| 113 | FilterMode filter_mode() const { return filter_mode_; } |
| 114 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback() const { |
| 115 | return callback_; |
| 116 | } |
| 117 | rtc::scoped_refptr<RtpSenderInternal> sender_selector() const { |
| 118 | RTC_DCHECK(filter_mode_ == FilterMode::kSenderSelector); |
| 119 | return sender_selector_; |
| 120 | } |
| 121 | rtc::scoped_refptr<RtpReceiverInternal> receiver_selector() const { |
| 122 | RTC_DCHECK(filter_mode_ == FilterMode::kReceiverSelector); |
| 123 | return receiver_selector_; |
| 124 | } |
| 125 | |
| 126 | private: |
| 127 | RequestInfo(FilterMode filter_mode, |
| 128 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback, |
| 129 | rtc::scoped_refptr<RtpSenderInternal> sender_selector, |
| 130 | rtc::scoped_refptr<RtpReceiverInternal> receiver_selector); |
| 131 | |
| 132 | FilterMode filter_mode_; |
| 133 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback_; |
| 134 | rtc::scoped_refptr<RtpSenderInternal> sender_selector_; |
| 135 | rtc::scoped_refptr<RtpReceiverInternal> receiver_selector_; |
| 136 | }; |
| 137 | |
| 138 | void GetStatsReportInternal(RequestInfo request); |
| 139 | |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 140 | // Structure for tracking stats about each RtpTransceiver managed by the |
| 141 | // PeerConnection. This can either by a Plan B style or Unified Plan style |
| 142 | // transceiver (i.e., can have 0 or many senders and receivers). |
| 143 | // Some fields are copied from the RtpTransceiver/BaseChannel object so that |
| 144 | // they can be accessed safely on threads other than the signaling thread. |
| 145 | // If a BaseChannel is not available (e.g., if signaling has not started), |
| 146 | // then |mid| and |transport_name| will be null. |
| 147 | struct RtpTransceiverStatsInfo { |
| 148 | rtc::scoped_refptr<RtpTransceiver> transceiver; |
| 149 | cricket::MediaType media_type; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 150 | absl::optional<std::string> mid; |
| 151 | absl::optional<std::string> transport_name; |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 152 | std::unique_ptr<TrackMediaInfoMap> track_media_info_map; |
| 153 | }; |
| 154 | |
Taylor Brandstetter | 25e022f | 2018-03-08 09:53:47 -0800 | [diff] [blame] | 155 | void DeliverCachedReport( |
| 156 | rtc::scoped_refptr<const RTCStatsReport> cached_report, |
Henrik Boström | 5b3541f | 2018-03-19 13:52:56 +0100 | [diff] [blame] | 157 | std::vector<RequestInfo> requests); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 158 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 159 | // Produces |RTCCertificateStats|. |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 160 | void ProduceCertificateStats_n( |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 161 | int64_t timestamp_us, |
| 162 | const std::map<std::string, CertificateStatsPair>& transport_cert_stats, |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 163 | RTCStatsReport* report) const; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 164 | // Produces |RTCCodecStats|. |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 165 | void ProduceCodecStats_n( |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 166 | int64_t timestamp_us, |
| 167 | const std::vector<RtpTransceiverStatsInfo>& transceiver_stats_infos, |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 168 | RTCStatsReport* report) const; |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 169 | // Produces |RTCDataChannelStats|. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 170 | void ProduceDataChannelStats_s(int64_t timestamp_us, |
| 171 | RTCStatsReport* report) const; |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 172 | // Produces |RTCIceCandidatePairStats| and |RTCIceCandidateStats|. |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 173 | void ProduceIceCandidateAndPairStats_n( |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 174 | int64_t timestamp_us, |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 175 | const std::map<std::string, cricket::TransportStats>& |
| 176 | transport_stats_by_name, |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 177 | const Call::Stats& call_stats, |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 178 | RTCStatsReport* report) const; |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 179 | // Produces |RTCMediaStreamStats|. |
| 180 | void ProduceMediaStreamStats_s(int64_t timestamp_us, |
| 181 | RTCStatsReport* report) const; |
| 182 | // Produces |RTCMediaStreamTrackStats|. |
| 183 | void ProduceMediaStreamTrackStats_s(int64_t timestamp_us, |
| 184 | RTCStatsReport* report) const; |
Henrik Boström | 646fda0 | 2019-05-22 15:49:42 +0200 | [diff] [blame] | 185 | // Produces RTCMediaSourceStats, including RTCAudioSourceStats and |
| 186 | // RTCVideoSourceStats. |
| 187 | void ProduceMediaSourceStats_s(int64_t timestamp_us, |
| 188 | RTCStatsReport* report) const; |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 189 | // Produces |RTCPeerConnectionStats|. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 190 | void ProducePeerConnectionStats_s(int64_t timestamp_us, |
| 191 | RTCStatsReport* report) const; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 192 | // Produces |RTCInboundRTPStreamStats| and |RTCOutboundRTPStreamStats|. |
Henrik Boström | 883eefc | 2019-05-27 13:40:25 +0200 | [diff] [blame] | 193 | // This has to be invoked after codecs and transport stats have been created |
| 194 | // because some metrics are calculated through lookup of other metrics. |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 195 | void ProduceRTPStreamStats_n( |
| 196 | int64_t timestamp_us, |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 197 | const std::vector<RtpTransceiverStatsInfo>& transceiver_stats_infos, |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 198 | RTCStatsReport* report) const; |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 199 | void ProduceAudioRTPStreamStats_n(int64_t timestamp_us, |
| 200 | const RtpTransceiverStatsInfo& stats, |
| 201 | RTCStatsReport* report) const; |
| 202 | void ProduceVideoRTPStreamStats_n(int64_t timestamp_us, |
| 203 | const RtpTransceiverStatsInfo& stats, |
| 204 | RTCStatsReport* report) const; |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 205 | // Produces |RTCTransportStats|. |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 206 | void ProduceTransportStats_n( |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 207 | int64_t timestamp_us, |
| 208 | const std::map<std::string, cricket::TransportStats>& |
| 209 | transport_stats_by_name, |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 210 | const std::map<std::string, CertificateStatsPair>& transport_cert_stats, |
| 211 | RTCStatsReport* report) const; |
| 212 | |
| 213 | // Helper function to stats-producing functions. |
| 214 | std::map<std::string, CertificateStatsPair> |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 215 | PrepareTransportCertificateStats_n( |
| 216 | const std::map<std::string, cricket::TransportStats>& |
| 217 | transport_stats_by_name) const; |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 218 | std::vector<RtpTransceiverStatsInfo> PrepareTransceiverStatsInfos_s() const; |
Steve Anton | 7eca093 | 2018-03-30 15:18:41 -0700 | [diff] [blame] | 219 | std::set<std::string> PrepareTransportNames_s() const; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 220 | |
Henrik Boström | 40b030e | 2019-02-28 09:49:31 +0100 | [diff] [blame] | 221 | // Stats gathering on a particular thread. |
| 222 | void ProducePartialResultsOnSignalingThread(int64_t timestamp_us); |
| 223 | void ProducePartialResultsOnNetworkThread(int64_t timestamp_us); |
| 224 | // Merges |network_report_| into |partial_report_| and completes the request. |
| 225 | // This is a NO-OP if |network_report_| is null. |
| 226 | void MergeNetworkReport_s(); |
| 227 | |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 228 | // Slots for signals (sigslot) that are wired up to |pc_|. |
| 229 | void OnDataChannelCreated(DataChannel* channel); |
| 230 | // Slots for signals (sigslot) that are wired up to |channel|. |
| 231 | void OnDataChannelOpened(DataChannel* channel); |
| 232 | void OnDataChannelClosed(DataChannel* channel); |
| 233 | |
Steve Anton | 2d8609c | 2018-01-23 16:38:46 -0800 | [diff] [blame] | 234 | PeerConnectionInternal* const pc_; |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 235 | rtc::Thread* const signaling_thread_; |
| 236 | rtc::Thread* const worker_thread_; |
| 237 | rtc::Thread* const network_thread_; |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 238 | |
| 239 | int num_pending_partial_reports_; |
| 240 | int64_t partial_report_timestamp_us_; |
Henrik Boström | 40b030e | 2019-02-28 09:49:31 +0100 | [diff] [blame] | 241 | // Reports that are produced on the signaling thread or the network thread are |
| 242 | // merged into this report. It is only touched on the signaling thread. Once |
| 243 | // all partial reports are merged this is the result of a request. |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 244 | rtc::scoped_refptr<RTCStatsReport> partial_report_; |
Henrik Boström | 5b3541f | 2018-03-19 13:52:56 +0100 | [diff] [blame] | 245 | std::vector<RequestInfo> requests_; |
Henrik Boström | 40b030e | 2019-02-28 09:49:31 +0100 | [diff] [blame] | 246 | // Holds the result of ProducePartialResultsOnNetworkThread(). It is merged |
| 247 | // into |partial_report_| on the signaling thread and then nulled by |
| 248 | // MergeNetworkReport_s(). Thread-safety is ensured by using |
| 249 | // |network_report_event_|. |
| 250 | rtc::scoped_refptr<RTCStatsReport> network_report_; |
| 251 | // If set, it is safe to touch the |network_report_| on the signaling thread. |
| 252 | // This is reset before async-invoking ProducePartialResultsOnNetworkThread() |
| 253 | // and set when ProducePartialResultsOnNetworkThread() is complete, after it |
| 254 | // has updated the value of |network_report_|. |
| 255 | rtc::Event network_report_event_; |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 256 | |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 257 | // Set in |GetStatsReport|, read in |ProducePartialResultsOnNetworkThread| and |
| 258 | // |ProducePartialResultsOnSignalingThread|, reset after work is complete. Not |
| 259 | // passed as arguments to avoid copies. This is thread safe - when we |
| 260 | // set/reset we know there are no pending stats requests in progress. |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 261 | std::vector<RtpTransceiverStatsInfo> transceiver_stats_infos_; |
Steve Anton | 7eca093 | 2018-03-30 15:18:41 -0700 | [diff] [blame] | 262 | std::set<std::string> transport_names_; |
Steve Anton | 5dfde18 | 2018-02-06 10:34:40 -0800 | [diff] [blame] | 263 | |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 264 | Call::Stats call_stats_; |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 265 | |
hbos | 0e6758d | 2016-08-31 07:57:36 -0700 | [diff] [blame] | 266 | // A timestamp, in microseconds, that is based on a timer that is |
| 267 | // monotonically increasing. That is, even if the system clock is modified the |
| 268 | // difference between the timer and this timestamp is how fresh the cached |
| 269 | // report is. |
| 270 | int64_t cache_timestamp_us_; |
| 271 | int64_t cache_lifetime_us_; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 272 | rtc::scoped_refptr<const RTCStatsReport> cached_report_; |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 273 | |
| 274 | // Data recorded and maintained by the stats collector during its lifetime. |
| 275 | // Some stats are produced from this record instead of other components. |
| 276 | struct InternalRecord { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 277 | InternalRecord() : data_channels_opened(0), data_channels_closed(0) {} |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 278 | |
| 279 | // The opened count goes up when a channel is fully opened and the closed |
| 280 | // count goes up if a previously opened channel has fully closed. The opened |
| 281 | // count does not go down when a channel closes, meaning (opened - closed) |
| 282 | // is the number of channels currently opened. A channel that is closed |
| 283 | // before reaching the open state does not affect these counters. |
| 284 | uint32_t data_channels_opened; |
| 285 | uint32_t data_channels_closed; |
| 286 | // Identifies by address channels that have been opened, which remain in the |
| 287 | // set until they have been fully closed. |
| 288 | std::set<uintptr_t> opened_data_channels; |
| 289 | }; |
| 290 | InternalRecord internal_record_; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 293 | const char* CandidateTypeToRTCIceCandidateTypeForTesting( |
| 294 | const std::string& type); |
| 295 | const char* DataStateToRTCDataChannelStateForTesting( |
| 296 | DataChannelInterface::DataState state); |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 297 | |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 298 | } // namespace webrtc |
| 299 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 300 | #endif // PC_RTC_STATS_COLLECTOR_H_ |