blob: fddab9da7ee39249ca52e44ff06163baaec16daf [file] [log] [blame]
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +00001/*
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
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000011#include "testing/gtest/include/gtest/gtest.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000012
13#include <algorithm>
14#include <vector>
15
pbos@webrtc.org2e10b8e2013-07-16 12:54:53 +000016#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
17#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000018
19using webrtc::RtcpBandwidthObserver;
20using webrtc::BitrateObserver;
21using webrtc::BitrateController;
22
stefan@webrtc.org28a331e2013-09-17 07:49:56 +000023uint8_t WeightedLoss(int num_packets1, uint8_t fraction_loss1,
24 int num_packets2, uint8_t fraction_loss2) {
25 int weighted_sum = num_packets1 * fraction_loss1 +
26 num_packets2 * fraction_loss2;
27 int total_num_packets = num_packets1 + num_packets2;
28 return (weighted_sum + total_num_packets / 2) / total_num_packets;
29}
30
31webrtc::RTCPReportBlock CreateReportBlock(
32 uint32_t remote_ssrc, uint32_t source_ssrc,
33 uint8_t fraction_lost, uint32_t extended_high_sequence_number) {
34 return webrtc::RTCPReportBlock(remote_ssrc, source_ssrc, fraction_lost, 0,
35 extended_high_sequence_number, 0, 0, 0);
36}
37
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000038class TestBitrateObserver: public BitrateObserver {
39 public:
40 TestBitrateObserver()
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +000041 : last_bitrate_(0),
42 last_fraction_loss_(0),
43 last_rtt_(0) {
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000044 }
45
46 virtual void OnNetworkChanged(const uint32_t bitrate,
47 const uint8_t fraction_loss,
48 const uint32_t rtt) {
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +000049 last_bitrate_ = bitrate;
50 last_fraction_loss_ = fraction_loss;
51 last_rtt_ = rtt;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000052 }
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +000053 uint32_t last_bitrate_;
54 uint8_t last_fraction_loss_;
55 uint32_t last_rtt_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000056};
57
58class BitrateControllerTest : public ::testing::Test {
59 protected:
andresp@webrtc.org44caf012014-03-26 21:00:21 +000060 BitrateControllerTest() : clock_(0), enforce_min_bitrate_(true) {}
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000061 ~BitrateControllerTest() {}
62
63 virtual void SetUp() {
andresp@webrtc.org44caf012014-03-26 21:00:21 +000064 controller_ = BitrateController::CreateBitrateController(
65 &clock_, enforce_min_bitrate_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000066 bandwidth_observer_ = controller_->CreateRtcpBandwidthObserver();
67 }
68
69 virtual void TearDown() {
70 delete bandwidth_observer_;
71 delete controller_;
72 }
andresp@webrtc.org44caf012014-03-26 21:00:21 +000073
74 webrtc::SimulatedClock clock_;
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +000075 bool enforce_min_bitrate_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000076 BitrateController* controller_;
77 RtcpBandwidthObserver* bandwidth_observer_;
78};
79
80TEST_F(BitrateControllerTest, Basic) {
81 TestBitrateObserver bitrate_observer;
82 controller_->SetBitrateObserver(&bitrate_observer, 200000, 100000, 300000);
83 controller_->RemoveBitrateObserver(&bitrate_observer);
84}
85
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000086TEST_F(BitrateControllerTest, InitialRemb) {
87 TestBitrateObserver bitrate_observer;
88 controller_->SetBitrateObserver(&bitrate_observer, 200000, 100000, 1500000);
89 const uint32_t kRemb = 1000000u;
90 const uint32_t kSecondRemb = kRemb + 500000u;
91
92 // Initial REMB applies immediately.
93 bandwidth_observer_->OnReceivedEstimatedBitrate(kRemb);
94 webrtc::ReportBlockList report_blocks;
95 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1));
96 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, 1);
97 report_blocks.clear();
98 EXPECT_EQ(kRemb, bitrate_observer.last_bitrate_);
99
100 // Second REMB doesn't apply immediately.
101 bandwidth_observer_->OnReceivedEstimatedBitrate(kRemb + 500000);
102 report_blocks.push_back(CreateReportBlock(1, 2, 0, 21));
103 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, 2001);
104 EXPECT_LT(bitrate_observer.last_bitrate_, kSecondRemb);
105}
106
stefan@webrtc.org077593b2014-06-19 12:13:00 +0000107TEST_F(BitrateControllerTest, UpdatingBitrateObserver) {
108 TestBitrateObserver bitrate_observer;
109 controller_->SetBitrateObserver(&bitrate_observer, 200000, 100000, 1500000);
110 clock_.AdvanceTimeMilliseconds(25);
111 controller_->Process();
112 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
113
114 controller_->SetBitrateObserver(&bitrate_observer, 1500000, 100000, 1500000);
115 clock_.AdvanceTimeMilliseconds(25);
116 controller_->Process();
117 EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_);
118
119 controller_->SetBitrateObserver(&bitrate_observer, 500000, 100000, 1500000);
120 clock_.AdvanceTimeMilliseconds(25);
121 controller_->Process();
122 EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_);
123}
124
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000125TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) {
126 TestBitrateObserver bitrate_observer;
127 controller_->SetBitrateObserver(&bitrate_observer, 200000, 100000, 300000);
128
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000129 // First REMB applies immediately.
130 int64_t time_ms = 1001;
131 webrtc::ReportBlockList report_blocks;
132 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1));
133 bandwidth_observer_->OnReceivedEstimatedBitrate(200000);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000134 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
135 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
136 EXPECT_EQ(0u, bitrate_observer.last_rtt_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000137 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
138 report_blocks.clear();
139 time_ms += 2000;
140
141 // Receive a high remb, test bitrate inc.
142 bandwidth_observer_->OnReceivedEstimatedBitrate(400000);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000143
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000144 // Test bitrate increase 8% per second.
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000145 report_blocks.push_back(CreateReportBlock(1, 2, 0, 21));
146 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000147 EXPECT_EQ(217000u, bitrate_observer.last_bitrate_);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000148 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
andresp@webrtc.org07bc7342014-03-21 16:51:01 +0000149 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000150 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000151
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000152 report_blocks.clear();
153 report_blocks.push_back(CreateReportBlock(1, 2, 0, 41));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000154 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
155 EXPECT_EQ(235360u, bitrate_observer.last_bitrate_);
156 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
157 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
158 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000159
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000160 report_blocks.clear();
161 report_blocks.push_back(CreateReportBlock(1, 2, 0, 61));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000162 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
163 EXPECT_EQ(255189u, bitrate_observer.last_bitrate_);
164 time_ms += 1000;
165
166 report_blocks.clear();
167 report_blocks.push_back(CreateReportBlock(1, 2, 0, 81));
168 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000169 EXPECT_EQ(276604u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000170 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000171
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000172 report_blocks.clear();
173 report_blocks.push_back(CreateReportBlock(1, 2, 0, 801));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000174 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000175 EXPECT_EQ(299732u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000176 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000177
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000178 // Reach max cap.
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000179 report_blocks.clear();
180 report_blocks.push_back(CreateReportBlock(1, 2, 0, 101));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000181 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000182 EXPECT_EQ(300000u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000183 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000184
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000185 report_blocks.clear();
186 report_blocks.push_back(CreateReportBlock(1, 2, 0, 141));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000187 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000188 EXPECT_EQ(300000u, bitrate_observer.last_bitrate_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000189
190 // Test that a low REMB trigger immediately.
191 bandwidth_observer_->OnReceivedEstimatedBitrate(250000);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000192 EXPECT_EQ(250000u, bitrate_observer.last_bitrate_);
193 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
194 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000195
196 bandwidth_observer_->OnReceivedEstimatedBitrate(1000);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000197 EXPECT_EQ(100000u, bitrate_observer.last_bitrate_); // Min cap.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000198 controller_->RemoveBitrateObserver(&bitrate_observer);
199}
200
201TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) {
202 TestBitrateObserver bitrate_observer;
203 controller_->SetBitrateObserver(&bitrate_observer, 200000, 100000, 300000);
204
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000205 // REMBs during the first 2 seconds apply immediately.
206 int64_t time_ms = 1;
207 webrtc::ReportBlockList report_blocks;
208 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1));
209 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
210 report_blocks.clear();
211 time_ms += 500;
212
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000213 RtcpBandwidthObserver* second_bandwidth_observer =
214 controller_->CreateRtcpBandwidthObserver();
215
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000216 // Test start bitrate.
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000217 report_blocks.push_back(CreateReportBlock(1, 2, 0, 21));
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000218 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
219 report_blocks, 100, 1);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000220 EXPECT_EQ(217000u, bitrate_observer.last_bitrate_);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000221 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
andresp@webrtc.org07bc7342014-03-21 16:51:01 +0000222 EXPECT_EQ(100u, bitrate_observer.last_rtt_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000223 time_ms += 500;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000224
225 // Test bitrate increase 8% per second.
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000226 report_blocks.clear();
227 report_blocks.push_back(CreateReportBlock(1, 2, 0, 21));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000228 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
229 time_ms += 500;
230 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
231 report_blocks, 100, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000232 EXPECT_EQ(235360u, bitrate_observer.last_bitrate_);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000233 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
234 EXPECT_EQ(100u, bitrate_observer.last_rtt_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000235 time_ms += 500;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000236
237 // Extra report should not change estimate.
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000238 report_blocks.clear();
239 report_blocks.push_back(CreateReportBlock(1, 2, 0, 31));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000240 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
241 report_blocks, 100, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000242 EXPECT_EQ(235360u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000243 time_ms += 500;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000244
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000245 report_blocks.clear();
246 report_blocks.push_back(CreateReportBlock(1, 2, 0, 41));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000247 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000248 EXPECT_EQ(255189u, bitrate_observer.last_bitrate_);
pwestin@webrtc.orga2cd7322012-04-23 08:32:47 +0000249
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000250 // Second report should not change estimate.
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000251 report_blocks.clear();
252 report_blocks.push_back(CreateReportBlock(1, 2, 0, 41));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000253 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
254 report_blocks, 100, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000255 EXPECT_EQ(255189u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000256 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000257
258 // Reports from only one bandwidth observer is ok.
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000259 report_blocks.clear();
260 report_blocks.push_back(CreateReportBlock(1, 2, 0, 61));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000261 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
262 report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000263 EXPECT_EQ(276604u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000264 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000265
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000266 report_blocks.clear();
267 report_blocks.push_back(CreateReportBlock(1, 2, 0, 81));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000268 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
269 report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000270 EXPECT_EQ(299732u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000271 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000272
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000273 // Reach max cap.
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000274 report_blocks.clear();
275 report_blocks.push_back(CreateReportBlock(1, 2, 0, 121));
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000276 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000277 report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000278 EXPECT_EQ(300000u, bitrate_observer.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000279 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000280
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000281 report_blocks.clear();
282 report_blocks.push_back(CreateReportBlock(1, 2, 0, 141));
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000283 second_bandwidth_observer->OnReceivedRtcpReceiverReport(
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000284 report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000285 EXPECT_EQ(300000u, bitrate_observer.last_bitrate_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000286
287 // Test that a low REMB trigger immediately.
288 // We don't care which bandwidth observer that delivers the REMB.
289 second_bandwidth_observer->OnReceivedEstimatedBitrate(250000);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000290 EXPECT_EQ(250000u, bitrate_observer.last_bitrate_);
291 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
292 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000293
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000294 // Min cap.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000295 bandwidth_observer_->OnReceivedEstimatedBitrate(1000);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000296 EXPECT_EQ(100000u, bitrate_observer.last_bitrate_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000297 controller_->RemoveBitrateObserver(&bitrate_observer);
298 delete second_bandwidth_observer;
299}
300
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000301TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) {
302 TestBitrateObserver bitrate_observer;
303 uint32_t sequence_number[2] = {0, 0xFF00};
304 const uint32_t kStartBitrate = 200000;
305 const uint32_t kMinBitrate = 100000;
306 const uint32_t kMaxBitrate = 300000;
307 controller_->SetBitrateObserver(&bitrate_observer, kStartBitrate, kMinBitrate,
308 kMaxBitrate);
309
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000310 // REMBs during the first 2 seconds apply immediately.
311 int64_t time_ms = 1001;
312 webrtc::ReportBlockList report_blocks;
313 report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0]));
314 bandwidth_observer_->OnReceivedEstimatedBitrate(kStartBitrate);
315 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
316 report_blocks.clear();
317 time_ms += 2000;
318
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000319 // Receive a high REMB, test bitrate increase.
320 bandwidth_observer_->OnReceivedEstimatedBitrate(400000);
321
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000322 uint32_t last_bitrate = 0;
323 // Ramp up to max bitrate.
324 for (int i = 0; i < 6; ++i) {
325 report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0]));
326 report_blocks.push_back(CreateReportBlock(1, 3, 0, sequence_number[1]));
327 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50,
328 time_ms);
329 EXPECT_GT(bitrate_observer.last_bitrate_, last_bitrate);
330 EXPECT_EQ(0, bitrate_observer.last_fraction_loss_);
331 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
332 last_bitrate = bitrate_observer.last_bitrate_;
333 time_ms += 1000;
334 sequence_number[0] += 20;
335 sequence_number[1] += 1;
336 report_blocks.clear();
337 }
338
339 EXPECT_EQ(kMaxBitrate, bitrate_observer.last_bitrate_);
340
341 // Packet loss on the first stream. Verify that bitrate decreases.
342 report_blocks.push_back(CreateReportBlock(1, 2, 50, sequence_number[0]));
343 report_blocks.push_back(CreateReportBlock(1, 3, 0, sequence_number[1]));
344 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
345 EXPECT_LT(bitrate_observer.last_bitrate_, last_bitrate);
346 EXPECT_EQ(WeightedLoss(20, 50, 1, 0), bitrate_observer.last_fraction_loss_);
347 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
348 last_bitrate = bitrate_observer.last_bitrate_;
349 sequence_number[0] += 20;
350 sequence_number[1] += 20;
351 time_ms += 1000;
352 report_blocks.clear();
353
354 // Packet loss on the second stream. Verify that bitrate decreases.
355 report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0]));
356 report_blocks.push_back(CreateReportBlock(1, 3, 75, sequence_number[1]));
357 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
358 EXPECT_LT(bitrate_observer.last_bitrate_, last_bitrate);
359 EXPECT_EQ(WeightedLoss(20, 0, 20, 75), bitrate_observer.last_fraction_loss_);
360 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
361 last_bitrate = bitrate_observer.last_bitrate_;
362 sequence_number[0] += 20;
363 sequence_number[1] += 1;
364 time_ms += 1000;
365 report_blocks.clear();
366
367 // All packets lost on stream with few packets, no back-off.
368 report_blocks.push_back(CreateReportBlock(1, 2, 1, sequence_number[0]));
369 report_blocks.push_back(CreateReportBlock(1, 3, 255, sequence_number[1]));
370 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
371 EXPECT_EQ(bitrate_observer.last_bitrate_, last_bitrate);
372 EXPECT_EQ(WeightedLoss(20, 1, 1, 255), bitrate_observer.last_fraction_loss_);
373 EXPECT_EQ(50u, bitrate_observer.last_rtt_);
374 last_bitrate = bitrate_observer.last_bitrate_;
375 sequence_number[0] += 20;
376 sequence_number[1] += 1;
377 report_blocks.clear();
378}
379
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000380TEST_F(BitrateControllerTest, TwoBitrateObserversOneRtcpObserver) {
381 TestBitrateObserver bitrate_observer_1;
382 TestBitrateObserver bitrate_observer_2;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000383 controller_->SetBitrateObserver(&bitrate_observer_2, 200000, 200000, 300000);
stefan@webrtc.org1281dc02012-08-13 16:13:09 +0000384 controller_->SetBitrateObserver(&bitrate_observer_1, 200000, 100000, 300000);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000385
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000386 // REMBs during the first 2 seconds apply immediately.
387 int64_t time_ms = 1001;
388 webrtc::ReportBlockList report_blocks;
389 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1));
390 bandwidth_observer_->OnReceivedEstimatedBitrate(200000);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000391 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
392 EXPECT_EQ(0, bitrate_observer_1.last_fraction_loss_);
393 EXPECT_EQ(0u, bitrate_observer_1.last_rtt_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000394 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
395 report_blocks.clear();
396 time_ms += 2000;
397
398 // Receive a high remb, test bitrate inc.
399 // Test too low start bitrate, hence lower than sum of min.
400 bandwidth_observer_->OnReceivedEstimatedBitrate(400000);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000401
402 // Test bitrate increase 8% per second, distributed equally.
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000403 report_blocks.push_back(CreateReportBlock(1, 2, 0, 21));
404 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000405 EXPECT_EQ(112500u, bitrate_observer_1.last_bitrate_);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000406 EXPECT_EQ(0, bitrate_observer_1.last_fraction_loss_);
407 EXPECT_EQ(50u, bitrate_observer_1.last_rtt_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000408 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000409
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000410 EXPECT_EQ(212500u, bitrate_observer_2.last_bitrate_);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000411 EXPECT_EQ(0, bitrate_observer_2.last_fraction_loss_);
412 EXPECT_EQ(50u, bitrate_observer_2.last_rtt_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000413
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000414 report_blocks.clear();
andresp@webrtc.org07bc7342014-03-21 16:51:01 +0000415 report_blocks.push_back(CreateReportBlock(1, 2, 0, 41));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000416 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000417 EXPECT_EQ(126000u, bitrate_observer_1.last_bitrate_);
418 EXPECT_EQ(226000u, bitrate_observer_2.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000419 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000420
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000421 report_blocks.clear();
andresp@webrtc.org07bc7342014-03-21 16:51:01 +0000422 report_blocks.push_back(CreateReportBlock(1, 2, 0, 61));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000423 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000424 EXPECT_EQ(140580u, bitrate_observer_1.last_bitrate_);
425 EXPECT_EQ(240580u, bitrate_observer_2.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000426 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000427
428 // Check that the bitrate sum honor our REMB.
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000429 report_blocks.clear();
430 report_blocks.push_back(CreateReportBlock(1, 2, 0, 101));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000431 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000432 EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_);
433 EXPECT_EQ(250000u, bitrate_observer_2.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000434 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000435
436 // Remove REMB cap, higher than sum of max.
437 bandwidth_observer_->OnReceivedEstimatedBitrate(700000);
438
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000439 report_blocks.clear();
440 report_blocks.push_back(CreateReportBlock(1, 2, 0, 121));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000441 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000442 EXPECT_EQ(166500u, bitrate_observer_1.last_bitrate_);
443 EXPECT_EQ(266500u, bitrate_observer_2.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000444 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000445
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000446 report_blocks.clear();
447 report_blocks.push_back(CreateReportBlock(1, 2, 0, 141));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000448 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000449 EXPECT_EQ(184320u, bitrate_observer_1.last_bitrate_);
450 EXPECT_EQ(284320u, bitrate_observer_2.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000451 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000452
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000453 report_blocks.clear();
454 report_blocks.push_back(CreateReportBlock(1, 2, 0, 161));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000455 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000456 EXPECT_EQ(207130u, bitrate_observer_1.last_bitrate_);
457 EXPECT_EQ(300000u, bitrate_observer_2.last_bitrate_); // Max cap.
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000458 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000459
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000460 report_blocks.clear();
461 report_blocks.push_back(CreateReportBlock(1, 2, 0, 181));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000462 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000463 EXPECT_EQ(248700u, bitrate_observer_1.last_bitrate_);
464 EXPECT_EQ(300000u, bitrate_observer_2.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000465 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000466
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000467 report_blocks.clear();
468 report_blocks.push_back(CreateReportBlock(1, 2, 0, 201));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000469 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000470 EXPECT_EQ(293596u, bitrate_observer_1.last_bitrate_);
471 EXPECT_EQ(300000u, bitrate_observer_2.last_bitrate_);
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000472 time_ms += 1000;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000473
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000474 report_blocks.clear();
475 report_blocks.push_back(CreateReportBlock(1, 2, 0, 221));
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000476 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000477 EXPECT_EQ(300000u, bitrate_observer_1.last_bitrate_); // Max cap.
478 EXPECT_EQ(300000u, bitrate_observer_2.last_bitrate_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000479
480 // Test that a low REMB trigger immediately.
481 bandwidth_observer_->OnReceivedEstimatedBitrate(350000);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000482 EXPECT_EQ(125000u, bitrate_observer_1.last_bitrate_);
483 EXPECT_EQ(0, bitrate_observer_1.last_fraction_loss_);
484 EXPECT_EQ(50u, bitrate_observer_1.last_rtt_);
485 EXPECT_EQ(225000u, bitrate_observer_2.last_bitrate_);
486 EXPECT_EQ(0, bitrate_observer_2.last_fraction_loss_);
487 EXPECT_EQ(50u, bitrate_observer_2.last_rtt_);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000488
489 bandwidth_observer_->OnReceivedEstimatedBitrate(1000);
kjellander@webrtc.org2e84c112012-05-31 13:55:01 +0000490 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_); // Min cap.
491 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_); // Min cap.
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000492 controller_->RemoveBitrateObserver(&bitrate_observer_1);
493 controller_->RemoveBitrateObserver(&bitrate_observer_2);
494}
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +0000495
solenberg@webrtc.org4e656022014-03-26 14:32:47 +0000496TEST_F(BitrateControllerTest, SetReservedBitrate) {
497 TestBitrateObserver bitrate_observer;
498 controller_->SetBitrateObserver(&bitrate_observer, 200000, 100000, 300000);
499
500 // Receive successively lower REMBs, verify the reserved bitrate is deducted.
501
502 controller_->SetReservedBitrate(0);
503 bandwidth_observer_->OnReceivedEstimatedBitrate(400000);
504 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
505 controller_->SetReservedBitrate(50000);
506 bandwidth_observer_->OnReceivedEstimatedBitrate(400000);
507 EXPECT_EQ(150000u, bitrate_observer.last_bitrate_);
508
509 controller_->SetReservedBitrate(0);
510 bandwidth_observer_->OnReceivedEstimatedBitrate(250000);
511 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
512 controller_->SetReservedBitrate(50000);
513 bandwidth_observer_->OnReceivedEstimatedBitrate(250000);
514 EXPECT_EQ(150000u, bitrate_observer.last_bitrate_);
515
516 controller_->SetReservedBitrate(0);
517 bandwidth_observer_->OnReceivedEstimatedBitrate(200000);
518 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
519 controller_->SetReservedBitrate(30000);
520 bandwidth_observer_->OnReceivedEstimatedBitrate(200000);
521 EXPECT_EQ(170000u, bitrate_observer.last_bitrate_);
522
523 controller_->SetReservedBitrate(0);
524 bandwidth_observer_->OnReceivedEstimatedBitrate(160000);
525 EXPECT_EQ(160000u, bitrate_observer.last_bitrate_);
526 controller_->SetReservedBitrate(30000);
527 bandwidth_observer_->OnReceivedEstimatedBitrate(160000);
528 EXPECT_EQ(130000u, bitrate_observer.last_bitrate_);
529
530 controller_->SetReservedBitrate(0);
531 bandwidth_observer_->OnReceivedEstimatedBitrate(120000);
532 EXPECT_EQ(120000u, bitrate_observer.last_bitrate_);
533 controller_->SetReservedBitrate(10000);
534 bandwidth_observer_->OnReceivedEstimatedBitrate(120000);
535 EXPECT_EQ(110000u, bitrate_observer.last_bitrate_);
536
537 controller_->SetReservedBitrate(0);
538 bandwidth_observer_->OnReceivedEstimatedBitrate(120000);
539 EXPECT_EQ(120000u, bitrate_observer.last_bitrate_);
540 controller_->SetReservedBitrate(50000);
541 bandwidth_observer_->OnReceivedEstimatedBitrate(120000);
542 EXPECT_EQ(100000u, bitrate_observer.last_bitrate_);
543
544 controller_->SetReservedBitrate(10000);
545 bandwidth_observer_->OnReceivedEstimatedBitrate(0);
546 EXPECT_EQ(100000u, bitrate_observer.last_bitrate_);
547
548 controller_->RemoveBitrateObserver(&bitrate_observer);
549}
550
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +0000551class BitrateControllerTestNoEnforceMin : public BitrateControllerTest {
552 protected:
553 BitrateControllerTestNoEnforceMin() : BitrateControllerTest() {
554 enforce_min_bitrate_ = false;
555 }
556};
557
558// The following three tests verify that the EnforceMinBitrate() method works
559// as intended.
560TEST_F(BitrateControllerTestNoEnforceMin, OneBitrateObserver) {
561 TestBitrateObserver bitrate_observer_1;
562 controller_->SetBitrateObserver(&bitrate_observer_1, 200000, 100000, 400000);
563
564 // High REMB.
565 bandwidth_observer_->OnReceivedEstimatedBitrate(150000);
566 EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_);
567
568 // Low REMB.
andresp@webrtc.org07bc7342014-03-21 16:51:01 +0000569 bandwidth_observer_->OnReceivedEstimatedBitrate(10000);
570 EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
571
572 // Keeps at least 10 kbps.
573 bandwidth_observer_->OnReceivedEstimatedBitrate(9000);
574 EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +0000575
576 controller_->RemoveBitrateObserver(&bitrate_observer_1);
577}
578
solenberg@webrtc.org4e656022014-03-26 14:32:47 +0000579TEST_F(BitrateControllerTestNoEnforceMin, SetReservedBitrate) {
580 TestBitrateObserver bitrate_observer_1;
581 controller_->SetBitrateObserver(&bitrate_observer_1, 200000, 100000, 400000);
582 controller_->SetReservedBitrate(10000);
583
584 // High REMB.
585 bandwidth_observer_->OnReceivedEstimatedBitrate(150000);
586 EXPECT_EQ(140000u, bitrate_observer_1.last_bitrate_);
587
588 // Low REMB.
589 bandwidth_observer_->OnReceivedEstimatedBitrate(15000);
590 EXPECT_EQ(5000u, bitrate_observer_1.last_bitrate_);
591
592 // Keeps at least 10 kbps.
593 bandwidth_observer_->OnReceivedEstimatedBitrate(9000);
594 EXPECT_EQ(0u, bitrate_observer_1.last_bitrate_);
595
596 controller_->RemoveBitrateObserver(&bitrate_observer_1);
597}
598
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +0000599TEST_F(BitrateControllerTestNoEnforceMin, ThreeBitrateObservers) {
600 TestBitrateObserver bitrate_observer_1;
601 TestBitrateObserver bitrate_observer_2;
602 TestBitrateObserver bitrate_observer_3;
603 // Set up the observers with min bitrates at 100000, 200000, and 300000.
604 // Note: The start bitrate of bitrate_observer_1 (700000) is used as the
605 // overall start bitrate.
606 controller_->SetBitrateObserver(&bitrate_observer_1, 700000, 100000, 400000);
607 controller_->SetBitrateObserver(&bitrate_observer_2, 200000, 200000, 400000);
608 controller_->SetBitrateObserver(&bitrate_observer_3, 200000, 300000, 400000);
609
610 // High REMB. Make sure the controllers get a fair share of the surplus
611 // (i.e., what is left after each controller gets its min rate).
612 bandwidth_observer_->OnReceivedEstimatedBitrate(690000);
613 // Verify that each observer gets its min rate (sum of min rates is 600000),
614 // and that the remaining 90000 is divided equally among the three.
615 EXPECT_EQ(130000u, bitrate_observer_1.last_bitrate_);
616 EXPECT_EQ(230000u, bitrate_observer_2.last_bitrate_);
617 EXPECT_EQ(330000u, bitrate_observer_3.last_bitrate_);
618
619 // High REMB, but below the sum of min bitrates.
620 bandwidth_observer_->OnReceivedEstimatedBitrate(500000);
621 // Verify that the first and second observers get their min bitrates, and the
622 // third gets the remainder.
623 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_); // Min bitrate.
624 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_); // Min bitrate.
625 EXPECT_EQ(200000u, bitrate_observer_3.last_bitrate_); // Remainder.
626
627 // Low REMB.
andresp@webrtc.org07bc7342014-03-21 16:51:01 +0000628 bandwidth_observer_->OnReceivedEstimatedBitrate(10000);
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +0000629 // Verify that the first observer gets all the rate, and the rest get zero.
andresp@webrtc.org07bc7342014-03-21 16:51:01 +0000630 EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
631 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_);
632 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_);
633
634 // Verify it keeps an estimate of at least 10kbps.
635 bandwidth_observer_->OnReceivedEstimatedBitrate(9000);
636 EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
henrik.lundin@webrtc.org29dd0de2013-10-21 14:00:01 +0000637 EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_);
638 EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_);
639
640 controller_->RemoveBitrateObserver(&bitrate_observer_1);
641 controller_->RemoveBitrateObserver(&bitrate_observer_2);
642 controller_->RemoveBitrateObserver(&bitrate_observer_3);
643}
644
645TEST_F(BitrateControllerTest, ThreeBitrateObserversLowRembEnforceMin) {
646 TestBitrateObserver bitrate_observer_1;
647 TestBitrateObserver bitrate_observer_2;
648 TestBitrateObserver bitrate_observer_3;
649 controller_->SetBitrateObserver(&bitrate_observer_1, 200000, 100000, 300000);
650 controller_->SetBitrateObserver(&bitrate_observer_2, 200000, 200000, 300000);
651 controller_->SetBitrateObserver(&bitrate_observer_3, 200000, 300000, 300000);
652
653 // Low REMB. Verify that all observers still get their respective min bitrate.
654 bandwidth_observer_->OnReceivedEstimatedBitrate(1000);
655 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_); // Min cap.
656 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_); // Min cap.
657 EXPECT_EQ(300000u, bitrate_observer_3.last_bitrate_); // Min cap.
658
659 controller_->RemoveBitrateObserver(&bitrate_observer_1);
660 controller_->RemoveBitrateObserver(&bitrate_observer_2);
661 controller_->RemoveBitrateObserver(&bitrate_observer_3);
662}