blob: e653d15bf2320433f214aa5412fd7ff4da914c6c [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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:369 */
10
11// This file contains structures used for retrieving statistics from an ongoing
12// libjingle session.
13
Mirko Bonadei92ea95e2017-09-15 04:47:3114#ifndef API_STATSTYPES_H_
15#define API_STATSTYPES_H_
henrike@webrtc.org28e20752013-07-10 00:45:3616
tommi@webrtc.org5c3ee4b2014-12-09 10:47:0117#include <algorithm>
tommi@webrtc.org4fb7e252015-01-21 11:36:1818#include <list>
tommi@webrtc.org92f40182015-03-04 15:25:1919#include <map>
henrike@webrtc.org28e20752013-07-10 00:45:3620#include <string>
oprypin803dc292017-02-01 09:55:5921#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:3622
Mirko Bonadei92ea95e2017-09-15 04:47:3123#include "rtc_base/constructormagic.h"
24#include "rtc_base/refcount.h"
25#include "rtc_base/scoped_ref_ptr.h"
26#include "rtc_base/stringencode.h"
27#include "rtc_base/thread_checker.h"
henrike@webrtc.org28e20752013-07-10 00:45:3628
29namespace webrtc {
30
31class StatsReport {
32 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:1833 // 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:0639
tommi@webrtc.org4fb7e252015-01-21 11:36:1840 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:3046
tommi@webrtc.org4fb7e252015-01-21 11:36:1847 // A StatsReport of |type| = "googTransport" contains information
48 // about a libjingle "transport".
49 kStatsReportTypeTransport,
tommi@webrtc.orgc9d155f2014-12-09 18:18:0650
tommi@webrtc.org4fb7e252015-01-21 11:36:1851 // 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:3055
tommi@webrtc.org4fb7e252015-01-21 11:36:1856 // 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:3660
tommi@webrtc.org4fb7e252015-01-21 11:36:1861 // 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:3665
tommi@webrtc.org4fb7e252015-01-21 11:36:1866 // 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:2898 enum StatsValueName {
99 kStatsValueNameActiveConnection,
Minyue2a8a78c2016-04-07 14:48:15100 kStatsValueNameAecDivergentFilterFraction,
tommi@webrtc.orgc57310b2014-12-12 17:41:28101 kStatsValueNameAudioInputLevel,
102 kStatsValueNameAudioOutputLevel,
103 kStatsValueNameBytesReceived,
104 kStatsValueNameBytesSent,
Peter Boströmb7d9a972015-12-18 15:01:11105 kStatsValueNameCodecImplementationName,
Steve Anton2dbc69f2017-08-25 00:15:13106 kStatsValueNameConcealedSamples,
Gustaf Ullberg9a2e9062017-09-18 07:28:20107 kStatsValueNameConcealmentEvents,
decurtis@webrtc.org487a4442015-01-15 22:55:07108 kStatsValueNameDataChannelId,
sakale5ba44e2016-10-26 14:09:24109 kStatsValueNameFramesDecoded,
sakal43536c32016-10-24 08:46:43110 kStatsValueNameFramesEncoded,
Gustaf Ullbergb0a02072017-10-02 10:00:34111 kStatsValueNameJitterBufferDelay,
fippobec70ab2016-01-28 09:27:15112 kStatsValueNameMediaType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28113 kStatsValueNamePacketsLost,
114 kStatsValueNamePacketsReceived,
115 kStatsValueNamePacketsSent,
decurtis@webrtc.org487a4442015-01-15 22:55:07116 kStatsValueNameProtocol,
sakal87da4042016-10-31 13:53:47117 kStatsValueNameQpSum,
Peter Thatcher04ac81f2015-09-21 18:48:28118 kStatsValueNameReceiving,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30119 kStatsValueNameSelectedCandidatePairId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28120 kStatsValueNameSsrc,
decurtis@webrtc.org487a4442015-01-15 22:55:07121 kStatsValueNameState,
zsteine76bd3a2017-07-14 19:17:49122 kStatsValueNameTotalAudioEnergy,
123 kStatsValueNameTotalSamplesDuration,
Steve Anton2dbc69f2017-08-25 00:15:13124 kStatsValueNameTotalSamplesReceived,
tommi@webrtc.orgc57310b2014-12-12 17:41:28125 kStatsValueNameTransportId,
zhihuang5ecf16c2016-06-02 00:09:15126 kStatsValueNameSentPingRequestsTotal,
127 kStatsValueNameSentPingRequestsBeforeFirstResponse,
128 kStatsValueNameSentPingResponses,
129 kStatsValueNameRecvPingRequests,
130 kStatsValueNameRecvPingResponses,
Qingsi Wang72a43a12018-02-21 00:03:18131 kStatsValueNameSentStunKeepaliveRequests,
132 kStatsValueNameRecvStunKeepaliveResponses,
133 kStatsValueNameStunKeepaliveRttTotal,
134 kStatsValueNameStunKeepaliveRttSquaredTotal,
tommi@webrtc.orgc57310b2014-12-12 17:41:28135
136 // Internal StatsValue names.
Henrik Lundin8e6fd462015-06-02 07:24:52137 kStatsValueNameAccelerateRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28138 kStatsValueNameActualEncBitrate,
139 kStatsValueNameAdaptationChanges,
140 kStatsValueNameAvailableReceiveBandwidth,
141 kStatsValueNameAvailableSendBandwidth,
142 kStatsValueNameAvgEncodeMs,
143 kStatsValueNameBandwidthLimitedResolution,
144 kStatsValueNameBucketDelay,
tommi@webrtc.orgc57310b2014-12-12 17:41:28145 kStatsValueNameCaptureStartNtpTimeMs,
guoweis@webrtc.org950c5182014-12-16 23:01:31146 kStatsValueNameCandidateIPAddress,
147 kStatsValueNameCandidateNetworkType,
148 kStatsValueNameCandidatePortNumber,
149 kStatsValueNameCandidatePriority,
150 kStatsValueNameCandidateTransportType,
151 kStatsValueNameCandidateType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28152 kStatsValueNameChannelId,
153 kStatsValueNameCodecName,
154 kStatsValueNameComponent,
155 kStatsValueNameContentName,
ilnik2e1b40b2017-09-04 14:57:17156 kStatsValueNameContentType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28157 kStatsValueNameCpuLimitedResolution,
158 kStatsValueNameCurrentDelayMs,
159 kStatsValueNameDecodeMs,
160 kStatsValueNameDecodingCNG,
161 kStatsValueNameDecodingCTN,
162 kStatsValueNameDecodingCTSG,
henrik.lundin63489782016-09-20 08:47:12163 kStatsValueNameDecodingMutedOutput,
tommi@webrtc.orgc57310b2014-12-12 17:41:28164 kStatsValueNameDecodingNormal,
165 kStatsValueNameDecodingPLC,
166 kStatsValueNameDecodingPLCCNG,
167 kStatsValueNameDer,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30168 kStatsValueNameDtlsCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28169 kStatsValueNameEchoDelayMedian,
170 kStatsValueNameEchoDelayStdDev,
171 kStatsValueNameEchoReturnLoss,
172 kStatsValueNameEchoReturnLossEnhancement,
173 kStatsValueNameEncodeUsagePercent,
174 kStatsValueNameExpandRate,
175 kStatsValueNameFingerprint,
176 kStatsValueNameFingerprintAlgorithm,
177 kStatsValueNameFirsReceived,
178 kStatsValueNameFirsSent,
Benjamin Wright514f0842018-12-10 17:55:17179 kStatsValueNameFirstFrameReceivedToDecodedMs,
tommi@webrtc.orgc57310b2014-12-12 17:41:28180 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 13:04:52191 kStatsValueNameHasEnteredLowResolution,
Ilya Nikolaevskiy70473fc2018-02-28 15:35:03192 kStatsValueNameHugeFramesSent,
tommi@webrtc.orgc57310b2014-12-12 17:41:28193 kStatsValueNameInitiator,
ilnik2e1b40b2017-09-04 14:57:17194 kStatsValueNameInterframeDelayMaxMs, // Max over last 10 seconds.
tommi@webrtc.orgc57310b2014-12-12 17:41:28195 kStatsValueNameIssuerId,
196 kStatsValueNameJitterBufferMs,
197 kStatsValueNameJitterReceived,
decurtis@webrtc.org487a4442015-01-15 22:55:07198 kStatsValueNameLabel,
tommi@webrtc.orgc57310b2014-12-12 17:41:28199 kStatsValueNameLocalAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31200 kStatsValueNameLocalCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28201 kStatsValueNameLocalCandidateType,
202 kStatsValueNameLocalCertificateId,
203 kStatsValueNameMaxDecodeMs,
204 kStatsValueNameMinPlayoutDelayMs,
205 kStatsValueNameNacksReceived,
206 kStatsValueNameNacksSent,
207 kStatsValueNamePlisReceived,
208 kStatsValueNamePlisSent,
Henrik Lundin8e6fd462015-06-02 07:24:52209 kStatsValueNamePreemptiveExpandRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28210 kStatsValueNamePreferredJitterBufferMs,
tommi@webrtc.orgc57310b2014-12-12 17:41:28211 kStatsValueNameRemoteAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31212 kStatsValueNameRemoteCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28213 kStatsValueNameRemoteCandidateType,
214 kStatsValueNameRemoteCertificateId,
215 kStatsValueNameRenderDelayMs,
ivoc8c63a822016-10-21 11:10:03216 kStatsValueNameResidualEchoLikelihood,
ivoc4e477a12017-01-15 16:29:46217 kStatsValueNameResidualEchoLikelihoodRecentMax,
ivoce1198e02017-09-08 15:13:19218 kStatsValueNameAnaBitrateActionCounter,
219 kStatsValueNameAnaChannelActionCounter,
220 kStatsValueNameAnaDtxActionCounter,
221 kStatsValueNameAnaFecActionCounter,
ivoc0d0b9122017-09-08 20:24:21222 kStatsValueNameAnaFrameLengthIncreaseCounter,
223 kStatsValueNameAnaFrameLengthDecreaseCounter,
224 kStatsValueNameAnaUplinkPacketLossFraction,
tommi@webrtc.orgc57310b2014-12-12 17:41:28225 kStatsValueNameRetransmitBitrate,
226 kStatsValueNameRtt,
minyue@webrtc.org652bc372015-02-18 23:50:46227 kStatsValueNameSecondaryDecodedRate,
minyue-webrtc0e320ec2017-08-28 11:51:27228 kStatsValueNameSecondaryDiscardedRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28229 kStatsValueNameSendPacketsDiscarded,
minyue@webrtc.org652bc372015-02-18 23:50:46230 kStatsValueNameSpeechExpandRate,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30231 kStatsValueNameSrtpCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28232 kStatsValueNameTargetDelayMs,
233 kStatsValueNameTargetEncBitrate,
ilnik2edc6842017-07-06 10:06:50234 kStatsValueNameTimingFrameInfo, // Result of |TimingFrameInfo::ToString|
tommi@webrtc.orgc57310b2014-12-12 17:41:28235 kStatsValueNameTrackId,
236 kStatsValueNameTransmitBitrate,
237 kStatsValueNameTransportType,
238 kStatsValueNameTypingNoiseState,
tommi@webrtc.orgc57310b2014-12-12 17:41:28239 kStatsValueNameWritable,
240 };
241
tommi@webrtc.orgd3900292015-03-12 16:35:55242 class IdBase : public rtc::RefCountInterface {
tommi@webrtc.org8e327c42015-01-19 20:41:26243 public:
tommi@webrtc.orgd3900292015-03-12 16:35:55244 ~IdBase() override;
tommi@webrtc.org4fb7e252015-01-21 11:36:18245 StatsType type() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55246
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:18254 virtual std::string ToString() const = 0;
255
256 protected:
tommi@webrtc.orgd3900292015-03-12 16:35:55257 // 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 09:55:59260 explicit IdBase(StatsType type); // Only meant for derived classes.
tommi@webrtc.org4fb7e252015-01-21 11:36:18261 const StatsType type_;
decurtis@webrtc.org322a5642015-02-03 22:09:37262
263 static const char kSeparator = '_';
tommi@webrtc.org8e327c42015-01-19 20:41:26264 };
265
tommi@webrtc.orgd3900292015-03-12 16:35:55266 typedef rtc::scoped_refptr<IdBase> Id;
267
henrike@webrtc.org28e20752013-07-10 00:45:36268 struct Value {
tommi@webrtc.orgd3900292015-03-12 16:35:55269 enum Type {
Peter Boström0c4e06b2015-10-07 10:23:21270 kInt, // int.
271 kInt64, // int64_t.
272 kFloat, // float.
273 kString, // std::string
tommi@webrtc.orgd3900292015-03-12 16:35:55274 kStaticString, // const char*.
Peter Boström0c4e06b2015-10-07 10:23:21275 kBool, // bool.
276 kId, // Id.
tommi@webrtc.orgd3900292015-03-12 16:35:55277 };
278
Peter Boström0c4e06b2015-10-07 10:23:21279 Value(StatsValueName name, int64_t value, Type int_type);
tommi@webrtc.orgd3900292015-03-12 16:35:55280 Value(StatsValueName name, float f);
tommi@webrtc.orgc9d155f2014-12-09 18:18:06281 Value(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55282 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 14:10:54288 // 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:55304 // 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 10:23:21317 bool operator==(int64_t value) const;
tommi@webrtc.orgd3900292015-03-12 16:35:55318 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 10:23:21325 int64_t int64_val() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55326 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:56331
tommi@webrtc.orgc57310b2014-12-12 17:41:28332 // Returns the string representation of |name|.
tommi@webrtc.orgc9d155f2014-12-09 18:18:06333 const char* display_name() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55334
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:19340 // TODO(tommi): Move |name| and |display_name| out of the Value struct.
tommi@webrtc.org242068d2014-07-14 20:19:56341 const StatsValueName name;
tommi@webrtc.orgd3900292015-03-12 16:35:55342
343 private:
nisse6da303d2017-01-18 14:10:54344 rtc::ThreadChecker thread_checker_;
Niels Möller1e062892018-02-07 09:18:32345 mutable int ref_count_ RTC_GUARDED_BY(thread_checker_) = 0;
nisse6da303d2017-01-18 14:10:54346
tommi@webrtc.orgd3900292015-03-12 16:35:55347 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 10:23:21351 int64_t int64_;
tommi@webrtc.orgd3900292015-03-12 16:35:55352 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:56358
henrikg3c089d72015-09-16 12:37:44359 RTC_DISALLOW_COPY_AND_ASSIGN(Value);
henrike@webrtc.org28e20752013-07-10 00:45:36360 };
361
nisse6da303d2017-01-18 14:10:54362 typedef rtc::scoped_refptr<Value> ValuePtr;
tommi@webrtc.org92f40182015-03-04 15:25:19363 typedef std::map<StatsValueName, ValuePtr> Values;
tommi@webrtc.org8e327c42015-01-19 20:41:26364
365 // Ownership of |id| is passed to |this|.
tommi@webrtc.orgd3900292015-03-12 16:35:55366 explicit StatsReport(const Id& id);
ossu7bb87ee2017-01-23 12:56:25367 ~StatsReport();
tommi@webrtc.org8e327c42015-01-19 20:41:26368
tommi@webrtc.org4fb7e252015-01-21 11:36:18369 // Factory functions for various types of stats IDs.
tommi@webrtc.orgd3900292015-03-12 16:35:55370 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 13:03:05373 static Id NewIdWithDirection(StatsType type,
374 const std::string& id,
375 Direction direction);
tommi@webrtc.orgd3900292015-03-12 16:35:55376 static Id NewCandidateId(bool local, const std::string& id);
Yves Gerey665174f2018-06-19 13:03:05377 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:18381
tommi@webrtc.orgd3900292015-03-12 16:35:55382 const Id& id() const { return id_; }
tommi@webrtc.org4fb7e252015-01-21 11:36:18383 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:19386 bool empty() const { return values_.empty(); }
tommi@webrtc.org4fb7e252015-01-21 11:36:18387 const Values& values() const { return values_; }
388
389 const char* TypeToString() const;
tommi@webrtc.org8e327c42015-01-19 20:41:26390
tommi@webrtc.org92f40182015-03-04 15:25:19391 void AddString(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55392 void AddString(StatsValueName name, const char* value);
Peter Boström0c4e06b2015-10-07 10:23:21393 void AddInt64(StatsValueName name, int64_t value);
tommi@webrtc.org92f40182015-03-04 15:25:19394 void AddInt(StatsValueName name, int value);
395 void AddFloat(StatsValueName name, float value);
tommi@webrtc.org242068d2014-07-14 20:19:56396 void AddBoolean(StatsValueName name, bool value);
tommi@webrtc.orgd3900292015-03-12 16:35:55397 void AddId(StatsValueName name, const Id& value);
tommi@webrtc.org8e327c42015-01-19 20:41:26398
tommi@webrtc.org4fb7e252015-01-21 11:36:18399 const Value* FindValue(StatsValueName name) const;
tommi@webrtc.org8e327c42015-01-19 20:41:26400
tommi@webrtc.org4fb7e252015-01-21 11:36:18401 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:55405 const Id id_;
tommi@webrtc.org8e327c42015-01-19 20:41:26406 double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds.
407 Values values_;
henrike@webrtc.org28e20752013-07-10 00:45:36408
henrikg3c089d72015-09-16 12:37:44409 RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport);
tommi@webrtc.org5b06b062014-08-15 08:38:30410};
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:18415// this type. In the StatsCollector, object ownership lies with the
416// StatsCollection class.
tommi@webrtc.org5b06b062014-08-15 08:38:30417typedef 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:18422class StatsCollection {
tommi@webrtc.org5b06b062014-08-15 08:38:30423 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:18424 StatsCollection();
425 ~StatsCollection();
tommi@webrtc.org5b06b062014-08-15 08:38:30426
tommi@webrtc.org4fb7e252015-01-21 11:36:18427 typedef std::list<StatsReport*> Container;
tommi@webrtc.org5b06b062014-08-15 08:38:30428 typedef Container::iterator iterator;
429 typedef Container::const_iterator const_iterator;
430
tommi@webrtc.orgc9d155f2014-12-09 18:18:06431 const_iterator begin() const;
432 const_iterator end() const;
tommi@webrtc.org4fb7e252015-01-21 11:36:18433 size_t size() const;
tommi@webrtc.org5b06b062014-08-15 08:38:30434
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:55437 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:30440
deadbeef8d60a942017-02-27 22:47:33441 // Looks for a report with the given |id|. If one is not found, null
tommi@webrtc.org5b06b062014-08-15 08:38:30442 // will be returned.
tommi@webrtc.org4fb7e252015-01-21 11:36:18443 StatsReport* Find(const StatsReport::Id& id);
tommi@webrtc.org5b06b062014-08-15 08:38:30444
445 private:
446 Container list_;
jbauch25c96d02015-08-07 16:48:18447 rtc::ThreadChecker thread_checker_;
tommi@webrtc.org5b06b062014-08-15 08:38:30448};
henrike@webrtc.org28e20752013-07-10 00:45:36449
450} // namespace webrtc
451
Mirko Bonadei92ea95e2017-09-15 04:47:31452#endif // API_STATSTYPES_H_