diff options
Diffstat (limited to '')
-rw-r--r-- | third_party/libwebrtc/stats/BUILD.gn | 3 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/attribute.cc | 172 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/g3doc/stats.md | 27 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/rtc_stats.cc | 271 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/rtc_stats_member.cc | 62 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/rtc_stats_report_unittest.cc | 22 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/rtc_stats_unittest.cc | 76 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/rtcstats_objects.cc | 733 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/test/rtc_test_stats.cc | 70 | ||||
-rw-r--r-- | third_party/libwebrtc/stats/test/rtc_test_stats.h | 2 |
10 files changed, 590 insertions, 848 deletions
diff --git a/third_party/libwebrtc/stats/BUILD.gn b/third_party/libwebrtc/stats/BUILD.gn index b2a0c20473..8993272921 100644 --- a/third_party/libwebrtc/stats/BUILD.gn +++ b/third_party/libwebrtc/stats/BUILD.gn @@ -16,7 +16,9 @@ rtc_library("rtc_stats") { visibility = [ "*" ] cflags = [] sources = [ + "attribute.cc", "rtc_stats.cc", + "rtc_stats_member.cc", "rtc_stats_report.cc", "rtcstats_objects.cc", ] @@ -27,6 +29,7 @@ rtc_library("rtc_stats") { "../rtc_base:macromagic", "../rtc_base:stringutils", ] + absl_deps = [ "//third_party/abseil-cpp/absl/types:variant" ] } rtc_library("rtc_stats_test_utils") { diff --git a/third_party/libwebrtc/stats/attribute.cc b/third_party/libwebrtc/stats/attribute.cc new file mode 100644 index 0000000000..fab948b1bd --- /dev/null +++ b/third_party/libwebrtc/stats/attribute.cc @@ -0,0 +1,172 @@ +/* + * Copyright 2024 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "api/stats/attribute.h" + +#include <string> + +#include "absl/types/variant.h" +#include "rtc_base/arraysize.h" +#include "rtc_base/checks.h" +#include "rtc_base/string_encode.h" +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { + +namespace { + +struct VisitIsSequence { + // Any type of vector is a sequence. + template <typename T> + bool operator()(const RTCStatsMember<std::vector<T>>* attribute) { + return true; + } + // Any other type is not. + template <typename T> + bool operator()(const RTCStatsMember<T>* attribute) { + return false; + } +}; + +// Converts the attribute to string in a JSON-compatible way. +struct VisitToString { + template <typename T, + typename std::enable_if_t< + std::is_same_v<T, int32_t> || std::is_same_v<T, uint32_t> || + std::is_same_v<T, bool> || std::is_same_v<T, std::string>, + bool> = true> + std::string ValueToString(const T& value) { + return rtc::ToString(value); + } + // Convert 64-bit integers to doubles before converting to string because JSON + // represents all numbers as floating points with ~15 digits of precision. + template <typename T, + typename std::enable_if_t<std::is_same_v<T, int64_t> || + std::is_same_v<T, uint64_t> || + std::is_same_v<T, double>, + bool> = true> + std::string ValueToString(const T& value) { + char buf[32]; + const int len = std::snprintf(&buf[0], arraysize(buf), "%.16g", + static_cast<double>(value)); + RTC_DCHECK_LE(len, arraysize(buf)); + return std::string(&buf[0], len); + } + + // Vector attributes. + template <typename T> + std::string operator()(const RTCStatsMember<std::vector<T>>* attribute) { + rtc::StringBuilder sb; + sb << "["; + const char* separator = ""; + constexpr bool element_is_string = std::is_same<T, std::string>::value; + for (const T& element : attribute->value()) { + sb << separator; + if (element_is_string) { + sb << "\""; + } + sb << ValueToString(element); + if (element_is_string) { + sb << "\""; + } + separator = ","; + } + sb << "]"; + return sb.Release(); + } + // Map attributes. + template <typename T> + std::string operator()( + const RTCStatsMember<std::map<std::string, T>>* attribute) { + rtc::StringBuilder sb; + sb << "{"; + const char* separator = ""; + constexpr bool element_is_string = std::is_same<T, std::string>::value; + for (const auto& pair : attribute->value()) { + sb << separator; + sb << "\"" << pair.first << "\":"; + if (element_is_string) { + sb << "\""; + } + sb << ValueToString(pair.second); + if (element_is_string) { + sb << "\""; + } + separator = ","; + } + sb << "}"; + return sb.Release(); + } + // Simple attributes. + template <typename T> + std::string operator()(const RTCStatsMember<T>* attribute) { + return ValueToString(attribute->value()); + } +}; + +struct VisitIsEqual { + template <typename T> + bool operator()(const RTCStatsMember<T>* attribute) { + if (!other.holds_alternative<T>()) { + return false; + } + absl::optional<T> attribute_as_optional = + attribute->has_value() ? absl::optional<T>(attribute->value()) + : absl::nullopt; + return attribute_as_optional == other.as_optional<T>(); + } + + const Attribute& other; +}; + +} // namespace + +const char* Attribute::name() const { + return name_; +} + +const Attribute::StatVariant& Attribute::as_variant() const { + return attribute_; +} + +bool Attribute::has_value() const { + return absl::visit([](const auto* attr) { return attr->has_value(); }, + attribute_); +} + +bool Attribute::is_sequence() const { + return absl::visit(VisitIsSequence(), attribute_); +} + +bool Attribute::is_string() const { + return absl::holds_alternative<const RTCStatsMember<std::string>*>( + attribute_); +} + +std::string Attribute::ToString() const { + if (!has_value()) { + return "null"; + } + return absl::visit(VisitToString(), attribute_); +} + +bool Attribute::operator==(const Attribute& other) const { + return absl::visit(VisitIsEqual{.other = other}, attribute_); +} + +bool Attribute::operator!=(const Attribute& other) const { + return !(*this == other); +} + +AttributeInit::AttributeInit(const char* name, + const Attribute::StatVariant& variant) + : name(name), variant(variant) {} + +} // namespace webrtc diff --git a/third_party/libwebrtc/stats/g3doc/stats.md b/third_party/libwebrtc/stats/g3doc/stats.md index 25127dc36e..7fb89340b8 100644 --- a/third_party/libwebrtc/stats/g3doc/stats.md +++ b/third_party/libwebrtc/stats/g3doc/stats.md @@ -1,18 +1,9 @@ -<!-- go/cmark -->
-<!--* freshness: {owner: 'hta' reviewed: '2022-10-01'} *-->
-
-# getStats in WebRTC
-
-The WebRTC getStats API is specified in
- https://w3c.github.io/webrtc-stats/
-and allows querying information about the current state of a RTCPeerConnection
-API and some of its member objects.
-
-## Adding new statistics to Chrome
-
-When adding a new standardized `RTCStatsMember` it is necessary to add
-it to the Chrome allowlist
- chrome/test/data/webrtc/peerconnection_getstats.js
-before landing the WebRTC change. This mechanism prevents the accidential
-addition and exposure of non-standard attributes and is not required for
-`RTCNonStandardStatsMember` which is not exposed to the web API.
\ No newline at end of file +<!-- go/cmark --> +<!--* freshness: {owner: 'hta' reviewed: '2024-01-08'} *--> + +# getStats in WebRTC + +The WebRTC getStats API is specified in + https://w3c.github.io/webrtc-stats/ +and allows querying information about the current state of a RTCPeerConnection +API and some of its member objects. diff --git a/third_party/libwebrtc/stats/rtc_stats.cc b/third_party/libwebrtc/stats/rtc_stats.cc index 25bde289c2..e7d72ee3a3 100644 --- a/third_party/libwebrtc/stats/rtc_stats.cc +++ b/third_party/libwebrtc/stats/rtc_stats.cc @@ -12,125 +12,25 @@ #include <cstdio> -#include "rtc_base/arraysize.h" -#include "rtc_base/string_encode.h" #include "rtc_base/strings/string_builder.h" namespace webrtc { -namespace { +RTCStats::RTCStats(const RTCStats& other) + : RTCStats(other.id_, other.timestamp_) {} -// Produces "[a,b,c]". Works for non-vector `RTCStatsMemberInterface::Type` -// types. -template <typename T> -std::string VectorToString(const std::vector<T>& vector) { - rtc::StringBuilder sb; - sb << "["; - const char* separator = ""; - for (const T& element : vector) { - sb << separator << rtc::ToString(element); - separator = ","; - } - sb << "]"; - return sb.Release(); -} - -// This overload is required because std::vector<bool> range loops don't -// return references but objects, causing -Wrange-loop-analysis diagnostics. -std::string VectorToString(const std::vector<bool>& vector) { - rtc::StringBuilder sb; - sb << "["; - const char* separator = ""; - for (bool element : vector) { - sb << separator << rtc::ToString(element); - separator = ","; - } - sb << "]"; - return sb.Release(); -} - -// Produces "[\"a\",\"b\",\"c\"]". Works for vectors of both const char* and -// std::string element types. -template <typename T> -std::string VectorOfStringsToString(const std::vector<T>& strings) { - rtc::StringBuilder sb; - sb << "["; - const char* separator = ""; - for (const T& element : strings) { - sb << separator << "\"" << rtc::ToString(element) << "\""; - separator = ","; - } - sb << "]"; - return sb.Release(); -} - -template <typename T> -std::string MapToString(const std::map<std::string, T>& map) { - rtc::StringBuilder sb; - sb << "{"; - const char* separator = ""; - for (const auto& element : map) { - sb << separator << rtc::ToString(element.first) << ":" - << rtc::ToString(element.second); - separator = ","; - } - sb << "}"; - return sb.Release(); -} - -template <typename T> -std::string ToStringAsDouble(const T value) { - // JSON represents numbers as floating point numbers with about 15 decimal - // digits of precision. - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%.16g", - static_cast<double>(value)); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} - -template <typename T> -std::string VectorToStringAsDouble(const std::vector<T>& vector) { - rtc::StringBuilder sb; - sb << "["; - const char* separator = ""; - for (const T& element : vector) { - sb << separator << ToStringAsDouble<T>(element); - separator = ","; - } - sb << "]"; - return sb.Release(); -} - -template <typename T> -std::string MapToStringAsDouble(const std::map<std::string, T>& map) { - rtc::StringBuilder sb; - sb << "{"; - const char* separator = ""; - for (const auto& element : map) { - sb << separator << "\"" << rtc::ToString(element.first) - << "\":" << ToStringAsDouble(element.second); - separator = ","; - } - sb << "}"; - return sb.Release(); -} - -} // namespace +RTCStats::~RTCStats() {} bool RTCStats::operator==(const RTCStats& other) const { if (type() != other.type() || id() != other.id()) return false; - std::vector<const RTCStatsMemberInterface*> members = Members(); - std::vector<const RTCStatsMemberInterface*> other_members = other.Members(); - RTC_DCHECK_EQ(members.size(), other_members.size()); - for (size_t i = 0; i < members.size(); ++i) { - const RTCStatsMemberInterface* member = members[i]; - const RTCStatsMemberInterface* other_member = other_members[i]; - RTC_DCHECK_EQ(member->type(), other_member->type()); - RTC_DCHECK_EQ(member->name(), other_member->name()); - if (*member != *other_member) + std::vector<Attribute> attributes = Attributes(); + std::vector<Attribute> other_attributes = other.Attributes(); + RTC_DCHECK_EQ(attributes.size(), other_attributes.size()); + for (size_t i = 0; i < attributes.size(); ++i) { + if (attributes[i] != other_attributes[i]) { return false; + } } return true; } @@ -148,150 +48,31 @@ std::string RTCStats::ToJson() const { << "\"," "\"timestamp\":" << timestamp_.us(); - for (const RTCStatsMemberInterface* member : Members()) { - if (member->is_defined()) { - sb << ",\"" << member->name() << "\":"; - if (member->is_string()) - sb << "\"" << member->ValueToJson() << "\""; - else - sb << member->ValueToJson(); + for (const Attribute& attribute : Attributes()) { + if (attribute.has_value()) { + sb << ",\"" << attribute.name() << "\":"; + if (attribute.holds_alternative<std::string>()) { + sb << "\""; + } + sb << attribute.ToString(); + if (attribute.holds_alternative<std::string>()) { + sb << "\""; + } } } sb << "}"; return sb.Release(); } -std::vector<const RTCStatsMemberInterface*> RTCStats::Members() const { - return MembersOfThisObjectAndAncestors(0); +std::vector<Attribute> RTCStats::Attributes() const { + return AttributesImpl(0); } -std::vector<const RTCStatsMemberInterface*> -RTCStats::MembersOfThisObjectAndAncestors(size_t additional_capacity) const { - std::vector<const RTCStatsMemberInterface*> members; - members.reserve(additional_capacity); - return members; +std::vector<Attribute> RTCStats::AttributesImpl( + size_t additional_capacity) const { + std::vector<Attribute> attributes; + attributes.reserve(additional_capacity); + return attributes; } -#define WEBRTC_DEFINE_RTCSTATSMEMBER(T, type, is_seq, is_str, to_str, to_json) \ - template <> \ - RTCStatsMemberInterface::Type RTCStatsMember<T>::StaticType() { \ - return type; \ - } \ - template <> \ - bool RTCStatsMember<T>::is_sequence() const { \ - return is_seq; \ - } \ - template <> \ - bool RTCStatsMember<T>::is_string() const { \ - return is_str; \ - } \ - template <> \ - std::string RTCStatsMember<T>::ValueToString() const { \ - RTC_DCHECK(value_.has_value()); \ - return to_str; \ - } \ - template <> \ - std::string RTCStatsMember<T>::ValueToJson() const { \ - RTC_DCHECK(value_.has_value()); \ - return to_json; \ - } \ - template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) RTCStatsMember<T> - -WEBRTC_DEFINE_RTCSTATSMEMBER(bool, - kBool, - false, - false, - rtc::ToString(*value_), - rtc::ToString(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(int32_t, - kInt32, - false, - false, - rtc::ToString(*value_), - rtc::ToString(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(uint32_t, - kUint32, - false, - false, - rtc::ToString(*value_), - rtc::ToString(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(int64_t, - kInt64, - false, - false, - rtc::ToString(*value_), - ToStringAsDouble(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(uint64_t, - kUint64, - false, - false, - rtc::ToString(*value_), - ToStringAsDouble(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(double, - kDouble, - false, - false, - rtc::ToString(*value_), - ToStringAsDouble(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::string, - kString, - false, - true, - *value_, - *value_); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<bool>, - kSequenceBool, - true, - false, - VectorToString(*value_), - VectorToString(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<int32_t>, - kSequenceInt32, - true, - false, - VectorToString(*value_), - VectorToString(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<uint32_t>, - kSequenceUint32, - true, - false, - VectorToString(*value_), - VectorToString(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<int64_t>, - kSequenceInt64, - true, - false, - VectorToString(*value_), - VectorToStringAsDouble(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<uint64_t>, - kSequenceUint64, - true, - false, - VectorToString(*value_), - VectorToStringAsDouble(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<double>, - kSequenceDouble, - true, - false, - VectorToString(*value_), - VectorToStringAsDouble(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<std::string>, - kSequenceString, - true, - false, - VectorOfStringsToString(*value_), - VectorOfStringsToString(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(rtc_stats_internal::MapStringUint64, - kMapStringUint64, - false, - false, - MapToString(*value_), - MapToStringAsDouble(*value_)); -WEBRTC_DEFINE_RTCSTATSMEMBER(rtc_stats_internal::MapStringDouble, - kMapStringDouble, - false, - false, - MapToString(*value_), - MapToStringAsDouble(*value_)); - } // namespace webrtc diff --git a/third_party/libwebrtc/stats/rtc_stats_member.cc b/third_party/libwebrtc/stats/rtc_stats_member.cc new file mode 100644 index 0000000000..3f91988ed0 --- /dev/null +++ b/third_party/libwebrtc/stats/rtc_stats_member.cc @@ -0,0 +1,62 @@ +/* + * Copyright 2023 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "api/stats/rtc_stats_member.h" + +namespace webrtc { + +#define WEBRTC_DEFINE_RTCSTATSMEMBER(T, type, is_seq, is_str) \ + template <> \ + RTCStatsMemberInterface::Type RTCStatsMember<T>::StaticType() { \ + return type; \ + } \ + template <> \ + bool RTCStatsMember<T>::is_sequence() const { \ + return is_seq; \ + } \ + template <> \ + bool RTCStatsMember<T>::is_string() const { \ + return is_str; \ + } \ + template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) RTCStatsMember<T> + +WEBRTC_DEFINE_RTCSTATSMEMBER(bool, kBool, false, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(int32_t, kInt32, false, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(uint32_t, kUint32, false, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(int64_t, kInt64, false, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(uint64_t, kUint64, false, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(double, kDouble, false, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::string, kString, false, true); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<bool>, kSequenceBool, true, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<int32_t>, kSequenceInt32, true, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<uint32_t>, + kSequenceUint32, + true, + false); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<int64_t>, kSequenceInt64, true, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<uint64_t>, + kSequenceUint64, + true, + false); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<double>, kSequenceDouble, true, false); +WEBRTC_DEFINE_RTCSTATSMEMBER(std::vector<std::string>, + kSequenceString, + true, + false); +WEBRTC_DEFINE_RTCSTATSMEMBER(rtc_stats_internal::MapStringUint64, + kMapStringUint64, + false, + false); +WEBRTC_DEFINE_RTCSTATSMEMBER(rtc_stats_internal::MapStringDouble, + kMapStringDouble, + false, + false); + +} // namespace webrtc diff --git a/third_party/libwebrtc/stats/rtc_stats_report_unittest.cc b/third_party/libwebrtc/stats/rtc_stats_report_unittest.cc index ded0c27609..b3ac0a2db4 100644 --- a/third_party/libwebrtc/stats/rtc_stats_report_unittest.cc +++ b/third_party/libwebrtc/stats/rtc_stats_report_unittest.cc @@ -10,6 +10,7 @@ #include "api/stats/rtc_stats_report.h" +#include "api/stats/attribute.h" #include "api/stats/rtc_stats.h" #include "rtc_base/checks.h" #include "test/gtest.h" @@ -21,36 +22,45 @@ class RTCTestStats1 : public RTCStats { WEBRTC_RTCSTATS_DECL(); RTCTestStats1(const std::string& id, Timestamp timestamp) - : RTCStats(id, timestamp), integer("integer") {} + : RTCStats(id, timestamp) {} RTCStatsMember<int32_t> integer; }; -WEBRTC_RTCSTATS_IMPL(RTCTestStats1, RTCStats, "test-stats-1", &integer) +WEBRTC_RTCSTATS_IMPL(RTCTestStats1, + RTCStats, + "test-stats-1", + AttributeInit("integer", &integer)) class RTCTestStats2 : public RTCStats { public: WEBRTC_RTCSTATS_DECL(); RTCTestStats2(const std::string& id, Timestamp timestamp) - : RTCStats(id, timestamp), number("number") {} + : RTCStats(id, timestamp) {} RTCStatsMember<double> number; }; -WEBRTC_RTCSTATS_IMPL(RTCTestStats2, RTCStats, "test-stats-2", &number) +WEBRTC_RTCSTATS_IMPL(RTCTestStats2, + RTCStats, + "test-stats-2", + AttributeInit("number", &number)) class RTCTestStats3 : public RTCStats { public: WEBRTC_RTCSTATS_DECL(); RTCTestStats3(const std::string& id, Timestamp timestamp) - : RTCStats(id, timestamp), string("string") {} + : RTCStats(id, timestamp) {} RTCStatsMember<std::string> string; }; -WEBRTC_RTCSTATS_IMPL(RTCTestStats3, RTCStats, "test-stats-3", &string) +WEBRTC_RTCSTATS_IMPL(RTCTestStats3, + RTCStats, + "test-stats-3", + AttributeInit("string", &string)) TEST(RTCStatsReport, AddAndGetStats) { rtc::scoped_refptr<RTCStatsReport> report = diff --git a/third_party/libwebrtc/stats/rtc_stats_unittest.cc b/third_party/libwebrtc/stats/rtc_stats_unittest.cc index 249491effd..fd90692875 100644 --- a/third_party/libwebrtc/stats/rtc_stats_unittest.cc +++ b/third_party/libwebrtc/stats/rtc_stats_unittest.cc @@ -44,19 +44,22 @@ class RTCChildStats : public RTCStats { WEBRTC_RTCSTATS_DECL(); RTCChildStats(const std::string& id, Timestamp timestamp) - : RTCStats(id, timestamp), child_int("childInt") {} + : RTCStats(id, timestamp) {} RTCStatsMember<int32_t> child_int; }; -WEBRTC_RTCSTATS_IMPL(RTCChildStats, RTCStats, "child-stats", &child_int) +WEBRTC_RTCSTATS_IMPL(RTCChildStats, + RTCStats, + "child-stats", + AttributeInit("childInt", &child_int)) class RTCGrandChildStats : public RTCChildStats { public: WEBRTC_RTCSTATS_DECL(); RTCGrandChildStats(const std::string& id, Timestamp timestamp) - : RTCChildStats(id, timestamp), grandchild_int("grandchildInt") {} + : RTCChildStats(id, timestamp) {} RTCStatsMember<int32_t> grandchild_int; }; @@ -64,16 +67,16 @@ class RTCGrandChildStats : public RTCChildStats { WEBRTC_RTCSTATS_IMPL(RTCGrandChildStats, RTCChildStats, "grandchild-stats", - &grandchild_int) + AttributeInit("grandchildInt", &grandchild_int)) -TEST(RTCStatsTest, RTCStatsAndMembers) { +TEST(RTCStatsTest, RTCStatsAndAttributes) { RTCTestStats stats("testId", Timestamp::Micros(42)); EXPECT_EQ(stats.id(), "testId"); EXPECT_EQ(stats.timestamp().us(), static_cast<int64_t>(42)); - std::vector<const RTCStatsMemberInterface*> members = stats.Members(); - EXPECT_EQ(members.size(), static_cast<size_t>(16)); - for (const RTCStatsMemberInterface* member : members) { - EXPECT_FALSE(member->is_defined()); + std::vector<Attribute> attributes = stats.Attributes(); + EXPECT_EQ(attributes.size(), static_cast<size_t>(16)); + for (const auto& attribute : attributes) { + EXPECT_FALSE(attribute.has_value()); } stats.m_bool = true; stats.m_int32 = 123; @@ -104,15 +107,15 @@ TEST(RTCStatsTest, RTCStatsAndMembers) { stats.m_sequence_bool = sequence_bool; stats.m_sequence_int32 = sequence_int32; stats.m_sequence_uint32 = sequence_uint32; - EXPECT_FALSE(stats.m_sequence_int64.is_defined()); + EXPECT_FALSE(stats.m_sequence_int64.has_value()); stats.m_sequence_int64 = sequence_int64; stats.m_sequence_uint64 = sequence_uint64; stats.m_sequence_double = sequence_double; stats.m_sequence_string = sequence_string; stats.m_map_string_uint64 = map_string_uint64; stats.m_map_string_double = map_string_double; - for (const RTCStatsMemberInterface* member : members) { - EXPECT_TRUE(member->is_defined()); + for (const auto& attribute : attributes) { + EXPECT_TRUE(attribute.has_value()); } EXPECT_EQ(*stats.m_bool, true); EXPECT_EQ(*stats.m_int32, static_cast<int32_t>(123)); @@ -217,8 +220,8 @@ TEST(RTCStatsTest, RTCStatsGrandChild) { stats.child_int = 1; stats.grandchild_int = 2; int32_t sum = 0; - for (const RTCStatsMemberInterface* member : stats.Members()) { - sum += *member->cast_to<const RTCStatsMember<int32_t>>(); + for (const auto& attribute : stats.Attributes()) { + sum += attribute.get<int32_t>(); } EXPECT_EQ(sum, static_cast<int32_t>(3)); @@ -379,8 +382,8 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) { // "mUint32" should not be part of the generated JSON object. int m_uint32; int m_uint64; - EXPECT_FALSE(stats.m_uint32.is_defined()); - EXPECT_FALSE(stats.m_uint64.is_defined()); + EXPECT_FALSE(stats.m_uint32.has_value()); + EXPECT_FALSE(stats.m_uint64.has_value()); EXPECT_FALSE(rtc::GetIntFromJsonObject(json_output, "mUint32", &m_uint32)); EXPECT_FALSE(rtc::GetIntFromJsonObject(json_output, "mUint64", &m_uint64)); @@ -456,45 +459,50 @@ TEST(RTCStatsTest, IsString) { EXPECT_FALSE(stats.m_map_string_double.is_string()); } -TEST(RTCStatsTest, ValueToString) { +TEST(RTCStatsTest, AttributeToString) { RTCTestStats stats("statsId", Timestamp::Micros(42)); stats.m_bool = true; - EXPECT_EQ("true", stats.m_bool.ValueToString()); + EXPECT_EQ("true", stats.GetAttribute(stats.m_bool).ToString()); stats.m_string = "foo"; - EXPECT_EQ("foo", stats.m_string.ValueToString()); + EXPECT_EQ("foo", stats.GetAttribute(stats.m_string).ToString()); stats.m_int32 = -32; - EXPECT_EQ("-32", stats.m_int32.ValueToString()); + EXPECT_EQ("-32", stats.GetAttribute(stats.m_int32).ToString()); stats.m_uint32 = 32; - EXPECT_EQ("32", stats.m_uint32.ValueToString()); + EXPECT_EQ("32", stats.GetAttribute(stats.m_uint32).ToString()); stats.m_int64 = -64; - EXPECT_EQ("-64", stats.m_int64.ValueToString()); + EXPECT_EQ("-64", stats.GetAttribute(stats.m_int64).ToString()); stats.m_uint64 = 64; - EXPECT_EQ("64", stats.m_uint64.ValueToString()); + EXPECT_EQ("64", stats.GetAttribute(stats.m_uint64).ToString()); stats.m_double = 0.5; - EXPECT_EQ("0.5", stats.m_double.ValueToString()); + EXPECT_EQ("0.5", stats.GetAttribute(stats.m_double).ToString()); stats.m_sequence_bool = {true, false}; - EXPECT_EQ("[true,false]", stats.m_sequence_bool.ValueToString()); + EXPECT_EQ("[true,false]", + stats.GetAttribute(stats.m_sequence_bool).ToString()); stats.m_sequence_int32 = {-32, 32}; - EXPECT_EQ("[-32,32]", stats.m_sequence_int32.ValueToString()); + EXPECT_EQ("[-32,32]", stats.GetAttribute(stats.m_sequence_int32).ToString()); stats.m_sequence_uint32 = {64, 32}; - EXPECT_EQ("[64,32]", stats.m_sequence_uint32.ValueToString()); + EXPECT_EQ("[64,32]", stats.GetAttribute(stats.m_sequence_uint32).ToString()); stats.m_sequence_int64 = {-64, 32}; - EXPECT_EQ("[-64,32]", stats.m_sequence_int64.ValueToString()); + EXPECT_EQ("[-64,32]", stats.GetAttribute(stats.m_sequence_int64).ToString()); stats.m_sequence_uint64 = {16, 32}; - EXPECT_EQ("[16,32]", stats.m_sequence_uint64.ValueToString()); + EXPECT_EQ("[16,32]", stats.GetAttribute(stats.m_sequence_uint64).ToString()); stats.m_sequence_double = {0.5, 0.25}; - EXPECT_EQ("[0.5,0.25]", stats.m_sequence_double.ValueToString()); + EXPECT_EQ("[0.5,0.25]", + stats.GetAttribute(stats.m_sequence_double).ToString()); stats.m_sequence_string = {"foo", "bar"}; - EXPECT_EQ("[\"foo\",\"bar\"]", stats.m_sequence_string.ValueToString()); + EXPECT_EQ("[\"foo\",\"bar\"]", + stats.GetAttribute(stats.m_sequence_string).ToString()); stats.m_map_string_uint64 = std::map<std::string, uint64_t>(); stats.m_map_string_uint64->emplace("foo", 32); stats.m_map_string_uint64->emplace("bar", 64); - EXPECT_EQ("{bar:64,foo:32}", stats.m_map_string_uint64.ValueToString()); + EXPECT_EQ("{\"bar\":64,\"foo\":32}", + stats.GetAttribute(stats.m_map_string_uint64).ToString()); stats.m_map_string_double = std::map<std::string, double>(); stats.m_map_string_double->emplace("foo", 0.5); stats.m_map_string_double->emplace("bar", 0.25); - EXPECT_EQ("{bar:0.25,foo:0.5}", stats.m_map_string_double.ValueToString()); + EXPECT_EQ("{\"bar\":0.25,\"foo\":0.5}", + stats.GetAttribute(stats.m_map_string_double).ToString()); } // Death tests. @@ -504,7 +512,7 @@ TEST(RTCStatsTest, ValueToString) { TEST(RTCStatsDeathTest, ValueOfUndefinedMember) { RTCTestStats stats("testId", Timestamp::Micros(0)); - EXPECT_FALSE(stats.m_int32.is_defined()); + EXPECT_FALSE(stats.m_int32.has_value()); EXPECT_DEATH(*stats.m_int32, ""); } diff --git a/third_party/libwebrtc/stats/rtcstats_objects.cc b/third_party/libwebrtc/stats/rtcstats_objects.cc index 77feaf87ba..4c58f45f02 100644 --- a/third_party/libwebrtc/stats/rtcstats_objects.cc +++ b/third_party/libwebrtc/stats/rtcstats_objects.cc @@ -12,6 +12,7 @@ #include <utility> +#include "api/stats/attribute.h" #include "api/stats/rtc_stats.h" #include "rtc_base/checks.h" @@ -19,182 +20,110 @@ namespace webrtc { // clang-format off WEBRTC_RTCSTATS_IMPL(RTCCertificateStats, RTCStats, "certificate", - &fingerprint, - &fingerprint_algorithm, - &base64_certificate, - &issuer_certificate_id) + AttributeInit("fingerprint", &fingerprint), + AttributeInit("fingerprintAlgorithm", &fingerprint_algorithm), + AttributeInit("base64Certificate", &base64_certificate), + AttributeInit("issuerCertificateId", &issuer_certificate_id)) // clang-format on RTCCertificateStats::RTCCertificateStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - fingerprint("fingerprint"), - fingerprint_algorithm("fingerprintAlgorithm"), - base64_certificate("base64Certificate"), - issuer_certificate_id("issuerCertificateId") {} - -RTCCertificateStats::RTCCertificateStats(const RTCCertificateStats& other) = - default; + : RTCStats(std::move(id), timestamp) {} + RTCCertificateStats::~RTCCertificateStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCCodecStats, RTCStats, "codec", - &transport_id, - &payload_type, - &mime_type, - &clock_rate, - &channels, - &sdp_fmtp_line) + AttributeInit("transportId", &transport_id), + AttributeInit("payloadType", &payload_type), + AttributeInit("mimeType", &mime_type), + AttributeInit("clockRate", &clock_rate), + AttributeInit("channels", &channels), + AttributeInit("sdpFmtpLine", &sdp_fmtp_line)) // clang-format on RTCCodecStats::RTCCodecStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - transport_id("transportId"), - payload_type("payloadType"), - mime_type("mimeType"), - clock_rate("clockRate"), - channels("channels"), - sdp_fmtp_line("sdpFmtpLine") {} - -RTCCodecStats::RTCCodecStats(const RTCCodecStats& other) = default; + : RTCStats(std::move(id), timestamp) {} RTCCodecStats::~RTCCodecStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCDataChannelStats, RTCStats, "data-channel", - &label, - &protocol, - &data_channel_identifier, - &state, - &messages_sent, - &bytes_sent, - &messages_received, - &bytes_received) + AttributeInit("label", &label), + AttributeInit("protocol", &protocol), + AttributeInit("dataChannelIdentifier", &data_channel_identifier), + AttributeInit("state", &state), + AttributeInit("messagesSent", &messages_sent), + AttributeInit("bytesSent", &bytes_sent), + AttributeInit("messagesReceived", &messages_received), + AttributeInit("bytesReceived", &bytes_received)) // clang-format on RTCDataChannelStats::RTCDataChannelStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - label("label"), - protocol("protocol"), - data_channel_identifier("dataChannelIdentifier"), - state("state"), - messages_sent("messagesSent"), - bytes_sent("bytesSent"), - messages_received("messagesReceived"), - bytes_received("bytesReceived") {} - -RTCDataChannelStats::RTCDataChannelStats(const RTCDataChannelStats& other) = - default; + : RTCStats(std::move(id), timestamp) {} RTCDataChannelStats::~RTCDataChannelStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCIceCandidatePairStats, RTCStats, "candidate-pair", - &transport_id, - &local_candidate_id, - &remote_candidate_id, - &state, - &priority, - &nominated, - &writable, - &packets_sent, - &packets_received, - &bytes_sent, - &bytes_received, - &total_round_trip_time, - ¤t_round_trip_time, - &available_outgoing_bitrate, - &available_incoming_bitrate, - &requests_received, - &requests_sent, - &responses_received, - &responses_sent, - &consent_requests_sent, - &packets_discarded_on_send, - &bytes_discarded_on_send, - &last_packet_received_timestamp, - &last_packet_sent_timestamp) + AttributeInit("transportId", &transport_id), + AttributeInit("localCandidateId", &local_candidate_id), + AttributeInit("remoteCandidateId", &remote_candidate_id), + AttributeInit("state", &state), + AttributeInit("priority", &priority), + AttributeInit("nominated", &nominated), + AttributeInit("writable", &writable), + AttributeInit("packetsSent", &packets_sent), + AttributeInit("packetsReceived", &packets_received), + AttributeInit("bytesSent", &bytes_sent), + AttributeInit("bytesReceived", &bytes_received), + AttributeInit("totalRoundTripTime", &total_round_trip_time), + AttributeInit("currentRoundTripTime", ¤t_round_trip_time), + AttributeInit("availableOutgoingBitrate", &available_outgoing_bitrate), + AttributeInit("availableIncomingBitrate", &available_incoming_bitrate), + AttributeInit("requestsReceived", &requests_received), + AttributeInit("requestsSent", &requests_sent), + AttributeInit("responsesReceived", &responses_received), + AttributeInit("responsesSent", &responses_sent), + AttributeInit("consentRequestsSent", &consent_requests_sent), + AttributeInit("packetsDiscardedOnSend", &packets_discarded_on_send), + AttributeInit("bytesDiscardedOnSend", &bytes_discarded_on_send), + AttributeInit("lastPacketReceivedTimestamp", + &last_packet_received_timestamp), + AttributeInit("lastPacketSentTimestamp", &last_packet_sent_timestamp)) // clang-format on RTCIceCandidatePairStats::RTCIceCandidatePairStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - transport_id("transportId"), - local_candidate_id("localCandidateId"), - remote_candidate_id("remoteCandidateId"), - state("state"), - priority("priority"), - nominated("nominated"), - writable("writable"), - packets_sent("packetsSent"), - packets_received("packetsReceived"), - bytes_sent("bytesSent"), - bytes_received("bytesReceived"), - total_round_trip_time("totalRoundTripTime"), - current_round_trip_time("currentRoundTripTime"), - available_outgoing_bitrate("availableOutgoingBitrate"), - available_incoming_bitrate("availableIncomingBitrate"), - requests_received("requestsReceived"), - requests_sent("requestsSent"), - responses_received("responsesReceived"), - responses_sent("responsesSent"), - consent_requests_sent("consentRequestsSent"), - packets_discarded_on_send("packetsDiscardedOnSend"), - bytes_discarded_on_send("bytesDiscardedOnSend"), - last_packet_received_timestamp("lastPacketReceivedTimestamp"), - last_packet_sent_timestamp("lastPacketSentTimestamp") {} - -RTCIceCandidatePairStats::RTCIceCandidatePairStats( - const RTCIceCandidatePairStats& other) = default; + : RTCStats(std::move(id), timestamp) {} RTCIceCandidatePairStats::~RTCIceCandidatePairStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCIceCandidateStats, RTCStats, "abstract-ice-candidate", - &transport_id, - &is_remote, - &network_type, - &ip, - &address, - &port, - &protocol, - &relay_protocol, - &candidate_type, - &priority, - &url, - &foundation, - &related_address, - &related_port, - &username_fragment, - &tcp_type, - &vpn, - &network_adapter_type) + AttributeInit("transportId", &transport_id), + AttributeInit("isRemote", &is_remote), + AttributeInit("networkType", &network_type), + AttributeInit("ip", &ip), + AttributeInit("address", &address), + AttributeInit("port", &port), + AttributeInit("protocol", &protocol), + AttributeInit("relayProtocol", &relay_protocol), + AttributeInit("candidateType", &candidate_type), + AttributeInit("priority", &priority), + AttributeInit("url", &url), + AttributeInit("foundation", &foundation), + AttributeInit("relatedAddress", &related_address), + AttributeInit("relatedPort", &related_port), + AttributeInit("usernameFragment", &username_fragment), + AttributeInit("tcpType", &tcp_type), + AttributeInit("vpn", &vpn), + AttributeInit("networkAdapterType", &network_adapter_type)) // clang-format on RTCIceCandidateStats::RTCIceCandidateStats(std::string id, Timestamp timestamp, bool is_remote) - : RTCStats(std::move(id), timestamp), - transport_id("transportId"), - is_remote("isRemote", is_remote), - network_type("networkType"), - ip("ip"), - address("address"), - port("port"), - protocol("protocol"), - relay_protocol("relayProtocol"), - candidate_type("candidateType"), - priority("priority"), - url("url"), - foundation("foundation"), - related_address("relatedAddress"), - related_port("relatedPort"), - username_fragment("usernameFragment"), - tcp_type("tcpType"), - vpn("vpn"), - network_adapter_type("networkAdapterType") {} - -RTCIceCandidateStats::RTCIceCandidateStats(const RTCIceCandidateStats& other) = - default; + : RTCStats(std::move(id), timestamp), is_remote(is_remote) {} RTCIceCandidateStats::~RTCIceCandidateStats() {} @@ -228,286 +157,172 @@ const char* RTCRemoteIceCandidateStats::type() const { // clang-format off WEBRTC_RTCSTATS_IMPL(RTCPeerConnectionStats, RTCStats, "peer-connection", - &data_channels_opened, - &data_channels_closed) + AttributeInit("dataChannelsOpened", &data_channels_opened), + AttributeInit("dataChannelsClosed", &data_channels_closed)) // clang-format on RTCPeerConnectionStats::RTCPeerConnectionStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - data_channels_opened("dataChannelsOpened"), - data_channels_closed("dataChannelsClosed") {} - -RTCPeerConnectionStats::RTCPeerConnectionStats( - const RTCPeerConnectionStats& other) = default; + : RTCStats(std::move(id), timestamp) {} RTCPeerConnectionStats::~RTCPeerConnectionStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCRtpStreamStats, RTCStats, "rtp", - &ssrc, - &kind, - &transport_id, - &codec_id) + AttributeInit("ssrc", &ssrc), + AttributeInit("kind", &kind), + AttributeInit("transportId", &transport_id), + AttributeInit("codecId", &codec_id)) // clang-format on RTCRtpStreamStats::RTCRtpStreamStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - ssrc("ssrc"), - kind("kind"), - transport_id("transportId"), - codec_id("codecId") {} - -RTCRtpStreamStats::RTCRtpStreamStats(const RTCRtpStreamStats& other) = default; + : RTCStats(std::move(id), timestamp) {} RTCRtpStreamStats::~RTCRtpStreamStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL( RTCReceivedRtpStreamStats, RTCRtpStreamStats, "received-rtp", - &jitter, - &packets_lost) + AttributeInit("jitter", &jitter), + AttributeInit("packetsLost", &packets_lost)) // clang-format on RTCReceivedRtpStreamStats::RTCReceivedRtpStreamStats(std::string id, Timestamp timestamp) - : RTCRtpStreamStats(std::move(id), timestamp), - jitter("jitter"), - packets_lost("packetsLost") {} - -RTCReceivedRtpStreamStats::RTCReceivedRtpStreamStats( - const RTCReceivedRtpStreamStats& other) = default; + : RTCRtpStreamStats(std::move(id), timestamp) {} RTCReceivedRtpStreamStats::~RTCReceivedRtpStreamStats() {} // clang-format off -WEBRTC_RTCSTATS_IMPL( - RTCSentRtpStreamStats, RTCRtpStreamStats, "sent-rtp", - &packets_sent, - &bytes_sent) +WEBRTC_RTCSTATS_IMPL(RTCSentRtpStreamStats, RTCRtpStreamStats, "sent-rtp", + AttributeInit("packetsSent", &packets_sent), + AttributeInit("bytesSent", &bytes_sent)) // clang-format on RTCSentRtpStreamStats::RTCSentRtpStreamStats(std::string id, Timestamp timestamp) - : RTCRtpStreamStats(std::move(id), timestamp), - packets_sent("packetsSent"), - bytes_sent("bytesSent") {} - -RTCSentRtpStreamStats::RTCSentRtpStreamStats( - const RTCSentRtpStreamStats& other) = default; + : RTCRtpStreamStats(std::move(id), timestamp) {} RTCSentRtpStreamStats::~RTCSentRtpStreamStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL( RTCInboundRtpStreamStats, RTCReceivedRtpStreamStats, "inbound-rtp", - &track_identifier, - &mid, - &remote_id, - &packets_received, - &packets_discarded, - &fec_packets_received, - &fec_bytes_received, - &fec_packets_discarded, - &fec_ssrc, - &bytes_received, - &header_bytes_received, - &retransmitted_packets_received, - &retransmitted_bytes_received, - &rtx_ssrc, - &last_packet_received_timestamp, - &jitter_buffer_delay, - &jitter_buffer_target_delay, - &jitter_buffer_minimum_delay, - &jitter_buffer_emitted_count, - &total_samples_received, - &concealed_samples, - &silent_concealed_samples, - &concealment_events, - &inserted_samples_for_deceleration, - &removed_samples_for_acceleration, - &audio_level, - &total_audio_energy, - &total_samples_duration, - &playout_id, - &frames_received, - &frame_width, - &frame_height, - &frames_per_second, - &frames_decoded, - &key_frames_decoded, - &frames_dropped, - &total_decode_time, - &total_processing_delay, - &total_assembly_time, - &frames_assembled_from_multiple_packets, - &total_inter_frame_delay, - &total_squared_inter_frame_delay, - &pause_count, - &total_pauses_duration, - &freeze_count, - &total_freezes_duration, - &content_type, - &estimated_playout_timestamp, - &decoder_implementation, - &fir_count, - &pli_count, - &nack_count, - &qp_sum, - &goog_timing_frame_info, - &power_efficient_decoder, - &jitter_buffer_flushes, - &delayed_packet_outage_samples, - &relative_packet_arrival_delay, - &interruption_count, - &total_interruption_duration, - &min_playout_delay) + AttributeInit("playoutId", &playout_id), + AttributeInit("trackIdentifier", &track_identifier), + AttributeInit("mid", &mid), + AttributeInit("remoteId", &remote_id), + AttributeInit("packetsReceived", &packets_received), + AttributeInit("packetsDiscarded", &packets_discarded), + AttributeInit("fecPacketsReceived", &fec_packets_received), + AttributeInit("fecBytesReceived", &fec_bytes_received), + AttributeInit("fecPacketsDiscarded", &fec_packets_discarded), + AttributeInit("fecSsrc", &fec_ssrc), + AttributeInit("bytesReceived", &bytes_received), + AttributeInit("headerBytesReceived", &header_bytes_received), + AttributeInit("retransmittedPacketsReceived", + &retransmitted_packets_received), + AttributeInit("retransmittedBytesReceived", &retransmitted_bytes_received), + AttributeInit("rtxSsrc", &rtx_ssrc), + AttributeInit("lastPacketReceivedTimestamp", + &last_packet_received_timestamp), + AttributeInit("jitterBufferDelay", &jitter_buffer_delay), + AttributeInit("jitterBufferTargetDelay", &jitter_buffer_target_delay), + AttributeInit("jitterBufferMinimumDelay", &jitter_buffer_minimum_delay), + AttributeInit("jitterBufferEmittedCount", &jitter_buffer_emitted_count), + AttributeInit("totalSamplesReceived", &total_samples_received), + AttributeInit("concealedSamples", &concealed_samples), + AttributeInit("silentConcealedSamples", &silent_concealed_samples), + AttributeInit("concealmentEvents", &concealment_events), + AttributeInit("insertedSamplesForDeceleration", + &inserted_samples_for_deceleration), + AttributeInit("removedSamplesForAcceleration", + &removed_samples_for_acceleration), + AttributeInit("audioLevel", &audio_level), + AttributeInit("totalAudioEnergy", &total_audio_energy), + AttributeInit("totalSamplesDuration", &total_samples_duration), + AttributeInit("framesReceived", &frames_received), + AttributeInit("frameWidth", &frame_width), + AttributeInit("frameHeight", &frame_height), + AttributeInit("framesPerSecond", &frames_per_second), + AttributeInit("framesDecoded", &frames_decoded), + AttributeInit("keyFramesDecoded", &key_frames_decoded), + AttributeInit("framesDropped", &frames_dropped), + AttributeInit("totalDecodeTime", &total_decode_time), + AttributeInit("totalProcessingDelay", &total_processing_delay), + AttributeInit("totalAssemblyTime", &total_assembly_time), + AttributeInit("framesAssembledFromMultiplePackets", + &frames_assembled_from_multiple_packets), + AttributeInit("totalInterFrameDelay", &total_inter_frame_delay), + AttributeInit("totalSquaredInterFrameDelay", + &total_squared_inter_frame_delay), + AttributeInit("pauseCount", &pause_count), + AttributeInit("totalPausesDuration", &total_pauses_duration), + AttributeInit("freezeCount", &freeze_count), + AttributeInit("totalFreezesDuration", &total_freezes_duration), + AttributeInit("contentType", &content_type), + AttributeInit("estimatedPlayoutTimestamp", &estimated_playout_timestamp), + AttributeInit("decoderImplementation", &decoder_implementation), + AttributeInit("firCount", &fir_count), + AttributeInit("pliCount", &pli_count), + AttributeInit("nackCount", &nack_count), + AttributeInit("qpSum", &qp_sum), + AttributeInit("googTimingFrameInfo", &goog_timing_frame_info), + AttributeInit("powerEfficientDecoder", &power_efficient_decoder), + AttributeInit("jitterBufferFlushes", &jitter_buffer_flushes), + AttributeInit("delayedPacketOutageSamples", &delayed_packet_outage_samples), + AttributeInit("relativePacketArrivalDelay", &relative_packet_arrival_delay), + AttributeInit("interruptionCount", &interruption_count), + AttributeInit("totalInterruptionDuration", &total_interruption_duration), + AttributeInit("minPlayoutDelay", &min_playout_delay)) // clang-format on RTCInboundRtpStreamStats::RTCInboundRtpStreamStats(std::string id, Timestamp timestamp) - : RTCReceivedRtpStreamStats(std::move(id), timestamp), - playout_id("playoutId"), - track_identifier("trackIdentifier"), - mid("mid"), - remote_id("remoteId"), - packets_received("packetsReceived"), - packets_discarded("packetsDiscarded"), - fec_packets_received("fecPacketsReceived"), - fec_bytes_received("fecBytesReceived"), - fec_packets_discarded("fecPacketsDiscarded"), - fec_ssrc("fecSsrc"), - bytes_received("bytesReceived"), - header_bytes_received("headerBytesReceived"), - retransmitted_packets_received("retransmittedPacketsReceived"), - retransmitted_bytes_received("retransmittedBytesReceived"), - rtx_ssrc("rtxSsrc"), - last_packet_received_timestamp("lastPacketReceivedTimestamp"), - jitter_buffer_delay("jitterBufferDelay"), - jitter_buffer_target_delay("jitterBufferTargetDelay"), - jitter_buffer_minimum_delay("jitterBufferMinimumDelay"), - jitter_buffer_emitted_count("jitterBufferEmittedCount"), - total_samples_received("totalSamplesReceived"), - concealed_samples("concealedSamples"), - silent_concealed_samples("silentConcealedSamples"), - concealment_events("concealmentEvents"), - inserted_samples_for_deceleration("insertedSamplesForDeceleration"), - removed_samples_for_acceleration("removedSamplesForAcceleration"), - audio_level("audioLevel"), - total_audio_energy("totalAudioEnergy"), - total_samples_duration("totalSamplesDuration"), - frames_received("framesReceived"), - frame_width("frameWidth"), - frame_height("frameHeight"), - frames_per_second("framesPerSecond"), - frames_decoded("framesDecoded"), - key_frames_decoded("keyFramesDecoded"), - frames_dropped("framesDropped"), - total_decode_time("totalDecodeTime"), - total_processing_delay("totalProcessingDelay"), - total_assembly_time("totalAssemblyTime"), - frames_assembled_from_multiple_packets( - "framesAssembledFromMultiplePackets"), - total_inter_frame_delay("totalInterFrameDelay"), - total_squared_inter_frame_delay("totalSquaredInterFrameDelay"), - pause_count("pauseCount"), - total_pauses_duration("totalPausesDuration"), - freeze_count("freezeCount"), - total_freezes_duration("totalFreezesDuration"), - content_type("contentType"), - estimated_playout_timestamp("estimatedPlayoutTimestamp"), - decoder_implementation("decoderImplementation"), - fir_count("firCount"), - pli_count("pliCount"), - nack_count("nackCount"), - qp_sum("qpSum"), - goog_timing_frame_info("googTimingFrameInfo"), - power_efficient_decoder("powerEfficientDecoder"), - jitter_buffer_flushes("jitterBufferFlushes"), - delayed_packet_outage_samples("delayedPacketOutageSamples"), - relative_packet_arrival_delay("relativePacketArrivalDelay"), - interruption_count("interruptionCount"), - total_interruption_duration("totalInterruptionDuration"), - min_playout_delay("minPlayoutDelay") {} - -RTCInboundRtpStreamStats::RTCInboundRtpStreamStats( - const RTCInboundRtpStreamStats& other) = default; + : RTCReceivedRtpStreamStats(std::move(id), timestamp) {} + RTCInboundRtpStreamStats::~RTCInboundRtpStreamStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL( RTCOutboundRtpStreamStats, RTCSentRtpStreamStats, "outbound-rtp", - &media_source_id, - &remote_id, - &mid, - &rid, - &retransmitted_packets_sent, - &header_bytes_sent, - &retransmitted_bytes_sent, - &target_bitrate, - &frames_encoded, - &key_frames_encoded, - &total_encode_time, - &total_encoded_bytes_target, - &frame_width, - &frame_height, - &frames_per_second, - &frames_sent, - &huge_frames_sent, - &total_packet_send_delay, - &quality_limitation_reason, - &quality_limitation_durations, - &quality_limitation_resolution_changes, - &content_type, - &encoder_implementation, - &fir_count, - &pli_count, - &nack_count, - &qp_sum, - &active, - &power_efficient_encoder, - &scalability_mode, - &rtx_ssrc) + AttributeInit("mediaSourceId", &media_source_id), + AttributeInit("remoteId", &remote_id), + AttributeInit("mid", &mid), + AttributeInit("rid", &rid), + AttributeInit("retransmittedPacketsSent", &retransmitted_packets_sent), + AttributeInit("headerBytesSent", &header_bytes_sent), + AttributeInit("retransmittedBytesSent", &retransmitted_bytes_sent), + AttributeInit("targetBitrate", &target_bitrate), + AttributeInit("framesEncoded", &frames_encoded), + AttributeInit("keyFramesEncoded", &key_frames_encoded), + AttributeInit("totalEncodeTime", &total_encode_time), + AttributeInit("totalEncodedBytesTarget", &total_encoded_bytes_target), + AttributeInit("frameWidth", &frame_width), + AttributeInit("frameHeight", &frame_height), + AttributeInit("framesPerSecond", &frames_per_second), + AttributeInit("framesSent", &frames_sent), + AttributeInit("hugeFramesSent", &huge_frames_sent), + AttributeInit("totalPacketSendDelay", &total_packet_send_delay), + AttributeInit("qualityLimitationReason", &quality_limitation_reason), + AttributeInit("qualityLimitationDurations", &quality_limitation_durations), + AttributeInit("qualityLimitationResolutionChanges", + &quality_limitation_resolution_changes), + AttributeInit("contentType", &content_type), + AttributeInit("encoderImplementation", &encoder_implementation), + AttributeInit("firCount", &fir_count), + AttributeInit("pliCount", &pli_count), + AttributeInit("nackCount", &nack_count), + AttributeInit("qpSum", &qp_sum), + AttributeInit("active", &active), + AttributeInit("powerEfficientEncoder", &power_efficient_encoder), + AttributeInit("scalabilityMode", &scalability_mode), + AttributeInit("rtxSsrc", &rtx_ssrc)) // clang-format on RTCOutboundRtpStreamStats::RTCOutboundRtpStreamStats(std::string id, Timestamp timestamp) - : RTCSentRtpStreamStats(std::move(id), timestamp), - media_source_id("mediaSourceId"), - remote_id("remoteId"), - mid("mid"), - rid("rid"), - retransmitted_packets_sent("retransmittedPacketsSent"), - header_bytes_sent("headerBytesSent"), - retransmitted_bytes_sent("retransmittedBytesSent"), - target_bitrate("targetBitrate"), - frames_encoded("framesEncoded"), - key_frames_encoded("keyFramesEncoded"), - total_encode_time("totalEncodeTime"), - total_encoded_bytes_target("totalEncodedBytesTarget"), - frame_width("frameWidth"), - frame_height("frameHeight"), - frames_per_second("framesPerSecond"), - frames_sent("framesSent"), - huge_frames_sent("hugeFramesSent"), - total_packet_send_delay("totalPacketSendDelay"), - quality_limitation_reason("qualityLimitationReason"), - quality_limitation_durations("qualityLimitationDurations"), - quality_limitation_resolution_changes( - "qualityLimitationResolutionChanges"), - content_type("contentType"), - encoder_implementation("encoderImplementation"), - fir_count("firCount"), - pli_count("pliCount"), - nack_count("nackCount"), - qp_sum("qpSum"), - active("active"), - power_efficient_encoder("powerEfficientEncoder"), - scalability_mode("scalabilityMode"), - rtx_ssrc("rtxSsrc") {} - -RTCOutboundRtpStreamStats::RTCOutboundRtpStreamStats( - const RTCOutboundRtpStreamStats& other) = default; + : RTCSentRtpStreamStats(std::move(id), timestamp) {} RTCOutboundRtpStreamStats::~RTCOutboundRtpStreamStats() {} @@ -515,25 +330,17 @@ RTCOutboundRtpStreamStats::~RTCOutboundRtpStreamStats() {} WEBRTC_RTCSTATS_IMPL( RTCRemoteInboundRtpStreamStats, RTCReceivedRtpStreamStats, "remote-inbound-rtp", - &local_id, - &round_trip_time, - &fraction_lost, - &total_round_trip_time, - &round_trip_time_measurements) + AttributeInit("localId", &local_id), + AttributeInit("roundTripTime", &round_trip_time), + AttributeInit("fractionLost", &fraction_lost), + AttributeInit("totalRoundTripTime", &total_round_trip_time), + AttributeInit("roundTripTimeMeasurements", &round_trip_time_measurements)) // clang-format on RTCRemoteInboundRtpStreamStats::RTCRemoteInboundRtpStreamStats( std::string id, Timestamp timestamp) - : RTCReceivedRtpStreamStats(std::move(id), timestamp), - local_id("localId"), - round_trip_time("roundTripTime"), - fraction_lost("fractionLost"), - total_round_trip_time("totalRoundTripTime"), - round_trip_time_measurements("roundTripTimeMeasurements") {} - -RTCRemoteInboundRtpStreamStats::RTCRemoteInboundRtpStreamStats( - const RTCRemoteInboundRtpStreamStats& other) = default; + : RTCReceivedRtpStreamStats(std::move(id), timestamp) {} RTCRemoteInboundRtpStreamStats::~RTCRemoteInboundRtpStreamStats() {} @@ -541,156 +348,100 @@ RTCRemoteInboundRtpStreamStats::~RTCRemoteInboundRtpStreamStats() {} WEBRTC_RTCSTATS_IMPL( RTCRemoteOutboundRtpStreamStats, RTCSentRtpStreamStats, "remote-outbound-rtp", - &local_id, - &remote_timestamp, - &reports_sent, - &round_trip_time, - &round_trip_time_measurements, - &total_round_trip_time) + AttributeInit("localId", &local_id), + AttributeInit("remoteTimestamp", &remote_timestamp), + AttributeInit("reportsSent", &reports_sent), + AttributeInit("roundTripTime", &round_trip_time), + AttributeInit("roundTripTimeMeasurements", &round_trip_time_measurements), + AttributeInit("totalRoundTripTime", &total_round_trip_time)) // clang-format on RTCRemoteOutboundRtpStreamStats::RTCRemoteOutboundRtpStreamStats( std::string id, Timestamp timestamp) - : RTCSentRtpStreamStats(std::move(id), timestamp), - local_id("localId"), - remote_timestamp("remoteTimestamp"), - reports_sent("reportsSent"), - round_trip_time("roundTripTime"), - round_trip_time_measurements("roundTripTimeMeasurements"), - total_round_trip_time("totalRoundTripTime") {} - -RTCRemoteOutboundRtpStreamStats::RTCRemoteOutboundRtpStreamStats( - const RTCRemoteOutboundRtpStreamStats& other) = default; + : RTCSentRtpStreamStats(std::move(id), timestamp) {} RTCRemoteOutboundRtpStreamStats::~RTCRemoteOutboundRtpStreamStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCMediaSourceStats, RTCStats, "parent-media-source", - &track_identifier, - &kind) + AttributeInit("trackIdentifier", &track_identifier), + AttributeInit("kind", &kind)) // clang-format on RTCMediaSourceStats::RTCMediaSourceStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - track_identifier("trackIdentifier"), - kind("kind") {} - -RTCMediaSourceStats::RTCMediaSourceStats(const RTCMediaSourceStats& other) = - default; + : RTCStats(std::move(id), timestamp) {} RTCMediaSourceStats::~RTCMediaSourceStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCAudioSourceStats, RTCMediaSourceStats, "media-source", - &audio_level, - &total_audio_energy, - &total_samples_duration, - &echo_return_loss, - &echo_return_loss_enhancement) + AttributeInit("audioLevel", &audio_level), + AttributeInit("totalAudioEnergy", &total_audio_energy), + AttributeInit("totalSamplesDuration", &total_samples_duration), + AttributeInit("echoReturnLoss", &echo_return_loss), + AttributeInit("echoReturnLossEnhancement", &echo_return_loss_enhancement)) // clang-format on RTCAudioSourceStats::RTCAudioSourceStats(std::string id, Timestamp timestamp) - : RTCMediaSourceStats(std::move(id), timestamp), - audio_level("audioLevel"), - total_audio_energy("totalAudioEnergy"), - total_samples_duration("totalSamplesDuration"), - echo_return_loss("echoReturnLoss"), - echo_return_loss_enhancement("echoReturnLossEnhancement") {} - -RTCAudioSourceStats::RTCAudioSourceStats(const RTCAudioSourceStats& other) = - default; + : RTCMediaSourceStats(std::move(id), timestamp) {} RTCAudioSourceStats::~RTCAudioSourceStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCVideoSourceStats, RTCMediaSourceStats, "media-source", - &width, - &height, - &frames, - &frames_per_second) + AttributeInit("width", &width), + AttributeInit("height", &height), + AttributeInit("frames", &frames), + AttributeInit("framesPerSecond", &frames_per_second)) // clang-format on RTCVideoSourceStats::RTCVideoSourceStats(std::string id, Timestamp timestamp) - : RTCMediaSourceStats(std::move(id), timestamp), - width("width"), - height("height"), - frames("frames"), - frames_per_second("framesPerSecond") {} - -RTCVideoSourceStats::RTCVideoSourceStats(const RTCVideoSourceStats& other) = - default; + : RTCMediaSourceStats(std::move(id), timestamp) {} RTCVideoSourceStats::~RTCVideoSourceStats() {} // clang-format off WEBRTC_RTCSTATS_IMPL(RTCTransportStats, RTCStats, "transport", - &bytes_sent, - &packets_sent, - &bytes_received, - &packets_received, - &rtcp_transport_stats_id, - &dtls_state, - &selected_candidate_pair_id, - &local_certificate_id, - &remote_certificate_id, - &tls_version, - &dtls_cipher, - &dtls_role, - &srtp_cipher, - &selected_candidate_pair_changes, - &ice_role, - &ice_local_username_fragment, - &ice_state) + AttributeInit("bytesSent", &bytes_sent), + AttributeInit("packetsSent", &packets_sent), + AttributeInit("bytesReceived", &bytes_received), + AttributeInit("packetsReceived", &packets_received), + AttributeInit("rtcpTransportStatsId", &rtcp_transport_stats_id), + AttributeInit("dtlsState", &dtls_state), + AttributeInit("selectedCandidatePairId", &selected_candidate_pair_id), + AttributeInit("localCertificateId", &local_certificate_id), + AttributeInit("remoteCertificateId", &remote_certificate_id), + AttributeInit("tlsVersion", &tls_version), + AttributeInit("dtlsCipher", &dtls_cipher), + AttributeInit("dtlsRole", &dtls_role), + AttributeInit("srtpCipher", &srtp_cipher), + AttributeInit("selectedCandidatePairChanges", + &selected_candidate_pair_changes), + AttributeInit("iceRole", &ice_role), + AttributeInit("iceLocalUsernameFragment", &ice_local_username_fragment), + AttributeInit("iceState", &ice_state)) // clang-format on RTCTransportStats::RTCTransportStats(std::string id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - bytes_sent("bytesSent"), - packets_sent("packetsSent"), - bytes_received("bytesReceived"), - packets_received("packetsReceived"), - rtcp_transport_stats_id("rtcpTransportStatsId"), - dtls_state("dtlsState"), - selected_candidate_pair_id("selectedCandidatePairId"), - local_certificate_id("localCertificateId"), - remote_certificate_id("remoteCertificateId"), - tls_version("tlsVersion"), - dtls_cipher("dtlsCipher"), - dtls_role("dtlsRole"), - srtp_cipher("srtpCipher"), - selected_candidate_pair_changes("selectedCandidatePairChanges"), - ice_role("iceRole"), - ice_local_username_fragment("iceLocalUsernameFragment"), - ice_state("iceState") {} - -RTCTransportStats::RTCTransportStats(const RTCTransportStats& other) = default; + : RTCStats(std::move(id), timestamp) {} RTCTransportStats::~RTCTransportStats() {} +// clang-format off +WEBRTC_RTCSTATS_IMPL(RTCAudioPlayoutStats, RTCStats, "media-playout", + AttributeInit("kind", &kind), + AttributeInit("synthesizedSamplesDuration", &synthesized_samples_duration), + AttributeInit("synthesizedSamplesEvents", &synthesized_samples_events), + AttributeInit("totalSamplesDuration", &total_samples_duration), + AttributeInit("totalPlayoutDelay", &total_playout_delay), + AttributeInit("totalSamplesCount", &total_samples_count)) +// clang-format on + RTCAudioPlayoutStats::RTCAudioPlayoutStats(const std::string& id, Timestamp timestamp) - : RTCStats(std::move(id), timestamp), - kind("kind", "audio"), - synthesized_samples_duration("synthesizedSamplesDuration"), - synthesized_samples_events("synthesizedSamplesEvents"), - total_samples_duration("totalSamplesDuration"), - total_playout_delay("totalPlayoutDelay"), - total_samples_count("totalSamplesCount") {} - -RTCAudioPlayoutStats::RTCAudioPlayoutStats(const RTCAudioPlayoutStats& other) = - default; + : RTCStats(std::move(id), timestamp), kind("audio") {} RTCAudioPlayoutStats::~RTCAudioPlayoutStats() {} -// clang-format off -WEBRTC_RTCSTATS_IMPL(RTCAudioPlayoutStats, RTCStats, "media-playout", - &kind, - &synthesized_samples_duration, - &synthesized_samples_events, - &total_samples_duration, - &total_playout_delay, - &total_samples_count) -// clang-format on - } // namespace webrtc diff --git a/third_party/libwebrtc/stats/test/rtc_test_stats.cc b/third_party/libwebrtc/stats/test/rtc_test_stats.cc index a83fa24178..834daeef72 100644 --- a/third_party/libwebrtc/stats/test/rtc_test_stats.cc +++ b/third_party/libwebrtc/stats/test/rtc_test_stats.cc @@ -10,6 +10,7 @@ #include "stats/test/rtc_test_stats.h" +#include "api/stats/attribute.h" #include "rtc_base/checks.h" namespace webrtc { @@ -17,60 +18,25 @@ namespace webrtc { WEBRTC_RTCSTATS_IMPL(RTCTestStats, RTCStats, "test-stats", - &m_bool, - &m_int32, - &m_uint32, - &m_int64, - &m_uint64, - &m_double, - &m_string, - &m_sequence_bool, - &m_sequence_int32, - &m_sequence_uint32, - &m_sequence_int64, - &m_sequence_uint64, - &m_sequence_double, - &m_sequence_string, - &m_map_string_uint64, - &m_map_string_double) + AttributeInit("mBool", &m_bool), + AttributeInit("mInt32", &m_int32), + AttributeInit("mUint32", &m_uint32), + AttributeInit("mInt64", &m_int64), + AttributeInit("mUint64", &m_uint64), + AttributeInit("mDouble", &m_double), + AttributeInit("mString", &m_string), + AttributeInit("mSequenceBool", &m_sequence_bool), + AttributeInit("mSequenceInt32", &m_sequence_int32), + AttributeInit("mSequenceUint32", &m_sequence_uint32), + AttributeInit("mSequenceInt64", &m_sequence_int64), + AttributeInit("mSequenceUint64", &m_sequence_uint64), + AttributeInit("mSequenceDouble", &m_sequence_double), + AttributeInit("mSequenceString", &m_sequence_string), + AttributeInit("mMapStringUint64", &m_map_string_uint64), + AttributeInit("mMapStringDouble", &m_map_string_double)) RTCTestStats::RTCTestStats(const std::string& id, Timestamp timestamp) - : RTCStats(id, timestamp), - m_bool("mBool"), - m_int32("mInt32"), - m_uint32("mUint32"), - m_int64("mInt64"), - m_uint64("mUint64"), - m_double("mDouble"), - m_string("mString"), - m_sequence_bool("mSequenceBool"), - m_sequence_int32("mSequenceInt32"), - m_sequence_uint32("mSequenceUint32"), - m_sequence_int64("mSequenceInt64"), - m_sequence_uint64("mSequenceUint64"), - m_sequence_double("mSequenceDouble"), - m_sequence_string("mSequenceString"), - m_map_string_uint64("mMapStringUint64"), - m_map_string_double("mMapStringDouble") {} - -RTCTestStats::RTCTestStats(const RTCTestStats& other) - : RTCStats(other.id(), other.timestamp()), - m_bool(other.m_bool), - m_int32(other.m_int32), - m_uint32(other.m_uint32), - m_int64(other.m_int64), - m_uint64(other.m_uint64), - m_double(other.m_double), - m_string(other.m_string), - m_sequence_bool(other.m_sequence_bool), - m_sequence_int32(other.m_sequence_int32), - m_sequence_uint32(other.m_sequence_uint32), - m_sequence_int64(other.m_sequence_int64), - m_sequence_uint64(other.m_sequence_uint64), - m_sequence_double(other.m_sequence_double), - m_sequence_string(other.m_sequence_string), - m_map_string_uint64(other.m_map_string_uint64), - m_map_string_double(other.m_map_string_double) {} + : RTCStats(id, timestamp) {} RTCTestStats::~RTCTestStats() {} diff --git a/third_party/libwebrtc/stats/test/rtc_test_stats.h b/third_party/libwebrtc/stats/test/rtc_test_stats.h index 0247c0cc01..05c0904c02 100644 --- a/third_party/libwebrtc/stats/test/rtc_test_stats.h +++ b/third_party/libwebrtc/stats/test/rtc_test_stats.h @@ -24,9 +24,7 @@ namespace webrtc { class RTC_EXPORT RTCTestStats : public RTCStats { public: WEBRTC_RTCSTATS_DECL(); - RTCTestStats(const std::string& id, Timestamp timestamp); - RTCTestStats(const RTCTestStats& other); ~RTCTestStats() override; RTCStatsMember<bool> m_bool; |