| 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/transport_feedback_adapter.h" | 18 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" |
| 19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 21 #include "webrtc/system_wrappers/include/clock.h" | 21 #include "webrtc/system_wrappers/include/clock.h" |
| 22 #include "webrtc/test/gmock.h" | 22 #include "webrtc/test/gmock.h" |
| 23 #include "webrtc/test/gtest.h" | 23 #include "webrtc/test/gtest.h" |
| 24 | 24 |
| 25 using ::testing::_; | 25 using ::testing::_; |
| 26 using ::testing::Invoke; | 26 using ::testing::Invoke; |
| 27 using testing::NiceMock; |
| 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, | 60 void ComparePacketVectors(const std::vector<PacketFeedback>& truth, |
| 80 const std::vector<PacketFeedback>& input) { | 61 const std::vector<PacketFeedback>& input) { |
| 81 ASSERT_EQ(truth.size(), input.size()); | 62 ASSERT_EQ(truth.size(), input.size()); |
| 82 size_t len = truth.size(); | 63 size_t len = truth.size(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 EXPECT_EQ(truth[i].arrival_time_ms, | 76 EXPECT_EQ(truth[i].arrival_time_ms, |
| 96 input[i].arrival_time_ms + arrival_time_delta); | 77 input[i].arrival_time_ms + arrival_time_delta); |
| 97 } | 78 } |
| 98 EXPECT_EQ(truth[i].send_time_ms, input[i].send_time_ms); | 79 EXPECT_EQ(truth[i].send_time_ms, input[i].send_time_ms); |
| 99 EXPECT_EQ(truth[i].sequence_number, input[i].sequence_number); | 80 EXPECT_EQ(truth[i].sequence_number, input[i].sequence_number); |
| 100 EXPECT_EQ(truth[i].payload_size, input[i].payload_size); | 81 EXPECT_EQ(truth[i].payload_size, input[i].payload_size); |
| 101 EXPECT_EQ(truth[i].pacing_info, input[i].pacing_info); | 82 EXPECT_EQ(truth[i].pacing_info, input[i].pacing_info); |
| 102 } | 83 } |
| 103 } | 84 } |
| 104 | 85 |
| 105 // Utility method, to reset arrival_time_ms before adding send time. | 86 void OnSentPacket(const PacketFeedback& packet_feedback) { |
| 106 void OnSentPacket(PacketFeedback packet_feedback) { | |
| 107 packet_feedback.arrival_time_ms = 0; | |
| 108 // TODO(philipel): Change -1, -1 to some values. | |
| 109 adapter_->AddPacket(packet_feedback.sequence_number, | 87 adapter_->AddPacket(packet_feedback.sequence_number, |
| 110 packet_feedback.payload_size, | 88 packet_feedback.payload_size, |
| 111 packet_feedback.pacing_info); | 89 packet_feedback.pacing_info); |
| 112 adapter_->OnSentPacket(packet_feedback.sequence_number, | 90 adapter_->OnSentPacket(packet_feedback.sequence_number, |
| 113 packet_feedback.send_time_ms); | 91 packet_feedback.send_time_ms); |
| 114 } | 92 } |
| 115 | 93 |
| 116 SimulatedClock clock_; | 94 SimulatedClock clock_; |
| 117 MockBitrateControllerAdapter bitrate_controller_; | |
| 118 std::unique_ptr<TransportFeedbackAdapter> adapter_; | 95 std::unique_ptr<TransportFeedbackAdapter> adapter_; |
| 119 | |
| 120 uint32_t target_bitrate_bps_; | |
| 121 }; | 96 }; |
| 122 | 97 |
| 123 TEST_F(TransportFeedbackAdapterTest, AdaptsFeedbackAndPopulatesSendTimes) { | 98 TEST_F(TransportFeedbackAdapterTest, AdaptsFeedbackAndPopulatesSendTimes) { |
| 124 std::vector<PacketFeedback> packets; | 99 std::vector<PacketFeedback> packets; |
| 125 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | 100 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); |
| 126 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); | 101 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); |
| 127 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); | 102 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); |
| 128 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); | 103 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); |
| 129 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); | 104 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); |
| 130 | 105 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | 149 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, |
| 175 packet.arrival_time_ms * 1000)); | 150 packet.arrival_time_ms * 1000)); |
| 176 } | 151 } |
| 177 | 152 |
| 178 feedback.Build(); | 153 feedback.Build(); |
| 179 | 154 |
| 180 adapter_->OnTransportFeedback(feedback); | 155 adapter_->OnTransportFeedback(feedback); |
| 181 ComparePacketVectors(sent_packets, adapter_->GetTransportFeedbackVector()); | 156 ComparePacketVectors(sent_packets, adapter_->GetTransportFeedbackVector()); |
| 182 } | 157 } |
| 183 | 158 |
| 184 TEST_F(TransportFeedbackAdapterTest, LongFeedbackDelays) { | |
| 185 const int64_t kFeedbackTimeoutMs = 60001; | |
| 186 const int kMaxConsecutiveFailedLookups = 5; | |
| 187 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) { | |
| 188 std::vector<PacketFeedback> packets; | |
| 189 packets.push_back( | |
| 190 PacketFeedback(i * 100, 2 * i * 100, 0, 1500, kPacingInfo0)); | |
| 191 packets.push_back( | |
| 192 PacketFeedback(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, kPacingInfo0)); | |
| 193 packets.push_back( | |
| 194 PacketFeedback(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, kPacingInfo0)); | |
| 195 packets.push_back( | |
| 196 PacketFeedback(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, kPacingInfo1)); | |
| 197 packets.push_back( | |
| 198 PacketFeedback(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, kPacingInfo1)); | |
| 199 | |
| 200 for (const PacketFeedback& packet : packets) | |
| 201 OnSentPacket(packet); | |
| 202 | |
| 203 rtcp::TransportFeedback feedback; | |
| 204 feedback.SetBase(packets[0].sequence_number, | |
| 205 packets[0].arrival_time_ms * 1000); | |
| 206 | |
| 207 for (const PacketFeedback& packet : packets) { | |
| 208 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | |
| 209 packet.arrival_time_ms * 1000)); | |
| 210 } | |
| 211 | |
| 212 feedback.Build(); | |
| 213 | |
| 214 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs); | |
| 215 PacketFeedback later_packet(kFeedbackTimeoutMs + i * 100 + 40, | |
| 216 kFeedbackTimeoutMs + i * 200 + 40, 5, 1500, | |
| 217 kPacingInfo1); | |
| 218 OnSentPacket(later_packet); | |
| 219 | |
| 220 adapter_->OnTransportFeedback(feedback); | |
| 221 | |
| 222 // Check that packets have timed out. | |
| 223 for (PacketFeedback& packet : packets) { | |
| 224 packet.send_time_ms = -1; | |
| 225 packet.payload_size = 0; | |
| 226 packet.pacing_info = PacedPacketInfo(); | |
| 227 } | |
| 228 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); | |
| 229 } | |
| 230 | |
| 231 // Target bitrate should have halved due to feedback delays. | |
| 232 EXPECT_EQ(150000u, target_bitrate_bps_); | |
| 233 | |
| 234 // Test with feedback that isn't late enough to time out. | |
| 235 { | |
| 236 std::vector<PacketFeedback> packets; | |
| 237 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | |
| 238 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); | |
| 239 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0)); | |
| 240 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1)); | |
| 241 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1)); | |
| 242 | |
| 243 for (const PacketFeedback& packet : packets) | |
| 244 OnSentPacket(packet); | |
| 245 | |
| 246 rtcp::TransportFeedback feedback; | |
| 247 feedback.SetBase(packets[0].sequence_number, | |
| 248 packets[0].arrival_time_ms * 1000); | |
| 249 | |
| 250 for (const PacketFeedback& packet : packets) { | |
| 251 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | |
| 252 packet.arrival_time_ms * 1000)); | |
| 253 } | |
| 254 | |
| 255 feedback.Build(); | |
| 256 | |
| 257 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1); | |
| 258 PacketFeedback later_packet(kFeedbackTimeoutMs + 140, | |
| 259 kFeedbackTimeoutMs + 240, 5, 1500, | |
| 260 kPacingInfo1); | |
| 261 OnSentPacket(later_packet); | |
| 262 | |
| 263 adapter_->OnTransportFeedback(feedback); | |
| 264 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); | |
| 265 } | |
| 266 } | |
| 267 | |
| 268 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) { | 159 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) { |
| 269 std::vector<PacketFeedback> packets; | 160 std::vector<PacketFeedback> packets; |
| 270 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | 161 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); |
| 271 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo1)); | 162 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo1)); |
| 272 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo2)); | 163 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo2)); |
| 273 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo3)); | 164 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo3)); |
| 274 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo4)); | 165 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo4)); |
| 275 | 166 |
| 276 const uint16_t kSendSideDropBefore = 1; | 167 const uint16_t kSendSideDropBefore = 1; |
| 277 const uint16_t kReceiveSideDropAfter = 3; | 168 const uint16_t kReceiveSideDropAfter = 3; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 338 |
| 448 EXPECT_TRUE(feedback.get() != nullptr); | 339 EXPECT_TRUE(feedback.get() != nullptr); |
| 449 adapter_->OnTransportFeedback(*feedback.get()); | 340 adapter_->OnTransportFeedback(*feedback.get()); |
| 450 { | 341 { |
| 451 std::vector<PacketFeedback> expected_packets; | 342 std::vector<PacketFeedback> expected_packets; |
| 452 expected_packets.push_back(packet_feedback); | 343 expected_packets.push_back(packet_feedback); |
| 453 ComparePacketVectors(expected_packets, | 344 ComparePacketVectors(expected_packets, |
| 454 adapter_->GetTransportFeedbackVector()); | 345 adapter_->GetTransportFeedbackVector()); |
| 455 } | 346 } |
| 456 } | 347 } |
| 457 | |
| 458 TEST_F(TransportFeedbackAdapterTest, UpdatesDelayBasedEstimate) { | |
| 459 uint16_t seq_num = 0; | |
| 460 size_t kPayloadSize = 1000; | |
| 461 // The test must run and insert packets/feedback long enough that the | |
| 462 // BWE computes a valid estimate. | |
| 463 const int64_t kRunTimeMs = 6000; | |
| 464 int64_t start_time_ms = clock_.TimeInMilliseconds(); | |
| 465 while (clock_.TimeInMilliseconds() - start_time_ms < kRunTimeMs) { | |
| 466 PacketFeedback packet(clock_.TimeInMilliseconds(), | |
| 467 clock_.TimeInMilliseconds(), seq_num, kPayloadSize, | |
| 468 PacedPacketInfo()); | |
| 469 OnSentPacket(packet); | |
| 470 // Create expected feedback and send into adapter. | |
| 471 std::unique_ptr<rtcp::TransportFeedback> feedback( | |
| 472 new rtcp::TransportFeedback()); | |
| 473 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); | |
| 474 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, | |
| 475 packet.arrival_time_ms * 1000)); | |
| 476 rtc::Buffer raw_packet = feedback->Build(); | |
| 477 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), | |
| 478 raw_packet.size()); | |
| 479 EXPECT_TRUE(feedback.get() != nullptr); | |
| 480 adapter_->OnTransportFeedback(*feedback.get()); | |
| 481 clock_.AdvanceTimeMilliseconds(50); | |
| 482 ++seq_num; | |
| 483 } | |
| 484 EXPECT_GT(target_bitrate_bps_, 0u); | |
| 485 } | |
| 486 | |
| 487 } // namespace test | 348 } // namespace test |
| 488 } // namespace webrtc | 349 } // namespace webrtc |
| OLD | NEW |