From 5b8c0a2a1e33e3e2e9fdba1ab5316c80dc1e5ad7 Mon Sep 17 00:00:00 2001 From: Oskar Sundbom Date: Thu, 16 Nov 2017 10:56:55 +0100 Subject: [PATCH] Optional: Use nullopt and implicit construction in /modules/congestion_controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes places where we explicitly construct an Optional to instead use nullopt or the requisite value type only. This CL was uploaded by git cl split. Bug: None Change-Id: If2a98dc714d1755f07af1f70248cf41e4a9db750 Reviewed-on: https://webrtc-review.googlesource.com/23612 Reviewed-by: Björn Terelius Commit-Queue: Oskar Sundbom Cr-Commit-Position: refs/heads/master@{#20887} --- .../bitrate_estimator.cc | 4 ++-- .../delay_based_bwe_unittest.cc | 4 ++-- .../probe_bitrate_estimator.cc | 2 +- .../probe_controller_unittest.cc | 19 ++++++++----------- ...end_side_congestion_controller_unittest.cc | 2 +- .../trendline_estimator.cc | 4 ++-- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/modules/congestion_controller/bitrate_estimator.cc b/modules/congestion_controller/bitrate_estimator.cc index 482667d802..76c132bbe9 100644 --- a/modules/congestion_controller/bitrate_estimator.cc +++ b/modules/congestion_controller/bitrate_estimator.cc @@ -94,8 +94,8 @@ float BitrateEstimator::UpdateWindow(int64_t now_ms, rtc::Optional BitrateEstimator::bitrate_bps() const { if (bitrate_estimate_ < 0.f) - return rtc::Optional(); - return rtc::Optional(bitrate_estimate_ * 1000); + return rtc::nullopt; + return bitrate_estimate_ * 1000; } void BitrateEstimator::ExpectFastRateChange() { diff --git a/modules/congestion_controller/delay_based_bwe_unittest.cc b/modules/congestion_controller/delay_based_bwe_unittest.cc index 765504459f..e53667b16f 100644 --- a/modules/congestion_controller/delay_based_bwe_unittest.cc +++ b/modules/congestion_controller/delay_based_bwe_unittest.cc @@ -29,7 +29,7 @@ constexpr float kTargetUtilizationFraction = 0.95f; TEST_F(DelayBasedBweTest, NoCrashEmptyFeedback) { std::vector packet_feedback_vector; bitrate_estimator_->IncomingPacketFeedbackVector(packet_feedback_vector, - rtc::Optional()); + rtc::nullopt); } TEST_F(DelayBasedBweTest, NoCrashOnlyLostFeedback) { @@ -39,7 +39,7 @@ TEST_F(DelayBasedBweTest, NoCrashOnlyLostFeedback) { packet_feedback_vector.push_back( PacketFeedback(-1, -1, 1, 1500, PacedPacketInfo())); bitrate_estimator_->IncomingPacketFeedbackVector(packet_feedback_vector, - rtc::Optional()); + rtc::nullopt); } TEST_F(DelayBasedBweTest, ProbeDetection) { diff --git a/modules/congestion_controller/probe_bitrate_estimator.cc b/modules/congestion_controller/probe_bitrate_estimator.cc index 8c5934d238..1a438829b1 100644 --- a/modules/congestion_controller/probe_bitrate_estimator.cc +++ b/modules/congestion_controller/probe_bitrate_estimator.cc @@ -164,7 +164,7 @@ int ProbeBitrateEstimator::HandleProbeAndEstimateBitrate( event_log_->Log( rtc::MakeUnique(cluster_id, res)); } - estimated_bitrate_bps_ = rtc::Optional(res); + estimated_bitrate_bps_ = res; return *estimated_bitrate_bps_; } diff --git a/modules/congestion_controller/probe_controller_unittest.cc b/modules/congestion_controller/probe_controller_unittest.cc index e09d8415c6..3477c87a26 100644 --- a/modules/congestion_controller/probe_controller_unittest.cc +++ b/modules/congestion_controller/probe_controller_unittest.cc @@ -130,8 +130,7 @@ TEST_F(ProbeControllerTest, RequestProbeInAlr) { testing::Mock::VerifyAndClearExpectations(&pacer_); EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly( - Return(rtc::Optional(clock_.TimeInMilliseconds()))); + .WillRepeatedly(Return(clock_.TimeInMilliseconds())); clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); probe_controller_->Process(); probe_controller_->SetEstimatedBitrate(250); @@ -146,7 +145,7 @@ TEST_F(ProbeControllerTest, RequestProbeWhenAlrEndedRecently) { testing::Mock::VerifyAndClearExpectations(&pacer_); EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1); EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly(Return(rtc::Optional())); + .WillRepeatedly(Return(rtc::nullopt)); clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); probe_controller_->Process(); probe_controller_->SetEstimatedBitrate(250); @@ -163,7 +162,7 @@ TEST_F(ProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) { testing::Mock::VerifyAndClearExpectations(&pacer_); EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly(Return(rtc::Optional())); + .WillRepeatedly(Return(rtc::nullopt)); clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); probe_controller_->Process(); probe_controller_->SetEstimatedBitrate(250); @@ -180,8 +179,7 @@ TEST_F(ProbeControllerTest, RequestProbeWhenBweDropNotRecent) { testing::Mock::VerifyAndClearExpectations(&pacer_); EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly( - Return(rtc::Optional(clock_.TimeInMilliseconds()))); + .WillRepeatedly(Return(clock_.TimeInMilliseconds())); clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1); probe_controller_->Process(); probe_controller_->SetEstimatedBitrate(250); @@ -202,7 +200,7 @@ TEST_F(ProbeControllerTest, PeriodicProbing) { // Expect the controller to send a new probe after 5s has passed. EXPECT_CALL(pacer_, CreateProbeCluster(1000)).Times(1); EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly(Return(rtc::Optional(start_time))); + .WillRepeatedly(Return(start_time)); clock_.AdvanceTimeMilliseconds(5000); probe_controller_->Process(); probe_controller_->SetEstimatedBitrate(500); @@ -211,7 +209,7 @@ TEST_F(ProbeControllerTest, PeriodicProbing) { // The following probe should be sent at 10s into ALR. EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0); EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly(Return(rtc::Optional(start_time))); + .WillRepeatedly(Return(start_time)); clock_.AdvanceTimeMilliseconds(4000); probe_controller_->Process(); probe_controller_->SetEstimatedBitrate(500); @@ -219,7 +217,7 @@ TEST_F(ProbeControllerTest, PeriodicProbing) { EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(1); EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly(Return(rtc::Optional(start_time))); + .WillRepeatedly(Return(start_time)); clock_.AdvanceTimeMilliseconds(1000); probe_controller_->Process(); probe_controller_->SetEstimatedBitrate(500); @@ -231,8 +229,7 @@ TEST_F(ProbeControllerTest, PeriodicProbingAfterReset) { probe_controller_.reset(new ProbeController(&local_pacer, &clock_)); int64_t alr_start_time = clock_.TimeInMilliseconds(); EXPECT_CALL(local_pacer, GetApplicationLimitedRegionStartTime()) - .WillRepeatedly( - Return(rtc::Optional(alr_start_time))); + .WillRepeatedly(Return(alr_start_time)); EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2); probe_controller_->EnablePeriodicAlrProbing(true); diff --git a/modules/congestion_controller/send_side_congestion_controller_unittest.cc b/modules/congestion_controller/send_side_congestion_controller_unittest.cc index 6c22f3f561..71aff4a620 100644 --- a/modules/congestion_controller/send_side_congestion_controller_unittest.cc +++ b/modules/congestion_controller/send_side_congestion_controller_unittest.cc @@ -94,7 +94,7 @@ class SendSideCongestionControllerTest : public ::testing::Test { uint8_t fraction_loss, // 0 - 255. int64_t rtt_ms, int64_t probing_interval_ms) override { - owner_->target_bitrate_bps_ = rtc::Optional(bitrate_bps); + owner_->target_bitrate_bps_ = bitrate_bps; } private: diff --git a/modules/congestion_controller/trendline_estimator.cc b/modules/congestion_controller/trendline_estimator.cc index 1489257600..eeb5edf1cb 100644 --- a/modules/congestion_controller/trendline_estimator.cc +++ b/modules/congestion_controller/trendline_estimator.cc @@ -39,8 +39,8 @@ rtc::Optional LinearFitSlope( denominator += (point.first - x_avg) * (point.first - x_avg); } if (denominator == 0) - return rtc::Optional(); - return rtc::Optional(numerator / denominator); + return rtc::nullopt; + return numerator / denominator; } } // namespace