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