Delete RTC[NonStandard/Restricted]StatsMember.

Whether a metric is to be exposed to JavaScript or not is a blink
implementation detail that the WebRTC repository does not need to be
concerned with.

This CL removes unused code and paves the way for the possibility of
making the one and only RTCStatsMember class be absl::optional<>-based
in the future.

Bug: webrtc:15162
Change-Id: I578715f48b8fcc3534b72b4c700fd6567f8d553e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/304722
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40139}
This commit is contained in:
Henrik Boström 2023-05-24 17:57:12 +02:00 committed by WebRTC LUCI CQ
parent 621cb2943d
commit 0f1376529a
5 changed files with 21 additions and 290 deletions

View File

@ -206,19 +206,6 @@ class RTC_EXPORT RTCStats {
return parent_class::MembersOfThisObjectAndAncestors(0); \
}
// Certain stat members should only be exposed to the JavaScript API in
// certain circumstances as to avoid passive fingerprinting.
enum class StatExposureCriteria : uint8_t {
// The stat should always be exposed. This is the default.
kAlways,
// The stat exposes hardware capabilities and thus should has limited exposure
// to JavaScript. The requirements for exposure are written in the spec at
// https://w3c.github.io/webrtc-stats/#limiting-exposure-of-hardware-capabilities.
kHardwareCapability,
// The stat is non-standard so user agents should filter these.
kNonStandard,
};
// Interface for `RTCStats` members, which have a name and a value of a type
// defined in a subclass. Only the types listed in `Type` are supported, these
// are implemented by `RTCStatsMember<T>`. The value of a member may be
@ -254,17 +241,6 @@ class RTCStatsMemberInterface {
virtual bool is_sequence() const = 0;
virtual bool is_string() const = 0;
virtual bool is_defined() const = 0;
// Is this part of the stats spec? Used so that chromium can easily filter
// out anything unstandardized.
bool is_standardized() const {
return exposure_criteria() != StatExposureCriteria::kNonStandard;
}
// The conditions for exposing the statistic to JavaScript. Stats with
// criteria that is not kAlways has some restriction and should be filtered
// in accordance to the spec.
virtual StatExposureCriteria exposure_criteria() const {
return StatExposureCriteria::kAlways;
}
// Type and value comparator. The names are not compared. These operators are
// exposed for testing.
bool operator==(const RTCStatsMemberInterface& other) const {
@ -360,9 +336,7 @@ class RTCStatsMember : public RTCStatsMemberInterface {
protected:
bool IsEqual(const RTCStatsMemberInterface& other) const override {
if (type() != other.type() ||
is_standardized() != other.is_standardized() ||
exposure_criteria() != other.exposure_criteria())
if (type() != other.type())
return false;
const RTCStatsMember<T>& other_t =
static_cast<const RTCStatsMember<T>&>(other);
@ -411,145 +385,6 @@ WEBRTC_DECLARE_RTCSTATSMEMBER(std::vector<std::string>);
WEBRTC_DECLARE_RTCSTATSMEMBER(rtc_stats_internal::MapStringUint64);
WEBRTC_DECLARE_RTCSTATSMEMBER(rtc_stats_internal::MapStringDouble);
// For stats with restricted exposure.
template <typename T, StatExposureCriteria E>
class RTCRestrictedStatsMember : public RTCStatsMember<T> {
public:
explicit RTCRestrictedStatsMember(const char* name)
: RTCStatsMember<T>(name) {}
RTCRestrictedStatsMember(const char* name, const T& value)
: RTCStatsMember<T>(name, value) {}
RTCRestrictedStatsMember(const char* name, T&& value)
: RTCStatsMember<T>(name, std::move(value)) {}
RTCRestrictedStatsMember(const RTCRestrictedStatsMember<T, E>& other)
: RTCStatsMember<T>(other) {}
RTCRestrictedStatsMember(RTCRestrictedStatsMember<T, E>&& other)
: RTCStatsMember<T>(std::move(other)) {}
StatExposureCriteria exposure_criteria() const override { return E; }
T& operator=(const T& value) { return RTCStatsMember<T>::operator=(value); }
T& operator=(const T&& value) {
return RTCStatsMember<T>::operator=(std::move(value));
}
private:
static_assert(E != StatExposureCriteria::kAlways,
"kAlways is the default exposure criteria. Use "
"RTCStatMember<T> instead.");
};
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<bool, StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<int32_t,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<uint32_t,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<int64_t,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<uint64_t,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<double, StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::string,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<bool>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<int32_t>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<uint32_t>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<int64_t>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<uint64_t>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<double>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<std::string>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::map<std::string, uint64_t>,
StatExposureCriteria::kHardwareCapability>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCRestrictedStatsMember<std::map<std::string, double>,
StatExposureCriteria::kHardwareCapability>;
// Using inheritance just so that it's obvious from the member's declaration
// whether it's standardized or not.
template <typename T>
class RTCNonStandardStatsMember
: public RTCRestrictedStatsMember<T, StatExposureCriteria::kNonStandard> {
public:
explicit RTCNonStandardStatsMember(const char* name)
: RTCRestrictedStatsBase(name) {}
RTCNonStandardStatsMember(const char* name, const T& value)
: RTCRestrictedStatsBase(name, value) {}
RTCNonStandardStatsMember(const char* name, T&& value)
: RTCRestrictedStatsBase(name, std::move(value)) {}
RTCNonStandardStatsMember(const RTCNonStandardStatsMember<T>& other)
: RTCRestrictedStatsBase(other) {}
RTCNonStandardStatsMember(RTCNonStandardStatsMember<T>&& other)
: RTCRestrictedStatsBase(std::move(other)) {}
T& operator=(const T& value) {
return RTCRestrictedStatsMember<
T, StatExposureCriteria::kNonStandard>::operator=(value);
}
T& operator=(const T&& value) {
return RTCRestrictedStatsMember<
T, StatExposureCriteria::kNonStandard>::operator=(std::move(value));
}
private:
using RTCRestrictedStatsBase =
RTCRestrictedStatsMember<T, StatExposureCriteria::kNonStandard>;
};
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<bool>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<int32_t>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<uint32_t>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<int64_t>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<uint64_t>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<double>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::string>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<bool>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<int32_t>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<uint32_t>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<int64_t>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<uint64_t>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<double>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<std::string>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::map<std::string, uint64_t>>;
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
RTCNonStandardStatsMember<std::map<std::string, double>>;
} // namespace webrtc
#endif // API_STATS_RTC_STATS_H_

View File

@ -251,8 +251,10 @@ class RTC_EXPORT RTCIceCandidateStats : public RTCStats {
// Enum type RTCIceTcpCandidateType.
RTCStatsMember<std::string> tcp_type;
RTCNonStandardStatsMember<bool> vpn;
RTCNonStandardStatsMember<std::string> network_adapter_type;
// The following metrics are NOT exposed to JavaScript. We should consider
// standardizing or removing them.
RTCStatsMember<bool> vpn;
RTCStatsMember<std::string> network_adapter_type;
protected:
RTCIceCandidateStats(std::string id, Timestamp timestamp, bool is_remote);
@ -402,9 +404,8 @@ class RTC_EXPORT RTCInboundRtpStreamStats final
// TODO(https://crbug.com/webrtc/14177): Expose even if A/V sync is off?
RTCStatsMember<double> estimated_playout_timestamp;
// Only defined for video.
RTCRestrictedStatsMember<std::string,
StatExposureCriteria::kHardwareCapability>
decoder_implementation;
// In JavaScript, this is only exposed if HW exposure is allowed.
RTCStatsMember<std::string> decoder_implementation;
// FIR and PLI counts are only defined for |kind == "video"|.
RTCStatsMember<uint32_t> fir_count;
RTCStatsMember<uint32_t> pli_count;
@ -417,17 +418,17 @@ class RTC_EXPORT RTCInboundRtpStreamStats final
// TimingFrameInfo::ToString().
// TODO(https://crbug.com/webrtc/14586): Unship or standardize this metric.
RTCStatsMember<std::string> goog_timing_frame_info;
RTCRestrictedStatsMember<bool, StatExposureCriteria::kHardwareCapability>
power_efficient_decoder;
// Non-standard audio metrics.
RTCNonStandardStatsMember<uint64_t> jitter_buffer_flushes;
RTCNonStandardStatsMember<uint64_t> delayed_packet_outage_samples;
RTCNonStandardStatsMember<double> relative_packet_arrival_delay;
RTCNonStandardStatsMember<uint32_t> interruption_count;
RTCNonStandardStatsMember<double> total_interruption_duration;
// In JavaScript, this is only exposed if HW exposure is allowed.
RTCStatsMember<bool> power_efficient_decoder;
// The former googMinPlayoutDelayMs (in seconds).
RTCNonStandardStatsMember<double> min_playout_delay;
// The following metrics are NOT exposed to JavaScript. We should consider
// standardizing or removing them.
RTCStatsMember<uint64_t> jitter_buffer_flushes;
RTCStatsMember<uint64_t> delayed_packet_outage_samples;
RTCStatsMember<double> relative_packet_arrival_delay;
RTCStatsMember<uint32_t> interruption_count;
RTCStatsMember<double> total_interruption_duration;
RTCStatsMember<double> min_playout_delay;
};
// https://w3c.github.io/webrtc-stats/#outboundrtpstats-dict*
@ -465,19 +466,18 @@ class RTC_EXPORT RTCOutboundRtpStreamStats final
RTCStatsMember<uint32_t> quality_limitation_resolution_changes;
// https://w3c.github.io/webrtc-provisional-stats/#dom-rtcoutboundrtpstreamstats-contenttype
RTCStatsMember<std::string> content_type;
// In JavaScript, this is only exposed if HW exposure is allowed.
// Only implemented for video.
// TODO(https://crbug.com/webrtc/14178): Implement for audio as well.
RTCRestrictedStatsMember<std::string,
StatExposureCriteria::kHardwareCapability>
encoder_implementation;
RTCStatsMember<std::string> encoder_implementation;
// FIR and PLI counts are only defined for |kind == "video"|.
RTCStatsMember<uint32_t> fir_count;
RTCStatsMember<uint32_t> pli_count;
RTCStatsMember<uint32_t> nack_count;
RTCStatsMember<uint64_t> qp_sum;
RTCStatsMember<bool> active;
RTCRestrictedStatsMember<bool, StatExposureCriteria::kHardwareCapability>
power_efficient_encoder;
// In JavaScript, this is only exposed if HW exposure is allowed.
RTCStatsMember<bool> power_efficient_encoder;
RTCStatsMember<std::string> scalability_mode;
};

View File

@ -595,14 +595,10 @@ class RTCStatsReportVerifier {
verifier.TestMemberIsNonNegative<uint64_t>(inbound_stream.qp_sum);
verifier.TestMemberIsDefined(inbound_stream.decoder_implementation);
verifier.TestMemberIsDefined(inbound_stream.power_efficient_decoder);
EXPECT_EQ(inbound_stream.power_efficient_decoder.exposure_criteria(),
StatExposureCriteria::kHardwareCapability);
} else {
verifier.TestMemberIsUndefined(inbound_stream.qp_sum);
verifier.TestMemberIsUndefined(inbound_stream.decoder_implementation);
verifier.TestMemberIsUndefined(inbound_stream.power_efficient_decoder);
EXPECT_EQ(inbound_stream.power_efficient_decoder.exposure_criteria(),
StatExposureCriteria::kHardwareCapability);
}
verifier.TestMemberIsNonNegative<uint32_t>(inbound_stream.packets_received);
if (inbound_stream.kind.is_defined() && *inbound_stream.kind == "audio") {
@ -829,8 +825,6 @@ class RTCStatsReportVerifier {
verifier.MarkMemberTested(outbound_stream.content_type, true);
verifier.TestMemberIsDefined(outbound_stream.encoder_implementation);
verifier.TestMemberIsDefined(outbound_stream.power_efficient_encoder);
EXPECT_EQ(outbound_stream.power_efficient_encoder.exposure_criteria(),
StatExposureCriteria::kHardwareCapability);
// Unless an implementation-specific amount of time has passed and at
// least one frame has been encoded, undefined is reported. Because it
// is hard to tell what is the case here, we treat FPS as optional.

View File

@ -294,81 +294,4 @@ WEBRTC_DEFINE_RTCSTATSMEMBER(rtc_stats_internal::MapStringDouble,
MapToString(*value_),
MapToStringAsDouble(*value_));
// Restricted members that expose hardware capabilites.
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<bool, StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<int32_t,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<uint32_t,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<int64_t,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<uint64_t,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<double, StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::string,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<bool>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<int32_t>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<uint32_t>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<int64_t>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<uint64_t>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<double>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::vector<std::string>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::map<std::string, uint64_t>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCRestrictedStatsMember<std::map<std::string, double>,
StatExposureCriteria::kHardwareCapability>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<bool>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<int32_t>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<uint32_t>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<int64_t>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<uint64_t>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<double>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::string>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<bool>>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<int32_t>>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<uint32_t>>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<int64_t>>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<uint64_t>>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<double>>;
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT)
RTCNonStandardStatsMember<std::vector<std::string>>;
} // namespace webrtc

View File

@ -387,13 +387,6 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
std::cout << stats.ToJson() << std::endl;
}
TEST(RTCStatsTest, IsStandardized) {
RTCStatsMember<int32_t> standardized("standardized");
RTCNonStandardStatsMember<int32_t> unstandardized("unstandardized");
EXPECT_TRUE(standardized.is_standardized());
EXPECT_FALSE(unstandardized.is_standardized());
}
TEST(RTCStatsTest, IsSequence) {
RTCTestStats stats("statsId", Timestamp::Micros(42));
EXPECT_FALSE(stats.m_bool.is_sequence());
@ -504,20 +497,6 @@ TEST(RTCStatsTest, ValueToString) {
EXPECT_EQ("{bar:0.25,foo:0.5}", stats.m_map_string_double.ValueToString());
}
TEST(RTCStatsTest, RestrictedStatsTest) {
RTCStatsMember<bool> unrestricted("unrestricted");
EXPECT_EQ(unrestricted.exposure_criteria(), StatExposureCriteria::kAlways);
RTCRestrictedStatsMember<bool, StatExposureCriteria::kHardwareCapability>
restricted("restricted");
EXPECT_EQ(restricted.exposure_criteria(),
StatExposureCriteria::kHardwareCapability);
unrestricted = true;
restricted = true;
EXPECT_NE(unrestricted, restricted)
<< "These can not be equal as they have different exposure criteria.";
}
// Death tests.
// Disabled on Android because death tests misbehave on Android, see
// base/test/gtest_util.h.