Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: webrtc/modules/congestion_controller/transport_feedback_adapter_unittest.cc

Issue 2710093004: Rename webrtc::PacketInfo to webrtc::PacketFeedback (Closed)
Patch Set: Rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 TransportFeedbackAdapterTest* const owner_; 70 TransportFeedbackAdapterTest* const owner_;
71 }; 71 };
72 72
73 void OnReceivedEstimatedBitrate(uint32_t bitrate) {} 73 void OnReceivedEstimatedBitrate(uint32_t bitrate) {}
74 74
75 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, 75 void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks,
76 int64_t rtt, 76 int64_t rtt,
77 int64_t now_ms) {} 77 int64_t now_ms) {}
78 78
79 void ComparePacketVectors(const std::vector<PacketInfo>& truth, 79 void ComparePacketVectors(const std::vector<PacketFeedback>& truth,
80 const std::vector<PacketInfo>& input) { 80 const std::vector<PacketFeedback>& input) {
81 ASSERT_EQ(truth.size(), input.size()); 81 ASSERT_EQ(truth.size(), input.size());
82 size_t len = truth.size(); 82 size_t len = truth.size();
83 // truth contains the input data for the test, and input is what will be 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 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 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 86 // (because of resolution limits in the packets, and because of the time
87 // base adjustment performed by the TransportFeedbackAdapter at the first 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 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. 89 // equal. However, the difference must be the same for all x.
90 int64_t arrival_time_delta = 90 int64_t arrival_time_delta =
91 truth[0].arrival_time_ms - input[0].arrival_time_ms; 91 truth[0].arrival_time_ms - input[0].arrival_time_ms;
92 for (size_t i = 0; i < len; ++i) { 92 for (size_t i = 0; i < len; ++i) {
93 EXPECT_EQ(truth[i].arrival_time_ms, 93 EXPECT_EQ(truth[i].arrival_time_ms,
94 input[i].arrival_time_ms + arrival_time_delta); 94 input[i].arrival_time_ms + arrival_time_delta);
95 EXPECT_EQ(truth[i].send_time_ms, input[i].send_time_ms); 95 EXPECT_EQ(truth[i].send_time_ms, input[i].send_time_ms);
96 EXPECT_EQ(truth[i].sequence_number, input[i].sequence_number); 96 EXPECT_EQ(truth[i].sequence_number, input[i].sequence_number);
97 EXPECT_EQ(truth[i].payload_size, input[i].payload_size); 97 EXPECT_EQ(truth[i].payload_size, input[i].payload_size);
98 EXPECT_EQ(truth[i].pacing_info, input[i].pacing_info); 98 EXPECT_EQ(truth[i].pacing_info, input[i].pacing_info);
99 } 99 }
100 } 100 }
101 101
102 void OnSentPacket(const PacketInfo& info) { 102 void OnSentPacket(const PacketFeedback& packet_feedback) {
103 adapter_->AddPacket(info.sequence_number, info.payload_size, 103 adapter_->AddPacket(packet_feedback.sequence_number,
104 info.pacing_info); 104 packet_feedback.payload_size,
105 adapter_->OnSentPacket(info.sequence_number, info.send_time_ms); 105 packet_feedback.pacing_info);
106 adapter_->OnSentPacket(packet_feedback.sequence_number,
107 packet_feedback.send_time_ms);
106 } 108 }
107 109
108 SimulatedClock clock_; 110 SimulatedClock clock_;
109 MockBitrateControllerAdapter bitrate_controller_; 111 MockBitrateControllerAdapter bitrate_controller_;
110 std::unique_ptr<TransportFeedbackAdapter> adapter_; 112 std::unique_ptr<TransportFeedbackAdapter> adapter_;
111 113
112 uint32_t target_bitrate_bps_; 114 uint32_t target_bitrate_bps_;
113 }; 115 };
114 116
115 TEST_F(TransportFeedbackAdapterTest, AdaptsFeedbackAndPopulatesSendTimes) { 117 TEST_F(TransportFeedbackAdapterTest, AdaptsFeedbackAndPopulatesSendTimes) {
116 std::vector<PacketInfo> packets; 118 std::vector<PacketFeedback> packets;
117 packets.push_back(PacketInfo(100, 200, 0, 1500, kPacingInfo0)); 119 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0));
118 packets.push_back(PacketInfo(110, 210, 1, 1500, kPacingInfo0)); 120 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0));
119 packets.push_back(PacketInfo(120, 220, 2, 1500, kPacingInfo0)); 121 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0));
120 packets.push_back(PacketInfo(130, 230, 3, 1500, kPacingInfo1)); 122 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1));
121 packets.push_back(PacketInfo(140, 240, 4, 1500, kPacingInfo1)); 123 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1));
122 124
123 for (const PacketInfo& packet : packets) 125 for (const PacketFeedback& packet : packets)
124 OnSentPacket(packet); 126 OnSentPacket(packet);
125 127
126 rtcp::TransportFeedback feedback; 128 rtcp::TransportFeedback feedback;
127 feedback.SetBase(packets[0].sequence_number, 129 feedback.SetBase(packets[0].sequence_number,
128 packets[0].arrival_time_ms * 1000); 130 packets[0].arrival_time_ms * 1000);
129 131
130 for (const PacketInfo& packet : packets) { 132 for (const PacketFeedback& packet : packets) {
131 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, 133 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number,
132 packet.arrival_time_ms * 1000)); 134 packet.arrival_time_ms * 1000));
133 } 135 }
134 136
135 feedback.Build(); 137 feedback.Build();
136 138
137 adapter_->OnTransportFeedback(feedback); 139 adapter_->OnTransportFeedback(feedback);
138 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); 140 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector());
139 } 141 }
140 142
141 TEST_F(TransportFeedbackAdapterTest, LongFeedbackDelays) { 143 TEST_F(TransportFeedbackAdapterTest, LongFeedbackDelays) {
142 const int64_t kFeedbackTimeoutMs = 60001; 144 const int64_t kFeedbackTimeoutMs = 60001;
143 const int kMaxConsecutiveFailedLookups = 5; 145 const int kMaxConsecutiveFailedLookups = 5;
144 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) { 146 for (int i = 0; i < kMaxConsecutiveFailedLookups; ++i) {
145 std::vector<PacketInfo> packets; 147 std::vector<PacketFeedback> packets;
146 packets.push_back(PacketInfo(i * 100, 2 * i * 100, 0, 1500, kPacingInfo0));
147 packets.push_back( 148 packets.push_back(
148 PacketInfo(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, kPacingInfo0)); 149 PacketFeedback(i * 100, 2 * i * 100, 0, 1500, kPacingInfo0));
149 packets.push_back( 150 packets.push_back(
150 PacketInfo(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, kPacingInfo0)); 151 PacketFeedback(i * 100 + 10, 2 * i * 100 + 10, 1, 1500, kPacingInfo0));
151 packets.push_back( 152 packets.push_back(
152 PacketInfo(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, kPacingInfo1)); 153 PacketFeedback(i * 100 + 20, 2 * i * 100 + 20, 2, 1500, kPacingInfo0));
153 packets.push_back( 154 packets.push_back(
154 PacketInfo(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, kPacingInfo1)); 155 PacketFeedback(i * 100 + 30, 2 * i * 100 + 30, 3, 1500, kPacingInfo1));
156 packets.push_back(
157 PacketFeedback(i * 100 + 40, 2 * i * 100 + 40, 4, 1500, kPacingInfo1));
155 158
156 for (const PacketInfo& packet : packets) 159 for (const PacketFeedback& packet : packets)
157 OnSentPacket(packet); 160 OnSentPacket(packet);
158 161
159 rtcp::TransportFeedback feedback; 162 rtcp::TransportFeedback feedback;
160 feedback.SetBase(packets[0].sequence_number, 163 feedback.SetBase(packets[0].sequence_number,
161 packets[0].arrival_time_ms * 1000); 164 packets[0].arrival_time_ms * 1000);
162 165
163 for (const PacketInfo& packet : packets) { 166 for (const PacketFeedback& packet : packets) {
164 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, 167 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number,
165 packet.arrival_time_ms * 1000)); 168 packet.arrival_time_ms * 1000));
166 } 169 }
167 170
168 feedback.Build(); 171 feedback.Build();
169 172
170 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs); 173 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs);
171 PacketInfo later_packet(kFeedbackTimeoutMs + i * 100 + 40, 174 PacketFeedback later_packet(kFeedbackTimeoutMs + i * 100 + 40,
172 kFeedbackTimeoutMs + i * 200 + 40, 5, 1500, 175 kFeedbackTimeoutMs + i * 200 + 40, 5, 1500,
173 kPacingInfo1); 176 kPacingInfo1);
174 OnSentPacket(later_packet); 177 OnSentPacket(later_packet);
175 178
176 adapter_->OnTransportFeedback(feedback); 179 adapter_->OnTransportFeedback(feedback);
177 180
178 // Check that packets have timed out. 181 // Check that packets have timed out.
179 for (PacketInfo& packet : packets) { 182 for (PacketFeedback& packet : packets) {
180 packet.send_time_ms = -1; 183 packet.send_time_ms = -1;
181 packet.payload_size = 0; 184 packet.payload_size = 0;
182 packet.pacing_info = PacedPacketInfo(); 185 packet.pacing_info = PacedPacketInfo();
183 } 186 }
184 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); 187 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector());
185 } 188 }
186 189
187 // Target bitrate should have halved due to feedback delays. 190 // Target bitrate should have halved due to feedback delays.
188 EXPECT_EQ(150000u, target_bitrate_bps_); 191 EXPECT_EQ(150000u, target_bitrate_bps_);
189 192
190 // Test with feedback that isn't late enough to time out. 193 // Test with feedback that isn't late enough to time out.
191 { 194 {
192 std::vector<PacketInfo> packets; 195 std::vector<PacketFeedback> packets;
193 packets.push_back(PacketInfo(100, 200, 0, 1500, kPacingInfo0)); 196 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0));
194 packets.push_back(PacketInfo(110, 210, 1, 1500, kPacingInfo0)); 197 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0));
195 packets.push_back(PacketInfo(120, 220, 2, 1500, kPacingInfo0)); 198 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo0));
196 packets.push_back(PacketInfo(130, 230, 3, 1500, kPacingInfo1)); 199 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo1));
197 packets.push_back(PacketInfo(140, 240, 4, 1500, kPacingInfo1)); 200 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo1));
198 201
199 for (const PacketInfo& packet : packets) 202 for (const PacketFeedback& packet : packets)
200 OnSentPacket(packet); 203 OnSentPacket(packet);
201 204
202 rtcp::TransportFeedback feedback; 205 rtcp::TransportFeedback feedback;
203 feedback.SetBase(packets[0].sequence_number, 206 feedback.SetBase(packets[0].sequence_number,
204 packets[0].arrival_time_ms * 1000); 207 packets[0].arrival_time_ms * 1000);
205 208
206 for (const PacketInfo& packet : packets) { 209 for (const PacketFeedback& packet : packets) {
207 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, 210 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number,
208 packet.arrival_time_ms * 1000)); 211 packet.arrival_time_ms * 1000));
209 } 212 }
210 213
211 feedback.Build(); 214 feedback.Build();
212 215
213 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1); 216 clock_.AdvanceTimeMilliseconds(kFeedbackTimeoutMs - 1);
214 PacketInfo later_packet(kFeedbackTimeoutMs + 140, kFeedbackTimeoutMs + 240, 217 PacketFeedback later_packet(kFeedbackTimeoutMs + 140,
215 5, 1500, kPacingInfo1); 218 kFeedbackTimeoutMs + 240, 5, 1500,
219 kPacingInfo1);
216 OnSentPacket(later_packet); 220 OnSentPacket(later_packet);
217 221
218 adapter_->OnTransportFeedback(feedback); 222 adapter_->OnTransportFeedback(feedback);
219 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector()); 223 ComparePacketVectors(packets, adapter_->GetTransportFeedbackVector());
220 } 224 }
221 } 225 }
222 226
223 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) { 227 TEST_F(TransportFeedbackAdapterTest, HandlesDroppedPackets) {
224 std::vector<PacketInfo> packets; 228 std::vector<PacketFeedback> packets;
225 packets.push_back(PacketInfo(100, 200, 0, 1500, kPacingInfo0)); 229 packets.push_back(PacketFeedback(100, 200, 0, 1500, kPacingInfo0));
226 packets.push_back(PacketInfo(110, 210, 1, 1500, kPacingInfo1)); 230 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo1));
227 packets.push_back(PacketInfo(120, 220, 2, 1500, kPacingInfo2)); 231 packets.push_back(PacketFeedback(120, 220, 2, 1500, kPacingInfo2));
228 packets.push_back(PacketInfo(130, 230, 3, 1500, kPacingInfo3)); 232 packets.push_back(PacketFeedback(130, 230, 3, 1500, kPacingInfo3));
229 packets.push_back(PacketInfo(140, 240, 4, 1500, kPacingInfo4)); 233 packets.push_back(PacketFeedback(140, 240, 4, 1500, kPacingInfo4));
230 234
231 const uint16_t kSendSideDropBefore = 1; 235 const uint16_t kSendSideDropBefore = 1;
232 const uint16_t kReceiveSideDropAfter = 3; 236 const uint16_t kReceiveSideDropAfter = 3;
233 237
234 for (const PacketInfo& packet : packets) { 238 for (const PacketFeedback& packet : packets) {
235 if (packet.sequence_number >= kSendSideDropBefore) 239 if (packet.sequence_number >= kSendSideDropBefore)
236 OnSentPacket(packet); 240 OnSentPacket(packet);
237 } 241 }
238 242
239 rtcp::TransportFeedback feedback; 243 rtcp::TransportFeedback feedback;
240 feedback.SetBase(packets[0].sequence_number, 244 feedback.SetBase(packets[0].sequence_number,
241 packets[0].arrival_time_ms * 1000); 245 packets[0].arrival_time_ms * 1000);
242 246
243 for (const PacketInfo& packet : packets) { 247 for (const PacketFeedback& packet : packets) {
244 if (packet.sequence_number <= kReceiveSideDropAfter) { 248 if (packet.sequence_number <= kReceiveSideDropAfter) {
245 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, 249 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number,
246 packet.arrival_time_ms * 1000)); 250 packet.arrival_time_ms * 1000));
247 } 251 }
248 } 252 }
249 253
250 feedback.Build(); 254 feedback.Build();
251 255
252 std::vector<PacketInfo> expected_packets( 256 std::vector<PacketFeedback> expected_packets(
253 packets.begin(), packets.begin() + kReceiveSideDropAfter + 1); 257 packets.begin(), packets.begin() + kReceiveSideDropAfter + 1);
254 // Packets that have timed out on the send-side have lost the 258 // Packets that have timed out on the send-side have lost the
255 // information stored on the send-side. 259 // information stored on the send-side.
256 for (size_t i = 0; i < kSendSideDropBefore; ++i) { 260 for (size_t i = 0; i < kSendSideDropBefore; ++i) {
257 expected_packets[i].send_time_ms = -1; 261 expected_packets[i].send_time_ms = -1;
258 expected_packets[i].payload_size = 0; 262 expected_packets[i].payload_size = 0;
259 expected_packets[i].pacing_info = PacedPacketInfo(); 263 expected_packets[i].pacing_info = PacedPacketInfo();
260 } 264 }
261 265
262 adapter_->OnTransportFeedback(feedback); 266 adapter_->OnTransportFeedback(feedback);
263 ComparePacketVectors(expected_packets, 267 ComparePacketVectors(expected_packets,
264 adapter_->GetTransportFeedbackVector()); 268 adapter_->GetTransportFeedbackVector());
265 } 269 }
266 270
267 TEST_F(TransportFeedbackAdapterTest, SendTimeWrapsBothWays) { 271 TEST_F(TransportFeedbackAdapterTest, SendTimeWrapsBothWays) {
268 int64_t kHighArrivalTimeMs = rtcp::TransportFeedback::kDeltaScaleFactor * 272 int64_t kHighArrivalTimeMs = rtcp::TransportFeedback::kDeltaScaleFactor *
269 static_cast<int64_t>(1 << 8) * 273 static_cast<int64_t>(1 << 8) *
270 static_cast<int64_t>((1 << 23) - 1) / 1000; 274 static_cast<int64_t>((1 << 23) - 1) / 1000;
271 std::vector<PacketInfo> packets; 275 std::vector<PacketFeedback> packets;
272 packets.push_back( 276 packets.push_back(
273 PacketInfo(kHighArrivalTimeMs - 64, 200, 0, 1500, PacedPacketInfo())); 277 PacketFeedback(kHighArrivalTimeMs - 64, 200, 0, 1500, PacedPacketInfo()));
274 packets.push_back( 278 packets.push_back(
275 PacketInfo(kHighArrivalTimeMs + 64, 210, 1, 1500, PacedPacketInfo())); 279 PacketFeedback(kHighArrivalTimeMs + 64, 210, 1, 1500, PacedPacketInfo()));
276 packets.push_back( 280 packets.push_back(
277 PacketInfo(kHighArrivalTimeMs, 220, 2, 1500, PacedPacketInfo())); 281 PacketFeedback(kHighArrivalTimeMs, 220, 2, 1500, PacedPacketInfo()));
278 282
279 for (const PacketInfo& packet : packets) 283 for (const PacketFeedback& packet : packets)
280 OnSentPacket(packet); 284 OnSentPacket(packet);
281 285
282 for (size_t i = 0; i < packets.size(); ++i) { 286 for (size_t i = 0; i < packets.size(); ++i) {
283 std::unique_ptr<rtcp::TransportFeedback> feedback( 287 std::unique_ptr<rtcp::TransportFeedback> feedback(
284 new rtcp::TransportFeedback()); 288 new rtcp::TransportFeedback());
285 feedback->SetBase(packets[i].sequence_number, 289 feedback->SetBase(packets[i].sequence_number,
286 packets[i].arrival_time_ms * 1000); 290 packets[i].arrival_time_ms * 1000);
287 291
288 EXPECT_TRUE(feedback->AddReceivedPacket(packets[i].sequence_number, 292 EXPECT_TRUE(feedback->AddReceivedPacket(packets[i].sequence_number,
289 packets[i].arrival_time_ms * 1000)); 293 packets[i].arrival_time_ms * 1000));
290 294
291 rtc::Buffer raw_packet = feedback->Build(); 295 rtc::Buffer raw_packet = feedback->Build();
292 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), 296 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(),
293 raw_packet.size()); 297 raw_packet.size());
294 298
295 std::vector<PacketInfo> expected_packets; 299 std::vector<PacketFeedback> expected_packets;
296 expected_packets.push_back(packets[i]); 300 expected_packets.push_back(packets[i]);
297 301
298 adapter_->OnTransportFeedback(*feedback.get()); 302 adapter_->OnTransportFeedback(*feedback.get());
299 ComparePacketVectors(expected_packets, 303 ComparePacketVectors(expected_packets,
300 adapter_->GetTransportFeedbackVector()); 304 adapter_->GetTransportFeedbackVector());
301 } 305 }
302 } 306 }
303 307
304 TEST_F(TransportFeedbackAdapterTest, HandlesReordering) { 308 TEST_F(TransportFeedbackAdapterTest, HandlesReordering) {
305 std::vector<PacketInfo> packets; 309 std::vector<PacketFeedback> packets;
306 packets.push_back(PacketInfo(120, 200, 0, 1500, kPacingInfo0)); 310 packets.push_back(PacketFeedback(120, 200, 0, 1500, kPacingInfo0));
307 packets.push_back(PacketInfo(110, 210, 1, 1500, kPacingInfo0)); 311 packets.push_back(PacketFeedback(110, 210, 1, 1500, kPacingInfo0));
308 packets.push_back(PacketInfo(100, 220, 2, 1500, kPacingInfo0)); 312 packets.push_back(PacketFeedback(100, 220, 2, 1500, kPacingInfo0));
309 std::vector<PacketInfo> expected_packets; 313 std::vector<PacketFeedback> expected_packets;
310 expected_packets.push_back(packets[2]); 314 expected_packets.push_back(packets[2]);
311 expected_packets.push_back(packets[1]); 315 expected_packets.push_back(packets[1]);
312 expected_packets.push_back(packets[0]); 316 expected_packets.push_back(packets[0]);
313 317
314 for (const PacketInfo& packet : packets) 318 for (const PacketFeedback& packet : packets)
315 OnSentPacket(packet); 319 OnSentPacket(packet);
316 320
317 rtcp::TransportFeedback feedback; 321 rtcp::TransportFeedback feedback;
318 feedback.SetBase(packets[0].sequence_number, 322 feedback.SetBase(packets[0].sequence_number,
319 packets[0].arrival_time_ms * 1000); 323 packets[0].arrival_time_ms * 1000);
320 324
321 for (const PacketInfo& packet : packets) { 325 for (const PacketFeedback& packet : packets) {
322 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number, 326 EXPECT_TRUE(feedback.AddReceivedPacket(packet.sequence_number,
323 packet.arrival_time_ms * 1000)); 327 packet.arrival_time_ms * 1000));
324 } 328 }
325 329
326 feedback.Build(); 330 feedback.Build();
327 331
328 adapter_->OnTransportFeedback(feedback); 332 adapter_->OnTransportFeedback(feedback);
329 ComparePacketVectors(expected_packets, 333 ComparePacketVectors(expected_packets,
330 adapter_->GetTransportFeedbackVector()); 334 adapter_->GetTransportFeedbackVector());
331 } 335 }
332 336
333 TEST_F(TransportFeedbackAdapterTest, TimestampDeltas) { 337 TEST_F(TransportFeedbackAdapterTest, TimestampDeltas) {
334 std::vector<PacketInfo> sent_packets; 338 std::vector<PacketFeedback> sent_packets;
335 const int64_t kSmallDeltaUs = 339 const int64_t kSmallDeltaUs =
336 rtcp::TransportFeedback::kDeltaScaleFactor * ((1 << 8) - 1); 340 rtcp::TransportFeedback::kDeltaScaleFactor * ((1 << 8) - 1);
337 const int64_t kLargePositiveDeltaUs = 341 const int64_t kLargePositiveDeltaUs =
338 rtcp::TransportFeedback::kDeltaScaleFactor * 342 rtcp::TransportFeedback::kDeltaScaleFactor *
339 std::numeric_limits<int16_t>::max(); 343 std::numeric_limits<int16_t>::max();
340 const int64_t kLargeNegativeDeltaUs = 344 const int64_t kLargeNegativeDeltaUs =
341 rtcp::TransportFeedback::kDeltaScaleFactor * 345 rtcp::TransportFeedback::kDeltaScaleFactor *
342 std::numeric_limits<int16_t>::min(); 346 std::numeric_limits<int16_t>::min();
343 347
344 PacketInfo info(100, 200, 0, 1500, true, PacedPacketInfo()); 348 PacketFeedback packet_feedback(100, 200, 0, 1500, true, PacedPacketInfo());
345 sent_packets.push_back(info); 349 sent_packets.push_back(packet_feedback);
346 350
347 info.send_time_ms += kSmallDeltaUs / 1000; 351 packet_feedback.send_time_ms += kSmallDeltaUs / 1000;
348 info.arrival_time_ms += kSmallDeltaUs / 1000; 352 packet_feedback.arrival_time_ms += kSmallDeltaUs / 1000;
349 ++info.sequence_number; 353 ++packet_feedback.sequence_number;
350 sent_packets.push_back(info); 354 sent_packets.push_back(packet_feedback);
351 355
352 info.send_time_ms += kLargePositiveDeltaUs / 1000; 356 packet_feedback.send_time_ms += kLargePositiveDeltaUs / 1000;
353 info.arrival_time_ms += kLargePositiveDeltaUs / 1000; 357 packet_feedback.arrival_time_ms += kLargePositiveDeltaUs / 1000;
354 ++info.sequence_number; 358 ++packet_feedback.sequence_number;
355 sent_packets.push_back(info); 359 sent_packets.push_back(packet_feedback);
356 360
357 info.send_time_ms += kLargeNegativeDeltaUs / 1000; 361 packet_feedback.send_time_ms += kLargeNegativeDeltaUs / 1000;
358 info.arrival_time_ms += kLargeNegativeDeltaUs / 1000; 362 packet_feedback.arrival_time_ms += kLargeNegativeDeltaUs / 1000;
359 ++info.sequence_number; 363 ++packet_feedback.sequence_number;
360 sent_packets.push_back(info); 364 sent_packets.push_back(packet_feedback);
361 365
362 // Too large, delta - will need two feedback messages. 366 // Too large, delta - will need two feedback messages.
363 info.send_time_ms += (kLargePositiveDeltaUs + 1000) / 1000; 367 packet_feedback.send_time_ms += (kLargePositiveDeltaUs + 1000) / 1000;
364 info.arrival_time_ms += (kLargePositiveDeltaUs + 1000) / 1000; 368 packet_feedback.arrival_time_ms += (kLargePositiveDeltaUs + 1000) / 1000;
365 ++info.sequence_number; 369 ++packet_feedback.sequence_number;
366 370
367 // Packets will be added to send history. 371 // Packets will be added to send history.
368 for (const PacketInfo& packet : sent_packets) 372 for (const PacketFeedback& packet : sent_packets)
369 OnSentPacket(packet); 373 OnSentPacket(packet);
370 OnSentPacket(info); 374 OnSentPacket(packet_feedback);
371 375
372 // Create expected feedback and send into adapter. 376 // Create expected feedback and send into adapter.
373 std::unique_ptr<rtcp::TransportFeedback> feedback( 377 std::unique_ptr<rtcp::TransportFeedback> feedback(
374 new rtcp::TransportFeedback()); 378 new rtcp::TransportFeedback());
375 feedback->SetBase(sent_packets[0].sequence_number, 379 feedback->SetBase(sent_packets[0].sequence_number,
376 sent_packets[0].arrival_time_ms * 1000); 380 sent_packets[0].arrival_time_ms * 1000);
377 381
378 for (const PacketInfo& packet : sent_packets) { 382 for (const PacketFeedback& packet : sent_packets) {
379 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, 383 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number,
380 packet.arrival_time_ms * 1000)); 384 packet.arrival_time_ms * 1000));
381 } 385 }
382 EXPECT_FALSE(feedback->AddReceivedPacket(info.sequence_number, 386 EXPECT_FALSE(feedback->AddReceivedPacket(
383 info.arrival_time_ms * 1000)); 387 packet_feedback.sequence_number, packet_feedback.arrival_time_ms * 1000));
384 388
385 rtc::Buffer raw_packet = feedback->Build(); 389 rtc::Buffer raw_packet = feedback->Build();
386 feedback = 390 feedback =
387 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size()); 391 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size());
388 392
389 std::vector<PacketInfo> received_feedback; 393 std::vector<PacketFeedback> received_feedback;
390 394
391 EXPECT_TRUE(feedback.get() != nullptr); 395 EXPECT_TRUE(feedback.get() != nullptr);
392 adapter_->OnTransportFeedback(*feedback.get()); 396 adapter_->OnTransportFeedback(*feedback.get());
393 { 397 {
394 // Expected to be ordered on arrival time when the feedback message has been 398 // Expected to be ordered on arrival time when the feedback message has been
395 // parsed. 399 // parsed.
396 std::vector<PacketInfo> expected_packets; 400 std::vector<PacketFeedback> expected_packets;
397 expected_packets.push_back(sent_packets[0]); 401 expected_packets.push_back(sent_packets[0]);
398 expected_packets.push_back(sent_packets[3]); 402 expected_packets.push_back(sent_packets[3]);
399 expected_packets.push_back(sent_packets[1]); 403 expected_packets.push_back(sent_packets[1]);
400 expected_packets.push_back(sent_packets[2]); 404 expected_packets.push_back(sent_packets[2]);
401 ComparePacketVectors(expected_packets, 405 ComparePacketVectors(expected_packets,
402 adapter_->GetTransportFeedbackVector()); 406 adapter_->GetTransportFeedbackVector());
403 } 407 }
404 408
405 // Create a new feedback message and add the trailing item. 409 // Create a new feedback message and add the trailing item.
406 feedback.reset(new rtcp::TransportFeedback()); 410 feedback.reset(new rtcp::TransportFeedback());
407 feedback->SetBase(info.sequence_number, info.arrival_time_ms * 1000); 411 feedback->SetBase(packet_feedback.sequence_number,
408 EXPECT_TRUE(feedback->AddReceivedPacket(info.sequence_number, 412 packet_feedback.arrival_time_ms * 1000);
409 info.arrival_time_ms * 1000)); 413 EXPECT_TRUE(feedback->AddReceivedPacket(
414 packet_feedback.sequence_number, packet_feedback.arrival_time_ms * 1000));
410 raw_packet = feedback->Build(); 415 raw_packet = feedback->Build();
411 feedback = 416 feedback =
412 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size()); 417 rtcp::TransportFeedback::ParseFrom(raw_packet.data(), raw_packet.size());
413 418
414 EXPECT_TRUE(feedback.get() != nullptr); 419 EXPECT_TRUE(feedback.get() != nullptr);
415 adapter_->OnTransportFeedback(*feedback.get()); 420 adapter_->OnTransportFeedback(*feedback.get());
416 { 421 {
417 std::vector<PacketInfo> expected_packets; 422 std::vector<PacketFeedback> expected_packets;
418 expected_packets.push_back(info); 423 expected_packets.push_back(packet_feedback);
419 ComparePacketVectors(expected_packets, 424 ComparePacketVectors(expected_packets,
420 adapter_->GetTransportFeedbackVector()); 425 adapter_->GetTransportFeedbackVector());
421 } 426 }
422 } 427 }
423 428
424 TEST_F(TransportFeedbackAdapterTest, UpdatesDelayBasedEstimate) { 429 TEST_F(TransportFeedbackAdapterTest, UpdatesDelayBasedEstimate) {
425 uint16_t seq_num = 0; 430 uint16_t seq_num = 0;
426 size_t kPayloadSize = 1000; 431 size_t kPayloadSize = 1000;
427 // The test must run and insert packets/feedback long enough that the 432 // The test must run and insert packets/feedback long enough that the
428 // BWE computes a valid estimate. 433 // BWE computes a valid estimate.
429 const int64_t kRunTimeMs = 6000; 434 const int64_t kRunTimeMs = 6000;
430 int64_t start_time_ms = clock_.TimeInMilliseconds(); 435 int64_t start_time_ms = clock_.TimeInMilliseconds();
431 while (clock_.TimeInMilliseconds() - start_time_ms < kRunTimeMs) { 436 while (clock_.TimeInMilliseconds() - start_time_ms < kRunTimeMs) {
432 PacketInfo packet(clock_.TimeInMilliseconds(), clock_.TimeInMilliseconds(), 437 PacketFeedback packet(clock_.TimeInMilliseconds(),
433 seq_num, kPayloadSize, PacedPacketInfo()); 438 clock_.TimeInMilliseconds(), seq_num, kPayloadSize,
439 PacedPacketInfo());
434 OnSentPacket(packet); 440 OnSentPacket(packet);
435 // Create expected feedback and send into adapter. 441 // Create expected feedback and send into adapter.
436 std::unique_ptr<rtcp::TransportFeedback> feedback( 442 std::unique_ptr<rtcp::TransportFeedback> feedback(
437 new rtcp::TransportFeedback()); 443 new rtcp::TransportFeedback());
438 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000); 444 feedback->SetBase(packet.sequence_number, packet.arrival_time_ms * 1000);
439 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number, 445 EXPECT_TRUE(feedback->AddReceivedPacket(packet.sequence_number,
440 packet.arrival_time_ms * 1000)); 446 packet.arrival_time_ms * 1000));
441 rtc::Buffer raw_packet = feedback->Build(); 447 rtc::Buffer raw_packet = feedback->Build();
442 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(), 448 feedback = rtcp::TransportFeedback::ParseFrom(raw_packet.data(),
443 raw_packet.size()); 449 raw_packet.size());
444 EXPECT_TRUE(feedback.get() != nullptr); 450 EXPECT_TRUE(feedback.get() != nullptr);
445 adapter_->OnTransportFeedback(*feedback.get()); 451 adapter_->OnTransportFeedback(*feedback.get());
446 clock_.AdvanceTimeMilliseconds(50); 452 clock_.AdvanceTimeMilliseconds(50);
447 ++seq_num; 453 ++seq_num;
448 } 454 }
449 EXPECT_GT(target_bitrate_bps_, 0u); 455 EXPECT_GT(target_bitrate_bps_, 0u);
450 } 456 }
451 457
452 } // namespace test 458 } // namespace test
453 } // namespace webrtc 459 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698