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 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 config.remote_ssrc = 5548; | 302 config.remote_ssrc = 5548; |
303 stream = call->CreateFlexfecReceiveStream(config); | 303 stream = call->CreateFlexfecReceiveStream(config); |
304 EXPECT_NE(stream, nullptr); | 304 EXPECT_NE(stream, nullptr); |
305 streams.push_back(stream); | 305 streams.push_back(stream); |
306 | 306 |
307 for (auto s : streams) { | 307 for (auto s : streams) { |
308 call->DestroyFlexfecReceiveStream(s); | 308 call->DestroyFlexfecReceiveStream(s); |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 // TODO(zstein): This is just a motivating example for | 312 class CallBitrateTest : public testing::Test { |
313 // MockSendSideCongestionController. It should be deleted once we have more | 313 public: |
314 // meaningful tests. | 314 void SetUp() { |
315 TEST(CallTest, MockSendSideCongestionControllerExample) { | 315 Clock* clock = Clock::GetRealTimeClock(); |
316 RtcEventLogNullImpl event_log; | 316 mock_cc_ = rtc::MakeUnique< |
317 Call::Config config(&event_log); | 317 testing::NiceMock<test::MockSendSideCongestionController>>( |
318 | 318 clock, &event_log_, &packet_router_); |
319 SimulatedClock clock(123456); | 319 } |
320 PacketRouter packet_router; | 320 |
321 testing::NiceMock<test::MockSendSideCongestionController> mock_cc( | 321 void CreateCall() { |
322 &clock, &event_log, &packet_router); | 322 Call::Config config(&event_log_); |
323 auto transport_send = | 323 CreateCall(config); |
324 rtc::MakeUnique<FakeRtpTransportControllerSend>(&mock_cc); | 324 } |
325 std::unique_ptr<Call> call(Call::Create(config, std::move(transport_send))); | 325 |
326 | 326 void CreateCall(const Call::Config& config) { |
327 Call::Config::BitrateConfig bitrate_config; | 327 std::unique_ptr<RtpTransportControllerSendInterface> fake_controller = |
328 bitrate_config.min_bitrate_bps = 1; | 328 rtc::MakeUnique<FakeRtpTransportControllerSend>(&packet_router_, |
329 bitrate_config.start_bitrate_bps = 2; | 329 mock_cc_.get()); |
330 bitrate_config.max_bitrate_bps = 3; | 330 call_.reset(Call::Create(config, std::move(fake_controller))); |
331 | 331 } |
332 EXPECT_CALL(mock_cc, SetBweBitrates(1, 2, 3)); | 332 |
333 call->SetBitrateConfig(bitrate_config); | 333 std::unique_ptr<testing::NiceMock<test::MockSendSideCongestionController>> |
| 334 mock_cc_; |
| 335 std::unique_ptr<Call> call_; |
| 336 |
| 337 webrtc::RtcEventLogNullImpl event_log_; |
| 338 |
| 339 private: |
| 340 PacketRouter packet_router_; |
| 341 }; |
| 342 |
| 343 TEST_F(CallBitrateTest, BiggerMaskMinUsed) { |
| 344 CreateCall(); |
| 345 Call::Config::BitrateConfigMask mask; |
| 346 mask.min_bitrate_bps = rtc::Optional<int>(1234); |
| 347 |
| 348 EXPECT_CALL(*mock_cc_, |
| 349 SetBweBitrates(*mask.min_bitrate_bps, testing::_, testing::_)); |
| 350 call_->SetBitrateConfigMask(mask); |
| 351 } |
| 352 |
| 353 TEST_F(CallBitrateTest, BiggerConfigMinUsed) { |
| 354 CreateCall(); |
| 355 |
| 356 Call::Config::BitrateConfigMask mask; |
| 357 mask.min_bitrate_bps = rtc::Optional<int>(1000); |
| 358 EXPECT_CALL(*mock_cc_, SetBweBitrates(1000, testing::_, testing::_)); |
| 359 call_->SetBitrateConfigMask(mask); |
| 360 |
| 361 Call::Config::BitrateConfig config; |
| 362 config.min_bitrate_bps = 1234; |
| 363 |
| 364 EXPECT_CALL(*mock_cc_, SetBweBitrates(1234, testing::_, testing::_)); |
| 365 call_->SetBitrateConfig(config); |
| 366 } |
| 367 |
| 368 // The last call to set start should be used. |
| 369 TEST_F(CallBitrateTest, LatestStartMaskPreferred) { |
| 370 CreateCall(); |
| 371 Call::Config::BitrateConfigMask mask; |
| 372 mask.start_bitrate_bps = rtc::Optional<int>(1300); |
| 373 |
| 374 EXPECT_CALL(*mock_cc_, |
| 375 SetBweBitrates(testing::_, *mask.start_bitrate_bps, testing::_)); |
| 376 call_->SetBitrateConfigMask(mask); |
| 377 |
| 378 Call::Config::BitrateConfig config; |
| 379 config.start_bitrate_bps = 1200; |
| 380 |
| 381 EXPECT_CALL(*mock_cc_, |
| 382 SetBweBitrates(testing::_, config.start_bitrate_bps, testing::_)); |
| 383 call_->SetBitrateConfig(config); |
| 384 } |
| 385 |
| 386 TEST_F(CallBitrateTest, SmallerMaskMaxUsed) { |
| 387 Call::Config config(&event_log_); |
| 388 config.bitrate_config.max_bitrate_bps = |
| 389 config.bitrate_config.start_bitrate_bps + 2000; |
| 390 CreateCall(config); |
| 391 |
| 392 Call::Config::BitrateConfigMask mask; |
| 393 mask.max_bitrate_bps = |
| 394 rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 1000); |
| 395 |
| 396 EXPECT_CALL(*mock_cc_, |
| 397 SetBweBitrates(testing::_, testing::_, *mask.max_bitrate_bps)); |
| 398 call_->SetBitrateConfigMask(mask); |
| 399 } |
| 400 |
| 401 TEST_F(CallBitrateTest, SmallerConfigMaxUsed) { |
| 402 Call::Config config(&event_log_); |
| 403 config.bitrate_config.max_bitrate_bps = |
| 404 config.bitrate_config.start_bitrate_bps + 1000; |
| 405 CreateCall(config); |
| 406 |
| 407 Call::Config::BitrateConfigMask mask; |
| 408 mask.max_bitrate_bps = |
| 409 rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 2000); |
| 410 |
| 411 // Expect no calls because nothing changes |
| 412 EXPECT_CALL(*mock_cc_, SetBweBitrates(testing::_, testing::_, testing::_)) |
| 413 .Times(0); |
| 414 call_->SetBitrateConfigMask(mask); |
| 415 } |
| 416 |
| 417 TEST_F(CallBitrateTest, MaskStartLessThanConfigMinClamped) { |
| 418 Call::Config config(&event_log_); |
| 419 config.bitrate_config.min_bitrate_bps = 2000; |
| 420 CreateCall(config); |
| 421 |
| 422 Call::Config::BitrateConfigMask mask; |
| 423 mask.start_bitrate_bps = rtc::Optional<int>(1000); |
| 424 |
| 425 EXPECT_CALL(*mock_cc_, SetBweBitrates(2000, 2000, testing::_)); |
| 426 call_->SetBitrateConfigMask(mask); |
| 427 } |
| 428 |
| 429 TEST_F(CallBitrateTest, MaskStartGreaterThanConfigMaxClamped) { |
| 430 Call::Config config(&event_log_); |
| 431 config.bitrate_config.start_bitrate_bps = 2000; |
| 432 CreateCall(config); |
| 433 |
| 434 Call::Config::BitrateConfigMask mask; |
| 435 mask.max_bitrate_bps = rtc::Optional<int>(1000); |
| 436 |
| 437 EXPECT_CALL(*mock_cc_, SetBweBitrates(testing::_, -1, 1000)); |
| 438 call_->SetBitrateConfigMask(mask); |
| 439 } |
| 440 |
| 441 TEST_F(CallBitrateTest, MaskMinGreaterThanConfigMaxClamped) { |
| 442 Call::Config config(&event_log_); |
| 443 config.bitrate_config.min_bitrate_bps = 2000; |
| 444 CreateCall(config); |
| 445 |
| 446 Call::Config::BitrateConfigMask mask; |
| 447 mask.max_bitrate_bps = rtc::Optional<int>(1000); |
| 448 |
| 449 EXPECT_CALL(*mock_cc_, SetBweBitrates(1000, testing::_, 1000)); |
| 450 call_->SetBitrateConfigMask(mask); |
| 451 } |
| 452 |
| 453 TEST_F(CallBitrateTest, SettingMaskStartForcesUpdate) { |
| 454 CreateCall(); |
| 455 |
| 456 Call::Config::BitrateConfigMask mask; |
| 457 mask.start_bitrate_bps = rtc::Optional<int>(1000); |
| 458 |
| 459 // SetBweBitrates should be called twice with the same params since |
| 460 // start_bitrate_bps is set. |
| 461 EXPECT_CALL(*mock_cc_, SetBweBitrates(testing::_, 1000, testing::_)).Times(2); |
| 462 call_->SetBitrateConfigMask(mask); |
| 463 call_->SetBitrateConfigMask(mask); |
| 464 } |
| 465 |
| 466 TEST_F(CallBitrateTest, |
| 467 SetBitrateConfigWithNoChangesDoesNotCallSetBweBitrates) { |
| 468 CreateCall(); |
| 469 |
| 470 Call::Config::BitrateConfig config1; |
| 471 config1.min_bitrate_bps = 0; |
| 472 config1.start_bitrate_bps = 1000; |
| 473 config1.max_bitrate_bps = -1; |
| 474 |
| 475 Call::Config::BitrateConfig config2; |
| 476 config2.min_bitrate_bps = 0; |
| 477 config2.start_bitrate_bps = -1; |
| 478 config2.max_bitrate_bps = -1; |
| 479 |
| 480 // The second call should not call SetBweBitrates because it doesn't |
| 481 // change any values. |
| 482 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1)); |
| 483 call_->SetBitrateConfig(config1); |
| 484 call_->SetBitrateConfig(config2); |
| 485 } |
| 486 |
| 487 // If SetBitrateConfig changes the max, but not the effective max, |
| 488 // SetBweBitrates shouldn't be called, to avoid unnecessary encoder |
| 489 // reconfigurations. |
| 490 TEST_F(CallBitrateTest, SetBweBitratesNotCalledWhenEffectiveMaxUnchanged) { |
| 491 CreateCall(); |
| 492 |
| 493 Call::Config::BitrateConfig config; |
| 494 config.min_bitrate_bps = 0; |
| 495 config.start_bitrate_bps = -1; |
| 496 config.max_bitrate_bps = 2000; |
| 497 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, -1, 2000)); |
| 498 call_->SetBitrateConfig(config); |
| 499 |
| 500 // Reduce effective max to 1000 with the mask. |
| 501 Call::Config::BitrateConfigMask mask; |
| 502 mask.max_bitrate_bps = rtc::Optional<int>(1000); |
| 503 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, -1, 1000)); |
| 504 call_->SetBitrateConfigMask(mask); |
| 505 |
| 506 // This leaves the effective max unchanged, so SetBweBitrates shouldn't be |
| 507 // called again. |
| 508 config.max_bitrate_bps = 1000; |
| 509 call_->SetBitrateConfig(config); |
| 510 } |
| 511 |
| 512 // When the "start bitrate" mask is removed, SetBweBitrates shouldn't be called |
| 513 // again, since nothing's changing. |
| 514 TEST_F(CallBitrateTest, SetBweBitratesNotCalledWhenStartMaskRemoved) { |
| 515 CreateCall(); |
| 516 |
| 517 Call::Config::BitrateConfigMask mask; |
| 518 mask.start_bitrate_bps = rtc::Optional<int>(1000); |
| 519 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1)); |
| 520 call_->SetBitrateConfigMask(mask); |
| 521 |
| 522 mask.start_bitrate_bps.reset(); |
| 523 call_->SetBitrateConfigMask(mask); |
| 524 } |
| 525 |
| 526 // Test that if SetBitrateConfig is called after SetBitrateConfigMask applies a |
| 527 // "start" value, the SetBitrateConfig call won't apply that start value a |
| 528 // second time. |
| 529 TEST_F(CallBitrateTest, SetBitrateConfigAfterSetBitrateConfigMaskWithStart) { |
| 530 CreateCall(); |
| 531 |
| 532 Call::Config::BitrateConfigMask mask; |
| 533 mask.start_bitrate_bps = rtc::Optional<int>(1000); |
| 534 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1)); |
| 535 call_->SetBitrateConfigMask(mask); |
| 536 |
| 537 Call::Config::BitrateConfig config; |
| 538 config.min_bitrate_bps = 0; |
| 539 config.start_bitrate_bps = -1; |
| 540 config.max_bitrate_bps = 5000; |
| 541 // The start value isn't changing, so SetBweBitrates should be called with |
| 542 // -1. |
| 543 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, -1, 5000)); |
| 544 call_->SetBitrateConfig(config); |
334 } | 545 } |
335 | 546 |
336 } // namespace webrtc | 547 } // namespace webrtc |
OLD | NEW |