| 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 |
| 11 #include "webrtc/base/networkroute.h" |
| 11 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" | 12 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
| 12 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 13 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 13 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 14 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
| 14 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" | 15 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont
roller.h" |
| 15 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" | 16 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" |
| 16 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_observer.h" | 17 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra
te_observer.h" |
| 17 #include "webrtc/system_wrappers/include/clock.h" | 18 #include "webrtc/system_wrappers/include/clock.h" |
| 18 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
| 19 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
| 20 | 21 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 // Let the pacer not be full next time the controller checks. | 112 // Let the pacer not be full next time the controller checks. |
| 112 // |OnNetworkChanged| should be called with the new estimate. | 113 // |OnNetworkChanged| should be called with the new estimate. |
| 113 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 114 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 114 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | 115 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
| 115 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); | 116 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); |
| 116 clock_.AdvanceTimeMilliseconds(25); | 117 clock_.AdvanceTimeMilliseconds(25); |
| 117 controller_->Process(); | 118 controller_->Process(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 TEST_F(CongestionControllerTest, SignalNetworkState) { | 121 TEST_F(CongestionControllerTest, OnNetworkRouteChanged) { |
| 121 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); | 122 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
| 122 controller_->SignalNetworkState(kNetworkDown); | 123 rtc::NetworkRoute route; |
| 124 route.connected = false; |
| 125 controller_->OnNetworkRouteChanged(route); |
| 123 | 126 |
| 124 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _)); | 127 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _)); |
| 125 controller_->SignalNetworkState(kNetworkUp); | 128 route.connected = true; |
| 129 controller_->OnNetworkRouteChanged(route); |
| 126 | 130 |
| 127 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); | 131 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
| 128 controller_->SignalNetworkState(kNetworkDown); | 132 route.connected = false; |
| 129 } | 133 controller_->OnNetworkRouteChanged(route); |
| 130 | |
| 131 TEST_F(CongestionControllerTest, ResetBweAndBitrates) { | |
| 132 int new_bitrate = 200000; | |
| 133 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _)); | |
| 134 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); | |
| 135 controller_->ResetBweAndBitrates(new_bitrate, -1, -1); | |
| 136 | |
| 137 // If the bitrate is reset to -1, the new starting bitrate will be | |
| 138 // the minimum default bitrate 10000bps. | |
| 139 int min_default_bitrate = 10000; | |
| 140 EXPECT_CALL(observer_, OnNetworkChanged(min_default_bitrate, _, _)); | |
| 141 EXPECT_CALL(*pacer_, SetEstimatedBitrate(min_default_bitrate)); | |
| 142 controller_->ResetBweAndBitrates(-1, -1, -1); | |
| 143 } | 134 } |
| 144 | 135 |
| 145 TEST_F(CongestionControllerTest, | 136 TEST_F(CongestionControllerTest, |
| 146 SignalNetworkStateAndQueueIsFullAndEstimateChange) { | 137 SignalNetworkStateAndQueueIsFullAndEstimateChange) { |
| 147 // Send queue is full | 138 // Send queue is full |
| 148 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 139 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 149 .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1)); | 140 .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1)); |
| 150 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); | 141 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); |
| 151 controller_->Process(); | 142 controller_->Process(); |
| 152 | 143 |
| 153 // Queue is full and network is down. Expect no bitrate change. | 144 // Queue is full and network is down. Expect no bitrate change. |
| 154 controller_->SignalNetworkState(kNetworkDown); | 145 rtc::NetworkRoute route; |
| 146 route.connected = false; |
| 147 controller_->OnNetworkRouteChanged(route); |
| 155 controller_->Process(); | 148 controller_->Process(); |
| 156 | 149 |
| 157 // Queue is full but network is up. Expect no bitrate change. | 150 // Queue is full but network is up. Expect no bitrate change. |
| 158 controller_->SignalNetworkState(kNetworkUp); | 151 route.connected = true; |
| 152 controller_->OnNetworkRouteChanged(route); |
| 159 controller_->Process(); | 153 controller_->Process(); |
| 160 | 154 |
| 161 // Receive new estimate but let the queue still be full. | 155 // Receive new estimate but let the queue still be full. |
| 162 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); | 156 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
| 163 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 157 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 164 clock_.AdvanceTimeMilliseconds(25); | 158 clock_.AdvanceTimeMilliseconds(25); |
| 165 controller_->Process(); | 159 controller_->Process(); |
| 166 | 160 |
| 167 // Let the pacer not be full next time the controller checks. | 161 // Let the pacer not be full next time the controller checks. |
| 168 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 162 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 169 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | 163 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
| 170 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); | 164 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); |
| 171 controller_->Process(); | 165 controller_->Process(); |
| 172 } | 166 } |
| 173 | 167 |
| 174 TEST_F(CongestionControllerTest, GetPacerQueuingDelayMs) { | 168 TEST_F(CongestionControllerTest, GetPacerQueuingDelayMs) { |
| 175 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _)).Times(AtLeast(1)); | 169 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _)).Times(AtLeast(1)); |
| 176 | 170 |
| 177 const int64_t kQueueTimeMs = 123; | 171 const int64_t kQueueTimeMs = 123; |
| 178 EXPECT_CALL(*pacer_, QueueInMs()).WillRepeatedly(Return(kQueueTimeMs)); | 172 EXPECT_CALL(*pacer_, QueueInMs()).WillRepeatedly(Return(kQueueTimeMs)); |
| 179 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); | 173 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
| 180 | 174 |
| 181 // Expect zero pacer delay when network is down. | 175 // Expect zero pacer delay when network is down. |
| 182 controller_->SignalNetworkState(kNetworkDown); | 176 rtc::NetworkRoute route; |
| 177 route.connected = false; |
| 178 controller_->OnNetworkRouteChanged(route); |
| 183 EXPECT_EQ(0, controller_->GetPacerQueuingDelayMs()); | 179 EXPECT_EQ(0, controller_->GetPacerQueuingDelayMs()); |
| 184 | 180 |
| 185 // Network is up, pacer delay should be reported. | 181 // Network is up, pacer delay should be reported. |
| 186 controller_->SignalNetworkState(kNetworkUp); | 182 route.connected = true; |
| 183 controller_->OnNetworkRouteChanged(route); |
| 187 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); | 184 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
| 188 } | 185 } |
| 189 | 186 |
| 190 } // namespace test | 187 } // namespace test |
| 191 } // namespace webrtc | 188 } // namespace webrtc |
| OLD | NEW |