henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | // This file contains structures used for retrieving statistics from an ongoing |
| 12 | // libjingle session. |
| 13 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 14 | #ifndef API_STATS_TYPES_H_ |
| 15 | #define API_STATS_TYPES_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 16 | |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 17 | #include <algorithm> |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 18 | #include <list> |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 19 | #include <map> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 20 | #include <string> |
oprypin | 803dc29 | 2017-02-01 09:55:59 | [diff] [blame] | 21 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 22 | |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 23 | #include "api/scoped_refptr.h" |
Artem Titov | 06159aa | 2021-02-09 22:38:13 | [diff] [blame] | 24 | #include "api/sequence_checker.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 25 | #include "rtc_base/constructor_magic.h" |
| 26 | #include "rtc_base/ref_count.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 27 | #include "rtc_base/string_encode.h" |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 28 | #include "rtc_base/system/rtc_export.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 32 | class RTC_EXPORT StatsReport { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 33 | public: |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 34 | // Indicates whether a track is for sending or receiving. |
| 35 | // Used in reports for audio/video tracks. |
| 36 | enum Direction { |
| 37 | kSend = 0, |
| 38 | kReceive, |
| 39 | }; |
tommi@webrtc.org | aa2c342 | 2014-12-09 20:23:06 | [diff] [blame] | 40 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 41 | enum StatsType { |
| 42 | // StatsReport types. |
| 43 | // A StatsReport of |type| = "googSession" contains overall information |
| 44 | // about the thing libjingle calls a session (which may contain one |
| 45 | // or more RTP sessions. |
| 46 | kStatsReportTypeSession, |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 47 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 48 | // A StatsReport of |type| = "googTransport" contains information |
| 49 | // about a libjingle "transport". |
| 50 | kStatsReportTypeTransport, |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 51 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 52 | // A StatsReport of |type| = "googComponent" contains information |
| 53 | // about a libjingle "channel" (typically, RTP or RTCP for a transport). |
| 54 | // This is intended to be the same thing as an ICE "Component". |
| 55 | kStatsReportTypeComponent, |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 56 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 57 | // A StatsReport of |type| = "googCandidatePair" contains information |
| 58 | // about a libjingle "connection" - a single source/destination port pair. |
| 59 | // This is intended to be the same thing as an ICE "candidate pair". |
| 60 | kStatsReportTypeCandidatePair, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 61 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 62 | // A StatsReport of |type| = "VideoBWE" is statistics for video Bandwidth |
| 63 | // Estimation, which is global per-session. The |id| field is "bweforvideo" |
| 64 | // (will probably change in the future). |
| 65 | kStatsReportTypeBwe, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 66 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 67 | // A StatsReport of |type| = "ssrc" is statistics for a specific rtp stream. |
| 68 | // The |id| field is the SSRC in decimal form of the rtp stream. |
| 69 | kStatsReportTypeSsrc, |
| 70 | |
| 71 | // A StatsReport of |type| = "remoteSsrc" is statistics for a specific |
| 72 | // rtp stream, generated by the remote end of the connection. |
| 73 | kStatsReportTypeRemoteSsrc, |
| 74 | |
| 75 | // A StatsReport of |type| = "googTrack" is statistics for a specific media |
| 76 | // track. The |id| field is the track id. |
| 77 | kStatsReportTypeTrack, |
| 78 | |
| 79 | // A StatsReport of |type| = "localcandidate" or "remotecandidate" is |
| 80 | // attributes on a specific ICE Candidate. It links to its connection pair |
| 81 | // by candidate id. The string value is taken from |
| 82 | // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. |
| 83 | kStatsReportTypeIceLocalCandidate, |
| 84 | kStatsReportTypeIceRemoteCandidate, |
| 85 | |
| 86 | // A StatsReport of |type| = "googCertificate" contains an SSL certificate |
| 87 | // transmitted by one of the endpoints of this connection. The |id| is |
| 88 | // controlled by the fingerprint, and is used to identify the certificate in |
| 89 | // the Channel stats (as "googLocalCertificateId" or |
| 90 | // "googRemoteCertificateId") and in any child certificates (as |
| 91 | // "googIssuerId"). |
| 92 | kStatsReportTypeCertificate, |
| 93 | |
| 94 | // A StatsReport of |type| = "datachannel" with statistics for a |
| 95 | // particular DataChannel. |
| 96 | kStatsReportTypeDataChannel, |
| 97 | }; |
| 98 | |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 99 | enum StatsValueName { |
| 100 | kStatsValueNameActiveConnection, |
Minyue | 2a8a78c | 2016-04-07 14:48:15 | [diff] [blame] | 101 | kStatsValueNameAecDivergentFilterFraction, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 102 | kStatsValueNameAudioInputLevel, |
| 103 | kStatsValueNameAudioOutputLevel, |
| 104 | kStatsValueNameBytesReceived, |
| 105 | kStatsValueNameBytesSent, |
Peter Boström | b7d9a97 | 2015-12-18 15:01:11 | [diff] [blame] | 106 | kStatsValueNameCodecImplementationName, |
Steve Anton | 2dbc69f | 2017-08-25 00:15:13 | [diff] [blame] | 107 | kStatsValueNameConcealedSamples, |
Gustaf Ullberg | 9a2e906 | 2017-09-18 07:28:20 | [diff] [blame] | 108 | kStatsValueNameConcealmentEvents, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 109 | kStatsValueNameDataChannelId, |
sakal | e5ba44e | 2016-10-26 14:09:24 | [diff] [blame] | 110 | kStatsValueNameFramesDecoded, |
sakal | 43536c3 | 2016-10-24 08:46:43 | [diff] [blame] | 111 | kStatsValueNameFramesEncoded, |
Gustaf Ullberg | b0a0207 | 2017-10-02 10:00:34 | [diff] [blame] | 112 | kStatsValueNameJitterBufferDelay, |
fippo | bec70ab | 2016-01-28 09:27:15 | [diff] [blame] | 113 | kStatsValueNameMediaType, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 114 | kStatsValueNamePacketsLost, |
| 115 | kStatsValueNamePacketsReceived, |
| 116 | kStatsValueNamePacketsSent, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 117 | kStatsValueNameProtocol, |
sakal | 87da404 | 2016-10-31 13:53:47 | [diff] [blame] | 118 | kStatsValueNameQpSum, |
Peter Thatcher | 04ac81f | 2015-09-21 18:48:28 | [diff] [blame] | 119 | kStatsValueNameReceiving, |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 120 | kStatsValueNameSelectedCandidatePairId, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 121 | kStatsValueNameSsrc, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 122 | kStatsValueNameState, |
zstein | e76bd3a | 2017-07-14 19:17:49 | [diff] [blame] | 123 | kStatsValueNameTotalAudioEnergy, |
| 124 | kStatsValueNameTotalSamplesDuration, |
Steve Anton | 2dbc69f | 2017-08-25 00:15:13 | [diff] [blame] | 125 | kStatsValueNameTotalSamplesReceived, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 126 | kStatsValueNameTransportId, |
zhihuang | 5ecf16c | 2016-06-02 00:09:15 | [diff] [blame] | 127 | kStatsValueNameSentPingRequestsTotal, |
| 128 | kStatsValueNameSentPingRequestsBeforeFirstResponse, |
| 129 | kStatsValueNameSentPingResponses, |
| 130 | kStatsValueNameRecvPingRequests, |
| 131 | kStatsValueNameRecvPingResponses, |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 132 | kStatsValueNameSentStunKeepaliveRequests, |
| 133 | kStatsValueNameRecvStunKeepaliveResponses, |
| 134 | kStatsValueNameStunKeepaliveRttTotal, |
| 135 | kStatsValueNameStunKeepaliveRttSquaredTotal, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 136 | |
| 137 | // Internal StatsValue names. |
Henrik Lundin | 8e6fd46 | 2015-06-02 07:24:52 | [diff] [blame] | 138 | kStatsValueNameAccelerateRate, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 139 | kStatsValueNameActualEncBitrate, |
| 140 | kStatsValueNameAdaptationChanges, |
| 141 | kStatsValueNameAvailableReceiveBandwidth, |
| 142 | kStatsValueNameAvailableSendBandwidth, |
| 143 | kStatsValueNameAvgEncodeMs, |
| 144 | kStatsValueNameBandwidthLimitedResolution, |
| 145 | kStatsValueNameBucketDelay, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 146 | kStatsValueNameCaptureStartNtpTimeMs, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 147 | kStatsValueNameCandidateIPAddress, |
| 148 | kStatsValueNameCandidateNetworkType, |
| 149 | kStatsValueNameCandidatePortNumber, |
| 150 | kStatsValueNameCandidatePriority, |
| 151 | kStatsValueNameCandidateTransportType, |
| 152 | kStatsValueNameCandidateType, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 153 | kStatsValueNameChannelId, |
| 154 | kStatsValueNameCodecName, |
| 155 | kStatsValueNameComponent, |
| 156 | kStatsValueNameContentName, |
ilnik | 2e1b40b | 2017-09-04 14:57:17 | [diff] [blame] | 157 | kStatsValueNameContentType, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 158 | kStatsValueNameCpuLimitedResolution, |
| 159 | kStatsValueNameCurrentDelayMs, |
| 160 | kStatsValueNameDecodeMs, |
| 161 | kStatsValueNameDecodingCNG, |
| 162 | kStatsValueNameDecodingCTN, |
| 163 | kStatsValueNameDecodingCTSG, |
henrik.lundin | 6348978 | 2016-09-20 08:47:12 | [diff] [blame] | 164 | kStatsValueNameDecodingMutedOutput, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 165 | kStatsValueNameDecodingNormal, |
| 166 | kStatsValueNameDecodingPLC, |
Alex Narest | 5b5d97c | 2019-08-07 16:15:08 | [diff] [blame] | 167 | kStatsValueNameDecodingCodecPLC, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 168 | kStatsValueNameDecodingPLCCNG, |
| 169 | kStatsValueNameDer, |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 170 | kStatsValueNameDtlsCipher, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 171 | kStatsValueNameEchoDelayMedian, |
| 172 | kStatsValueNameEchoDelayStdDev, |
| 173 | kStatsValueNameEchoReturnLoss, |
| 174 | kStatsValueNameEchoReturnLossEnhancement, |
| 175 | kStatsValueNameEncodeUsagePercent, |
| 176 | kStatsValueNameExpandRate, |
| 177 | kStatsValueNameFingerprint, |
| 178 | kStatsValueNameFingerprintAlgorithm, |
| 179 | kStatsValueNameFirsReceived, |
| 180 | kStatsValueNameFirsSent, |
Benjamin Wright | 514f084 | 2018-12-10 17:55:17 | [diff] [blame] | 181 | kStatsValueNameFirstFrameReceivedToDecodedMs, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 182 | kStatsValueNameFrameHeightInput, |
| 183 | kStatsValueNameFrameHeightReceived, |
| 184 | kStatsValueNameFrameHeightSent, |
| 185 | kStatsValueNameFrameRateDecoded, |
| 186 | kStatsValueNameFrameRateInput, |
| 187 | kStatsValueNameFrameRateOutput, |
| 188 | kStatsValueNameFrameRateReceived, |
| 189 | kStatsValueNameFrameRateSent, |
| 190 | kStatsValueNameFrameWidthInput, |
| 191 | kStatsValueNameFrameWidthReceived, |
| 192 | kStatsValueNameFrameWidthSent, |
Ă…sa Persson | c3ed630 | 2017-11-16 13:04:52 | [diff] [blame] | 193 | kStatsValueNameHasEnteredLowResolution, |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 15:35:03 | [diff] [blame] | 194 | kStatsValueNameHugeFramesSent, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 195 | kStatsValueNameInitiator, |
ilnik | 2e1b40b | 2017-09-04 14:57:17 | [diff] [blame] | 196 | kStatsValueNameInterframeDelayMaxMs, // Max over last 10 seconds. |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 197 | kStatsValueNameIssuerId, |
| 198 | kStatsValueNameJitterBufferMs, |
| 199 | kStatsValueNameJitterReceived, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 200 | kStatsValueNameLabel, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 201 | kStatsValueNameLocalAddress, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 202 | kStatsValueNameLocalCandidateId, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 203 | kStatsValueNameLocalCandidateType, |
| 204 | kStatsValueNameLocalCertificateId, |
| 205 | kStatsValueNameMaxDecodeMs, |
| 206 | kStatsValueNameMinPlayoutDelayMs, |
| 207 | kStatsValueNameNacksReceived, |
| 208 | kStatsValueNameNacksSent, |
| 209 | kStatsValueNamePlisReceived, |
| 210 | kStatsValueNamePlisSent, |
Henrik Lundin | 8e6fd46 | 2015-06-02 07:24:52 | [diff] [blame] | 211 | kStatsValueNamePreemptiveExpandRate, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 212 | kStatsValueNamePreferredJitterBufferMs, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 213 | kStatsValueNameRemoteAddress, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 214 | kStatsValueNameRemoteCandidateId, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 215 | kStatsValueNameRemoteCandidateType, |
| 216 | kStatsValueNameRemoteCertificateId, |
| 217 | kStatsValueNameRenderDelayMs, |
ivoc | 8c63a82 | 2016-10-21 11:10:03 | [diff] [blame] | 218 | kStatsValueNameResidualEchoLikelihood, |
ivoc | 4e477a1 | 2017-01-15 16:29:46 | [diff] [blame] | 219 | kStatsValueNameResidualEchoLikelihoodRecentMax, |
ivoc | e1198e0 | 2017-09-08 15:13:19 | [diff] [blame] | 220 | kStatsValueNameAnaBitrateActionCounter, |
| 221 | kStatsValueNameAnaChannelActionCounter, |
| 222 | kStatsValueNameAnaDtxActionCounter, |
| 223 | kStatsValueNameAnaFecActionCounter, |
ivoc | 0d0b912 | 2017-09-08 20:24:21 | [diff] [blame] | 224 | kStatsValueNameAnaFrameLengthIncreaseCounter, |
| 225 | kStatsValueNameAnaFrameLengthDecreaseCounter, |
| 226 | kStatsValueNameAnaUplinkPacketLossFraction, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 227 | kStatsValueNameRetransmitBitrate, |
| 228 | kStatsValueNameRtt, |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 | [diff] [blame] | 229 | kStatsValueNameSecondaryDecodedRate, |
minyue-webrtc | 0e320ec | 2017-08-28 11:51:27 | [diff] [blame] | 230 | kStatsValueNameSecondaryDiscardedRate, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 231 | kStatsValueNameSendPacketsDiscarded, |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 | [diff] [blame] | 232 | kStatsValueNameSpeechExpandRate, |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 233 | kStatsValueNameSrtpCipher, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 234 | kStatsValueNameTargetDelayMs, |
| 235 | kStatsValueNameTargetEncBitrate, |
ilnik | 2edc684 | 2017-07-06 10:06:50 | [diff] [blame] | 236 | kStatsValueNameTimingFrameInfo, // Result of |TimingFrameInfo::ToString| |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 237 | kStatsValueNameTrackId, |
| 238 | kStatsValueNameTransmitBitrate, |
| 239 | kStatsValueNameTransportType, |
| 240 | kStatsValueNameTypingNoiseState, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 241 | kStatsValueNameWritable, |
Alex Narest | bbeb109 | 2019-08-16 09:49:04 | [diff] [blame] | 242 | kStatsValueNameAudioDeviceUnderrunCounter, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 243 | }; |
| 244 | |
Mirko Bonadei | 051cae5 | 2019-11-12 12:01:23 | [diff] [blame] | 245 | class RTC_EXPORT IdBase : public rtc::RefCountInterface { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 246 | public: |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 247 | ~IdBase() override; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 248 | StatsType type() const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 249 | |
| 250 | // Users of IdBase will be using the Id typedef, which is compatible with |
| 251 | // this Equals() function. It simply calls the protected (and overridden) |
| 252 | // Equals() method. |
| 253 | bool Equals(const rtc::scoped_refptr<IdBase>& other) const { |
| 254 | return Equals(*other.get()); |
| 255 | } |
| 256 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 257 | virtual std::string ToString() const = 0; |
| 258 | |
| 259 | protected: |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 260 | // Protected since users of the IdBase type will be using the Id typedef. |
| 261 | virtual bool Equals(const IdBase& other) const; |
| 262 | |
oprypin | 803dc29 | 2017-02-01 09:55:59 | [diff] [blame] | 263 | explicit IdBase(StatsType type); // Only meant for derived classes. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 264 | const StatsType type_; |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 265 | |
| 266 | static const char kSeparator = '_'; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 267 | }; |
| 268 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 269 | typedef rtc::scoped_refptr<IdBase> Id; |
| 270 | |
Mirko Bonadei | 051cae5 | 2019-11-12 12:01:23 | [diff] [blame] | 271 | struct RTC_EXPORT Value { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 272 | enum Type { |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 273 | kInt, // int. |
| 274 | kInt64, // int64_t. |
| 275 | kFloat, // float. |
| 276 | kString, // std::string |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 277 | kStaticString, // const char*. |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 278 | kBool, // bool. |
| 279 | kId, // Id. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 280 | }; |
| 281 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 282 | Value(StatsValueName name, int64_t value, Type int_type); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 283 | Value(StatsValueName name, float f); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 284 | Value(StatsValueName name, const std::string& value); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 285 | Value(StatsValueName name, const char* value); |
| 286 | Value(StatsValueName name, bool b); |
| 287 | Value(StatsValueName name, const Id& value); |
| 288 | |
| 289 | ~Value(); |
| 290 | |
nisse | 6da303d | 2017-01-18 14:10:54 | [diff] [blame] | 291 | // Support ref counting. Note that for performance reasons, we |
| 292 | // don't use thread safe operations. Therefore, all operations |
| 293 | // affecting the ref count (in practice, creation and copying of |
| 294 | // the Values mapping) must occur on webrtc's signalling thread. |
| 295 | int AddRef() const { |
| 296 | RTC_DCHECK_RUN_ON(&thread_checker_); |
| 297 | return ++ref_count_; |
| 298 | } |
| 299 | int Release() const { |
| 300 | RTC_DCHECK_RUN_ON(&thread_checker_); |
| 301 | int count = --ref_count_; |
| 302 | if (!count) |
| 303 | delete this; |
| 304 | return count; |
| 305 | } |
| 306 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 307 | // TODO(tommi): This compares name as well as value... |
| 308 | // I think we should only need to compare the value part and |
| 309 | // move the name part into a hash map. |
| 310 | bool Equals(const Value& other) const; |
| 311 | |
| 312 | // Comparison operators. Return true iff the current instance is of the |
| 313 | // correct type and holds the same value. No conversion is performed so |
| 314 | // a string value of "123" is not equal to an int value of 123 and an int |
| 315 | // value of 123 is not equal to a float value of 123.0f. |
| 316 | // One exception to this is that types kInt and kInt64 can be compared and |
| 317 | // kString and kStaticString too. |
| 318 | bool operator==(const std::string& value) const; |
| 319 | bool operator==(const char* value) const; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 320 | bool operator==(int64_t value) const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 321 | bool operator==(bool value) const; |
| 322 | bool operator==(float value) const; |
| 323 | bool operator==(const Id& value) const; |
| 324 | |
| 325 | // Getters that allow getting the native value directly. |
| 326 | // The caller must know the type beforehand or else hit a check. |
| 327 | int int_val() const; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 328 | int64_t int64_val() const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 329 | float float_val() const; |
| 330 | const char* static_string_val() const; |
| 331 | const std::string& string_val() const; |
| 332 | bool bool_val() const; |
| 333 | const Id& id_val() const; |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 | [diff] [blame] | 334 | |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 335 | // Returns the string representation of |name|. |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 336 | const char* display_name() const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 337 | |
| 338 | // Converts the native value to a string representation of the value. |
| 339 | std::string ToString() const; |
| 340 | |
| 341 | Type type() const { return type_; } |
| 342 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 343 | // TODO(tommi): Move |name| and |display_name| out of the Value struct. |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 | [diff] [blame] | 344 | const StatsValueName name; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 345 | |
| 346 | private: |
Artem Titov | 06159aa | 2021-02-09 22:38:13 | [diff] [blame] | 347 | webrtc::SequenceChecker thread_checker_; |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 348 | mutable int ref_count_ RTC_GUARDED_BY(thread_checker_) = 0; |
nisse | 6da303d | 2017-01-18 14:10:54 | [diff] [blame] | 349 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 350 | const Type type_; |
| 351 | // TODO(tommi): Use C++ 11 union and make value_ const. |
| 352 | union InternalType { |
| 353 | int int_; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 354 | int64_t int64_; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 355 | float float_; |
| 356 | bool bool_; |
| 357 | std::string* string_; |
| 358 | const char* static_string_; |
| 359 | Id* id_; |
| 360 | } value_; |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 | [diff] [blame] | 361 | |
henrikg | 3c089d7 | 2015-09-16 12:37:44 | [diff] [blame] | 362 | RTC_DISALLOW_COPY_AND_ASSIGN(Value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 363 | }; |
| 364 | |
nisse | 6da303d | 2017-01-18 14:10:54 | [diff] [blame] | 365 | typedef rtc::scoped_refptr<Value> ValuePtr; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 366 | typedef std::map<StatsValueName, ValuePtr> Values; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 367 | |
| 368 | // Ownership of |id| is passed to |this|. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 369 | explicit StatsReport(const Id& id); |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 370 | ~StatsReport(); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 371 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 372 | // Factory functions for various types of stats IDs. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 373 | static Id NewBandwidthEstimationId(); |
| 374 | static Id NewTypedId(StatsType type, const std::string& id); |
| 375 | static Id NewTypedIntId(StatsType type, int id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 376 | static Id NewIdWithDirection(StatsType type, |
| 377 | const std::string& id, |
| 378 | Direction direction); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 379 | static Id NewCandidateId(bool local, const std::string& id); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 380 | static Id NewComponentId(const std::string& content_name, int component); |
| 381 | static Id NewCandidatePairId(const std::string& content_name, |
| 382 | int component, |
| 383 | int index); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 384 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 385 | const Id& id() const { return id_; } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 386 | StatsType type() const { return id_->type(); } |
| 387 | double timestamp() const { return timestamp_; } |
| 388 | void set_timestamp(double t) { timestamp_ = t; } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 389 | bool empty() const { return values_.empty(); } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 390 | const Values& values() const { return values_; } |
| 391 | |
| 392 | const char* TypeToString() const; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 393 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 394 | void AddString(StatsValueName name, const std::string& value); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 395 | void AddString(StatsValueName name, const char* value); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 396 | void AddInt64(StatsValueName name, int64_t value); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 397 | void AddInt(StatsValueName name, int value); |
| 398 | void AddFloat(StatsValueName name, float value); |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 | [diff] [blame] | 399 | void AddBoolean(StatsValueName name, bool value); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 400 | void AddId(StatsValueName name, const Id& value); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 401 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 402 | const Value* FindValue(StatsValueName name) const; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 403 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 404 | private: |
| 405 | // The unique identifier for this object. |
| 406 | // This is used as a key for this report in ordered containers, |
| 407 | // so it must never be changed. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 408 | const Id id_; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 409 | double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds. |
| 410 | Values values_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 411 | |
henrikg | 3c089d7 | 2015-09-16 12:37:44 | [diff] [blame] | 412 | RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 413 | }; |
| 414 | |
| 415 | // Typedef for an array of const StatsReport pointers. |
| 416 | // Ownership of the pointers held by this implementation is assumed to lie |
| 417 | // elsewhere and lifetime guarantees are made by the implementation that uses |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 418 | // this type. In the StatsCollector, object ownership lies with the |
| 419 | // StatsCollection class. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 420 | typedef std::vector<const StatsReport*> StatsReports; |
| 421 | |
| 422 | // A map from the report id to the report. |
| 423 | // This class wraps an STL container and provides a limited set of |
| 424 | // functionality in order to keep things simple. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 425 | class StatsCollection { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 426 | public: |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 427 | StatsCollection(); |
| 428 | ~StatsCollection(); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 429 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 430 | typedef std::list<StatsReport*> Container; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 431 | typedef Container::iterator iterator; |
| 432 | typedef Container::const_iterator const_iterator; |
| 433 | |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 434 | const_iterator begin() const; |
| 435 | const_iterator end() const; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 436 | size_t size() const; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 437 | |
| 438 | // Creates a new report object with |id| that does not already |
| 439 | // exist in the list of reports. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 440 | StatsReport* InsertNew(const StatsReport::Id& id); |
| 441 | StatsReport* FindOrAddNew(const StatsReport::Id& id); |
| 442 | StatsReport* ReplaceOrAddNew(const StatsReport::Id& id); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 443 | |
deadbeef | 8d60a94 | 2017-02-27 22:47:33 | [diff] [blame] | 444 | // Looks for a report with the given |id|. If one is not found, null |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 445 | // will be returned. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 446 | StatsReport* Find(const StatsReport::Id& id); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 447 | |
| 448 | private: |
| 449 | Container list_; |
Artem Titov | 06159aa | 2021-02-09 22:38:13 | [diff] [blame] | 450 | webrtc::SequenceChecker thread_checker_; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 | [diff] [blame] | 451 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 452 | |
| 453 | } // namespace webrtc |
| 454 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 455 | #endif // API_STATS_TYPES_H_ |