diff --git a/p2p/base/fakepackettransport.h b/p2p/base/fakepackettransport.h index cbff5110ed..e57bc179a7 100644 --- a/p2p/base/fakepackettransport.h +++ b/p2p/base/fakepackettransport.h @@ -88,10 +88,10 @@ class FakePacketTransport : public PacketTransportInternal { const CopyOnWriteBuffer* last_sent_packet() { return &last_sent_packet_; } - Optional network_route() const override { + absl::optional network_route() const override { return network_route_; } - void SetNetworkRoute(Optional network_route) { + void SetNetworkRoute(absl::optional network_route) { network_route_ = network_route; } @@ -132,7 +132,7 @@ class FakePacketTransport : public PacketTransportInternal { bool writable_ = false; bool receiving_ = false; - Optional network_route_; + absl::optional network_route_; }; } // namespace rtc diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index bcca5524c7..effe58be7e 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -446,7 +446,7 @@ rtc_source_set("rtc_base_approved_generic") { deps += [ "..:webrtc_common", "../api:array_view", - "../api:optional", + "//third_party/abseil-cpp/absl/types:optional", ] if (is_android) { @@ -661,7 +661,7 @@ rtc_static_library("rtc_numerics") { ":checks", ":rtc_base_approved", ":safe_compare", - "../api:optional", + "//third_party/abseil-cpp/absl/types:optional", ] } @@ -728,7 +728,7 @@ rtc_static_library("rtc_base_generic") { ":stringutils", "..:webrtc_common", "../api:array_view", - "../api:optional", + "//third_party/abseil-cpp/absl/types:optional", ] public_deps = [ ":rtc_base_approved", @@ -1304,9 +1304,9 @@ if (rtc_include_tests) { ":rtc_base_tests_utils", ":stringutils", "../api:array_view", - "../api:optional", "../test:fileutils", "../test:test_support", + "//third_party/abseil-cpp/absl/types:optional", ] public_deps = [ ":rtc_base", diff --git a/rtc_base/experiments/BUILD.gn b/rtc_base/experiments/BUILD.gn index 8b2b0621d8..a95e258789 100644 --- a/rtc_base/experiments/BUILD.gn +++ b/rtc_base/experiments/BUILD.gn @@ -15,8 +15,8 @@ rtc_static_library("alr_experiment") { ] deps = [ "../:rtc_base_approved", - "../../api:optional", "../../system_wrappers:field_trial_api", + "//third_party/abseil-cpp/absl/types:optional", ] } @@ -29,11 +29,11 @@ rtc_static_library("field_trial_parser") { ] deps = [ "../:rtc_base_approved", - "../../api:optional", "../../api/units:data_rate", "../../api/units:data_size", "../../api/units:time_delta", "../../system_wrappers:field_trial_api", + "//third_party/abseil-cpp/absl/types:optional", ] } @@ -44,8 +44,8 @@ rtc_static_library("congestion_controller_experiment") { ] deps = [ "../:rtc_base_approved", - "../../api:optional", "../../system_wrappers:field_trial_api", + "//third_party/abseil-cpp/absl/types:optional", ] } @@ -57,9 +57,9 @@ rtc_static_library("quality_scaling_experiment") { deps = [ "../:rtc_base_approved", "../..:webrtc_common", - "../../api:optional", "../../api/video_codecs:video_codecs_api", "../../system_wrappers:field_trial_api", + "//third_party/abseil-cpp/absl/types:optional", ] } diff --git a/rtc_base/experiments/alr_experiment.cc b/rtc_base/experiments/alr_experiment.cc index c69caed787..dff5acecc8 100644 --- a/rtc_base/experiments/alr_experiment.cc +++ b/rtc_base/experiments/alr_experiment.cc @@ -31,9 +31,9 @@ bool AlrExperimentSettings::MaxOneFieldTrialEnabled() { .empty(); } -rtc::Optional +absl::optional AlrExperimentSettings::CreateFromFieldTrial(const char* experiment_name) { - rtc::Optional ret; + absl::optional ret; std::string group_name = field_trial::FindFullName(experiment_name); const std::string kIgnoredSuffix = "_Dogfood"; diff --git a/rtc_base/experiments/alr_experiment.h b/rtc_base/experiments/alr_experiment.h index a9c483d632..4d9fd00130 100644 --- a/rtc_base/experiments/alr_experiment.h +++ b/rtc_base/experiments/alr_experiment.h @@ -11,7 +11,7 @@ #ifndef RTC_BASE_EXPERIMENTS_ALR_EXPERIMENT_H_ #define RTC_BASE_EXPERIMENTS_ALR_EXPERIMENT_H_ -#include "api/optional.h" +#include "absl/types/optional.h" namespace webrtc { struct AlrExperimentSettings { @@ -28,7 +28,7 @@ struct AlrExperimentSettings { static const char kScreenshareProbingBweExperimentName[]; static const char kStrictPacingAndProbingExperimentName[]; - static rtc::Optional CreateFromFieldTrial( + static absl::optional CreateFromFieldTrial( const char* experiment_name); static bool MaxOneFieldTrialEnabled(); diff --git a/rtc_base/experiments/congestion_controller_experiment.cc b/rtc_base/experiments/congestion_controller_experiment.cc index 9fdaacdb49..b05ef716af 100644 --- a/rtc_base/experiments/congestion_controller_experiment.cc +++ b/rtc_base/experiments/congestion_controller_experiment.cc @@ -31,10 +31,10 @@ bool CongestionControllerExperiment::InjectedControllerEnabled() { return trial_string.find("Enabled,Injected") == 0; } -rtc::Optional +absl::optional CongestionControllerExperiment::GetBbrExperimentConfig() { if (!BbrControllerEnabled()) - return rtc::nullopt; + return absl::nullopt; std::string trial_string = webrtc::field_trial::FindFullName(kControllerExperiment); BbrExperimentConfig config; @@ -56,7 +56,7 @@ CongestionControllerExperiment::GetBbrExperimentConfig() { &config.probe_rtt_congestion_window_gain) == 17) { return config; } else { - return rtc::nullopt; + return absl::nullopt; } } diff --git a/rtc_base/experiments/congestion_controller_experiment.h b/rtc_base/experiments/congestion_controller_experiment.h index eba8926e58..5428a4f894 100644 --- a/rtc_base/experiments/congestion_controller_experiment.h +++ b/rtc_base/experiments/congestion_controller_experiment.h @@ -34,7 +34,7 @@ class CongestionControllerExperiment { }; static bool BbrControllerEnabled(); static bool InjectedControllerEnabled(); - static rtc::Optional GetBbrExperimentConfig(); + static absl::optional GetBbrExperimentConfig(); }; } // namespace webrtc diff --git a/rtc_base/experiments/field_trial_parser.cc b/rtc_base/experiments/field_trial_parser.cc index d2a3addae3..4ea603f931 100644 --- a/rtc_base/experiments/field_trial_parser.cc +++ b/rtc_base/experiments/field_trial_parser.cc @@ -47,7 +47,7 @@ void ParseFieldTrial( int key_end = std::min(val_end, colon_pos); int val_begin = key_end + 1; std::string key = trial_string.substr(i, key_end - i); - rtc::Optional opt_value; + absl::optional opt_value; if (val_end >= val_begin) opt_value = trial_string.substr(val_begin, val_end - val_begin); i = val_end + 1; @@ -65,37 +65,37 @@ void ParseFieldTrial( } template <> -rtc::Optional ParseTypedParameter(std::string str) { +absl::optional ParseTypedParameter(std::string str) { if (str == "true" || str == "1") { return true; } else if (str == "false" || str == "0") { return false; } - return rtc::nullopt; + return absl::nullopt; } template <> -rtc::Optional ParseTypedParameter(std::string str) { +absl::optional ParseTypedParameter(std::string str) { double value; if (sscanf(str.c_str(), "%lf", &value) == 1) { return value; } else { - return rtc::nullopt; + return absl::nullopt; } } template <> -rtc::Optional ParseTypedParameter(std::string str) { +absl::optional ParseTypedParameter(std::string str) { int value; if (sscanf(str.c_str(), "%i", &value) == 1) { return value; } else { - return rtc::nullopt; + return absl::nullopt; } } template <> -rtc::Optional ParseTypedParameter(std::string str) { +absl::optional ParseTypedParameter(std::string str) { return std::move(str); } @@ -108,10 +108,10 @@ bool FieldTrialFlag::Get() const { return value_; } -bool FieldTrialFlag::Parse(rtc::Optional str_value) { +bool FieldTrialFlag::Parse(absl::optional str_value) { // Only set the flag if there is no argument provided. if (str_value) { - rtc::Optional opt_value = ParseTypedParameter(*str_value); + absl::optional opt_value = ParseTypedParameter(*str_value); if (!opt_value) return false; value_ = *opt_value; diff --git a/rtc_base/experiments/field_trial_parser.h b/rtc_base/experiments/field_trial_parser.h index ba604993c7..ff00b90f36 100644 --- a/rtc_base/experiments/field_trial_parser.h +++ b/rtc_base/experiments/field_trial_parser.h @@ -13,7 +13,7 @@ #include #include #include -#include "api/optional.h" +#include "absl/types/optional.h" // Field trial parser functionality. Provides funcitonality to parse field trial // argument strings in key:value format. Each parameter is described using @@ -39,7 +39,7 @@ class FieldTrialParameterInterface { friend void ParseFieldTrial( std::initializer_list fields, std::string raw_string); - virtual bool Parse(rtc::Optional str_value) = 0; + virtual bool Parse(absl::optional str_value) = 0; std::string Key() const; private: @@ -52,10 +52,10 @@ void ParseFieldTrial( std::initializer_list fields, std::string raw_string); -// Specialize this in code file for custom types. Should return rtc::nullopt if +// Specialize this in code file for custom types. Should return absl::nullopt if // the given string cannot be properly parsed. template -rtc::Optional ParseTypedParameter(std::string); +absl::optional ParseTypedParameter(std::string); // This class uses the ParseTypedParameter function to implement a parameter // implementation with an enforced default value. @@ -68,9 +68,9 @@ class FieldTrialParameter : public FieldTrialParameterInterface { operator T() const { return Get(); } protected: - bool Parse(rtc::Optional str_value) override { + bool Parse(absl::optional str_value) override { if (str_value) { - rtc::Optional value = ParseTypedParameter(*str_value); + absl::optional value = ParseTypedParameter(*str_value); if (value.has_value()) { value_ = value.value(); return true; @@ -84,31 +84,31 @@ class FieldTrialParameter : public FieldTrialParameterInterface { }; // This class uses the ParseTypedParameter function to implement an optional -// parameter implementation that can default to rtc::nullopt. +// parameter implementation that can default to absl::nullopt. template class FieldTrialOptional : public FieldTrialParameterInterface { public: explicit FieldTrialOptional(std::string key) : FieldTrialParameterInterface(key) {} - FieldTrialOptional(std::string key, rtc::Optional default_value) + FieldTrialOptional(std::string key, absl::optional default_value) : FieldTrialParameterInterface(key), value_(default_value) {} - rtc::Optional Get() const { return value_; } + absl::optional Get() const { return value_; } protected: - bool Parse(rtc::Optional str_value) override { + bool Parse(absl::optional str_value) override { if (str_value) { - rtc::Optional value = ParseTypedParameter(*str_value); + absl::optional value = ParseTypedParameter(*str_value); if (!value.has_value()) return false; value_ = value.value(); } else { - value_ = rtc::nullopt; + value_ = absl::nullopt; } return true; } private: - rtc::Optional value_; + absl::optional value_; }; // Equivalent to a FieldTrialParameter in the case that both key and value @@ -121,7 +121,7 @@ class FieldTrialFlag : public FieldTrialParameterInterface { bool Get() const; protected: - bool Parse(rtc::Optional str_value) override; + bool Parse(absl::optional str_value) override; private: bool value_; diff --git a/rtc_base/experiments/field_trial_parser_unittest.cc b/rtc_base/experiments/field_trial_parser_unittest.cc index 6c343fc122..73bddfdee0 100644 --- a/rtc_base/experiments/field_trial_parser_unittest.cc +++ b/rtc_base/experiments/field_trial_parser_unittest.cc @@ -43,14 +43,14 @@ enum class CustomEnum { // Providing a custom parser for an enum can make the trial string easier to // read, but also adds more code and makes the string more verbose. template <> -rtc::Optional ParseTypedParameter(std::string str) { +absl::optional ParseTypedParameter(std::string str) { if (str == "default") return CustomEnum::kDefault; else if (str == "red") return CustomEnum::kRed; else if (str == "blue") return CustomEnum::kBlue; - return rtc::nullopt; + return absl::nullopt; } TEST(FieldTrialParserTest, ParsesValidParameters) { @@ -104,7 +104,7 @@ TEST(FieldTrialParserTest, IgnoresInvalid) { EXPECT_EQ(exp.hash.Get(), "a80"); } TEST(FieldTrialParserTest, ParsesOptionalParameters) { - FieldTrialOptional max_count("c", rtc::nullopt); + FieldTrialOptional max_count("c", absl::nullopt); ParseFieldTrial({&max_count}, ""); EXPECT_FALSE(max_count.Get().has_value()); ParseFieldTrial({&max_count}, "c:10"); diff --git a/rtc_base/experiments/field_trial_units.cc b/rtc_base/experiments/field_trial_units.cc index 94af4a72b3..f53978b211 100644 --- a/rtc_base/experiments/field_trial_units.cc +++ b/rtc_base/experiments/field_trial_units.cc @@ -12,7 +12,7 @@ #include #include -#include "api/optional.h" +#include "absl/types/optional.h" // Large enough to fit "seconds", the longest supported unit name. #define RTC_TRIAL_UNIT_LENGTH_STR "7" @@ -26,7 +26,7 @@ struct ValueWithUnit { std::string unit; }; -rtc::Optional ParseValueWithUnit(std::string str) { +absl::optional ParseValueWithUnit(std::string str) { if (str == "inf") { return ValueWithUnit{std::numeric_limits::infinity(), ""}; } else if (str == "-inf") { @@ -40,13 +40,13 @@ rtc::Optional ParseValueWithUnit(std::string str) { return ValueWithUnit{double_val, unit_char}; } } - return rtc::nullopt; + return absl::nullopt; } } // namespace template <> -rtc::Optional ParseTypedParameter(std::string str) { - rtc::Optional result = ParseValueWithUnit(str); +absl::optional ParseTypedParameter(std::string str) { + absl::optional result = ParseValueWithUnit(str); if (result) { if (result->unit.empty() || result->unit == "kbps") { return DataRate::kbps(result->value); @@ -54,22 +54,22 @@ rtc::Optional ParseTypedParameter(std::string str) { return DataRate::bps(result->value); } } - return rtc::nullopt; + return absl::nullopt; } template <> -rtc::Optional ParseTypedParameter(std::string str) { - rtc::Optional result = ParseValueWithUnit(str); +absl::optional ParseTypedParameter(std::string str) { + absl::optional result = ParseValueWithUnit(str); if (result) { if (result->unit.empty() || result->unit == "bytes") return DataSize::bytes(result->value); } - return rtc::nullopt; + return absl::nullopt; } template <> -rtc::Optional ParseTypedParameter(std::string str) { - rtc::Optional result = ParseValueWithUnit(str); +absl::optional ParseTypedParameter(std::string str) { + absl::optional result = ParseValueWithUnit(str); if (result) { if (result->unit == "s" || result->unit == "seconds") { return TimeDelta::seconds(result->value); @@ -79,7 +79,7 @@ rtc::Optional ParseTypedParameter(std::string str) { return TimeDelta::ms(result->value); } } - return rtc::nullopt; + return absl::nullopt; } template class FieldTrialParameter; diff --git a/rtc_base/experiments/field_trial_units_unittest.cc b/rtc_base/experiments/field_trial_units_unittest.cc index da76f5ad89..1a2b75d646 100644 --- a/rtc_base/experiments/field_trial_units_unittest.cc +++ b/rtc_base/experiments/field_trial_units_unittest.cc @@ -21,7 +21,7 @@ struct DummyExperiment { FieldTrialParameter period = FieldTrialParameter("p", TimeDelta::ms(100)); FieldTrialOptional max_buffer = - FieldTrialOptional("b", rtc::nullopt); + FieldTrialOptional("b", absl::nullopt); explicit DummyExperiment(std::string field_trial) { ParseFieldTrial({&target_rate, &max_buffer, &period}, field_trial); diff --git a/rtc_base/experiments/quality_scaling_experiment.cc b/rtc_base/experiments/quality_scaling_experiment.cc index 8c999543c2..c13de3f46b 100644 --- a/rtc_base/experiments/quality_scaling_experiment.cc +++ b/rtc_base/experiments/quality_scaling_experiment.cc @@ -23,14 +23,14 @@ constexpr int kMaxVp9Qp = 255; constexpr int kMaxH264Qp = 51; constexpr int kMaxGenericQp = 255; -rtc::Optional GetThresholds(int low, - int high, - int max) { +absl::optional GetThresholds(int low, + int high, + int max) { if (low < kMinQp || high > max || high < low) - return rtc::nullopt; + return absl::nullopt; RTC_LOG(LS_INFO) << "QP thresholds: low: " << low << ", high: " << high; - return rtc::Optional( + return absl::optional( VideoEncoder::QpThresholds(low, high)); } } // namespace @@ -39,11 +39,11 @@ bool QualityScalingExperiment::Enabled() { return webrtc::field_trial::IsEnabled(kFieldTrial); } -rtc::Optional +absl::optional QualityScalingExperiment::ParseSettings() { const std::string group = webrtc::field_trial::FindFullName(kFieldTrial); if (group.empty()) - return rtc::nullopt; + return absl::nullopt; Settings s; if (sscanf(group.c_str(), "Enabled-%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%d", @@ -51,16 +51,16 @@ QualityScalingExperiment::ParseSettings() { &s.h264_high, &s.generic_low, &s.generic_high, &s.alpha_high, &s.alpha_low, &s.drop) != 11) { RTC_LOG(LS_WARNING) << "Invalid number of parameters provided."; - return rtc::nullopt; + return absl::nullopt; } return s; } -rtc::Optional +absl::optional QualityScalingExperiment::GetQpThresholds(VideoCodecType codec_type) { const auto settings = ParseSettings(); if (!settings) - return rtc::nullopt; + return absl::nullopt; switch (codec_type) { case kVideoCodecVP8: @@ -73,7 +73,7 @@ QualityScalingExperiment::GetQpThresholds(VideoCodecType codec_type) { return GetThresholds(settings->generic_low, settings->generic_high, kMaxGenericQp); default: - return rtc::nullopt; + return absl::nullopt; } } diff --git a/rtc_base/experiments/quality_scaling_experiment.h b/rtc_base/experiments/quality_scaling_experiment.h index 6f24d6bfd7..80a25ef1ee 100644 --- a/rtc_base/experiments/quality_scaling_experiment.h +++ b/rtc_base/experiments/quality_scaling_experiment.h @@ -10,7 +10,7 @@ #ifndef RTC_BASE_EXPERIMENTS_QUALITY_SCALING_EXPERIMENT_H_ #define RTC_BASE_EXPERIMENTS_QUALITY_SCALING_EXPERIMENT_H_ -#include "api/optional.h" +#include "absl/types/optional.h" #include "api/video_codecs/video_encoder.h" #include "common_types.h" // NOLINT(build/include) @@ -44,10 +44,10 @@ class QualityScalingExperiment { static bool Enabled(); // Returns settings from field trial. - static rtc::Optional ParseSettings(); + static absl::optional ParseSettings(); // Returns QpThresholds for the |codec_type|. - static rtc::Optional GetQpThresholds( + static absl::optional GetQpThresholds( VideoCodecType codec_type); // Returns parsed values. If the parsing fails, default values are returned. diff --git a/rtc_base/numerics/histogram_percentile_counter.cc b/rtc_base/numerics/histogram_percentile_counter.cc index 87ebd53d47..4bc8cb0dec 100644 --- a/rtc_base/numerics/histogram_percentile_counter.cc +++ b/rtc_base/numerics/histogram_percentile_counter.cc @@ -48,12 +48,12 @@ void HistogramPercentileCounter::Add(uint32_t value) { Add(value, 1); } -rtc::Optional HistogramPercentileCounter::GetPercentile( +absl::optional HistogramPercentileCounter::GetPercentile( float fraction) { RTC_CHECK_LE(fraction, 1.0); RTC_CHECK_GE(fraction, 0.0); if (total_elements_ == 0) - return rtc::nullopt; + return absl::nullopt; size_t elements_to_skip = static_cast( std::max(0.0f, std::ceil(total_elements_ * fraction) - 1)); if (elements_to_skip >= total_elements_) @@ -73,7 +73,7 @@ rtc::Optional HistogramPercentileCounter::GetPercentile( } } RTC_NOTREACHED(); - return rtc::nullopt; + return absl::nullopt; } } // namespace rtc diff --git a/rtc_base/numerics/histogram_percentile_counter.h b/rtc_base/numerics/histogram_percentile_counter.h index 4ad2e5377d..7e5743fc62 100644 --- a/rtc_base/numerics/histogram_percentile_counter.h +++ b/rtc_base/numerics/histogram_percentile_counter.h @@ -15,7 +15,7 @@ #include #include -#include "api/optional.h" +#include "absl/types/optional.h" namespace rtc { // Calculates percentiles on the stream of data. Use |Add| methods to add new @@ -30,7 +30,7 @@ class HistogramPercentileCounter { void Add(uint32_t value, size_t count); void Add(const HistogramPercentileCounter& other); // Argument should be from 0 to 1. - rtc::Optional GetPercentile(float fraction); + absl::optional GetPercentile(float fraction); private: std::vector histogram_low_; diff --git a/rtc_base/numerics/moving_max_counter.h b/rtc_base/numerics/moving_max_counter.h index 4595cf3551..6c6286dfd4 100644 --- a/rtc_base/numerics/moving_max_counter.h +++ b/rtc_base/numerics/moving_max_counter.h @@ -17,7 +17,7 @@ #include #include -#include "api/optional.h" +#include "absl/types/optional.h" #include "rtc_base/checks.h" #include "rtc_base/constructormagic.h" @@ -40,7 +40,7 @@ class MovingMaxCounter { // Advances the current time, and returns the maximum sample in the time // window ending at the current time. The new current time must be at least as // large as the old current time. - rtc::Optional Max(int64_t current_time_ms); + absl::optional Max(int64_t current_time_ms); void Reset(); private: @@ -83,9 +83,9 @@ void MovingMaxCounter::Add(const T& sample, int64_t current_time_ms) { } template -rtc::Optional MovingMaxCounter::Max(int64_t current_time_ms) { +absl::optional MovingMaxCounter::Max(int64_t current_time_ms) { RollWindow(current_time_ms); - rtc::Optional res; + absl::optional res; if (!samples_.empty()) { res.emplace(samples_.front().second); } diff --git a/rtc_base/numerics/sample_counter.cc b/rtc_base/numerics/sample_counter.cc index 037fddc9df..d9244c385a 100644 --- a/rtc_base/numerics/sample_counter.cc +++ b/rtc_base/numerics/sample_counter.cc @@ -54,24 +54,24 @@ void SampleCounter::Add(const SampleCounter& other) { max_ = other.max_; } -rtc::Optional SampleCounter::Avg(int64_t min_required_samples) const { +absl::optional SampleCounter::Avg(int64_t min_required_samples) const { RTC_DCHECK_GT(min_required_samples, 0); if (num_samples_ < min_required_samples) - return rtc::nullopt; + return absl::nullopt; return rtc::dchecked_cast(sum_ / num_samples_); } -rtc::Optional SampleCounter::Variance( +absl::optional SampleCounter::Variance( int64_t min_required_samples) const { RTC_DCHECK_GT(min_required_samples, 0); if (num_samples_ < min_required_samples) - return rtc::nullopt; + return absl::nullopt; // E[(x-mean)^2] = E[x^2] - mean^2 int64_t mean = sum_ / num_samples_; return sum_squared_ / num_samples_ - mean * mean; } -rtc::Optional SampleCounter::Max() const { +absl::optional SampleCounter::Max() const { return max_; } diff --git a/rtc_base/numerics/sample_counter.h b/rtc_base/numerics/sample_counter.h index 0de6f25f19..643754e8f9 100644 --- a/rtc_base/numerics/sample_counter.h +++ b/rtc_base/numerics/sample_counter.h @@ -11,7 +11,7 @@ #ifndef RTC_BASE_NUMERICS_SAMPLE_COUNTER_H_ #define RTC_BASE_NUMERICS_SAMPLE_COUNTER_H_ -#include "api/optional.h" +#include "absl/types/optional.h" namespace rtc { @@ -22,9 +22,9 @@ class SampleCounter { SampleCounter(); ~SampleCounter(); void Add(int sample); - rtc::Optional Avg(int64_t min_required_samples) const; - rtc::Optional Variance(int64_t min_required_samples) const; - rtc::Optional Max() const; + absl::optional Avg(int64_t min_required_samples) const; + absl::optional Variance(int64_t min_required_samples) const; + absl::optional Max() const; void Reset(); // Adds all the samples from the |other| SampleCounter as if they were all // individually added using |Add(int)| method. @@ -34,7 +34,7 @@ class SampleCounter { int64_t sum_ = 0; int64_t sum_squared_ = 0; int64_t num_samples_ = 0; - rtc::Optional max_; + absl::optional max_; }; } // namespace rtc diff --git a/rtc_base/numerics/sample_counter_unittest.cc b/rtc_base/numerics/sample_counter_unittest.cc index 844ea4ac6a..898f00cc62 100644 --- a/rtc_base/numerics/sample_counter_unittest.cc +++ b/rtc_base/numerics/sample_counter_unittest.cc @@ -23,9 +23,9 @@ namespace rtc { TEST(SampleCounterTest, ProcessesNoSamples) { constexpr int kMinSamples = 1; SampleCounter counter; - EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt)); - EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt)); - EXPECT_THAT(counter.Max(), Eq(rtc::nullopt)); + EXPECT_THAT(counter.Avg(kMinSamples), Eq(absl::nullopt)); + EXPECT_THAT(counter.Avg(kMinSamples), Eq(absl::nullopt)); + EXPECT_THAT(counter.Max(), Eq(absl::nullopt)); } TEST(SampleCounterTest, NotEnoughSamples) { @@ -34,8 +34,8 @@ TEST(SampleCounterTest, NotEnoughSamples) { for (int value : {1, 2, 3, 4, 5}) { counter.Add(value); } - EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt)); - EXPECT_THAT(counter.Avg(kMinSamples), Eq(rtc::nullopt)); + EXPECT_THAT(counter.Avg(kMinSamples), Eq(absl::nullopt)); + EXPECT_THAT(counter.Avg(kMinSamples), Eq(absl::nullopt)); EXPECT_THAT(counter.Max(), Eq(5)); } diff --git a/rtc_base/numerics/sequence_number_util.h b/rtc_base/numerics/sequence_number_util.h index 9e4b8446f5..c55513a3e4 100644 --- a/rtc_base/numerics/sequence_number_util.h +++ b/rtc_base/numerics/sequence_number_util.h @@ -14,7 +14,7 @@ #include #include -#include "api/optional.h" +#include "absl/types/optional.h" #include "rtc_base/numerics/mod_ops.h" #include "rtc_base/numerics/safe_compare.h" @@ -120,7 +120,7 @@ class SeqNumUnwrapper { private: uint64_t last_unwrapped_; - rtc::Optional last_value_; + absl::optional last_value_; }; } // namespace webrtc diff --git a/rtc_base/rate_limiter.cc b/rtc_base/rate_limiter.cc index 34e0a4064d..0343f256b2 100644 --- a/rtc_base/rate_limiter.cc +++ b/rtc_base/rate_limiter.cc @@ -29,7 +29,7 @@ RateLimiter::~RateLimiter() {} bool RateLimiter::TryUseRate(size_t packet_size_bytes) { rtc::CritScope cs(&lock_); int64_t now_ms = clock_->TimeInMilliseconds(); - rtc::Optional current_rate = current_rate_.Rate(now_ms); + absl::optional current_rate = current_rate_.Rate(now_ms); if (current_rate) { // If there is a current rate, check if adding bytes would cause maximum // bitrate target to be exceeded. If there is NOT a valid current rate, diff --git a/rtc_base/rate_statistics.cc b/rtc_base/rate_statistics.cc index e2d6b113df..9b1ff8fc9a 100644 --- a/rtc_base/rate_statistics.cc +++ b/rtc_base/rate_statistics.cc @@ -61,7 +61,7 @@ void RateStatistics::Update(size_t count, int64_t now_ms) { ++num_samples_; } -rtc::Optional RateStatistics::Rate(int64_t now_ms) const { +absl::optional RateStatistics::Rate(int64_t now_ms) const { // Yeah, this const_cast ain't pretty, but the alternative is to declare most // of the members as mutable... const_cast(this)->EraseOld(now_ms); @@ -71,7 +71,7 @@ rtc::Optional RateStatistics::Rate(int64_t now_ms) const { int64_t active_window_size = now_ms - oldest_time_ + 1; if (num_samples_ == 0 || active_window_size <= 1 || (num_samples_ <= 1 && active_window_size < current_window_size_ms_)) { - return rtc::nullopt; + return absl::nullopt; } float scale = scale_ / active_window_size; diff --git a/rtc_base/rate_statistics.h b/rtc_base/rate_statistics.h index aa285298a6..fe5ae824a4 100644 --- a/rtc_base/rate_statistics.h +++ b/rtc_base/rate_statistics.h @@ -13,7 +13,7 @@ #include -#include "api/optional.h" +#include "absl/types/optional.h" #include "typedefs.h" // NOLINT(build/include) namespace webrtc { @@ -42,7 +42,7 @@ class RateStatistics { // from a monotonic clock. Ie, it doesn't matter if this call moves the // window, since any subsequent call to Update or Rate would still have moved // the window as much or more. - rtc::Optional Rate(int64_t now_ms) const; + absl::optional Rate(int64_t now_ms) const; // Update the size of the averaging window. The maximum allowed value for // window_size_ms is max_window_size_ms as supplied in the constructor. diff --git a/rtc_base/rate_statistics_unittest.cc b/rtc_base/rate_statistics_unittest.cc index 51249b14ea..62f1486d50 100644 --- a/rtc_base/rate_statistics_unittest.cc +++ b/rtc_base/rate_statistics_unittest.cc @@ -53,7 +53,7 @@ TEST_F(RateStatisticsTest, TestStrictMode) { // Approximately 1200 kbps expected. Not exact since when packets // are removed we will jump 10 ms to the next packet. if (i > kInterval) { - rtc::Optional rate = stats_.Rate(now_ms); + absl::optional rate = stats_.Rate(now_ms); EXPECT_TRUE(static_cast(rate)); uint32_t samples = i / kInterval + 1; uint64_t total_bits = samples * kPacketSize * 8; @@ -78,7 +78,7 @@ TEST_F(RateStatisticsTest, IncreasingThenDecreasingBitrate) { const uint32_t kExpectedBitrate = 8000000; // 1000 bytes per millisecond until plateau is reached. int prev_error = kExpectedBitrate; - rtc::Optional bitrate; + absl::optional bitrate; while (++now_ms < 10000) { stats_.Update(1000, now_ms); bitrate = stats_.Rate(now_ms); @@ -102,7 +102,7 @@ TEST_F(RateStatisticsTest, IncreasingThenDecreasingBitrate) { // Zero bytes per millisecond until 0 is reached. while (++now_ms < 20000) { stats_.Update(0, now_ms); - rtc::Optional new_bitrate = stats_.Rate(now_ms); + absl::optional new_bitrate = stats_.Rate(now_ms); if (static_cast(new_bitrate) && *new_bitrate != *bitrate) { // New bitrate must be lower than previous one. EXPECT_LT(*new_bitrate, *bitrate); @@ -130,7 +130,7 @@ TEST_F(RateStatisticsTest, ResetAfterSilence) { const uint32_t kExpectedBitrate = 8000000; // 1000 bytes per millisecond until the window has been filled. int prev_error = kExpectedBitrate; - rtc::Optional bitrate; + absl::optional bitrate; while (++now_ms < 10000) { stats_.Update(1000, now_ms); bitrate = stats_.Rate(now_ms); @@ -213,7 +213,7 @@ TEST_F(RateStatisticsTest, RespectsWindowSizeEdges) { // Window size should be full, and the single data point should be accepted. ++now_ms; - rtc::Optional bitrate = stats_.Rate(now_ms); + absl::optional bitrate = stats_.Rate(now_ms); EXPECT_TRUE(static_cast(bitrate)); EXPECT_EQ(1000 * 8u, *bitrate); @@ -239,7 +239,7 @@ TEST_F(RateStatisticsTest, HandlesZeroCounts) { stats_.Update(kWindowMs, now_ms); now_ms += kWindowMs - 1; stats_.Update(0, now_ms); - rtc::Optional bitrate = stats_.Rate(now_ms); + absl::optional bitrate = stats_.Rate(now_ms); EXPECT_TRUE(static_cast(bitrate)); EXPECT_EQ(1000 * 8u, *bitrate); @@ -262,7 +262,7 @@ TEST_F(RateStatisticsTest, HandlesQuietPeriods) { stats_.Update(0, now_ms); now_ms += kWindowMs - 1; - rtc::Optional bitrate = stats_.Rate(now_ms); + absl::optional bitrate = stats_.Rate(now_ms); EXPECT_TRUE(static_cast(bitrate)); EXPECT_EQ(0u, *bitrate); diff --git a/rtc_base/rtccertificategenerator.cc b/rtc_base/rtccertificategenerator.cc index c9847464d4..0b51c611ba 100644 --- a/rtc_base/rtccertificategenerator.cc +++ b/rtc_base/rtccertificategenerator.cc @@ -42,7 +42,7 @@ class RTCCertificateGenerationTask : public RefCountInterface, Thread* signaling_thread, Thread* worker_thread, const KeyParams& key_params, - const Optional& expires_ms, + const absl::optional& expires_ms, const scoped_refptr& callback) : signaling_thread_(signaling_thread), worker_thread_(worker_thread), @@ -94,7 +94,7 @@ class RTCCertificateGenerationTask : public RefCountInterface, Thread* const signaling_thread_; Thread* const worker_thread_; const KeyParams key_params_; - const Optional expires_ms_; + const absl::optional expires_ms_; const scoped_refptr callback_; scoped_refptr certificate_; }; @@ -104,7 +104,7 @@ class RTCCertificateGenerationTask : public RefCountInterface, // static scoped_refptr RTCCertificateGenerator::GenerateCertificate( const KeyParams& key_params, - const Optional& expires_ms) { + const absl::optional& expires_ms) { if (!key_params.IsValid()) return nullptr; SSLIdentity* identity; @@ -139,7 +139,7 @@ RTCCertificateGenerator::RTCCertificateGenerator(Thread* signaling_thread, void RTCCertificateGenerator::GenerateCertificateAsync( const KeyParams& key_params, - const Optional& expires_ms, + const absl::optional& expires_ms, const scoped_refptr& callback) { RTC_DCHECK(signaling_thread_->IsCurrent()); RTC_DCHECK(callback); diff --git a/rtc_base/rtccertificategenerator.h b/rtc_base/rtccertificategenerator.h index df1be441e5..a6c503a9f2 100644 --- a/rtc_base/rtccertificategenerator.h +++ b/rtc_base/rtccertificategenerator.h @@ -11,7 +11,7 @@ #ifndef RTC_BASE_RTCCERTIFICATEGENERATOR_H_ #define RTC_BASE_RTCCERTIFICATEGENERATOR_H_ -#include "api/optional.h" +#include "absl/types/optional.h" #include "rtc_base/refcount.h" #include "rtc_base/rtccertificate.h" #include "rtc_base/scoped_ref_ptr.h" @@ -43,7 +43,7 @@ class RTCCertificateGeneratorInterface { // its own restrictions on the expiration time. virtual void GenerateCertificateAsync( const KeyParams& key_params, - const Optional& expires_ms, + const absl::optional& expires_ms, const scoped_refptr& callback) = 0; }; @@ -60,7 +60,7 @@ class RTCCertificateGenerator : public RTCCertificateGeneratorInterface { // specified, a default expiration time is used. static scoped_refptr GenerateCertificate( const KeyParams& key_params, - const Optional& expires_ms); + const absl::optional& expires_ms); RTCCertificateGenerator(Thread* signaling_thread, Thread* worker_thread); ~RTCCertificateGenerator() override {} @@ -72,7 +72,7 @@ class RTCCertificateGenerator : public RTCCertificateGeneratorInterface { // specified, a default expiration time is used. void GenerateCertificateAsync( const KeyParams& key_params, - const Optional& expires_ms, + const absl::optional& expires_ms, const scoped_refptr& callback) override; private: diff --git a/rtc_base/rtccertificategenerator_unittest.cc b/rtc_base/rtccertificategenerator_unittest.cc index baf0475144..3929128960 100644 --- a/rtc_base/rtccertificategenerator_unittest.cc +++ b/rtc_base/rtccertificategenerator_unittest.cc @@ -12,7 +12,7 @@ #include -#include "api/optional.h" +#include "absl/types/optional.h" #include "rtc_base/checks.h" #include "rtc_base/gunit.h" #include "rtc_base/logging.h" @@ -79,19 +79,19 @@ class RTCCertificateGeneratorTest : public testing::Test { }; TEST_F(RTCCertificateGeneratorTest, GenerateECDSA) { - EXPECT_TRUE(RTCCertificateGenerator::GenerateCertificate( - KeyParams::ECDSA(), Optional())); + EXPECT_TRUE(RTCCertificateGenerator::GenerateCertificate(KeyParams::ECDSA(), + absl::nullopt)); } TEST_F(RTCCertificateGeneratorTest, GenerateRSA) { - EXPECT_TRUE(RTCCertificateGenerator::GenerateCertificate( - KeyParams::RSA(), Optional())); + EXPECT_TRUE(RTCCertificateGenerator::GenerateCertificate(KeyParams::RSA(), + absl::nullopt)); } TEST_F(RTCCertificateGeneratorTest, GenerateAsyncECDSA) { EXPECT_FALSE(fixture_->certificate()); - fixture_->generator()->GenerateCertificateAsync( - KeyParams::ECDSA(), Optional(), fixture_); + fixture_->generator()->GenerateCertificateAsync(KeyParams::ECDSA(), + absl::nullopt, fixture_); // Until generation has completed, the certificate is null. Since this is an // async call, generation must not have completed until we process messages // posted to this thread (which is done by |EXPECT_TRUE_WAIT|). @@ -110,15 +110,14 @@ TEST_F(RTCCertificateGeneratorTest, GenerateWithExpires) { // Generate a certificate that expires immediately. scoped_refptr cert_a = - RTCCertificateGenerator::GenerateCertificate(KeyParams::ECDSA(), - Optional(0)); + RTCCertificateGenerator::GenerateCertificate(KeyParams::ECDSA(), 0); EXPECT_TRUE(cert_a); // Generate a certificate that expires in one minute. const uint64_t kExpiresMs = 60000; scoped_refptr cert_b = - RTCCertificateGenerator::GenerateCertificate( - KeyParams::ECDSA(), Optional(kExpiresMs)); + RTCCertificateGenerator::GenerateCertificate(KeyParams::ECDSA(), + kExpiresMs); EXPECT_TRUE(cert_b); // Verify that |cert_b| expires approximately |kExpiresMs| after |cert_a| @@ -133,11 +132,11 @@ TEST_F(RTCCertificateGeneratorTest, GenerateWithInvalidParamsShouldFail) { KeyParams invalid_params = KeyParams::RSA(0, 0); EXPECT_FALSE(invalid_params.IsValid()); - EXPECT_FALSE(RTCCertificateGenerator::GenerateCertificate( - invalid_params, Optional())); + EXPECT_FALSE(RTCCertificateGenerator::GenerateCertificate(invalid_params, + absl::nullopt)); - fixture_->generator()->GenerateCertificateAsync( - invalid_params, Optional(), fixture_); + fixture_->generator()->GenerateCertificateAsync(invalid_params, absl::nullopt, + fixture_); EXPECT_TRUE_WAIT(fixture_->GenerateAsyncCompleted(), kGenerationTimeoutMs); EXPECT_FALSE(fixture_->certificate()); } diff --git a/rtc_base/socket.h b/rtc_base/socket.h index 5950989e34..b8290bb139 100644 --- a/rtc_base/socket.h +++ b/rtc_base/socket.h @@ -25,7 +25,7 @@ #include "rtc_base/win32.h" #endif -#include "api/optional.h" +#include "absl/types/optional.h" #include "rtc_base/constructormagic.h" #include "rtc_base/socketaddress.h" @@ -147,8 +147,8 @@ struct PacketInfo { PacketType packet_type = PacketType::kUnknown; PacketInfoProtocolType protocol = PacketInfoProtocolType::kUnknown; - // A unique id assigned by the network manager, and rtc::nullopt if not set. - rtc::Optional network_id; + // A unique id assigned by the network manager, and absl::nullopt if not set. + absl::optional network_id; size_t packet_size_bytes = 0; size_t turn_overhead_bytes = 0; SocketAddress local_socket_address; diff --git a/rtc_base/string_to_number.cc b/rtc_base/string_to_number.cc index fe17f3433b..06ac9e9acd 100644 --- a/rtc_base/string_to_number.cc +++ b/rtc_base/string_to_number.cc @@ -18,7 +18,7 @@ namespace rtc { namespace string_to_number_internal { -rtc::Optional ParseSigned(const char* str, int base) { +absl::optional ParseSigned(const char* str, int base) { RTC_DCHECK(str); if (isdigit(str[0]) || str[0] == '-') { char* end = nullptr; @@ -28,10 +28,10 @@ rtc::Optional ParseSigned(const char* str, int base) { return value; } } - return rtc::nullopt; + return absl::nullopt; } -rtc::Optional ParseUnsigned(const char* str, int base) { +absl::optional ParseUnsigned(const char* str, int base) { RTC_DCHECK(str); if (isdigit(str[0]) || str[0] == '-') { // Explicitly discard negative values. std::strtoull parsing causes unsigned @@ -45,7 +45,7 @@ rtc::Optional ParseUnsigned(const char* str, int base) { return value; } } - return rtc::nullopt; + return absl::nullopt; } } // namespace string_to_number_internal diff --git a/rtc_base/string_to_number.h b/rtc_base/string_to_number.h index 3a7ca58b89..9b4fa671a3 100644 --- a/rtc_base/string_to_number.h +++ b/rtc_base/string_to_number.h @@ -14,7 +14,7 @@ #include #include -#include "api/optional.h" +#include "absl/types/optional.h" namespace rtc { @@ -25,8 +25,8 @@ namespace rtc { // are disabled in WebRTC. // // Integers are parsed using one of the following functions: -// rtc::Optional StringToNumber(const char* str, int base = 10); -// rtc::Optional StringToNumber(const std::string& str, +// absl::optional StringToNumber(const char* str, int base = 10); +// absl::optional StringToNumber(const std::string& str, // int base = 10); // // These functions parse a value from the beginning of a string into one of the @@ -46,13 +46,13 @@ namespace string_to_number_internal { using unsigned_type = unsigned long long; // NOLINT(runtime/int) using signed_type = long long; // NOLINT(runtime/int) -rtc::Optional ParseSigned(const char* str, int base); -rtc::Optional ParseUnsigned(const char* str, int base); +absl::optional ParseSigned(const char* str, int base); +absl::optional ParseUnsigned(const char* str, int base); } // namespace string_to_number_internal template typename std::enable_if::value && std::is_signed::value, - rtc::Optional>::type + absl::optional>::type StringToNumber(const char* str, int base = 10) { using string_to_number_internal::signed_type; static_assert( @@ -61,31 +61,31 @@ StringToNumber(const char* str, int base = 10) { std::numeric_limits::lowest() >= std::numeric_limits::lowest(), "StringToNumber only supports signed integers as large as long long int"); - rtc::Optional value = + absl::optional value = string_to_number_internal::ParseSigned(str, base); if (value && *value >= std::numeric_limits::lowest() && *value <= std::numeric_limits::max()) { return static_cast(*value); } - return rtc::nullopt; + return absl::nullopt; } template typename std::enable_if::value && std::is_unsigned::value, - rtc::Optional>::type + absl::optional>::type StringToNumber(const char* str, int base = 10) { using string_to_number_internal::unsigned_type; static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), "StringToNumber only supports unsigned integers as large as " "unsigned long long int"); - rtc::Optional value = + absl::optional value = string_to_number_internal::ParseUnsigned(str, base); if (value && *value <= std::numeric_limits::max()) { return static_cast(*value); } - return rtc::nullopt; + return absl::nullopt; } // The std::string overloads only exists if there is a matching const char* diff --git a/rtc_base/string_to_number_unittest.cc b/rtc_base/string_to_number_unittest.cc index 691b26f5c1..f7bf48421c 100644 --- a/rtc_base/string_to_number_unittest.cc +++ b/rtc_base/string_to_number_unittest.cc @@ -68,10 +68,10 @@ TYPED_TEST_P(BasicNumberTest, TestInvalidNumbers) { (min_value == 0) ? "-2" : (std::to_string(min_value) + "1"); // Make the large value approximately ten times larger than the maximum. const std::string too_large_string = std::to_string(max_value) + "1"; - EXPECT_EQ(rtc::nullopt, StringToNumber(too_low_string)); - EXPECT_EQ(rtc::nullopt, StringToNumber(too_low_string.c_str())); - EXPECT_EQ(rtc::nullopt, StringToNumber(too_large_string)); - EXPECT_EQ(rtc::nullopt, StringToNumber(too_large_string.c_str())); + EXPECT_EQ(absl::nullopt, StringToNumber(too_low_string)); + EXPECT_EQ(absl::nullopt, StringToNumber(too_low_string.c_str())); + EXPECT_EQ(absl::nullopt, StringToNumber(too_large_string)); + EXPECT_EQ(absl::nullopt, StringToNumber(too_large_string.c_str())); } TYPED_TEST_P(BasicNumberTest, TestInvalidInputs) { @@ -79,18 +79,18 @@ TYPED_TEST_P(BasicNumberTest, TestInvalidInputs) { const char kInvalidCharArray[] = "Invalid string containing 47"; const char kPlusMinusCharArray[] = "+-100"; const char kNumberFollowedByCruft[] = "640x480"; - EXPECT_EQ(rtc::nullopt, StringToNumber(kInvalidCharArray)); - EXPECT_EQ(rtc::nullopt, StringToNumber(std::string(kInvalidCharArray))); - EXPECT_EQ(rtc::nullopt, StringToNumber(kPlusMinusCharArray)); - EXPECT_EQ(rtc::nullopt, StringToNumber(std::string(kPlusMinusCharArray))); - EXPECT_EQ(rtc::nullopt, StringToNumber(kNumberFollowedByCruft)); - EXPECT_EQ(rtc::nullopt, + EXPECT_EQ(absl::nullopt, StringToNumber(kInvalidCharArray)); + EXPECT_EQ(absl::nullopt, StringToNumber(std::string(kInvalidCharArray))); + EXPECT_EQ(absl::nullopt, StringToNumber(kPlusMinusCharArray)); + EXPECT_EQ(absl::nullopt, StringToNumber(std::string(kPlusMinusCharArray))); + EXPECT_EQ(absl::nullopt, StringToNumber(kNumberFollowedByCruft)); + EXPECT_EQ(absl::nullopt, StringToNumber(std::string(kNumberFollowedByCruft))); - EXPECT_EQ(rtc::nullopt, StringToNumber(" 5")); - EXPECT_EQ(rtc::nullopt, StringToNumber(" - 5")); - EXPECT_EQ(rtc::nullopt, StringToNumber("- 5")); - EXPECT_EQ(rtc::nullopt, StringToNumber(" -5")); - EXPECT_EQ(rtc::nullopt, StringToNumber("5 ")); + EXPECT_EQ(absl::nullopt, StringToNumber(" 5")); + EXPECT_EQ(absl::nullopt, StringToNumber(" - 5")); + EXPECT_EQ(absl::nullopt, StringToNumber("- 5")); + EXPECT_EQ(absl::nullopt, StringToNumber(" -5")); + EXPECT_EQ(absl::nullopt, StringToNumber("5 ")); } REGISTER_TYPED_TEST_CASE_P(BasicNumberTest, @@ -105,10 +105,10 @@ INSTANTIATE_TYPED_TEST_CASE_P(StringToNumberTest_Integers, IntegerTypes); TEST(StringToNumberTest, TestSpecificValues) { - EXPECT_EQ(rtc::nullopt, StringToNumber("256")); - EXPECT_EQ(rtc::nullopt, StringToNumber("-256")); - EXPECT_EQ(rtc::nullopt, StringToNumber("256")); - EXPECT_EQ(rtc::nullopt, StringToNumber("-256")); + EXPECT_EQ(absl::nullopt, StringToNumber("256")); + EXPECT_EQ(absl::nullopt, StringToNumber("-256")); + EXPECT_EQ(absl::nullopt, StringToNumber("256")); + EXPECT_EQ(absl::nullopt, StringToNumber("-256")); } } // namespace rtc