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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 namespace test { | 58 namespace test { |
59 | 59 |
60 class CongestionControllerTest : public ::testing::Test { | 60 class CongestionControllerTest : public ::testing::Test { |
61 protected: | 61 protected: |
62 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} | 62 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} |
63 ~CongestionControllerTest() override {} | 63 ~CongestionControllerTest() override {} |
64 | 64 |
65 void SetUp() override { | 65 void SetUp() override { |
66 pacer_ = new NiceMock<MockPacedSender>(); | 66 pacer_.reset(new NiceMock<MockPacedSender>()); |
67 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. | 67 controller_.reset( |
68 controller_.reset(new CongestionController( | 68 new CongestionController(&clock_, &observer_, &remote_bitrate_observer_, |
69 &clock_, &observer_, &remote_bitrate_observer_, &event_log_, | 69 &event_log_, &packet_router_, pacer_.get())); |
70 &packet_router_, std::move(pacer))); | |
71 bandwidth_observer_.reset( | 70 bandwidth_observer_.reset( |
72 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); | 71 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); |
73 | 72 |
74 // Set the initial bitrate estimate and expect the |observer| and |pacer_| | 73 // Set the initial bitrate estimate and expect the |observer| and |pacer_| |
75 // to be updated. | 74 // to be updated. |
76 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); | 75 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
77 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); | 76 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); |
78 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3)); | 77 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3)); |
79 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5)); | 78 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5)); |
80 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); | 79 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); |
81 } | 80 } |
82 | 81 |
83 // Custom setup - use an observer that tracks the target bitrate, without | 82 // Custom setup - use an observer that tracks the target bitrate, without |
84 // prescribing on which iterations it must change (like a mock would). | 83 // prescribing on which iterations it must change (like a mock would). |
85 void TargetBitrateTrackingSetup() { | 84 void TargetBitrateTrackingSetup() { |
86 std::unique_ptr<PacedSender> pacer(new NiceMock<MockPacedSender>()); | 85 pacer_.reset(new NiceMock<MockPacedSender>()); |
87 controller_.reset(new CongestionController( | 86 controller_.reset(new CongestionController( |
88 &clock_, &target_bitrate_observer_, &remote_bitrate_observer_, | 87 &clock_, &target_bitrate_observer_, &remote_bitrate_observer_, |
89 &event_log_, &packet_router_, std::move(pacer))); | 88 &event_log_, &packet_router_, pacer_.get())); |
90 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); | 89 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); |
91 } | 90 } |
92 | 91 |
93 void OnSentPacket(const PacketFeedback& packet_feedback) { | 92 void OnSentPacket(const PacketFeedback& packet_feedback) { |
94 constexpr uint32_t ssrc = 0; | 93 constexpr uint32_t ssrc = 0; |
95 controller_->AddPacket(ssrc, packet_feedback.sequence_number, | 94 controller_->AddPacket(ssrc, packet_feedback.sequence_number, |
96 packet_feedback.payload_size, | 95 packet_feedback.payload_size, |
97 packet_feedback.pacing_info); | 96 packet_feedback.pacing_info); |
98 controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number, | 97 controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number, |
99 packet_feedback.send_time_ms)); | 98 packet_feedback.send_time_ms)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 controller_->OnTransportFeedback(*feedback.get()); | 141 controller_->OnTransportFeedback(*feedback.get()); |
143 clock_.AdvanceTimeMilliseconds(50); | 142 clock_.AdvanceTimeMilliseconds(50); |
144 controller_->Process(); | 143 controller_->Process(); |
145 ++(*seq_num); | 144 ++(*seq_num); |
146 } | 145 } |
147 } | 146 } |
148 | 147 |
149 SimulatedClock clock_; | 148 SimulatedClock clock_; |
150 StrictMock<MockCongestionObserver> observer_; | 149 StrictMock<MockCongestionObserver> observer_; |
151 TargetBitrateObserver target_bitrate_observer_; | 150 TargetBitrateObserver target_bitrate_observer_; |
152 NiceMock<MockPacedSender>* pacer_; | |
153 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 151 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
154 NiceMock<MockRtcEventLog> event_log_; | 152 NiceMock<MockRtcEventLog> event_log_; |
155 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | 153 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
156 PacketRouter packet_router_; | 154 PacketRouter packet_router_; |
| 155 std::unique_ptr<NiceMock<MockPacedSender>> pacer_; |
157 std::unique_ptr<CongestionController> controller_; | 156 std::unique_ptr<CongestionController> controller_; |
158 | 157 |
159 rtc::Optional<uint32_t> target_bitrate_bps_; | 158 rtc::Optional<uint32_t> target_bitrate_bps_; |
160 }; | 159 }; |
161 | 160 |
162 TEST_F(CongestionControllerTest, OnNetworkChanged) { | 161 TEST_F(CongestionControllerTest, OnNetworkChanged) { |
163 // Test no change. | 162 // Test no change. |
164 clock_.AdvanceTimeMilliseconds(25); | 163 clock_.AdvanceTimeMilliseconds(25); |
165 controller_->Process(); | 164 controller_->Process(); |
166 | 165 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 221 |
223 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); | 222 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
224 controller_->SignalNetworkState(kNetworkUp); | 223 controller_->SignalNetworkState(kNetworkUp); |
225 | 224 |
226 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); | 225 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
227 controller_->SignalNetworkState(kNetworkDown); | 226 controller_->SignalNetworkState(kNetworkDown); |
228 } | 227 } |
229 | 228 |
230 TEST_F(CongestionControllerTest, OnNetworkRouteChanged) { | 229 TEST_F(CongestionControllerTest, OnNetworkRouteChanged) { |
231 int new_bitrate = 200000; | 230 int new_bitrate = 200000; |
232 testing::Mock::VerifyAndClearExpectations(pacer_); | 231 testing::Mock::VerifyAndClearExpectations(pacer_.get()); |
233 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); | 232 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); |
234 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); | 233 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); |
235 rtc::NetworkRoute route; | 234 rtc::NetworkRoute route; |
236 route.local_network_id = 1; | 235 route.local_network_id = 1; |
237 controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1); | 236 controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1); |
238 | 237 |
239 // If the bitrate is reset to -1, the new starting bitrate will be | 238 // If the bitrate is reset to -1, the new starting bitrate will be |
240 // the minimum default bitrate kMinBitrateBps. | 239 // the minimum default bitrate kMinBitrateBps. |
241 EXPECT_CALL( | 240 EXPECT_CALL( |
242 observer_, | 241 observer_, |
243 OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _)); | 242 OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _)); |
244 EXPECT_CALL(*pacer_, | 243 EXPECT_CALL(*pacer_, |
245 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); | 244 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); |
246 route.local_network_id = 2; | 245 route.local_network_id = 2; |
247 controller_->OnNetworkRouteChanged(route, -1, -1, -1); | 246 controller_->OnNetworkRouteChanged(route, -1, -1, -1); |
248 } | 247 } |
249 | 248 |
250 TEST_F(CongestionControllerTest, OldFeedback) { | 249 TEST_F(CongestionControllerTest, OldFeedback) { |
251 int new_bitrate = 200000; | 250 int new_bitrate = 200000; |
252 testing::Mock::VerifyAndClearExpectations(pacer_); | 251 testing::Mock::VerifyAndClearExpectations(pacer_.get()); |
253 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); | 252 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); |
254 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); | 253 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); |
255 | 254 |
256 // Send a few packets on the first network route. | 255 // Send a few packets on the first network route. |
257 std::vector<PacketFeedback> packets; | 256 std::vector<PacketFeedback> packets; |
258 packets.push_back(PacketFeedback(0, 0, 0, 1500, kPacingInfo0)); | 257 packets.push_back(PacketFeedback(0, 0, 0, 1500, kPacingInfo0)); |
259 packets.push_back(PacketFeedback(10, 10, 1, 1500, kPacingInfo0)); | 258 packets.push_back(PacketFeedback(10, 10, 1, 1500, kPacingInfo0)); |
260 packets.push_back(PacketFeedback(20, 20, 2, 1500, kPacingInfo0)); | 259 packets.push_back(PacketFeedback(20, 20, 2, 1500, kPacingInfo0)); |
261 packets.push_back(PacketFeedback(30, 30, 3, 1500, kPacingInfo1)); | 260 packets.push_back(PacketFeedback(30, 30, 3, 1500, kPacingInfo1)); |
262 packets.push_back(PacketFeedback(40, 40, 4, 1500, kPacingInfo1)); | 261 packets.push_back(PacketFeedback(40, 40, 4, 1500, kPacingInfo1)); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 int64_t now_ms = clock_.TimeInMilliseconds(); | 365 int64_t now_ms = clock_.TimeInMilliseconds(); |
367 header.extension.absoluteSendTime = AbsSendTime(now_ms, 1000); | 366 header.extension.absoluteSendTime = AbsSendTime(now_ms, 1000); |
368 controller.OnReceivedPacket(now_ms, payload_size, header); | 367 controller.OnReceivedPacket(now_ms, payload_size, header); |
369 } | 368 } |
370 | 369 |
371 ASSERT_EQ(1u, ssrcs.size()); | 370 ASSERT_EQ(1u, ssrcs.size()); |
372 EXPECT_EQ(header.ssrc, ssrcs[0]); | 371 EXPECT_EQ(header.ssrc, ssrcs[0]); |
373 } | 372 } |
374 | 373 |
375 TEST_F(CongestionControllerTest, ProbeOnRouteChange) { | 374 TEST_F(CongestionControllerTest, ProbeOnRouteChange) { |
376 testing::Mock::VerifyAndClearExpectations(pacer_); | 375 testing::Mock::VerifyAndClearExpectations(pacer_.get()); |
377 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); | 376 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); |
378 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); | 377 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); |
379 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); | 378 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
380 rtc::NetworkRoute route; | 379 rtc::NetworkRoute route; |
381 route.local_network_id = 1; | 380 route.local_network_id = 1; |
382 controller_->OnNetworkRouteChanged(route, 2 * kInitialBitrateBps, 0, | 381 controller_->OnNetworkRouteChanged(route, 2 * kInitialBitrateBps, 0, |
383 20 * kInitialBitrateBps); | 382 20 * kInitialBitrateBps); |
384 } | 383 } |
385 | 384 |
386 // Estimated bitrate reduced when the feedbacks arrive with such a long delay, | 385 // Estimated bitrate reduced when the feedbacks arrive with such a long delay, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 ASSERT_TRUE(target_bitrate_bps_); | 488 ASSERT_TRUE(target_bitrate_bps_); |
490 | 489 |
491 // Repeat, but this time with a building delay, and make sure that the | 490 // Repeat, but this time with a building delay, and make sure that the |
492 // estimation is adjusted downwards. | 491 // estimation is adjusted downwards. |
493 uint32_t bitrate_before_delay = *target_bitrate_bps_; | 492 uint32_t bitrate_before_delay = *target_bitrate_bps_; |
494 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); | 493 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); |
495 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); | 494 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); |
496 } | 495 } |
497 } // namespace test | 496 } // namespace test |
498 } // namespace webrtc | 497 } // namespace webrtc |
OLD | NEW |