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

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

Issue 2789843002: Delete VieRemb class, move functionality to PacketRouter. (Closed)
Patch Set: Convert ViERemb tests to PacketRouter tests. 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);
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);
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 // TODO(nisse): This test is a bit pointless. Do we really want to
danilchap 2017/04/11 12:34:14 Is there a use case where same module used both as
nisse-webrtc 2017/04/11 14:30:14 Reworked to test handover.
262 // support the same module being registered twice? The REMBStatus
263 // logic probably won't do the right thing in this case.
stefan-webrtc 2017/04/11 09:28:36 Can this even be done in the code right now? I tho
nisse-webrtc 2017/04/11 10:57:41 I don't think there's any code that calls AddSendR
264 TEST(PacketRouterRembTest, OneModuleTestForSendingRemb) {
265 rtc::ScopedFakeClock clock;
266 MockRtpRtcp rtp;
267 PacketRouter packet_router;
268
269 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
270 packet_router.AddSendRtpModule(&rtp);
271 packet_router.AddReceiveRtpModule(&rtp);
272
273 const uint32_t bitrate_estimate = 456;
274 uint32_t ssrc = 1234;
275 std::vector<uint32_t> ssrcs(&ssrc, &ssrc + 1);
276
277 EXPECT_CALL(rtp, REMB()).WillRepeatedly(Return(true));
278 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
279
280 // Call OnReceiveBitrateChanged twice to get a first estimate.
281 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
282 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
283 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
284
285 // Lower bitrate to send another REMB packet.
286 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate - 100, ssrcs)).Times(1);
287 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate - 100);
288
289 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
290 packet_router.RemoveReceiveRtpModule(&rtp);
291 packet_router.RemoveSendRtpModule(&rtp);
292 }
293
294 TEST(PacketRouterRembTest, LowerEstimateToSendRemb) {
295 rtc::ScopedFakeClock clock;
296 MockRtpRtcp rtp;
297 PacketRouter packet_router;
298
299 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
300 packet_router.AddSendRtpModule(&rtp);
301
302 uint32_t bitrate_estimate = 456;
303 uint32_t ssrc = 1234;
304 std::vector<uint32_t> ssrcs(&ssrc, &ssrc + 1);
danilchap 2017/04/11 12:34:14 std::vector<uint32_t> ssrcs = {1234}; likely clean
nisse-webrtc 2017/04/11 14:30:14 Done, all occurences.
305
306 EXPECT_CALL(rtp, REMB()).WillRepeatedly(Return(true));
danilchap 2017/04/11 12:34:14 do you mean ON_CALL here? (i.e. you do not want to
nisse-webrtc 2017/04/11 14:30:14 Done. All replaced with ON_CALL(...).WillByDefault
307 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
308
309 // Call OnReceiveBitrateChanged twice to get a first estimate.
310 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
311 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
312 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
313
314 // Lower the estimate with more than 3% to trigger a call to SetREMBData right
315 // away.
316 bitrate_estimate = bitrate_estimate - 100;
317 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
318 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
319
320 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
321 packet_router.RemoveSendRtpModule(&rtp);
322 }
323
324 TEST(PacketRouterRembTest, UseReceiveModule) {
danilchap 2017/04/11 12:34:14 may be name test 'UseReceiveModuleWhenNoSendModule
nisse-webrtc 2017/04/11 14:30:14 No interesting difference, it just uses a bit stri
325 rtc::ScopedFakeClock clock;
326 MockRtpRtcp rtp;
327 PacketRouter packet_router;
328
329 EXPECT_CALL(rtp, SetREMBStatus(true)).Times(1);
330 packet_router.AddReceiveRtpModule(&rtp);
331
332 uint32_t bitrate_estimate = 456;
333 uint32_t ssrc = 1234;
334 std::vector<uint32_t> ssrcs(&ssrc, &ssrc + 1);
335
336 EXPECT_CALL(rtp, REMB()).WillRepeatedly(Return(true));
337 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
338
339 // Call OnReceiveBitrateChanged twice to get a first estimate.
340 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
341 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
342 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
343
344 // Lower the estimate with more than 3% to trigger a call to SetREMBData right
345 // away.
346 bitrate_estimate = bitrate_estimate - 100;
347 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
348 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
349
350 EXPECT_CALL(rtp, SetREMBStatus(false)).Times(1);
351 packet_router.RemoveReceiveRtpModule(&rtp);
352 }
353
354 TEST(PacketRouterRembTest, VerifyIncreasingAndDecreasing) {
355 rtc::ScopedFakeClock clock;
356 MockRtpRtcp rtp_0;
357 MockRtpRtcp rtp_1; // TODO(nisse): How is this relevant to this test?
danilchap 2017/04/11 12:34:14 May be add test 'PreferSenderModuleToSendRemb' whe
nisse-webrtc 2017/04/11 14:30:14 Deleting rtp_1. There are now two tests using rtp
358 PacketRouter packet_router;
359 packet_router.AddSendRtpModule(&rtp_0);
360 packet_router.AddReceiveRtpModule(&rtp_1);
361
362 uint32_t bitrate_estimate[] = {456, 789};
363 uint32_t ssrc[] = {1234, 5678};
364 std::vector<uint32_t> ssrcs(ssrc, ssrc + sizeof(ssrc) / sizeof(ssrc[0]));
365
366 EXPECT_CALL(rtp_0, REMB()).WillRepeatedly(Return(true));
367 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
368
369 // Call OnReceiveBitrateChanged twice to get a first estimate.
370 EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[0], ssrcs)).Times(1);
371 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
372 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[0]);
373
374 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1] + 100);
375
376 // Lower the estimate to trigger a callback.
377 EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate[1], ssrcs)).Times(1);
378 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate[1]);
379
380 packet_router.RemoveSendRtpModule(&rtp_0);
381 packet_router.RemoveReceiveRtpModule(&rtp_1);
382 }
383
384 TEST(PacketRouterRembTest, NoRembForIncreasedBitrate) {
385 rtc::ScopedFakeClock clock;
386 MockRtpRtcp rtp_0;
387 MockRtpRtcp rtp_1; // TODO(nisse): How is this relevant to this test?
388 PacketRouter packet_router;
389 packet_router.AddSendRtpModule(&rtp_0);
390 packet_router.AddReceiveRtpModule(&rtp_1);
391
392 uint32_t bitrate_estimate = 456;
393 uint32_t ssrc[] = {1234, 5678};
394 std::vector<uint32_t> ssrcs(ssrc, ssrc + sizeof(ssrc) / sizeof(ssrc[0]));
395
396 EXPECT_CALL(rtp_0, REMB()).WillRepeatedly(Return(true));
397 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
398
399 // Call OnReceiveBitrateChanged twice to get a first estimate.
400 EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
401 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
402 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
403
404 // Increased estimate shouldn't trigger a callback right away.
405 EXPECT_CALL(rtp_0, SetREMBData(_, _)).Times(0);
406 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate + 1);
407
408 // Decreasing the estimate less than 3% shouldn't trigger a new callback.
409 EXPECT_CALL(rtp_0, SetREMBData(_, _)).Times(0);
410 int lower_estimate = bitrate_estimate * 98 / 100;
411 packet_router.OnReceiveBitrateChanged(ssrcs, lower_estimate);
412
413 packet_router.RemoveSendRtpModule(&rtp_0);
414 packet_router.RemoveReceiveRtpModule(&rtp_1);
415 }
416
417 TEST(PacketRouterRembTest, ChangeSendRtpModule) {
418 rtc::ScopedFakeClock clock;
419 MockRtpRtcp rtp_0;
420 MockRtpRtcp rtp_1;
421 PacketRouter packet_router;
422 packet_router.AddSendRtpModule(&rtp_0);
423 packet_router.AddReceiveRtpModule(&rtp_1);
424
425 uint32_t bitrate_estimate = 456;
426 uint32_t ssrc[] = {1234, 5678};
427 std::vector<uint32_t> ssrcs(ssrc, ssrc + sizeof(ssrc) / sizeof(ssrc[0]));
428
429 EXPECT_CALL(rtp_0, REMB()).WillRepeatedly(Return(true));
430 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
431
432 // Call OnReceiveBitrateChanged twice to get a first estimate.
433 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
434 EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
435 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
436
437 // Decrease estimate to trigger a REMB.
438 bitrate_estimate = bitrate_estimate - 100;
439 EXPECT_CALL(rtp_0, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
440 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
441
442 // Remove the sending module -> should get remb on the second module.
443 packet_router.RemoveSendRtpModule(&rtp_0);
444
445 EXPECT_CALL(rtp_0, REMB()).WillRepeatedly(Return(false));
446 EXPECT_CALL(rtp_1, REMB()).WillRepeatedly(Return(true));
447
448 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
449
450 bitrate_estimate = bitrate_estimate - 100;
451 EXPECT_CALL(rtp_1, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
452 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
453
454 packet_router.RemoveReceiveRtpModule(&rtp_1);
455 }
456
457 TEST(PacketRouterRembTest, OnlyOneRembForDoubleProcess) {
stefan-webrtc 2017/04/11 09:28:36 Process has no meaning below. Should it say OnRece
nisse-webrtc 2017/04/11 14:30:14 Renamed to OnlyOneRembForRepeatedOnReceiveBitrateC
458 rtc::ScopedFakeClock clock;
459 MockRtpRtcp rtp;
460 PacketRouter packet_router;
461 packet_router.AddSendRtpModule(&rtp);
462
463 uint32_t bitrate_estimate = 456;
464 uint32_t ssrc = 1234;
465 std::vector<uint32_t> ssrcs(&ssrc, &ssrc + 1);
466
467 EXPECT_CALL(rtp, REMB()).WillRepeatedly(Return(true));
468 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
469
470 // Call OnReceiveBitrateChanged twice to get a first estimate.
471 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
472 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1);
473 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
474
475 // Lower the estimate, should trigger a call to SetREMBData right away.
476 bitrate_estimate = bitrate_estimate - 100;
477 EXPECT_CALL(rtp, SetREMBData(bitrate_estimate, ssrcs)).Times(1);
478 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
479
480 // Call OnReceiveBitrateChanged again, this should not trigger a new callback.
481 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(0);
482 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
483 packet_router.RemoveSendRtpModule(&rtp);
484 }
485
486 // Only register receiving modules and make sure we fallback to trigger a REMB
487 // packet on this one.
488 TEST(PacketRouterRembTest, NoSendingRtpModule) {
489 rtc::ScopedFakeClock clock;
490 MockRtpRtcp rtp;
491 PacketRouter packet_router;
492
493 packet_router.AddReceiveRtpModule(&rtp);
494
495 uint32_t bitrate_estimate = 456;
496 uint32_t ssrc = 1234;
497 std::vector<uint32_t> ssrcs(&ssrc, &ssrc + 1);
498
499 EXPECT_CALL(rtp, REMB()).WillRepeatedly(Return(true));
500 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
501
502 // Call OnReceiveBitrateChanged twice to get a first estimate.
503 clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
504 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1);
505 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
506
507 // Lower the estimate to trigger a new packet REMB packet.
508 bitrate_estimate = bitrate_estimate - 100;
509 EXPECT_CALL(rtp, SetREMBData(_, _)).Times(1);
510 packet_router.OnReceiveBitrateChanged(ssrcs, bitrate_estimate);
511
512 packet_router.RemoveReceiveRtpModule(&rtp);
513 }
514
259 } // namespace webrtc 515 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698