OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. | 39 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. |
40 std::unique_ptr<PacketRouter> packet_router(new PacketRouter()); | 40 std::unique_ptr<PacketRouter> packet_router(new PacketRouter()); |
41 controller_.reset(new CongestionController( | 41 controller_.reset(new CongestionController( |
42 &clock_, &observer_, &remote_bitrate_observer_, &event_log_, | 42 &clock_, &observer_, &remote_bitrate_observer_, &event_log_, |
43 std::move(packet_router), std::move(pacer))); | 43 std::move(packet_router), std::move(pacer))); |
44 bandwidth_observer_.reset( | 44 bandwidth_observer_.reset( |
45 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); | 45 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); |
46 | 46 |
47 // Set the initial bitrate estimate and expect the |observer| and |pacer_| | 47 // Set the initial bitrate estimate and expect the |observer| and |pacer_| |
48 // to be updated. | 48 // to be updated. |
49 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); | 49 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _)); |
50 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); | 50 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); |
51 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); | 51 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); |
52 } | 52 } |
53 | 53 |
54 SimulatedClock clock_; | 54 SimulatedClock clock_; |
55 StrictMock<MockCongestionObserver> observer_; | 55 StrictMock<MockCongestionObserver> observer_; |
56 NiceMock<MockPacedSender>* pacer_; | 56 NiceMock<MockPacedSender>* pacer_; |
57 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 57 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
58 NiceMock<MockRtcEventLog> event_log_; | 58 NiceMock<MockRtcEventLog> event_log_; |
59 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | 59 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
60 std::unique_ptr<CongestionController> controller_; | 60 std::unique_ptr<CongestionController> controller_; |
61 const uint32_t kInitialBitrateBps = 60000; | 61 const uint32_t kInitialBitrateBps = 60000; |
62 }; | 62 }; |
63 | 63 |
64 TEST_F(CongestionControllerTest, OnNetworkChanged) { | 64 TEST_F(CongestionControllerTest, OnNetworkChanged) { |
65 // Test no change. | 65 // Test no change. |
66 clock_.AdvanceTimeMilliseconds(25); | 66 clock_.AdvanceTimeMilliseconds(25); |
67 controller_->Process(); | 67 controller_->Process(); |
68 | 68 |
69 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); | 69 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); |
70 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); | 70 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
71 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 71 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
72 clock_.AdvanceTimeMilliseconds(25); | 72 clock_.AdvanceTimeMilliseconds(25); |
73 controller_->Process(); | 73 controller_->Process(); |
74 | 74 |
75 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); | 75 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _)); |
76 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); | 76 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); |
77 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps); | 77 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps); |
78 clock_.AdvanceTimeMilliseconds(25); | 78 clock_.AdvanceTimeMilliseconds(25); |
79 controller_->Process(); | 79 controller_->Process(); |
80 } | 80 } |
81 | 81 |
82 TEST_F(CongestionControllerTest, OnSendQueueFull) { | 82 TEST_F(CongestionControllerTest, OnSendQueueFull) { |
83 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 83 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
84 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); | 84 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); |
85 | 85 |
86 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); | 86 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
87 controller_->Process(); | 87 controller_->Process(); |
88 | 88 |
89 // Let the pacer not be full next time the controller checks. | 89 // Let the pacer not be full next time the controller checks. |
90 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 90 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
91 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | 91 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
92 | 92 |
93 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); | 93 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _)); |
94 controller_->Process(); | 94 controller_->Process(); |
95 } | 95 } |
96 | 96 |
97 TEST_F(CongestionControllerTest, OnSendQueueFullAndEstimateChange) { | 97 TEST_F(CongestionControllerTest, OnSendQueueFullAndEstimateChange) { |
98 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 98 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
99 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); | 99 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); |
100 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); | 100 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
101 controller_->Process(); | 101 controller_->Process(); |
102 | 102 |
103 // Receive new estimate but let the queue still be full. | 103 // Receive new estimate but let the queue still be full. |
104 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 104 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
105 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 105 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
106 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); | 106 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); |
107 // The send pacer should get the new estimate though. | 107 // The send pacer should get the new estimate though. |
108 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); | 108 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
109 clock_.AdvanceTimeMilliseconds(25); | 109 clock_.AdvanceTimeMilliseconds(25); |
110 controller_->Process(); | 110 controller_->Process(); |
111 | 111 |
112 // Let the pacer not be full next time the controller checks. | 112 // Let the pacer not be full next time the controller checks. |
113 // |OnNetworkChanged| should be called with the new estimate. | 113 // |OnNetworkChanged| should be called with the new estimate. |
114 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 114 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
115 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | 115 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
116 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); | 116 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); |
117 clock_.AdvanceTimeMilliseconds(25); | 117 clock_.AdvanceTimeMilliseconds(25); |
118 controller_->Process(); | 118 controller_->Process(); |
119 } | 119 } |
120 | 120 |
121 TEST_F(CongestionControllerTest, SignalNetworkState) { | 121 TEST_F(CongestionControllerTest, SignalNetworkState) { |
122 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); | 122 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
123 controller_->SignalNetworkState(kNetworkDown); | 123 controller_->SignalNetworkState(kNetworkDown); |
124 | 124 |
125 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); | 125 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _)); |
126 controller_->SignalNetworkState(kNetworkUp); | 126 controller_->SignalNetworkState(kNetworkUp); |
127 | 127 |
128 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); | 128 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
129 controller_->SignalNetworkState(kNetworkDown); | 129 controller_->SignalNetworkState(kNetworkDown); |
130 } | 130 } |
131 | 131 |
132 TEST_F(CongestionControllerTest, ResetBweAndBitrates) { | 132 TEST_F(CongestionControllerTest, ResetBweAndBitrates) { |
133 int new_bitrate = 200000; | 133 int new_bitrate = 200000; |
134 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); | 134 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _)); |
135 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); | 135 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); |
136 controller_->ResetBweAndBitrates(new_bitrate, -1, -1); | 136 controller_->ResetBweAndBitrates(new_bitrate, -1, -1); |
137 | 137 |
138 // If the bitrate is reset to -1, the new starting bitrate will be | 138 // If the bitrate is reset to -1, the new starting bitrate will be |
139 // the minimum default bitrate kMinBitrateBps. | 139 // the minimum default bitrate kMinBitrateBps. |
140 EXPECT_CALL( | 140 EXPECT_CALL(observer_, OnNetworkChanged( |
141 observer_, | 141 congestion_controller::GetMinBitrateBps(), _, _)); |
142 OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _)); | |
143 EXPECT_CALL(*pacer_, | 142 EXPECT_CALL(*pacer_, |
144 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); | 143 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); |
145 controller_->ResetBweAndBitrates(-1, -1, -1); | 144 controller_->ResetBweAndBitrates(-1, -1, -1); |
146 } | 145 } |
147 | 146 |
148 TEST_F(CongestionControllerTest, | 147 TEST_F(CongestionControllerTest, |
149 SignalNetworkStateAndQueueIsFullAndEstimateChange) { | 148 SignalNetworkStateAndQueueIsFullAndEstimateChange) { |
150 // Send queue is full | 149 // Send queue is full |
151 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 150 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
152 .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1)); | 151 .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1)); |
153 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); | 152 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
154 controller_->Process(); | 153 controller_->Process(); |
155 | 154 |
156 // Queue is full and network is down. Expect no bitrate change. | 155 // Queue is full and network is down. Expect no bitrate change. |
157 controller_->SignalNetworkState(kNetworkDown); | 156 controller_->SignalNetworkState(kNetworkDown); |
158 controller_->Process(); | 157 controller_->Process(); |
159 | 158 |
160 // Queue is full but network is up. Expect no bitrate change. | 159 // Queue is full but network is up. Expect no bitrate change. |
161 controller_->SignalNetworkState(kNetworkUp); | 160 controller_->SignalNetworkState(kNetworkUp); |
162 controller_->Process(); | 161 controller_->Process(); |
163 | 162 |
164 // Receive new estimate but let the queue still be full. | 163 // Receive new estimate but let the queue still be full. |
165 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); | 164 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
166 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 165 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
167 clock_.AdvanceTimeMilliseconds(25); | 166 clock_.AdvanceTimeMilliseconds(25); |
168 controller_->Process(); | 167 controller_->Process(); |
169 | 168 |
170 // Let the pacer not be full next time the controller checks. | 169 // Let the pacer not be full next time the controller checks. |
171 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 170 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
172 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | 171 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
173 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); | 172 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); |
174 controller_->Process(); | 173 controller_->Process(); |
175 } | 174 } |
176 | 175 |
177 TEST_F(CongestionControllerTest, GetPacerQueuingDelayMs) { | 176 TEST_F(CongestionControllerTest, GetPacerQueuingDelayMs) { |
178 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, _)).Times(AtLeast(1)); | 177 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _)).Times(AtLeast(1)); |
179 | 178 |
180 const int64_t kQueueTimeMs = 123; | 179 const int64_t kQueueTimeMs = 123; |
181 EXPECT_CALL(*pacer_, QueueInMs()).WillRepeatedly(Return(kQueueTimeMs)); | 180 EXPECT_CALL(*pacer_, QueueInMs()).WillRepeatedly(Return(kQueueTimeMs)); |
182 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); | 181 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
183 | 182 |
184 // Expect zero pacer delay when network is down. | 183 // Expect zero pacer delay when network is down. |
185 controller_->SignalNetworkState(kNetworkDown); | 184 controller_->SignalNetworkState(kNetworkDown); |
186 EXPECT_EQ(0, controller_->GetPacerQueuingDelayMs()); | 185 EXPECT_EQ(0, controller_->GetPacerQueuingDelayMs()); |
187 | 186 |
188 // Network is up, pacer delay should be reported. | 187 // Network is up, pacer delay should be reported. |
189 controller_->SignalNetworkState(kNetworkUp); | 188 controller_->SignalNetworkState(kNetworkUp); |
190 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); | 189 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
191 } | 190 } |
192 | 191 |
193 TEST_F(CongestionControllerTest, GetProbingInterval) { | |
194 clock_.AdvanceTimeMilliseconds(25); | |
195 controller_->Process(); | |
196 | |
197 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); | |
198 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); | |
199 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | |
200 clock_.AdvanceTimeMilliseconds(25); | |
201 controller_->Process(); | |
202 } | |
203 | |
204 } // namespace test | 192 } // namespace test |
205 } // namespace webrtc | 193 } // namespace webrtc |
OLD | NEW |