Chromium Code Reviews| 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 |
| 11 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | |
| 11 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" | 12 #include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h" |
| 12 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 13 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 13 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 14 #include "webrtc/modules/congestion_controller/congestion_controller_unittests_h elper.h" |
| 14 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont roller.h" | 15 #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_cont roller.h" |
| 15 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" | 16 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" |
| 16 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" | 17 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" |
| 17 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_observer.h" | 18 #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" | |
| 18 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
| 19 #include "webrtc/test/gmock.h" | 21 #include "webrtc/test/gmock.h" |
| 20 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
| 21 | 23 |
| 22 using testing::_; | 24 using testing::_; |
| 23 using testing::AtLeast; | 25 using testing::AtLeast; |
| 24 using testing::NiceMock; | 26 using testing::NiceMock; |
| 25 using testing::Return; | 27 using testing::Return; |
| 26 using testing::SaveArg; | 28 using testing::SaveArg; |
| 27 using testing::StrictMock; | 29 using testing::StrictMock; |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 32 const webrtc::PacedPacketInfo kPacingInfo0(0, 5, 2000); | |
| 33 const webrtc::PacedPacketInfo kPacingInfo1(1, 8, 4000); | |
| 30 | 34 |
| 31 // Helper to convert some time format to resolution used in absolute send time | 35 // Helper to convert some time format to resolution used in absolute send time |
| 32 // header extension, rounded upwards. |t| is the time to convert, in some | 36 // header extension, rounded upwards. |t| is the time to convert, in some |
| 33 // resolution. |denom| is the value to divide |t| by to get whole seconds, | 37 // resolution. |denom| is the value to divide |t| by to get whole seconds, |
| 34 // e.g. |denom| = 1000 if |t| is in milliseconds. | 38 // e.g. |denom| = 1000 if |t| is in milliseconds. |
| 35 uint32_t AbsSendTime(int64_t t, int64_t denom) { | 39 uint32_t AbsSendTime(int64_t t, int64_t denom) { |
| 36 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; | 40 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; |
| 37 } | 41 } |
| 38 | 42 |
| 39 } // namespace | 43 } // namespace |
| 40 | 44 |
| 41 namespace webrtc { | 45 namespace webrtc { |
| 42 namespace test { | 46 namespace test { |
| 43 | 47 |
| 44 class CongestionControllerTest : public ::testing::Test { | 48 class CongestionControllerTest : public ::testing::Test { |
| 45 protected: | 49 protected: |
| 46 CongestionControllerTest() : clock_(123456) {} | 50 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} |
| 47 ~CongestionControllerTest() override {} | 51 ~CongestionControllerTest() override {} |
| 48 | 52 |
| 49 void SetUp() override { | 53 void SetUp() override { |
| 50 pacer_ = new NiceMock<MockPacedSender>(); | 54 pacer_ = new NiceMock<MockPacedSender>(); |
| 51 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. | 55 std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership. |
| 52 controller_.reset(new CongestionController( | 56 controller_.reset(new CongestionController( |
| 53 &clock_, &observer_, &remote_bitrate_observer_, &event_log_, | 57 &clock_, &observer_, &remote_bitrate_observer_, &event_log_, |
| 54 &packet_router_, std::move(pacer))); | 58 &packet_router_, std::move(pacer))); |
| 55 bandwidth_observer_.reset( | 59 bandwidth_observer_.reset( |
| 56 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); | 60 controller_->GetBitrateController()->CreateRtcpBandwidthObserver()); |
| 57 | 61 |
| 58 // Set the initial bitrate estimate and expect the |observer| and |pacer_| | 62 // Set the initial bitrate estimate and expect the |observer| and |pacer_| |
| 59 // to be updated. | 63 // to be updated. |
| 60 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); | 64 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _, _)); |
| 61 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); | 65 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps)); |
| 62 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3)); | 66 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 3)); |
| 63 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5)); | 67 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 5)); |
| 64 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); | 68 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); |
| 65 } | 69 } |
| 66 | 70 |
| 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 | |
| 67 SimulatedClock clock_; | 107 SimulatedClock clock_; |
| 68 StrictMock<MockCongestionObserver> observer_; | 108 StrictMock<MockCongestionObserver> observer_; |
| 109 TargetBitrateObserver target_bitrate_observer_; | |
| 69 NiceMock<MockPacedSender>* pacer_; | 110 NiceMock<MockPacedSender>* pacer_; |
| 70 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; | 111 NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; |
| 71 NiceMock<MockRtcEventLog> event_log_; | 112 NiceMock<MockRtcEventLog> event_log_; |
| 72 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | 113 std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
| 73 PacketRouter packet_router_; | 114 PacketRouter packet_router_; |
| 74 std::unique_ptr<CongestionController> controller_; | 115 std::unique_ptr<CongestionController> controller_; |
| 75 const uint32_t kInitialBitrateBps = 60000; | 116 const uint32_t kInitialBitrateBps = 60000; |
| 117 | |
| 118 rtc::Optional<uint32_t> target_bitrate_bps_; | |
| 76 }; | 119 }; |
| 77 | 120 |
| 78 TEST_F(CongestionControllerTest, OnNetworkChanged) { | 121 TEST_F(CongestionControllerTest, OnNetworkChanged) { |
| 79 // Test no change. | 122 // Test no change. |
| 80 clock_.AdvanceTimeMilliseconds(25); | 123 clock_.AdvanceTimeMilliseconds(25); |
| 81 controller_->Process(); | 124 controller_->Process(); |
| 82 | 125 |
| 83 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); | 126 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
| 84 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); | 127 EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2)); |
| 85 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); | 128 bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 289 |
| 247 TEST_F(CongestionControllerTest, ProbeOnBweReset) { | 290 TEST_F(CongestionControllerTest, ProbeOnBweReset) { |
| 248 testing::Mock::VerifyAndClearExpectations(pacer_); | 291 testing::Mock::VerifyAndClearExpectations(pacer_); |
| 249 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); | 292 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 6)); |
| 250 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); | 293 EXPECT_CALL(*pacer_, CreateProbeCluster(kInitialBitrateBps * 12)); |
| 251 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); | 294 EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _, _)); |
| 252 controller_->ResetBweAndBitrates(2 * kInitialBitrateBps, 0, | 295 controller_->ResetBweAndBitrates(2 * kInitialBitrateBps, 0, |
| 253 20 * kInitialBitrateBps); | 296 20 * kInitialBitrateBps); |
| 254 } | 297 } |
| 255 | 298 |
| 299 // Estimated bitrate reduced when the feedbacks arrive with such a long delay, | |
| 300 // that the send-time-history no longer holds the feedbacked packets. | |
| 301 TEST_F(CongestionControllerTest, LongFeedbackDelays) { | |
| 302 TargetBitrateTrackingSetup(); | |
| 303 | |
| 304 const int64_t kFeedbackTimeoutMs = 60001; | |
| 305 const int kMaxConsecutiveFailedLookups = 5; | |
| 306 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) { | |
| 307 std::vector<PacketFeedback> packets; | |
| 308 packets.push_back( | |
| 309 PacketFeedback(i * 100, 2 * i * 100, 0, 1500, kPacingInfo0)); | |
| 310 packets.push_back( | |
| 311 PacketFeedback(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, kPacingInfo0)); | |
| 312 packets.push_back( | |
| 313 PacketFeedback(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, kPacingInfo0)); | |
| 314 packets.push_back( | |
| 315 PacketFeedback(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, kPacingInfo1)); | |
| 316 packets.push_back( | |
| 317 PacketFeedback(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, kPacingInfo1)); | |
| 318 | |
| 319 for (const PacketFeedback& packet : packets) | |
| 320 OnSentPacket(packet); | |
| 321 | |
| 322 rtcp::TransportFeedback feedback; | |
| 323 feedback.SetBase(packets[0].sequence_number, | |
| 324 packets[0].arrival_time_ms * 1000); | |
| 325 | |
| 326 for (const PacketFeedback& packet : packets) { | |
| 327 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | |
| 328 packet.arrival_time_ms * 1000)); | |
| 329 } | |
| 330 | |
| 331 feedback.Build(); | |
| 332 | |
| 333 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs); | |
| 334 PacketFeedback later_packet(kFeedbackTimeoutMs + i * 100 + 40, | |
| 335 kFeedbackTimeoutMs + i * 200 + 40, 5, 1500, | |
| 336 kPacingInfo1); | |
| 337 OnSentPacket(later_packet); | |
| 338 | |
| 339 controller_->OnTransportFeedback(feedback); | |
| 340 | |
| 341 // Check that packets have timed out. | |
| 342 for (PacketFeedback& packet : packets) { | |
| 343 packet.send_time_ms = -1; | |
| 344 packet.payload_size = 0; | |
| 345 packet.pacing_info = PacedPacketInfo(); | |
| 346 } | |
| 347 ComparePacketVectors(packets, controller_->GetTransportFeedbackVector()); | |
| 348 } | |
| 349 | |
| 350 controller_->Process(); | |
| 351 | |
| 352 EXPECT_EQ(kInitialBitrateBps / 2, target_bitrate_bps_); | |
| 353 | |
| 354 // Test with feedback that isn't late enough to time out. | |
| 355 { | |
| 356 std::vector<PacketFeedback> packets; | |
| 357 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | |
| 358 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); | |
| 359 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); | |
| 360 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); | |
| 361 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); | |
| 362 | |
| 363 for (const PacketFeedback& packet : packets) | |
| 364 OnSentPacket(packet); | |
| 365 | |
| 366 rtcp::TransportFeedback feedback; | |
| 367 feedback.SetBase(packets[0].sequence_number, | |
| 368 packets[0].arrival_time_ms * 1000); | |
| 369 | |
| 370 for (const PacketFeedback& packet : packets) { | |
| 371 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | |
| 372 packet.arrival_time_ms * 1000)); | |
| 373 } | |
| 374 | |
| 375 feedback.Build(); | |
| 376 | |
| 377 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1); | |
| 378 PacketFeedback later_packet(kFeedbackTimeoutMs + 140, | |
| 379 kFeedbackTimeoutMs + 240, 5, 1500, | |
| 380 kPacingInfo1); | |
| 381 OnSentPacket(later_packet); | |
| 382 | |
| 383 controller_->OnTransportFeedback(feedback); | |
| 384 ComparePacketVectors(packets, controller_->GetTransportFeedbackVector()); | |
| 385 } | |
| 386 } | |
| 387 | |
| 388 // Bandwidth estimation is updated when feedbacks are received. | |
| 389 // Feedbacks which show an increasing delay cause the estimation to be reduced. | |
| 390 TEST_F(CongestionControllerTest, UpdatesDelayBasedEstimate) { | |
| 391 TargetBitrateTrackingSetup(); | |
| 392 | |
| 393 uint16_t seq_num = 0; | |
| 394 constexpr size_t kPayloadSize = 1000; | |
| 395 | |
| 396 // The test must run and insert packets/feedback long enough that the | |
| 397 // BWE computes a valid estimate. | |
| 398 const int64_t kRunTimeMs = 6000; | |
| 399 int64_t start_time_ms = clock_.TimeInMilliseconds(); | |
| 400 while (clock_.TimeInMilliseconds() - start_time_ms < kRunTimeMs) { | |
| 401 PacketFeedback packet(clock_.TimeInMilliseconds(), | |
| 402 clock_.TimeInMilliseconds(), seq_num, kPayloadSize, | |
| 403 PacedPacketInfo()); | |
| 404 OnSentPacket(packet); | |
| 405 // Create expected feedback and send into adapter. | |
| 406 std::unique_ptr<rtcp::TransportFeedback> feedback( | |
| 407 new rtcp::TransportFeedback()); | |
| 408 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); | |
| 409 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, | |
| 410 packet.arrival_time_ms * 1000)); | |
| 411 rtc::Buffer raw_packet = feedback->Build(); | |
| 412 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), | |
| 413 raw_packet.size()); | |
| 414 EXPECT_TRUE(feedback.get() != nullptr); | |
| 415 controller_->OnTransportFeedback(*feedback.get()); | |
| 416 clock_.AdvanceTimeMilliseconds(50); | |
| 417 controller_->Process(); | |
| 418 ++seq_num; | |
| 419 } | |
| 420 EXPECT_TRUE(target_bitrate_bps_); | |
| 421 if (!target_bitrate_bps_) | |
| 422 return; // Would crash the tests later otherwise. | |
|
stefan-webrtc
2017/03/09 09:41:02
Change line 420 to ASSERT_TRUE instead. That basic
elad.alon_webrtc.org
2017/03/09 12:03:54
Done.
| |
| 423 | |
| 424 // Repeat, but this time with a building delay, and make sure that the | |
| 425 // estimation is adjusted downwards. | |
| 426 uint32_t bitrate_before_delay = *target_bitrate_bps_; | |
| 427 int64_t delay = 0; | |
| 428 while (clock_.TimeInMilliseconds() - start_time_ms < 2 * kRunTimeMs) { | |
|
stefan-webrtc
2017/03/09 09:41:02
Perhaps break this loop out into a function with d
elad.alon_webrtc.org
2017/03/09 12:03:54
Done.
| |
| 429 delay += 50; // Delay has to increase, or it's just an added RTT. | |
|
stefan-webrtc
2017/03/09 09:41:02
"a longer RTT"?
elad.alon_webrtc.org
2017/03/09 12:03:54
"Longer" is confusing to me, because it might be u
| |
| 430 PacketFeedback packet(clock_.TimeInMilliseconds() + delay, | |
| 431 clock_.TimeInMilliseconds(), seq_num, kPayloadSize, | |
| 432 PacedPacketInfo()); | |
| 433 OnSentPacket(packet); | |
| 434 // Create expected feedback and send into adapter. | |
| 435 std::unique_ptr<rtcp::TransportFeedback> feedback( | |
| 436 new rtcp::TransportFeedback()); | |
| 437 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); | |
| 438 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, | |
| 439 packet.arrival_time_ms * 1000)); | |
| 440 rtc::Buffer raw_packet = feedback->Build(); | |
| 441 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), | |
| 442 raw_packet.size()); | |
| 443 EXPECT_TRUE(feedback.get() != nullptr); | |
| 444 controller_->OnTransportFeedback(*feedback.get()); | |
| 445 clock_.AdvanceTimeMilliseconds(50); | |
| 446 controller_->Process(); | |
| 447 ++seq_num; | |
| 448 } | |
| 449 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); | |
| 450 } | |
| 256 } // namespace test | 451 } // namespace test |
| 257 } // namespace webrtc | 452 } // namespace webrtc |
| OLD | NEW |