| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * libjingle | |
| 3 * Copyright 2014 Google Inc. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | |
| 9 * this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 * this list of conditions and the following disclaimer in the documentation | |
| 12 * and/or other materials provided with the distribution. | |
| 13 * 3. The name of the author may not be used to endorse or promote products | |
| 14 * derived from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #include "talk/app/webrtc/statstypes.h" | |
| 29 | |
| 30 #include <string.h> | |
| 31 | |
| 32 #include "webrtc/base/checks.h" | |
| 33 | |
| 34 // TODO(tommi): Could we have a static map of value name -> expected type | |
| 35 // and use this to RTC_DCHECK on correct usage (somewhat strongly typed values)? | |
| 36 // Alternatively, we could define the names+type in a separate document and | |
| 37 // generate strongly typed inline C++ code that forces the correct type to be | |
| 38 // used for a given name at compile time. | |
| 39 | |
| 40 using rtc::RefCountedObject; | |
| 41 | |
| 42 namespace webrtc { | |
| 43 namespace { | |
| 44 | |
| 45 // The id of StatsReport of type kStatsReportTypeBwe. | |
| 46 const char kStatsReportVideoBweId[] = "bweforvideo"; | |
| 47 | |
| 48 // NOTE: These names need to be consistent with an external | |
| 49 // specification (W3C Stats Identifiers). | |
| 50 const char* InternalTypeToString(StatsReport::StatsType type) { | |
| 51 switch (type) { | |
| 52 case StatsReport::kStatsReportTypeSession: | |
| 53 return "googLibjingleSession"; | |
| 54 case StatsReport::kStatsReportTypeBwe: | |
| 55 return "VideoBwe"; | |
| 56 case StatsReport::kStatsReportTypeRemoteSsrc: | |
| 57 return "remoteSsrc"; | |
| 58 case StatsReport::kStatsReportTypeSsrc: | |
| 59 return "ssrc"; | |
| 60 case StatsReport::kStatsReportTypeTrack: | |
| 61 return "googTrack"; | |
| 62 case StatsReport::kStatsReportTypeIceLocalCandidate: | |
| 63 return "localcandidate"; | |
| 64 case StatsReport::kStatsReportTypeIceRemoteCandidate: | |
| 65 return "remotecandidate"; | |
| 66 case StatsReport::kStatsReportTypeTransport: | |
| 67 return "transport"; | |
| 68 case StatsReport::kStatsReportTypeComponent: | |
| 69 return "googComponent"; | |
| 70 case StatsReport::kStatsReportTypeCandidatePair: | |
| 71 return "googCandidatePair"; | |
| 72 case StatsReport::kStatsReportTypeCertificate: | |
| 73 return "googCertificate"; | |
| 74 case StatsReport::kStatsReportTypeDataChannel: | |
| 75 return "datachannel"; | |
| 76 } | |
| 77 RTC_DCHECK(false); | |
| 78 return nullptr; | |
| 79 } | |
| 80 | |
| 81 class BandwidthEstimationId : public StatsReport::IdBase { | |
| 82 public: | |
| 83 BandwidthEstimationId() | |
| 84 : StatsReport::IdBase(StatsReport::kStatsReportTypeBwe) {} | |
| 85 std::string ToString() const override { return kStatsReportVideoBweId; } | |
| 86 }; | |
| 87 | |
| 88 class TypedId : public StatsReport::IdBase { | |
| 89 public: | |
| 90 TypedId(StatsReport::StatsType type, const std::string& id) | |
| 91 : StatsReport::IdBase(type), id_(id) {} | |
| 92 | |
| 93 bool Equals(const IdBase& other) const override { | |
| 94 return IdBase::Equals(other) && | |
| 95 static_cast<const TypedId&>(other).id_ == id_; | |
| 96 } | |
| 97 | |
| 98 std::string ToString() const override { | |
| 99 return std::string(InternalTypeToString(type_)) + kSeparator + id_; | |
| 100 } | |
| 101 | |
| 102 protected: | |
| 103 const std::string id_; | |
| 104 }; | |
| 105 | |
| 106 class TypedIntId : public StatsReport::IdBase { | |
| 107 public: | |
| 108 TypedIntId(StatsReport::StatsType type, int id) | |
| 109 : StatsReport::IdBase(type), id_(id) {} | |
| 110 | |
| 111 bool Equals(const IdBase& other) const override { | |
| 112 return IdBase::Equals(other) && | |
| 113 static_cast<const TypedIntId&>(other).id_ == id_; | |
| 114 } | |
| 115 | |
| 116 std::string ToString() const override { | |
| 117 return std::string(InternalTypeToString(type_)) + | |
| 118 kSeparator + | |
| 119 rtc::ToString<int>(id_); | |
| 120 } | |
| 121 | |
| 122 protected: | |
| 123 const int id_; | |
| 124 }; | |
| 125 | |
| 126 class IdWithDirection : public TypedId { | |
| 127 public: | |
| 128 IdWithDirection(StatsReport::StatsType type, const std::string& id, | |
| 129 StatsReport::Direction direction) | |
| 130 : TypedId(type, id), direction_(direction) {} | |
| 131 | |
| 132 bool Equals(const IdBase& other) const override { | |
| 133 return TypedId::Equals(other) && | |
| 134 static_cast<const IdWithDirection&>(other).direction_ == direction_; | |
| 135 } | |
| 136 | |
| 137 std::string ToString() const override { | |
| 138 std::string ret(TypedId::ToString()); | |
| 139 ret += kSeparator; | |
| 140 ret += direction_ == StatsReport::kSend ? "send" : "recv"; | |
| 141 return ret; | |
| 142 } | |
| 143 | |
| 144 private: | |
| 145 const StatsReport::Direction direction_; | |
| 146 }; | |
| 147 | |
| 148 class CandidateId : public TypedId { | |
| 149 public: | |
| 150 CandidateId(bool local, const std::string& id) | |
| 151 : TypedId(local ? | |
| 152 StatsReport::kStatsReportTypeIceLocalCandidate : | |
| 153 StatsReport::kStatsReportTypeIceRemoteCandidate, | |
| 154 id) { | |
| 155 } | |
| 156 | |
| 157 std::string ToString() const override { | |
| 158 return "Cand-" + id_; | |
| 159 } | |
| 160 }; | |
| 161 | |
| 162 class ComponentId : public StatsReport::IdBase { | |
| 163 public: | |
| 164 ComponentId(const std::string& content_name, int component) | |
| 165 : ComponentId(StatsReport::kStatsReportTypeComponent, content_name, | |
| 166 component) {} | |
| 167 | |
| 168 bool Equals(const IdBase& other) const override { | |
| 169 return IdBase::Equals(other) && | |
| 170 static_cast<const ComponentId&>(other).component_ == component_ && | |
| 171 static_cast<const ComponentId&>(other).content_name_ == content_name_; | |
| 172 } | |
| 173 | |
| 174 std::string ToString() const override { | |
| 175 return ToString("Channel-"); | |
| 176 } | |
| 177 | |
| 178 protected: | |
| 179 ComponentId(StatsReport::StatsType type, const std::string& content_name, | |
| 180 int component) | |
| 181 : IdBase(type), | |
| 182 content_name_(content_name), | |
| 183 component_(component) {} | |
| 184 | |
| 185 std::string ToString(const char* prefix) const { | |
| 186 std::string ret(prefix); | |
| 187 ret += content_name_; | |
| 188 ret += '-'; | |
| 189 ret += rtc::ToString<>(component_); | |
| 190 return ret; | |
| 191 } | |
| 192 | |
| 193 private: | |
| 194 const std::string content_name_; | |
| 195 const int component_; | |
| 196 }; | |
| 197 | |
| 198 class CandidatePairId : public ComponentId { | |
| 199 public: | |
| 200 CandidatePairId(const std::string& content_name, int component, int index) | |
| 201 : ComponentId(StatsReport::kStatsReportTypeCandidatePair, content_name, | |
| 202 component), | |
| 203 index_(index) {} | |
| 204 | |
| 205 bool Equals(const IdBase& other) const override { | |
| 206 return ComponentId::Equals(other) && | |
| 207 static_cast<const CandidatePairId&>(other).index_ == index_; | |
| 208 } | |
| 209 | |
| 210 std::string ToString() const override { | |
| 211 std::string ret(ComponentId::ToString("Conn-")); | |
| 212 ret += '-'; | |
| 213 ret += rtc::ToString<>(index_); | |
| 214 return ret; | |
| 215 } | |
| 216 | |
| 217 private: | |
| 218 const int index_; | |
| 219 }; | |
| 220 | |
| 221 } // namespace | |
| 222 | |
| 223 StatsReport::IdBase::IdBase(StatsType type) : type_(type) {} | |
| 224 StatsReport::IdBase::~IdBase() {} | |
| 225 | |
| 226 StatsReport::StatsType StatsReport::IdBase::type() const { return type_; } | |
| 227 | |
| 228 bool StatsReport::IdBase::Equals(const IdBase& other) const { | |
| 229 return other.type_ == type_; | |
| 230 } | |
| 231 | |
| 232 StatsReport::Value::Value(StatsValueName name, int64_t value, Type int_type) | |
| 233 : name(name), type_(int_type) { | |
| 234 RTC_DCHECK(type_ == kInt || type_ == kInt64); | |
| 235 type_ == kInt ? value_.int_ = static_cast<int>(value) : value_.int64_ = value; | |
| 236 } | |
| 237 | |
| 238 StatsReport::Value::Value(StatsValueName name, float f) | |
| 239 : name(name), type_(kFloat) { | |
| 240 value_.float_ = f; | |
| 241 } | |
| 242 | |
| 243 StatsReport::Value::Value(StatsValueName name, const std::string& value) | |
| 244 : name(name), type_(kString) { | |
| 245 value_.string_ = new std::string(value); | |
| 246 } | |
| 247 | |
| 248 StatsReport::Value::Value(StatsValueName name, const char* value) | |
| 249 : name(name), type_(kStaticString) { | |
| 250 value_.static_string_ = value; | |
| 251 } | |
| 252 | |
| 253 StatsReport::Value::Value(StatsValueName name, bool b) | |
| 254 : name(name), type_(kBool) { | |
| 255 value_.bool_ = b; | |
| 256 } | |
| 257 | |
| 258 StatsReport::Value::Value(StatsValueName name, const Id& value) | |
| 259 : name(name), type_(kId) { | |
| 260 value_.id_ = new Id(value); | |
| 261 } | |
| 262 | |
| 263 StatsReport::Value::~Value() { | |
| 264 switch (type_) { | |
| 265 case kInt: | |
| 266 case kInt64: | |
| 267 case kFloat: | |
| 268 case kBool: | |
| 269 case kStaticString: | |
| 270 break; | |
| 271 case kString: | |
| 272 delete value_.string_; | |
| 273 break; | |
| 274 case kId: | |
| 275 delete value_.id_; | |
| 276 break; | |
| 277 } | |
| 278 } | |
| 279 | |
| 280 bool StatsReport::Value::Equals(const Value& other) const { | |
| 281 if (name != other.name) | |
| 282 return false; | |
| 283 | |
| 284 // There's a 1:1 relation between a name and a type, so we don't have to | |
| 285 // check that. | |
| 286 RTC_DCHECK_EQ(type_, other.type_); | |
| 287 | |
| 288 switch (type_) { | |
| 289 case kInt: | |
| 290 return value_.int_ == other.value_.int_; | |
| 291 case kInt64: | |
| 292 return value_.int64_ == other.value_.int64_; | |
| 293 case kFloat: | |
| 294 return value_.float_ == other.value_.float_; | |
| 295 case kStaticString: { | |
| 296 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) | |
| 297 if (value_.static_string_ != other.value_.static_string_) { | |
| 298 RTC_DCHECK(strcmp(value_.static_string_, other.value_.static_string_) != | |
| 299 0) | |
| 300 << "Duplicate global?"; | |
| 301 } | |
| 302 #endif | |
| 303 return value_.static_string_ == other.value_.static_string_; | |
| 304 } | |
| 305 case kString: | |
| 306 return *value_.string_ == *other.value_.string_; | |
| 307 case kBool: | |
| 308 return value_.bool_ == other.value_.bool_; | |
| 309 case kId: | |
| 310 return (*value_.id_)->Equals(*other.value_.id_); | |
| 311 } | |
| 312 RTC_NOTREACHED(); | |
| 313 return false; | |
| 314 } | |
| 315 | |
| 316 bool StatsReport::Value::operator==(const std::string& value) const { | |
| 317 return (type_ == kString && value_.string_->compare(value) == 0) || | |
| 318 (type_ == kStaticString && value.compare(value_.static_string_) == 0); | |
| 319 } | |
| 320 | |
| 321 bool StatsReport::Value::operator==(const char* value) const { | |
| 322 if (type_ == kString) | |
| 323 return value_.string_->compare(value) == 0; | |
| 324 if (type_ != kStaticString) | |
| 325 return false; | |
| 326 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) | |
| 327 if (value_.static_string_ != value) | |
| 328 RTC_DCHECK(strcmp(value_.static_string_, value) != 0) | |
| 329 << "Duplicate global?"; | |
| 330 #endif | |
| 331 return value == value_.static_string_; | |
| 332 } | |
| 333 | |
| 334 bool StatsReport::Value::operator==(int64_t value) const { | |
| 335 return type_ == kInt ? value_.int_ == static_cast<int>(value) : | |
| 336 (type_ == kInt64 ? value_.int64_ == value : false); | |
| 337 } | |
| 338 | |
| 339 bool StatsReport::Value::operator==(bool value) const { | |
| 340 return type_ == kBool && value_.bool_ == value; | |
| 341 } | |
| 342 | |
| 343 bool StatsReport::Value::operator==(float value) const { | |
| 344 return type_ == kFloat && value_.float_ == value; | |
| 345 } | |
| 346 | |
| 347 bool StatsReport::Value::operator==(const Id& value) const { | |
| 348 return type_ == kId && (*value_.id_)->Equals(value); | |
| 349 } | |
| 350 | |
| 351 int StatsReport::Value::int_val() const { | |
| 352 RTC_DCHECK(type_ == kInt); | |
| 353 return value_.int_; | |
| 354 } | |
| 355 | |
| 356 int64_t StatsReport::Value::int64_val() const { | |
| 357 RTC_DCHECK(type_ == kInt64); | |
| 358 return value_.int64_; | |
| 359 } | |
| 360 | |
| 361 float StatsReport::Value::float_val() const { | |
| 362 RTC_DCHECK(type_ == kFloat); | |
| 363 return value_.float_; | |
| 364 } | |
| 365 | |
| 366 const char* StatsReport::Value::static_string_val() const { | |
| 367 RTC_DCHECK(type_ == kStaticString); | |
| 368 return value_.static_string_; | |
| 369 } | |
| 370 | |
| 371 const std::string& StatsReport::Value::string_val() const { | |
| 372 RTC_DCHECK(type_ == kString); | |
| 373 return *value_.string_; | |
| 374 } | |
| 375 | |
| 376 bool StatsReport::Value::bool_val() const { | |
| 377 RTC_DCHECK(type_ == kBool); | |
| 378 return value_.bool_; | |
| 379 } | |
| 380 | |
| 381 const char* StatsReport::Value::display_name() const { | |
| 382 switch (name) { | |
| 383 case kStatsValueNameAudioOutputLevel: | |
| 384 return "audioOutputLevel"; | |
| 385 case kStatsValueNameAudioInputLevel: | |
| 386 return "audioInputLevel"; | |
| 387 case kStatsValueNameBytesSent: | |
| 388 return "bytesSent"; | |
| 389 case kStatsValueNamePacketsSent: | |
| 390 return "packetsSent"; | |
| 391 case kStatsValueNameBytesReceived: | |
| 392 return "bytesReceived"; | |
| 393 case kStatsValueNameLabel: | |
| 394 return "label"; | |
| 395 case kStatsValueNamePacketsReceived: | |
| 396 return "packetsReceived"; | |
| 397 case kStatsValueNamePacketsLost: | |
| 398 return "packetsLost"; | |
| 399 case kStatsValueNameProtocol: | |
| 400 return "protocol"; | |
| 401 case kStatsValueNameTransportId: | |
| 402 return "transportId"; | |
| 403 case kStatsValueNameSelectedCandidatePairId: | |
| 404 return "selectedCandidatePairId"; | |
| 405 case kStatsValueNameSsrc: | |
| 406 return "ssrc"; | |
| 407 case kStatsValueNameState: | |
| 408 return "state"; | |
| 409 case kStatsValueNameDataChannelId: | |
| 410 return "datachannelid"; | |
| 411 case kStatsValueNameCodecImplementationName: | |
| 412 return "codecImplementationName"; | |
| 413 case kStatsValueNameMediaType: | |
| 414 return "mediaType"; | |
| 415 // 'goog' prefixed constants. | |
| 416 case kStatsValueNameAccelerateRate: | |
| 417 return "googAccelerateRate"; | |
| 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"; | |
| 432 | |
| 433 // Candidate related attributes. Values are taken from | |
| 434 // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. | |
| 435 case kStatsValueNameCandidateIPAddress: | |
| 436 return "ipAddress"; | |
| 437 case kStatsValueNameCandidateNetworkType: | |
| 438 return "networkType"; | |
| 439 case kStatsValueNameCandidatePortNumber: | |
| 440 return "portNumber"; | |
| 441 case kStatsValueNameCandidatePriority: | |
| 442 return "priority"; | |
| 443 case kStatsValueNameCandidateTransportType: | |
| 444 return "transport"; | |
| 445 case kStatsValueNameCandidateType: | |
| 446 return "candidateType"; | |
| 447 | |
| 448 case kStatsValueNameChannelId: | |
| 449 return "googChannelId"; | |
| 450 case kStatsValueNameCodecName: | |
| 451 return "googCodecName"; | |
| 452 case kStatsValueNameComponent: | |
| 453 return "googComponent"; | |
| 454 case kStatsValueNameContentName: | |
| 455 return "googContentName"; | |
| 456 case kStatsValueNameCpuLimitedResolution: | |
| 457 return "googCpuLimitedResolution"; | |
| 458 case kStatsValueNameDecodingCTSG: | |
| 459 return "googDecodingCTSG"; | |
| 460 case kStatsValueNameDecodingCTN: | |
| 461 return "googDecodingCTN"; | |
| 462 case kStatsValueNameDecodingNormal: | |
| 463 return "googDecodingNormal"; | |
| 464 case kStatsValueNameDecodingPLC: | |
| 465 return "googDecodingPLC"; | |
| 466 case kStatsValueNameDecodingCNG: | |
| 467 return "googDecodingCNG"; | |
| 468 case kStatsValueNameDecodingPLCCNG: | |
| 469 return "googDecodingPLCCNG"; | |
| 470 case kStatsValueNameDer: | |
| 471 return "googDerBase64"; | |
| 472 case kStatsValueNameDtlsCipher: | |
| 473 return "dtlsCipher"; | |
| 474 case kStatsValueNameEchoCancellationQualityMin: | |
| 475 return "googEchoCancellationQualityMin"; | |
| 476 case kStatsValueNameEchoDelayMedian: | |
| 477 return "googEchoCancellationEchoDelayMedian"; | |
| 478 case kStatsValueNameEchoDelayStdDev: | |
| 479 return "googEchoCancellationEchoDelayStdDev"; | |
| 480 case kStatsValueNameEchoReturnLoss: | |
| 481 return "googEchoCancellationReturnLoss"; | |
| 482 case kStatsValueNameEchoReturnLossEnhancement: | |
| 483 return "googEchoCancellationReturnLossEnhancement"; | |
| 484 case kStatsValueNameEncodeUsagePercent: | |
| 485 return "googEncodeUsagePercent"; | |
| 486 case kStatsValueNameExpandRate: | |
| 487 return "googExpandRate"; | |
| 488 case kStatsValueNameFingerprint: | |
| 489 return "googFingerprint"; | |
| 490 case kStatsValueNameFingerprintAlgorithm: | |
| 491 return "googFingerprintAlgorithm"; | |
| 492 case kStatsValueNameFirsReceived: | |
| 493 return "googFirsReceived"; | |
| 494 case kStatsValueNameFirsSent: | |
| 495 return "googFirsSent"; | |
| 496 case kStatsValueNameFrameHeightInput: | |
| 497 return "googFrameHeightInput"; | |
| 498 case kStatsValueNameFrameHeightReceived: | |
| 499 return "googFrameHeightReceived"; | |
| 500 case kStatsValueNameFrameHeightSent: | |
| 501 return "googFrameHeightSent"; | |
| 502 case kStatsValueNameFrameRateReceived: | |
| 503 return "googFrameRateReceived"; | |
| 504 case kStatsValueNameFrameRateDecoded: | |
| 505 return "googFrameRateDecoded"; | |
| 506 case kStatsValueNameFrameRateOutput: | |
| 507 return "googFrameRateOutput"; | |
| 508 case kStatsValueNameDecodeMs: | |
| 509 return "googDecodeMs"; | |
| 510 case kStatsValueNameMaxDecodeMs: | |
| 511 return "googMaxDecodeMs"; | |
| 512 case kStatsValueNameCurrentDelayMs: | |
| 513 return "googCurrentDelayMs"; | |
| 514 case kStatsValueNameTargetDelayMs: | |
| 515 return "googTargetDelayMs"; | |
| 516 case kStatsValueNameJitterBufferMs: | |
| 517 return "googJitterBufferMs"; | |
| 518 case kStatsValueNameMinPlayoutDelayMs: | |
| 519 return "googMinPlayoutDelayMs"; | |
| 520 case kStatsValueNameRenderDelayMs: | |
| 521 return "googRenderDelayMs"; | |
| 522 case kStatsValueNameCaptureStartNtpTimeMs: | |
| 523 return "googCaptureStartNtpTimeMs"; | |
| 524 case kStatsValueNameFrameRateInput: | |
| 525 return "googFrameRateInput"; | |
| 526 case kStatsValueNameFrameRateSent: | |
| 527 return "googFrameRateSent"; | |
| 528 case kStatsValueNameFrameWidthInput: | |
| 529 return "googFrameWidthInput"; | |
| 530 case kStatsValueNameFrameWidthReceived: | |
| 531 return "googFrameWidthReceived"; | |
| 532 case kStatsValueNameFrameWidthSent: | |
| 533 return "googFrameWidthSent"; | |
| 534 case kStatsValueNameInitiator: | |
| 535 return "googInitiator"; | |
| 536 case kStatsValueNameIssuerId: | |
| 537 return "googIssuerId"; | |
| 538 case kStatsValueNameJitterReceived: | |
| 539 return "googJitterReceived"; | |
| 540 case kStatsValueNameLocalAddress: | |
| 541 return "googLocalAddress"; | |
| 542 case kStatsValueNameLocalCandidateId: | |
| 543 return "localCandidateId"; | |
| 544 case kStatsValueNameLocalCandidateType: | |
| 545 return "googLocalCandidateType"; | |
| 546 case kStatsValueNameLocalCertificateId: | |
| 547 return "localCertificateId"; | |
| 548 case kStatsValueNameAdaptationChanges: | |
| 549 return "googAdaptationChanges"; | |
| 550 case kStatsValueNameNacksReceived: | |
| 551 return "googNacksReceived"; | |
| 552 case kStatsValueNameNacksSent: | |
| 553 return "googNacksSent"; | |
| 554 case kStatsValueNamePreemptiveExpandRate: | |
| 555 return "googPreemptiveExpandRate"; | |
| 556 case kStatsValueNamePlisReceived: | |
| 557 return "googPlisReceived"; | |
| 558 case kStatsValueNamePlisSent: | |
| 559 return "googPlisSent"; | |
| 560 case kStatsValueNamePreferredJitterBufferMs: | |
| 561 return "googPreferredJitterBufferMs"; | |
| 562 case kStatsValueNameReceiving: | |
| 563 return "googReadable"; | |
| 564 case kStatsValueNameRemoteAddress: | |
| 565 return "googRemoteAddress"; | |
| 566 case kStatsValueNameRemoteCandidateId: | |
| 567 return "remoteCandidateId"; | |
| 568 case kStatsValueNameRemoteCandidateType: | |
| 569 return "googRemoteCandidateType"; | |
| 570 case kStatsValueNameRemoteCertificateId: | |
| 571 return "remoteCertificateId"; | |
| 572 case kStatsValueNameRetransmitBitrate: | |
| 573 return "googRetransmitBitrate"; | |
| 574 case kStatsValueNameRtt: | |
| 575 return "googRtt"; | |
| 576 case kStatsValueNameSecondaryDecodedRate: | |
| 577 return "googSecondaryDecodedRate"; | |
| 578 case kStatsValueNameSendPacketsDiscarded: | |
| 579 return "packetsDiscardedOnSend"; | |
| 580 case kStatsValueNameSpeechExpandRate: | |
| 581 return "googSpeechExpandRate"; | |
| 582 case kStatsValueNameSrtpCipher: | |
| 583 return "srtpCipher"; | |
| 584 case kStatsValueNameTargetEncBitrate: | |
| 585 return "googTargetEncBitrate"; | |
| 586 case kStatsValueNameTransmitBitrate: | |
| 587 return "googTransmitBitrate"; | |
| 588 case kStatsValueNameTransportType: | |
| 589 return "googTransportType"; | |
| 590 case kStatsValueNameTrackId: | |
| 591 return "googTrackId"; | |
| 592 case kStatsValueNameTypingNoiseState: | |
| 593 return "googTypingNoiseState"; | |
| 594 case kStatsValueNameViewLimitedResolution: | |
| 595 return "googViewLimitedResolution"; | |
| 596 case kStatsValueNameWritable: | |
| 597 return "googWritable"; | |
| 598 } | |
| 599 | |
| 600 return nullptr; | |
| 601 } | |
| 602 | |
| 603 std::string StatsReport::Value::ToString() const { | |
| 604 switch (type_) { | |
| 605 case kInt: | |
| 606 return rtc::ToString(value_.int_); | |
| 607 case kInt64: | |
| 608 return rtc::ToString(value_.int64_); | |
| 609 case kFloat: | |
| 610 return rtc::ToString(value_.float_); | |
| 611 case kStaticString: | |
| 612 return std::string(value_.static_string_); | |
| 613 case kString: | |
| 614 return *value_.string_; | |
| 615 case kBool: | |
| 616 return value_.bool_ ? "true" : "false"; | |
| 617 case kId: | |
| 618 return (*value_.id_)->ToString(); | |
| 619 } | |
| 620 RTC_NOTREACHED(); | |
| 621 return std::string(); | |
| 622 } | |
| 623 | |
| 624 StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) { | |
| 625 RTC_DCHECK(id_.get()); | |
| 626 } | |
| 627 | |
| 628 // static | |
| 629 StatsReport::Id StatsReport::NewBandwidthEstimationId() { | |
| 630 return Id(new RefCountedObject<BandwidthEstimationId>()); | |
| 631 } | |
| 632 | |
| 633 // static | |
| 634 StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) { | |
| 635 return Id(new RefCountedObject<TypedId>(type, id)); | |
| 636 } | |
| 637 | |
| 638 // static | |
| 639 StatsReport::Id StatsReport::NewTypedIntId(StatsType type, int id) { | |
| 640 return Id(new RefCountedObject<TypedIntId>(type, id)); | |
| 641 } | |
| 642 | |
| 643 // static | |
| 644 StatsReport::Id StatsReport::NewIdWithDirection( | |
| 645 StatsType type, const std::string& id, StatsReport::Direction direction) { | |
| 646 return Id(new RefCountedObject<IdWithDirection>(type, id, direction)); | |
| 647 } | |
| 648 | |
| 649 // static | |
| 650 StatsReport::Id StatsReport::NewCandidateId(bool local, const std::string& id) { | |
| 651 return Id(new RefCountedObject<CandidateId>(local, id)); | |
| 652 } | |
| 653 | |
| 654 // static | |
| 655 StatsReport::Id StatsReport::NewComponentId( | |
| 656 const std::string& content_name, int component) { | |
| 657 return Id(new RefCountedObject<ComponentId>(content_name, component)); | |
| 658 } | |
| 659 | |
| 660 // static | |
| 661 StatsReport::Id StatsReport::NewCandidatePairId( | |
| 662 const std::string& content_name, int component, int index) { | |
| 663 return Id(new RefCountedObject<CandidatePairId>( | |
| 664 content_name, component, index)); | |
| 665 } | |
| 666 | |
| 667 const char* StatsReport::TypeToString() const { | |
| 668 return InternalTypeToString(id_->type()); | |
| 669 } | |
| 670 | |
| 671 void StatsReport::AddString(StatsReport::StatsValueName name, | |
| 672 const std::string& value) { | |
| 673 const Value* found = FindValue(name); | |
| 674 if (!found || !(*found == value)) | |
| 675 values_[name] = ValuePtr(new Value(name, value)); | |
| 676 } | |
| 677 | |
| 678 void StatsReport::AddString(StatsReport::StatsValueName name, | |
| 679 const char* value) { | |
| 680 const Value* found = FindValue(name); | |
| 681 if (!found || !(*found == value)) | |
| 682 values_[name] = ValuePtr(new Value(name, value)); | |
| 683 } | |
| 684 | |
| 685 void StatsReport::AddInt64(StatsReport::StatsValueName name, int64_t value) { | |
| 686 const Value* found = FindValue(name); | |
| 687 if (!found || !(*found == value)) | |
| 688 values_[name] = ValuePtr(new Value(name, value, Value::kInt64)); | |
| 689 } | |
| 690 | |
| 691 void StatsReport::AddInt(StatsReport::StatsValueName name, int value) { | |
| 692 const Value* found = FindValue(name); | |
| 693 if (!found || !(*found == static_cast<int64_t>(value))) | |
| 694 values_[name] = ValuePtr(new Value(name, value, Value::kInt)); | |
| 695 } | |
| 696 | |
| 697 void StatsReport::AddFloat(StatsReport::StatsValueName name, float value) { | |
| 698 const Value* found = FindValue(name); | |
| 699 if (!found || !(*found == value)) | |
| 700 values_[name] = ValuePtr(new Value(name, value)); | |
| 701 } | |
| 702 | |
| 703 void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) { | |
| 704 const Value* found = FindValue(name); | |
| 705 if (!found || !(*found == value)) | |
| 706 values_[name] = ValuePtr(new Value(name, value)); | |
| 707 } | |
| 708 | |
| 709 void StatsReport::AddId(StatsReport::StatsValueName name, | |
| 710 const Id& value) { | |
| 711 const Value* found = FindValue(name); | |
| 712 if (!found || !(*found == value)) | |
| 713 values_[name] = ValuePtr(new Value(name, value)); | |
| 714 } | |
| 715 | |
| 716 const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { | |
| 717 Values::const_iterator it = values_.find(name); | |
| 718 return it == values_.end() ? nullptr : it->second.get(); | |
| 719 } | |
| 720 | |
| 721 StatsCollection::StatsCollection() { | |
| 722 } | |
| 723 | |
| 724 StatsCollection::~StatsCollection() { | |
| 725 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 726 for (auto* r : list_) | |
| 727 delete r; | |
| 728 } | |
| 729 | |
| 730 StatsCollection::const_iterator StatsCollection::begin() const { | |
| 731 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 732 return list_.begin(); | |
| 733 } | |
| 734 | |
| 735 StatsCollection::const_iterator StatsCollection::end() const { | |
| 736 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 737 return list_.end(); | |
| 738 } | |
| 739 | |
| 740 size_t StatsCollection::size() const { | |
| 741 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 742 return list_.size(); | |
| 743 } | |
| 744 | |
| 745 StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { | |
| 746 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 747 RTC_DCHECK(Find(id) == nullptr); | |
| 748 StatsReport* report = new StatsReport(id); | |
| 749 list_.push_back(report); | |
| 750 return report; | |
| 751 } | |
| 752 | |
| 753 StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { | |
| 754 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 755 StatsReport* ret = Find(id); | |
| 756 return ret ? ret : InsertNew(id); | |
| 757 } | |
| 758 | |
| 759 StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { | |
| 760 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 761 RTC_DCHECK(id.get()); | |
| 762 Container::iterator it = std::find_if(list_.begin(), list_.end(), | |
| 763 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); | |
| 764 if (it != end()) { | |
| 765 StatsReport* report = new StatsReport((*it)->id()); | |
| 766 delete *it; | |
| 767 *it = report; | |
| 768 return report; | |
| 769 } | |
| 770 return InsertNew(id); | |
| 771 } | |
| 772 | |
| 773 // Looks for a report with the given |id|. If one is not found, NULL | |
| 774 // will be returned. | |
| 775 StatsReport* StatsCollection::Find(const StatsReport::Id& id) { | |
| 776 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 777 Container::iterator it = std::find_if(list_.begin(), list_.end(), | |
| 778 [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); | |
| 779 return it == list_.end() ? nullptr : *it; | |
| 780 } | |
| 781 | |
| 782 } // namespace webrtc | |
| OLD | NEW |