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