1792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org/*
2792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org *
4792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org *  Use of this source code is governed by a BSD-style license
5792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org *  that can be found in the LICENSE file in the root of the source
6792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org *  tree. An additional intellectual property rights grant can be found
7792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org *  in the file PATENTS.  All contributing project authors may
8792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org */
10792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
11792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org#include <algorithm>
12792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org#include <vector>
13792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
14792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org#include "testing/gtest/include/gtest/gtest.h"
150e7e259ebd69993bb5670a991f43aa1b06c9bf9emflodman#include "webrtc/call/bitrate_allocator.h"
16792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
17792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
18792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgnamespace webrtc {
19792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
20792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgclass TestBitrateObserver : public BitrateObserver {
21792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org public:
22792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver()
23792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org      : last_bitrate_(0), last_fraction_loss_(0), last_rtt_(0) {}
24792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
25792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  virtual void OnNetworkChanged(uint32_t bitrate,
26792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org                                uint8_t fraction_loss,
27792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org                                int64_t rtt) {
28792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org    last_bitrate_ = bitrate;
29792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org    last_fraction_loss_ = fraction_loss;
30792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org    last_rtt_ = rtt;
31792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  }
32792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  uint32_t last_bitrate_;
33792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  uint8_t last_fraction_loss_;
34792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  int64_t last_rtt_;
35792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org};
36792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
37792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgclass BitrateAllocatorTest : public ::testing::Test {
38792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org protected:
39e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  BitrateAllocatorTest() : allocator_(new BitrateAllocator()) {
40e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer    allocator_->OnNetworkChanged(300000u, 0, 0);
41e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  }
42792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  ~BitrateAllocatorTest() {}
43792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
44792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  rtc::scoped_ptr<BitrateAllocator> allocator_;
45792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org};
46792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
47792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgTEST_F(BitrateAllocatorTest, UpdatingBitrateObserver) {
48792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer;
498e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  int start_bitrate =
508e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer, 100000, 1500000);
51e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(300000, start_bitrate);
52792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(200000, 0, 0);
53792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
54792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
558e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  // TODO(pbos): Expect capping to 1.5M instead of 3M when not boosting the max
560e7e259ebd69993bb5670a991f43aa1b06c9bf9emflodman  // bitrate for FEC/retransmissions (see todo in BitrateAllocator).
578e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  allocator_->OnNetworkChanged(4000000, 0, 0);
588e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_);
598e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  start_bitrate =
608e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer, 100000, 4000000);
618e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  EXPECT_EQ(4000000, start_bitrate);
628e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström
638e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  start_bitrate =
648e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer, 100000, 1500000);
658e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  EXPECT_EQ(3000000, start_bitrate);
668e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_);
67792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(1500000, 0, 0);
68792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_);
69792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org}
70792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
71792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgTEST_F(BitrateAllocatorTest, TwoBitrateObserversOneRtcpObserver) {
72792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_1;
73792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_2;
748e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  int start_bitrate =
758e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 300000);
76e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(300000, start_bitrate);
778e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  start_bitrate =
788e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_2, 200000, 300000);
79e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(200000, start_bitrate);
80792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
81792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Test too low start bitrate, hence lower than sum of min. Min bitrates will
82792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // be allocated to all observers.
83792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(200000, 0, 50);
84792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
85792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(0, bitrate_observer_1.last_fraction_loss_);
86792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(50, bitrate_observer_1.last_rtt_);
87792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_);
88792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(0, bitrate_observer_2.last_fraction_loss_);
89792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(50, bitrate_observer_2.last_rtt_);
90792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
91792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Test a bitrate which should be distributed equally.
92792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(500000, 0, 50);
93792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  const uint32_t kBitrateToShare = 500000 - 200000 - 100000;
94792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(100000u + kBitrateToShare / 2, bitrate_observer_1.last_bitrate_);
95792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(200000u + kBitrateToShare / 2, bitrate_observer_2.last_bitrate_);
96792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
97e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  // Limited by 2x max bitrates since we leave room for FEC and retransmissions.
98e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  allocator_->OnNetworkChanged(1500000, 0, 50);
99e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(600000u, bitrate_observer_1.last_bitrate_);
100e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(600000u, bitrate_observer_2.last_bitrate_);
101792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org}
102792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
103792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgclass BitrateAllocatorTestNoEnforceMin : public ::testing::Test {
104792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org protected:
105792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  BitrateAllocatorTestNoEnforceMin() : allocator_(new BitrateAllocator()) {
106792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org    allocator_->EnforceMinBitrate(false);
107e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer    allocator_->OnNetworkChanged(300000u, 0, 0);
108792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  }
109792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  ~BitrateAllocatorTestNoEnforceMin() {}
110792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
111792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  rtc::scoped_ptr<BitrateAllocator> allocator_;
112792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org};
113792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
114792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org// The following three tests verify that the EnforceMinBitrate() method works
115792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org// as intended.
116792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgTEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) {
117792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_1;
1188e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  int start_bitrate =
1198e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 400000);
120e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(300000, start_bitrate);
121792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
122792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // High REMB.
123792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(150000, 0, 0);
124792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_);
125792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
126792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Low REMB.
127792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(10000, 0, 0);
128792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
129792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
130792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->RemoveBitrateObserver(&bitrate_observer_1);
131792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org}
132792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
133792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgTEST_F(BitrateAllocatorTestNoEnforceMin, ThreeBitrateObservers) {
134792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_1;
135792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_2;
136792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_3;
137792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Set up the observers with min bitrates at 100000, 200000, and 300000.
1388e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  int start_bitrate =
1398e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 400000);
140e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(300000, start_bitrate);
141e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer
1428e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  start_bitrate =
1438e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_2, 200000, 400000);
144e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(200000, start_bitrate);
145e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
146e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer
1478e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  start_bitrate =
1488e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_3, 300000, 400000);
149e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(0, start_bitrate);
150e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
151e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_);
152792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
153792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // High REMB. Make sure the controllers get a fair share of the surplus
154792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // (i.e., what is left after each controller gets its min rate).
155792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(690000, 0, 0);
156792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Verify that each observer gets its min rate (sum of min rates is 600000),
157792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // and that the remaining 90000 is divided equally among the three.
158e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  uint32_t bitrate_to_share = 690000u - 100000u - 200000u - 300000u;
159e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(100000u + bitrate_to_share / 3, bitrate_observer_1.last_bitrate_);
160e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(200000u + bitrate_to_share / 3, bitrate_observer_2.last_bitrate_);
161e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(300000u + bitrate_to_share / 3, bitrate_observer_3.last_bitrate_);
162792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
163792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // High REMB, but below the sum of min bitrates.
164792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(500000, 0, 0);
165792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Verify that the first and second observers get their min bitrates, and the
166792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // third gets the remainder.
167792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);  // Min bitrate.
168792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_);  // Min bitrate.
169792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(200000u, bitrate_observer_3.last_bitrate_);  // Remainder.
170792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
171792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Low REMB.
172792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(10000, 0, 0);
173792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Verify that the first observer gets all the rate, and the rest get zero.
174792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
175792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_);
176792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_);
177792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
178792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->RemoveBitrateObserver(&bitrate_observer_1);
179792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->RemoveBitrateObserver(&bitrate_observer_2);
180792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->RemoveBitrateObserver(&bitrate_observer_3);
181792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org}
182792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
183792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.orgTEST_F(BitrateAllocatorTest, ThreeBitrateObserversLowRembEnforceMin) {
184792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_1;
185792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_2;
186792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  TestBitrateObserver bitrate_observer_3;
1878e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  int start_bitrate =
1888e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 400000);
189e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(300000, start_bitrate);
190e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer
1918e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  start_bitrate =
1928e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_2, 200000, 400000);
193e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(200000, start_bitrate);
194e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
195e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer
1968e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström  start_bitrate =
1978e4e8b045523efb4d4d3416cc17ddb3d1705e41dPeter Boström      allocator_->AddBitrateObserver(&bitrate_observer_3, 300000, 400000);
198e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(300000, start_bitrate);
199e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(100000, static_cast<int>(bitrate_observer_1.last_bitrate_));
200e59041672283a28bde0b043c0c2bc198272f82e1Stefan Holmer  EXPECT_EQ(200000, static_cast<int>(bitrate_observer_2.last_bitrate_));
201792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
202792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  // Low REMB. Verify that all observers still get their respective min bitrate.
203792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->OnNetworkChanged(1000, 0, 0);
204792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);  // Min cap.
205792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_);  // Min cap.
206792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  EXPECT_EQ(300000u, bitrate_observer_3.last_bitrate_);  // Min cap.
207792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org
208792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->RemoveBitrateObserver(&bitrate_observer_1);
209792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->RemoveBitrateObserver(&bitrate_observer_2);
210792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org  allocator_->RemoveBitrateObserver(&bitrate_observer_3);
211792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org}
212792f1a14e2b62382c5c6080d0b8fdc5c89d27bc6stefan@webrtc.org}  // namespace webrtc
213