blob: ff447a5145c38c25f4628d2db74b737c99718a12 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28// This file contains structures used for retrieving statistics from an ongoing
29// libjingle session.
30
31#ifndef TALK_APP_WEBRTC_STATSTYPES_H_
32#define TALK_APP_WEBRTC_STATSTYPES_H_
33
tommi@webrtc.org5c3ee4b2014-12-09 10:47:01 +000034#include <algorithm>
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000035#include <list>
tommi@webrtc.org92f40182015-03-04 15:25:19 +000036#include <map>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include <string>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000039#include "webrtc/base/basictypes.h"
andrew@webrtc.org6ae5a6d2014-09-16 01:03:29 +000040#include "webrtc/base/common.h"
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000041#include "webrtc/base/refcount.h"
tommi@webrtc.org8e327c42015-01-19 20:41:26 +000042#include "webrtc/base/scoped_ptr.h"
tommi@webrtc.orgd3900292015-03-12 16:35:55 +000043#include "webrtc/base/linked_ptr.h"
44#include "webrtc/base/scoped_ref_ptr.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000045#include "webrtc/base/stringencode.h"
jbauch25c96d02015-08-07 09:48:18 -070046#include "webrtc/base/thread_checker.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48namespace webrtc {
49
50class StatsReport {
51 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000052 // Indicates whether a track is for sending or receiving.
53 // Used in reports for audio/video tracks.
54 enum Direction {
55 kSend = 0,
56 kReceive,
57 };
tommi@webrtc.orgaa2c3422014-12-09 20:23:06 +000058
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000059 enum StatsType {
60 // StatsReport types.
61 // A StatsReport of |type| = "googSession" contains overall information
62 // about the thing libjingle calls a session (which may contain one
63 // or more RTP sessions.
64 kStatsReportTypeSession,
tommi@webrtc.org5b06b062014-08-15 08:38:30 +000065
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000066 // A StatsReport of |type| = "googTransport" contains information
67 // about a libjingle "transport".
68 kStatsReportTypeTransport,
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +000069
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000070 // A StatsReport of |type| = "googComponent" contains information
71 // about a libjingle "channel" (typically, RTP or RTCP for a transport).
72 // This is intended to be the same thing as an ICE "Component".
73 kStatsReportTypeComponent,
tommi@webrtc.org5b06b062014-08-15 08:38:30 +000074
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000075 // A StatsReport of |type| = "googCandidatePair" contains information
76 // about a libjingle "connection" - a single source/destination port pair.
77 // This is intended to be the same thing as an ICE "candidate pair".
78 kStatsReportTypeCandidatePair,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000080 // A StatsReport of |type| = "VideoBWE" is statistics for video Bandwidth
81 // Estimation, which is global per-session. The |id| field is "bweforvideo"
82 // (will probably change in the future).
83 kStatsReportTypeBwe,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +000085 // A StatsReport of |type| = "ssrc" is statistics for a specific rtp stream.
86 // The |id| field is the SSRC in decimal form of the rtp stream.
87 kStatsReportTypeSsrc,
88
89 // A StatsReport of |type| = "remoteSsrc" is statistics for a specific
90 // rtp stream, generated by the remote end of the connection.
91 kStatsReportTypeRemoteSsrc,
92
93 // A StatsReport of |type| = "googTrack" is statistics for a specific media
94 // track. The |id| field is the track id.
95 kStatsReportTypeTrack,
96
97 // A StatsReport of |type| = "localcandidate" or "remotecandidate" is
98 // attributes on a specific ICE Candidate. It links to its connection pair
99 // by candidate id. The string value is taken from
100 // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*.
101 kStatsReportTypeIceLocalCandidate,
102 kStatsReportTypeIceRemoteCandidate,
103
104 // A StatsReport of |type| = "googCertificate" contains an SSL certificate
105 // transmitted by one of the endpoints of this connection. The |id| is
106 // controlled by the fingerprint, and is used to identify the certificate in
107 // the Channel stats (as "googLocalCertificateId" or
108 // "googRemoteCertificateId") and in any child certificates (as
109 // "googIssuerId").
110 kStatsReportTypeCertificate,
111
112 // A StatsReport of |type| = "datachannel" with statistics for a
113 // particular DataChannel.
114 kStatsReportTypeDataChannel,
115 };
116
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000117 enum StatsValueName {
118 kStatsValueNameActiveConnection,
119 kStatsValueNameAudioInputLevel,
120 kStatsValueNameAudioOutputLevel,
121 kStatsValueNameBytesReceived,
122 kStatsValueNameBytesSent,
Peter Boströmb7d9a972015-12-18 16:01:11 +0100123 kStatsValueNameCodecImplementationName,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000124 kStatsValueNameDataChannelId,
fippobec70ab2016-01-28 01:27:15 -0800125 kStatsValueNameMediaType,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000126 kStatsValueNamePacketsLost,
127 kStatsValueNamePacketsReceived,
128 kStatsValueNamePacketsSent,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000129 kStatsValueNameProtocol,
Peter Thatcher04ac81f2015-09-21 11:48:28 -0700130 kStatsValueNameReceiving,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000131 kStatsValueNameSelectedCandidatePairId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000132 kStatsValueNameSsrc,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000133 kStatsValueNameState,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000134 kStatsValueNameTransportId,
135
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,
156 kStatsValueNameCpuLimitedResolution,
157 kStatsValueNameCurrentDelayMs,
158 kStatsValueNameDecodeMs,
159 kStatsValueNameDecodingCNG,
160 kStatsValueNameDecodingCTN,
161 kStatsValueNameDecodingCTSG,
162 kStatsValueNameDecodingNormal,
163 kStatsValueNameDecodingPLC,
164 kStatsValueNameDecodingPLCCNG,
165 kStatsValueNameDer,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000166 kStatsValueNameDtlsCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000167 kStatsValueNameEchoCancellationQualityMin,
168 kStatsValueNameEchoDelayMedian,
169 kStatsValueNameEchoDelayStdDev,
170 kStatsValueNameEchoReturnLoss,
171 kStatsValueNameEchoReturnLossEnhancement,
172 kStatsValueNameEncodeUsagePercent,
173 kStatsValueNameExpandRate,
174 kStatsValueNameFingerprint,
175 kStatsValueNameFingerprintAlgorithm,
176 kStatsValueNameFirsReceived,
177 kStatsValueNameFirsSent,
178 kStatsValueNameFrameHeightInput,
179 kStatsValueNameFrameHeightReceived,
180 kStatsValueNameFrameHeightSent,
181 kStatsValueNameFrameRateDecoded,
182 kStatsValueNameFrameRateInput,
183 kStatsValueNameFrameRateOutput,
184 kStatsValueNameFrameRateReceived,
185 kStatsValueNameFrameRateSent,
186 kStatsValueNameFrameWidthInput,
187 kStatsValueNameFrameWidthReceived,
188 kStatsValueNameFrameWidthSent,
189 kStatsValueNameInitiator,
190 kStatsValueNameIssuerId,
191 kStatsValueNameJitterBufferMs,
192 kStatsValueNameJitterReceived,
decurtis@webrtc.org487a4442015-01-15 22:55:07 +0000193 kStatsValueNameLabel,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000194 kStatsValueNameLocalAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000195 kStatsValueNameLocalCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000196 kStatsValueNameLocalCandidateType,
197 kStatsValueNameLocalCertificateId,
198 kStatsValueNameMaxDecodeMs,
199 kStatsValueNameMinPlayoutDelayMs,
200 kStatsValueNameNacksReceived,
201 kStatsValueNameNacksSent,
202 kStatsValueNamePlisReceived,
203 kStatsValueNamePlisSent,
Henrik Lundin8e6fd462015-06-02 09:24:52 +0200204 kStatsValueNamePreemptiveExpandRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000205 kStatsValueNamePreferredJitterBufferMs,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000206 kStatsValueNameRemoteAddress,
guoweis@webrtc.org950c5182014-12-16 23:01:31 +0000207 kStatsValueNameRemoteCandidateId,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000208 kStatsValueNameRemoteCandidateType,
209 kStatsValueNameRemoteCertificateId,
210 kStatsValueNameRenderDelayMs,
211 kStatsValueNameRetransmitBitrate,
212 kStatsValueNameRtt,
minyue@webrtc.org652bc372015-02-18 23:50:46 +0000213 kStatsValueNameSecondaryDecodedRate,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000214 kStatsValueNameSendPacketsDiscarded,
minyue@webrtc.org652bc372015-02-18 23:50:46 +0000215 kStatsValueNameSpeechExpandRate,
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30 +0000216 kStatsValueNameSrtpCipher,
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000217 kStatsValueNameTargetDelayMs,
218 kStatsValueNameTargetEncBitrate,
219 kStatsValueNameTrackId,
220 kStatsValueNameTransmitBitrate,
221 kStatsValueNameTransportType,
222 kStatsValueNameTypingNoiseState,
223 kStatsValueNameViewLimitedResolution,
224 kStatsValueNameWritable,
225 };
226
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000227 class IdBase : public rtc::RefCountInterface {
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000228 public:
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000229 ~IdBase() override;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000230 StatsType type() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000231
232 // Users of IdBase will be using the Id typedef, which is compatible with
233 // this Equals() function. It simply calls the protected (and overridden)
234 // Equals() method.
235 bool Equals(const rtc::scoped_refptr<IdBase>& other) const {
236 return Equals(*other.get());
237 }
238
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000239 virtual std::string ToString() const = 0;
240
241 protected:
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000242 // Protected since users of the IdBase type will be using the Id typedef.
243 virtual bool Equals(const IdBase& other) const;
244
245 IdBase(StatsType type); // Only meant for derived classes.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000246 const StatsType type_;
decurtis@webrtc.org322a5642015-02-03 22:09:37 +0000247
248 static const char kSeparator = '_';
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000249 };
250
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000251 typedef rtc::scoped_refptr<IdBase> Id;
252
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 struct Value {
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000254 enum Type {
Peter Boström0c4e06b2015-10-07 12:23:21 +0200255 kInt, // int.
256 kInt64, // int64_t.
257 kFloat, // float.
258 kString, // std::string
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000259 kStaticString, // const char*.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200260 kBool, // bool.
261 kId, // Id.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000262 };
263
Peter Boström0c4e06b2015-10-07 12:23:21 +0200264 Value(StatsValueName name, int64_t value, Type int_type);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000265 Value(StatsValueName name, float f);
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000266 Value(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000267 Value(StatsValueName name, const char* value);
268 Value(StatsValueName name, bool b);
269 Value(StatsValueName name, const Id& value);
270
271 ~Value();
272
273 // TODO(tommi): This compares name as well as value...
274 // I think we should only need to compare the value part and
275 // move the name part into a hash map.
276 bool Equals(const Value& other) const;
277
278 // Comparison operators. Return true iff the current instance is of the
279 // correct type and holds the same value. No conversion is performed so
280 // a string value of "123" is not equal to an int value of 123 and an int
281 // value of 123 is not equal to a float value of 123.0f.
282 // One exception to this is that types kInt and kInt64 can be compared and
283 // kString and kStaticString too.
284 bool operator==(const std::string& value) const;
285 bool operator==(const char* value) const;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200286 bool operator==(int64_t value) const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000287 bool operator==(bool value) const;
288 bool operator==(float value) const;
289 bool operator==(const Id& value) const;
290
291 // Getters that allow getting the native value directly.
292 // The caller must know the type beforehand or else hit a check.
293 int int_val() const;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200294 int64_t int64_val() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000295 float float_val() const;
296 const char* static_string_val() const;
297 const std::string& string_val() const;
298 bool bool_val() const;
299 const Id& id_val() const;
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000300
tommi@webrtc.orgc57310b2014-12-12 17:41:28 +0000301 // Returns the string representation of |name|.
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000302 const char* display_name() const;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000303
304 // Converts the native value to a string representation of the value.
305 std::string ToString() const;
306
307 Type type() const { return type_; }
308
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000309 // TODO(tommi): Move |name| and |display_name| out of the Value struct.
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000310 const StatsValueName name;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000311
312 private:
313 const Type type_;
314 // TODO(tommi): Use C++ 11 union and make value_ const.
315 union InternalType {
316 int int_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200317 int64_t int64_;
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000318 float float_;
319 bool bool_;
320 std::string* string_;
321 const char* static_string_;
322 Id* id_;
323 } value_;
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000324
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000325 private:
henrikg3c089d72015-09-16 05:37:44 -0700326 RTC_DISALLOW_COPY_AND_ASSIGN(Value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 };
328
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000329 // TODO(tommi): Consider using a similar approach to how we store Ids using
330 // scoped_refptr for values.
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000331 typedef rtc::linked_ptr<Value> ValuePtr;
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000332 typedef std::map<StatsValueName, ValuePtr> Values;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000333
334 // Ownership of |id| is passed to |this|.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000335 explicit StatsReport(const Id& id);
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000336
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000337 // Factory functions for various types of stats IDs.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000338 static Id NewBandwidthEstimationId();
339 static Id NewTypedId(StatsType type, const std::string& id);
340 static Id NewTypedIntId(StatsType type, int id);
341 static Id NewIdWithDirection(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000342 StatsType type, const std::string& id, Direction direction);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000343 static Id NewCandidateId(bool local, const std::string& id);
344 static Id NewComponentId(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000345 const std::string& content_name, int component);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000346 static Id NewCandidatePairId(
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000347 const std::string& content_name, int component, int index);
348
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000349 const Id& id() const { return id_; }
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000350 StatsType type() const { return id_->type(); }
351 double timestamp() const { return timestamp_; }
352 void set_timestamp(double t) { timestamp_ = t; }
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000353 bool empty() const { return values_.empty(); }
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000354 const Values& values() const { return values_; }
355
356 const char* TypeToString() const;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000357
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000358 void AddString(StatsValueName name, const std::string& value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000359 void AddString(StatsValueName name, const char* value);
Peter Boström0c4e06b2015-10-07 12:23:21 +0200360 void AddInt64(StatsValueName name, int64_t value);
tommi@webrtc.org92f40182015-03-04 15:25:19 +0000361 void AddInt(StatsValueName name, int value);
362 void AddFloat(StatsValueName name, float value);
tommi@webrtc.org242068d2014-07-14 20:19:56 +0000363 void AddBoolean(StatsValueName name, bool value);
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000364 void AddId(StatsValueName name, const Id& value);
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000365
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000366 const Value* FindValue(StatsValueName name) const;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000367
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000368 private:
369 // The unique identifier for this object.
370 // This is used as a key for this report in ordered containers,
371 // so it must never be changed.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000372 const Id id_;
tommi@webrtc.org8e327c42015-01-19 20:41:26 +0000373 double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds.
374 Values values_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375
henrikg3c089d72015-09-16 05:37:44 -0700376 RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000377};
378
379// Typedef for an array of const StatsReport pointers.
380// Ownership of the pointers held by this implementation is assumed to lie
381// elsewhere and lifetime guarantees are made by the implementation that uses
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000382// this type. In the StatsCollector, object ownership lies with the
383// StatsCollection class.
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000384typedef std::vector<const StatsReport*> StatsReports;
385
386// A map from the report id to the report.
387// This class wraps an STL container and provides a limited set of
388// functionality in order to keep things simple.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000389class StatsCollection {
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000390 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000391 StatsCollection();
392 ~StatsCollection();
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000393
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000394 typedef std::list<StatsReport*> Container;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000395 typedef Container::iterator iterator;
396 typedef Container::const_iterator const_iterator;
397
tommi@webrtc.orgc9d155f2014-12-09 18:18:06 +0000398 const_iterator begin() const;
399 const_iterator end() const;
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000400 size_t size() const;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000401
402 // Creates a new report object with |id| that does not already
403 // exist in the list of reports.
tommi@webrtc.orgd3900292015-03-12 16:35:55 +0000404 StatsReport* InsertNew(const StatsReport::Id& id);
405 StatsReport* FindOrAddNew(const StatsReport::Id& id);
406 StatsReport* ReplaceOrAddNew(const StatsReport::Id& id);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000407
408 // Looks for a report with the given |id|. If one is not found, NULL
409 // will be returned.
tommi@webrtc.org4fb7e252015-01-21 11:36:18 +0000410 StatsReport* Find(const StatsReport::Id& id);
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000411
412 private:
413 Container list_;
jbauch25c96d02015-08-07 09:48:18 -0700414 rtc::ThreadChecker thread_checker_;
tommi@webrtc.org5b06b062014-08-15 08:38:30 +0000415};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416
417} // namespace webrtc
418
419#endif // TALK_APP_WEBRTC_STATSTYPES_H_