blob: 80f0eb5ae6f79cf0a4f8dd999851b08fe517efb0 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
11// This file contains structures used for retrieving statistics from an ongoing
12// libjingle session.
13
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#ifndef API_STATSTYPES_H_
15#define API_STATSTYPES_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016
tommi@webrtc.org5c3ee4b2014-12-09 10:47:01 +000017#include <algorithm>
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000018#include <list>
tommi@webrtc.org92f40182015-03-04 15:25:19 +000019#include <map>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <string>
oprypin803dc292017-02-01 01:55:59 -080021#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/basictypes.h"
24#include "rtc_base/constructormagic.h"
25#include "rtc_base/refcount.h"
26#include "rtc_base/scoped_ref_ptr.h"
27#include "rtc_base/stringencode.h"
28#include "rtc_base/thread_checker.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30namespace webrtc {
31
32class StatsReport {
33 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000034 // 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.orgaa2c3422014-12-09 20:23:06 +000040
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000041 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.org5b06b062014-08-15 08:38:30 +000047
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000048 // A StatsReport of |type| = "googTransport" contains information
49 // about a libjingle "transport".
50 kStatsReportTypeTransport,
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +000051
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000052 // 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.org5b06b062014-08-15 08:38:30 +000056
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000057 // 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.org28e20752013-07-10 00:45:36 +000061
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000062 // 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.org28e20752013-07-10 00:45:36 +000066
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000067 // 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.orgc57310b2014-12-12 17:41:28 +000099 enum StatsValueName {
100 kStatsValueNameActiveConnection,
Minyue2a8a78c2016-04-07 16:48:15 +0200101 kStatsValueNameAecDivergentFilterFraction,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000102 kStatsValueNameAudioInputLevel,
103 kStatsValueNameAudioOutputLevel,
104 kStatsValueNameBytesReceived,
105 kStatsValueNameBytesSent,
Peter Boströmb7d9a972015-12-18 16:01:11 +0100106 kStatsValueNameCodecImplementationName,
Steve Anton2dbc69f2017-08-24 17:15:13 -0700107 kStatsValueNameConcealedSamples,
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200108 kStatsValueNameConcealmentEvents,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000109 kStatsValueNameDataChannelId,
sakale5ba44e2016-10-26 07:09:24 -0700110 kStatsValueNameFramesDecoded,
sakal43536c32016-10-24 01:46:43 -0700111 kStatsValueNameFramesEncoded,
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200112 kStatsValueNameJitterBufferDelay,
fippobec70ab2016-01-28 01:27:15 -0800113 kStatsValueNameMediaType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000114 kStatsValueNamePacketsLost,
115 kStatsValueNamePacketsReceived,
116 kStatsValueNamePacketsSent,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000117 kStatsValueNameProtocol,
sakal87da4042016-10-31 06:53:47 -0700118 kStatsValueNameQpSum,
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700119 kStatsValueNameReceiving,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000120 kStatsValueNameSelectedCandidatePairId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000121 kStatsValueNameSsrc,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000122 kStatsValueNameState,
zsteine76bd3a2017-07-14 12:17:49 -0700123 kStatsValueNameTotalAudioEnergy,
124 kStatsValueNameTotalSamplesDuration,
Steve Anton2dbc69f2017-08-24 17:15:13 -0700125 kStatsValueNameTotalSamplesReceived,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000126 kStatsValueNameTransportId,
zhihuang5ecf16c2016-06-01 17:09:15 -0700127 kStatsValueNameSentPingRequestsTotal,
128 kStatsValueNameSentPingRequestsBeforeFirstResponse,
129 kStatsValueNameSentPingResponses,
130 kStatsValueNameRecvPingRequests,
131 kStatsValueNameRecvPingResponses,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000132
133 // Internal StatsValue names.
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200134 kStatsValueNameAccelerateRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000135 kStatsValueNameActualEncBitrate,
136 kStatsValueNameAdaptationChanges,
137 kStatsValueNameAvailableReceiveBandwidth,
138 kStatsValueNameAvailableSendBandwidth,
139 kStatsValueNameAvgEncodeMs,
140 kStatsValueNameBandwidthLimitedResolution,
141 kStatsValueNameBucketDelay,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000142 kStatsValueNameCaptureStartNtpTimeMs,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000143 kStatsValueNameCandidateIPAddress,
144 kStatsValueNameCandidateNetworkType,
145 kStatsValueNameCandidatePortNumber,
146 kStatsValueNameCandidatePriority,
147 kStatsValueNameCandidateTransportType,
148 kStatsValueNameCandidateType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000149 kStatsValueNameChannelId,
150 kStatsValueNameCodecName,
151 kStatsValueNameComponent,
152 kStatsValueNameContentName,
ilnik2e1b40b2017-09-04 07:57:17 -0700153 kStatsValueNameContentType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000154 kStatsValueNameCpuLimitedResolution,
155 kStatsValueNameCurrentDelayMs,
156 kStatsValueNameDecodeMs,
157 kStatsValueNameDecodingCNG,
158 kStatsValueNameDecodingCTN,
159 kStatsValueNameDecodingCTSG,
henrik.lundin63489782016-09-20 01:47:12 -0700160 kStatsValueNameDecodingMutedOutput,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000161 kStatsValueNameDecodingNormal,
162 kStatsValueNameDecodingPLC,
163 kStatsValueNameDecodingPLCCNG,
164 kStatsValueNameDer,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000165 kStatsValueNameDtlsCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000166 kStatsValueNameEchoCancellationQualityMin,
167 kStatsValueNameEchoDelayMedian,
168 kStatsValueNameEchoDelayStdDev,
169 kStatsValueNameEchoReturnLoss,
170 kStatsValueNameEchoReturnLossEnhancement,
171 kStatsValueNameEncodeUsagePercent,
172 kStatsValueNameExpandRate,
173 kStatsValueNameFingerprint,
174 kStatsValueNameFingerprintAlgorithm,
175 kStatsValueNameFirsReceived,
176 kStatsValueNameFirsSent,
177 kStatsValueNameFrameHeightInput,
178 kStatsValueNameFrameHeightReceived,
179 kStatsValueNameFrameHeightSent,
180 kStatsValueNameFrameRateDecoded,
181 kStatsValueNameFrameRateInput,
182 kStatsValueNameFrameRateOutput,
183 kStatsValueNameFrameRateReceived,
184 kStatsValueNameFrameRateSent,
185 kStatsValueNameFrameWidthInput,
186 kStatsValueNameFrameWidthReceived,
187 kStatsValueNameFrameWidthSent,
Ă…sa Perssonc3ed6302017-11-16 14:04:52 +0100188 kStatsValueNameHasEnteredLowResolution,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000189 kStatsValueNameInitiator,
ilnik2e1b40b2017-09-04 07:57:17 -0700190 kStatsValueNameInterframeDelayMaxMs, // Max over last 10 seconds.
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000191 kStatsValueNameIssuerId,
192 kStatsValueNameJitterBufferMs,
193 kStatsValueNameJitterReceived,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000194 kStatsValueNameLabel,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000195 kStatsValueNameLocalAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000196 kStatsValueNameLocalCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000197 kStatsValueNameLocalCandidateType,
198 kStatsValueNameLocalCertificateId,
199 kStatsValueNameMaxDecodeMs,
200 kStatsValueNameMinPlayoutDelayMs,
201 kStatsValueNameNacksReceived,
202 kStatsValueNameNacksSent,
203 kStatsValueNamePlisReceived,
204 kStatsValueNamePlisSent,
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200205 kStatsValueNamePreemptiveExpandRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000206 kStatsValueNamePreferredJitterBufferMs,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000207 kStatsValueNameRemoteAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000208 kStatsValueNameRemoteCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000209 kStatsValueNameRemoteCandidateType,
210 kStatsValueNameRemoteCertificateId,
211 kStatsValueNameRenderDelayMs,
ivoc8c63a822016-10-21 04:10:03 -0700212 kStatsValueNameResidualEchoLikelihood,
ivoc4e477a12017-01-15 08:29:46 -0800213 kStatsValueNameResidualEchoLikelihoodRecentMax,
ivoce1198e02017-09-08 08:13:19 -0700214 kStatsValueNameAnaBitrateActionCounter,
215 kStatsValueNameAnaChannelActionCounter,
216 kStatsValueNameAnaDtxActionCounter,
217 kStatsValueNameAnaFecActionCounter,
ivoc0d0b9122017-09-08 13:24:21 -0700218 kStatsValueNameAnaFrameLengthIncreaseCounter,
219 kStatsValueNameAnaFrameLengthDecreaseCounter,
220 kStatsValueNameAnaUplinkPacketLossFraction,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000221 kStatsValueNameRetransmitBitrate,
222 kStatsValueNameRtt,
minyue@webrtc.org652bc372015-02-18 23:50:46 +0000223 kStatsValueNameSecondaryDecodedRate,
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200224 kStatsValueNameSecondaryDiscardedRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000225 kStatsValueNameSendPacketsDiscarded,
minyue@webrtc.org652bc372015-02-18 23:50:46 +0000226 kStatsValueNameSpeechExpandRate,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000227 kStatsValueNameSrtpCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000228 kStatsValueNameTargetDelayMs,
229 kStatsValueNameTargetEncBitrate,
ilnik2edc6842017-07-06 03:06:50 -0700230 kStatsValueNameTimingFrameInfo, // Result of |TimingFrameInfo::ToString|
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000231 kStatsValueNameTrackId,
232 kStatsValueNameTransmitBitrate,
233 kStatsValueNameTransportType,
234 kStatsValueNameTypingNoiseState,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000235 kStatsValueNameWritable,
236 };
237
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000238 class IdBase : public rtc::RefCountInterface {
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000239 public:
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000240 ~IdBase() override;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000241 StatsType type() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000242
243 // Users of IdBase will be using the Id typedef, which is compatible with
244 // this Equals() function. It simply calls the protected (and overridden)
245 // Equals() method.
246 bool Equals(const rtc::scoped_refptr<IdBase>& other) const {
247 return Equals(*other.get());
248 }
249
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000250 virtual std::string ToString() const = 0;
251
252 protected:
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000253 // Protected since users of the IdBase type will be using the Id typedef.
254 virtual bool Equals(const IdBase& other) const;
255
oprypin803dc292017-02-01 01:55:59 -0800256 explicit IdBase(StatsType type); // Only meant for derived classes.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000257 const StatsType type_;
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000258
259 static const char kSeparator = '_';
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000260 };
261
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000262 typedef rtc::scoped_refptr<IdBase> Id;
263
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 struct Value {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000265 enum Type {
Peter Boström0c4e06b2015-10-07 12:23:21 +0200266 kInt, // int.
267 kInt64, // int64_t.
268 kFloat, // float.
269 kString, // std::string
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000270 kStaticString, // const char*.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200271 kBool, // bool.
272 kId, // Id.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000273 };
274
Peter Boström0c4e06b2015-10-07 12:23:21 +0200275 Value(StatsValueName name, int64_t value, Type int_type);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000276 Value(StatsValueName name, float f);
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000277 Value(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000278 Value(StatsValueName name, const char* value);
279 Value(StatsValueName name, bool b);
280 Value(StatsValueName name, const Id& value);
281
282 ~Value();
283
nisse6da303d2017-01-18 06:10:54 -0800284 // Support ref counting. Note that for performance reasons, we
285 // don't use thread safe operations. Therefore, all operations
286 // affecting the ref count (in practice, creation and copying of
287 // the Values mapping) must occur on webrtc's signalling thread.
288 int AddRef() const {
289 RTC_DCHECK_RUN_ON(&thread_checker_);
290 return ++ref_count_;
291 }
292 int Release() const {
293 RTC_DCHECK_RUN_ON(&thread_checker_);
294 int count = --ref_count_;
295 if (!count)
296 delete this;
297 return count;
298 }
299
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000300 // TODO(tommi): This compares name as well as value...
301 // I think we should only need to compare the value part and
302 // move the name part into a hash map.
303 bool Equals(const Value& other) const;
304
305 // Comparison operators. Return true iff the current instance is of the
306 // correct type and holds the same value. No conversion is performed so
307 // a string value of "123" is not equal to an int value of 123 and an int
308 // value of 123 is not equal to a float value of 123.0f.
309 // One exception to this is that types kInt and kInt64 can be compared and
310 // kString and kStaticString too.
311 bool operator==(const std::string& value) const;
312 bool operator==(const char* value) const;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200313 bool operator==(int64_t value) const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000314 bool operator==(bool value) const;
315 bool operator==(float value) const;
316 bool operator==(const Id& value) const;
317
318 // Getters that allow getting the native value directly.
319 // The caller must know the type beforehand or else hit a check.
320 int int_val() const;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200321 int64_t int64_val() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000322 float float_val() const;
323 const char* static_string_val() const;
324 const std::string& string_val() const;
325 bool bool_val() const;
326 const Id& id_val() const;
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000327
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000328 // Returns the string representation of |name|.
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000329 const char* display_name() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000330
331 // Converts the native value to a string representation of the value.
332 std::string ToString() const;
333
334 Type type() const { return type_; }
335
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000336 // TODO(tommi): Move |name| and |display_name| out of the Value struct.
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000337 const StatsValueName name;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000338
339 private:
nisse6da303d2017-01-18 06:10:54 -0800340 rtc::ThreadChecker thread_checker_;
danilchapa37de392017-09-09 04:17:22 -0700341 mutable int ref_count_ RTC_ACCESS_ON(thread_checker_) = 0;
nisse6da303d2017-01-18 06:10:54 -0800342
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000343 const Type type_;
344 // TODO(tommi): Use C++ 11 union and make value_ const.
345 union InternalType {
346 int int_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200347 int64_t int64_;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000348 float float_;
349 bool bool_;
350 std::string* string_;
351 const char* static_string_;
352 Id* id_;
353 } value_;
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000354
henrikg3c089d72015-09-16 05:37:44 -0700355 RTC_DISALLOW_COPY_AND_ASSIGN(Value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 };
357
nisse6da303d2017-01-18 06:10:54 -0800358 typedef rtc::scoped_refptr<Value> ValuePtr;
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000359 typedef std::map<StatsValueName, ValuePtr> Values;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000360
361 // Ownership of |id| is passed to |this|.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000362 explicit StatsReport(const Id& id);
ossu7bb87ee2017-01-23 04:56:25 -0800363 ~StatsReport();
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000364
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000365 // Factory functions for various types of stats IDs.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000366 static Id NewBandwidthEstimationId();
367 static Id NewTypedId(StatsType type, const std::string& id);
368 static Id NewTypedIntId(StatsType type, int id);
369 static Id NewIdWithDirection(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000370 StatsType type, const std::string& id, Direction direction);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000371 static Id NewCandidateId(bool local, const std::string& id);
372 static Id NewComponentId(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000373 const std::string& content_name, int component);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000374 static Id NewCandidatePairId(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000375 const std::string& content_name, int component, int index);
376
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000377 const Id& id() const { return id_; }
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000378 StatsType type() const { return id_->type(); }
379 double timestamp() const { return timestamp_; }
380 void set_timestamp(double t) { timestamp_ = t; }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000381 bool empty() const { return values_.empty(); }
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000382 const Values& values() const { return values_; }
383
384 const char* TypeToString() const;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000385
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000386 void AddString(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000387 void AddString(StatsValueName name, const char* value);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200388 void AddInt64(StatsValueName name, int64_t value);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000389 void AddInt(StatsValueName name, int value);
390 void AddFloat(StatsValueName name, float value);
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000391 void AddBoolean(StatsValueName name, bool value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000392 void AddId(StatsValueName name, const Id& value);
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000393
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000394 const Value* FindValue(StatsValueName name) const;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000395
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000396 private:
397 // The unique identifier for this object.
398 // This is used as a key for this report in ordered containers,
399 // so it must never be changed.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000400 const Id id_;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000401 double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds.
402 Values values_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403
henrikg3c089d72015-09-16 05:37:44 -0700404 RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000405};
406
407// Typedef for an array of const StatsReport pointers.
408// Ownership of the pointers held by this implementation is assumed to lie
409// elsewhere and lifetime guarantees are made by the implementation that uses
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000410// this type. In the StatsCollector, object ownership lies with the
411// StatsCollection class.
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000412typedef std::vector<const StatsReport*> StatsReports;
413
414// A map from the report id to the report.
415// This class wraps an STL container and provides a limited set of
416// functionality in order to keep things simple.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000417class StatsCollection {
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000418 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000419 StatsCollection();
420 ~StatsCollection();
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000421
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000422 typedef std::list<StatsReport*> Container;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000423 typedef Container::iterator iterator;
424 typedef Container::const_iterator const_iterator;
425
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000426 const_iterator begin() const;
427 const_iterator end() const;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000428 size_t size() const;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000429
430 // Creates a new report object with |id| that does not already
431 // exist in the list of reports.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000432 StatsReport* InsertNew(const StatsReport::Id& id);
433 StatsReport* FindOrAddNew(const StatsReport::Id& id);
434 StatsReport* ReplaceOrAddNew(const StatsReport::Id& id);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000435
deadbeef8d60a942017-02-27 14:47:33 -0800436 // Looks for a report with the given |id|. If one is not found, null
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000437 // will be returned.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000438 StatsReport* Find(const StatsReport::Id& id);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000439
440 private:
441 Container list_;
jbauch25c96d02015-08-07 09:48:18 -0700442 rtc::ThreadChecker thread_checker_;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000443};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444
445} // namespace webrtc
446
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200447#endif // API_STATSTYPES_H_