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

Side by Side Diff: webrtc/modules/pacing/packet_router_unittest.cc

Issue 2789843002: Delete VieRemb class, move functionality to PacketRouter. (Closed)
Patch Set: Delete obsolete suppression for PacketRouterTest.SendTransportFeedback. Created 3 years, 8 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
11 #include <list> 11 #include <list>
12 #include <memory> 12 #include <memory>
13 13
14 #include "webrtc/base/checks.h" 14 #include "webrtc/base/checks.h"
15 #include "webrtc/base/fakeclock.h"
15 #include "webrtc/modules/pacing/packet_router.h" 16 #include "webrtc/modules/pacing/packet_router.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
17 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" 18 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
19 #include "webrtc/test/gmock.h" 20 #include "webrtc/test/gmock.h"
20 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
21 22
22 using ::testing::_; 23 using ::testing::_;
23 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
24 using ::testing::Field; 25 using ::testing::Field;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 236
236 packet_router_->SetTransportWideSequenceNumber(kStartSeq - 1); 237 packet_router_->SetTransportWideSequenceNumber(kStartSeq - 1);
237 238
238 for (size_t i = 0; i < kNumPackets; ++i) { 239 for (size_t i = 0; i < kNumPackets; ++i) {
239 uint16_t seq = packet_router_->AllocateSequenceNumber(); 240 uint16_t seq = packet_router_->AllocateSequenceNumber();
240 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i; 241 uint32_t expected_unwrapped_seq = static_cast<uint32_t>(kStartSeq) + i;
241 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq); 242 EXPECT_EQ(static_cast<uint16_t>(expected_unwrapped_seq & 0xFFFF), seq);
242 } 243 }
243 } 244 }
244 245
245 TEST_F(PacketRouterTest, SendFeedback) { 246 TEST_F(PacketRouterTest, SendTransportFeedback) {
246 MockRtpRtcp rtp_1; 247 MockRtpRtcp rtp_1;
247 MockRtpRtcp rtp_2; 248 MockRtpRtcp rtp_2;
248 packet_router_->AddSendRtpModule(&rtp_1); 249 packet_router_->AddSendRtpModule(&rtp_1);
249 packet_router_->AddReceiveRtpModule(&rtp_2); 250 packet_router_->AddReceiveRtpModule(&rtp_2);
250 251
251 rtcp::TransportFeedback feedback; 252 rtcp::TransportFeedback feedback;
252 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1); 253 EXPECT_CALL(rtp_1, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true));
253 packet_router_->SendFeedback(&feedback); 254 packet_router_->SendTransportFeedback(&feedback);
254 packet_router_->RemoveSendRtpModule(&rtp_1); 255 packet_router_->RemoveSendRtpModule(&rtp_1);
255 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1); 256 EXPECT_CALL(rtp_2, SendFeedbackPacket(_)).Times(1).WillOnce(Return(true));
256 packet_router_->SendFeedback(&feedback); 257 packet_router_->SendTransportFeedback(&feedback);
257 packet_router_->RemoveReceiveRtpModule(&rtp_2); 258 packet_router_->RemoveReceiveRtpModule(&rtp_2);
258 } 259 }
260
261 TEST(PacketRouterRembTest, PreferSendModuleOverReceiveModule) {
262 rtc::ScopedFakeClock clock;
263 MockRtpRtcp rtp_recv;
264 MockRtpRtcp rtp_send;
265 PacketRouter packet_router;
266
267 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1);
268 packet_router.AddReceiveRtpModule(&rtp_recv);
269
270 const uint32_t bitrate_estimate = 456;
271 const std::vector<uint32_t> ssrcs = {1234};
272
273 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true));
274 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
275
276 // Call OnReceiveBitrateChanged twice to get a first estimate.
277 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
278 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
279 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
280
281 // Add a send module, which should be preferred over the receive module.
282 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1);
283 EXPECT_CALL(rtp_send, SetREMBStatus(true)).Times(1);
284 packet_router.AddSendRtpModule(&rtp_send);
285 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(false));
286 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
287
288 // Lower bitrate to send another REMB packet.
289 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
290 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
291
292 EXPECT_CALL(rtp_send, SetREMBStatus(false)).Times(1);
293 EXPECT_CALL(rtp_recv, SetREMBStatus(true)).Times(1);
294 packet_router.RemoveSendRtpModule(&rtp_send);
295 EXPECT_CALL(rtp_recv, SetREMBStatus(false)).Times(1);
296 packet_router.RemoveReceiveRtpModule(&rtp_recv);
297 }
298
299 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) {
300 rtc::ScopedFakeClock clock;
301 MockRtpRtcp rtp;
302 PacketRouter packet_router;
303
304 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
305 packet_router.AddSendRtpModule(&rtp);
306
307 uint32_t bitrate_estimate = 456;
308 const std::vector<uint32_t> ssrcs = {1234};
309
310 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
311 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
312
313 // Call OnReceiveBitrateChanged twice to get a first estimate.
314 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
315 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
316 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
317
318 // Lower the estimate with more than 3% to trigger a call to SetREMBData right
319 // away.
320 bitrate_estimate = bitrate_estimate - 100;
321 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
322 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
323
324 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
325 packet_router.RemoveSendRtpModule(&rtp);
326 }
327
328 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) {
329 rtc::ScopedFakeClock clock;
330 MockRtpRtcp rtp;
331 PacketRouter packet_router;
332 packet_router.AddSendRtpModule(&rtp);
333
334 uint32_t bitrate_estimate[] = {456, 789};
335 std::vector<uint32_t> ssrcs = {1234, 5678};
336
337 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
338 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
339
340 // Call OnReceiveBitrateChanged twice to get a first estimate.
341 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1);
342 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
343 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
344
345 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100);
346
347 // Lower the estimate to trigger a callback.
348 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1);
349 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]);
350
351 packet_router.RemoveSendRtpModule(&rtp);
352 }
353
354 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) {
355 rtc::ScopedFakeClock clock;
356 MockRtpRtcp rtp;
357 PacketRouter packet_router;
358 packet_router.AddSendRtpModule(&rtp);
359
360 uint32_t bitrate_estimate = 456;
361 std::vector<uint32_t> ssrcs = {1234, 5678};
362
363 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
364 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
365
366 // Call OnReceiveBitrateChanged twice to get a first estimate.
367 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
368 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
369 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
370
371 // Increased estimate shouldn't trigger a callback right away.
372 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
373 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1);
374
375 // Decreasing the estimate less than 3% shouldn't trigger a new callback.
376 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
377 int lower_estimate = bitrate_estimate * 98 / 100;
378 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate);
379
380 packet_router.RemoveSendRtpModule(&rtp);
381 }
382
383 TEST(PacketRouterRembTest, ChangeSendRtpModule) {
384 rtc::ScopedFakeClock clock;
385 MockRtpRtcp rtp_send;
386 MockRtpRtcp rtp_recv;
387 PacketRouter packet_router;
388 packet_router.AddSendRtpModule(&rtp_send);
389 packet_router.AddReceiveRtpModule(&rtp_recv);
390
391 uint32_t bitrate_estimate = 456;
392 std::vector<uint32_t> ssrcs = {1234, 5678};
393
394 ON_CALL(rtp_send, REMB()).WillByDefault(Return(true));
395 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
396
397 // Call OnReceiveBitrateChanged twice to get a first estimate.
398 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
399 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
400 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
401
402 // Decrease estimate to trigger a REMB.
403 bitrate_estimate = bitrate_estimate - 100;
404 EXPECT_CALL(rtp_send, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
405 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
406
407 // Remove the sending module -> should get remb on the second module.
408 packet_router.RemoveSendRtpModule(&rtp_send);
409
410 ON_CALL(rtp_send, REMB()).WillByDefault(Return(false));
411 ON_CALL(rtp_recv, REMB()).WillByDefault(Return(true));
412
413 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
414
415 bitrate_estimate = bitrate_estimate - 100;
416 EXPECT_CALL(rtp_recv, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
417 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
418
419 packet_router.RemoveReceiveRtpModule(&rtp_recv);
420 }
421
422 TEST(PacketRouterRembTest, OnlyOneRembForRepeatedOnReceiveBitrateChanged) {
423 rtc::ScopedFakeClock clock;
424 MockRtpRtcp rtp;
425 PacketRouter packet_router;
426 packet_router.AddSendRtpModule(&rtp);
427
428 uint32_t bitrate_estimate = 456;
429 const std::vector<uint32_t> ssrcs = {1234};
430
431 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
432 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
433
434 // Call OnReceiveBitrateChanged twice to get a first estimate.
435 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
436 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1);
437 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
438
439 // Lower the estimate, should trigger a call to SetREMBData right away.
440 bitrate_estimate = bitrate_estimate - 100;
441 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
442 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
443
444 // Call OnReceiveBitrateChanged again, this should not trigger a new callback.
445 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
446 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
447 packet_router.RemoveSendRtpModule(&rtp);
448 }
449
450 // Only register receiving modules and make sure we fallback to trigger a REMB
451 // packet on this one.
452 TEST(PacketRouterRembTest, NoSendingRtpModule) {
453 rtc::ScopedFakeClock clock;
454 MockRtpRtcp rtp;
455 PacketRouter packet_router;
456
457 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
458 packet_router.AddReceiveRtpModule(&rtp);
459
460 uint32_t bitrate_estimate = 456;
461 const std::vector<uint32_t> ssrcs = {1234};
462
463 ON_CALL(rtp, REMB()).WillByDefault(Return(true));
464 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
465
466 // Call OnReceiveBitrateChanged twice to get a first estimate.
467 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
468 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
469 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
470
471 // Lower the estimate to trigger a new packet REMB packet.
472 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
473 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
474
475 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
476 packet_router.RemoveReceiveRtpModule(&rtp);
477 }
478
259 } // namespace webrtc 479 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/packet_router.cc ('k') | webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698