Rename factory names for Frequency unit type

to follow regular function name style

Bug: webrtc:9709
Change-Id: Idb2ad7af0b185c4b696afddb4a2eab1613901f69
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168528
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30525}
This commit is contained in:
Danil Chapovalov
2020-02-14 13:52:46 +01:00
committed by Commit Bot
parent cb4d380ba5
commit 2517a47b01
5 changed files with 64 additions and 65 deletions

View File

@ -126,7 +126,7 @@ inline constexpr DataSize operator/(const DataRate rate,
return DataSize::bytes(data_rate_impl::MillibytePerSec(rate) / millihertz);
}
inline constexpr Frequency operator/(const DataRate rate, const DataSize size) {
return Frequency::millihertz(data_rate_impl::MillibytePerSec(rate) /
return Frequency::MilliHertz(data_rate_impl::MillibytePerSec(rate) /
size.bytes());
}
inline constexpr DataRate operator*(const DataSize size,

View File

@ -166,7 +166,7 @@ TEST(UnitConversionTest, DataRateAndDataSizeAndFrequency) {
const int64_t kHertz = 30;
const int64_t kBitsPerSecond = 96000;
const int64_t kBytes = 1200;
const Frequency freq_a = Frequency::hertz(kHertz);
const Frequency freq_a = Frequency::Hertz(kHertz);
const DataRate rate_b = DataRate::bps(kBitsPerSecond);
const DataSize size_c = DataSize::bytes(kBytes);
EXPECT_EQ((freq_a * size_c).bps(), kHertz * kBytes * 8);

View File

@ -26,26 +26,24 @@ namespace webrtc {
class Frequency final : public rtc_units_impl::RelativeUnit<Frequency> {
public:
template <typename T>
static constexpr Frequency MilliHertz(T value) {
static_assert(std::is_arithmetic<T>::value, "");
return FromValue(value);
}
template <typename T>
static constexpr Frequency Hertz(T value) {
static_assert(std::is_arithmetic<T>::value, "");
return FromFraction(1'000, value);
}
template <typename T>
static constexpr Frequency KiloHertz(T value) {
static_assert(std::is_arithmetic<T>::value, "");
return FromFraction(1'000'000, value);
}
Frequency() = delete;
template <int64_t hertz>
static constexpr Frequency Hertz() {
return FromFraction(1000, hertz);
}
template <typename T>
static constexpr Frequency kHz(T hertz) {
static_assert(std::is_arithmetic<T>::value, "");
return FromFraction(1000000, hertz);
}
template <typename T>
static constexpr Frequency hertz(T hertz) {
static_assert(std::is_arithmetic<T>::value, "");
return FromFraction(1000, hertz);
}
template <typename T>
static constexpr Frequency millihertz(T hertz) {
static_assert(std::is_arithmetic<T>::value, "");
return FromValue(hertz);
}
template <typename T = int64_t>
constexpr T hertz() const {
return ToFraction<1000, T>();
@ -67,7 +65,7 @@ inline constexpr Frequency operator/(int64_t nominator,
RTC_DCHECK_LE(nominator, std::numeric_limits<int64_t>::max() / kKiloPerMicro);
RTC_CHECK(interval.IsFinite());
RTC_CHECK(!interval.IsZero());
return Frequency::millihertz(nominator * kKiloPerMicro / interval.us());
return Frequency::MilliHertz(nominator * kKiloPerMicro / interval.us());
}
inline constexpr TimeDelta operator/(int64_t nominator,

View File

@ -28,29 +28,30 @@ TEST(FrequencyTest, ConstExpr) {
TEST(FrequencyTest, GetBackSameValues) {
const int64_t kValue = 31;
EXPECT_EQ(Frequency::hertz(kValue).hertz<int64_t>(), kValue);
EXPECT_EQ(Frequency::Hertz(kValue).hertz<int64_t>(), kValue);
EXPECT_EQ(Frequency::Zero().hertz<int64_t>(), 0);
}
TEST(FrequencyTest, GetDifferentPrefix) {
const int64_t kValue = 30000;
EXPECT_EQ(Frequency::millihertz(kValue).hertz<int64_t>(), kValue / 1000);
EXPECT_EQ(Frequency::hertz(kValue).millihertz(), kValue * 1000);
EXPECT_EQ(Frequency::MilliHertz(kValue).hertz<int64_t>(), kValue / 1000);
EXPECT_EQ(Frequency::Hertz(kValue).millihertz(), kValue * 1000);
EXPECT_EQ(Frequency::KiloHertz(kValue).hertz(), kValue * 1000);
}
TEST(FrequencyTest, IdentityChecks) {
const int64_t kValue = 31;
EXPECT_TRUE(Frequency::Zero().IsZero());
EXPECT_FALSE(Frequency::hertz(kValue).IsZero());
EXPECT_FALSE(Frequency::Hertz(kValue).IsZero());
EXPECT_TRUE(Frequency::PlusInfinity().IsInfinite());
EXPECT_TRUE(Frequency::MinusInfinity().IsInfinite());
EXPECT_FALSE(Frequency::Zero().IsInfinite());
EXPECT_FALSE(Frequency::hertz(kValue).IsInfinite());
EXPECT_FALSE(Frequency::Hertz(kValue).IsInfinite());
EXPECT_FALSE(Frequency::PlusInfinity().IsFinite());
EXPECT_FALSE(Frequency::MinusInfinity().IsFinite());
EXPECT_TRUE(Frequency::hertz(kValue).IsFinite());
EXPECT_TRUE(Frequency::Hertz(kValue).IsFinite());
EXPECT_TRUE(Frequency::Zero().IsFinite());
EXPECT_TRUE(Frequency::PlusInfinity().IsPlusInfinity());
@ -63,19 +64,19 @@ TEST(FrequencyTest, IdentityChecks) {
TEST(FrequencyTest, ComparisonOperators) {
const int64_t kSmall = 42;
const int64_t kLarge = 45;
const Frequency small = Frequency::hertz(kSmall);
const Frequency large = Frequency::hertz(kLarge);
const Frequency small = Frequency::Hertz(kSmall);
const Frequency large = Frequency::Hertz(kLarge);
EXPECT_EQ(Frequency::Zero(), Frequency::hertz(0));
EXPECT_EQ(Frequency::Zero(), Frequency::Hertz(0));
EXPECT_EQ(Frequency::PlusInfinity(), Frequency::PlusInfinity());
EXPECT_EQ(small, Frequency::hertz(kSmall));
EXPECT_LE(small, Frequency::hertz(kSmall));
EXPECT_GE(small, Frequency::hertz(kSmall));
EXPECT_NE(small, Frequency::hertz(kLarge));
EXPECT_LE(small, Frequency::hertz(kLarge));
EXPECT_LT(small, Frequency::hertz(kLarge));
EXPECT_GE(large, Frequency::hertz(kSmall));
EXPECT_GT(large, Frequency::hertz(kSmall));
EXPECT_EQ(small, Frequency::Hertz(kSmall));
EXPECT_LE(small, Frequency::Hertz(kSmall));
EXPECT_GE(small, Frequency::Hertz(kSmall));
EXPECT_NE(small, Frequency::Hertz(kLarge));
EXPECT_LE(small, Frequency::Hertz(kLarge));
EXPECT_LT(small, Frequency::Hertz(kLarge));
EXPECT_GE(large, Frequency::Hertz(kSmall));
EXPECT_GT(large, Frequency::Hertz(kSmall));
EXPECT_LT(Frequency::Zero(), small);
EXPECT_GT(Frequency::PlusInfinity(), large);
@ -83,11 +84,11 @@ TEST(FrequencyTest, ComparisonOperators) {
}
TEST(FrequencyTest, Clamping) {
const Frequency upper = Frequency::hertz(800);
const Frequency lower = Frequency::hertz(100);
const Frequency under = Frequency::hertz(100);
const Frequency inside = Frequency::hertz(500);
const Frequency over = Frequency::hertz(1000);
const Frequency upper = Frequency::Hertz(800);
const Frequency lower = Frequency::Hertz(100);
const Frequency under = Frequency::Hertz(100);
const Frequency inside = Frequency::Hertz(500);
const Frequency over = Frequency::Hertz(1000);
EXPECT_EQ(under.Clamped(lower, upper), lower);
EXPECT_EQ(inside.Clamped(lower, upper), inside);
EXPECT_EQ(over.Clamped(lower, upper), upper);
@ -106,40 +107,40 @@ TEST(FrequencyTest, Clamping) {
TEST(FrequencyTest, MathOperations) {
const int64_t kValueA = 457;
const int64_t kValueB = 260;
const Frequency frequency_a = Frequency::hertz(kValueA);
const Frequency frequency_b = Frequency::hertz(kValueB);
const Frequency frequency_a = Frequency::Hertz(kValueA);
const Frequency frequency_b = Frequency::Hertz(kValueB);
EXPECT_EQ((frequency_a + frequency_b).hertz<int64_t>(), kValueA + kValueB);
EXPECT_EQ((frequency_a - frequency_b).hertz<int64_t>(), kValueA - kValueB);
EXPECT_EQ((Frequency::hertz(kValueA) * kValueB).hertz<int64_t>(),
EXPECT_EQ((Frequency::Hertz(kValueA) * kValueB).hertz<int64_t>(),
kValueA * kValueB);
EXPECT_EQ((frequency_b / 10).hertz<int64_t>(), kValueB / 10);
EXPECT_EQ(frequency_b / frequency_a, static_cast<double>(kValueB) / kValueA);
Frequency mutable_frequency = Frequency::hertz(kValueA);
mutable_frequency += Frequency::hertz(kValueB);
EXPECT_EQ(mutable_frequency, Frequency::hertz(kValueA + kValueB));
mutable_frequency -= Frequency::hertz(kValueB);
EXPECT_EQ(mutable_frequency, Frequency::hertz(kValueA));
Frequency mutable_frequency = Frequency::Hertz(kValueA);
mutable_frequency += Frequency::Hertz(kValueB);
EXPECT_EQ(mutable_frequency, Frequency::Hertz(kValueA + kValueB));
mutable_frequency -= Frequency::Hertz(kValueB);
EXPECT_EQ(mutable_frequency, Frequency::Hertz(kValueA));
}
TEST(FrequencyTest, Rounding) {
const Frequency freq_high = Frequency::hertz(23.976);
const Frequency freq_high = Frequency::Hertz(23.976);
EXPECT_EQ(freq_high.hertz(), 24);
EXPECT_EQ(freq_high.RoundDownTo(Frequency::hertz(1)), Frequency::hertz(23));
EXPECT_EQ(freq_high.RoundTo(Frequency::hertz(1)), Frequency::hertz(24));
EXPECT_EQ(freq_high.RoundUpTo(Frequency::hertz(1)), Frequency::hertz(24));
EXPECT_EQ(freq_high.RoundDownTo(Frequency::Hertz(1)), Frequency::Hertz(23));
EXPECT_EQ(freq_high.RoundTo(Frequency::Hertz(1)), Frequency::Hertz(24));
EXPECT_EQ(freq_high.RoundUpTo(Frequency::Hertz(1)), Frequency::Hertz(24));
const Frequency freq_low = Frequency::hertz(23.4);
const Frequency freq_low = Frequency::Hertz(23.4);
EXPECT_EQ(freq_low.hertz(), 23);
EXPECT_EQ(freq_low.RoundDownTo(Frequency::hertz(1)), Frequency::hertz(23));
EXPECT_EQ(freq_low.RoundTo(Frequency::hertz(1)), Frequency::hertz(23));
EXPECT_EQ(freq_low.RoundUpTo(Frequency::hertz(1)), Frequency::hertz(24));
EXPECT_EQ(freq_low.RoundDownTo(Frequency::Hertz(1)), Frequency::Hertz(23));
EXPECT_EQ(freq_low.RoundTo(Frequency::Hertz(1)), Frequency::Hertz(23));
EXPECT_EQ(freq_low.RoundUpTo(Frequency::Hertz(1)), Frequency::Hertz(24));
}
TEST(FrequencyTest, InfinityOperations) {
const double kValue = 267;
const Frequency finite = Frequency::hertz(kValue);
const Frequency finite = Frequency::Hertz(kValue);
EXPECT_TRUE((Frequency::PlusInfinity() + finite).IsPlusInfinity());
EXPECT_TRUE((Frequency::PlusInfinity() - finite).IsPlusInfinity());
EXPECT_TRUE((finite + Frequency::PlusInfinity()).IsPlusInfinity());
@ -152,9 +153,9 @@ TEST(FrequencyTest, InfinityOperations) {
}
TEST(UnitConversionTest, TimeDeltaAndFrequency) {
EXPECT_EQ(1 / Frequency::hertz(50), TimeDelta::Millis(20));
EXPECT_EQ(1 / TimeDelta::Millis(20), Frequency::hertz(50));
EXPECT_EQ(Frequency::kHz(200) * TimeDelta::Millis(2), 400.0);
EXPECT_EQ(1 / Frequency::Hertz(50), TimeDelta::Millis(20));
EXPECT_EQ(1 / TimeDelta::Millis(20), Frequency::Hertz(50));
EXPECT_EQ(Frequency::KiloHertz(200) * TimeDelta::Millis(2), 400.0);
}
} // namespace test
} // namespace webrtc

View File

@ -262,7 +262,7 @@ DataRate CalculateOverheadRate(DataRate data_rate,
Frequency packet_rate = data_rate / packet_size;
// TOSO(srte): We should not need to round to nearest whole packet per second
// rate here.
return packet_rate.RoundUpTo(Frequency::hertz(1)) * overhead_per_packet;
return packet_rate.RoundUpTo(Frequency::Hertz(1)) * overhead_per_packet;
}
absl::optional<VideoCodecType> GetVideoCodecType(const RtpConfig& config) {