perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Sebastian Jansson | 172fd85 | 2018-05-24 12:17:06 | [diff] [blame] | 11 | #include "modules/congestion_controller/include/send_side_congestion_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 12 | #include "logging/rtc_event_log/mock/mock_rtc_event_log.h" |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 13 | #include "modules/bitrate_controller/include/bitrate_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 14 | #include "modules/congestion_controller/include/mock/mock_congestion_observer.h" |
Sebastian Jansson | 172fd85 | 2018-05-24 12:17:06 | [diff] [blame] | 15 | #include "modules/congestion_controller/rtp/congestion_controller_unittests_helper.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "modules/pacing/mock/mock_paced_sender.h" |
Niels Möller | fd6c091 | 2017-10-31 09:19:10 | [diff] [blame] | 17 | #include "modules/pacing/packet_router.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "modules/remote_bitrate_estimator/include/bwe_defines.h" |
| 19 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 20 | #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
Sebastian Jansson | 1298541 | 2018-10-15 19:06:26 | [diff] [blame] | 21 | #include "rtc_base/network/sent_packet.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "system_wrappers/include/clock.h" |
philipel | a420551 | 2017-09-26 12:36:58 | [diff] [blame] | 23 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 24 | #include "test/gmock.h" |
| 25 | #include "test/gtest.h" |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 26 | |
| 27 | using testing::_; |
asapersson | 14f1250 | 2016-09-08 06:14:50 | [diff] [blame] | 28 | using testing::AtLeast; |
philipel | a420551 | 2017-09-26 12:36:58 | [diff] [blame] | 29 | using testing::Ge; |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 30 | using testing::NiceMock; |
| 31 | using testing::Return; |
| 32 | using testing::SaveArg; |
| 33 | using testing::StrictMock; |
| 34 | |
nisse | 0584331 | 2017-04-19 06:38:35 | [diff] [blame] | 35 | namespace webrtc { |
| 36 | |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 37 | namespace { |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 38 | const webrtc::PacedPacketInfo kPacingInfo0(0, 5, 2000); |
| 39 | const webrtc::PacedPacketInfo kPacingInfo1(1, 8, 4000); |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 40 | |
nisse | 0584331 | 2017-04-19 06:38:35 | [diff] [blame] | 41 | const uint32_t kInitialBitrateBps = 60000; |
| 42 | |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 43 | } // namespace |
| 44 | |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 45 | namespace test { |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 46 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 47 | class LegacySendSideCongestionControllerTest : public ::testing::Test { |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 48 | protected: |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 49 | LegacySendSideCongestionControllerTest() |
Erik Språng | 8493594 | 2018-03-08 14:35:36 | [diff] [blame] | 50 | : clock_(123456), |
| 51 | target_bitrate_observer_(this), |
| 52 | bandwidth_observer_(nullptr) {} |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 53 | ~LegacySendSideCongestionControllerTest() override {} |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 54 | |
| 55 | void SetUp() override { |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 56 | pacer_.reset(new NiceMock<MockPacedSender>()); |
Sebastian Jansson | 7d92de6 | 2018-12-17 10:14:11 | [diff] [blame] | 57 | controller_.reset(new DEPRECATED_SendSideCongestionController( |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 58 | &clock_, &observer_, &event_log_, pacer_.get())); |
Sebastian Jansson | 8d9c540 | 2017-11-15 16:22:16 | [diff] [blame] | 59 | bandwidth_observer_ = controller_->GetBandwidthObserver(); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 60 | |
| 61 | // Set the initial bitrate estimate and expect the |observer| and |pacer_| |
| 62 | // to be updated. |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 63 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 64 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); |
Piotr (Peter) Slatala | c39f462 | 2019-02-15 15:38:04 | [diff] [blame] | 65 | EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3, 1)); |
| 66 | EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5, 2)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 67 | controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); |
| 68 | } |
| 69 | |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 70 | // Custom setup - use an observer that tracks the target bitrate, without |
| 71 | // prescribing on which iterations it must change (like a mock would). |
| 72 | void TargetBitrateTrackingSetup() { |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 73 | pacer_.reset(new NiceMock<MockPacedSender>()); |
Sebastian Jansson | 7d92de6 | 2018-12-17 10:14:11 | [diff] [blame] | 74 | controller_.reset(new DEPRECATED_SendSideCongestionController( |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 75 | &clock_, &target_bitrate_observer_, &event_log_, pacer_.get())); |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 76 | controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); |
| 77 | } |
| 78 | |
| 79 | void OnSentPacket(const PacketFeedback& packet_feedback) { |
elad.alon | d12a8e1 | 2017-03-23 18:04:48 | [diff] [blame] | 80 | constexpr uint32_t ssrc = 0; |
| 81 | controller_->AddPacket(ssrc, packet_feedback.sequence_number, |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 82 | packet_feedback.payload_size, |
| 83 | packet_feedback.pacing_info); |
| 84 | controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number, |
| 85 | packet_feedback.send_time_ms)); |
| 86 | } |
| 87 | |
| 88 | // Allows us to track the target bitrate, without prescribing the exact |
| 89 | // iterations when this would hapen, like a mock would. |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 90 | class TargetBitrateObserver : public NetworkChangedObserver { |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 91 | public: |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 92 | explicit TargetBitrateObserver( |
| 93 | LegacySendSideCongestionControllerTest* owner) |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 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 { |
Oskar Sundbom | 5b8c0a2 | 2017-11-16 09:56:55 | [diff] [blame] | 100 | owner_->target_bitrate_bps_ = bitrate_bps; |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | private: |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 104 | LegacySendSideCongestionControllerTest* owner_; |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 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 | |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 136 | SimulatedClock clock_; |
| 137 | StrictMock<MockCongestionObserver> observer_; |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 138 | TargetBitrateObserver target_bitrate_observer_; |
Ivo Creusen | fa1d568 | 2016-07-06 07:12:06 | [diff] [blame] | 139 | NiceMock<MockRtcEventLog> event_log_; |
Sebastian Jansson | 8d9c540 | 2017-11-15 16:22:16 | [diff] [blame] | 140 | RtcpBandwidthObserver* bandwidth_observer_; |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 141 | PacketRouter packet_router_; |
| 142 | std::unique_ptr<NiceMock<MockPacedSender>> pacer_; |
Sebastian Jansson | 7d92de6 | 2018-12-17 10:14:11 | [diff] [blame] | 143 | std::unique_ptr<DEPRECATED_SendSideCongestionController> controller_; |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 144 | |
Danil Chapovalov | 0040b66 | 2018-06-18 08:48:16 | [diff] [blame] | 145 | absl::optional<uint32_t> target_bitrate_bps_; |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 146 | }; |
| 147 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 148 | TEST_F(LegacySendSideCongestionControllerTest, OnNetworkChanged) { |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 149 | // Test no change. |
| 150 | clock_.AdvanceTimeMilliseconds(25); |
| 151 | controller_->Process(); |
| 152 | |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 153 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 154 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 155 | bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 156 | clock_.AdvanceTimeMilliseconds(25); |
| 157 | controller_->Process(); |
| 158 | |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 159 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 160 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 161 | bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps); |
| 162 | clock_.AdvanceTimeMilliseconds(25); |
| 163 | controller_->Process(); |
| 164 | } |
| 165 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 166 | TEST_F(LegacySendSideCongestionControllerTest, OnSendQueueFull) { |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 167 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 168 | .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 169 | |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 170 | EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 171 | controller_->Process(); |
| 172 | |
| 173 | // Let the pacer not be full next time the controller checks. |
| 174 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 175 | .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 176 | |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 177 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 178 | controller_->Process(); |
| 179 | } |
| 180 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 181 | TEST_F(LegacySendSideCongestionControllerTest, |
| 182 | OnSendQueueFullAndEstimateChange) { |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 183 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 184 | .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 185 | EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 186 | controller_->Process(); |
| 187 | |
| 188 | // Receive new estimate but let the queue still be full. |
| 189 | bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 190 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 191 | .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 192 | // The send pacer should get the new estimate though. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 193 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 194 | clock_.AdvanceTimeMilliseconds(25); |
| 195 | controller_->Process(); |
| 196 | |
| 197 | // Let the pacer not be full next time the controller checks. |
| 198 | // |OnNetworkChanged| should be called with the new estimate. |
| 199 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 200 | .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 201 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 202 | clock_.AdvanceTimeMilliseconds(25); |
| 203 | controller_->Process(); |
| 204 | } |
| 205 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 206 | TEST_F(LegacySendSideCongestionControllerTest, SignalNetworkState) { |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 207 | EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 208 | controller_->SignalNetworkState(kNetworkDown); |
| 209 | |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 210 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 211 | controller_->SignalNetworkState(kNetworkUp); |
| 212 | |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 213 | EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 214 | controller_->SignalNetworkState(kNetworkDown); |
| 215 | } |
| 216 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 217 | TEST_F(LegacySendSideCongestionControllerTest, OnNetworkRouteChanged) { |
honghaiz | 059e183 | 2016-06-24 18:03:55 | [diff] [blame] | 218 | int new_bitrate = 200000; |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 219 | testing::Mock::VerifyAndClearExpectations(pacer_.get()); |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 220 | EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 221 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); |
Stefan Holmer | 9ea46b5 | 2017-03-15 11:40:25 | [diff] [blame] | 222 | rtc::NetworkRoute route; |
| 223 | route.local_network_id = 1; |
| 224 | controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1); |
honghaiz | 059e183 | 2016-06-24 18:03:55 | [diff] [blame] | 225 | |
| 226 | // If the bitrate is reset to -1, the new starting bitrate will be |
michaelt | f082c2aa | 2016-11-07 12:17:14 | [diff] [blame] | 227 | // the minimum default bitrate kMinBitrateBps. |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 228 | EXPECT_CALL( |
| 229 | observer_, |
| 230 | OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 231 | EXPECT_CALL(*pacer_, |
| 232 | SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); |
Stefan Holmer | 9ea46b5 | 2017-03-15 11:40:25 | [diff] [blame] | 233 | route.local_network_id = 2; |
| 234 | controller_->OnNetworkRouteChanged(route, -1, -1, -1); |
honghaiz | 059e183 | 2016-06-24 18:03:55 | [diff] [blame] | 235 | } |
| 236 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 237 | TEST_F(LegacySendSideCongestionControllerTest, OldFeedback) { |
stefan | dd20054 | 2017-03-17 13:19:11 | [diff] [blame] | 238 | int new_bitrate = 200000; |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 239 | testing::Mock::VerifyAndClearExpectations(pacer_.get()); |
stefan | dd20054 | 2017-03-17 13:19:11 | [diff] [blame] | 240 | EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 241 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); |
stefan | dd20054 | 2017-03-17 13:19:11 | [diff] [blame] | 242 | |
| 243 | // Send a few packets on the first network route. |
| 244 | std::vector<PacketFeedback> packets; |
| 245 | packets.push_back(PacketFeedback(0, 0, 0, 1500, kPacingInfo0)); |
| 246 | packets.push_back(PacketFeedback(10, 10, 1, 1500, kPacingInfo0)); |
| 247 | packets.push_back(PacketFeedback(20, 20, 2, 1500, kPacingInfo0)); |
| 248 | packets.push_back(PacketFeedback(30, 30, 3, 1500, kPacingInfo1)); |
| 249 | packets.push_back(PacketFeedback(40, 40, 4, 1500, kPacingInfo1)); |
| 250 | |
| 251 | for (const PacketFeedback& packet : packets) |
| 252 | OnSentPacket(packet); |
| 253 | |
| 254 | // Change route and then insert a number of feedback packets. |
| 255 | rtc::NetworkRoute route; |
| 256 | route.local_network_id = 1; |
| 257 | controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1); |
| 258 | |
| 259 | for (const PacketFeedback& packet : packets) { |
| 260 | rtcp::TransportFeedback feedback; |
| 261 | feedback.SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); |
| 262 | |
| 263 | EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, |
| 264 | packet.arrival_time_ms * 1000)); |
| 265 | feedback.Build(); |
| 266 | controller_->OnTransportFeedback(feedback); |
| 267 | } |
| 268 | |
| 269 | // If the bitrate is reset to -1, the new starting bitrate will be |
| 270 | // the minimum default bitrate kMinBitrateBps. |
| 271 | EXPECT_CALL( |
| 272 | observer_, |
| 273 | OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _)); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 274 | EXPECT_CALL(*pacer_, |
| 275 | SetEstimatedBitrate(congestion_controller::GetMinBitrateBps())); |
stefan | dd20054 | 2017-03-17 13:19:11 | [diff] [blame] | 276 | route.local_network_id = 2; |
| 277 | controller_->OnNetworkRouteChanged(route, -1, -1, -1); |
| 278 | } |
| 279 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 280 | TEST_F(LegacySendSideCongestionControllerTest, |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 281 | SignalNetworkStateAndQueueIsFullAndEstimateChange) { |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 282 | // Send queue is full |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 283 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 284 | .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1)); |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 285 | EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 286 | controller_->Process(); |
| 287 | |
| 288 | // Queue is full and network is down. Expect no bitrate change. |
| 289 | controller_->SignalNetworkState(kNetworkDown); |
| 290 | controller_->Process(); |
| 291 | |
| 292 | // Queue is full but network is up. Expect no bitrate change. |
| 293 | controller_->SignalNetworkState(kNetworkUp); |
| 294 | controller_->Process(); |
| 295 | |
| 296 | // Receive new estimate but let the queue still be full. |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 297 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 298 | bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 299 | clock_.AdvanceTimeMilliseconds(25); |
| 300 | controller_->Process(); |
| 301 | |
| 302 | // Let the pacer not be full next time the controller checks. |
| 303 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 304 | .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1)); |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 305 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
perkj | fea9309 | 2016-05-14 07:58:48 | [diff] [blame] | 306 | controller_->Process(); |
| 307 | } |
| 308 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 309 | TEST_F(LegacySendSideCongestionControllerTest, GetPacerQueuingDelayMs) { |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 310 | EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, _)).Times(AtLeast(1)); |
asapersson | 14f1250 | 2016-09-08 06:14:50 | [diff] [blame] | 311 | |
| 312 | const int64_t kQueueTimeMs = 123; |
| 313 | EXPECT_CALL(*pacer_, QueueInMs()).WillRepeatedly(Return(kQueueTimeMs)); |
| 314 | EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
| 315 | |
| 316 | // Expect zero pacer delay when network is down. |
| 317 | controller_->SignalNetworkState(kNetworkDown); |
| 318 | EXPECT_EQ(0, controller_->GetPacerQueuingDelayMs()); |
| 319 | |
| 320 | // Network is up, pacer delay should be reported. |
| 321 | controller_->SignalNetworkState(kNetworkUp); |
| 322 | EXPECT_EQ(kQueueTimeMs, controller_->GetPacerQueuingDelayMs()); |
| 323 | } |
| 324 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 325 | TEST_F(LegacySendSideCongestionControllerTest, GetProbingInterval) { |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 326 | clock_.AdvanceTimeMilliseconds(25); |
| 327 | controller_->Process(); |
| 328 | |
| 329 | EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0))); |
Sebastian Jansson | ea86bb7 | 2018-02-14 16:53:38 | [diff] [blame] | 330 | EXPECT_CALL(*pacer_, SetEstimatedBitrate(_)); |
minyue | 78b4d56 | 2016-11-30 12:47:39 | [diff] [blame] | 331 | bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| 332 | clock_.AdvanceTimeMilliseconds(25); |
| 333 | controller_->Process(); |
| 334 | } |
| 335 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 336 | TEST_F(LegacySendSideCongestionControllerTest, ProbeOnRouteChange) { |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 337 | testing::Mock::VerifyAndClearExpectations(pacer_.get()); |
Piotr (Peter) Slatala | c39f462 | 2019-02-15 15:38:04 | [diff] [blame] | 338 | EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6, _)); |
| 339 | EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12, _)); |
philipel | cb9ba30 | 2017-03-07 14:30:59 | [diff] [blame] | 340 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
Stefan Holmer | 9ea46b5 | 2017-03-15 11:40:25 | [diff] [blame] | 341 | rtc::NetworkRoute route; |
| 342 | route.local_network_id = 1; |
| 343 | controller_->OnNetworkRouteChanged(route, 2 * kInitialBitrateBps, 0, |
| 344 | 20 * kInitialBitrateBps); |
philipel | cb9ba30 | 2017-03-07 14:30:59 | [diff] [blame] | 345 | } |
| 346 | |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 347 | // Bandwidth estimation is updated when feedbacks are received. |
| 348 | // Feedbacks which show an increasing delay cause the estimation to be reduced. |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 349 | TEST_F(LegacySendSideCongestionControllerTest, UpdatesDelayBasedEstimate) { |
elad.alon | 5bbf43f | 2017-03-09 14:40:08 | [diff] [blame] | 350 | TargetBitrateTrackingSetup(); |
| 351 | |
| 352 | const int64_t kRunTimeMs = 6000; |
| 353 | uint16_t seq_num = 0; |
| 354 | |
| 355 | // The test must run and insert packets/feedback long enough that the |
| 356 | // BWE computes a valid estimate. This is first done in an environment which |
| 357 | // simulates no bandwidth limitation, and therefore not built-up delay. |
| 358 | PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 0); |
| 359 | ASSERT_TRUE(target_bitrate_bps_); |
| 360 | |
| 361 | // Repeat, but this time with a building delay, and make sure that the |
| 362 | // estimation is adjusted downwards. |
| 363 | uint32_t bitrate_before_delay = *target_bitrate_bps_; |
| 364 | PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); |
| 365 | EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); |
| 366 | } |
philipel | a420551 | 2017-09-26 12:36:58 | [diff] [blame] | 367 | |
Sebastian Jansson | 56da2f7 | 2018-02-28 12:07:28 | [diff] [blame] | 368 | TEST_F(LegacySendSideCongestionControllerTest, PacerQueueEncodeRatePushback) { |
philipel | a420551 | 2017-09-26 12:36:58 | [diff] [blame] | 369 | ScopedFieldTrials pushback_field_trial( |
| 370 | "WebRTC-PacerPushbackExperiment/Enabled/"); |
| 371 | SetUp(); |
| 372 | |
| 373 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()).WillOnce(Return(0)); |
| 374 | controller_->Process(); |
| 375 | |
| 376 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()).WillOnce(Return(100)); |
| 377 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 0.9, _, _, _)); |
| 378 | controller_->Process(); |
| 379 | |
| 380 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()).WillOnce(Return(50)); |
| 381 | controller_->Process(); |
| 382 | |
| 383 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()).WillOnce(Return(0)); |
| 384 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
| 385 | controller_->Process(); |
| 386 | |
| 387 | const uint32_t kMinAdjustedBps = 50000; |
| 388 | int expected_queue_threshold = |
| 389 | 1000 - kMinAdjustedBps * 1000.0 / kInitialBitrateBps; |
| 390 | |
| 391 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 392 | .WillOnce(Return(expected_queue_threshold)); |
| 393 | EXPECT_CALL(observer_, OnNetworkChanged(Ge(kMinAdjustedBps), _, _, _)); |
| 394 | controller_->Process(); |
| 395 | |
| 396 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()) |
| 397 | .WillOnce(Return(expected_queue_threshold + 1)); |
| 398 | EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _)); |
| 399 | controller_->Process(); |
| 400 | |
| 401 | EXPECT_CALL(*pacer_, ExpectedQueueTimeMs()).WillOnce(Return(0)); |
| 402 | EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
| 403 | controller_->Process(); |
| 404 | } |
| 405 | |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 406 | } // namespace test |
| 407 | } // namespace webrtc |