| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 <limits> | 11 #include <limits> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/safe_conversions.h" | 16 #include "webrtc/base/safe_conversions.h" |
| 17 #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller
.h" | 17 #include "webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller
.h" |
| 18 #include "webrtc/modules/congestion_controller/congestion_controller_unittests_h
elper.h" |
| 18 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" | 19 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" |
| 19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 21 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
| 22 #include "webrtc/test/gmock.h" | 23 #include "webrtc/test/gmock.h" |
| 23 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
| 24 | 25 |
| 25 using ::testing::_; | 26 using ::testing::_; |
| 26 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 27 | 28 |
| 28 namespace webrtc { | 29 namespace webrtc { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 const PacedPacketInfo kPacingInfo0(0, 5, 2000); | 32 const PacedPacketInfo kPacingInfo0(0, 5, 2000); |
| 32 const PacedPacketInfo kPacingInfo1(1, 8, 4000); | 33 const PacedPacketInfo kPacingInfo1(1, 8, 4000); |
| 33 const PacedPacketInfo kPacingInfo2(2, 14, 7000); | 34 const PacedPacketInfo kPacingInfo2(2, 14, 7000); |
| 34 const PacedPacketInfo kPacingInfo3(3, 20, 10000); | 35 const PacedPacketInfo kPacingInfo3(3, 20, 10000); |
| 35 const PacedPacketInfo kPacingInfo4(4, 22, 10000); | 36 const PacedPacketInfo kPacingInfo4(4, 22, 10000); |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace test { | 39 namespace test { |
| 39 | 40 |
| 40 class TransportFeedbackAdapterTest : public ::testing::Test { | 41 class TransportFeedbackAdapterTest : public ::testing::Test { |
| 41 public: | 42 public: |
| 42 TransportFeedbackAdapterTest() | 43 TransportFeedbackAdapterTest() : clock_(0) {} |
| 43 : clock_(0), bitrate_controller_(this), target_bitrate_bps_(0) {} | |
| 44 | 44 |
| 45 virtual ~TransportFeedbackAdapterTest() {} | 45 virtual ~TransportFeedbackAdapterTest() {} |
| 46 | 46 |
| 47 virtual void SetUp() { | 47 virtual void SetUp() { |
| 48 adapter_.reset( | 48 adapter_.reset(new TransportFeedbackAdapter(&clock_)); |
| 49 new TransportFeedbackAdapter(nullptr, &clock_, &bitrate_controller_)); | |
| 50 adapter_->InitBwe(); | |
| 51 adapter_->SetStartBitrate(300000); | |
| 52 } | 49 } |
| 53 | 50 |
| 54 virtual void TearDown() { adapter_.reset(); } | 51 virtual void TearDown() { adapter_.reset(); } |
| 55 | 52 |
| 56 protected: | 53 protected: |
| 57 // Proxy class used since TransportFeedbackAdapter will own the instance | |
| 58 // passed at construction. | |
| 59 class MockBitrateControllerAdapter : public MockBitrateController { | |
| 60 public: | |
| 61 explicit MockBitrateControllerAdapter(TransportFeedbackAdapterTest* owner) | |
| 62 : MockBitrateController(), owner_(owner) {} | |
| 63 | |
| 64 ~MockBitrateControllerAdapter() override {} | |
| 65 | |
| 66 void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) override { | |
| 67 owner_->target_bitrate_bps_ = result.target_bitrate_bps; | |
| 68 } | |
| 69 | |
| 70 TransportFeedbackAdapterTest* const owner_; | |
| 71 }; | |
| 72 | |
| 73 void OnReceivedEstimatedBitrate(uint32_t bitrate) {} | 54 void OnReceivedEstimatedBitrate(uint32_t bitrate) {} |
| 74 | 55 |
| 75 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, | 56 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, |
| 76 int64_t rtt, | 57 int64_t rtt, |
| 77 int64_t now_ms) {} | 58 int64_t now_ms) {} |
| 78 | 59 |
| 79 void ComparePacketVectors(const std::vector<PacketFeedback>& truth, | |
| 80 const std::vector<PacketFeedback>& input) { | |
| 81 ASSERT_EQ(truth.size(), input.size()); | |
| 82 size_t len = truth.size(); | |
| 83 // truth contains the input data for the test, and input is what will be | |
| 84 // sent to the bandwidth estimator. truth.arrival_tims_ms is used to | |
| 85 // populate the transport feedback messages. As these times may be changed | |
| 86 // (because of resolution limits in the packets, and because of the time | |
| 87 // base adjustment performed by the TransportFeedbackAdapter at the first | |
| 88 // packet, the truth[x].arrival_time and input[x].arrival_time may not be | |
| 89 // equal. However, the difference must be the same for all x. | |
| 90 int64_t arrival_time_delta = | |
| 91 truth[0].arrival_time_ms - input[0].arrival_time_ms; | |
| 92 for (size_t i = 0; i < len; ++i) { | |
| 93 RTC_CHECK(truth[i].arrival_time_ms != PacketFeedback::kNotReceived); | |
| 94 if (input[i].arrival_time_ms != PacketFeedback::kNotReceived) { | |
| 95 EXPECT_EQ(truth[i].arrival_time_ms, | |
| 96 input[i].arrival_time_ms + arrival_time_delta); | |
| 97 } | |
| 98 EXPECT_EQ(truth[i].send_time_ms, input[i].send_time_ms); | |
| 99 EXPECT_EQ(truth[i].sequence_number, input[i].sequence_number); | |
| 100 EXPECT_EQ(truth[i].payload_size, input[i].payload_size); | |
| 101 EXPECT_EQ(truth[i].pacing_info, input[i].pacing_info); | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 void OnSentPacket(const PacketFeedback& packet_feedback) { | 60 void OnSentPacket(const PacketFeedback& packet_feedback) { |
| 106 adapter_->AddPacket(packet_feedback.sequence_number, | 61 adapter_->AddPacket(packet_feedback.sequence_number, |
| 107 packet_feedback.payload_size, | 62 packet_feedback.payload_size, |
| 108 packet_feedback.pacing_info); | 63 packet_feedback.pacing_info); |
| 109 adapter_->OnSentPacket(packet_feedback.sequence_number, | 64 adapter_->OnSentPacket(packet_feedback.sequence_number, |
| 110 packet_feedback.send_time_ms); | 65 packet_feedback.send_time_ms); |
| 111 } | 66 } |
| 112 | 67 |
| 113 SimulatedClock clock_; | 68 SimulatedClock clock_; |
| 114 MockBitrateControllerAdapter bitrate_controller_; | |
| 115 std::unique_ptr<TransportFeedbackAdapter> adapter_; | 69 std::unique_ptr<TransportFeedbackAdapter> adapter_; |
| 116 | |
| 117 uint32_t target_bitrate_bps_; | |
| 118 }; | 70 }; |
| 119 | 71 |
| 120 TEST_F(TransportFeedbackAdapterTest, AdaptsFeedbackAndPopulatesSendTimes) { | 72 TEST_F(TransportFeedbackAdapterTest, AdaptsFeedbackAndPopulatesSendTimes) { |
| 121 std::vector<PacketFeedback> packets; | 73 std::vector<PacketFeedback> packets; |
| 122 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | 74 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); |
| 123 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); | 75 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); |
| 124 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); | 76 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); |
| 125 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); | 77 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); |
| 126 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); | 78 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); |
| 127 | 79 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | 123 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, |
| 172 packet.arrival_time_ms * 1000)); | 124 packet.arrival_time_ms * 1000)); |
| 173 } | 125 } |
| 174 | 126 |
| 175 feedback.Build(); | 127 feedback.Build(); |
| 176 | 128 |
| 177 adapter_->OnTransportFeedback(feedback); | 129 adapter_->OnTransportFeedback(feedback); |
| 178 ComparePacketVectors(sent_packets, adapter_->GetTransportFeedbackVector()); | 130 ComparePacketVectors(sent_packets, adapter_->GetTransportFeedbackVector()); |
| 179 } | 131 } |
| 180 | 132 |
| 181 TEST_F(TransportFeedbackAdapterTest, LongFeedbackDelays) { | |
| 182 const int64_t kFeedbackTimeoutMs = 60001; | |
| 183 const int kMaxConsecutiveFailedLookups = 5; | |
| 184 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) { | |
| 185 std::vector<PacketFeedback> packets; | |
| 186 packets.push_back( | |
| 187 PacketFeedback(i * 100, 2 * i * 100, 0, 1500, kPacingInfo0)); | |
| 188 packets.push_back( | |
| 189 PacketFeedback(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, kPacingInfo0)); | |
| 190 packets.push_back( | |
| 191 PacketFeedback(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, kPacingInfo0)); | |
| 192 packets.push_back( | |
| 193 PacketFeedback(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, kPacingInfo1)); | |
| 194 packets.push_back( | |
| 195 PacketFeedback(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, kPacingInfo1)); | |
| 196 | |
| 197 for (const PacketFeedback& packet : packets) | |
| 198 OnSentPacket(packet); | |
| 199 | |
| 200 rtcp::TransportFeedback feedback; | |
| 201 feedback.SetBase(packets[0].sequence_number, | |
| 202 packets[0].arrival_time_ms * 1000); | |
| 203 | |
| 204 for (const PacketFeedback& packet : packets) { | |
| 205 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | |
| 206 packet.arrival_time_ms * 1000)); | |
| 207 } | |
| 208 | |
| 209 feedback.Build(); | |
| 210 | |
| 211 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs); | |
| 212 PacketFeedback later_packet(kFeedbackTimeoutMs + i * 100 + 40, | |
| 213 kFeedbackTimeoutMs + i * 200 + 40, 5, 1500, | |
| 214 kPacingInfo1); | |
| 215 OnSentPacket(later_packet); | |
| 216 | |
| 217 adapter_->OnTransportFeedback(feedback); | |
| 218 | |
| 219 // Check that packets have timed out. | |
| 220 for (PacketFeedback& packet : packets) { | |
| 221 packet.send_time_ms = -1; | |
| 222 packet.payload_size = 0; | |
| 223 packet.pacing_info = PacedPacketInfo(); | |
| 224 } | |
| 225 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); | |
| 226 } | |
| 227 | |
| 228 // Target bitrate should have halved due to feedback delays. | |
| 229 EXPECT_EQ(150000u, target_bitrate_bps_); | |
| 230 | |
| 231 // Test with feedback that isn't late enough to time out. | |
| 232 { | |
| 233 std::vector<PacketFeedback> packets; | |
| 234 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | |
| 235 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); | |
| 236 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); | |
| 237 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); | |
| 238 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); | |
| 239 | |
| 240 for (const PacketFeedback& packet : packets) | |
| 241 OnSentPacket(packet); | |
| 242 | |
| 243 rtcp::TransportFeedback feedback; | |
| 244 feedback.SetBase(packets[0].sequence_number, | |
| 245 packets[0].arrival_time_ms * 1000); | |
| 246 | |
| 247 for (const PacketFeedback& packet : packets) { | |
| 248 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | |
| 249 packet.arrival_time_ms * 1000)); | |
| 250 } | |
| 251 | |
| 252 feedback.Build(); | |
| 253 | |
| 254 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1); | |
| 255 PacketFeedback later_packet(kFeedbackTimeoutMs + 140, | |
| 256 kFeedbackTimeoutMs + 240, 5, 1500, | |
| 257 kPacingInfo1); | |
| 258 OnSentPacket(later_packet); | |
| 259 | |
| 260 adapter_->OnTransportFeedback(feedback); | |
| 261 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); | |
| 262 } | |
| 263 } | |
| 264 | |
| 265 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) { | 133 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) { |
| 266 std::vector<PacketFeedback> packets; | 134 std::vector<PacketFeedback> packets; |
| 267 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | 135 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); |
| 268 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo1)); | 136 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo1)); |
| 269 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo2)); | 137 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo2)); |
| 270 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo3)); | 138 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo3)); |
| 271 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo4)); | 139 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo4)); |
| 272 | 140 |
| 273 const uint16_t kSendSideDropBefore = 1; | 141 const uint16_t kSendSideDropBefore = 1; |
| 274 const uint16_t kReceiveSideDropAfter = 3; | 142 const uint16_t kReceiveSideDropAfter = 3; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 312 |
| 445 EXPECT_TRUE(feedback.get() != nullptr); | 313 EXPECT_TRUE(feedback.get() != nullptr); |
| 446 adapter_->OnTransportFeedback(*feedback.get()); | 314 adapter_->OnTransportFeedback(*feedback.get()); |
| 447 { | 315 { |
| 448 std::vector<PacketFeedback> expected_packets; | 316 std::vector<PacketFeedback> expected_packets; |
| 449 expected_packets.push_back(packet_feedback); | 317 expected_packets.push_back(packet_feedback); |
| 450 ComparePacketVectors(expected_packets, | 318 ComparePacketVectors(expected_packets, |
| 451 adapter_->GetTransportFeedbackVector()); | 319 adapter_->GetTransportFeedbackVector()); |
| 452 } | 320 } |
| 453 } | 321 } |
| 454 | |
| 455 TEST_F(TransportFeedbackAdapterTest, UpdatesDelayBasedEstimate) { | |
| 456 uint16_t seq_num = 0; | |
| 457 size_t kPayloadSize = 1000; | |
| 458 // The test must run and insert packets/feedback long enough that the | |
| 459 // BWE computes a valid estimate. | |
| 460 const int64_t kRunTimeMs = 6000; | |
| 461 int64_t start_time_ms = clock_.TimeInMilliseconds(); | |
| 462 while (clock_.TimeInMilliseconds() - start_time_ms < kRunTimeMs) { | |
| 463 PacketFeedback packet(clock_.TimeInMilliseconds(), | |
| 464 clock_.TimeInMilliseconds(), seq_num, kPayloadSize, | |
| 465 PacedPacketInfo()); | |
| 466 OnSentPacket(packet); | |
| 467 // Create expected feedback and send into adapter. | |
| 468 std::unique_ptr<rtcp::TransportFeedback> feedback( | |
| 469 new rtcp::TransportFeedback()); | |
| 470 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); | |
| 471 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, | |
| 472 packet.arrival_time_ms * 1000)); | |
| 473 rtc::Buffer raw_packet = feedback->Build(); | |
| 474 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), | |
| 475 raw_packet.size()); | |
| 476 EXPECT_TRUE(feedback.get() != nullptr); | |
| 477 adapter_->OnTransportFeedback(*feedback.get()); | |
| 478 clock_.AdvanceTimeMilliseconds(50); | |
| 479 ++seq_num; | |
| 480 } | |
| 481 EXPECT_GT(target_bitrate_bps_, 0u); | |
| 482 } | |
| 483 | |
| 484 } // namespace test | 322 } // namespace test |
| 485 } // namespace webrtc | 323 } // namespace webrtc |
| OLD | NEW |