| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; | 42 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; |
| 43 } | 43 } |
| 44 | 44 |
| 45 class MockPacketRouter : public PacketRouter { | 45 class MockPacketRouter : public PacketRouter { |
| 46 public: | 46 public: |
| 47 MOCK_METHOD2(OnReceiveBitrateChanged, | 47 MOCK_METHOD2(OnReceiveBitrateChanged, |
| 48 void(const std::vector<uint32_t>& ssrcs, | 48 void(const std::vector<uint32_t>& ssrcs, |
| 49 uint32_t bitrate)); | 49 uint32_t bitrate)); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 const uint32_t kInitialBitrateBps = 60000; | 52 constexpr uint32_t kInitialBitrateBps = 60000; |
| 53 constexpr size_t kRtpHeadersSize = 12; |
| 54 constexpr size_t kTransportHeadersSize = 20; |
| 53 | 55 |
| 54 } // namespace | 56 } // namespace |
| 55 | 57 |
| 56 namespace test { | 58 namespace test { |
| 57 | 59 |
| 58 class CongestionControllerTest : public ::testing::Test { | 60 class CongestionControllerTest : public ::testing::Test { |
| 59 protected: | 61 protected: |
| 60 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} | 62 CongestionControllerTest() : clock_(123456), target_bitrate_observer_(this) {} |
| 61 ~CongestionControllerTest() override {} | 63 ~CongestionControllerTest() override {} |
| 62 | 64 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 83 void TargetBitrateTrackingSetup() { | 85 void TargetBitrateTrackingSetup() { |
| 84 std::unique_ptr<PacedSender> pacer(new NiceMock<MockPacedSender>()); | 86 std::unique_ptr<PacedSender> pacer(new NiceMock<MockPacedSender>()); |
| 85 controller_.reset(new CongestionController( | 87 controller_.reset(new CongestionController( |
| 86 &clock_, &target_bitrate_observer_, &remote_bitrate_observer_, | 88 &clock_, &target_bitrate_observer_, &remote_bitrate_observer_, |
| 87 &event_log_, &packet_router_, std::move(pacer))); | 89 &event_log_, &packet_router_, std::move(pacer))); |
| 88 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); | 90 controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void OnSentPacket(const PacketFeedback& packet_feedback) { | 93 void OnSentPacket(const PacketFeedback& packet_feedback) { |
| 92 constexpr uint32_t ssrc = 0; | 94 constexpr uint32_t ssrc = 0; |
| 93 controller_->AddPacket(ssrc, packet_feedback.sequence_number, | 95 controller_->AddPacket( |
| 94 packet_feedback.payload_size, | 96 ssrc, packet_feedback.sequence_number, packet_feedback.payload_size, |
| 95 packet_feedback.pacing_info); | 97 packet_feedback.rtp_headers_size, packet_feedback.pacing_info); |
| 96 controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number, | 98 controller_->OnSentPacket(rtc::SentPacket(packet_feedback.sequence_number, |
| 97 packet_feedback.send_time_ms)); | 99 packet_feedback.send_time_ms)); |
| 98 } | 100 } |
| 99 | 101 |
| 100 // Allows us to track the target bitrate, without prescribing the exact | 102 // Allows us to track the target bitrate, without prescribing the exact |
| 101 // iterations when this would hapen, like a mock would. | 103 // iterations when this would hapen, like a mock would. |
| 102 class TargetBitrateObserver : public CongestionController::Observer { | 104 class TargetBitrateObserver : public CongestionController::Observer { |
| 103 public: | 105 public: |
| 104 explicit TargetBitrateObserver(CongestionControllerTest* owner) | 106 explicit TargetBitrateObserver(CongestionControllerTest* owner) |
| 105 : owner_(owner) {} | 107 : owner_(owner) {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 | 119 |
| 118 void PacketTransmissionAndFeedbackBlock(uint16_t* seq_num, | 120 void PacketTransmissionAndFeedbackBlock(uint16_t* seq_num, |
| 119 int64_t runtime_ms, | 121 int64_t runtime_ms, |
| 120 int64_t delay) { | 122 int64_t delay) { |
| 121 int64_t delay_buildup = 0; | 123 int64_t delay_buildup = 0; |
| 122 int64_t start_time_ms = clock_.TimeInMilliseconds(); | 124 int64_t start_time_ms = clock_.TimeInMilliseconds(); |
| 123 while (clock_.TimeInMilliseconds() - start_time_ms < runtime_ms) { | 125 while (clock_.TimeInMilliseconds() - start_time_ms < runtime_ms) { |
| 124 constexpr size_t kPayloadSize = 1000; | 126 constexpr size_t kPayloadSize = 1000; |
| 125 PacketFeedback packet(clock_.TimeInMilliseconds() + delay_buildup, | 127 PacketFeedback packet(clock_.TimeInMilliseconds() + delay_buildup, |
| 126 clock_.TimeInMilliseconds(), *seq_num, kPayloadSize, | 128 clock_.TimeInMilliseconds(), *seq_num, kPayloadSize, |
| 129 kRtpHeadersSize, kTransportHeadersSize, |
| 127 PacedPacketInfo()); | 130 PacedPacketInfo()); |
| 128 delay_buildup += delay; // Delay has to increase, or it's just RTT. | 131 delay_buildup += delay; // Delay has to increase, or it's just RTT. |
| 129 OnSentPacket(packet); | 132 OnSentPacket(packet); |
| 130 // Create expected feedback and send into adapter. | 133 // Create expected feedback and send into adapter. |
| 131 std::unique_ptr<rtcp::TransportFeedback> feedback( | 134 std::unique_ptr<rtcp::TransportFeedback> feedback( |
| 132 new rtcp::TransportFeedback()); | 135 new rtcp::TransportFeedback()); |
| 133 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); | 136 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); |
| 134 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, | 137 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, |
| 135 packet.arrival_time_ms * 1000)); | 138 packet.arrival_time_ms * 1000)); |
| 136 rtc::Buffer raw_packet = feedback->Build(); | 139 rtc::Buffer raw_packet = feedback->Build(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 249 } |
| 247 | 250 |
| 248 TEST_F(CongestionControllerTest, OldFeedback) { | 251 TEST_F(CongestionControllerTest, OldFeedback) { |
| 249 int new_bitrate = 200000; | 252 int new_bitrate = 200000; |
| 250 testing::Mock::VerifyAndClearExpectations(pacer_); | 253 testing::Mock::VerifyAndClearExpectations(pacer_); |
| 251 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); | 254 EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _, _)); |
| 252 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); | 255 EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate)); |
| 253 | 256 |
| 254 // Send a few packets on the first network route. | 257 // Send a few packets on the first network route. |
| 255 std::vector<PacketFeedback> packets; | 258 std::vector<PacketFeedback> packets; |
| 256 packets.push_back(PacketFeedback(0, 0, 0, 1500, kPacingInfo0)); | 259 packets.push_back(PacketFeedback(0, 0, 0, 1500, kRtpHeadersSize, |
| 257 packets.push_back(PacketFeedback(10, 10, 1, 1500, kPacingInfo0)); | 260 kTransportHeadersSize, kPacingInfo0)); |
| 258 packets.push_back(PacketFeedback(20, 20, 2, 1500, kPacingInfo0)); | 261 packets.push_back(PacketFeedback(10, 10, 1, 1500, kRtpHeadersSize, |
| 259 packets.push_back(PacketFeedback(30, 30, 3, 1500, kPacingInfo1)); | 262 kTransportHeadersSize, kPacingInfo0)); |
| 260 packets.push_back(PacketFeedback(40, 40, 4, 1500, kPacingInfo1)); | 263 packets.push_back(PacketFeedback(20, 20, 2, 1500, kRtpHeadersSize, |
| 264 kTransportHeadersSize, kPacingInfo0)); |
| 265 packets.push_back(PacketFeedback(30, 30, 3, 1500, kRtpHeadersSize, |
| 266 kTransportHeadersSize, kPacingInfo1)); |
| 267 packets.push_back(PacketFeedback(40, 40, 4, 1500, kRtpHeadersSize, |
| 268 kTransportHeadersSize, kPacingInfo1)); |
| 261 | 269 |
| 262 for (const PacketFeedback& packet : packets) | 270 for (const PacketFeedback& packet : packets) |
| 263 OnSentPacket(packet); | 271 OnSentPacket(packet); |
| 264 | 272 |
| 265 // Change route and then insert a number of feedback packets. | 273 // Change route and then insert a number of feedback packets. |
| 266 rtc::NetworkRoute route; | 274 rtc::NetworkRoute route; |
| 267 route.local_network_id = 1; | 275 route.local_network_id = 1; |
| 268 controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1); | 276 controller_->OnNetworkRouteChanged(route, new_bitrate, -1, -1); |
| 269 | 277 |
| 270 for (const PacketFeedback& packet : packets) { | 278 for (const PacketFeedback& packet : packets) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 391 |
| 384 // Estimated bitrate reduced when the feedbacks arrive with such a long delay, | 392 // Estimated bitrate reduced when the feedbacks arrive with such a long delay, |
| 385 // that the send-time-history no longer holds the feedbacked packets. | 393 // that the send-time-history no longer holds the feedbacked packets. |
| 386 TEST_F(CongestionControllerTest, LongFeedbackDelays) { | 394 TEST_F(CongestionControllerTest, LongFeedbackDelays) { |
| 387 TargetBitrateTrackingSetup(); | 395 TargetBitrateTrackingSetup(); |
| 388 | 396 |
| 389 const int64_t kFeedbackTimeoutMs = 60001; | 397 const int64_t kFeedbackTimeoutMs = 60001; |
| 390 const int kMaxConsecutiveFailedLookups = 5; | 398 const int kMaxConsecutiveFailedLookups = 5; |
| 391 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) { | 399 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) { |
| 392 std::vector<PacketFeedback> packets; | 400 std::vector<PacketFeedback> packets; |
| 393 packets.push_back( | 401 packets.push_back(PacketFeedback(i * 100, 2 * i * 100, 0, 1500, |
| 394 PacketFeedback(i * 100, 2 * i * 100, 0, 1500, kPacingInfo0)); | 402 kRtpHeadersSize, kTransportHeadersSize, |
| 395 packets.push_back( | 403 kPacingInfo0)); |
| 396 PacketFeedback(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, kPacingInfo0)); | 404 packets.push_back(PacketFeedback(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, |
| 397 packets.push_back( | 405 kRtpHeadersSize, kTransportHeadersSize, |
| 398 PacketFeedback(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, kPacingInfo0)); | 406 kPacingInfo0)); |
| 399 packets.push_back( | 407 packets.push_back(PacketFeedback(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, |
| 400 PacketFeedback(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, kPacingInfo1)); | 408 kRtpHeadersSize, kTransportHeadersSize, |
| 401 packets.push_back( | 409 kPacingInfo0)); |
| 402 PacketFeedback(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, kPacingInfo1)); | 410 packets.push_back(PacketFeedback(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, |
| 411 kRtpHeadersSize, kTransportHeadersSize, |
| 412 kPacingInfo1)); |
| 413 packets.push_back(PacketFeedback(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, |
| 414 kRtpHeadersSize, kTransportHeadersSize, |
| 415 kPacingInfo1)); |
| 403 | 416 |
| 404 for (const PacketFeedback& packet : packets) | 417 for (const PacketFeedback& packet : packets) |
| 405 OnSentPacket(packet); | 418 OnSentPacket(packet); |
| 406 | 419 |
| 407 rtcp::TransportFeedback feedback; | 420 rtcp::TransportFeedback feedback; |
| 408 feedback.SetBase(packets[0].sequence_number, | 421 feedback.SetBase(packets[0].sequence_number, |
| 409 packets[0].arrival_time_ms * 1000); | 422 packets[0].arrival_time_ms * 1000); |
| 410 | 423 |
| 411 for (const PacketFeedback& packet : packets) { | 424 for (const PacketFeedback& packet : packets) { |
| 412 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | 425 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, |
| 413 packet.arrival_time_ms * 1000)); | 426 packet.arrival_time_ms * 1000)); |
| 414 } | 427 } |
| 415 | 428 |
| 416 feedback.Build(); | 429 feedback.Build(); |
| 417 | 430 |
| 418 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs); | 431 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs); |
| 419 PacketFeedback later_packet(kFeedbackTimeoutMs + i * 100 + 40, | 432 PacketFeedback later_packet( |
| 420 kFeedbackTimeoutMs + i * 200 + 40, 5, 1500, | 433 kFeedbackTimeoutMs + i * 100 + 40, kFeedbackTimeoutMs + i * 200 + 40, 5, |
| 421 kPacingInfo1); | 434 1500, kRtpHeadersSize, kTransportHeadersSize, kPacingInfo1); |
| 422 OnSentPacket(later_packet); | 435 OnSentPacket(later_packet); |
| 423 | 436 |
| 424 controller_->OnTransportFeedback(feedback); | 437 controller_->OnTransportFeedback(feedback); |
| 425 | 438 |
| 426 // Check that packets have timed out. | 439 // Check that packets have timed out. |
| 427 for (PacketFeedback& packet : packets) { | 440 for (PacketFeedback& packet : packets) { |
| 428 packet.send_time_ms = -1; | 441 packet.send_time_ms = -1; |
| 429 packet.payload_size = 0; | 442 packet.payload_size = 0; |
| 430 packet.pacing_info = PacedPacketInfo(); | 443 packet.pacing_info = PacedPacketInfo(); |
| 431 } | 444 } |
| 432 ComparePacketFeedbackVectors(packets, | 445 ComparePacketFeedbackVectors(packets, |
| 433 controller_->GetTransportFeedbackVector()); | 446 controller_->GetTransportFeedbackVector()); |
| 434 } | 447 } |
| 435 | 448 |
| 436 controller_->Process(); | 449 controller_->Process(); |
| 437 | 450 |
| 438 EXPECT_EQ(kInitialBitrateBps / 2, target_bitrate_bps_); | 451 EXPECT_EQ(kInitialBitrateBps / 2, target_bitrate_bps_); |
| 439 | 452 |
| 440 // Test with feedback that isn't late enough to time out. | 453 // Test with feedback that isn't late enough to time out. |
| 441 { | 454 { |
| 442 std::vector<PacketFeedback> packets; | 455 std::vector<PacketFeedback> packets; |
| 443 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | 456 packets.push_back(PacketFeedback(100, 200, 0, 1500, kRtpHeadersSize, |
| 444 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); | 457 kTransportHeadersSize, kPacingInfo0)); |
| 445 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); | 458 packets.push_back(PacketFeedback(110, 210, 1, 1500, kRtpHeadersSize, |
| 446 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); | 459 kTransportHeadersSize, kPacingInfo0)); |
| 447 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); | 460 packets.push_back(PacketFeedback(120, 220, 2, 1500, kRtpHeadersSize, |
| 461 kTransportHeadersSize, kPacingInfo0)); |
| 462 packets.push_back(PacketFeedback(130, 230, 3, 1500, kRtpHeadersSize, |
| 463 kTransportHeadersSize, kPacingInfo1)); |
| 464 packets.push_back(PacketFeedback(140, 240, 4, 1500, kRtpHeadersSize, |
| 465 kTransportHeadersSize, kPacingInfo1)); |
| 448 | 466 |
| 449 for (const PacketFeedback& packet : packets) | 467 for (const PacketFeedback& packet : packets) |
| 450 OnSentPacket(packet); | 468 OnSentPacket(packet); |
| 451 | 469 |
| 452 rtcp::TransportFeedback feedback; | 470 rtcp::TransportFeedback feedback; |
| 453 feedback.SetBase(packets[0].sequence_number, | 471 feedback.SetBase(packets[0].sequence_number, |
| 454 packets[0].arrival_time_ms * 1000); | 472 packets[0].arrival_time_ms * 1000); |
| 455 | 473 |
| 456 for (const PacketFeedback& packet : packets) { | 474 for (const PacketFeedback& packet : packets) { |
| 457 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | 475 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, |
| 458 packet.arrival_time_ms * 1000)); | 476 packet.arrival_time_ms * 1000)); |
| 459 } | 477 } |
| 460 | 478 |
| 461 feedback.Build(); | 479 feedback.Build(); |
| 462 | 480 |
| 463 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1); | 481 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1); |
| 464 PacketFeedback later_packet(kFeedbackTimeoutMs + 140, | 482 PacketFeedback later_packet( |
| 465 kFeedbackTimeoutMs + 240, 5, 1500, | 483 kFeedbackTimeoutMs + 140, kFeedbackTimeoutMs + 240, 5, 1500, |
| 466 kPacingInfo1); | 484 kRtpHeadersSize, kTransportHeadersSize, kPacingInfo1); |
| 467 OnSentPacket(later_packet); | 485 OnSentPacket(later_packet); |
| 468 | 486 |
| 469 controller_->OnTransportFeedback(feedback); | 487 controller_->OnTransportFeedback(feedback); |
| 470 ComparePacketFeedbackVectors(packets, | 488 ComparePacketFeedbackVectors(packets, |
| 471 controller_->GetTransportFeedbackVector()); | 489 controller_->GetTransportFeedbackVector()); |
| 472 } | 490 } |
| 473 } | 491 } |
| 474 | 492 |
| 475 // Bandwidth estimation is updated when feedbacks are received. | 493 // Bandwidth estimation is updated when feedbacks are received. |
| 476 // Feedbacks which show an increasing delay cause the estimation to be reduced. | 494 // Feedbacks which show an increasing delay cause the estimation to be reduced. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 487 ASSERT_TRUE(target_bitrate_bps_); | 505 ASSERT_TRUE(target_bitrate_bps_); |
| 488 | 506 |
| 489 // Repeat, but this time with a building delay, and make sure that the | 507 // Repeat, but this time with a building delay, and make sure that the |
| 490 // estimation is adjusted downwards. | 508 // estimation is adjusted downwards. |
| 491 uint32_t bitrate_before_delay = *target_bitrate_bps_; | 509 uint32_t bitrate_before_delay = *target_bitrate_bps_; |
| 492 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); | 510 PacketTransmissionAndFeedbackBlock(&seq_num, kRunTimeMs, 50); |
| 493 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); | 511 EXPECT_LT(*target_bitrate_bps_, bitrate_before_delay); |
| 494 } | 512 } |
| 495 } // namespace test | 513 } // namespace test |
| 496 } // namespace webrtc | 514 } // namespace webrtc |
| OLD | NEW |