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 |
128 for (const PacketFeedback& packet : packets) | 80 for (const PacketFeedback& packet : packets) |
129 OnSentPacket(packet); | 81 OnSentPacket(packet); |
130 | 82 |
131 rtcp::TransportFeedback feedback; | 83 rtcp::TransportFeedback feedback; |
132 feedback.SetBase(packets[0].sequence_number, | 84 feedback.SetBase(packets[0].sequence_number, |
133 packets[0].arrival_time_ms * 1000); | 85 packets[0].arrival_time_ms * 1000); |
134 | 86 |
135 for (const PacketFeedback& packet : packets) { | 87 for (const PacketFeedback& packet : packets) { |
136 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | 88 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, |
137 packet.arrival_time_ms * 1000)); | 89 packet.arrival_time_ms * 1000)); |
138 } | 90 } |
139 | 91 |
140 feedback.Build(); | 92 feedback.Build(); |
141 | 93 |
142 adapter_->OnTransportFeedback(feedback); | 94 adapter_->OnTransportFeedback(feedback); |
143 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); | 95 ComparePacketFeedbackVectors(packets, adapter_->GetTransportFeedbackVector()); |
144 } | 96 } |
145 | 97 |
146 TEST_F(TransportFeedbackAdapterTest, FeedbackVectorReportsUnreceived) { | 98 TEST_F(TransportFeedbackAdapterTest, FeedbackVectorReportsUnreceived) { |
147 std::vector<PacketFeedback> sent_packets = { | 99 std::vector<PacketFeedback> sent_packets = { |
148 PacketFeedback(100, 220, 0, 1500, kPacingInfo0), | 100 PacketFeedback(100, 220, 0, 1500, kPacingInfo0), |
149 PacketFeedback(110, 210, 1, 1500, kPacingInfo0), | 101 PacketFeedback(110, 210, 1, 1500, kPacingInfo0), |
150 PacketFeedback(120, 220, 2, 1500, kPacingInfo0), | 102 PacketFeedback(120, 220, 2, 1500, kPacingInfo0), |
151 PacketFeedback(130, 230, 3, 1500, kPacingInfo0), | 103 PacketFeedback(130, 230, 3, 1500, kPacingInfo0), |
152 PacketFeedback(140, 240, 4, 1500, kPacingInfo0), | 104 PacketFeedback(140, 240, 4, 1500, kPacingInfo0), |
153 PacketFeedback(150, 250, 5, 1500, kPacingInfo0), | 105 PacketFeedback(150, 250, 5, 1500, kPacingInfo0), |
(...skipping 14 matching lines...) Expand all Loading... |
168 received_packets[0].arrival_time_ms * 1000); | 120 received_packets[0].arrival_time_ms * 1000); |
169 | 121 |
170 for (const PacketFeedback& packet : received_packets) { | 122 for (const PacketFeedback& packet : received_packets) { |
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 ComparePacketFeedbackVectors(sent_packets, |
179 } | 131 adapter_->GetTransportFeedbackVector()); |
180 | |
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 } | 132 } |
264 | 133 |
265 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) { | 134 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) { |
266 std::vector<PacketFeedback> packets; | 135 std::vector<PacketFeedback> packets; |
267 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); | 136 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0)); |
268 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo1)); | 137 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo1)); |
269 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo2)); | 138 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo2)); |
270 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo3)); | 139 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo3)); |
271 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo4)); | 140 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo4)); |
272 | 141 |
(...skipping 22 matching lines...) Expand all Loading... |
295 packets.begin(), packets.begin() + kReceiveSideDropAfter + 1); | 164 packets.begin(), packets.begin() + kReceiveSideDropAfter + 1); |
296 // Packets that have timed out on the send-side have lost the | 165 // Packets that have timed out on the send-side have lost the |
297 // information stored on the send-side. | 166 // information stored on the send-side. |
298 for (size_t i = 0; i < kSendSideDropBefore; ++i) { | 167 for (size_t i = 0; i < kSendSideDropBefore; ++i) { |
299 expected_packets[i].send_time_ms = -1; | 168 expected_packets[i].send_time_ms = -1; |
300 expected_packets[i].payload_size = 0; | 169 expected_packets[i].payload_size = 0; |
301 expected_packets[i].pacing_info = PacedPacketInfo(); | 170 expected_packets[i].pacing_info = PacedPacketInfo(); |
302 } | 171 } |
303 | 172 |
304 adapter_->OnTransportFeedback(feedback); | 173 adapter_->OnTransportFeedback(feedback); |
305 ComparePacketVectors(expected_packets, | 174 ComparePacketFeedbackVectors(expected_packets, |
306 adapter_->GetTransportFeedbackVector()); | 175 adapter_->GetTransportFeedbackVector()); |
307 } | 176 } |
308 | 177 |
309 TEST_F(TransportFeedbackAdapterTest, SendTimeWrapsBothWays) { | 178 TEST_F(TransportFeedbackAdapterTest, SendTimeWrapsBothWays) { |
310 int64_t kHighArrivalTimeMs = rtcp::TransportFeedback::kDeltaScaleFactor * | 179 int64_t kHighArrivalTimeMs = rtcp::TransportFeedback::kDeltaScaleFactor * |
311 static_cast<int64_t>(1 << 8) * | 180 static_cast<int64_t>(1 << 8) * |
312 static_cast<int64_t>((1 << 23) - 1) / 1000; | 181 static_cast<int64_t>((1 << 23) - 1) / 1000; |
313 std::vector<PacketFeedback> packets; | 182 std::vector<PacketFeedback> packets; |
314 packets.push_back( | 183 packets.push_back( |
315 PacketFeedback(kHighArrivalTimeMs - 64, 200, 0, 1500, PacedPacketInfo())); | 184 PacketFeedback(kHighArrivalTimeMs - 64, 200, 0, 1500, PacedPacketInfo())); |
316 packets.push_back( | 185 packets.push_back( |
(...skipping 14 matching lines...) Expand all Loading... |
331 packets[i].arrival_time_ms * 1000)); | 200 packets[i].arrival_time_ms * 1000)); |
332 | 201 |
333 rtc::Buffer raw_packet = feedback->Build(); | 202 rtc::Buffer raw_packet = feedback->Build(); |
334 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), | 203 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), |
335 raw_packet.size()); | 204 raw_packet.size()); |
336 | 205 |
337 std::vector<PacketFeedback> expected_packets; | 206 std::vector<PacketFeedback> expected_packets; |
338 expected_packets.push_back(packets[i]); | 207 expected_packets.push_back(packets[i]); |
339 | 208 |
340 adapter_->OnTransportFeedback(*feedback.get()); | 209 adapter_->OnTransportFeedback(*feedback.get()); |
341 ComparePacketVectors(expected_packets, | 210 ComparePacketFeedbackVectors(expected_packets, |
342 adapter_->GetTransportFeedbackVector()); | 211 adapter_->GetTransportFeedbackVector()); |
343 } | 212 } |
344 } | 213 } |
345 | 214 |
346 TEST_F(TransportFeedbackAdapterTest, HandlesArrivalReordering) { | 215 TEST_F(TransportFeedbackAdapterTest, HandlesArrivalReordering) { |
347 std::vector<PacketFeedback> packets; | 216 std::vector<PacketFeedback> packets; |
348 packets.push_back(PacketFeedback(120, 200, 0, 1500, kPacingInfo0)); | 217 packets.push_back(PacketFeedback(120, 200, 0, 1500, kPacingInfo0)); |
349 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); | 218 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0)); |
350 packets.push_back(PacketFeedback(100, 220, 2, 1500, kPacingInfo0)); | 219 packets.push_back(PacketFeedback(100, 220, 2, 1500, kPacingInfo0)); |
351 | 220 |
352 for (const PacketFeedback& packet : packets) | 221 for (const PacketFeedback& packet : packets) |
353 OnSentPacket(packet); | 222 OnSentPacket(packet); |
354 | 223 |
355 rtcp::TransportFeedback feedback; | 224 rtcp::TransportFeedback feedback; |
356 feedback.SetBase(packets[0].sequence_number, | 225 feedback.SetBase(packets[0].sequence_number, |
357 packets[0].arrival_time_ms * 1000); | 226 packets[0].arrival_time_ms * 1000); |
358 | 227 |
359 for (const PacketFeedback& packet : packets) { | 228 for (const PacketFeedback& packet : packets) { |
360 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, | 229 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, |
361 packet.arrival_time_ms * 1000)); | 230 packet.arrival_time_ms * 1000)); |
362 } | 231 } |
363 | 232 |
364 feedback.Build(); | 233 feedback.Build(); |
365 | 234 |
366 // Adapter keeps the packets ordered by sequence number (which is itself | 235 // Adapter keeps the packets ordered by sequence number (which is itself |
367 // assigned by the order of transmission). Reordering by some other criteria, | 236 // assigned by the order of transmission). Reordering by some other criteria, |
368 // eg. arrival time, is up to the observers. | 237 // eg. arrival time, is up to the observers. |
369 adapter_->OnTransportFeedback(feedback); | 238 adapter_->OnTransportFeedback(feedback); |
370 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); | 239 ComparePacketFeedbackVectors(packets, adapter_->GetTransportFeedbackVector()); |
371 } | 240 } |
372 | 241 |
373 TEST_F(TransportFeedbackAdapterTest, TimestampDeltas) { | 242 TEST_F(TransportFeedbackAdapterTest, TimestampDeltas) { |
374 std::vector<PacketFeedback> sent_packets; | 243 std::vector<PacketFeedback> sent_packets; |
375 const int64_t kSmallDeltaUs = | 244 const int64_t kSmallDeltaUs = |
376 rtcp::TransportFeedback::kDeltaScaleFactor * ((1 << 8) - 1); | 245 rtcp::TransportFeedback::kDeltaScaleFactor * ((1 << 8) - 1); |
377 const int64_t kLargePositiveDeltaUs = | 246 const int64_t kLargePositiveDeltaUs = |
378 rtcp::TransportFeedback::kDeltaScaleFactor * | 247 rtcp::TransportFeedback::kDeltaScaleFactor * |
379 std::numeric_limits<int16_t>::max(); | 248 std::numeric_limits<int16_t>::max(); |
380 const int64_t kLargeNegativeDeltaUs = | 249 const int64_t kLargeNegativeDeltaUs = |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 packet_feedback.sequence_number, packet_feedback.arrival_time_ms * 1000)); | 292 packet_feedback.sequence_number, packet_feedback.arrival_time_ms * 1000)); |
424 | 293 |
425 rtc::Buffer raw_packet = feedback->Build(); | 294 rtc::Buffer raw_packet = feedback->Build(); |
426 feedback = | 295 feedback = |
427 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size()); | 296 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size()); |
428 | 297 |
429 std::vector<PacketFeedback> received_feedback; | 298 std::vector<PacketFeedback> received_feedback; |
430 | 299 |
431 EXPECT_TRUE(feedback.get() != nullptr); | 300 EXPECT_TRUE(feedback.get() != nullptr); |
432 adapter_->OnTransportFeedback(*feedback.get()); | 301 adapter_->OnTransportFeedback(*feedback.get()); |
433 ComparePacketVectors(sent_packets, adapter_->GetTransportFeedbackVector()); | 302 ComparePacketFeedbackVectors(sent_packets, |
| 303 adapter_->GetTransportFeedbackVector()); |
434 | 304 |
435 // Create a new feedback message and add the trailing item. | 305 // Create a new feedback message and add the trailing item. |
436 feedback.reset(new rtcp::TransportFeedback()); | 306 feedback.reset(new rtcp::TransportFeedback()); |
437 feedback->SetBase(packet_feedback.sequence_number, | 307 feedback->SetBase(packet_feedback.sequence_number, |
438 packet_feedback.arrival_time_ms * 1000); | 308 packet_feedback.arrival_time_ms * 1000); |
439 EXPECT_TRUE(feedback->AddReceivedPacket( | 309 EXPECT_TRUE(feedback->AddReceivedPacket( |
440 packet_feedback.sequence_number, packet_feedback.arrival_time_ms * 1000)); | 310 packet_feedback.sequence_number, packet_feedback.arrival_time_ms * 1000)); |
441 raw_packet = feedback->Build(); | 311 raw_packet = feedback->Build(); |
442 feedback = | 312 feedback = |
443 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size()); | 313 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size()); |
444 | 314 |
445 EXPECT_TRUE(feedback.get() != nullptr); | 315 EXPECT_TRUE(feedback.get() != nullptr); |
446 adapter_->OnTransportFeedback(*feedback.get()); | 316 adapter_->OnTransportFeedback(*feedback.get()); |
447 { | 317 { |
448 std::vector<PacketFeedback> expected_packets; | 318 std::vector<PacketFeedback> expected_packets; |
449 expected_packets.push_back(packet_feedback); | 319 expected_packets.push_back(packet_feedback); |
450 ComparePacketVectors(expected_packets, | 320 ComparePacketFeedbackVectors(expected_packets, |
451 adapter_->GetTransportFeedbackVector()); | 321 adapter_->GetTransportFeedbackVector()); |
452 } | 322 } |
453 } | 323 } |
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 | 324 } // namespace test |
485 } // namespace webrtc | 325 } // namespace webrtc |
OLD | NEW |