pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 11 | #include <algorithm> |
| 12 | #include <vector> |
| 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 14 | #include "logging/rtc_event_log/mock/mock_rtc_event_log.h" |
| 15 | #include "modules/bitrate_controller/include/bitrate_controller.h" |
| 16 | #include "modules/pacing/mock/mock_paced_sender.h" |
| 17 | #include "modules/remote_bitrate_estimator/include/bwe_defines.h" |
| 18 | #include "test/field_trial.h" |
| 19 | #include "test/gtest.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 20 | |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 21 | using ::testing::Exactly; |
| 22 | using ::testing::Return; |
| 23 | |
perkj | e30c272 | 2016-05-09 04:57:11 -0700 | [diff] [blame] | 24 | using webrtc::BitrateController; |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 25 | using webrtc::BitrateObserver; |
| 26 | using webrtc::PacedSender; |
| 27 | using webrtc::RtcpBandwidthObserver; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 28 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 29 | uint8_t WeightedLoss(int num_packets1, uint8_t fraction_loss1, |
| 30 | int num_packets2, uint8_t fraction_loss2) { |
| 31 | int weighted_sum = num_packets1 * fraction_loss1 + |
| 32 | num_packets2 * fraction_loss2; |
| 33 | int total_num_packets = num_packets1 + num_packets2; |
| 34 | return (weighted_sum + total_num_packets / 2) / total_num_packets; |
| 35 | } |
| 36 | |
| 37 | webrtc::RTCPReportBlock CreateReportBlock( |
| 38 | uint32_t remote_ssrc, uint32_t source_ssrc, |
| 39 | uint8_t fraction_lost, uint32_t extended_high_sequence_number) { |
| 40 | return webrtc::RTCPReportBlock(remote_ssrc, source_ssrc, fraction_lost, 0, |
| 41 | extended_high_sequence_number, 0, 0, 0); |
| 42 | } |
| 43 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 44 | class TestBitrateObserver: public BitrateObserver { |
| 45 | public: |
| 46 | TestBitrateObserver() |
kjellander@webrtc.org | 2e84c11 | 2012-05-31 13:55:01 +0000 | [diff] [blame] | 47 | : last_bitrate_(0), |
| 48 | last_fraction_loss_(0), |
| 49 | last_rtt_(0) { |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 50 | } |
| 51 | |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 52 | virtual void OnNetworkChanged(uint32_t bitrate, |
| 53 | uint8_t fraction_loss, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 54 | int64_t rtt) { |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 55 | last_bitrate_ = static_cast<int>(bitrate); |
kjellander@webrtc.org | 2e84c11 | 2012-05-31 13:55:01 +0000 | [diff] [blame] | 56 | last_fraction_loss_ = fraction_loss; |
| 57 | last_rtt_ = rtt; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 58 | } |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 59 | int last_bitrate_; |
kjellander@webrtc.org | 2e84c11 | 2012-05-31 13:55:01 +0000 | [diff] [blame] | 60 | uint8_t last_fraction_loss_; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 61 | int64_t last_rtt_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | class BitrateControllerTest : public ::testing::Test { |
| 65 | protected: |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 66 | BitrateControllerTest() : clock_(0) {} |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 67 | ~BitrateControllerTest() {} |
| 68 | |
| 69 | virtual void SetUp() { |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 70 | controller_.reset(BitrateController::CreateBitrateController( |
| 71 | &clock_, &bitrate_observer_, &event_log_)); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 72 | controller_->SetStartBitrate(kStartBitrateBps); |
| 73 | EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
| 74 | controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); |
| 75 | EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 76 | bandwidth_observer_.reset(controller_->CreateRtcpBandwidthObserver()); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | virtual void TearDown() { |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 80 | } |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 81 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 82 | const int kMinBitrateBps = 100000; |
| 83 | const int kStartBitrateBps = 200000; |
| 84 | const int kMaxBitrateBps = 300000; |
| 85 | |
| 86 | const int kDefaultMinBitrateBps = 10000; |
| 87 | const int kDefaultMaxBitrateBps = 1000000000; |
| 88 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 89 | webrtc::SimulatedClock clock_; |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 90 | TestBitrateObserver bitrate_observer_; |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 91 | std::unique_ptr<BitrateController> controller_; |
| 92 | std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
Ivo Creusen | fa1d568 | 2016-07-06 09:12:06 +0200 | [diff] [blame] | 93 | testing::NiceMock<webrtc::MockRtcEventLog> event_log_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 96 | TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { |
| 97 | // Receive successively lower REMBs, verify the reserved bitrate is deducted. |
| 98 | controller_->SetMinMaxBitrate(0, 0); |
| 99 | EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); |
| 100 | bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); |
michaelt | f082c2a | 2016-11-07 04:17:14 -0800 | [diff] [blame] | 101 | EXPECT_EQ(webrtc::congestion_controller::GetMinBitrateBps(), |
| 102 | bitrate_observer_.last_bitrate_); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 103 | bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps); |
| 104 | clock_.AdvanceTimeMilliseconds(1000); |
| 105 | controller_->Process(); |
| 106 | EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_); |
| 107 | } |
| 108 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 109 | TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) { |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 110 | // First REMB applies immediately. |
| 111 | int64_t time_ms = 1001; |
| 112 | webrtc::ReportBlockList report_blocks; |
| 113 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); |
| 114 | bandwidth_observer_->OnReceivedEstimatedBitrate(200000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 115 | EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 116 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 117 | EXPECT_EQ(0, bitrate_observer_.last_rtt_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 118 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
| 119 | report_blocks.clear(); |
| 120 | time_ms += 2000; |
| 121 | |
| 122 | // Receive a high remb, test bitrate inc. |
| 123 | bandwidth_observer_->OnReceivedEstimatedBitrate(400000); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 124 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 125 | // Test bitrate increase 8% per second. |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 126 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); |
| 127 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 128 | EXPECT_EQ(217000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 129 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 130 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 131 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 132 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 133 | report_blocks.clear(); |
| 134 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 41)); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 135 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 136 | EXPECT_EQ(235360, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 137 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 138 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 139 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 140 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 141 | report_blocks.clear(); |
| 142 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 61)); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 143 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 144 | EXPECT_EQ(255189, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 145 | time_ms += 1000; |
| 146 | |
| 147 | report_blocks.clear(); |
| 148 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 81)); |
| 149 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 150 | EXPECT_EQ(276604, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 151 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 152 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 153 | report_blocks.clear(); |
stefan | d48717b | 2016-08-22 08:50:31 -0700 | [diff] [blame] | 154 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 101)); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 155 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 156 | EXPECT_EQ(299732, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 157 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 158 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 159 | // Reach max cap. |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 160 | report_blocks.clear(); |
stefan | d48717b | 2016-08-22 08:50:31 -0700 | [diff] [blame] | 161 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 121)); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 162 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 163 | EXPECT_EQ(300000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 164 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 165 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 166 | report_blocks.clear(); |
| 167 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 141)); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 168 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 169 | EXPECT_EQ(300000, bitrate_observer_.last_bitrate_); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 170 | |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 171 | // Test that a low delay-based estimate limits the combined estimate. |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 172 | webrtc::DelayBasedBwe::Result result(false, 280000); |
| 173 | controller_->OnDelayBasedBweResult(result); |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 174 | EXPECT_EQ(280000, bitrate_observer_.last_bitrate_); |
| 175 | |
| 176 | // Test that a low REMB limits the combined estimate. |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 177 | bandwidth_observer_->OnReceivedEstimatedBitrate(250000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 178 | EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 179 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 180 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 181 | |
| 182 | bandwidth_observer_->OnReceivedEstimatedBitrate(1000); |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 183 | EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) { |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 187 | const uint32_t kSenderSsrc1 = 1; |
| 188 | const uint32_t kSenderSsrc2 = 2; |
| 189 | const uint32_t kMediaSsrc1 = 3; |
| 190 | const uint32_t kMediaSsrc2 = 4; |
| 191 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 192 | int64_t time_ms = 1; |
| 193 | webrtc::ReportBlockList report_blocks; |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 194 | report_blocks = {CreateReportBlock(kSenderSsrc1, kMediaSsrc1, 0, 1)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 195 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 196 | time_ms += 500; |
| 197 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 198 | RtcpBandwidthObserver* second_bandwidth_observer = |
| 199 | controller_->CreateRtcpBandwidthObserver(); |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 200 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 21)}; |
| 201 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
| 202 | report_blocks, 100, time_ms); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 203 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 204 | // Test start bitrate. |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 205 | EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 206 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 207 | EXPECT_EQ(100, bitrate_observer_.last_rtt_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 208 | time_ms += 500; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 209 | |
| 210 | // Test bitrate increase 8% per second. |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 211 | report_blocks = {CreateReportBlock(kSenderSsrc1, kMediaSsrc1, 0, 21)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 212 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
| 213 | time_ms += 500; |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 214 | |
| 215 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 21)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 216 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
| 217 | report_blocks, 100, time_ms); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 218 | EXPECT_EQ(217000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 219 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 220 | EXPECT_EQ(100, bitrate_observer_.last_rtt_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 221 | time_ms += 500; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 222 | |
| 223 | // Extra report should not change estimate. |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 224 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 31)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 225 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
| 226 | report_blocks, 100, time_ms); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 227 | EXPECT_EQ(217000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 228 | time_ms += 500; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 229 | |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 230 | report_blocks = {CreateReportBlock(kSenderSsrc1, kMediaSsrc1, 0, 41)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 231 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 232 | EXPECT_EQ(235360, bitrate_observer_.last_bitrate_); |
pwestin@webrtc.org | a2cd732 | 2012-04-23 08:32:47 +0000 | [diff] [blame] | 233 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 234 | // Second report should not change estimate. |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 235 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 41)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 236 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
| 237 | report_blocks, 100, time_ms); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 238 | EXPECT_EQ(235360, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 239 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 240 | |
| 241 | // Reports from only one bandwidth observer is ok. |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 242 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 61)}; |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 243 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
| 244 | report_blocks, 50, time_ms); |
| 245 | EXPECT_EQ(255189, bitrate_observer_.last_bitrate_); |
| 246 | time_ms += 1000; |
| 247 | |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 248 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 81)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 249 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
| 250 | report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 251 | EXPECT_EQ(276604, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 252 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 253 | |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 254 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 121)}; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 255 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
| 256 | report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 257 | EXPECT_EQ(299732, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 258 | time_ms += 1000; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 259 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 260 | // Reach max cap. |
Danil Chapovalov | 7f8369a | 2017-06-08 17:22:51 +0200 | [diff] [blame] | 261 | report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 141)}; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 262 | second_bandwidth_observer->OnReceivedRtcpReceiverReport( |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 263 | report_blocks, 50, time_ms); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 264 | EXPECT_EQ(300000, bitrate_observer_.last_bitrate_); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 265 | |
| 266 | // Test that a low REMB trigger immediately. |
| 267 | // We don't care which bandwidth observer that delivers the REMB. |
| 268 | second_bandwidth_observer->OnReceivedEstimatedBitrate(250000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 269 | EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 270 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 271 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 272 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 273 | // Min cap. |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 274 | bandwidth_observer_->OnReceivedEstimatedBitrate(1000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 275 | EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 276 | delete second_bandwidth_observer; |
| 277 | } |
| 278 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 279 | TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) { |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 280 | uint32_t sequence_number[2] = {0, 0xFF00}; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 281 | const int kStartBitrate = 200000; |
| 282 | const int kMinBitrate = 100000; |
| 283 | const int kMaxBitrate = 300000; |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 284 | controller_->SetStartBitrate(kStartBitrate); |
| 285 | controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 286 | |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 287 | // REMBs during the first 2 seconds apply immediately. |
| 288 | int64_t time_ms = 1001; |
| 289 | webrtc::ReportBlockList report_blocks; |
| 290 | report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0])); |
| 291 | bandwidth_observer_->OnReceivedEstimatedBitrate(kStartBitrate); |
| 292 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
| 293 | report_blocks.clear(); |
| 294 | time_ms += 2000; |
| 295 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 296 | // Receive a high REMB, test bitrate increase. |
| 297 | bandwidth_observer_->OnReceivedEstimatedBitrate(400000); |
| 298 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 299 | int last_bitrate = 0; |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 300 | // Ramp up to max bitrate. |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 301 | for (int i = 0; i < 7; ++i) { |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 302 | report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0])); |
| 303 | report_blocks.push_back(CreateReportBlock(1, 3, 0, sequence_number[1])); |
| 304 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, |
| 305 | time_ms); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 306 | EXPECT_GT(bitrate_observer_.last_bitrate_, last_bitrate); |
| 307 | EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); |
| 308 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
| 309 | last_bitrate = bitrate_observer_.last_bitrate_; |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 310 | time_ms += 1000; |
| 311 | sequence_number[0] += 20; |
| 312 | sequence_number[1] += 1; |
| 313 | report_blocks.clear(); |
| 314 | } |
| 315 | |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 316 | EXPECT_EQ(kMaxBitrate, bitrate_observer_.last_bitrate_); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 317 | |
| 318 | // Packet loss on the first stream. Verify that bitrate decreases. |
| 319 | report_blocks.push_back(CreateReportBlock(1, 2, 50, sequence_number[0])); |
| 320 | report_blocks.push_back(CreateReportBlock(1, 3, 0, sequence_number[1])); |
| 321 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 322 | EXPECT_LT(bitrate_observer_.last_bitrate_, last_bitrate); |
| 323 | EXPECT_EQ(WeightedLoss(20, 50, 1, 0), bitrate_observer_.last_fraction_loss_); |
| 324 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
| 325 | last_bitrate = bitrate_observer_.last_bitrate_; |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 326 | sequence_number[0] += 20; |
| 327 | sequence_number[1] += 20; |
| 328 | time_ms += 1000; |
| 329 | report_blocks.clear(); |
| 330 | |
| 331 | // Packet loss on the second stream. Verify that bitrate decreases. |
| 332 | report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0])); |
| 333 | report_blocks.push_back(CreateReportBlock(1, 3, 75, sequence_number[1])); |
| 334 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 335 | EXPECT_LT(bitrate_observer_.last_bitrate_, last_bitrate); |
| 336 | EXPECT_EQ(WeightedLoss(20, 0, 20, 75), bitrate_observer_.last_fraction_loss_); |
| 337 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
| 338 | last_bitrate = bitrate_observer_.last_bitrate_; |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 339 | sequence_number[0] += 20; |
| 340 | sequence_number[1] += 1; |
| 341 | time_ms += 1000; |
| 342 | report_blocks.clear(); |
| 343 | |
| 344 | // All packets lost on stream with few packets, no back-off. |
| 345 | report_blocks.push_back(CreateReportBlock(1, 2, 1, sequence_number[0])); |
| 346 | report_blocks.push_back(CreateReportBlock(1, 3, 255, sequence_number[1])); |
| 347 | bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 348 | EXPECT_EQ(bitrate_observer_.last_bitrate_, last_bitrate); |
| 349 | EXPECT_EQ(WeightedLoss(20, 1, 1, 255), bitrate_observer_.last_fraction_loss_); |
| 350 | EXPECT_EQ(50, bitrate_observer_.last_rtt_); |
| 351 | last_bitrate = bitrate_observer_.last_bitrate_; |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 352 | sequence_number[0] += 20; |
| 353 | sequence_number[1] += 1; |
| 354 | report_blocks.clear(); |
| 355 | } |
| 356 | |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 357 | TEST_F(BitrateControllerTest, SetReservedBitrate) { |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 358 | // Receive successively lower REMBs, verify the reserved bitrate is deducted. |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 359 | controller_->SetReservedBitrate(0); |
| 360 | bandwidth_observer_->OnReceivedEstimatedBitrate(400000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 361 | EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 362 | controller_->SetReservedBitrate(50000); |
| 363 | bandwidth_observer_->OnReceivedEstimatedBitrate(400000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 364 | EXPECT_EQ(150000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 365 | |
| 366 | controller_->SetReservedBitrate(0); |
| 367 | bandwidth_observer_->OnReceivedEstimatedBitrate(250000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 368 | EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 369 | controller_->SetReservedBitrate(50000); |
| 370 | bandwidth_observer_->OnReceivedEstimatedBitrate(250000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 371 | EXPECT_EQ(150000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 372 | |
| 373 | controller_->SetReservedBitrate(0); |
| 374 | bandwidth_observer_->OnReceivedEstimatedBitrate(200000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 375 | EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 376 | controller_->SetReservedBitrate(30000); |
| 377 | bandwidth_observer_->OnReceivedEstimatedBitrate(200000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 378 | EXPECT_EQ(170000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 379 | |
| 380 | controller_->SetReservedBitrate(0); |
| 381 | bandwidth_observer_->OnReceivedEstimatedBitrate(160000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 382 | EXPECT_EQ(160000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 383 | controller_->SetReservedBitrate(30000); |
| 384 | bandwidth_observer_->OnReceivedEstimatedBitrate(160000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 385 | EXPECT_EQ(130000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 386 | |
| 387 | controller_->SetReservedBitrate(0); |
| 388 | bandwidth_observer_->OnReceivedEstimatedBitrate(120000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 389 | EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 390 | controller_->SetReservedBitrate(10000); |
| 391 | bandwidth_observer_->OnReceivedEstimatedBitrate(120000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 392 | EXPECT_EQ(110000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 393 | |
| 394 | controller_->SetReservedBitrate(0); |
| 395 | bandwidth_observer_->OnReceivedEstimatedBitrate(120000); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 396 | EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 397 | controller_->SetReservedBitrate(50000); |
| 398 | bandwidth_observer_->OnReceivedEstimatedBitrate(120000); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 399 | // Limited by min bitrate. |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 400 | EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 +0000 | [diff] [blame] | 401 | |
| 402 | controller_->SetReservedBitrate(10000); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 403 | bandwidth_observer_->OnReceivedEstimatedBitrate(1); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 404 | EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 +0000 | [diff] [blame] | 405 | } |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 406 | |
| 407 | TEST_F(BitrateControllerTest, TimeoutsWithoutFeedback) { |
| 408 | { |
| 409 | webrtc::test::ScopedFieldTrials override_field_trials( |
Stefan Holmer | db158f9 | 2016-10-13 02:11:51 +0200 | [diff] [blame] | 410 | "WebRTC-FeedbackTimeout/Enabled/"); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 411 | SetUp(); |
| 412 | int expected_bitrate_bps = 300000; |
| 413 | controller_->SetBitrates(300000, kDefaultMinBitrateBps, |
| 414 | kDefaultMaxBitrateBps); |
| 415 | |
| 416 | webrtc::ReportBlockList report_blocks; |
| 417 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); |
| 418 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 419 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 420 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 421 | clock_.AdvanceTimeMilliseconds(500); |
| 422 | |
| 423 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); |
| 424 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 425 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 426 | report_blocks.clear(); |
| 427 | expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; |
| 428 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 429 | clock_.AdvanceTimeMilliseconds(1500); |
| 430 | |
| 431 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 41)); |
| 432 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 433 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 434 | expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; |
| 435 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
stefan | 5cb1982 | 2017-06-16 07:47:00 -0700 | [diff] [blame] | 436 | clock_.AdvanceTimeMilliseconds(4000); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 437 | |
stefan | 5cb1982 | 2017-06-16 07:47:00 -0700 | [diff] [blame] | 438 | // 4 seconds since feedback, expect increase. |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 439 | controller_->Process(); |
| 440 | expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; |
| 441 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
stefan | 5cb1982 | 2017-06-16 07:47:00 -0700 | [diff] [blame] | 442 | clock_.AdvanceTimeMilliseconds(2000); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 443 | |
stefan | 5cb1982 | 2017-06-16 07:47:00 -0700 | [diff] [blame] | 444 | // 6 seconds since feedback, expect no increase. |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 445 | controller_->Process(); |
| 446 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
stefan | 5cb1982 | 2017-06-16 07:47:00 -0700 | [diff] [blame] | 447 | clock_.AdvanceTimeMilliseconds(9001); |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 448 | |
stefan | 5cb1982 | 2017-06-16 07:47:00 -0700 | [diff] [blame] | 449 | // More than 15 seconds since feedback, expect decrease. |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 450 | controller_->Process(); |
| 451 | expected_bitrate_bps *= 0.8; |
| 452 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 453 | clock_.AdvanceTimeMilliseconds(500); |
| 454 | |
| 455 | // Only one timeout every second. |
| 456 | controller_->Process(); |
| 457 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 458 | clock_.AdvanceTimeMilliseconds(501); |
| 459 | |
| 460 | // New timeout allowed. |
| 461 | controller_->Process(); |
| 462 | expected_bitrate_bps *= 0.8; |
| 463 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | TEST_F(BitrateControllerTest, StopIncreaseWithoutPacketReports) { |
| 468 | int expected_bitrate_bps = 300000; |
| 469 | controller_->SetBitrates(300000, kDefaultMinBitrateBps, |
| 470 | kDefaultMaxBitrateBps); |
| 471 | |
| 472 | webrtc::ReportBlockList report_blocks; |
| 473 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); |
| 474 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 475 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 476 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 477 | clock_.AdvanceTimeMilliseconds(500); |
| 478 | |
| 479 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); |
| 480 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 481 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 482 | report_blocks.clear(); |
| 483 | expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; |
| 484 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 485 | clock_.AdvanceTimeMilliseconds(1500); |
| 486 | |
| 487 | // 1.2 seconds without packets reported as received, no increase. |
| 488 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); |
| 489 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 490 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 491 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 492 | clock_.AdvanceTimeMilliseconds(1000); |
| 493 | |
| 494 | // 5 packets reported as received since last, too few, no increase. |
| 495 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 26)); |
| 496 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 497 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 498 | report_blocks.clear(); |
| 499 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 500 | clock_.AdvanceTimeMilliseconds(100); |
| 501 | |
| 502 | // 15 packets reported as received since last, enough to increase. |
| 503 | report_blocks.push_back(CreateReportBlock(1, 2, 0, 41)); |
| 504 | bandwidth_observer_->OnReceivedRtcpReceiverReport( |
| 505 | report_blocks, 50, clock_.TimeInMilliseconds()); |
| 506 | expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; |
| 507 | EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); |
| 508 | clock_.AdvanceTimeMilliseconds(1000); |
| 509 | } |