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