blob: 484296f53f1c776fab2b29b0f60f0ec769261de1 [file] [log] [blame]
perkjec81bcd2016-05-11 13:01:131/*
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 Jansson172fd852018-05-24 12:17:0611#include "modules/congestion_controller/include/send_side_congestion_controller.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3112#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
Sebastian Janssonea86bb72018-02-14 16:53:3813#include "modules/bitrate_controller/include/bitrate_controller.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3114#include "modules/congestion_controller/include/mock/mock_congestion_observer.h"
Sebastian Jansson172fd852018-05-24 12:17:0615#include "modules/congestion_controller/rtp/congestion_controller_unittests_helper.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "modules/pacing/mock/mock_paced_sender.h"
Niels Möllerfd6c0912017-10-31 09:19:1017#include "modules/pacing/packet_router.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3118#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 Jansson12985412018-10-15 19:06:2621#include "rtc_base/network/sent_packet.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "system_wrappers/include/clock.h"
philipela4205512017-09-26 12:36:5823#include "test/field_trial.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "test/gmock.h"
25#include "test/gtest.h"
perkjec81bcd2016-05-11 13:01:1326
27using testing::_;
asapersson14f12502016-09-08 06:14:5028using testing::AtLeast;
philipela4205512017-09-26 12:36:5829using testing::Ge;
perkjec81bcd2016-05-11 13:01:1330using testing::NiceMock;
31using testing::Return;
32using testing::SaveArg;
33using testing::StrictMock;
34
nisse05843312017-04-19 06:38:3535namespace webrtc {
36
brandtrb29e6522016-12-21 14:37:1837namespace {
elad.alon5bbf43f2017-03-09 14:40:0838const webrtc::PacedPacketInfo kPacingInfo0(0, 5, 2000);
39const webrtc::PacedPacketInfo kPacingInfo1(1, 8, 4000);
brandtrb29e6522016-12-21 14:37:1840
nisse05843312017-04-19 06:38:3541const uint32_t kInitialBitrateBps = 60000;
42
brandtrb29e6522016-12-21 14:37:1843} // namespace
44
Sebastian Janssonea86bb72018-02-14 16:53:3845namespace test {
perkjec81bcd2016-05-11 13:01:1346
Sebastian Jansson56da2f72018-02-28 12:07:2847class LegacySendSideCongestionControllerTest : public ::testing::Test {
perkjec81bcd2016-05-11 13:01:1348 protected:
Sebastian Jansson56da2f72018-02-28 12:07:2849 LegacySendSideCongestionControllerTest()
Erik Språng84935942018-03-08 14:35:3650 : clock_(123456),
51 target_bitrate_observer_(this),
52 bandwidth_observer_(nullptr) {}
Sebastian Jansson56da2f72018-02-28 12:07:2853 ~LegacySendSideCongestionControllerTest() override {}
perkjec81bcd2016-05-11 13:01:1354
55 void SetUp() override {
Stefan Holmer5c8942a2017-08-22 14:16:4456 pacer_.reset(new NiceMock<MockPacedSender>());
Sebastian Jansson7d92de62018-12-17 10:14:1157 controller_.reset(new DEPRECATED_SendSideCongestionController(
Stefan Holmer5c8942a2017-08-22 14:16:4458 &clock_, &observer_, &event_log_, pacer_.get()));
Sebastian Jansson8d9c5402017-11-15 16:22:1659 bandwidth_observer_ = controller_->GetBandwidthObserver();
perkjec81bcd2016-05-11 13:01:1360
61 // Set the initial bitrate estimate and expect the |observer| and |pacer_|
62 // to be updated.
minyue78b4d562016-11-30 12:47:3963 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _));
Sebastian Janssonea86bb72018-02-14 16:53:3864 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps));
Piotr (Peter) Slatalac39f4622019-02-15 15:38:0465 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3, 1));
66 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5, 2));
perkjec81bcd2016-05-11 13:01:1367 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps);
68 }
69
elad.alon5bbf43f2017-03-09 14:40:0870 // 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 Holmer5c8942a2017-08-22 14:16:4473 pacer_.reset(new NiceMock<MockPacedSender>());
Sebastian Jansson7d92de62018-12-17 10:14:1174 controller_.reset(new DEPRECATED_SendSideCongestionController(
Stefan Holmer5c8942a2017-08-22 14:16:4475 &clock_, &target_bitrate_observer_, &event_log_, pacer_.get()));
elad.alon5bbf43f2017-03-09 14:40:0876 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps);
77 }
78
79 void OnSentPacket(const PacketFeedback& packet_feedback) {
elad.alond12a8e12017-03-23 18:04:4880 constexpr uint32_t ssrc = 0;
81 controller_->AddPacket(ssrc, packet_feedback.sequence_number,
elad.alon5bbf43f2017-03-09 14:40:0882 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 Janssone4be6da2018-02-15 15:51:4190 class TargetBitrateObserver : public NetworkChangedObserver {
elad.alon5bbf43f2017-03-09 14:40:0891 public:
Sebastian Jansson56da2f72018-02-28 12:07:2892 explicit TargetBitrateObserver(
93 LegacySendSideCongestionControllerTest* owner)
elad.alon5bbf43f2017-03-09 14:40:0894 : 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 Sundbom5b8c0a22017-11-16 09:56:55100 owner_->target_bitrate_bps_ = bitrate_bps;
elad.alon5bbf43f2017-03-09 14:40:08101 }
102
103 private:
Sebastian Jansson56da2f72018-02-28 12:07:28104 LegacySendSideCongestionControllerTest* owner_;
elad.alon5bbf43f2017-03-09 14:40:08105 };
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
perkjec81bcd2016-05-11 13:01:13136 SimulatedClock clock_;
137 StrictMock<MockCongestionObserver> observer_;
elad.alon5bbf43f2017-03-09 14:40:08138 TargetBitrateObserver target_bitrate_observer_;
Ivo Creusenfa1d5682016-07-06 07:12:06139 NiceMock<MockRtcEventLog> event_log_;
Sebastian Jansson8d9c5402017-11-15 16:22:16140 RtcpBandwidthObserver* bandwidth_observer_;
Stefan Holmer5c8942a2017-08-22 14:16:44141 PacketRouter packet_router_;
142 std::unique_ptr<NiceMock<MockPacedSender>> pacer_;
Sebastian Jansson7d92de62018-12-17 10:14:11143 std::unique_ptr<DEPRECATED_SendSideCongestionController> controller_;
elad.alon5bbf43f2017-03-09 14:40:08144
Danil Chapovalov0040b662018-06-18 08:48:16145 absl::optional<uint32_t> target_bitrate_bps_;
perkjec81bcd2016-05-11 13:01:13146};
147
Sebastian Jansson56da2f72018-02-28 12:07:28148TEST_F(LegacySendSideCongestionControllerTest, OnNetworkChanged) {
perkjec81bcd2016-05-11 13:01:13149 // Test no change.
150 clock_.AdvanceTimeMilliseconds(25);
151 controller_->Process();
152
minyue78b4d562016-11-30 12:47:39153 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _));
Sebastian Janssonea86bb72018-02-14 16:53:38154 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2));
perkjec81bcd2016-05-11 13:01:13155 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
156 clock_.AdvanceTimeMilliseconds(25);
157 controller_->Process();
158
minyue78b4d562016-11-30 12:47:39159 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _));
Sebastian Janssonea86bb72018-02-14 16:53:38160 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps));
perkjec81bcd2016-05-11 13:01:13161 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps);
162 clock_.AdvanceTimeMilliseconds(25);
163 controller_->Process();
164}
165
Sebastian Jansson56da2f72018-02-28 12:07:28166TEST_F(LegacySendSideCongestionControllerTest, OnSendQueueFull) {
perkjec81bcd2016-05-11 13:01:13167 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
Sebastian Janssonea86bb72018-02-14 16:53:38168 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1));
perkjec81bcd2016-05-11 13:01:13169
minyue78b4d562016-11-30 12:47:39170 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _));
perkjec81bcd2016-05-11 13:01:13171 controller_->Process();
172
173 // Let the pacer not be full next time the controller checks.
174 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
Sebastian Janssonea86bb72018-02-14 16:53:38175 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1));
perkjec81bcd2016-05-11 13:01:13176
minyue78b4d562016-11-30 12:47:39177 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _));
perkjec81bcd2016-05-11 13:01:13178 controller_->Process();
179}
180
Sebastian Jansson56da2f72018-02-28 12:07:28181TEST_F(LegacySendSideCongestionControllerTest,
182 OnSendQueueFullAndEstimateChange) {
perkjec81bcd2016-05-11 13:01:13183 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
Sebastian Janssonea86bb72018-02-14 16:53:38184 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1));
minyue78b4d562016-11-30 12:47:39185 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _));
perkjec81bcd2016-05-11 13:01:13186 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 Janssonea86bb72018-02-14 16:53:38191 .WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1));
perkjec81bcd2016-05-11 13:01:13192 // The send pacer should get the new estimate though.
Sebastian Janssonea86bb72018-02-14 16:53:38193 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2));
perkjec81bcd2016-05-11 13:01:13194 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 Janssonea86bb72018-02-14 16:53:38200 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1));
minyue78b4d562016-11-30 12:47:39201 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _));
perkjec81bcd2016-05-11 13:01:13202 clock_.AdvanceTimeMilliseconds(25);
203 controller_->Process();
204}
205
Sebastian Jansson56da2f72018-02-28 12:07:28206TEST_F(LegacySendSideCongestionControllerTest, SignalNetworkState) {
minyue78b4d562016-11-30 12:47:39207 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _));
perkjfea93092016-05-14 07:58:48208 controller_->SignalNetworkState(kNetworkDown);
209
minyue78b4d562016-11-30 12:47:39210 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _));
perkjfea93092016-05-14 07:58:48211 controller_->SignalNetworkState(kNetworkUp);
212
minyue78b4d562016-11-30 12:47:39213 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _));
perkjfea93092016-05-14 07:58:48214 controller_->SignalNetworkState(kNetworkDown);
215}
216
Sebastian Jansson56da2f72018-02-28 12:07:28217TEST_F(LegacySendSideCongestionControllerTest, OnNetworkRouteChanged) {
honghaiz059e1832016-06-24 18:03:55218 int new_bitrate = 200000;
Stefan Holmer5c8942a2017-08-22 14:16:44219 testing::Mock::VerifyAndClearExpectations(pacer_.get());
minyue78b4d562016-11-30 12:47:39220 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _));
Sebastian Janssonea86bb72018-02-14 16:53:38221 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate));
Stefan Holmer9ea46b52017-03-15 11:40:25222 rtc::NetworkRoute route;
223 route.local_network_id = 1;
224 controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1);
honghaiz059e1832016-06-24 18:03:55225
226 // If the bitrate is reset to -1, the new starting bitrate will be
michaeltf082c2aa2016-11-07 12:17:14227 // the minimum default bitrate kMinBitrateBps.
minyue78b4d562016-11-30 12:47:39228 EXPECT_CALL(
229 observer_,
230 OnNetworkChanged(congestion_controller::GetMinBitrateBps(), _, _, _));
Sebastian Janssonea86bb72018-02-14 16:53:38231 EXPECT_CALL(*pacer_,
232 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps()));
Stefan Holmer9ea46b52017-03-15 11:40:25233 route.local_network_id = 2;
234 controller_->OnNetworkRouteChanged(route, -1, -1, -1);
honghaiz059e1832016-06-24 18:03:55235}
236
Sebastian Jansson56da2f72018-02-28 12:07:28237TEST_F(LegacySendSideCongestionControllerTest, OldFeedback) {
stefandd200542017-03-17 13:19:11238 int new_bitrate = 200000;
Stefan Holmer5c8942a2017-08-22 14:16:44239 testing::Mock::VerifyAndClearExpectations(pacer_.get());
stefandd200542017-03-17 13:19:11240 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _));
Sebastian Janssonea86bb72018-02-14 16:53:38241 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate));
stefandd200542017-03-17 13:19:11242
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 Janssonea86bb72018-02-14 16:53:38274 EXPECT_CALL(*pacer_,
275 SetEstimatedBitrate(congestion_controller::GetMinBitrateBps()));
stefandd200542017-03-17 13:19:11276 route.local_network_id = 2;
277 controller_->OnNetworkRouteChanged(route, -1, -1, -1);
278}
279
Sebastian Jansson56da2f72018-02-28 12:07:28280TEST_F(LegacySendSideCongestionControllerTest,
perkjfea93092016-05-14 07:58:48281 SignalNetworkStateAndQueueIsFullAndEstimateChange) {
Sebastian Janssonea86bb72018-02-14 16:53:38282 // Send queue is full
perkjfea93092016-05-14 07:58:48283 EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
284 .WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1));
minyue78b4d562016-11-30 12:47:39285 EXPECT_CALL(observer_, OnNetworkChanged(0, _, _, _));
perkjfea93092016-05-14 07:58:48286 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 Janssonea86bb72018-02-14 16:53:38297 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2));
perkjfea93092016-05-14 07:58:48298 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 Janssonea86bb72018-02-14 16:53:38304 .WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1));
minyue78b4d562016-11-30 12:47:39305 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _));
perkjfea93092016-05-14 07:58:48306 controller_->Process();
307}
308
Sebastian Jansson56da2f72018-02-28 12:07:28309TEST_F(LegacySendSideCongestionControllerTest, GetPacerQueuingDelayMs) {
minyue78b4d562016-11-30 12:47:39310 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, _)).Times(AtLeast(1));
asapersson14f12502016-09-08 06:14:50311
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 Jansson56da2f72018-02-28 12:07:28325TEST_F(LegacySendSideCongestionControllerTest, GetProbingInterval) {
minyue78b4d562016-11-30 12:47:39326 clock_.AdvanceTimeMilliseconds(25);
327 controller_->Process();
328
329 EXPECT_CALL(observer_, OnNetworkChanged(_, _, _, testing::Ne(0)));
Sebastian Janssonea86bb72018-02-14 16:53:38330 EXPECT_CALL(*pacer_, SetEstimatedBitrate(_));
minyue78b4d562016-11-30 12:47:39331 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
332 clock_.AdvanceTimeMilliseconds(25);
333 controller_->Process();
334}
335
Sebastian Jansson56da2f72018-02-28 12:07:28336TEST_F(LegacySendSideCongestionControllerTest, ProbeOnRouteChange) {
Stefan Holmer5c8942a2017-08-22 14:16:44337 testing::Mock::VerifyAndClearExpectations(pacer_.get());
Piotr (Peter) Slatalac39f4622019-02-15 15:38:04338 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6, _));
339 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12, _));
philipelcb9ba302017-03-07 14:30:59340 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _));
Stefan Holmer9ea46b52017-03-15 11:40:25341 rtc::NetworkRoute route;
342 route.local_network_id = 1;
343 controller_->OnNetworkRouteChanged(route, 2 * kInitialBitrateBps, 0,
344 20 * kInitialBitrateBps);
philipelcb9ba302017-03-07 14:30:59345}
346
elad.alon5bbf43f2017-03-09 14:40:08347// Bandwidth estimation is updated when feedbacks are received.
348// Feedbacks which show an increasing delay cause the estimation to be reduced.
Sebastian Jansson56da2f72018-02-28 12:07:28349TEST_F(LegacySendSideCongestionControllerTest, UpdatesDelayBasedEstimate) {
elad.alon5bbf43f2017-03-09 14:40:08350 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}
philipela4205512017-09-26 12:36:58367
Sebastian Jansson56da2f72018-02-28 12:07:28368TEST_F(LegacySendSideCongestionControllerTest, PacerQueueEncodeRatePushback) {
philipela4205512017-09-26 12:36:58369 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
perkjec81bcd2016-05-11 13:01:13406} // namespace test
407} // namespace webrtc