summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/stats
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/stats')
-rw-r--r--third_party/libwebrtc/stats/BUILD.gn4
-rw-r--r--third_party/libwebrtc/stats/attribute.cc19
-rw-r--r--third_party/libwebrtc/stats/rtc_stats_member.cc62
-rw-r--r--third_party/libwebrtc/stats/rtc_stats_report_unittest.cc7
-rw-r--r--third_party/libwebrtc/stats/rtc_stats_unittest.cc101
-rw-r--r--third_party/libwebrtc/stats/test/rtc_test_stats.h33
6 files changed, 69 insertions, 157 deletions
diff --git a/third_party/libwebrtc/stats/BUILD.gn b/third_party/libwebrtc/stats/BUILD.gn
index 8993272921..1ca584d6a2 100644
--- a/third_party/libwebrtc/stats/BUILD.gn
+++ b/third_party/libwebrtc/stats/BUILD.gn
@@ -18,7 +18,6 @@ rtc_library("rtc_stats") {
sources = [
"attribute.cc",
"rtc_stats.cc",
- "rtc_stats_member.cc",
"rtc_stats_report.cc",
"rtcstats_objects.cc",
]
@@ -46,6 +45,7 @@ rtc_library("rtc_stats_test_utils") {
"../rtc_base:checks",
"../rtc_base/system:rtc_export",
]
+ absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
if (rtc_include_tests && !build_with_chromium) {
@@ -75,5 +75,7 @@ if (rtc_include_tests && !build_with_chromium) {
"//testing/android/native_test:native_test_support",
]
}
+
+ absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
}
}
diff --git a/third_party/libwebrtc/stats/attribute.cc b/third_party/libwebrtc/stats/attribute.cc
index fab948b1bd..cf49cb2311 100644
--- a/third_party/libwebrtc/stats/attribute.cc
+++ b/third_party/libwebrtc/stats/attribute.cc
@@ -25,12 +25,12 @@ namespace {
struct VisitIsSequence {
// Any type of vector is a sequence.
template <typename T>
- bool operator()(const RTCStatsMember<std::vector<T>>* attribute) {
+ bool operator()(const absl::optional<std::vector<T>>* attribute) {
return true;
}
// Any other type is not.
template <typename T>
- bool operator()(const RTCStatsMember<T>* attribute) {
+ bool operator()(const absl::optional<T>* attribute) {
return false;
}
};
@@ -62,7 +62,7 @@ struct VisitToString {
// Vector attributes.
template <typename T>
- std::string operator()(const RTCStatsMember<std::vector<T>>* attribute) {
+ std::string operator()(const absl::optional<std::vector<T>>* attribute) {
rtc::StringBuilder sb;
sb << "[";
const char* separator = "";
@@ -84,7 +84,7 @@ struct VisitToString {
// Map attributes.
template <typename T>
std::string operator()(
- const RTCStatsMember<std::map<std::string, T>>* attribute) {
+ const absl::optional<std::map<std::string, T>>* attribute) {
rtc::StringBuilder sb;
sb << "{";
const char* separator = "";
@@ -106,21 +106,18 @@ struct VisitToString {
}
// Simple attributes.
template <typename T>
- std::string operator()(const RTCStatsMember<T>* attribute) {
+ std::string operator()(const absl::optional<T>* attribute) {
return ValueToString(attribute->value());
}
};
struct VisitIsEqual {
template <typename T>
- bool operator()(const RTCStatsMember<T>* attribute) {
+ bool operator()(const absl::optional<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>();
+ return *attribute == other.as_optional<T>();
}
const Attribute& other;
@@ -146,7 +143,7 @@ bool Attribute::is_sequence() const {
}
bool Attribute::is_string() const {
- return absl::holds_alternative<const RTCStatsMember<std::string>*>(
+ return absl::holds_alternative<const absl::optional<std::string>*>(
attribute_);
}
diff --git a/third_party/libwebrtc/stats/rtc_stats_member.cc b/third_party/libwebrtc/stats/rtc_stats_member.cc
deleted file mode 100644
index 3f91988ed0..0000000000
--- a/third_party/libwebrtc/stats/rtc_stats_member.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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 b3ac0a2db4..f11ff52e53 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 "absl/types/optional.h"
#include "api/stats/attribute.h"
#include "api/stats/rtc_stats.h"
#include "rtc_base/checks.h"
@@ -24,7 +25,7 @@ class RTCTestStats1 : public RTCStats {
RTCTestStats1(const std::string& id, Timestamp timestamp)
: RTCStats(id, timestamp) {}
- RTCStatsMember<int32_t> integer;
+ absl::optional<int32_t> integer;
};
WEBRTC_RTCSTATS_IMPL(RTCTestStats1,
@@ -39,7 +40,7 @@ class RTCTestStats2 : public RTCStats {
RTCTestStats2(const std::string& id, Timestamp timestamp)
: RTCStats(id, timestamp) {}
- RTCStatsMember<double> number;
+ absl::optional<double> number;
};
WEBRTC_RTCSTATS_IMPL(RTCTestStats2,
@@ -54,7 +55,7 @@ class RTCTestStats3 : public RTCStats {
RTCTestStats3(const std::string& id, Timestamp timestamp)
: RTCStats(id, timestamp) {}
- RTCStatsMember<std::string> string;
+ absl::optional<std::string> string;
};
WEBRTC_RTCSTATS_IMPL(RTCTestStats3,
diff --git a/third_party/libwebrtc/stats/rtc_stats_unittest.cc b/third_party/libwebrtc/stats/rtc_stats_unittest.cc
index fd90692875..555360f07f 100644
--- a/third_party/libwebrtc/stats/rtc_stats_unittest.cc
+++ b/third_party/libwebrtc/stats/rtc_stats_unittest.cc
@@ -15,6 +15,7 @@
#include <cstring>
#include <iostream>
+#include "absl/types/optional.h"
#include "rtc_base/checks.h"
#include "rtc_base/strings/json.h"
#include "stats/test/rtc_test_stats.h"
@@ -46,7 +47,7 @@ class RTCChildStats : public RTCStats {
RTCChildStats(const std::string& id, Timestamp timestamp)
: RTCStats(id, timestamp) {}
- RTCStatsMember<int32_t> child_int;
+ absl::optional<int32_t> child_int;
};
WEBRTC_RTCSTATS_IMPL(RTCChildStats,
@@ -61,7 +62,7 @@ class RTCGrandChildStats : public RTCChildStats {
RTCGrandChildStats(const std::string& id, Timestamp timestamp)
: RTCChildStats(id, timestamp) {}
- RTCStatsMember<int32_t> grandchild_int;
+ absl::optional<int32_t> grandchild_int;
};
WEBRTC_RTCSTATS_IMPL(RTCGrandChildStats,
@@ -166,7 +167,8 @@ TEST(RTCStatsTest, EqualityOperator) {
stats_with_all_values.m_map_string_double = std::map<std::string, double>();
EXPECT_NE(stats_with_all_values, empty_stats);
EXPECT_EQ(stats_with_all_values, stats_with_all_values);
- EXPECT_NE(stats_with_all_values.m_int32, stats_with_all_values.m_uint32);
+ EXPECT_NE(stats_with_all_values.GetAttribute(stats_with_all_values.m_int32),
+ stats_with_all_values.GetAttribute(stats_with_all_values.m_uint32));
RTCTestStats one_member_different[] = {
stats_with_all_values, stats_with_all_values, stats_with_all_values,
@@ -392,71 +394,42 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
TEST(RTCStatsTest, IsSequence) {
RTCTestStats stats("statsId", Timestamp::Micros(42));
- EXPECT_FALSE(stats.m_bool.is_sequence());
- EXPECT_FALSE(stats.m_int32.is_sequence());
- EXPECT_FALSE(stats.m_uint32.is_sequence());
- EXPECT_FALSE(stats.m_int64.is_sequence());
- EXPECT_FALSE(stats.m_uint64.is_sequence());
- EXPECT_FALSE(stats.m_double.is_sequence());
- EXPECT_FALSE(stats.m_string.is_sequence());
- EXPECT_TRUE(stats.m_sequence_bool.is_sequence());
- EXPECT_TRUE(stats.m_sequence_int32.is_sequence());
- EXPECT_TRUE(stats.m_sequence_uint32.is_sequence());
- EXPECT_TRUE(stats.m_sequence_int64.is_sequence());
- EXPECT_TRUE(stats.m_sequence_uint64.is_sequence());
- EXPECT_TRUE(stats.m_sequence_double.is_sequence());
- EXPECT_TRUE(stats.m_sequence_string.is_sequence());
- EXPECT_FALSE(stats.m_map_string_uint64.is_sequence());
- EXPECT_FALSE(stats.m_map_string_double.is_sequence());
-}
-
-TEST(RTCStatsTest, Type) {
- RTCTestStats stats("statsId", Timestamp::Micros(42));
- EXPECT_EQ(RTCStatsMemberInterface::kBool, stats.m_bool.type());
- EXPECT_EQ(RTCStatsMemberInterface::kInt32, stats.m_int32.type());
- EXPECT_EQ(RTCStatsMemberInterface::kUint32, stats.m_uint32.type());
- EXPECT_EQ(RTCStatsMemberInterface::kInt64, stats.m_int64.type());
- EXPECT_EQ(RTCStatsMemberInterface::kUint64, stats.m_uint64.type());
- EXPECT_EQ(RTCStatsMemberInterface::kDouble, stats.m_double.type());
- EXPECT_EQ(RTCStatsMemberInterface::kString, stats.m_string.type());
- EXPECT_EQ(RTCStatsMemberInterface::kSequenceBool,
- stats.m_sequence_bool.type());
- EXPECT_EQ(RTCStatsMemberInterface::kSequenceInt32,
- stats.m_sequence_int32.type());
- EXPECT_EQ(RTCStatsMemberInterface::kSequenceUint32,
- stats.m_sequence_uint32.type());
- EXPECT_EQ(RTCStatsMemberInterface::kSequenceInt64,
- stats.m_sequence_int64.type());
- EXPECT_EQ(RTCStatsMemberInterface::kSequenceUint64,
- stats.m_sequence_uint64.type());
- EXPECT_EQ(RTCStatsMemberInterface::kSequenceDouble,
- stats.m_sequence_double.type());
- EXPECT_EQ(RTCStatsMemberInterface::kSequenceString,
- stats.m_sequence_string.type());
- EXPECT_EQ(RTCStatsMemberInterface::kMapStringUint64,
- stats.m_map_string_uint64.type());
- EXPECT_EQ(RTCStatsMemberInterface::kMapStringDouble,
- stats.m_map_string_double.type());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_bool).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_int32).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_uint32).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_int64).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_uint64).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_double).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_string).is_sequence());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_sequence_bool).is_sequence());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_sequence_int32).is_sequence());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_sequence_uint32).is_sequence());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_sequence_int64).is_sequence());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_sequence_uint64).is_sequence());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_sequence_double).is_sequence());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_sequence_string).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_map_string_uint64).is_sequence());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_map_string_double).is_sequence());
}
TEST(RTCStatsTest, IsString) {
RTCTestStats stats("statsId", Timestamp::Micros(42));
- EXPECT_TRUE(stats.m_string.is_string());
- EXPECT_FALSE(stats.m_bool.is_string());
- EXPECT_FALSE(stats.m_int32.is_string());
- EXPECT_FALSE(stats.m_uint32.is_string());
- EXPECT_FALSE(stats.m_int64.is_string());
- EXPECT_FALSE(stats.m_uint64.is_string());
- EXPECT_FALSE(stats.m_double.is_string());
- EXPECT_FALSE(stats.m_sequence_bool.is_string());
- EXPECT_FALSE(stats.m_sequence_int32.is_string());
- EXPECT_FALSE(stats.m_sequence_uint32.is_string());
- EXPECT_FALSE(stats.m_sequence_int64.is_string());
- EXPECT_FALSE(stats.m_sequence_uint64.is_string());
- EXPECT_FALSE(stats.m_sequence_double.is_string());
- EXPECT_FALSE(stats.m_sequence_string.is_string());
- EXPECT_FALSE(stats.m_map_string_uint64.is_string());
- EXPECT_FALSE(stats.m_map_string_double.is_string());
+ EXPECT_TRUE(stats.GetAttribute(stats.m_string).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_bool).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_int32).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_uint32).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_int64).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_uint64).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_double).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_sequence_bool).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_sequence_int32).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_sequence_uint32).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_sequence_int64).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_sequence_uint64).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_sequence_double).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_sequence_string).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_map_string_uint64).is_string());
+ EXPECT_FALSE(stats.GetAttribute(stats.m_map_string_double).is_string());
}
TEST(RTCStatsTest, AttributeToString) {
diff --git a/third_party/libwebrtc/stats/test/rtc_test_stats.h b/third_party/libwebrtc/stats/test/rtc_test_stats.h
index 05c0904c02..ff1a06f97c 100644
--- a/third_party/libwebrtc/stats/test/rtc_test_stats.h
+++ b/third_party/libwebrtc/stats/test/rtc_test_stats.h
@@ -16,6 +16,7 @@
#include <string>
#include <vector>
+#include "absl/types/optional.h"
#include "api/stats/rtc_stats.h"
#include "rtc_base/system/rtc_export.h"
@@ -27,22 +28,22 @@ class RTC_EXPORT RTCTestStats : public RTCStats {
RTCTestStats(const std::string& id, Timestamp timestamp);
~RTCTestStats() override;
- RTCStatsMember<bool> m_bool;
- RTCStatsMember<int32_t> m_int32;
- RTCStatsMember<uint32_t> m_uint32;
- RTCStatsMember<int64_t> m_int64;
- RTCStatsMember<uint64_t> m_uint64;
- RTCStatsMember<double> m_double;
- RTCStatsMember<std::string> m_string;
- RTCStatsMember<std::vector<bool>> m_sequence_bool;
- RTCStatsMember<std::vector<int32_t>> m_sequence_int32;
- RTCStatsMember<std::vector<uint32_t>> m_sequence_uint32;
- RTCStatsMember<std::vector<int64_t>> m_sequence_int64;
- RTCStatsMember<std::vector<uint64_t>> m_sequence_uint64;
- RTCStatsMember<std::vector<double>> m_sequence_double;
- RTCStatsMember<std::vector<std::string>> m_sequence_string;
- RTCStatsMember<std::map<std::string, uint64_t>> m_map_string_uint64;
- RTCStatsMember<std::map<std::string, double>> m_map_string_double;
+ absl::optional<bool> m_bool;
+ absl::optional<int32_t> m_int32;
+ absl::optional<uint32_t> m_uint32;
+ absl::optional<int64_t> m_int64;
+ absl::optional<uint64_t> m_uint64;
+ absl::optional<double> m_double;
+ absl::optional<std::string> m_string;
+ absl::optional<std::vector<bool>> m_sequence_bool;
+ absl::optional<std::vector<int32_t>> m_sequence_int32;
+ absl::optional<std::vector<uint32_t>> m_sequence_uint32;
+ absl::optional<std::vector<int64_t>> m_sequence_int64;
+ absl::optional<std::vector<uint64_t>> m_sequence_uint64;
+ absl::optional<std::vector<double>> m_sequence_double;
+ absl::optional<std::vector<std::string>> m_sequence_string;
+ absl::optional<std::map<std::string, uint64_t>> m_map_string_uint64;
+ absl::optional<std::map<std::string, double>> m_map_string_double;
};
} // namespace webrtc