diff options
Diffstat (limited to '')
22 files changed, 2818 insertions, 0 deletions
diff --git a/third_party/libwebrtc/api/units/BUILD.gn b/third_party/libwebrtc/api/units/BUILD.gn new file mode 100644 index 0000000000..45cdcd3097 --- /dev/null +++ b/third_party/libwebrtc/api/units/BUILD.gn @@ -0,0 +1,111 @@ +# Copyright (c) 2018 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. + +import("../../webrtc.gni") + +rtc_library("data_rate") { + visibility = [ "*" ] + sources = [ + "data_rate.cc", + "data_rate.h", + ] + + deps = [ + ":data_size", + ":frequency", + ":time_delta", + "..:array_view", + "../../rtc_base:checks", + "../../rtc_base:stringutils", + "../../rtc_base/units:unit_base", + ] +} + +rtc_library("data_size") { + visibility = [ "*" ] + sources = [ + "data_size.cc", + "data_size.h", + ] + + deps = [ + "..:array_view", + "../../rtc_base:checks", + "../../rtc_base:stringutils", + "../../rtc_base/units:unit_base", + ] +} + +rtc_library("time_delta") { + visibility = [ "*" ] + sources = [ + "time_delta.cc", + "time_delta.h", + ] + + deps = [ + "..:array_view", + "../../rtc_base:checks", + "../../rtc_base:stringutils", + "../../rtc_base/units:unit_base", + ] +} + +rtc_library("frequency") { + visibility = [ "*" ] + sources = [ + "frequency.cc", + "frequency.h", + ] + + deps = [ + ":time_delta", + "..:array_view", + "../../rtc_base:checks", + "../../rtc_base:stringutils", + "../../rtc_base/units:unit_base", + ] +} + +rtc_library("timestamp") { + visibility = [ "*" ] + sources = [ + "timestamp.cc", + "timestamp.h", + ] + + deps = [ + ":time_delta", + "..:array_view", + "../../rtc_base:checks", + "../../rtc_base:stringutils", + "../../rtc_base/units:unit_base", + ] +} + +if (rtc_include_tests) { + rtc_library("units_unittests") { + testonly = true + sources = [ + "data_rate_unittest.cc", + "data_size_unittest.cc", + "frequency_unittest.cc", + "time_delta_unittest.cc", + "timestamp_unittest.cc", + ] + deps = [ + ":data_rate", + ":data_size", + ":frequency", + ":time_delta", + ":timestamp", + "../../rtc_base:logging", + "../../test:test_support", + ] + } +} diff --git a/third_party/libwebrtc/api/units/OWNERS b/third_party/libwebrtc/api/units/OWNERS new file mode 100644 index 0000000000..53e076b20b --- /dev/null +++ b/third_party/libwebrtc/api/units/OWNERS @@ -0,0 +1 @@ +srte@webrtc.org diff --git a/third_party/libwebrtc/api/units/data_rate.cc b/third_party/libwebrtc/api/units/data_rate.cc new file mode 100644 index 0000000000..f9586c5f40 --- /dev/null +++ b/third_party/libwebrtc/api/units/data_rate.cc @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018 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/units/data_rate.h" + +#include "api/array_view.h" +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { + +std::string ToString(DataRate value) { + char buf[64]; + rtc::SimpleStringBuilder sb(buf); + if (value.IsPlusInfinity()) { + sb << "+inf bps"; + } else if (value.IsMinusInfinity()) { + sb << "-inf bps"; + } else { + if (value.bps() == 0 || value.bps() % 1000 != 0) { + sb << value.bps() << " bps"; + } else { + sb << value.kbps() << " kbps"; + } + } + return sb.str(); +} +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/data_rate.h b/third_party/libwebrtc/api/units/data_rate.h new file mode 100644 index 0000000000..d813c61156 --- /dev/null +++ b/third_party/libwebrtc/api/units/data_rate.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2018 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. + */ + +#ifndef API_UNITS_DATA_RATE_H_ +#define API_UNITS_DATA_RATE_H_ + +#ifdef WEBRTC_UNIT_TEST +#include <ostream> // no-presubmit-check TODO(webrtc:8982) +#endif // WEBRTC_UNIT_TEST + +#include <limits> +#include <string> +#include <type_traits> + +#include "api/units/data_size.h" +#include "api/units/frequency.h" +#include "api/units/time_delta.h" +#include "rtc_base/checks.h" +#include "rtc_base/units/unit_base.h" // IWYU pragma: export + +namespace webrtc { +// DataRate is a class that represents a given data rate. This can be used to +// represent bandwidth, encoding bitrate, etc. The internal storage is bits per +// second (bps). +class DataRate final : public rtc_units_impl::RelativeUnit<DataRate> { + public: + template <typename T> + static constexpr DataRate BitsPerSec(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromValue(value); + } + template <typename T> + static constexpr DataRate BytesPerSec(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromFraction(8, value); + } + template <typename T> + static constexpr DataRate KilobitsPerSec(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromFraction(1000, value); + } + static constexpr DataRate Infinity() { return PlusInfinity(); } + + DataRate() = delete; + + template <typename T = int64_t> + constexpr T bps() const { + return ToValue<T>(); + } + template <typename T = int64_t> + constexpr T bytes_per_sec() const { + return ToFraction<8, T>(); + } + template <typename T = int64_t> + constexpr T kbps() const { + return ToFraction<1000, T>(); + } + constexpr int64_t bps_or(int64_t fallback_value) const { + return ToValueOr(fallback_value); + } + constexpr int64_t kbps_or(int64_t fallback_value) const { + return ToFractionOr<1000>(fallback_value); + } + + private: + // Bits per second used internally to simplify debugging by making the value + // more recognizable. + friend class rtc_units_impl::UnitBase<DataRate>; + using RelativeUnit::RelativeUnit; + static constexpr bool one_sided = true; +}; + +namespace data_rate_impl { +inline constexpr int64_t Microbits(const DataSize& size) { + constexpr int64_t kMaxBeforeConversion = + std::numeric_limits<int64_t>::max() / 8000000; + RTC_DCHECK_LE(size.bytes(), kMaxBeforeConversion) + << "size is too large to be expressed in microbits"; + return size.bytes() * 8000000; +} + +inline constexpr int64_t MillibytePerSec(const DataRate& size) { + constexpr int64_t kMaxBeforeConversion = + std::numeric_limits<int64_t>::max() / (1000 / 8); + RTC_DCHECK_LE(size.bps(), kMaxBeforeConversion) + << "rate is too large to be expressed in microbytes per second"; + return size.bps() * (1000 / 8); +} +} // namespace data_rate_impl + +inline constexpr DataRate operator/(const DataSize size, + const TimeDelta duration) { + return DataRate::BitsPerSec(data_rate_impl::Microbits(size) / duration.us()); +} +inline constexpr TimeDelta operator/(const DataSize size, const DataRate rate) { + return TimeDelta::Micros(data_rate_impl::Microbits(size) / rate.bps()); +} +inline constexpr DataSize operator*(const DataRate rate, + const TimeDelta duration) { + int64_t microbits = rate.bps() * duration.us(); + return DataSize::Bytes((microbits + 4000000) / 8000000); +} +inline constexpr DataSize operator*(const TimeDelta duration, + const DataRate rate) { + return rate * duration; +} + +inline constexpr DataSize operator/(const DataRate rate, + const Frequency frequency) { + int64_t millihertz = frequency.millihertz<int64_t>(); + // Note that the value is truncated here reather than rounded, potentially + // introducing an error of .5 bytes if rounding were expected. + 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) / + size.bytes()); +} +inline constexpr DataRate operator*(const DataSize size, + const Frequency frequency) { + RTC_DCHECK(frequency.IsZero() || + size.bytes() <= std::numeric_limits<int64_t>::max() / 8 / + frequency.millihertz<int64_t>()); + int64_t millibits_per_second = + size.bytes() * 8 * frequency.millihertz<int64_t>(); + return DataRate::BitsPerSec((millibits_per_second + 500) / 1000); +} +inline constexpr DataRate operator*(const Frequency frequency, + const DataSize size) { + return size * frequency; +} + +std::string ToString(DataRate value); +inline std::string ToLogString(DataRate value) { + return ToString(value); +} + +#ifdef WEBRTC_UNIT_TEST +inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) + std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) + DataRate value) { + return stream << ToString(value); +} +#endif // WEBRTC_UNIT_TEST + +} // namespace webrtc + +#endif // API_UNITS_DATA_RATE_H_ diff --git a/third_party/libwebrtc/api/units/data_rate_gn/moz.build b/third_party/libwebrtc/api/units/data_rate_gn/moz.build new file mode 100644 index 0000000000..de76b8e11c --- /dev/null +++ b/third_party/libwebrtc/api/units/data_rate_gn/moz.build @@ -0,0 +1,221 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1" +DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True +DEFINES["RTC_ENABLE_VP9"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_LIBRARY_IMPL"] = True +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "!/third_party/libwebrtc/gen", + "/ipc/chromium/src", + "/third_party/libwebrtc/", + "/third_party/libwebrtc/third_party/abseil-cpp/", + "/tools/profiler/public" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/api/units/data_rate.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION_ROLL"] = "r22_1" + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_GNU_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_LIBCPP_HAS_NO_ALIGNED_ALLOCATION"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES"] = "0" + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_AURA"] = "1" + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_UDEV"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "2" + DEFINES["UNICODE"] = True + DEFINES["USE_AURA"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP" + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_HAS_NODISCARD"] = True + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "mips32": + + DEFINES["MIPS32_LE"] = True + DEFINES["MIPS_FPU_LE"] = True + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["CPU_ARCH"] == "x86_64": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0" + +if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_X11"] = "1" + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Android": + + OS_LIBS += [ + "android_support", + "unwind" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + + OS_LIBS += [ + "android_support" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +Library("data_rate_gn") diff --git a/third_party/libwebrtc/api/units/data_rate_unittest.cc b/third_party/libwebrtc/api/units/data_rate_unittest.cc new file mode 100644 index 0000000000..f77b3702d4 --- /dev/null +++ b/third_party/libwebrtc/api/units/data_rate_unittest.cc @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2018 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/units/data_rate.h" + +#include "rtc_base/logging.h" +#include "test/gtest.h" + +namespace webrtc { +namespace test { + +TEST(DataRateTest, CompilesWithChecksAndLogs) { + DataRate a = DataRate::KilobitsPerSec(300); + DataRate b = DataRate::KilobitsPerSec(210); + RTC_CHECK_GT(a, b); + RTC_LOG(LS_INFO) << a; +} + +TEST(DataRateTest, ConstExpr) { + constexpr int64_t kValue = 12345; + constexpr DataRate kDataRateZero = DataRate::Zero(); + constexpr DataRate kDataRateInf = DataRate::Infinity(); + static_assert(kDataRateZero.IsZero(), ""); + static_assert(kDataRateInf.IsInfinite(), ""); + static_assert(kDataRateInf.bps_or(-1) == -1, ""); + static_assert(kDataRateInf > kDataRateZero, ""); + + constexpr DataRate kDataRateBps = DataRate::BitsPerSec(kValue); + constexpr DataRate kDataRateKbps = DataRate::KilobitsPerSec(kValue); + static_assert(kDataRateBps.bps<double>() == kValue, ""); + static_assert(kDataRateBps.bps_or(0) == kValue, ""); + static_assert(kDataRateKbps.kbps_or(0) == kValue, ""); +} + +TEST(DataRateTest, GetBackSameValues) { + const int64_t kValue = 123 * 8; + EXPECT_EQ(DataRate::BitsPerSec(kValue).bps(), kValue); + EXPECT_EQ(DataRate::KilobitsPerSec(kValue).kbps(), kValue); +} + +TEST(DataRateTest, GetDifferentPrefix) { + const int64_t kValue = 123 * 8000; + EXPECT_EQ(DataRate::BitsPerSec(kValue).kbps(), kValue / 1000); +} + +TEST(DataRateTest, IdentityChecks) { + const int64_t kValue = 3000; + EXPECT_TRUE(DataRate::Zero().IsZero()); + EXPECT_FALSE(DataRate::BitsPerSec(kValue).IsZero()); + + EXPECT_TRUE(DataRate::Infinity().IsInfinite()); + EXPECT_FALSE(DataRate::Zero().IsInfinite()); + EXPECT_FALSE(DataRate::BitsPerSec(kValue).IsInfinite()); + + EXPECT_FALSE(DataRate::Infinity().IsFinite()); + EXPECT_TRUE(DataRate::BitsPerSec(kValue).IsFinite()); + EXPECT_TRUE(DataRate::Zero().IsFinite()); +} + +TEST(DataRateTest, ComparisonOperators) { + const int64_t kSmall = 450; + const int64_t kLarge = 451; + const DataRate small = DataRate::BitsPerSec(kSmall); + const DataRate large = DataRate::BitsPerSec(kLarge); + + EXPECT_EQ(DataRate::Zero(), DataRate::BitsPerSec(0)); + EXPECT_EQ(DataRate::Infinity(), DataRate::Infinity()); + EXPECT_EQ(small, small); + EXPECT_LE(small, small); + EXPECT_GE(small, small); + EXPECT_NE(small, large); + EXPECT_LE(small, large); + EXPECT_LT(small, large); + EXPECT_GE(large, small); + EXPECT_GT(large, small); + EXPECT_LT(DataRate::Zero(), small); + EXPECT_GT(DataRate::Infinity(), large); +} + +TEST(DataRateTest, ConvertsToAndFromDouble) { + const int64_t kValue = 128; + const double kDoubleValue = static_cast<double>(kValue); + const double kDoubleKbps = kValue * 1e-3; + const double kFloatKbps = static_cast<float>(kDoubleKbps); + + EXPECT_EQ(DataRate::BitsPerSec(kValue).bps<double>(), kDoubleValue); + EXPECT_EQ(DataRate::BitsPerSec(kValue).kbps<double>(), kDoubleKbps); + EXPECT_EQ(DataRate::BitsPerSec(kValue).kbps<float>(), kFloatKbps); + EXPECT_EQ(DataRate::BitsPerSec(kDoubleValue).bps(), kValue); + EXPECT_EQ(DataRate::KilobitsPerSec(kDoubleKbps).bps(), kValue); + + const double kInfinity = std::numeric_limits<double>::infinity(); + EXPECT_EQ(DataRate::Infinity().bps<double>(), kInfinity); + EXPECT_TRUE(DataRate::BitsPerSec(kInfinity).IsInfinite()); + EXPECT_TRUE(DataRate::KilobitsPerSec(kInfinity).IsInfinite()); +} +TEST(DataRateTest, Clamping) { + const DataRate upper = DataRate::KilobitsPerSec(800); + const DataRate lower = DataRate::KilobitsPerSec(100); + const DataRate under = DataRate::KilobitsPerSec(100); + const DataRate inside = DataRate::KilobitsPerSec(500); + const DataRate over = DataRate::KilobitsPerSec(1000); + EXPECT_EQ(under.Clamped(lower, upper), lower); + EXPECT_EQ(inside.Clamped(lower, upper), inside); + EXPECT_EQ(over.Clamped(lower, upper), upper); + + DataRate mutable_rate = lower; + mutable_rate.Clamp(lower, upper); + EXPECT_EQ(mutable_rate, lower); + mutable_rate = inside; + mutable_rate.Clamp(lower, upper); + EXPECT_EQ(mutable_rate, inside); + mutable_rate = over; + mutable_rate.Clamp(lower, upper); + EXPECT_EQ(mutable_rate, upper); +} + +TEST(DataRateTest, MathOperations) { + const int64_t kValueA = 450; + const int64_t kValueB = 267; + const DataRate rate_a = DataRate::BitsPerSec(kValueA); + const DataRate rate_b = DataRate::BitsPerSec(kValueB); + const int32_t kInt32Value = 123; + const double kFloatValue = 123.0; + + EXPECT_EQ((rate_a + rate_b).bps(), kValueA + kValueB); + EXPECT_EQ((rate_a - rate_b).bps(), kValueA - kValueB); + + EXPECT_EQ((rate_a * kValueB).bps(), kValueA * kValueB); + EXPECT_EQ((rate_a * kInt32Value).bps(), kValueA * kInt32Value); + EXPECT_EQ((rate_a * kFloatValue).bps(), kValueA * kFloatValue); + + EXPECT_EQ(rate_a / rate_b, static_cast<double>(kValueA) / kValueB); + + EXPECT_EQ((rate_a / 10).bps(), kValueA / 10); + EXPECT_NEAR((rate_a / 0.5).bps(), kValueA * 2, 1); + + DataRate mutable_rate = DataRate::BitsPerSec(kValueA); + mutable_rate += rate_b; + EXPECT_EQ(mutable_rate.bps(), kValueA + kValueB); + mutable_rate -= rate_a; + EXPECT_EQ(mutable_rate.bps(), kValueB); +} + +TEST(UnitConversionTest, DataRateAndDataSizeAndTimeDelta) { + const int64_t kSeconds = 5; + const int64_t kBitsPerSecond = 440; + const int64_t kBytes = 44000; + const TimeDelta delta_a = TimeDelta::Seconds(kSeconds); + const DataRate rate_b = DataRate::BitsPerSec(kBitsPerSecond); + const DataSize size_c = DataSize::Bytes(kBytes); + EXPECT_EQ((delta_a * rate_b).bytes(), kSeconds * kBitsPerSecond / 8); + EXPECT_EQ((rate_b * delta_a).bytes(), kSeconds * kBitsPerSecond / 8); + EXPECT_EQ((size_c / delta_a).bps(), kBytes * 8 / kSeconds); + EXPECT_EQ((size_c / rate_b).seconds(), kBytes * 8 / kBitsPerSecond); +} + +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 DataRate rate_b = DataRate::BitsPerSec(kBitsPerSecond); + const DataSize size_c = DataSize::Bytes(kBytes); + EXPECT_EQ((freq_a * size_c).bps(), kHertz * kBytes * 8); + EXPECT_EQ((size_c * freq_a).bps(), kHertz * kBytes * 8); + EXPECT_EQ((rate_b / size_c).hertz<int64_t>(), kBitsPerSecond / kBytes / 8); + EXPECT_EQ((rate_b / freq_a).bytes(), kBitsPerSecond / kHertz / 8); +} + +TEST(UnitConversionDeathTest, DivisionFailsOnLargeSize) { + // Note that the failure is expected since the current implementation is + // implementated in a way that does not support division of large sizes. If + // the implementation is changed, this test can safely be removed. + const int64_t kJustSmallEnoughForDivision = + std::numeric_limits<int64_t>::max() / 8000000; + const DataSize large_size = DataSize::Bytes(kJustSmallEnoughForDivision); + const DataRate data_rate = DataRate::KilobitsPerSec(100); + const TimeDelta time_delta = TimeDelta::Millis(100); + EXPECT_TRUE((large_size / data_rate).IsFinite()); + EXPECT_TRUE((large_size / time_delta).IsFinite()); +#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) && RTC_DCHECK_IS_ON + const int64_t kToolargeForDivision = kJustSmallEnoughForDivision + 1; + const DataSize too_large_size = DataSize::Bytes(kToolargeForDivision); + EXPECT_DEATH(too_large_size / data_rate, ""); + EXPECT_DEATH(too_large_size / time_delta, ""); +#endif // GTEST_HAS_DEATH_TEST && !!defined(WEBRTC_ANDROID) && RTC_DCHECK_IS_ON +} +} // namespace test +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/data_size.cc b/third_party/libwebrtc/api/units/data_size.cc new file mode 100644 index 0000000000..45487dfd83 --- /dev/null +++ b/third_party/libwebrtc/api/units/data_size.cc @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018 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/units/data_size.h" + +#include "api/array_view.h" +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { + +std::string ToString(DataSize value) { + char buf[64]; + rtc::SimpleStringBuilder sb(buf); + if (value.IsPlusInfinity()) { + sb << "+inf bytes"; + } else if (value.IsMinusInfinity()) { + sb << "-inf bytes"; + } else { + sb << value.bytes() << " bytes"; + } + return sb.str(); +} +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/data_size.h b/third_party/libwebrtc/api/units/data_size.h new file mode 100644 index 0000000000..9df6434fb9 --- /dev/null +++ b/third_party/libwebrtc/api/units/data_size.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018 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. + */ + +#ifndef API_UNITS_DATA_SIZE_H_ +#define API_UNITS_DATA_SIZE_H_ + +#ifdef WEBRTC_UNIT_TEST +#include <ostream> // no-presubmit-check TODO(webrtc:8982) +#endif // WEBRTC_UNIT_TEST + +#include <string> +#include <type_traits> + +#include "rtc_base/units/unit_base.h" // IWYU pragma: export + +namespace webrtc { +// DataSize is a class represeting a count of bytes. +class DataSize final : public rtc_units_impl::RelativeUnit<DataSize> { + public: + template <typename T> + static constexpr DataSize Bytes(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromValue(value); + } + static constexpr DataSize Infinity() { return PlusInfinity(); } + + DataSize() = delete; + + template <typename T = int64_t> + constexpr T bytes() const { + return ToValue<T>(); + } + + constexpr int64_t bytes_or(int64_t fallback_value) const { + return ToValueOr(fallback_value); + } + + private: + friend class rtc_units_impl::UnitBase<DataSize>; + using RelativeUnit::RelativeUnit; + static constexpr bool one_sided = true; +}; + +std::string ToString(DataSize value); +inline std::string ToLogString(DataSize value) { + return ToString(value); +} + +#ifdef WEBRTC_UNIT_TEST +inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) + std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) + DataSize value) { + return stream << ToString(value); +} +#endif // WEBRTC_UNIT_TEST + +} // namespace webrtc + +#endif // API_UNITS_DATA_SIZE_H_ diff --git a/third_party/libwebrtc/api/units/data_size_gn/moz.build b/third_party/libwebrtc/api/units/data_size_gn/moz.build new file mode 100644 index 0000000000..dc54ce4f15 --- /dev/null +++ b/third_party/libwebrtc/api/units/data_size_gn/moz.build @@ -0,0 +1,221 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1" +DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True +DEFINES["RTC_ENABLE_VP9"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_LIBRARY_IMPL"] = True +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "!/third_party/libwebrtc/gen", + "/ipc/chromium/src", + "/third_party/libwebrtc/", + "/third_party/libwebrtc/third_party/abseil-cpp/", + "/tools/profiler/public" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/api/units/data_size.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION_ROLL"] = "r22_1" + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_GNU_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_LIBCPP_HAS_NO_ALIGNED_ALLOCATION"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES"] = "0" + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_AURA"] = "1" + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_UDEV"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "2" + DEFINES["UNICODE"] = True + DEFINES["USE_AURA"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP" + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_HAS_NODISCARD"] = True + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "mips32": + + DEFINES["MIPS32_LE"] = True + DEFINES["MIPS_FPU_LE"] = True + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["CPU_ARCH"] == "x86_64": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0" + +if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_X11"] = "1" + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Android": + + OS_LIBS += [ + "android_support", + "unwind" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + + OS_LIBS += [ + "android_support" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +Library("data_size_gn") diff --git a/third_party/libwebrtc/api/units/data_size_unittest.cc b/third_party/libwebrtc/api/units/data_size_unittest.cc new file mode 100644 index 0000000000..eb8d98c1f0 --- /dev/null +++ b/third_party/libwebrtc/api/units/data_size_unittest.cc @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2018 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/units/data_size.h" + +#include <limits> + +#include "test/gtest.h" + +namespace webrtc { +namespace test { + +TEST(DataSizeTest, ConstExpr) { + constexpr int64_t kValue = 12345; + constexpr DataSize kDataSizeZero = DataSize::Zero(); + constexpr DataSize kDataSizeInf = DataSize::Infinity(); + static_assert(kDataSizeZero.IsZero(), ""); + static_assert(kDataSizeInf.IsInfinite(), ""); + static_assert(kDataSizeInf.bytes_or(-1) == -1, ""); + static_assert(kDataSizeInf > kDataSizeZero, ""); + + constexpr DataSize kDataSize = DataSize::Bytes(kValue); + static_assert(kDataSize.bytes_or(-1) == kValue, ""); + + EXPECT_EQ(kDataSize.bytes(), kValue); +} + +TEST(DataSizeTest, GetBackSameValues) { + const int64_t kValue = 123 * 8; + EXPECT_EQ(DataSize::Bytes(kValue).bytes(), kValue); +} + +TEST(DataSizeTest, IdentityChecks) { + const int64_t kValue = 3000; + EXPECT_TRUE(DataSize::Zero().IsZero()); + EXPECT_FALSE(DataSize::Bytes(kValue).IsZero()); + + EXPECT_TRUE(DataSize::Infinity().IsInfinite()); + EXPECT_FALSE(DataSize::Zero().IsInfinite()); + EXPECT_FALSE(DataSize::Bytes(kValue).IsInfinite()); + + EXPECT_FALSE(DataSize::Infinity().IsFinite()); + EXPECT_TRUE(DataSize::Bytes(kValue).IsFinite()); + EXPECT_TRUE(DataSize::Zero().IsFinite()); +} + +TEST(DataSizeTest, ComparisonOperators) { + const int64_t kSmall = 450; + const int64_t kLarge = 451; + const DataSize small = DataSize::Bytes(kSmall); + const DataSize large = DataSize::Bytes(kLarge); + + EXPECT_EQ(DataSize::Zero(), DataSize::Bytes(0)); + EXPECT_EQ(DataSize::Infinity(), DataSize::Infinity()); + EXPECT_EQ(small, small); + EXPECT_LE(small, small); + EXPECT_GE(small, small); + EXPECT_NE(small, large); + EXPECT_LE(small, large); + EXPECT_LT(small, large); + EXPECT_GE(large, small); + EXPECT_GT(large, small); + EXPECT_LT(DataSize::Zero(), small); + EXPECT_GT(DataSize::Infinity(), large); +} + +TEST(DataSizeTest, ConvertsToAndFromDouble) { + const int64_t kValue = 128; + const double kDoubleValue = static_cast<double>(kValue); + + EXPECT_EQ(DataSize::Bytes(kValue).bytes<double>(), kDoubleValue); + EXPECT_EQ(DataSize::Bytes(kDoubleValue).bytes(), kValue); + + const double kInfinity = std::numeric_limits<double>::infinity(); + EXPECT_EQ(DataSize::Infinity().bytes<double>(), kInfinity); + EXPECT_TRUE(DataSize::Bytes(kInfinity).IsInfinite()); +} + +TEST(DataSizeTest, MathOperations) { + const int64_t kValueA = 450; + const int64_t kValueB = 267; + const DataSize size_a = DataSize::Bytes(kValueA); + const DataSize size_b = DataSize::Bytes(kValueB); + EXPECT_EQ((size_a + size_b).bytes(), kValueA + kValueB); + EXPECT_EQ((size_a - size_b).bytes(), kValueA - kValueB); + + const int32_t kInt32Value = 123; + const double kFloatValue = 123.0; + EXPECT_EQ((size_a * kValueB).bytes(), kValueA * kValueB); + EXPECT_EQ((size_a * kInt32Value).bytes(), kValueA * kInt32Value); + EXPECT_EQ((size_a * kFloatValue).bytes(), kValueA * kFloatValue); + + EXPECT_EQ((size_a / 10).bytes(), kValueA / 10); + EXPECT_EQ(size_a / size_b, static_cast<double>(kValueA) / kValueB); + + DataSize mutable_size = DataSize::Bytes(kValueA); + mutable_size += size_b; + EXPECT_EQ(mutable_size.bytes(), kValueA + kValueB); + mutable_size -= size_a; + EXPECT_EQ(mutable_size.bytes(), kValueB); +} +} // namespace test +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/frequency.cc b/third_party/libwebrtc/api/units/frequency.cc new file mode 100644 index 0000000000..2d938a2814 --- /dev/null +++ b/third_party/libwebrtc/api/units/frequency.cc @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 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/units/frequency.h" + +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { +std::string ToString(Frequency value) { + char buf[64]; + rtc::SimpleStringBuilder sb(buf); + if (value.IsPlusInfinity()) { + sb << "+inf Hz"; + } else if (value.IsMinusInfinity()) { + sb << "-inf Hz"; + } else if (value.millihertz<int64_t>() % 1000 != 0) { + sb.AppendFormat("%.3f Hz", value.hertz<double>()); + } else { + sb << value.hertz<int64_t>() << " Hz"; + } + return sb.str(); +} +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/frequency.h b/third_party/libwebrtc/api/units/frequency.h new file mode 100644 index 0000000000..06081e4c0d --- /dev/null +++ b/third_party/libwebrtc/api/units/frequency.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2019 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. + */ +#ifndef API_UNITS_FREQUENCY_H_ +#define API_UNITS_FREQUENCY_H_ + +#ifdef WEBRTC_UNIT_TEST +#include <ostream> // no-presubmit-check TODO(webrtc:8982) +#endif // WEBRTC_UNIT_TEST + +#include <cstdlib> +#include <limits> +#include <string> +#include <type_traits> + +#include "api/units/time_delta.h" +#include "rtc_base/units/unit_base.h" // IWYU pragma: export + +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 <typename T = int64_t> + constexpr T hertz() const { + return ToFraction<1000, T>(); + } + template <typename T = int64_t> + constexpr T millihertz() const { + return ToValue<T>(); + } + + private: + friend class rtc_units_impl::UnitBase<Frequency>; + using RelativeUnit::RelativeUnit; + static constexpr bool one_sided = true; +}; + +inline constexpr Frequency operator/(int64_t nominator, + const TimeDelta& interval) { + constexpr int64_t kKiloPerMicro = 1000 * 1000000; + 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()); +} + +inline constexpr TimeDelta operator/(int64_t nominator, + const Frequency& frequency) { + constexpr int64_t kMegaPerMilli = 1000000 * 1000; + RTC_DCHECK_LE(nominator, std::numeric_limits<int64_t>::max() / kMegaPerMilli); + RTC_CHECK(frequency.IsFinite()); + RTC_CHECK(!frequency.IsZero()); + return TimeDelta::Micros(nominator * kMegaPerMilli / frequency.millihertz()); +} + +inline constexpr double operator*(Frequency frequency, TimeDelta time_delta) { + return frequency.hertz<double>() * time_delta.seconds<double>(); +} +inline constexpr double operator*(TimeDelta time_delta, Frequency frequency) { + return frequency * time_delta; +} + +std::string ToString(Frequency value); +inline std::string ToLogString(Frequency value) { + return ToString(value); +} + +#ifdef WEBRTC_UNIT_TEST +inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) + std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) + Frequency value) { + return stream << ToString(value); +} +#endif // WEBRTC_UNIT_TEST + +} // namespace webrtc +#endif // API_UNITS_FREQUENCY_H_ diff --git a/third_party/libwebrtc/api/units/frequency_gn/moz.build b/third_party/libwebrtc/api/units/frequency_gn/moz.build new file mode 100644 index 0000000000..3c84c283b8 --- /dev/null +++ b/third_party/libwebrtc/api/units/frequency_gn/moz.build @@ -0,0 +1,221 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1" +DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True +DEFINES["RTC_ENABLE_VP9"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_LIBRARY_IMPL"] = True +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "!/third_party/libwebrtc/gen", + "/ipc/chromium/src", + "/third_party/libwebrtc/", + "/third_party/libwebrtc/third_party/abseil-cpp/", + "/tools/profiler/public" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/api/units/frequency.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION_ROLL"] = "r22_1" + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_GNU_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_LIBCPP_HAS_NO_ALIGNED_ALLOCATION"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES"] = "0" + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_AURA"] = "1" + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_UDEV"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "2" + DEFINES["UNICODE"] = True + DEFINES["USE_AURA"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP" + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_HAS_NODISCARD"] = True + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "mips32": + + DEFINES["MIPS32_LE"] = True + DEFINES["MIPS_FPU_LE"] = True + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["CPU_ARCH"] == "x86_64": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0" + +if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_X11"] = "1" + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Android": + + OS_LIBS += [ + "android_support", + "unwind" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + + OS_LIBS += [ + "android_support" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +Library("frequency_gn") diff --git a/third_party/libwebrtc/api/units/frequency_unittest.cc b/third_party/libwebrtc/api/units/frequency_unittest.cc new file mode 100644 index 0000000000..1260c2107d --- /dev/null +++ b/third_party/libwebrtc/api/units/frequency_unittest.cc @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2019 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/units/frequency.h" + +#include <limits> + +#include "test/gtest.h" + +namespace webrtc { +namespace test { +TEST(FrequencyTest, ConstExpr) { + constexpr Frequency kFrequencyZero = Frequency::Zero(); + constexpr Frequency kFrequencyPlusInf = Frequency::PlusInfinity(); + constexpr Frequency kFrequencyMinusInf = Frequency::MinusInfinity(); + static_assert(kFrequencyZero.IsZero(), ""); + static_assert(kFrequencyPlusInf.IsPlusInfinity(), ""); + static_assert(kFrequencyMinusInf.IsMinusInfinity(), ""); + + static_assert(kFrequencyPlusInf > kFrequencyZero, ""); +} + +TEST(FrequencyTest, GetBackSameValues) { + const int64_t kValue = 31; + 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::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_TRUE(Frequency::PlusInfinity().IsInfinite()); + EXPECT_TRUE(Frequency::MinusInfinity().IsInfinite()); + EXPECT_FALSE(Frequency::Zero().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::Zero().IsFinite()); + + EXPECT_TRUE(Frequency::PlusInfinity().IsPlusInfinity()); + EXPECT_FALSE(Frequency::MinusInfinity().IsPlusInfinity()); + + EXPECT_TRUE(Frequency::MinusInfinity().IsMinusInfinity()); + EXPECT_FALSE(Frequency::PlusInfinity().IsMinusInfinity()); +} + +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); + + 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_LT(Frequency::Zero(), small); + + EXPECT_GT(Frequency::PlusInfinity(), large); + EXPECT_LT(Frequency::MinusInfinity(), Frequency::Zero()); +} + +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); + EXPECT_EQ(under.Clamped(lower, upper), lower); + EXPECT_EQ(inside.Clamped(lower, upper), inside); + EXPECT_EQ(over.Clamped(lower, upper), upper); + + Frequency mutable_frequency = lower; + mutable_frequency.Clamp(lower, upper); + EXPECT_EQ(mutable_frequency, lower); + mutable_frequency = inside; + mutable_frequency.Clamp(lower, upper); + EXPECT_EQ(mutable_frequency, inside); + mutable_frequency = over; + mutable_frequency.Clamp(lower, upper); + EXPECT_EQ(mutable_frequency, upper); +} + +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); + 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>(), + 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)); +} +TEST(FrequencyTest, Rounding) { + 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)); + + 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)); +} + +TEST(FrequencyTest, InfinityOperations) { + const double kValue = 267; + const Frequency finite = Frequency::Hertz(kValue); + EXPECT_TRUE((Frequency::PlusInfinity() + finite).IsPlusInfinity()); + EXPECT_TRUE((Frequency::PlusInfinity() - finite).IsPlusInfinity()); + EXPECT_TRUE((finite + Frequency::PlusInfinity()).IsPlusInfinity()); + EXPECT_TRUE((finite - Frequency::MinusInfinity()).IsPlusInfinity()); + + EXPECT_TRUE((Frequency::MinusInfinity() + finite).IsMinusInfinity()); + EXPECT_TRUE((Frequency::MinusInfinity() - finite).IsMinusInfinity()); + EXPECT_TRUE((finite + Frequency::MinusInfinity()).IsMinusInfinity()); + EXPECT_TRUE((finite - Frequency::PlusInfinity()).IsMinusInfinity()); +} + +TEST(UnitConversionTest, TimeDeltaAndFrequency) { + 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 diff --git a/third_party/libwebrtc/api/units/time_delta.cc b/third_party/libwebrtc/api/units/time_delta.cc new file mode 100644 index 0000000000..31bf3e0106 --- /dev/null +++ b/third_party/libwebrtc/api/units/time_delta.cc @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018 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/units/time_delta.h" + +#include "api/array_view.h" +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { + +std::string ToString(TimeDelta value) { + char buf[64]; + rtc::SimpleStringBuilder sb(buf); + if (value.IsPlusInfinity()) { + sb << "+inf ms"; + } else if (value.IsMinusInfinity()) { + sb << "-inf ms"; + } else { + if (value.us() == 0 || (value.us() % 1000) != 0) + sb << value.us() << " us"; + else if (value.ms() % 1000 != 0) + sb << value.ms() << " ms"; + else + sb << value.seconds() << " s"; + } + return sb.str(); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/time_delta.h b/third_party/libwebrtc/api/units/time_delta.h new file mode 100644 index 0000000000..5981e32dce --- /dev/null +++ b/third_party/libwebrtc/api/units/time_delta.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2018 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. + */ + +#ifndef API_UNITS_TIME_DELTA_H_ +#define API_UNITS_TIME_DELTA_H_ + +#ifdef WEBRTC_UNIT_TEST +#include <ostream> // no-presubmit-check TODO(webrtc:8982) +#endif // WEBRTC_UNIT_TEST + +#include <cstdlib> +#include <string> +#include <type_traits> + +#include "rtc_base/units/unit_base.h" // IWYU pragma: export + +namespace webrtc { + +// TimeDelta represents the difference between two timestamps. Commonly this can +// be a duration. However since two Timestamps are not guaranteed to have the +// same epoch (they might come from different computers, making exact +// synchronisation infeasible), the duration covered by a TimeDelta can be +// undefined. To simplify usage, it can be constructed and converted to +// different units, specifically seconds (s), milliseconds (ms) and +// microseconds (us). +class TimeDelta final : public rtc_units_impl::RelativeUnit<TimeDelta> { + public: + template <typename T> + static constexpr TimeDelta Minutes(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return Seconds(value * 60); + } + template <typename T> + static constexpr TimeDelta Seconds(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromFraction(1'000'000, value); + } + template <typename T> + static constexpr TimeDelta Millis(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromFraction(1'000, value); + } + template <typename T> + static constexpr TimeDelta Micros(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromValue(value); + } + + TimeDelta() = delete; + + template <typename T = int64_t> + constexpr T seconds() const { + return ToFraction<1000000, T>(); + } + template <typename T = int64_t> + constexpr T ms() const { + return ToFraction<1000, T>(); + } + template <typename T = int64_t> + constexpr T us() const { + return ToValue<T>(); + } + template <typename T = int64_t> + constexpr T ns() const { + return ToMultiple<1000, T>(); + } + + constexpr int64_t seconds_or(int64_t fallback_value) const { + return ToFractionOr<1000000>(fallback_value); + } + constexpr int64_t ms_or(int64_t fallback_value) const { + return ToFractionOr<1000>(fallback_value); + } + constexpr int64_t us_or(int64_t fallback_value) const { + return ToValueOr(fallback_value); + } + + constexpr TimeDelta Abs() const { + return us() < 0 ? TimeDelta::Micros(-us()) : *this; + } + + private: + friend class rtc_units_impl::UnitBase<TimeDelta>; + using RelativeUnit::RelativeUnit; + static constexpr bool one_sided = false; +}; + +std::string ToString(TimeDelta value); +inline std::string ToLogString(TimeDelta value) { + return ToString(value); +} + +#ifdef WEBRTC_UNIT_TEST +inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) + std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) + TimeDelta value) { + return stream << ToString(value); +} +#endif // WEBRTC_UNIT_TEST + +} // namespace webrtc + +#endif // API_UNITS_TIME_DELTA_H_ diff --git a/third_party/libwebrtc/api/units/time_delta_gn/moz.build b/third_party/libwebrtc/api/units/time_delta_gn/moz.build new file mode 100644 index 0000000000..3fe57620d8 --- /dev/null +++ b/third_party/libwebrtc/api/units/time_delta_gn/moz.build @@ -0,0 +1,221 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1" +DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True +DEFINES["RTC_ENABLE_VP9"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_LIBRARY_IMPL"] = True +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "!/third_party/libwebrtc/gen", + "/ipc/chromium/src", + "/third_party/libwebrtc/", + "/third_party/libwebrtc/third_party/abseil-cpp/", + "/tools/profiler/public" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/api/units/time_delta.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION_ROLL"] = "r22_1" + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_GNU_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_LIBCPP_HAS_NO_ALIGNED_ALLOCATION"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES"] = "0" + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_AURA"] = "1" + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_UDEV"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "2" + DEFINES["UNICODE"] = True + DEFINES["USE_AURA"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP" + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_HAS_NODISCARD"] = True + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "mips32": + + DEFINES["MIPS32_LE"] = True + DEFINES["MIPS_FPU_LE"] = True + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["CPU_ARCH"] == "x86_64": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0" + +if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_X11"] = "1" + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Android": + + OS_LIBS += [ + "android_support", + "unwind" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + + OS_LIBS += [ + "android_support" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +Library("time_delta_gn") diff --git a/third_party/libwebrtc/api/units/time_delta_unittest.cc b/third_party/libwebrtc/api/units/time_delta_unittest.cc new file mode 100644 index 0000000000..51a7aa233a --- /dev/null +++ b/third_party/libwebrtc/api/units/time_delta_unittest.cc @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2018 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/units/time_delta.h" + +#include <limits> + +#include "test/gtest.h" + +namespace webrtc { +namespace test { +TEST(TimeDeltaTest, ConstExpr) { + constexpr int64_t kValue = -12345; + constexpr TimeDelta kTimeDeltaZero = TimeDelta::Zero(); + constexpr TimeDelta kTimeDeltaPlusInf = TimeDelta::PlusInfinity(); + constexpr TimeDelta kTimeDeltaMinusInf = TimeDelta::MinusInfinity(); + static_assert(kTimeDeltaZero.IsZero(), ""); + static_assert(kTimeDeltaPlusInf.IsPlusInfinity(), ""); + static_assert(kTimeDeltaMinusInf.IsMinusInfinity(), ""); + static_assert(kTimeDeltaPlusInf.ms_or(-1) == -1, ""); + + static_assert(kTimeDeltaPlusInf > kTimeDeltaZero, ""); + + constexpr TimeDelta kTimeDeltaMinutes = TimeDelta::Minutes(kValue); + constexpr TimeDelta kTimeDeltaSeconds = TimeDelta::Seconds(kValue); + constexpr TimeDelta kTimeDeltaMs = TimeDelta::Millis(kValue); + constexpr TimeDelta kTimeDeltaUs = TimeDelta::Micros(kValue); + + static_assert(kTimeDeltaMinutes.seconds_or(0) == kValue * 60, ""); + static_assert(kTimeDeltaSeconds.seconds_or(0) == kValue, ""); + static_assert(kTimeDeltaMs.ms_or(0) == kValue, ""); + static_assert(kTimeDeltaUs.us_or(0) == kValue, ""); +} + +TEST(TimeDeltaTest, GetBackSameValues) { + const int64_t kValue = 499; + for (int sign = -1; sign <= 1; ++sign) { + int64_t value = kValue * sign; + EXPECT_EQ(TimeDelta::Millis(value).ms(), value); + EXPECT_EQ(TimeDelta::Micros(value).us(), value); + EXPECT_EQ(TimeDelta::Seconds(value).seconds(), value); + EXPECT_EQ(TimeDelta::Seconds(value).seconds(), value); + } + EXPECT_EQ(TimeDelta::Zero().us(), 0); +} + +TEST(TimeDeltaTest, GetDifferentPrefix) { + const int64_t kValue = 3000000; + EXPECT_EQ(TimeDelta::Micros(kValue).seconds(), kValue / 1000000); + EXPECT_EQ(TimeDelta::Millis(kValue).seconds(), kValue / 1000); + EXPECT_EQ(TimeDelta::Micros(kValue).ms(), kValue / 1000); + EXPECT_EQ(TimeDelta::Minutes(kValue / 60).seconds(), kValue); + + EXPECT_EQ(TimeDelta::Millis(kValue).us(), kValue * 1000); + EXPECT_EQ(TimeDelta::Seconds(kValue).ms(), kValue * 1000); + EXPECT_EQ(TimeDelta::Seconds(kValue).us(), kValue * 1000000); + EXPECT_EQ(TimeDelta::Minutes(kValue / 60).seconds(), kValue); +} + +TEST(TimeDeltaTest, IdentityChecks) { + const int64_t kValue = 3000; + EXPECT_TRUE(TimeDelta::Zero().IsZero()); + EXPECT_FALSE(TimeDelta::Millis(kValue).IsZero()); + + EXPECT_TRUE(TimeDelta::PlusInfinity().IsInfinite()); + EXPECT_TRUE(TimeDelta::MinusInfinity().IsInfinite()); + EXPECT_FALSE(TimeDelta::Zero().IsInfinite()); + EXPECT_FALSE(TimeDelta::Millis(-kValue).IsInfinite()); + EXPECT_FALSE(TimeDelta::Millis(kValue).IsInfinite()); + + EXPECT_FALSE(TimeDelta::PlusInfinity().IsFinite()); + EXPECT_FALSE(TimeDelta::MinusInfinity().IsFinite()); + EXPECT_TRUE(TimeDelta::Millis(-kValue).IsFinite()); + EXPECT_TRUE(TimeDelta::Millis(kValue).IsFinite()); + EXPECT_TRUE(TimeDelta::Zero().IsFinite()); + + EXPECT_TRUE(TimeDelta::PlusInfinity().IsPlusInfinity()); + EXPECT_FALSE(TimeDelta::MinusInfinity().IsPlusInfinity()); + + EXPECT_TRUE(TimeDelta::MinusInfinity().IsMinusInfinity()); + EXPECT_FALSE(TimeDelta::PlusInfinity().IsMinusInfinity()); +} + +TEST(TimeDeltaTest, ComparisonOperators) { + const int64_t kSmall = 450; + const int64_t kLarge = 451; + const TimeDelta small = TimeDelta::Millis(kSmall); + const TimeDelta large = TimeDelta::Millis(kLarge); + + EXPECT_EQ(TimeDelta::Zero(), TimeDelta::Millis(0)); + EXPECT_EQ(TimeDelta::PlusInfinity(), TimeDelta::PlusInfinity()); + EXPECT_EQ(small, TimeDelta::Millis(kSmall)); + EXPECT_LE(small, TimeDelta::Millis(kSmall)); + EXPECT_GE(small, TimeDelta::Millis(kSmall)); + EXPECT_NE(small, TimeDelta::Millis(kLarge)); + EXPECT_LE(small, TimeDelta::Millis(kLarge)); + EXPECT_LT(small, TimeDelta::Millis(kLarge)); + EXPECT_GE(large, TimeDelta::Millis(kSmall)); + EXPECT_GT(large, TimeDelta::Millis(kSmall)); + EXPECT_LT(TimeDelta::Zero(), small); + EXPECT_GT(TimeDelta::Zero(), TimeDelta::Millis(-kSmall)); + EXPECT_GT(TimeDelta::Zero(), TimeDelta::Millis(-kSmall)); + + EXPECT_GT(TimeDelta::PlusInfinity(), large); + EXPECT_LT(TimeDelta::MinusInfinity(), TimeDelta::Zero()); +} + +TEST(TimeDeltaTest, Clamping) { + const TimeDelta upper = TimeDelta::Millis(800); + const TimeDelta lower = TimeDelta::Millis(100); + const TimeDelta under = TimeDelta::Millis(100); + const TimeDelta inside = TimeDelta::Millis(500); + const TimeDelta over = TimeDelta::Millis(1000); + EXPECT_EQ(under.Clamped(lower, upper), lower); + EXPECT_EQ(inside.Clamped(lower, upper), inside); + EXPECT_EQ(over.Clamped(lower, upper), upper); + + TimeDelta mutable_delta = lower; + mutable_delta.Clamp(lower, upper); + EXPECT_EQ(mutable_delta, lower); + mutable_delta = inside; + mutable_delta.Clamp(lower, upper); + EXPECT_EQ(mutable_delta, inside); + mutable_delta = over; + mutable_delta.Clamp(lower, upper); + EXPECT_EQ(mutable_delta, upper); +} + +TEST(TimeDeltaTest, CanBeInititializedFromLargeInt) { + const int kMaxInt = std::numeric_limits<int>::max(); + EXPECT_EQ(TimeDelta::Seconds(kMaxInt).us(), + static_cast<int64_t>(kMaxInt) * 1000000); + EXPECT_EQ(TimeDelta::Millis(kMaxInt).us(), + static_cast<int64_t>(kMaxInt) * 1000); +} + +TEST(TimeDeltaTest, ConvertsToAndFromDouble) { + const int64_t kMicros = 17017; + const double kNanosDouble = kMicros * 1e3; + const double kMicrosDouble = kMicros; + const double kMillisDouble = kMicros * 1e-3; + const double kSecondsDouble = kMillisDouble * 1e-3; + + EXPECT_EQ(TimeDelta::Micros(kMicros).seconds<double>(), kSecondsDouble); + EXPECT_EQ(TimeDelta::Seconds(kSecondsDouble).us(), kMicros); + + EXPECT_EQ(TimeDelta::Micros(kMicros).ms<double>(), kMillisDouble); + EXPECT_EQ(TimeDelta::Millis(kMillisDouble).us(), kMicros); + + EXPECT_EQ(TimeDelta::Micros(kMicros).us<double>(), kMicrosDouble); + EXPECT_EQ(TimeDelta::Micros(kMicrosDouble).us(), kMicros); + + EXPECT_NEAR(TimeDelta::Micros(kMicros).ns<double>(), kNanosDouble, 1); + + const double kPlusInfinity = std::numeric_limits<double>::infinity(); + const double kMinusInfinity = -kPlusInfinity; + + EXPECT_EQ(TimeDelta::PlusInfinity().seconds<double>(), kPlusInfinity); + EXPECT_EQ(TimeDelta::MinusInfinity().seconds<double>(), kMinusInfinity); + EXPECT_EQ(TimeDelta::PlusInfinity().ms<double>(), kPlusInfinity); + EXPECT_EQ(TimeDelta::MinusInfinity().ms<double>(), kMinusInfinity); + EXPECT_EQ(TimeDelta::PlusInfinity().us<double>(), kPlusInfinity); + EXPECT_EQ(TimeDelta::MinusInfinity().us<double>(), kMinusInfinity); + EXPECT_EQ(TimeDelta::PlusInfinity().ns<double>(), kPlusInfinity); + EXPECT_EQ(TimeDelta::MinusInfinity().ns<double>(), kMinusInfinity); + + EXPECT_TRUE(TimeDelta::Seconds(kPlusInfinity).IsPlusInfinity()); + EXPECT_TRUE(TimeDelta::Seconds(kMinusInfinity).IsMinusInfinity()); + EXPECT_TRUE(TimeDelta::Millis(kPlusInfinity).IsPlusInfinity()); + EXPECT_TRUE(TimeDelta::Millis(kMinusInfinity).IsMinusInfinity()); + EXPECT_TRUE(TimeDelta::Micros(kPlusInfinity).IsPlusInfinity()); + EXPECT_TRUE(TimeDelta::Micros(kMinusInfinity).IsMinusInfinity()); +} + +TEST(TimeDeltaTest, MathOperations) { + const int64_t kValueA = 267; + const int64_t kValueB = 450; + const TimeDelta delta_a = TimeDelta::Millis(kValueA); + const TimeDelta delta_b = TimeDelta::Millis(kValueB); + EXPECT_EQ((delta_a + delta_b).ms(), kValueA + kValueB); + EXPECT_EQ((delta_a - delta_b).ms(), kValueA - kValueB); + + EXPECT_EQ((delta_b / 10).ms(), kValueB / 10); + EXPECT_EQ(delta_b / delta_a, static_cast<double>(kValueB) / kValueA); + + EXPECT_EQ(TimeDelta::Micros(-kValueA).Abs().us(), kValueA); + EXPECT_EQ(TimeDelta::Micros(kValueA).Abs().us(), kValueA); + + TimeDelta mutable_delta = TimeDelta::Millis(kValueA); + mutable_delta += TimeDelta::Millis(kValueB); + EXPECT_EQ(mutable_delta, TimeDelta::Millis(kValueA + kValueB)); + mutable_delta -= TimeDelta::Millis(kValueB); + EXPECT_EQ(mutable_delta, TimeDelta::Millis(kValueA)); +} + +TEST(TimeDeltaTest, MultiplyByScalar) { + const TimeDelta kValue = TimeDelta::Micros(267); + const int64_t kInt64 = 450; + const int32_t kInt32 = 123; + const size_t kUnsignedInt = 125; + const double kFloat = 123.0; + + EXPECT_EQ((kValue * kInt64).us(), kValue.us() * kInt64); + EXPECT_EQ(kValue * kInt64, kInt64 * kValue); + + EXPECT_EQ((kValue * kInt32).us(), kValue.us() * kInt32); + EXPECT_EQ(kValue * kInt32, kInt32 * kValue); + + EXPECT_EQ((kValue * kUnsignedInt).us(), kValue.us() * int64_t{kUnsignedInt}); + EXPECT_EQ(kValue * kUnsignedInt, kUnsignedInt * kValue); + + EXPECT_DOUBLE_EQ((kValue * kFloat).us(), kValue.us() * kFloat); + EXPECT_EQ(kValue * kFloat, kFloat * kValue); +} + +TEST(TimeDeltaTest, InfinityOperations) { + const int64_t kValue = 267; + const TimeDelta finite = TimeDelta::Millis(kValue); + EXPECT_TRUE((TimeDelta::PlusInfinity() + finite).IsPlusInfinity()); + EXPECT_TRUE((TimeDelta::PlusInfinity() - finite).IsPlusInfinity()); + EXPECT_TRUE((finite + TimeDelta::PlusInfinity()).IsPlusInfinity()); + EXPECT_TRUE((finite - TimeDelta::MinusInfinity()).IsPlusInfinity()); + + EXPECT_TRUE((TimeDelta::MinusInfinity() + finite).IsMinusInfinity()); + EXPECT_TRUE((TimeDelta::MinusInfinity() - finite).IsMinusInfinity()); + EXPECT_TRUE((finite + TimeDelta::MinusInfinity()).IsMinusInfinity()); + EXPECT_TRUE((finite - TimeDelta::PlusInfinity()).IsMinusInfinity()); +} +} // namespace test +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/timestamp.cc b/third_party/libwebrtc/api/units/timestamp.cc new file mode 100644 index 0000000000..fc4f419596 --- /dev/null +++ b/third_party/libwebrtc/api/units/timestamp.cc @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018 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/units/timestamp.h" + +#include "api/array_view.h" +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { +std::string ToString(Timestamp value) { + char buf[64]; + rtc::SimpleStringBuilder sb(buf); + if (value.IsPlusInfinity()) { + sb << "+inf ms"; + } else if (value.IsMinusInfinity()) { + sb << "-inf ms"; + } else { + if (value.us() == 0 || (value.us() % 1000) != 0) + sb << value.us() << " us"; + else if (value.ms() % 1000 != 0) + sb << value.ms() << " ms"; + else + sb << value.seconds() << " s"; + } + return sb.str(); +} +} // namespace webrtc diff --git a/third_party/libwebrtc/api/units/timestamp.h b/third_party/libwebrtc/api/units/timestamp.h new file mode 100644 index 0000000000..8aabe05cad --- /dev/null +++ b/third_party/libwebrtc/api/units/timestamp.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2018 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. + */ + +#ifndef API_UNITS_TIMESTAMP_H_ +#define API_UNITS_TIMESTAMP_H_ + +#ifdef WEBRTC_UNIT_TEST +#include <ostream> // no-presubmit-check TODO(webrtc:8982) +#endif // WEBRTC_UNIT_TEST + +#include <string> +#include <type_traits> + +#include "api/units/time_delta.h" +#include "rtc_base/checks.h" +#include "rtc_base/units/unit_base.h" // IWYU pragma: export + +namespace webrtc { +// Timestamp represents the time that has passed since some unspecified epoch. +// The epoch is assumed to be before any represented timestamps, this means that +// negative values are not valid. The most notable feature is that the +// difference of two Timestamps results in a TimeDelta. +class Timestamp final : public rtc_units_impl::UnitBase<Timestamp> { + public: + template <typename T> + static constexpr Timestamp Seconds(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromFraction(1'000'000, value); + } + template <typename T> + static constexpr Timestamp Millis(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromFraction(1'000, value); + } + template <typename T> + static constexpr Timestamp Micros(T value) { + static_assert(std::is_arithmetic<T>::value, ""); + return FromValue(value); + } + + Timestamp() = delete; + + template <typename T = int64_t> + constexpr T seconds() const { + return ToFraction<1000000, T>(); + } + template <typename T = int64_t> + constexpr T ms() const { + return ToFraction<1000, T>(); + } + template <typename T = int64_t> + constexpr T us() const { + return ToValue<T>(); + } + + constexpr int64_t seconds_or(int64_t fallback_value) const { + return ToFractionOr<1000000>(fallback_value); + } + constexpr int64_t ms_or(int64_t fallback_value) const { + return ToFractionOr<1000>(fallback_value); + } + constexpr int64_t us_or(int64_t fallback_value) const { + return ToValueOr(fallback_value); + } + + constexpr Timestamp operator+(const TimeDelta delta) const { + if (IsPlusInfinity() || delta.IsPlusInfinity()) { + RTC_DCHECK(!IsMinusInfinity()); + RTC_DCHECK(!delta.IsMinusInfinity()); + return PlusInfinity(); + } else if (IsMinusInfinity() || delta.IsMinusInfinity()) { + RTC_DCHECK(!IsPlusInfinity()); + RTC_DCHECK(!delta.IsPlusInfinity()); + return MinusInfinity(); + } + return Timestamp::Micros(us() + delta.us()); + } + constexpr Timestamp operator-(const TimeDelta delta) const { + if (IsPlusInfinity() || delta.IsMinusInfinity()) { + RTC_DCHECK(!IsMinusInfinity()); + RTC_DCHECK(!delta.IsPlusInfinity()); + return PlusInfinity(); + } else if (IsMinusInfinity() || delta.IsPlusInfinity()) { + RTC_DCHECK(!IsPlusInfinity()); + RTC_DCHECK(!delta.IsMinusInfinity()); + return MinusInfinity(); + } + return Timestamp::Micros(us() - delta.us()); + } + constexpr TimeDelta operator-(const Timestamp other) const { + if (IsPlusInfinity() || other.IsMinusInfinity()) { + RTC_DCHECK(!IsMinusInfinity()); + RTC_DCHECK(!other.IsPlusInfinity()); + return TimeDelta::PlusInfinity(); + } else if (IsMinusInfinity() || other.IsPlusInfinity()) { + RTC_DCHECK(!IsPlusInfinity()); + RTC_DCHECK(!other.IsMinusInfinity()); + return TimeDelta::MinusInfinity(); + } + return TimeDelta::Micros(us() - other.us()); + } + constexpr Timestamp& operator-=(const TimeDelta delta) { + *this = *this - delta; + return *this; + } + constexpr Timestamp& operator+=(const TimeDelta delta) { + *this = *this + delta; + return *this; + } + + private: + friend class rtc_units_impl::UnitBase<Timestamp>; + using UnitBase::UnitBase; + static constexpr bool one_sided = true; +}; + +std::string ToString(Timestamp value); +inline std::string ToLogString(Timestamp value) { + return ToString(value); +} + +#ifdef WEBRTC_UNIT_TEST +inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) + std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) + Timestamp value) { + return stream << ToString(value); +} +#endif // WEBRTC_UNIT_TEST + +} // namespace webrtc + +#endif // API_UNITS_TIMESTAMP_H_ diff --git a/third_party/libwebrtc/api/units/timestamp_gn/moz.build b/third_party/libwebrtc/api/units/timestamp_gn/moz.build new file mode 100644 index 0000000000..a869cbcd71 --- /dev/null +++ b/third_party/libwebrtc/api/units/timestamp_gn/moz.build @@ -0,0 +1,221 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1" +DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True +DEFINES["RTC_ENABLE_VP9"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_LIBRARY_IMPL"] = True +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "!/third_party/libwebrtc/gen", + "/ipc/chromium/src", + "/third_party/libwebrtc/", + "/third_party/libwebrtc/third_party/abseil-cpp/", + "/tools/profiler/public" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/api/units/timestamp.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION_ROLL"] = "r22_1" + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_GNU_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_LIBCPP_HAS_NO_ALIGNED_ALLOCATION"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES"] = "0" + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_AURA"] = "1" + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_UDEV"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_GLIB"] = "1" + DEFINES["USE_OZONE"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["_LARGEFILE64_SOURCE"] = True + DEFINES["_LARGEFILE_SOURCE"] = True + DEFINES["__STDC_CONSTANT_MACROS"] = True + DEFINES["__STDC_FORMAT_MACROS"] = True + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "2" + DEFINES["UNICODE"] = True + DEFINES["USE_AURA"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP" + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_HAS_NODISCARD"] = True + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "mips32": + + DEFINES["MIPS32_LE"] = True + DEFINES["MIPS_FPU_LE"] = True + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["CPU_ARCH"] == "x86_64": + + DEFINES["WEBRTC_ENABLE_AVX2"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_DEBUG"] = True + +if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0" + +if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_X11"] = "1" + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Android": + + OS_LIBS += [ + "android_support", + "unwind" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + + OS_LIBS += [ + "android_support" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "arm" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["_GNU_SOURCE"] = True + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["_GNU_SOURCE"] = True + +Library("timestamp_gn") diff --git a/third_party/libwebrtc/api/units/timestamp_unittest.cc b/third_party/libwebrtc/api/units/timestamp_unittest.cc new file mode 100644 index 0000000000..43b2985d43 --- /dev/null +++ b/third_party/libwebrtc/api/units/timestamp_unittest.cc @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2018 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 <limits> + +#include "api/units/timestamp.h" +#include "test/gtest.h" + +namespace webrtc { +namespace test { +TEST(TimestampTest, ConstExpr) { + constexpr int64_t kValue = 12345; + constexpr Timestamp kTimestampInf = Timestamp::PlusInfinity(); + static_assert(kTimestampInf.IsInfinite(), ""); + static_assert(kTimestampInf.ms_or(-1) == -1, ""); + + constexpr Timestamp kTimestampSeconds = Timestamp::Seconds(kValue); + constexpr Timestamp kTimestampMs = Timestamp::Millis(kValue); + constexpr Timestamp kTimestampUs = Timestamp::Micros(kValue); + + static_assert(kTimestampSeconds.seconds_or(0) == kValue, ""); + static_assert(kTimestampMs.ms_or(0) == kValue, ""); + static_assert(kTimestampUs.us_or(0) == kValue, ""); + + static_assert(kTimestampMs > kTimestampUs, ""); + + EXPECT_EQ(kTimestampSeconds.seconds(), kValue); + EXPECT_EQ(kTimestampMs.ms(), kValue); + EXPECT_EQ(kTimestampUs.us(), kValue); +} + +TEST(TimestampTest, GetBackSameValues) { + const int64_t kValue = 499; + EXPECT_EQ(Timestamp::Millis(kValue).ms(), kValue); + EXPECT_EQ(Timestamp::Micros(kValue).us(), kValue); + EXPECT_EQ(Timestamp::Seconds(kValue).seconds(), kValue); +} + +TEST(TimestampTest, GetDifferentPrefix) { + const int64_t kValue = 3000000; + EXPECT_EQ(Timestamp::Micros(kValue).seconds(), kValue / 1000000); + EXPECT_EQ(Timestamp::Millis(kValue).seconds(), kValue / 1000); + EXPECT_EQ(Timestamp::Micros(kValue).ms(), kValue / 1000); + + EXPECT_EQ(Timestamp::Millis(kValue).us(), kValue * 1000); + EXPECT_EQ(Timestamp::Seconds(kValue).ms(), kValue * 1000); + EXPECT_EQ(Timestamp::Seconds(kValue).us(), kValue * 1000000); +} + +TEST(TimestampTest, IdentityChecks) { + const int64_t kValue = 3000; + + EXPECT_TRUE(Timestamp::PlusInfinity().IsInfinite()); + EXPECT_TRUE(Timestamp::MinusInfinity().IsInfinite()); + EXPECT_FALSE(Timestamp::Millis(kValue).IsInfinite()); + + EXPECT_FALSE(Timestamp::PlusInfinity().IsFinite()); + EXPECT_FALSE(Timestamp::MinusInfinity().IsFinite()); + EXPECT_TRUE(Timestamp::Millis(kValue).IsFinite()); + + EXPECT_TRUE(Timestamp::PlusInfinity().IsPlusInfinity()); + EXPECT_FALSE(Timestamp::MinusInfinity().IsPlusInfinity()); + + EXPECT_TRUE(Timestamp::MinusInfinity().IsMinusInfinity()); + EXPECT_FALSE(Timestamp::PlusInfinity().IsMinusInfinity()); +} + +TEST(TimestampTest, ComparisonOperators) { + const int64_t kSmall = 450; + const int64_t kLarge = 451; + + EXPECT_EQ(Timestamp::PlusInfinity(), Timestamp::PlusInfinity()); + EXPECT_GE(Timestamp::PlusInfinity(), Timestamp::PlusInfinity()); + EXPECT_GT(Timestamp::PlusInfinity(), Timestamp::Millis(kLarge)); + EXPECT_EQ(Timestamp::Millis(kSmall), Timestamp::Millis(kSmall)); + EXPECT_LE(Timestamp::Millis(kSmall), Timestamp::Millis(kSmall)); + EXPECT_GE(Timestamp::Millis(kSmall), Timestamp::Millis(kSmall)); + EXPECT_NE(Timestamp::Millis(kSmall), Timestamp::Millis(kLarge)); + EXPECT_LE(Timestamp::Millis(kSmall), Timestamp::Millis(kLarge)); + EXPECT_LT(Timestamp::Millis(kSmall), Timestamp::Millis(kLarge)); + EXPECT_GE(Timestamp::Millis(kLarge), Timestamp::Millis(kSmall)); + EXPECT_GT(Timestamp::Millis(kLarge), Timestamp::Millis(kSmall)); +} + +TEST(TimestampTest, CanBeInititializedFromLargeInt) { + const int kMaxInt = std::numeric_limits<int>::max(); + EXPECT_EQ(Timestamp::Seconds(kMaxInt).us(), + static_cast<int64_t>(kMaxInt) * 1000000); + EXPECT_EQ(Timestamp::Millis(kMaxInt).us(), + static_cast<int64_t>(kMaxInt) * 1000); +} + +TEST(TimestampTest, ConvertsToAndFromDouble) { + const int64_t kMicros = 17017; + const double kMicrosDouble = kMicros; + const double kMillisDouble = kMicros * 1e-3; + const double kSecondsDouble = kMillisDouble * 1e-3; + + EXPECT_EQ(Timestamp::Micros(kMicros).seconds<double>(), kSecondsDouble); + EXPECT_EQ(Timestamp::Seconds(kSecondsDouble).us(), kMicros); + + EXPECT_EQ(Timestamp::Micros(kMicros).ms<double>(), kMillisDouble); + EXPECT_EQ(Timestamp::Millis(kMillisDouble).us(), kMicros); + + EXPECT_EQ(Timestamp::Micros(kMicros).us<double>(), kMicrosDouble); + EXPECT_EQ(Timestamp::Micros(kMicrosDouble).us(), kMicros); + + const double kPlusInfinity = std::numeric_limits<double>::infinity(); + const double kMinusInfinity = -kPlusInfinity; + + EXPECT_EQ(Timestamp::PlusInfinity().seconds<double>(), kPlusInfinity); + EXPECT_EQ(Timestamp::MinusInfinity().seconds<double>(), kMinusInfinity); + EXPECT_EQ(Timestamp::PlusInfinity().ms<double>(), kPlusInfinity); + EXPECT_EQ(Timestamp::MinusInfinity().ms<double>(), kMinusInfinity); + EXPECT_EQ(Timestamp::PlusInfinity().us<double>(), kPlusInfinity); + EXPECT_EQ(Timestamp::MinusInfinity().us<double>(), kMinusInfinity); + + EXPECT_TRUE(Timestamp::Seconds(kPlusInfinity).IsPlusInfinity()); + EXPECT_TRUE(Timestamp::Seconds(kMinusInfinity).IsMinusInfinity()); + EXPECT_TRUE(Timestamp::Millis(kPlusInfinity).IsPlusInfinity()); + EXPECT_TRUE(Timestamp::Millis(kMinusInfinity).IsMinusInfinity()); + EXPECT_TRUE(Timestamp::Micros(kPlusInfinity).IsPlusInfinity()); + EXPECT_TRUE(Timestamp::Micros(kMinusInfinity).IsMinusInfinity()); +} + +TEST(UnitConversionTest, TimestampAndTimeDeltaMath) { + const int64_t kValueA = 267; + const int64_t kValueB = 450; + const Timestamp time_a = Timestamp::Millis(kValueA); + const Timestamp time_b = Timestamp::Millis(kValueB); + const TimeDelta delta_a = TimeDelta::Millis(kValueA); + const TimeDelta delta_b = TimeDelta::Millis(kValueB); + + EXPECT_EQ((time_a - time_b), TimeDelta::Millis(kValueA - kValueB)); + EXPECT_EQ((time_b - delta_a), Timestamp::Millis(kValueB - kValueA)); + EXPECT_EQ((time_b + delta_a), Timestamp::Millis(kValueB + kValueA)); + + Timestamp mutable_time = time_a; + mutable_time += delta_b; + EXPECT_EQ(mutable_time, time_a + delta_b); + mutable_time -= delta_b; + EXPECT_EQ(mutable_time, time_a); +} + +TEST(UnitConversionTest, InfinityOperations) { + const int64_t kValue = 267; + const Timestamp finite_time = Timestamp::Millis(kValue); + const TimeDelta finite_delta = TimeDelta::Millis(kValue); + EXPECT_TRUE((Timestamp::PlusInfinity() + finite_delta).IsInfinite()); + EXPECT_TRUE((Timestamp::PlusInfinity() - finite_delta).IsInfinite()); + EXPECT_TRUE((finite_time + TimeDelta::PlusInfinity()).IsInfinite()); + EXPECT_TRUE((finite_time - TimeDelta::MinusInfinity()).IsInfinite()); +} +} // namespace test +} // namespace webrtc |