Chromium Code Reviews| 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(observer_, OnNetworkChanged( | 140 EXPECT_CALL( |
| 141 congestion_controller::GetMinBitrateBps(), _, _)); | 141 observer_, |
| 142 OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _)); | |
| 142 EXPECT_CALL(*pacer_, | 143 EXPECT_CALL(*pacer_, |
| 143 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); | 144 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); |
| 144 controller_->ResetBweAndBitrates(-1, -1, -1); | 145 controller_->ResetBweAndBitrates(-1, -1, -1); |
| 145 } | 146 } |
| 146 | 147 |
| 147 TEST_F(CongestionControllerTest, | 148 TEST_F(CongestionControllerTest, |
| 148 SignalNetworkStateAndQueueIsFullAndEstimateChange) { | 149 SignalNetworkStateAndQueueIsFullAndEstimateChange) { |
| 149 // Send queue is full | 150 // Send queue is full |
| 150 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 151 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 151 .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1)); | 152 .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1)); |
| 152 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _)); | 153 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
| 153 controller_->Process(); | 154 controller_->Process(); |
| 154 | 155 |
| 155 // Queue is full and network is down. Expect no bitrate change. | 156 // Queue is full and network is down. Expect no bitrate change. |
| 156 controller_->SignalNetworkState(kNetworkDown); | 157 controller_->SignalNetworkState(kNetworkDown); |
| 157 controller_->Process(); | 158 controller_->Process(); |
| 158 | 159 |
| 159 // Queue is full but network is up. Expect no bitrate change. | 160 // Queue is full but network is up. Expect no bitrate change. |
| 160 controller_->SignalNetworkState(kNetworkUp); | 161 controller_->SignalNetworkState(kNetworkUp); |
| 161 controller_->Process(); | 162 controller_->Process(); |
| 162 | 163 |
| 163 // Receive new estimate but let the queue still be full. | 164 // Receive new estimate but let the queue still be full. |
| 164 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); | 165 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
| 165 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 166 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 166 clock_.AdvanceTimeMilliseconds(25); | 167 clock_.AdvanceTimeMilliseconds(25); |
| 167 controller_->Process(); | 168 controller_->Process(); |
| 168 | 169 |
| 169 // Let the pacer not be full next time the controller checks. | 170 // Let the pacer not be full next time the controller checks. |
| 170 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) | 171 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 171 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); | 172 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
| 172 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _)); | 173 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
| 173 controller_->Process(); | 174 controller_->Process(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 TEST_F(CongestionControllerTest, GetPacerQueuingDelayMs) { | 177 TEST_F(CongestionControllerTest, GetPacerQueuingDelayMs) { |
| 177 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _)).Times(AtLeast(1)); | 178 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, _)).Times(AtLeast(1)); |
| 178 | 179 |
| 179 const int64_t kQueueTimeMs = 123; | 180 const int64_t kQueueTimeMs = 123; |
| 180 EXPECT_CALL(*pacer_, QueueInMs()).WillRepeatedly(Return(kQueueTimeMs)); | 181 EXPECT_CALL(*pacer_, QueueInMs()).WillRepeatedly(Return(kQueueTimeMs)); |
| 181 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); | 182 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
| 182 | 183 |
| 183 // Expect zero pacer delay when network is down. | 184 // Expect zero pacer delay when network is down. |
| 184 controller_->SignalNetworkState(kNetworkDown); | 185 controller_->SignalNetworkState(kNetworkDown); |
| 185 EXPECT_EQ(0, controller_->GetPacerQueuingDelayMs()); | 186 EXPECT_EQ(0, controller_->GetPacerQueuingDelayMs()); |
| 186 | 187 |
| 187 // Network is up, pacer delay should be reported. | 188 // Network is up, pacer delay should be reported. |
| 188 controller_->SignalNetworkState(kNetworkUp); | 189 controller_->SignalNetworkState(kNetworkUp); |
| 189 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); | 190 EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
| 190 } | 191 } |
|
minyue-webrtc
2016/11/22 10:14:25
would be nice to test that TransportFeedbackAdapte
michaelt
2016/11/22 16:29:00
I think mocking TransportFeedbackAdapter should no
stefan-webrtc
2016/11/22 16:39:05
I don't think that's what we want to test. We want
michaelt
2016/11/23 12:28:29
Since we relay here on concert classes, we would h
| |
| 191 | 192 |
| 192 } // namespace test | 193 } // namespace test |
| 193 } // namespace webrtc | 194 } // namespace webrtc |
| OLD | NEW |