blob: 0e97eaf596b08fa74410e7b932fe84c761819e06 [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
Steve Anton10542f22019-01-11 09:11:00 -080014#ifndef API_STATS_TYPES_H_
15#define API_STATS_TYPES_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 Bonadeid9708072019-01-25 20:26:48 +010023#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "rtc_base/constructor_magic.h"
25#include "rtc_base/ref_count.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "rtc_base/string_encode.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "rtc_base/thread_checker.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
29namespace webrtc {
30
31class StatsReport {
32 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000033 // 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.orgaa2c3422014-12-09 20:23:06 +000039
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000040 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.org5b06b062014-08-15 08:38:30 +000046
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000047 // A StatsReport of |type| = "googTransport" contains information
48 // about a libjingle "transport".
49 kStatsReportTypeTransport,
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +000050
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000051 // 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.org5b06b062014-08-15 08:38:30 +000055
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000056 // 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.org28e20752013-07-10 00:45:36 +000060
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000061 // 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.org28e20752013-07-10 00:45:36 +000065
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000066 // 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.orgc57310b2014-12-12 17:41:28 +000098 enum StatsValueName {
99 kStatsValueNameActiveConnection,
Minyue2a8a78c2016-04-07 16:48:15 +0200100 kStatsValueNameAecDivergentFilterFraction,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000101 kStatsValueNameAudioInputLevel,
102 kStatsValueNameAudioOutputLevel,
103 kStatsValueNameBytesReceived,
104 kStatsValueNameBytesSent,
Peter Boströmb7d9a972015-12-18 16:01:11 +0100105 kStatsValueNameCodecImplementationName,
Steve Anton2dbc69f2017-08-24 17:15:13 -0700106 kStatsValueNameConcealedSamples,
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200107 kStatsValueNameConcealmentEvents,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000108 kStatsValueNameDataChannelId,
sakale5ba44e2016-10-26 07:09:24 -0700109 kStatsValueNameFramesDecoded,
sakal43536c32016-10-24 01:46:43 -0700110 kStatsValueNameFramesEncoded,
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200111 kStatsValueNameJitterBufferDelay,
fippobec70ab2016-01-28 01:27:15 -0800112 kStatsValueNameMediaType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000113 kStatsValueNamePacketsLost,
114 kStatsValueNamePacketsReceived,
115 kStatsValueNamePacketsSent,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000116 kStatsValueNameProtocol,
sakal87da4042016-10-31 06:53:47 -0700117 kStatsValueNameQpSum,
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700118 kStatsValueNameReceiving,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000119 kStatsValueNameSelectedCandidatePairId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000120 kStatsValueNameSsrc,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000121 kStatsValueNameState,
zsteine76bd3a2017-07-14 12:17:49 -0700122 kStatsValueNameTotalAudioEnergy,
123 kStatsValueNameTotalSamplesDuration,
Steve Anton2dbc69f2017-08-24 17:15:13 -0700124 kStatsValueNameTotalSamplesReceived,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000125 kStatsValueNameTransportId,
zhihuang5ecf16c2016-06-01 17:09:15 -0700126 kStatsValueNameSentPingRequestsTotal,
127 kStatsValueNameSentPingRequestsBeforeFirstResponse,
128 kStatsValueNameSentPingResponses,
129 kStatsValueNameRecvPingRequests,
130 kStatsValueNameRecvPingResponses,
Qingsi Wang72a43a12018-02-20 16:03:18 -0800131 kStatsValueNameSentStunKeepaliveRequests,
132 kStatsValueNameRecvStunKeepaliveResponses,
133 kStatsValueNameStunKeepaliveRttTotal,
134 kStatsValueNameStunKeepaliveRttSquaredTotal,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000135
136 // Internal StatsValue names.
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200137 kStatsValueNameAccelerateRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000138 kStatsValueNameActualEncBitrate,
139 kStatsValueNameAdaptationChanges,
140 kStatsValueNameAvailableReceiveBandwidth,
141 kStatsValueNameAvailableSendBandwidth,
142 kStatsValueNameAvgEncodeMs,
143 kStatsValueNameBandwidthLimitedResolution,
144 kStatsValueNameBucketDelay,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000145 kStatsValueNameCaptureStartNtpTimeMs,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000146 kStatsValueNameCandidateIPAddress,
147 kStatsValueNameCandidateNetworkType,
148 kStatsValueNameCandidatePortNumber,
149 kStatsValueNameCandidatePriority,
150 kStatsValueNameCandidateTransportType,
151 kStatsValueNameCandidateType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000152 kStatsValueNameChannelId,
153 kStatsValueNameCodecName,
154 kStatsValueNameComponent,
155 kStatsValueNameContentName,
ilnik2e1b40b2017-09-04 07:57:17 -0700156 kStatsValueNameContentType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000157 kStatsValueNameCpuLimitedResolution,
158 kStatsValueNameCurrentDelayMs,
159 kStatsValueNameDecodeMs,
160 kStatsValueNameDecodingCNG,
161 kStatsValueNameDecodingCTN,
162 kStatsValueNameDecodingCTSG,
henrik.lundin63489782016-09-20 01:47:12 -0700163 kStatsValueNameDecodingMutedOutput,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000164 kStatsValueNameDecodingNormal,
165 kStatsValueNameDecodingPLC,
166 kStatsValueNameDecodingPLCCNG,
167 kStatsValueNameDer,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000168 kStatsValueNameDtlsCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000169 kStatsValueNameEchoDelayMedian,
170 kStatsValueNameEchoDelayStdDev,
171 kStatsValueNameEchoReturnLoss,
172 kStatsValueNameEchoReturnLossEnhancement,
173 kStatsValueNameEncodeUsagePercent,
174 kStatsValueNameExpandRate,
175 kStatsValueNameFingerprint,
176 kStatsValueNameFingerprintAlgorithm,
177 kStatsValueNameFirsReceived,
178 kStatsValueNameFirsSent,
Benjamin Wright514f0842018-12-10 09:55:17 -0800179 kStatsValueNameFirstFrameReceivedToDecodedMs,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000180 kStatsValueNameFrameHeightInput,
181 kStatsValueNameFrameHeightReceived,
182 kStatsValueNameFrameHeightSent,
183 kStatsValueNameFrameRateDecoded,
184 kStatsValueNameFrameRateInput,
185 kStatsValueNameFrameRateOutput,
186 kStatsValueNameFrameRateReceived,
187 kStatsValueNameFrameRateSent,
188 kStatsValueNameFrameWidthInput,
189 kStatsValueNameFrameWidthReceived,
190 kStatsValueNameFrameWidthSent,
Ă…sa Perssonc3ed6302017-11-16 14:04:52 +0100191 kStatsValueNameHasEnteredLowResolution,
Ilya Nikolaevskiy70473fc2018-02-28 16:35:03 +0100192 kStatsValueNameHugeFramesSent,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000193 kStatsValueNameInitiator,
ilnik2e1b40b2017-09-04 07:57:17 -0700194 kStatsValueNameInterframeDelayMaxMs, // Max over last 10 seconds.
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000195 kStatsValueNameIssuerId,
196 kStatsValueNameJitterBufferMs,
197 kStatsValueNameJitterReceived,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000198 kStatsValueNameLabel,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000199 kStatsValueNameLocalAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000200 kStatsValueNameLocalCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000201 kStatsValueNameLocalCandidateType,
202 kStatsValueNameLocalCertificateId,
203 kStatsValueNameMaxDecodeMs,
204 kStatsValueNameMinPlayoutDelayMs,
205 kStatsValueNameNacksReceived,
206 kStatsValueNameNacksSent,
207 kStatsValueNamePlisReceived,
208 kStatsValueNamePlisSent,
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200209 kStatsValueNamePreemptiveExpandRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000210 kStatsValueNamePreferredJitterBufferMs,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000211 kStatsValueNameRemoteAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000212 kStatsValueNameRemoteCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000213 kStatsValueNameRemoteCandidateType,
214 kStatsValueNameRemoteCertificateId,
215 kStatsValueNameRenderDelayMs,
ivoc8c63a822016-10-21 04:10:03 -0700216 kStatsValueNameResidualEchoLikelihood,
ivoc4e477a12017-01-15 08:29:46 -0800217 kStatsValueNameResidualEchoLikelihoodRecentMax,
ivoce1198e02017-09-08 08:13:19 -0700218 kStatsValueNameAnaBitrateActionCounter,
219 kStatsValueNameAnaChannelActionCounter,
220 kStatsValueNameAnaDtxActionCounter,
221 kStatsValueNameAnaFecActionCounter,
ivoc0d0b9122017-09-08 13:24:21 -0700222 kStatsValueNameAnaFrameLengthIncreaseCounter,
223 kStatsValueNameAnaFrameLengthDecreaseCounter,
224 kStatsValueNameAnaUplinkPacketLossFraction,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000225 kStatsValueNameRetransmitBitrate,
226 kStatsValueNameRtt,
minyue@webrtc.org652bc372015-02-18 23:50:46 +0000227 kStatsValueNameSecondaryDecodedRate,
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200228 kStatsValueNameSecondaryDiscardedRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000229 kStatsValueNameSendPacketsDiscarded,
minyue@webrtc.org652bc372015-02-18 23:50:46 +0000230 kStatsValueNameSpeechExpandRate,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000231 kStatsValueNameSrtpCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000232 kStatsValueNameTargetDelayMs,
233 kStatsValueNameTargetEncBitrate,
ilnik2edc6842017-07-06 03:06:50 -0700234 kStatsValueNameTimingFrameInfo, // Result of |TimingFrameInfo::ToString|
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000235 kStatsValueNameTrackId,
236 kStatsValueNameTransmitBitrate,
237 kStatsValueNameTransportType,
238 kStatsValueNameTypingNoiseState,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000239 kStatsValueNameWritable,
240 };
241
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000242 class IdBase : public rtc::RefCountInterface {
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000243 public:
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000244 ~IdBase() override;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000245 StatsType type() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000246
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.org4fb7e252015-01-21 11:36:18 +0000254 virtual std::string ToString() const = 0;
255
256 protected:
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000257 // Protected since users of the IdBase type will be using the Id typedef.
258 virtual bool Equals(const IdBase& other) const;
259
oprypin803dc292017-02-01 01:55:59 -0800260 explicit IdBase(StatsType type); // Only meant for derived classes.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000261 const StatsType type_;
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000262
263 static const char kSeparator = '_';
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000264 };
265
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000266 typedef rtc::scoped_refptr<IdBase> Id;
267
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 struct Value {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000269 enum Type {
Peter Boström0c4e06b2015-10-07 12:23:21 +0200270 kInt, // int.
271 kInt64, // int64_t.
272 kFloat, // float.
273 kString, // std::string
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000274 kStaticString, // const char*.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200275 kBool, // bool.
276 kId, // Id.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000277 };
278
Peter Boström0c4e06b2015-10-07 12:23:21 +0200279 Value(StatsValueName name, int64_t value, Type int_type);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000280 Value(StatsValueName name, float f);
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000281 Value(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000282 Value(StatsValueName name, const char* value);
283 Value(StatsValueName name, bool b);
284 Value(StatsValueName name, const Id& value);
285
286 ~Value();
287
nisse6da303d2017-01-18 06:10:54 -0800288 // 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.orgd3900292015-03-12 16:35:55 +0000304 // 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öm0c4e06b2015-10-07 12:23:21 +0200317 bool operator==(int64_t value) const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000318 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öm0c4e06b2015-10-07 12:23:21 +0200325 int64_t int64_val() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000326 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.org242068d2014-07-14 20:19:56 +0000331
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000332 // Returns the string representation of |name|.
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000333 const char* display_name() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000334
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.org92f40182015-03-04 15:25:19 +0000340 // TODO(tommi): Move |name| and |display_name| out of the Value struct.
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000341 const StatsValueName name;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000342
343 private:
nisse6da303d2017-01-18 06:10:54 -0800344 rtc::ThreadChecker thread_checker_;
Niels Möller1e062892018-02-07 10:18:32 +0100345 mutable int ref_count_ RTC_GUARDED_BY(thread_checker_) = 0;
nisse6da303d2017-01-18 06:10:54 -0800346
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000347 const Type type_;
348 // TODO(tommi): Use C++ 11 union and make value_ const.
349 union InternalType {
350 int int_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200351 int64_t int64_;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000352 float float_;
353 bool bool_;
354 std::string* string_;
355 const char* static_string_;
356 Id* id_;
357 } value_;
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000358
henrikg3c089d72015-09-16 05:37:44 -0700359 RTC_DISALLOW_COPY_AND_ASSIGN(Value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 };
361
nisse6da303d2017-01-18 06:10:54 -0800362 typedef rtc::scoped_refptr<Value> ValuePtr;
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000363 typedef std::map<StatsValueName, ValuePtr> Values;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000364
365 // Ownership of |id| is passed to |this|.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000366 explicit StatsReport(const Id& id);
ossu7bb87ee2017-01-23 04:56:25 -0800367 ~StatsReport();
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000368
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000369 // Factory functions for various types of stats IDs.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000370 static Id NewBandwidthEstimationId();
371 static Id NewTypedId(StatsType type, const std::string& id);
372 static Id NewTypedIntId(StatsType type, int id);
Yves Gerey665174f2018-06-19 15:03:05 +0200373 static Id NewIdWithDirection(StatsType type,
374 const std::string& id,
375 Direction direction);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000376 static Id NewCandidateId(bool local, const std::string& id);
Yves Gerey665174f2018-06-19 15:03:05 +0200377 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.org4fb7e252015-01-21 11:36:18 +0000381
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000382 const Id& id() const { return id_; }
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000383 StatsType type() const { return id_->type(); }
384 double timestamp() const { return timestamp_; }
385 void set_timestamp(double t) { timestamp_ = t; }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000386 bool empty() const { return values_.empty(); }
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000387 const Values& values() const { return values_; }
388
389 const char* TypeToString() const;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000390
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000391 void AddString(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000392 void AddString(StatsValueName name, const char* value);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200393 void AddInt64(StatsValueName name, int64_t value);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000394 void AddInt(StatsValueName name, int value);
395 void AddFloat(StatsValueName name, float value);
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000396 void AddBoolean(StatsValueName name, bool value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000397 void AddId(StatsValueName name, const Id& value);
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000398
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000399 const Value* FindValue(StatsValueName name) const;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000400
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000401 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.orgd3900292015-03-12 16:35:55 +0000405 const Id id_;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000406 double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds.
407 Values values_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408
henrikg3c089d72015-09-16 05:37:44 -0700409 RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000410};
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.org4fb7e252015-01-21 11:36:18 +0000415// this type. In the StatsCollector, object ownership lies with the
416// StatsCollection class.
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000417typedef 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.org4fb7e252015-01-21 11:36:18 +0000422class StatsCollection {
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000423 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000424 StatsCollection();
425 ~StatsCollection();
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000426
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000427 typedef std::list<StatsReport*> Container;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000428 typedef Container::iterator iterator;
429 typedef Container::const_iterator const_iterator;
430
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000431 const_iterator begin() const;
432 const_iterator end() const;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000433 size_t size() const;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000434
435 // Creates a new report object with |id| that does not already
436 // exist in the list of reports.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000437 StatsReport* InsertNew(const StatsReport::Id& id);
438 StatsReport* FindOrAddNew(const StatsReport::Id& id);
439 StatsReport* ReplaceOrAddNew(const StatsReport::Id& id);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000440
deadbeef8d60a942017-02-27 14:47:33 -0800441 // Looks for a report with the given |id|. If one is not found, null
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000442 // will be returned.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000443 StatsReport* Find(const StatsReport::Id& id);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000444
445 private:
446 Container list_;
jbauch25c96d02015-08-07 09:48:18 -0700447 rtc::ThreadChecker thread_checker_;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000448};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449
450} // namespace webrtc
451
Steve Anton10542f22019-01-11 09:11:00 -0800452#endif // API_STATS_TYPES_H_