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

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

Issue 2743553003: Revert of Move delay_based_bwe_ into CongestionController (Closed)
Patch Set: Created 3 years, 9 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
11 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
12 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" 11 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h"
13 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 12 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
14 #include "webrtc/modules/congestion_controller/congestion_controller_unittests_h elper.h" 13 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
15 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont roller.h" 14 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont roller.h"
16 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" 15 #include "webrtc/modules/pacing/mock/mock_paced_sender.h"
17 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" 16 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
18 #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"
19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
20 #include "webrtc/system_wrappers/include/clock.h" 18 #include "webrtc/system_wrappers/include/clock.h"
21 #include "webrtc/test/gmock.h" 19 #include "webrtc/test/gmock.h"
22 #include "webrtc/test/gtest.h" 20 #include "webrtc/test/gtest.h"
23 21
24 using testing::_; 22 using testing::_;
25 using testing::AtLeast; 23 using testing::AtLeast;
26 using testing::NiceMock; 24 using testing::NiceMock;
27 using testing::Return; 25 using testing::Return;
28 using testing::SaveArg; 26 using testing::SaveArg;
29 using testing::StrictMock; 27 using testing::StrictMock;
30 28
31 namespace { 29 namespace {
32 const webrtc::PacedPacketInfo kPacingInfo0(0, 5, 2000);
33 const webrtc::PacedPacketInfo kPacingInfo1(1, 8, 4000);
34 30
35 // Helper to convert some time format to resolution used in absolute send time 31 // Helper to convert some time format to resolution used in absolute send time
36 // header extension, rounded upwards. |t| is the time to convert, in some 32 // header extension, rounded upwards. |t| is the time to convert, in some
37 // resolution. |denom| is the value to divide |t| by to get whole seconds, 33 // resolution. |denom| is the value to divide |t| by to get whole seconds,
38 // e.g. |denom| = 1000 if |t| is in milliseconds. 34 // e.g. |denom| = 1000 if |t| is in milliseconds.
39 uint32_t AbsSendTime(int64_t t, int64_t denom) { 35 uint32_t AbsSendTime(int64_t t, int64_t denom) {
40 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; 36 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful;
41 } 37 }
42 38
43 } // namespace 39 } // namespace
44 40
45 namespace webrtc { 41 namespace webrtc {
46 namespace test { 42 namespace test {
47 43
48 class CongestionControllerTest : public ::testing::Test { 44 class CongestionControllerTest : public ::testing::Test {
49 protected: 45 protected:
50 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} 46 CongestionControllerTest() : clock_(123456) {}
51 ~CongestionControllerTest() override {} 47 ~CongestionControllerTest() override {}
52 48
53 void SetUp() override { 49 void SetUp() override {
54 pacer_ = new NiceMock<MockPacedSender>(); 50 pacer_ = new NiceMock<MockPacedSender>();
55 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. 51 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership.
56 controller_.reset(new CongestionController( 52 controller_.reset(new CongestionController(
57 &clock_, &observer_, &remote_bitrate_observer_, &event_log_, 53 &clock_, &observer_, &remote_bitrate_observer_, &event_log_,
58 &packet_router_, std::move(pacer))); 54 &packet_router_, std::move(pacer)));
59 bandwidth_observer_.reset( 55 bandwidth_observer_.reset(
60 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); 56 controller_->GetBitrateController()->CreateRtcpBandwidthObserver());
61 57
62 // Set the initial bitrate estimate and expect the |observer| and |pacer_| 58 // Set the initial bitrate estimate and expect the |observer| and |pacer_|
63 // to be updated. 59 // to be updated.
64 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); 60 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _));
65 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); 61 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps));
66 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3)); 62 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3));
67 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5)); 63 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5));
68 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); 64 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps);
69 } 65 }
70 66
71 // Custom setup - use an observer that tracks the target bitrate, without
72 // prescribing on which iterations it must change (like a mock would).
73 void TargetBitrateTrackingSetup() {
74 std::unique_ptr<PacedSender> pacer(new NiceMock<MockPacedSender>());
75 controller_.reset(new CongestionController(
76 &clock_, &target_bitrate_observer_, &remote_bitrate_observer_,
77 &event_log_, &packet_router_, std::move(pacer)));
78 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps);
79 }
80
81 void OnSentPacket(const PacketFeedback& packet_feedback) {
82 controller_->AddPacket(packet_feedback.sequence_number,
83 packet_feedback.payload_size,
84 packet_feedback.pacing_info);
85 controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number,
86 packet_feedback.send_time_ms));
87 }
88
89 // Allows us to track the target bitrate, without prescribing the exact
90 // iterations when this would hapen, like a mock would.
91 class TargetBitrateObserver : public CongestionController::Observer {
92 public:
93 explicit TargetBitrateObserver(CongestionControllerTest* owner)
94 : owner_(owner) {}
95 ~TargetBitrateObserver() override = default;
96 void OnNetworkChanged(uint32_t bitrate_bps,
97 uint8_t fraction_loss, // 0 - 255.
98 int64_t rtt_ms,
99 int64_t probing_interval_ms) override {
100 owner_->target_bitrate_bps_ = rtc::Optional<uint32_t>(bitrate_bps);
101 }
102
103 private:
104 CongestionControllerTest* owner_;
105 };
106
107 void PacketTransmissionAndFeedbackBlock(uint16_t* seq_num,
108 int64_t runtime_ms,
109 int64_t delay) {
110 int64_t delay_buildup = 0;
111 int64_t start_time_ms = clock_.TimeInMilliseconds();
112 while (clock_.TimeInMilliseconds() - start_time_ms < runtime_ms) {
113 constexpr size_t kPayloadSize = 1000;
114 PacketFeedback packet(clock_.TimeInMilliseconds() + delay_buildup,
115 clock_.TimeInMilliseconds(), *seq_num, kPayloadSize,
116 PacedPacketInfo());
117 delay_buildup += delay; // Delay has to increase, or it's just RTT.
118 OnSentPacket(packet);
119 // Create expected feedback and send into adapter.
120 std::unique_ptr<rtcp::TransportFeedback> feedback(
121 new rtcp::TransportFeedback());
122 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000);
123 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number,
124 packet.arrival_time_ms * 1000));
125 rtc::Buffer raw_packet = feedback->Build();
126 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(),
127 raw_packet.size());
128 EXPECT_TRUE(feedback.get() != nullptr);
129 controller_->OnTransportFeedback(*feedback.get());
130 clock_.AdvanceTimeMilliseconds(50);
131 controller_->Process();
132 ++(*seq_num);
133 }
134 }
135
136 SimulatedClock clock_; 67 SimulatedClock clock_;
137 StrictMock<MockCongestionObserver> observer_; 68 StrictMock<MockCongestionObserver> observer_;
138 TargetBitrateObserver target_bitrate_observer_;
139 NiceMock<MockPacedSender>* pacer_; 69 NiceMock<MockPacedSender>* pacer_;
140 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; 70 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_;
141 NiceMock<MockRtcEventLog> event_log_; 71 NiceMock<MockRtcEventLog> event_log_;
142 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; 72 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_;
143 PacketRouter packet_router_; 73 PacketRouter packet_router_;
144 std::unique_ptr<CongestionController> controller_; 74 std::unique_ptr<CongestionController> controller_;
145 const uint32_t kInitialBitrateBps = 60000; 75 const uint32_t kInitialBitrateBps = 60000;
146
147 rtc::Optional<uint32_t> target_bitrate_bps_;
148 }; 76 };
149 77
150 TEST_F(CongestionControllerTest, OnNetworkChanged) { 78 TEST_F(CongestionControllerTest, OnNetworkChanged) {
151 // Test no change. 79 // Test no change.
152 clock_.AdvanceTimeMilliseconds(25); 80 clock_.AdvanceTimeMilliseconds(25);
153 controller_->Process(); 81 controller_->Process();
154 82
155 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); 83 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _));
156 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); 84 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2));
157 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); 85 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 246
319 TEST_F(CongestionControllerTest, ProbeOnBweReset) { 247 TEST_F(CongestionControllerTest, ProbeOnBweReset) {
320 testing::Mock::VerifyAndClearExpectations(pacer_); 248 testing::Mock::VerifyAndClearExpectations(pacer_);
321 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); 249 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6));
322 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); 250 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12));
323 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); 251 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _));
324 controller_->ResetBweAndBitrates(2 * kInitialBitrateBps, 0, 252 controller_->ResetBweAndBitrates(2 * kInitialBitrateBps, 0,
325 20 * kInitialBitrateBps); 253 20 * kInitialBitrateBps);
326 } 254 }
327 255
328 // Estimated bitrate reduced when the feedbacks arrive with such a long delay,
329 // that the send-time-history no longer holds the feedbacked packets.
330 TEST_F(CongestionControllerTest, LongFeedbackDelays) {
331 TargetBitrateTrackingSetup();
332
333 const int64_t kFeedbackTimeoutMs = 60001;
334 const int kMaxConsecutiveFailedLookups = 5;
335 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) {
336 std::vector<PacketFeedback> packets;
337 packets.push_back(
338 PacketFeedback(i * 100, 2 * i * 100, 0, 1500, kPacingInfo0));
339 packets.push_back(
340 PacketFeedback(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, kPacingInfo0));
341 packets.push_back(
342 PacketFeedback(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, kPacingInfo0));
343 packets.push_back(
344 PacketFeedback(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, kPacingInfo1));
345 packets.push_back(
346 PacketFeedback(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, kPacingInfo1));
347
348 for (const PacketFeedback& packet : packets)
349 OnSentPacket(packet);
350
351 rtcp::TransportFeedback feedback;
352 feedback.SetBase(packets[0].sequence_number,
353 packets[0].arrival_time_ms * 1000);
354
355 for (const PacketFeedback& packet : packets) {
356 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number,
357 packet.arrival_time_ms * 1000));
358 }
359
360 feedback.Build();
361
362 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs);
363 PacketFeedback later_packet(kFeedbackTimeoutMs + i * 100 + 40,
364 kFeedbackTimeoutMs + i * 200 + 40, 5, 1500,
365 kPacingInfo1);
366 OnSentPacket(later_packet);
367
368 controller_->OnTransportFeedback(feedback);
369
370 // Check that packets have timed out.
371 for (PacketFeedback& packet : packets) {
372 packet.send_time_ms = -1;
373 packet.payload_size = 0;
374 packet.pacing_info = PacedPacketInfo();
375 }
376 ComparePacketFeedbackVectors(packets,
377 controller_->GetTransportFeedbackVector());
378 }
379
380 controller_->Process();
381
382 EXPECT_EQ(kInitialBitrateBps / 2, target_bitrate_bps_);
383
384 // Test with feedback that isn't late enough to time out.
385 {
386 std::vector<PacketFeedback> packets;
387 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0));
388 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0));
389 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0));
390 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1));
391 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1));
392
393 for (const PacketFeedback& packet : packets)
394 OnSentPacket(packet);
395
396 rtcp::TransportFeedback feedback;
397 feedback.SetBase(packets[0].sequence_number,
398 packets[0].arrival_time_ms * 1000);
399
400 for (const PacketFeedback& packet : packets) {
401 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number,
402 packet.arrival_time_ms * 1000));
403 }
404
405 feedback.Build();
406
407 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1);
408 PacketFeedback later_packet(kFeedbackTimeoutMs + 140,
409 kFeedbackTimeoutMs + 240, 5, 1500,
410 kPacingInfo1);
411 OnSentPacket(later_packet);
412
413 controller_->OnTransportFeedback(feedback);
414 ComparePacketFeedbackVectors(packets,
415 controller_->GetTransportFeedbackVector());
416 }
417 }
418
419 // Bandwidth estimation is updated when feedbacks are received.
420 // Feedbacks which show an increasing delay cause the estimation to be reduced.
421 TEST_F(CongestionControllerTest, UpdatesDelayBasedEstimate) {
422 TargetBitrateTrackingSetup();
423
424 const int64_t kRunTimeMs = 6000;
425 uint16_t seq_num = 0;
426
427 // The test must run and insert packets/feedback long enough that the
428 // BWE computes a valid estimate. This is first done in an environment which
429 // simulates no bandwidth limitation, and therefore not built-up delay.
430 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 0);
431 ASSERT_TRUE(target_bitrate_bps_);
432
433 // Repeat, but this time with a building delay, and make sure that the
434 // estimation is adjusted downwards.
435 uint32_t bitrate_before_delay = *target_bitrate_bps_;
436 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50);
437 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay);
438 }
439 } // namespace test 256 } // namespace test
440 } // namespace webrtc 257 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698