tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "api/stats_types.h" |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 12 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 13 | #include <string.h> |
| 14 | |
Steve Anton | a59dcc3 | 2019-03-25 13:53:07 -0700 | [diff] [blame] | 15 | #include "absl/algorithm/container.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 17 | #include "rtc_base/ref_counted_object.h" |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 18 | |
| 19 | // TODO(tommi): Could we have a static map of value name -> expected type |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 20 | // and use this to RTC_DCHECK on correct usage (somewhat strongly typed values)? |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 21 | // Alternatively, we could define the names+type in a separate document and |
| 22 | // generate strongly typed inline C++ code that forces the correct type to be |
| 23 | // used for a given name at compile time. |
| 24 | |
tommi@webrtc.org | 4b89aa0 | 2015-03-16 09:52:30 +0000 | [diff] [blame] | 25 | using rtc::RefCountedObject; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 26 | |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 27 | namespace webrtc { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 28 | namespace { |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 29 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 30 | // The id of StatsReport of type kStatsReportTypeBwe. |
| 31 | const char kStatsReportVideoBweId[] = "bweforvideo"; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 32 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 33 | // NOTE: These names need to be consistent with an external |
| 34 | // specification (W3C Stats Identifiers). |
| 35 | const char* InternalTypeToString(StatsReport::StatsType type) { |
| 36 | switch (type) { |
| 37 | case StatsReport::kStatsReportTypeSession: |
| 38 | return "googLibjingleSession"; |
| 39 | case StatsReport::kStatsReportTypeBwe: |
| 40 | return "VideoBwe"; |
| 41 | case StatsReport::kStatsReportTypeRemoteSsrc: |
| 42 | return "remoteSsrc"; |
| 43 | case StatsReport::kStatsReportTypeSsrc: |
| 44 | return "ssrc"; |
| 45 | case StatsReport::kStatsReportTypeTrack: |
| 46 | return "googTrack"; |
| 47 | case StatsReport::kStatsReportTypeIceLocalCandidate: |
| 48 | return "localcandidate"; |
| 49 | case StatsReport::kStatsReportTypeIceRemoteCandidate: |
| 50 | return "remotecandidate"; |
| 51 | case StatsReport::kStatsReportTypeTransport: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 52 | return "transport"; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 53 | case StatsReport::kStatsReportTypeComponent: |
| 54 | return "googComponent"; |
| 55 | case StatsReport::kStatsReportTypeCandidatePair: |
| 56 | return "googCandidatePair"; |
| 57 | case StatsReport::kStatsReportTypeCertificate: |
| 58 | return "googCertificate"; |
| 59 | case StatsReport::kStatsReportTypeDataChannel: |
| 60 | return "datachannel"; |
| 61 | } |
nisse | eb4ca4e | 2017-01-12 02:24:27 -0800 | [diff] [blame] | 62 | RTC_NOTREACHED(); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 63 | return nullptr; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 64 | } |
| 65 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 66 | class BandwidthEstimationId : public StatsReport::IdBase { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 67 | public: |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 68 | BandwidthEstimationId() |
| 69 | : StatsReport::IdBase(StatsReport::kStatsReportTypeBwe) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 70 | std::string ToString() const override { return kStatsReportVideoBweId; } |
| 71 | }; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 72 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 73 | class TypedId : public StatsReport::IdBase { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 74 | public: |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 75 | TypedId(StatsReport::StatsType type, const std::string& id) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 76 | : StatsReport::IdBase(type), id_(id) {} |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 77 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 78 | bool Equals(const IdBase& other) const override { |
| 79 | return IdBase::Equals(other) && |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 80 | static_cast<const TypedId&>(other).id_ == id_; |
| 81 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 82 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 83 | std::string ToString() const override { |
| 84 | return std::string(InternalTypeToString(type_)) + kSeparator + id_; |
| 85 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 86 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 87 | protected: |
| 88 | const std::string id_; |
| 89 | }; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 90 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 91 | class TypedIntId : public StatsReport::IdBase { |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 92 | public: |
| 93 | TypedIntId(StatsReport::StatsType type, int id) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 94 | : StatsReport::IdBase(type), id_(id) {} |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 95 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 96 | bool Equals(const IdBase& other) const override { |
| 97 | return IdBase::Equals(other) && |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 98 | static_cast<const TypedIntId&>(other).id_ == id_; |
| 99 | } |
| 100 | |
| 101 | std::string ToString() const override { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 102 | return std::string(InternalTypeToString(type_)) + kSeparator + |
Jonas Olsson | 6b1985d | 2018-07-05 11:59:48 +0200 | [diff] [blame] | 103 | rtc::ToString(id_); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | protected: |
| 107 | const int id_; |
| 108 | }; |
| 109 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 110 | class IdWithDirection : public TypedId { |
| 111 | public: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 112 | IdWithDirection(StatsReport::StatsType type, |
| 113 | const std::string& id, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 114 | StatsReport::Direction direction) |
| 115 | : TypedId(type, id), direction_(direction) {} |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 116 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 117 | bool Equals(const IdBase& other) const override { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 118 | return TypedId::Equals(other) && |
| 119 | static_cast<const IdWithDirection&>(other).direction_ == direction_; |
| 120 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 121 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 122 | std::string ToString() const override { |
| 123 | std::string ret(TypedId::ToString()); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 124 | ret += kSeparator; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 125 | ret += direction_ == StatsReport::kSend ? "send" : "recv"; |
| 126 | return ret; |
| 127 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 128 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 129 | private: |
| 130 | const StatsReport::Direction direction_; |
| 131 | }; |
| 132 | |
| 133 | class CandidateId : public TypedId { |
| 134 | public: |
| 135 | CandidateId(bool local, const std::string& id) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 136 | : TypedId(local ? StatsReport::kStatsReportTypeIceLocalCandidate |
| 137 | : StatsReport::kStatsReportTypeIceRemoteCandidate, |
| 138 | id) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 139 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 140 | std::string ToString() const override { return "Cand-" + id_; } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 143 | class ComponentId : public StatsReport::IdBase { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 144 | public: |
| 145 | ComponentId(const std::string& content_name, int component) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 146 | : ComponentId(StatsReport::kStatsReportTypeComponent, |
| 147 | content_name, |
| 148 | component) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 149 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 150 | bool Equals(const IdBase& other) const override { |
| 151 | return IdBase::Equals(other) && |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 152 | static_cast<const ComponentId&>(other).component_ == component_ && |
| 153 | static_cast<const ComponentId&>(other).content_name_ == |
| 154 | content_name_; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 157 | std::string ToString() const override { return ToString("Channel-"); } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 158 | |
| 159 | protected: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 160 | ComponentId(StatsReport::StatsType type, |
| 161 | const std::string& content_name, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 162 | int component) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 163 | : IdBase(type), content_name_(content_name), component_(component) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 164 | |
| 165 | std::string ToString(const char* prefix) const { |
| 166 | std::string ret(prefix); |
| 167 | ret += content_name_; |
| 168 | ret += '-'; |
Jonas Olsson | 6b1985d | 2018-07-05 11:59:48 +0200 | [diff] [blame] | 169 | ret += rtc::ToString(component_); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | private: |
| 174 | const std::string content_name_; |
| 175 | const int component_; |
| 176 | }; |
| 177 | |
| 178 | class CandidatePairId : public ComponentId { |
| 179 | public: |
| 180 | CandidatePairId(const std::string& content_name, int component, int index) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 181 | : ComponentId(StatsReport::kStatsReportTypeCandidatePair, |
| 182 | content_name, |
| 183 | component), |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 184 | index_(index) {} |
| 185 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 186 | bool Equals(const IdBase& other) const override { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 187 | return ComponentId::Equals(other) && |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 188 | static_cast<const CandidatePairId&>(other).index_ == index_; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | std::string ToString() const override { |
| 192 | std::string ret(ComponentId::ToString("Conn-")); |
| 193 | ret += '-'; |
Jonas Olsson | 6b1985d | 2018-07-05 11:59:48 +0200 | [diff] [blame] | 194 | ret += rtc::ToString(index_); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 195 | return ret; |
| 196 | } |
| 197 | |
| 198 | private: |
| 199 | const int index_; |
| 200 | }; |
| 201 | |
| 202 | } // namespace |
| 203 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 204 | StatsReport::IdBase::IdBase(StatsType type) : type_(type) {} |
| 205 | StatsReport::IdBase::~IdBase() {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 206 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 207 | StatsReport::StatsType StatsReport::IdBase::type() const { |
| 208 | return type_; |
| 209 | } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 210 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 211 | bool StatsReport::IdBase::Equals(const IdBase& other) const { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 212 | return other.type_ == type_; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 215 | StatsReport::Value::Value(StatsValueName name, int64_t value, Type int_type) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 216 | : name(name), type_(int_type) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 217 | RTC_DCHECK(type_ == kInt || type_ == kInt64); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 218 | type_ == kInt ? value_.int_ = static_cast<int>(value) : value_.int64_ = value; |
| 219 | } |
| 220 | |
| 221 | StatsReport::Value::Value(StatsValueName name, float f) |
| 222 | : name(name), type_(kFloat) { |
| 223 | value_.float_ = f; |
| 224 | } |
| 225 | |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 226 | StatsReport::Value::Value(StatsValueName name, const std::string& value) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 227 | : name(name), type_(kString) { |
| 228 | value_.string_ = new std::string(value); |
| 229 | } |
| 230 | |
| 231 | StatsReport::Value::Value(StatsValueName name, const char* value) |
| 232 | : name(name), type_(kStaticString) { |
| 233 | value_.static_string_ = value; |
| 234 | } |
| 235 | |
| 236 | StatsReport::Value::Value(StatsValueName name, bool b) |
| 237 | : name(name), type_(kBool) { |
| 238 | value_.bool_ = b; |
| 239 | } |
| 240 | |
| 241 | StatsReport::Value::Value(StatsValueName name, const Id& value) |
| 242 | : name(name), type_(kId) { |
| 243 | value_.id_ = new Id(value); |
| 244 | } |
| 245 | |
| 246 | StatsReport::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 | |
| 263 | bool 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. |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 269 | RTC_DCHECK_EQ(type_, other.type_); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 270 | |
| 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: { |
kwiberg | 5377bc7 | 2016-10-04 13:46:56 -0700 | [diff] [blame] | 279 | #if RTC_DCHECK_IS_ON |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 280 | if (value_.static_string_ != other.value_.static_string_) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 281 | RTC_DCHECK(strcmp(value_.static_string_, other.value_.static_string_) != |
| 282 | 0) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 283 | << "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 | |
| 299 | bool 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 | |
| 304 | bool 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; |
kwiberg | 5377bc7 | 2016-10-04 13:46:56 -0700 | [diff] [blame] | 309 | #if RTC_DCHECK_IS_ON |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 310 | if (value_.static_string_ != value) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 311 | RTC_DCHECK(strcmp(value_.static_string_, value) != 0) |
| 312 | << "Duplicate global?"; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 313 | #endif |
| 314 | return value == value_.static_string_; |
| 315 | } |
| 316 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 317 | bool StatsReport::Value::operator==(int64_t value) const { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 318 | return type_ == kInt ? value_.int_ == static_cast<int>(value) |
| 319 | : (type_ == kInt64 ? value_.int64_ == value : false); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | bool StatsReport::Value::operator==(bool value) const { |
| 323 | return type_ == kBool && value_.bool_ == value; |
| 324 | } |
| 325 | |
| 326 | bool StatsReport::Value::operator==(float value) const { |
| 327 | return type_ == kFloat && value_.float_ == value; |
| 328 | } |
| 329 | |
| 330 | bool StatsReport::Value::operator==(const Id& value) const { |
| 331 | return type_ == kId && (*value_.id_)->Equals(value); |
| 332 | } |
| 333 | |
| 334 | int StatsReport::Value::int_val() const { |
Ruslan Burakov | 2594f27 | 2019-03-12 11:10:57 +0100 | [diff] [blame] | 335 | RTC_DCHECK_EQ(type_, kInt); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 336 | return value_.int_; |
| 337 | } |
| 338 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 339 | int64_t StatsReport::Value::int64_val() const { |
Ruslan Burakov | 2594f27 | 2019-03-12 11:10:57 +0100 | [diff] [blame] | 340 | RTC_DCHECK_EQ(type_, kInt64); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 341 | return value_.int64_; |
| 342 | } |
| 343 | |
| 344 | float StatsReport::Value::float_val() const { |
Ruslan Burakov | 2594f27 | 2019-03-12 11:10:57 +0100 | [diff] [blame] | 345 | RTC_DCHECK_EQ(type_, kFloat); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 346 | return value_.float_; |
| 347 | } |
| 348 | |
| 349 | const char* StatsReport::Value::static_string_val() const { |
Ruslan Burakov | 2594f27 | 2019-03-12 11:10:57 +0100 | [diff] [blame] | 350 | RTC_DCHECK_EQ(type_, kStaticString); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 351 | return value_.static_string_; |
| 352 | } |
| 353 | |
| 354 | const std::string& StatsReport::Value::string_val() const { |
Ruslan Burakov | 2594f27 | 2019-03-12 11:10:57 +0100 | [diff] [blame] | 355 | RTC_DCHECK_EQ(type_, kString); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 356 | return *value_.string_; |
| 357 | } |
| 358 | |
| 359 | bool StatsReport::Value::bool_val() const { |
Ruslan Burakov | 2594f27 | 2019-03-12 11:10:57 +0100 | [diff] [blame] | 360 | RTC_DCHECK_EQ(type_, kBool); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 361 | return value_.bool_; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 362 | } |
| 363 | |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 364 | const char* StatsReport::Value::display_name() const { |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 365 | switch (name) { |
Minyue | 2a8a78c | 2016-04-07 16:48:15 +0200 | [diff] [blame] | 366 | case kStatsValueNameAecDivergentFilterFraction: |
| 367 | return "aecDivergentFilterFraction"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 368 | case kStatsValueNameAudioOutputLevel: |
| 369 | return "audioOutputLevel"; |
| 370 | case kStatsValueNameAudioInputLevel: |
| 371 | return "audioInputLevel"; |
| 372 | case kStatsValueNameBytesSent: |
| 373 | return "bytesSent"; |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 374 | case kStatsValueNameConcealedSamples: |
| 375 | return "concealedSamples"; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 376 | case kStatsValueNameConcealmentEvents: |
| 377 | return "concealmentEvents"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 378 | case kStatsValueNamePacketsSent: |
| 379 | return "packetsSent"; |
| 380 | case kStatsValueNameBytesReceived: |
| 381 | return "bytesReceived"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 382 | case kStatsValueNameLabel: |
| 383 | return "label"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 384 | case kStatsValueNamePacketsReceived: |
| 385 | return "packetsReceived"; |
| 386 | case kStatsValueNamePacketsLost: |
| 387 | return "packetsLost"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 388 | case kStatsValueNameProtocol: |
| 389 | return "protocol"; |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 390 | case kStatsValueNameTotalSamplesReceived: |
| 391 | return "totalSamplesReceived"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 392 | case kStatsValueNameTransportId: |
| 393 | return "transportId"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 394 | case kStatsValueNameSelectedCandidatePairId: |
| 395 | return "selectedCandidatePairId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 396 | case kStatsValueNameSsrc: |
| 397 | return "ssrc"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 398 | case kStatsValueNameState: |
| 399 | return "state"; |
| 400 | case kStatsValueNameDataChannelId: |
| 401 | return "datachannelid"; |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 402 | case kStatsValueNameFramesDecoded: |
| 403 | return "framesDecoded"; |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 404 | case kStatsValueNameFramesEncoded: |
| 405 | return "framesEncoded"; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 406 | case kStatsValueNameJitterBufferDelay: |
| 407 | return "jitterBufferDelay"; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 408 | case kStatsValueNameCodecImplementationName: |
| 409 | return "codecImplementationName"; |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame] | 410 | case kStatsValueNameMediaType: |
| 411 | return "mediaType"; |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 412 | case kStatsValueNameQpSum: |
| 413 | return "qpSum"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 414 | // 'goog' prefixed constants. |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 415 | case kStatsValueNameAccelerateRate: |
| 416 | return "googAccelerateRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 417 | case kStatsValueNameActiveConnection: |
| 418 | return "googActiveConnection"; |
| 419 | case kStatsValueNameActualEncBitrate: |
| 420 | return "googActualEncBitrate"; |
| 421 | case kStatsValueNameAvailableReceiveBandwidth: |
| 422 | return "googAvailableReceiveBandwidth"; |
| 423 | case kStatsValueNameAvailableSendBandwidth: |
| 424 | return "googAvailableSendBandwidth"; |
| 425 | case kStatsValueNameAvgEncodeMs: |
| 426 | return "googAvgEncodeMs"; |
| 427 | case kStatsValueNameBucketDelay: |
| 428 | return "googBucketDelay"; |
| 429 | case kStatsValueNameBandwidthLimitedResolution: |
| 430 | return "googBandwidthLimitedResolution"; |
zhihuang | 5ecf16c | 2016-06-01 17:09:15 -0700 | [diff] [blame] | 431 | // STUN ping related attributes. |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 432 | // |
zhihuang | 5ecf16c | 2016-06-01 17:09:15 -0700 | [diff] [blame] | 433 | // TODO(zhihuang) Rename these stats to follow the standards. |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 434 | // Connectivity checks. |
zhihuang | 5ecf16c | 2016-06-01 17:09:15 -0700 | [diff] [blame] | 435 | case kStatsValueNameSentPingRequestsTotal: |
| 436 | return "requestsSent"; |
| 437 | case kStatsValueNameSentPingRequestsBeforeFirstResponse: |
| 438 | return "consentRequestsSent"; |
| 439 | case kStatsValueNameSentPingResponses: |
| 440 | return "responsesSent"; |
| 441 | case kStatsValueNameRecvPingRequests: |
| 442 | return "requestsReceived"; |
| 443 | case kStatsValueNameRecvPingResponses: |
| 444 | return "responsesReceived"; |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 445 | // STUN Keepalive pings. |
| 446 | case kStatsValueNameSentStunKeepaliveRequests: |
| 447 | return "stunKeepaliveRequestsSent"; |
| 448 | case kStatsValueNameRecvStunKeepaliveResponses: |
| 449 | return "stunKeepaliveResponsesReceived"; |
| 450 | case kStatsValueNameStunKeepaliveRttTotal: |
| 451 | return "stunKeepaliveRttTotal"; |
| 452 | case kStatsValueNameStunKeepaliveRttSquaredTotal: |
| 453 | return "stunKeepaliveRttSquaredTotal"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 454 | |
| 455 | // Candidate related attributes. Values are taken from |
| 456 | // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. |
| 457 | case kStatsValueNameCandidateIPAddress: |
| 458 | return "ipAddress"; |
| 459 | case kStatsValueNameCandidateNetworkType: |
| 460 | return "networkType"; |
| 461 | case kStatsValueNameCandidatePortNumber: |
| 462 | return "portNumber"; |
| 463 | case kStatsValueNameCandidatePriority: |
| 464 | return "priority"; |
| 465 | case kStatsValueNameCandidateTransportType: |
| 466 | return "transport"; |
| 467 | case kStatsValueNameCandidateType: |
| 468 | return "candidateType"; |
| 469 | |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 470 | case kStatsValueNameChannelId: |
| 471 | return "googChannelId"; |
| 472 | case kStatsValueNameCodecName: |
| 473 | return "googCodecName"; |
| 474 | case kStatsValueNameComponent: |
| 475 | return "googComponent"; |
| 476 | case kStatsValueNameContentName: |
| 477 | return "googContentName"; |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 478 | case kStatsValueNameContentType: |
| 479 | return "googContentType"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 480 | case kStatsValueNameCpuLimitedResolution: |
| 481 | return "googCpuLimitedResolution"; |
| 482 | case kStatsValueNameDecodingCTSG: |
| 483 | return "googDecodingCTSG"; |
| 484 | case kStatsValueNameDecodingCTN: |
| 485 | return "googDecodingCTN"; |
henrik.lundin | 6348978 | 2016-09-20 01:47:12 -0700 | [diff] [blame] | 486 | case kStatsValueNameDecodingMutedOutput: |
| 487 | return "googDecodingMuted"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 488 | case kStatsValueNameDecodingNormal: |
| 489 | return "googDecodingNormal"; |
| 490 | case kStatsValueNameDecodingPLC: |
| 491 | return "googDecodingPLC"; |
Alex Narest | 5b5d97c | 2019-08-07 18:15:08 +0200 | [diff] [blame] | 492 | case kStatsValueNameDecodingCodecPLC: |
| 493 | return "googDecodingCodecPLC"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 494 | case kStatsValueNameDecodingCNG: |
| 495 | return "googDecodingCNG"; |
| 496 | case kStatsValueNameDecodingPLCCNG: |
| 497 | return "googDecodingPLCCNG"; |
| 498 | case kStatsValueNameDer: |
| 499 | return "googDerBase64"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 500 | case kStatsValueNameDtlsCipher: |
| 501 | return "dtlsCipher"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 502 | case kStatsValueNameEchoDelayMedian: |
| 503 | return "googEchoCancellationEchoDelayMedian"; |
| 504 | case kStatsValueNameEchoDelayStdDev: |
| 505 | return "googEchoCancellationEchoDelayStdDev"; |
| 506 | case kStatsValueNameEchoReturnLoss: |
| 507 | return "googEchoCancellationReturnLoss"; |
| 508 | case kStatsValueNameEchoReturnLossEnhancement: |
| 509 | return "googEchoCancellationReturnLossEnhancement"; |
| 510 | case kStatsValueNameEncodeUsagePercent: |
| 511 | return "googEncodeUsagePercent"; |
| 512 | case kStatsValueNameExpandRate: |
| 513 | return "googExpandRate"; |
| 514 | case kStatsValueNameFingerprint: |
| 515 | return "googFingerprint"; |
| 516 | case kStatsValueNameFingerprintAlgorithm: |
| 517 | return "googFingerprintAlgorithm"; |
| 518 | case kStatsValueNameFirsReceived: |
| 519 | return "googFirsReceived"; |
| 520 | case kStatsValueNameFirsSent: |
| 521 | return "googFirsSent"; |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 522 | case kStatsValueNameFirstFrameReceivedToDecodedMs: |
| 523 | return "googFirstFrameReceivedToDecodedMs"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 524 | case kStatsValueNameFrameHeightInput: |
| 525 | return "googFrameHeightInput"; |
| 526 | case kStatsValueNameFrameHeightReceived: |
| 527 | return "googFrameHeightReceived"; |
| 528 | case kStatsValueNameFrameHeightSent: |
| 529 | return "googFrameHeightSent"; |
| 530 | case kStatsValueNameFrameRateReceived: |
| 531 | return "googFrameRateReceived"; |
| 532 | case kStatsValueNameFrameRateDecoded: |
| 533 | return "googFrameRateDecoded"; |
| 534 | case kStatsValueNameFrameRateOutput: |
| 535 | return "googFrameRateOutput"; |
| 536 | case kStatsValueNameDecodeMs: |
| 537 | return "googDecodeMs"; |
| 538 | case kStatsValueNameMaxDecodeMs: |
| 539 | return "googMaxDecodeMs"; |
| 540 | case kStatsValueNameCurrentDelayMs: |
| 541 | return "googCurrentDelayMs"; |
| 542 | case kStatsValueNameTargetDelayMs: |
| 543 | return "googTargetDelayMs"; |
| 544 | case kStatsValueNameJitterBufferMs: |
| 545 | return "googJitterBufferMs"; |
| 546 | case kStatsValueNameMinPlayoutDelayMs: |
| 547 | return "googMinPlayoutDelayMs"; |
| 548 | case kStatsValueNameRenderDelayMs: |
| 549 | return "googRenderDelayMs"; |
| 550 | case kStatsValueNameCaptureStartNtpTimeMs: |
| 551 | return "googCaptureStartNtpTimeMs"; |
| 552 | case kStatsValueNameFrameRateInput: |
| 553 | return "googFrameRateInput"; |
| 554 | case kStatsValueNameFrameRateSent: |
| 555 | return "googFrameRateSent"; |
| 556 | case kStatsValueNameFrameWidthInput: |
| 557 | return "googFrameWidthInput"; |
| 558 | case kStatsValueNameFrameWidthReceived: |
| 559 | return "googFrameWidthReceived"; |
| 560 | case kStatsValueNameFrameWidthSent: |
| 561 | return "googFrameWidthSent"; |
Ã…sa Persson | c3ed630 | 2017-11-16 14:04:52 +0100 | [diff] [blame] | 562 | case kStatsValueNameHasEnteredLowResolution: |
| 563 | return "googHasEnteredLowResolution"; |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 16:35:03 +0100 | [diff] [blame] | 564 | case kStatsValueNameHugeFramesSent: |
| 565 | return "hugeFramesSent"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 566 | case kStatsValueNameInitiator: |
| 567 | return "googInitiator"; |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 568 | case kStatsValueNameInterframeDelayMaxMs: |
| 569 | return "googInterframeDelayMax"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 570 | case kStatsValueNameIssuerId: |
| 571 | return "googIssuerId"; |
| 572 | case kStatsValueNameJitterReceived: |
| 573 | return "googJitterReceived"; |
| 574 | case kStatsValueNameLocalAddress: |
| 575 | return "googLocalAddress"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 576 | case kStatsValueNameLocalCandidateId: |
| 577 | return "localCandidateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 578 | case kStatsValueNameLocalCandidateType: |
| 579 | return "googLocalCandidateType"; |
| 580 | case kStatsValueNameLocalCertificateId: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 581 | return "localCertificateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 582 | case kStatsValueNameAdaptationChanges: |
| 583 | return "googAdaptationChanges"; |
| 584 | case kStatsValueNameNacksReceived: |
| 585 | return "googNacksReceived"; |
| 586 | case kStatsValueNameNacksSent: |
| 587 | return "googNacksSent"; |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 588 | case kStatsValueNamePreemptiveExpandRate: |
| 589 | return "googPreemptiveExpandRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 590 | case kStatsValueNamePlisReceived: |
| 591 | return "googPlisReceived"; |
| 592 | case kStatsValueNamePlisSent: |
| 593 | return "googPlisSent"; |
| 594 | case kStatsValueNamePreferredJitterBufferMs: |
| 595 | return "googPreferredJitterBufferMs"; |
Peter Thatcher | 04ac81f | 2015-09-21 11:48:28 -0700 | [diff] [blame] | 596 | case kStatsValueNameReceiving: |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 597 | return "googReadable"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 598 | case kStatsValueNameRemoteAddress: |
| 599 | return "googRemoteAddress"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 600 | case kStatsValueNameRemoteCandidateId: |
| 601 | return "remoteCandidateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 602 | case kStatsValueNameRemoteCandidateType: |
| 603 | return "googRemoteCandidateType"; |
| 604 | case kStatsValueNameRemoteCertificateId: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 605 | return "remoteCertificateId"; |
ivoc | 8c63a82 | 2016-10-21 04:10:03 -0700 | [diff] [blame] | 606 | case kStatsValueNameResidualEchoLikelihood: |
| 607 | return "googResidualEchoLikelihood"; |
ivoc | 4e477a1 | 2017-01-15 08:29:46 -0800 | [diff] [blame] | 608 | case kStatsValueNameResidualEchoLikelihoodRecentMax: |
| 609 | return "googResidualEchoLikelihoodRecentMax"; |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 610 | case kStatsValueNameAnaBitrateActionCounter: |
| 611 | return "googAnaBitrateActionCounter"; |
| 612 | case kStatsValueNameAnaChannelActionCounter: |
| 613 | return "googAnaChannelActionCounter"; |
| 614 | case kStatsValueNameAnaDtxActionCounter: |
| 615 | return "googAnaDtxActionCounter"; |
| 616 | case kStatsValueNameAnaFecActionCounter: |
| 617 | return "googAnaFecActionCounter"; |
ivoc | 0d0b912 | 2017-09-08 13:24:21 -0700 | [diff] [blame] | 618 | case kStatsValueNameAnaFrameLengthIncreaseCounter: |
| 619 | return "googAnaFrameLengthIncreaseCounter"; |
| 620 | case kStatsValueNameAnaFrameLengthDecreaseCounter: |
| 621 | return "googAnaFrameLengthDecreaseCounter"; |
| 622 | case kStatsValueNameAnaUplinkPacketLossFraction: |
| 623 | return "googAnaUplinkPacketLossFraction"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 624 | case kStatsValueNameRetransmitBitrate: |
| 625 | return "googRetransmitBitrate"; |
| 626 | case kStatsValueNameRtt: |
| 627 | return "googRtt"; |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 628 | case kStatsValueNameSecondaryDecodedRate: |
| 629 | return "googSecondaryDecodedRate"; |
minyue-webrtc | 0e320ec | 2017-08-28 13:51:27 +0200 | [diff] [blame] | 630 | case kStatsValueNameSecondaryDiscardedRate: |
| 631 | return "googSecondaryDiscardedRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 632 | case kStatsValueNameSendPacketsDiscarded: |
| 633 | return "packetsDiscardedOnSend"; |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 634 | case kStatsValueNameSpeechExpandRate: |
| 635 | return "googSpeechExpandRate"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 636 | case kStatsValueNameSrtpCipher: |
| 637 | return "srtpCipher"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 638 | case kStatsValueNameTargetEncBitrate: |
| 639 | return "googTargetEncBitrate"; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 640 | case kStatsValueNameTotalAudioEnergy: |
| 641 | return "totalAudioEnergy"; |
| 642 | case kStatsValueNameTotalSamplesDuration: |
| 643 | return "totalSamplesDuration"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 644 | case kStatsValueNameTransmitBitrate: |
| 645 | return "googTransmitBitrate"; |
| 646 | case kStatsValueNameTransportType: |
| 647 | return "googTransportType"; |
| 648 | case kStatsValueNameTrackId: |
| 649 | return "googTrackId"; |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 650 | case kStatsValueNameTimingFrameInfo: |
| 651 | return "googTimingFrameInfo"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 652 | case kStatsValueNameTypingNoiseState: |
| 653 | return "googTypingNoiseState"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 654 | case kStatsValueNameWritable: |
| 655 | return "googWritable"; |
Alex Narest | bbeb109 | 2019-08-16 11:49:04 +0200 | [diff] [blame] | 656 | case kStatsValueNameAudioDeviceUnderrunCounter: |
| 657 | return "googAudioDeviceUnderrunCounter"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | return nullptr; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 661 | } |
| 662 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 663 | std::string StatsReport::Value::ToString() const { |
| 664 | switch (type_) { |
| 665 | case kInt: |
| 666 | return rtc::ToString(value_.int_); |
| 667 | case kInt64: |
| 668 | return rtc::ToString(value_.int64_); |
| 669 | case kFloat: |
| 670 | return rtc::ToString(value_.float_); |
| 671 | case kStaticString: |
| 672 | return std::string(value_.static_string_); |
| 673 | case kString: |
| 674 | return *value_.string_; |
| 675 | case kBool: |
| 676 | return value_.bool_ ? "true" : "false"; |
| 677 | case kId: |
| 678 | return (*value_.id_)->ToString(); |
| 679 | } |
| 680 | RTC_NOTREACHED(); |
| 681 | return std::string(); |
tommi@webrtc.org | afa6d16 | 2015-03-02 11:27:48 +0000 | [diff] [blame] | 682 | } |
| 683 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 684 | StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 685 | RTC_DCHECK(id_.get()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 686 | } |
| 687 | |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 688 | StatsReport::~StatsReport() = default; |
| 689 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 690 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 691 | StatsReport::Id StatsReport::NewBandwidthEstimationId() { |
| 692 | return Id(new RefCountedObject<BandwidthEstimationId>()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 696 | StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) { |
| 697 | return Id(new RefCountedObject<TypedId>(type, id)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 701 | StatsReport::Id StatsReport::NewTypedIntId(StatsType type, int id) { |
| 702 | return Id(new RefCountedObject<TypedIntId>(type, id)); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 706 | StatsReport::Id StatsReport::NewIdWithDirection( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 707 | StatsType type, |
| 708 | const std::string& id, |
| 709 | StatsReport::Direction direction) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 710 | return Id(new RefCountedObject<IdWithDirection>(type, id, direction)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 714 | StatsReport::Id StatsReport::NewCandidateId(bool local, const std::string& id) { |
| 715 | return Id(new RefCountedObject<CandidateId>(local, id)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | // static |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 719 | StatsReport::Id StatsReport::NewComponentId(const std::string& content_name, |
| 720 | int component) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 721 | return Id(new RefCountedObject<ComponentId>(content_name, component)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | // static |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 725 | StatsReport::Id StatsReport::NewCandidatePairId(const std::string& content_name, |
| 726 | int component, |
| 727 | int index) { |
| 728 | return Id( |
| 729 | new RefCountedObject<CandidatePairId>(content_name, component, index)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | const char* StatsReport::TypeToString() const { |
| 733 | return InternalTypeToString(id_->type()); |
| 734 | } |
| 735 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 736 | void StatsReport::AddString(StatsReport::StatsValueName name, |
| 737 | const std::string& value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 738 | const Value* found = FindValue(name); |
| 739 | if (!found || !(*found == value)) |
| 740 | values_[name] = ValuePtr(new Value(name, value)); |
| 741 | } |
| 742 | |
| 743 | void StatsReport::AddString(StatsReport::StatsValueName name, |
| 744 | const char* value) { |
| 745 | const Value* found = FindValue(name); |
| 746 | if (!found || !(*found == value)) |
| 747 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 750 | void StatsReport::AddInt64(StatsReport::StatsValueName name, int64_t value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 751 | const Value* found = FindValue(name); |
| 752 | if (!found || !(*found == value)) |
| 753 | values_[name] = ValuePtr(new Value(name, value, Value::kInt64)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 754 | } |
| 755 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 756 | void StatsReport::AddInt(StatsReport::StatsValueName name, int value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 757 | const Value* found = FindValue(name); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 758 | if (!found || !(*found == static_cast<int64_t>(value))) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 759 | values_[name] = ValuePtr(new Value(name, value, Value::kInt)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 760 | } |
| 761 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 762 | void StatsReport::AddFloat(StatsReport::StatsValueName name, float value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 763 | const Value* found = FindValue(name); |
| 764 | if (!found || !(*found == value)) |
| 765 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 766 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 767 | |
| 768 | void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 769 | const Value* found = FindValue(name); |
| 770 | if (!found || !(*found == value)) |
| 771 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 774 | void StatsReport::AddId(StatsReport::StatsValueName name, const Id& value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 775 | const Value* found = FindValue(name); |
| 776 | if (!found || !(*found == value)) |
| 777 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 778 | } |
| 779 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 780 | const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 781 | Values::const_iterator it = values_.find(name); |
| 782 | return it == values_.end() ? nullptr : it->second.get(); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 785 | StatsCollection::StatsCollection() {} |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 786 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 787 | StatsCollection::~StatsCollection() { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 788 | RTC_DCHECK(thread_checker_.IsCurrent()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 789 | for (auto* r : list_) |
| 790 | delete r; |
| 791 | } |
| 792 | |
| 793 | StatsCollection::const_iterator StatsCollection::begin() const { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 794 | RTC_DCHECK(thread_checker_.IsCurrent()); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 795 | return list_.begin(); |
| 796 | } |
| 797 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 798 | StatsCollection::const_iterator StatsCollection::end() const { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 799 | RTC_DCHECK(thread_checker_.IsCurrent()); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 800 | return list_.end(); |
| 801 | } |
| 802 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 803 | size_t StatsCollection::size() const { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 804 | RTC_DCHECK(thread_checker_.IsCurrent()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 805 | return list_.size(); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 806 | } |
| 807 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 808 | StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 809 | RTC_DCHECK(thread_checker_.IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 810 | RTC_DCHECK(Find(id) == nullptr); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 811 | StatsReport* report = new StatsReport(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 812 | list_.push_back(report); |
| 813 | return report; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 814 | } |
| 815 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 816 | StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 817 | RTC_DCHECK(thread_checker_.IsCurrent()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 818 | StatsReport* ret = Find(id); |
| 819 | return ret ? ret : InsertNew(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 820 | } |
| 821 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 822 | StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 823 | RTC_DCHECK(thread_checker_.IsCurrent()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 824 | RTC_DCHECK(id.get()); |
Steve Anton | a59dcc3 | 2019-03-25 13:53:07 -0700 | [diff] [blame] | 825 | Container::iterator it = absl::c_find_if( |
| 826 | list_, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 827 | [&id](const StatsReport* r) -> bool { return r->id()->Equals(id); }); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 828 | if (it != end()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 829 | StatsReport* report = new StatsReport((*it)->id()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 830 | delete *it; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 831 | *it = report; |
| 832 | return report; |
| 833 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 834 | return InsertNew(id); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 835 | } |
| 836 | |
deadbeef | 8d60a94 | 2017-02-27 14:47:33 -0800 | [diff] [blame] | 837 | // Looks for a report with the given |id|. If one is not found, null |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 838 | // will be returned. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 839 | StatsReport* StatsCollection::Find(const StatsReport::Id& id) { |
Sebastian Jansson | c01367d | 2019-04-08 15:20:44 +0200 | [diff] [blame] | 840 | RTC_DCHECK(thread_checker_.IsCurrent()); |
Steve Anton | a59dcc3 | 2019-03-25 13:53:07 -0700 | [diff] [blame] | 841 | Container::iterator it = absl::c_find_if( |
| 842 | list_, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 843 | [&id](const StatsReport* r) -> bool { return r->id()->Equals(id); }); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 844 | return it == list_.end() ? nullptr : *it; |
| 845 | } |
| 846 | |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 847 | } // namespace webrtc |