blob: 8f25d0543bc6129241b2abab06084566d0d1eef1 [file] [log] [blame]
tommi@webrtc.org5c3ee4b2014-12-09 10:47:011/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2014 The WebRTC project authors. All Rights Reserved.
tommi@webrtc.org5c3ee4b2014-12-09 10:47:013 *
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.
tommi@webrtc.org5c3ee4b2014-12-09 10:47:019 */
10
Henrik Kjellander15583c12016-02-10 09:53:1211#include "webrtc/api/statstypes.h"
tommi@webrtc.org5c3ee4b2014-12-09 10:47:0112
tommi@webrtc.orgd3900292015-03-12 16:35:5513#include <string.h>
14
15#include "webrtc/base/checks.h"
16
17// TODO(tommi): Could we have a static map of value name -> expected type
henrikg91d6ede2015-09-17 07:24:3418// and use this to RTC_DCHECK on correct usage (somewhat strongly typed values)?
tommi@webrtc.orgd3900292015-03-12 16:35:5519// Alternatively, we could define the names+type in a separate document and
20// generate strongly typed inline C++ code that forces the correct type to be
21// used for a given name at compile time.
22
tommi@webrtc.org4b89aa02015-03-16 09:52:3023using rtc::RefCountedObject;
tommi@webrtc.org8e327c42015-01-19 20:41:2624
tommi@webrtc.org5c3ee4b2014-12-09 10:47:0125namespace webrtc {
tommi@webrtc.org4fb7e252015-01-21 11:36:1826namespace {
tommi@webrtc.org5c3ee4b2014-12-09 10:47:0127
tommi@webrtc.org4fb7e252015-01-21 11:36:1828// The id of StatsReport of type kStatsReportTypeBwe.
29const char kStatsReportVideoBweId[] = "bweforvideo";
tommi@webrtc.orgc9d155f2014-12-09 18:18:0630
tommi@webrtc.org4fb7e252015-01-21 11:36:1831// NOTE: These names need to be consistent with an external
32// specification (W3C Stats Identifiers).
33const char* InternalTypeToString(StatsReport::StatsType type) {
34 switch (type) {
35 case StatsReport::kStatsReportTypeSession:
36 return "googLibjingleSession";
37 case StatsReport::kStatsReportTypeBwe:
38 return "VideoBwe";
39 case StatsReport::kStatsReportTypeRemoteSsrc:
40 return "remoteSsrc";
41 case StatsReport::kStatsReportTypeSsrc:
42 return "ssrc";
43 case StatsReport::kStatsReportTypeTrack:
44 return "googTrack";
45 case StatsReport::kStatsReportTypeIceLocalCandidate:
46 return "localcandidate";
47 case StatsReport::kStatsReportTypeIceRemoteCandidate:
48 return "remotecandidate";
49 case StatsReport::kStatsReportTypeTransport:
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:3050 return "transport";
tommi@webrtc.org4fb7e252015-01-21 11:36:1851 case StatsReport::kStatsReportTypeComponent:
52 return "googComponent";
53 case StatsReport::kStatsReportTypeCandidatePair:
54 return "googCandidatePair";
55 case StatsReport::kStatsReportTypeCertificate:
56 return "googCertificate";
57 case StatsReport::kStatsReportTypeDataChannel:
58 return "datachannel";
59 }
henrikg91d6ede2015-09-17 07:24:3460 RTC_DCHECK(false);
tommi@webrtc.org4fb7e252015-01-21 11:36:1861 return nullptr;
tommi@webrtc.orgc9d155f2014-12-09 18:18:0662}
63
tommi@webrtc.orgd3900292015-03-12 16:35:5564class BandwidthEstimationId : public StatsReport::IdBase {
tommi@webrtc.org4fb7e252015-01-21 11:36:1865 public:
tommi@webrtc.orgd3900292015-03-12 16:35:5566 BandwidthEstimationId()
67 : StatsReport::IdBase(StatsReport::kStatsReportTypeBwe) {}
tommi@webrtc.org4fb7e252015-01-21 11:36:1868 std::string ToString() const override { return kStatsReportVideoBweId; }
69};
tommi@webrtc.org8e327c42015-01-19 20:41:2670
tommi@webrtc.orgd3900292015-03-12 16:35:5571class TypedId : public StatsReport::IdBase {
tommi@webrtc.org4fb7e252015-01-21 11:36:1872 public:
tommi@webrtc.org4fb7e252015-01-21 11:36:1873 TypedId(StatsReport::StatsType type, const std::string& id)
tommi@webrtc.orgd3900292015-03-12 16:35:5574 : StatsReport::IdBase(type), id_(id) {}
tommi@webrtc.org8e327c42015-01-19 20:41:2675
tommi@webrtc.orgd3900292015-03-12 16:35:5576 bool Equals(const IdBase& other) const override {
77 return IdBase::Equals(other) &&
tommi@webrtc.org4fb7e252015-01-21 11:36:1878 static_cast<const TypedId&>(other).id_ == id_;
79 }
tommi@webrtc.orgc9d155f2014-12-09 18:18:0680
tommi@webrtc.org4fb7e252015-01-21 11:36:1881 std::string ToString() const override {
82 return std::string(InternalTypeToString(type_)) + kSeparator + id_;
83 }
tommi@webrtc.orgc9d155f2014-12-09 18:18:0684
tommi@webrtc.org4fb7e252015-01-21 11:36:1885 protected:
86 const std::string id_;
87};
tommi@webrtc.orgc9d155f2014-12-09 18:18:0688
tommi@webrtc.orgd3900292015-03-12 16:35:5589class TypedIntId : public StatsReport::IdBase {
decurtis@webrtc.org322a5642015-02-03 22:09:3790 public:
91 TypedIntId(StatsReport::StatsType type, int id)
tommi@webrtc.orgd3900292015-03-12 16:35:5592 : StatsReport::IdBase(type), id_(id) {}
decurtis@webrtc.org322a5642015-02-03 22:09:3793
tommi@webrtc.orgd3900292015-03-12 16:35:5594 bool Equals(const IdBase& other) const override {
95 return IdBase::Equals(other) &&
decurtis@webrtc.org322a5642015-02-03 22:09:3796 static_cast<const TypedIntId&>(other).id_ == id_;
97 }
98
99 std::string ToString() const override {
100 return std::string(InternalTypeToString(type_)) +
101 kSeparator +
102 rtc::ToString<int>(id_);
103 }
104
105 protected:
106 const int id_;
107};
108
tommi@webrtc.org4fb7e252015-01-21 11:36:18109class IdWithDirection : public TypedId {
110 public:
111 IdWithDirection(StatsReport::StatsType type, const std::string& id,
112 StatsReport::Direction direction)
113 : TypedId(type, id), direction_(direction) {}
tommi@webrtc.orgc9d155f2014-12-09 18:18:06114
tommi@webrtc.orgd3900292015-03-12 16:35:55115 bool Equals(const IdBase& other) const override {
tommi@webrtc.org4fb7e252015-01-21 11:36:18116 return TypedId::Equals(other) &&
117 static_cast<const IdWithDirection&>(other).direction_ == direction_;
118 }
tommi@webrtc.orgc9d155f2014-12-09 18:18:06119
tommi@webrtc.org4fb7e252015-01-21 11:36:18120 std::string ToString() const override {
121 std::string ret(TypedId::ToString());
decurtis@webrtc.org322a5642015-02-03 22:09:37122 ret += kSeparator;
tommi@webrtc.org4fb7e252015-01-21 11:36:18123 ret += direction_ == StatsReport::kSend ? "send" : "recv";
124 return ret;
125 }
tommi@webrtc.orgc9d155f2014-12-09 18:18:06126
tommi@webrtc.org4fb7e252015-01-21 11:36:18127 private:
128 const StatsReport::Direction direction_;
129};
130
131class CandidateId : public TypedId {
132 public:
133 CandidateId(bool local, const std::string& id)
134 : TypedId(local ?
135 StatsReport::kStatsReportTypeIceLocalCandidate :
136 StatsReport::kStatsReportTypeIceRemoteCandidate,
137 id) {
138 }
139
140 std::string ToString() const override {
141 return "Cand-" + id_;
142 }
143};
144
tommi@webrtc.orgd3900292015-03-12 16:35:55145class ComponentId : public StatsReport::IdBase {
tommi@webrtc.org4fb7e252015-01-21 11:36:18146 public:
147 ComponentId(const std::string& content_name, int component)
148 : ComponentId(StatsReport::kStatsReportTypeComponent, content_name,
149 component) {}
150
tommi@webrtc.orgd3900292015-03-12 16:35:55151 bool Equals(const IdBase& other) const override {
152 return IdBase::Equals(other) &&
tommi@webrtc.org4fb7e252015-01-21 11:36:18153 static_cast<const ComponentId&>(other).component_ == component_ &&
154 static_cast<const ComponentId&>(other).content_name_ == content_name_;
155 }
156
157 std::string ToString() const override {
158 return ToString("Channel-");
159 }
160
161 protected:
162 ComponentId(StatsReport::StatsType type, const std::string& content_name,
163 int component)
tommi@webrtc.orgd3900292015-03-12 16:35:55164 : IdBase(type),
tommi@webrtc.org4fb7e252015-01-21 11:36:18165 content_name_(content_name),
166 component_(component) {}
167
168 std::string ToString(const char* prefix) const {
169 std::string ret(prefix);
170 ret += content_name_;
171 ret += '-';
172 ret += rtc::ToString<>(component_);
173 return ret;
174 }
175
176 private:
177 const std::string content_name_;
178 const int component_;
179};
180
181class CandidatePairId : public ComponentId {
182 public:
183 CandidatePairId(const std::string& content_name, int component, int index)
184 : ComponentId(StatsReport::kStatsReportTypeCandidatePair, content_name,
185 component),
186 index_(index) {}
187
tommi@webrtc.orgd3900292015-03-12 16:35:55188 bool Equals(const IdBase& other) const override {
tommi@webrtc.org4fb7e252015-01-21 11:36:18189 return ComponentId::Equals(other) &&
190 static_cast<const CandidatePairId&>(other).index_ == index_;
191 }
192
193 std::string ToString() const override {
194 std::string ret(ComponentId::ToString("Conn-"));
195 ret += '-';
196 ret += rtc::ToString<>(index_);
197 return ret;
198 }
199
200 private:
201 const int index_;
202};
203
204} // namespace
205
tommi@webrtc.orgd3900292015-03-12 16:35:55206StatsReport::IdBase::IdBase(StatsType type) : type_(type) {}
207StatsReport::IdBase::~IdBase() {}
tommi@webrtc.org4fb7e252015-01-21 11:36:18208
tommi@webrtc.orgd3900292015-03-12 16:35:55209StatsReport::StatsType StatsReport::IdBase::type() const { return type_; }
tommi@webrtc.org4fb7e252015-01-21 11:36:18210
tommi@webrtc.orgd3900292015-03-12 16:35:55211bool StatsReport::IdBase::Equals(const IdBase& other) const {
tommi@webrtc.org4fb7e252015-01-21 11:36:18212 return other.type_ == type_;
tommi@webrtc.orgc9d155f2014-12-09 18:18:06213}
214
Peter Boström0c4e06b2015-10-07 10:23:21215StatsReport::Value::Value(StatsValueName name, int64_t value, Type int_type)
tommi@webrtc.orgd3900292015-03-12 16:35:55216 : name(name), type_(int_type) {
henrikg91d6ede2015-09-17 07:24:34217 RTC_DCHECK(type_ == kInt || type_ == kInt64);
tommi@webrtc.orgd3900292015-03-12 16:35:55218 type_ == kInt ? value_.int_ = static_cast<int>(value) : value_.int64_ = value;
219}
220
221StatsReport::Value::Value(StatsValueName name, float f)
222 : name(name), type_(kFloat) {
223 value_.float_ = f;
224}
225
tommi@webrtc.orgc9d155f2014-12-09 18:18:06226StatsReport::Value::Value(StatsValueName name, const std::string& value)
tommi@webrtc.orgd3900292015-03-12 16:35:55227 : name(name), type_(kString) {
228 value_.string_ = new std::string(value);
229}
230
231StatsReport::Value::Value(StatsValueName name, const char* value)
232 : name(name), type_(kStaticString) {
233 value_.static_string_ = value;
234}
235
236StatsReport::Value::Value(StatsValueName name, bool b)
237 : name(name), type_(kBool) {
238 value_.bool_ = b;
239}
240
241StatsReport::Value::Value(StatsValueName name, const Id& value)
242 : name(name), type_(kId) {
243 value_.id_ = new Id(value);
244}
245
246StatsReport::Value::~Value() {
247 switch (type_) {
248 case kInt:
249 case kInt64:
250 case kFloat:
251 case kBool:
252 case kStaticString:
253 break;
254 case kString:
255 delete value_.string_;
256 break;
257 case kId:
258 delete value_.id_;
259 break;
260 }
261}
262
263bool StatsReport::Value::Equals(const Value& other) const {
264 if (name != other.name)
265 return false;
266
267 // There's a 1:1 relation between a name and a type, so we don't have to
268 // check that.
henrikg91d6ede2015-09-17 07:24:34269 RTC_DCHECK_EQ(type_, other.type_);
tommi@webrtc.orgd3900292015-03-12 16:35:55270
271 switch (type_) {
272 case kInt:
273 return value_.int_ == other.value_.int_;
274 case kInt64:
275 return value_.int64_ == other.value_.int64_;
276 case kFloat:
277 return value_.float_ == other.value_.float_;
278 case kStaticString: {
kwiberg5377bc72016-10-04 20:46:56279#if RTC_DCHECK_IS_ON
tommi@webrtc.orgd3900292015-03-12 16:35:55280 if (value_.static_string_ != other.value_.static_string_) {
henrikg91d6ede2015-09-17 07:24:34281 RTC_DCHECK(strcmp(value_.static_string_, other.value_.static_string_) !=
282 0)
tommi@webrtc.orgd3900292015-03-12 16:35:55283 << "Duplicate global?";
284 }
285#endif
286 return value_.static_string_ == other.value_.static_string_;
287 }
288 case kString:
289 return *value_.string_ == *other.value_.string_;
290 case kBool:
291 return value_.bool_ == other.value_.bool_;
292 case kId:
293 return (*value_.id_)->Equals(*other.value_.id_);
294 }
295 RTC_NOTREACHED();
296 return false;
297}
298
299bool StatsReport::Value::operator==(const std::string& value) const {
300 return (type_ == kString && value_.string_->compare(value) == 0) ||
301 (type_ == kStaticString && value.compare(value_.static_string_) == 0);
302}
303
304bool StatsReport::Value::operator==(const char* value) const {
305 if (type_ == kString)
306 return value_.string_->compare(value) == 0;
307 if (type_ != kStaticString)
308 return false;
kwiberg5377bc72016-10-04 20:46:56309#if RTC_DCHECK_IS_ON
tommi@webrtc.orgd3900292015-03-12 16:35:55310 if (value_.static_string_ != value)
henrikg91d6ede2015-09-17 07:24:34311 RTC_DCHECK(strcmp(value_.static_string_, value) != 0)
312 << "Duplicate global?";
tommi@webrtc.orgd3900292015-03-12 16:35:55313#endif
314 return value == value_.static_string_;
315}
316
Peter Boström0c4e06b2015-10-07 10:23:21317bool StatsReport::Value::operator==(int64_t value) const {
tommi@webrtc.orgd3900292015-03-12 16:35:55318 return type_ == kInt ? value_.int_ == static_cast<int>(value) :
319 (type_ == kInt64 ? value_.int64_ == value : false);
320}
321
322bool StatsReport::Value::operator==(bool value) const {
323 return type_ == kBool && value_.bool_ == value;
324}
325
326bool StatsReport::Value::operator==(float value) const {
327 return type_ == kFloat && value_.float_ == value;
328}
329
330bool StatsReport::Value::operator==(const Id& value) const {
331 return type_ == kId && (*value_.id_)->Equals(value);
332}
333
334int StatsReport::Value::int_val() const {
henrikg91d6ede2015-09-17 07:24:34335 RTC_DCHECK(type_ == kInt);
tommi@webrtc.orgd3900292015-03-12 16:35:55336 return value_.int_;
337}
338
Peter Boström0c4e06b2015-10-07 10:23:21339int64_t StatsReport::Value::int64_val() const {
henrikg91d6ede2015-09-17 07:24:34340 RTC_DCHECK(type_ == kInt64);
tommi@webrtc.orgd3900292015-03-12 16:35:55341 return value_.int64_;
342}
343
344float StatsReport::Value::float_val() const {
henrikg91d6ede2015-09-17 07:24:34345 RTC_DCHECK(type_ == kFloat);
tommi@webrtc.orgd3900292015-03-12 16:35:55346 return value_.float_;
347}
348
349const char* StatsReport::Value::static_string_val() const {
henrikg91d6ede2015-09-17 07:24:34350 RTC_DCHECK(type_ == kStaticString);
tommi@webrtc.orgd3900292015-03-12 16:35:55351 return value_.static_string_;
352}
353
354const std::string& StatsReport::Value::string_val() const {
henrikg91d6ede2015-09-17 07:24:34355 RTC_DCHECK(type_ == kString);
tommi@webrtc.orgd3900292015-03-12 16:35:55356 return *value_.string_;
357}
358
359bool StatsReport::Value::bool_val() const {
henrikg91d6ede2015-09-17 07:24:34360 RTC_DCHECK(type_ == kBool);
tommi@webrtc.orgd3900292015-03-12 16:35:55361 return value_.bool_;
tommi@webrtc.orgc9d155f2014-12-09 18:18:06362}
363
tommi@webrtc.orgc9d155f2014-12-09 18:18:06364const char* StatsReport::Value::display_name() const {
tommi@webrtc.orgc57310b2014-12-12 17:41:28365 switch (name) {
Minyue2a8a78c2016-04-07 14:48:15366 case kStatsValueNameAecDivergentFilterFraction:
367 return "aecDivergentFilterFraction";
tommi@webrtc.orgc57310b2014-12-12 17:41:28368 case kStatsValueNameAudioOutputLevel:
369 return "audioOutputLevel";
370 case kStatsValueNameAudioInputLevel:
371 return "audioInputLevel";
372 case kStatsValueNameBytesSent:
373 return "bytesSent";
374 case kStatsValueNamePacketsSent:
375 return "packetsSent";
376 case kStatsValueNameBytesReceived:
377 return "bytesReceived";
decurtis@webrtc.org487a4442015-01-15 22:55:07378 case kStatsValueNameLabel:
379 return "label";
tommi@webrtc.orgc57310b2014-12-12 17:41:28380 case kStatsValueNamePacketsReceived:
381 return "packetsReceived";
382 case kStatsValueNamePacketsLost:
383 return "packetsLost";
decurtis@webrtc.org487a4442015-01-15 22:55:07384 case kStatsValueNameProtocol:
385 return "protocol";
tommi@webrtc.orgc57310b2014-12-12 17:41:28386 case kStatsValueNameTransportId:
387 return "transportId";
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30388 case kStatsValueNameSelectedCandidatePairId:
389 return "selectedCandidatePairId";
tommi@webrtc.orgc57310b2014-12-12 17:41:28390 case kStatsValueNameSsrc:
391 return "ssrc";
decurtis@webrtc.org487a4442015-01-15 22:55:07392 case kStatsValueNameState:
393 return "state";
394 case kStatsValueNameDataChannelId:
395 return "datachannelid";
sakale5ba44e2016-10-26 14:09:24396 case kStatsValueNameFramesDecoded:
397 return "framesDecoded";
sakal43536c32016-10-24 08:46:43398 case kStatsValueNameFramesEncoded:
399 return "framesEncoded";
Peter Boströmb7d9a972015-12-18 15:01:11400 case kStatsValueNameCodecImplementationName:
401 return "codecImplementationName";
fippobec70ab2016-01-28 09:27:15402 case kStatsValueNameMediaType:
403 return "mediaType";
tommi@webrtc.orgc57310b2014-12-12 17:41:28404 // 'goog' prefixed constants.
Henrik Lundin8e6fd462015-06-02 07:24:52405 case kStatsValueNameAccelerateRate:
406 return "googAccelerateRate";
tommi@webrtc.orgc57310b2014-12-12 17:41:28407 case kStatsValueNameActiveConnection:
408 return "googActiveConnection";
409 case kStatsValueNameActualEncBitrate:
410 return "googActualEncBitrate";
411 case kStatsValueNameAvailableReceiveBandwidth:
412 return "googAvailableReceiveBandwidth";
413 case kStatsValueNameAvailableSendBandwidth:
414 return "googAvailableSendBandwidth";
415 case kStatsValueNameAvgEncodeMs:
416 return "googAvgEncodeMs";
417 case kStatsValueNameBucketDelay:
418 return "googBucketDelay";
419 case kStatsValueNameBandwidthLimitedResolution:
420 return "googBandwidthLimitedResolution";
zhihuang5ecf16c2016-06-02 00:09:15421 // STUN ping related attributes.
422 // TODO(zhihuang) Rename these stats to follow the standards.
423 case kStatsValueNameSentPingRequestsTotal:
424 return "requestsSent";
425 case kStatsValueNameSentPingRequestsBeforeFirstResponse:
426 return "consentRequestsSent";
427 case kStatsValueNameSentPingResponses:
428 return "responsesSent";
429 case kStatsValueNameRecvPingRequests:
430 return "requestsReceived";
431 case kStatsValueNameRecvPingResponses:
432 return "responsesReceived";
guoweis@webrtc.org950c5182014-12-16 23:01:31433
434 // Candidate related attributes. Values are taken from
435 // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*.
436 case kStatsValueNameCandidateIPAddress:
437 return "ipAddress";
438 case kStatsValueNameCandidateNetworkType:
439 return "networkType";
440 case kStatsValueNameCandidatePortNumber:
441 return "portNumber";
442 case kStatsValueNameCandidatePriority:
443 return "priority";
444 case kStatsValueNameCandidateTransportType:
445 return "transport";
446 case kStatsValueNameCandidateType:
447 return "candidateType";
448
tommi@webrtc.orgc57310b2014-12-12 17:41:28449 case kStatsValueNameChannelId:
450 return "googChannelId";
451 case kStatsValueNameCodecName:
452 return "googCodecName";
453 case kStatsValueNameComponent:
454 return "googComponent";
455 case kStatsValueNameContentName:
456 return "googContentName";
457 case kStatsValueNameCpuLimitedResolution:
458 return "googCpuLimitedResolution";
459 case kStatsValueNameDecodingCTSG:
460 return "googDecodingCTSG";
461 case kStatsValueNameDecodingCTN:
462 return "googDecodingCTN";
henrik.lundin63489782016-09-20 08:47:12463 case kStatsValueNameDecodingMutedOutput:
464 return "googDecodingMuted";
tommi@webrtc.orgc57310b2014-12-12 17:41:28465 case kStatsValueNameDecodingNormal:
466 return "googDecodingNormal";
467 case kStatsValueNameDecodingPLC:
468 return "googDecodingPLC";
469 case kStatsValueNameDecodingCNG:
470 return "googDecodingCNG";
471 case kStatsValueNameDecodingPLCCNG:
472 return "googDecodingPLCCNG";
473 case kStatsValueNameDer:
474 return "googDerBase64";
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30475 case kStatsValueNameDtlsCipher:
476 return "dtlsCipher";
tommi@webrtc.orgc57310b2014-12-12 17:41:28477 case kStatsValueNameEchoCancellationQualityMin:
478 return "googEchoCancellationQualityMin";
479 case kStatsValueNameEchoDelayMedian:
480 return "googEchoCancellationEchoDelayMedian";
481 case kStatsValueNameEchoDelayStdDev:
482 return "googEchoCancellationEchoDelayStdDev";
483 case kStatsValueNameEchoReturnLoss:
484 return "googEchoCancellationReturnLoss";
485 case kStatsValueNameEchoReturnLossEnhancement:
486 return "googEchoCancellationReturnLossEnhancement";
487 case kStatsValueNameEncodeUsagePercent:
488 return "googEncodeUsagePercent";
489 case kStatsValueNameExpandRate:
490 return "googExpandRate";
491 case kStatsValueNameFingerprint:
492 return "googFingerprint";
493 case kStatsValueNameFingerprintAlgorithm:
494 return "googFingerprintAlgorithm";
495 case kStatsValueNameFirsReceived:
496 return "googFirsReceived";
497 case kStatsValueNameFirsSent:
498 return "googFirsSent";
499 case kStatsValueNameFrameHeightInput:
500 return "googFrameHeightInput";
501 case kStatsValueNameFrameHeightReceived:
502 return "googFrameHeightReceived";
503 case kStatsValueNameFrameHeightSent:
504 return "googFrameHeightSent";
505 case kStatsValueNameFrameRateReceived:
506 return "googFrameRateReceived";
507 case kStatsValueNameFrameRateDecoded:
508 return "googFrameRateDecoded";
509 case kStatsValueNameFrameRateOutput:
510 return "googFrameRateOutput";
511 case kStatsValueNameDecodeMs:
512 return "googDecodeMs";
513 case kStatsValueNameMaxDecodeMs:
514 return "googMaxDecodeMs";
515 case kStatsValueNameCurrentDelayMs:
516 return "googCurrentDelayMs";
517 case kStatsValueNameTargetDelayMs:
518 return "googTargetDelayMs";
519 case kStatsValueNameJitterBufferMs:
520 return "googJitterBufferMs";
521 case kStatsValueNameMinPlayoutDelayMs:
522 return "googMinPlayoutDelayMs";
523 case kStatsValueNameRenderDelayMs:
524 return "googRenderDelayMs";
525 case kStatsValueNameCaptureStartNtpTimeMs:
526 return "googCaptureStartNtpTimeMs";
527 case kStatsValueNameFrameRateInput:
528 return "googFrameRateInput";
529 case kStatsValueNameFrameRateSent:
530 return "googFrameRateSent";
531 case kStatsValueNameFrameWidthInput:
532 return "googFrameWidthInput";
533 case kStatsValueNameFrameWidthReceived:
534 return "googFrameWidthReceived";
535 case kStatsValueNameFrameWidthSent:
536 return "googFrameWidthSent";
537 case kStatsValueNameInitiator:
538 return "googInitiator";
539 case kStatsValueNameIssuerId:
540 return "googIssuerId";
541 case kStatsValueNameJitterReceived:
542 return "googJitterReceived";
543 case kStatsValueNameLocalAddress:
544 return "googLocalAddress";
guoweis@webrtc.org950c5182014-12-16 23:01:31545 case kStatsValueNameLocalCandidateId:
546 return "localCandidateId";
tommi@webrtc.orgc57310b2014-12-12 17:41:28547 case kStatsValueNameLocalCandidateType:
548 return "googLocalCandidateType";
549 case kStatsValueNameLocalCertificateId:
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30550 return "localCertificateId";
tommi@webrtc.orgc57310b2014-12-12 17:41:28551 case kStatsValueNameAdaptationChanges:
552 return "googAdaptationChanges";
553 case kStatsValueNameNacksReceived:
554 return "googNacksReceived";
555 case kStatsValueNameNacksSent:
556 return "googNacksSent";
Henrik Lundin8e6fd462015-06-02 07:24:52557 case kStatsValueNamePreemptiveExpandRate:
558 return "googPreemptiveExpandRate";
tommi@webrtc.orgc57310b2014-12-12 17:41:28559 case kStatsValueNamePlisReceived:
560 return "googPlisReceived";
561 case kStatsValueNamePlisSent:
562 return "googPlisSent";
563 case kStatsValueNamePreferredJitterBufferMs:
564 return "googPreferredJitterBufferMs";
Peter Thatcher04ac81f2015-09-21 18:48:28565 case kStatsValueNameReceiving:
tommi@webrtc.orgc57310b2014-12-12 17:41:28566 return "googReadable";
tommi@webrtc.orgc57310b2014-12-12 17:41:28567 case kStatsValueNameRemoteAddress:
568 return "googRemoteAddress";
guoweis@webrtc.org950c5182014-12-16 23:01:31569 case kStatsValueNameRemoteCandidateId:
570 return "remoteCandidateId";
tommi@webrtc.orgc57310b2014-12-12 17:41:28571 case kStatsValueNameRemoteCandidateType:
572 return "googRemoteCandidateType";
573 case kStatsValueNameRemoteCertificateId:
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30574 return "remoteCertificateId";
ivoc8c63a822016-10-21 11:10:03575 case kStatsValueNameResidualEchoLikelihood:
576 return "googResidualEchoLikelihood";
tommi@webrtc.orgc57310b2014-12-12 17:41:28577 case kStatsValueNameRetransmitBitrate:
578 return "googRetransmitBitrate";
579 case kStatsValueNameRtt:
580 return "googRtt";
minyue@webrtc.org652bc372015-02-18 23:50:46581 case kStatsValueNameSecondaryDecodedRate:
582 return "googSecondaryDecodedRate";
tommi@webrtc.orgc57310b2014-12-12 17:41:28583 case kStatsValueNameSendPacketsDiscarded:
584 return "packetsDiscardedOnSend";
minyue@webrtc.org652bc372015-02-18 23:50:46585 case kStatsValueNameSpeechExpandRate:
586 return "googSpeechExpandRate";
pthatcher@webrtc.org7bea1ff2015-03-04 01:38:30587 case kStatsValueNameSrtpCipher:
588 return "srtpCipher";
tommi@webrtc.orgc57310b2014-12-12 17:41:28589 case kStatsValueNameTargetEncBitrate:
590 return "googTargetEncBitrate";
591 case kStatsValueNameTransmitBitrate:
592 return "googTransmitBitrate";
593 case kStatsValueNameTransportType:
594 return "googTransportType";
595 case kStatsValueNameTrackId:
596 return "googTrackId";
597 case kStatsValueNameTypingNoiseState:
598 return "googTypingNoiseState";
599 case kStatsValueNameViewLimitedResolution:
600 return "googViewLimitedResolution";
601 case kStatsValueNameWritable:
602 return "googWritable";
tommi@webrtc.orgc57310b2014-12-12 17:41:28603 }
604
605 return nullptr;
tommi@webrtc.orgc9d155f2014-12-09 18:18:06606}
607
tommi@webrtc.orgd3900292015-03-12 16:35:55608std::string StatsReport::Value::ToString() const {
609 switch (type_) {
610 case kInt:
611 return rtc::ToString(value_.int_);
612 case kInt64:
613 return rtc::ToString(value_.int64_);
614 case kFloat:
615 return rtc::ToString(value_.float_);
616 case kStaticString:
617 return std::string(value_.static_string_);
618 case kString:
619 return *value_.string_;
620 case kBool:
621 return value_.bool_ ? "true" : "false";
622 case kId:
623 return (*value_.id_)->ToString();
624 }
625 RTC_NOTREACHED();
626 return std::string();
tommi@webrtc.orgafa6d162015-03-02 11:27:48627}
628
tommi@webrtc.orgd3900292015-03-12 16:35:55629StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) {
henrikg91d6ede2015-09-17 07:24:34630 RTC_DCHECK(id_.get());
tommi@webrtc.org4fb7e252015-01-21 11:36:18631}
632
633// static
tommi@webrtc.orgd3900292015-03-12 16:35:55634StatsReport::Id StatsReport::NewBandwidthEstimationId() {
635 return Id(new RefCountedObject<BandwidthEstimationId>());
tommi@webrtc.org4fb7e252015-01-21 11:36:18636}
637
638// static
tommi@webrtc.orgd3900292015-03-12 16:35:55639StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) {
640 return Id(new RefCountedObject<TypedId>(type, id));
tommi@webrtc.org4fb7e252015-01-21 11:36:18641}
642
643// static
tommi@webrtc.orgd3900292015-03-12 16:35:55644StatsReport::Id StatsReport::NewTypedIntId(StatsType type, int id) {
645 return Id(new RefCountedObject<TypedIntId>(type, id));
decurtis@webrtc.org322a5642015-02-03 22:09:37646}
647
648// static
tommi@webrtc.orgd3900292015-03-12 16:35:55649StatsReport::Id StatsReport::NewIdWithDirection(
tommi@webrtc.org4fb7e252015-01-21 11:36:18650 StatsType type, const std::string& id, StatsReport::Direction direction) {
tommi@webrtc.orgd3900292015-03-12 16:35:55651 return Id(new RefCountedObject<IdWithDirection>(type, id, direction));
tommi@webrtc.org4fb7e252015-01-21 11:36:18652}
653
654// static
tommi@webrtc.orgd3900292015-03-12 16:35:55655StatsReport::Id StatsReport::NewCandidateId(bool local, const std::string& id) {
656 return Id(new RefCountedObject<CandidateId>(local, id));
tommi@webrtc.org4fb7e252015-01-21 11:36:18657}
658
659// static
tommi@webrtc.orgd3900292015-03-12 16:35:55660StatsReport::Id StatsReport::NewComponentId(
tommi@webrtc.org4fb7e252015-01-21 11:36:18661 const std::string& content_name, int component) {
tommi@webrtc.orgd3900292015-03-12 16:35:55662 return Id(new RefCountedObject<ComponentId>(content_name, component));
tommi@webrtc.org4fb7e252015-01-21 11:36:18663}
664
665// static
tommi@webrtc.orgd3900292015-03-12 16:35:55666StatsReport::Id StatsReport::NewCandidatePairId(
tommi@webrtc.org4fb7e252015-01-21 11:36:18667 const std::string& content_name, int component, int index) {
tommi@webrtc.orgd3900292015-03-12 16:35:55668 return Id(new RefCountedObject<CandidatePairId>(
669 content_name, component, index));
tommi@webrtc.org4fb7e252015-01-21 11:36:18670}
671
672const char* StatsReport::TypeToString() const {
673 return InternalTypeToString(id_->type());
674}
675
tommi@webrtc.org92f40182015-03-04 15:25:19676void StatsReport::AddString(StatsReport::StatsValueName name,
677 const std::string& value) {
tommi@webrtc.orgd3900292015-03-12 16:35:55678 const Value* found = FindValue(name);
679 if (!found || !(*found == value))
680 values_[name] = ValuePtr(new Value(name, value));
681}
682
683void StatsReport::AddString(StatsReport::StatsValueName name,
684 const char* value) {
685 const Value* found = FindValue(name);
686 if (!found || !(*found == value))
687 values_[name] = ValuePtr(new Value(name, value));
tommi@webrtc.orgc9d155f2014-12-09 18:18:06688}
689
Peter Boström0c4e06b2015-10-07 10:23:21690void StatsReport::AddInt64(StatsReport::StatsValueName name, int64_t value) {
tommi@webrtc.orgd3900292015-03-12 16:35:55691 const Value* found = FindValue(name);
692 if (!found || !(*found == value))
693 values_[name] = ValuePtr(new Value(name, value, Value::kInt64));
tommi@webrtc.orgc9d155f2014-12-09 18:18:06694}
695
tommi@webrtc.org92f40182015-03-04 15:25:19696void StatsReport::AddInt(StatsReport::StatsValueName name, int value) {
tommi@webrtc.orgd3900292015-03-12 16:35:55697 const Value* found = FindValue(name);
Peter Boström0c4e06b2015-10-07 10:23:21698 if (!found || !(*found == static_cast<int64_t>(value)))
tommi@webrtc.orgd3900292015-03-12 16:35:55699 values_[name] = ValuePtr(new Value(name, value, Value::kInt));
tommi@webrtc.orgc9d155f2014-12-09 18:18:06700}
701
tommi@webrtc.org92f40182015-03-04 15:25:19702void StatsReport::AddFloat(StatsReport::StatsValueName name, float value) {
tommi@webrtc.orgd3900292015-03-12 16:35:55703 const Value* found = FindValue(name);
704 if (!found || !(*found == value))
705 values_[name] = ValuePtr(new Value(name, value));
tommi@webrtc.org92f40182015-03-04 15:25:19706}
tommi@webrtc.orgc9d155f2014-12-09 18:18:06707
708void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) {
tommi@webrtc.orgd3900292015-03-12 16:35:55709 const Value* found = FindValue(name);
710 if (!found || !(*found == value))
711 values_[name] = ValuePtr(new Value(name, value));
tommi@webrtc.org8e327c42015-01-19 20:41:26712}
713
tommi@webrtc.orgd3900292015-03-12 16:35:55714void StatsReport::AddId(StatsReport::StatsValueName name,
715 const Id& value) {
716 const Value* found = FindValue(name);
717 if (!found || !(*found == value))
718 values_[name] = ValuePtr(new Value(name, value));
tommi@webrtc.orgc9d155f2014-12-09 18:18:06719}
720
tommi@webrtc.org4fb7e252015-01-21 11:36:18721const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const {
tommi@webrtc.org92f40182015-03-04 15:25:19722 Values::const_iterator it = values_.find(name);
723 return it == values_.end() ? nullptr : it->second.get();
tommi@webrtc.orgc9d155f2014-12-09 18:18:06724}
725
tommi@webrtc.org4fb7e252015-01-21 11:36:18726StatsCollection::StatsCollection() {
tommi@webrtc.orgc9d155f2014-12-09 18:18:06727}
728
tommi@webrtc.org4fb7e252015-01-21 11:36:18729StatsCollection::~StatsCollection() {
henrikg91d6ede2015-09-17 07:24:34730 RTC_DCHECK(thread_checker_.CalledOnValidThread());
tommi@webrtc.org4fb7e252015-01-21 11:36:18731 for (auto* r : list_)
732 delete r;
733}
734
735StatsCollection::const_iterator StatsCollection::begin() const {
henrikg91d6ede2015-09-17 07:24:34736 RTC_DCHECK(thread_checker_.CalledOnValidThread());
tommi@webrtc.orgc9d155f2014-12-09 18:18:06737 return list_.begin();
738}
739
tommi@webrtc.org4fb7e252015-01-21 11:36:18740StatsCollection::const_iterator StatsCollection::end() const {
henrikg91d6ede2015-09-17 07:24:34741 RTC_DCHECK(thread_checker_.CalledOnValidThread());
tommi@webrtc.orgc9d155f2014-12-09 18:18:06742 return list_.end();
743}
744
tommi@webrtc.org4fb7e252015-01-21 11:36:18745size_t StatsCollection::size() const {
henrikg91d6ede2015-09-17 07:24:34746 RTC_DCHECK(thread_checker_.CalledOnValidThread());
tommi@webrtc.org4fb7e252015-01-21 11:36:18747 return list_.size();
tommi@webrtc.orgc9d155f2014-12-09 18:18:06748}
749
tommi@webrtc.orgd3900292015-03-12 16:35:55750StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) {
henrikg91d6ede2015-09-17 07:24:34751 RTC_DCHECK(thread_checker_.CalledOnValidThread());
752 RTC_DCHECK(Find(id) == nullptr);
tommi@webrtc.orgd3900292015-03-12 16:35:55753 StatsReport* report = new StatsReport(id);
tommi@webrtc.org4fb7e252015-01-21 11:36:18754 list_.push_back(report);
755 return report;
tommi@webrtc.orgc9d155f2014-12-09 18:18:06756}
757
tommi@webrtc.orgd3900292015-03-12 16:35:55758StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) {
henrikg91d6ede2015-09-17 07:24:34759 RTC_DCHECK(thread_checker_.CalledOnValidThread());
tommi@webrtc.orgd3900292015-03-12 16:35:55760 StatsReport* ret = Find(id);
761 return ret ? ret : InsertNew(id);
tommi@webrtc.org4fb7e252015-01-21 11:36:18762}
763
tommi@webrtc.orgd3900292015-03-12 16:35:55764StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) {
henrikg91d6ede2015-09-17 07:24:34765 RTC_DCHECK(thread_checker_.CalledOnValidThread());
766 RTC_DCHECK(id.get());
tommi@webrtc.org4fb7e252015-01-21 11:36:18767 Container::iterator it = std::find_if(list_.begin(), list_.end(),
tommi@webrtc.orgd3900292015-03-12 16:35:55768 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); });
tommi@webrtc.org4fb7e252015-01-21 11:36:18769 if (it != end()) {
tommi@webrtc.orgd3900292015-03-12 16:35:55770 StatsReport* report = new StatsReport((*it)->id());
tommi@webrtc.org4fb7e252015-01-21 11:36:18771 delete *it;
tommi@webrtc.org4fb7e252015-01-21 11:36:18772 *it = report;
773 return report;
774 }
tommi@webrtc.orgd3900292015-03-12 16:35:55775 return InsertNew(id);
tommi@webrtc.orgc9d155f2014-12-09 18:18:06776}
777
778// Looks for a report with the given |id|. If one is not found, NULL
779// will be returned.
tommi@webrtc.org4fb7e252015-01-21 11:36:18780StatsReport* StatsCollection::Find(const StatsReport::Id& id) {
henrikg91d6ede2015-09-17 07:24:34781 RTC_DCHECK(thread_checker_.CalledOnValidThread());
tommi@webrtc.org4fb7e252015-01-21 11:36:18782 Container::iterator it = std::find_if(list_.begin(), list_.end(),
tommi@webrtc.orgd3900292015-03-12 16:35:55783 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); });
tommi@webrtc.org4fb7e252015-01-21 11:36:18784 return it == list_.end() ? nullptr : *it;
785}
786
tommi@webrtc.org5c3ee4b2014-12-09 10:47:01787} // namespace webrtc