Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: webrtc/modules/congestion_controller/send_side_congestion_controller_unittest.cc

Issue 3000773002: Move PacedSender ownership to RtpTransportControllerSend. (Closed)
Patch Set: Fix test bug. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 namespace test { 48 namespace test {
49 49
50 class SendSideCongestionControllerTest : public ::testing::Test { 50 class SendSideCongestionControllerTest : public ::testing::Test {
51 protected: 51 protected:
52 SendSideCongestionControllerTest() 52 SendSideCongestionControllerTest()
53 : clock_(123456), target_bitrate_observer_(this) {} 53 : clock_(123456), target_bitrate_observer_(this) {}
54 ~SendSideCongestionControllerTest() override {} 54 ~SendSideCongestionControllerTest() override {}
55 55
56 void SetUp() override { 56 void SetUp() override {
57 pacer_ = new NiceMock<MockPacedSender>(); 57 pacer_.reset(new NiceMock<MockPacedSender>());
58 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership.
59 controller_.reset(new SendSideCongestionController( 58 controller_.reset(new SendSideCongestionController(
60 &clock_, &observer_, &event_log_, std::move(pacer))); 59 &clock_, &observer_, &event_log_, pacer_.get()));
61 bandwidth_observer_.reset( 60 bandwidth_observer_.reset(
62 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); 61 controller_->GetBitrateController()->CreateRtcpBandwidthObserver());
63 62
64 // Set the initial bitrate estimate and expect the |observer| and |pacer_| 63 // Set the initial bitrate estimate and expect the |observer| and |pacer_|
65 // to be updated. 64 // to be updated.
66 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); 65 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _));
67 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); 66 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps));
68 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3)); 67 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3));
69 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5)); 68 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5));
70 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); 69 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps);
71 } 70 }
72 71
73 // Custom setup - use an observer that tracks the target bitrate, without 72 // Custom setup - use an observer that tracks the target bitrate, without
74 // prescribing on which iterations it must change (like a mock would). 73 // prescribing on which iterations it must change (like a mock would).
75 void TargetBitrateTrackingSetup() { 74 void TargetBitrateTrackingSetup() {
76 std::unique_ptr<PacedSender> pacer(new NiceMock<MockPacedSender>()); 75 pacer_.reset(new NiceMock<MockPacedSender>());
77 controller_.reset(new SendSideCongestionController( 76 controller_.reset(new SendSideCongestionController(
78 &clock_, &target_bitrate_observer_, &event_log_, std::move(pacer))); 77 &clock_, &target_bitrate_observer_, &event_log_, pacer_.get()));
79 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); 78 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps);
80 } 79 }
81 80
82 void OnSentPacket(const PacketFeedback& packet_feedback) { 81 void OnSentPacket(const PacketFeedback& packet_feedback) {
83 constexpr uint32_t ssrc = 0; 82 constexpr uint32_t ssrc = 0;
84 controller_->AddPacket(ssrc, packet_feedback.sequence_number, 83 controller_->AddPacket(ssrc, packet_feedback.sequence_number,
85 packet_feedback.payload_size, 84 packet_feedback.payload_size,
86 packet_feedback.pacing_info); 85 packet_feedback.pacing_info);
87 controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number, 86 controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number,
88 packet_feedback.send_time_ms)); 87 packet_feedback.send_time_ms));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 controller_->OnTransportFeedback(*feedback.get()); 130 controller_->OnTransportFeedback(*feedback.get());
132 clock_.AdvanceTimeMilliseconds(50); 131 clock_.AdvanceTimeMilliseconds(50);
133 controller_->Process(); 132 controller_->Process();
134 ++(*seq_num); 133 ++(*seq_num);
135 } 134 }
136 } 135 }
137 136
138 SimulatedClock clock_; 137 SimulatedClock clock_;
139 StrictMock<MockCongestionObserver> observer_; 138 StrictMock<MockCongestionObserver> observer_;
140 TargetBitrateObserver target_bitrate_observer_; 139 TargetBitrateObserver target_bitrate_observer_;
141 NiceMock<MockPacedSender>* pacer_;
142 NiceMock<MockRtcEventLog> event_log_; 140 NiceMock<MockRtcEventLog> event_log_;
143 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; 141 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_;
142 PacketRouter packet_router_;
143 std::unique_ptr<NiceMock<MockPacedSender>> pacer_;
144 std::unique_ptr<SendSideCongestionController> controller_; 144 std::unique_ptr<SendSideCongestionController> controller_;
145 145
146 rtc::Optional<uint32_t> target_bitrate_bps_; 146 rtc::Optional<uint32_t> target_bitrate_bps_;
147 }; 147 };
148 148
149 TEST_F(SendSideCongestionControllerTest, OnNetworkChanged) { 149 TEST_F(SendSideCongestionControllerTest, OnNetworkChanged) {
150 // Test no change. 150 // Test no change.
151 clock_.AdvanceTimeMilliseconds(25); 151 clock_.AdvanceTimeMilliseconds(25);
152 controller_->Process(); 152 controller_->Process();
153 153
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); 210 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _));
211 controller_->SignalNetworkState(kNetworkUp); 211 controller_->SignalNetworkState(kNetworkUp);
212 212
213 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); 213 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _));
214 controller_->SignalNetworkState(kNetworkDown); 214 controller_->SignalNetworkState(kNetworkDown);
215 } 215 }
216 216
217 TEST_F(SendSideCongestionControllerTest, OnNetworkRouteChanged) { 217 TEST_F(SendSideCongestionControllerTest, OnNetworkRouteChanged) {
218 int new_bitrate = 200000; 218 int new_bitrate = 200000;
219 testing::Mock::VerifyAndClearExpectations(pacer_); 219 testing::Mock::VerifyAndClearExpectations(pacer_.get());
220 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); 220 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _));
221 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); 221 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate));
222 rtc::NetworkRoute route; 222 rtc::NetworkRoute route;
223 route.local_network_id = 1; 223 route.local_network_id = 1;
224 controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1); 224 controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1);
225 225
226 // If the bitrate is reset to -1, the new starting bitrate will be 226 // If the bitrate is reset to -1, the new starting bitrate will be
227 // the minimum default bitrate kMinBitrateBps. 227 // the minimum default bitrate kMinBitrateBps.
228 EXPECT_CALL( 228 EXPECT_CALL(
229 observer_, 229 observer_,
230 OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _)); 230 OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _));
231 EXPECT_CALL(*pacer_, 231 EXPECT_CALL(*pacer_,
232 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); 232 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps()));
233 route.local_network_id = 2; 233 route.local_network_id = 2;
234 controller_->OnNetworkRouteChanged(route, -1, -1, -1); 234 controller_->OnNetworkRouteChanged(route, -1, -1, -1);
235 } 235 }
236 236
237 TEST_F(SendSideCongestionControllerTest, OldFeedback) { 237 TEST_F(SendSideCongestionControllerTest, OldFeedback) {
238 int new_bitrate = 200000; 238 int new_bitrate = 200000;
239 testing::Mock::VerifyAndClearExpectations(pacer_); 239 testing::Mock::VerifyAndClearExpectations(pacer_.get());
240 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); 240 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _));
241 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); 241 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate));
242 242
243 // Send a few packets on the first network route. 243 // Send a few packets on the first network route.
244 std::vector<PacketFeedback> packets; 244 std::vector<PacketFeedback> packets;
245 packets.push_back(PacketFeedback(0, 0, 0, 1500, kPacingInfo0)); 245 packets.push_back(PacketFeedback(0, 0, 0, 1500, kPacingInfo0));
246 packets.push_back(PacketFeedback(10, 10, 1, 1500, kPacingInfo0)); 246 packets.push_back(PacketFeedback(10, 10, 1, 1500, kPacingInfo0));
247 packets.push_back(PacketFeedback(20, 20, 2, 1500, kPacingInfo0)); 247 packets.push_back(PacketFeedback(20, 20, 2, 1500, kPacingInfo0));
248 packets.push_back(PacketFeedback(30, 30, 3, 1500, kPacingInfo1)); 248 packets.push_back(PacketFeedback(30, 30, 3, 1500, kPacingInfo1));
249 packets.push_back(PacketFeedback(40, 40, 4, 1500, kPacingInfo1)); 249 packets.push_back(PacketFeedback(40, 40, 4, 1500, kPacingInfo1));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 controller_->Process(); 327 controller_->Process();
328 328
329 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); 329 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0)));
330 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); 330 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_));
331 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); 331 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
332 clock_.AdvanceTimeMilliseconds(25); 332 clock_.AdvanceTimeMilliseconds(25);
333 controller_->Process(); 333 controller_->Process();
334 } 334 }
335 335
336 TEST_F(SendSideCongestionControllerTest, ProbeOnRouteChange) { 336 TEST_F(SendSideCongestionControllerTest, ProbeOnRouteChange) {
337 testing::Mock::VerifyAndClearExpectations(pacer_); 337 testing::Mock::VerifyAndClearExpectations(pacer_.get());
338 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); 338 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6));
339 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); 339 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12));
340 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); 340 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _));
341 rtc::NetworkRoute route; 341 rtc::NetworkRoute route;
342 route.local_network_id = 1; 342 route.local_network_id = 1;
343 controller_->OnNetworkRouteChanged(route, 2 * kInitialBitrateBps, 0, 343 controller_->OnNetworkRouteChanged(route, 2 * kInitialBitrateBps, 0,
344 20 * kInitialBitrateBps); 344 20 * kInitialBitrateBps);
345 } 345 }
346 346
347 // Estimated bitrate reduced when the feedbacks arrive with such a long delay, 347 // Estimated bitrate reduced when the feedbacks arrive with such a long delay,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 ASSERT_TRUE(target_bitrate_bps_); 450 ASSERT_TRUE(target_bitrate_bps_);
451 451
452 // Repeat, but this time with a building delay, and make sure that the 452 // Repeat, but this time with a building delay, and make sure that the
453 // estimation is adjusted downwards. 453 // estimation is adjusted downwards.
454 uint32_t bitrate_before_delay = *target_bitrate_bps_; 454 uint32_t bitrate_before_delay = *target_bitrate_bps_;
455 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); 455 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50);
456 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); 456 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay);
457 } 457 }
458 } // namespace test 458 } // namespace test
459 } // namespace webrtc 459 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698