Chromium Code Reviews| 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 <list> | 11 #include <list> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | |
| 14 | 15 |
| 16 #include "webrtc/base/ptr_util.h" | |
| 15 #include "webrtc/call/audio_state.h" | 17 #include "webrtc/call/audio_state.h" |
| 16 #include "webrtc/call/call.h" | 18 #include "webrtc/call/call.h" |
| 17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 18 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" | 20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
| 21 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont roller.h" | |
| 19 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
| 20 #include "webrtc/test/mock_audio_decoder_factory.h" | 23 #include "webrtc/test/mock_audio_decoder_factory.h" |
| 21 #include "webrtc/test/mock_transport.h" | 24 #include "webrtc/test/mock_transport.h" |
| 22 #include "webrtc/test/mock_voice_engine.h" | 25 #include "webrtc/test/mock_voice_engine.h" |
| 23 | 26 |
| 24 namespace { | 27 namespace { |
| 25 | 28 |
| 26 struct CallHelper { | 29 struct CallHelper { |
| 27 explicit CallHelper( | 30 explicit CallHelper( |
| 28 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr) | 31 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr) |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 config.remote_ssrc = 5548; | 301 config.remote_ssrc = 5548; |
| 299 stream = call->CreateFlexfecReceiveStream(config); | 302 stream = call->CreateFlexfecReceiveStream(config); |
| 300 EXPECT_NE(stream, nullptr); | 303 EXPECT_NE(stream, nullptr); |
| 301 streams.push_back(stream); | 304 streams.push_back(stream); |
| 302 | 305 |
| 303 for (auto s : streams) { | 306 for (auto s : streams) { |
| 304 call->DestroyFlexfecReceiveStream(s); | 307 call->DestroyFlexfecReceiveStream(s); |
| 305 } | 308 } |
| 306 } | 309 } |
| 307 | 310 |
| 311 // TODO(zstein): This probably belongs in webrtc/modules/congestion_controller/ | |
| 312 class MockSendSideCongestionController : public SendSideCongestionController { | |
| 313 public: | |
| 314 MockSendSideCongestionController(const Clock* clock, | |
| 315 Observer* observer, | |
| 316 RtcEventLog* event_log, | |
| 317 PacketRouter* packet_router) | |
| 318 : SendSideCongestionController(clock, | |
| 319 observer, | |
| 320 event_log, | |
| 321 packet_router) {} | |
| 322 | |
| 323 MOCK_METHOD3(SetBweBitrates, void(int, int, int)); | |
| 324 }; | |
| 325 | |
| 326 class FakeRtpTransportController : public RtpTransportControllerSendInterface { | |
| 327 public: | |
| 328 explicit FakeRtpTransportController(PacketRouter* r, | |
| 329 SendSideCongestionController* cc) | |
| 330 : packet_router_(r), send_side_cc_(cc) {} | |
| 331 | |
| 332 PacketRouter* packet_router() override { return packet_router_; } | |
| 333 | |
| 334 SendSideCongestionController* send_side_cc() override { | |
| 335 return send_side_cc_; | |
| 336 } | |
| 337 | |
| 338 TransportFeedbackObserver* transport_feedback_observer() override { | |
| 339 return send_side_cc_; | |
| 340 } | |
| 341 | |
| 342 RtpPacketSender* packet_sender() override { return nullptr; } | |
| 343 | |
| 344 private: | |
| 345 PacketRouter* packet_router_; | |
| 346 SendSideCongestionController* send_side_cc_; | |
| 347 }; | |
| 348 | |
| 349 class CallBitrateTest : public testing::Test { | |
| 350 public: | |
| 351 void SetUp() { | |
| 352 Clock* clock = Clock::GetRealTimeClock(); // TODO(zstein): test clock? | |
| 353 mock_cc_ = | |
| 354 rtc::MakeUnique<testing::NiceMock<MockSendSideCongestionController>>( | |
| 355 clock, nullptr, &event_log_, &packet_router_); | |
| 356 } | |
| 357 | |
| 358 void CreateCall() { | |
| 359 Call::Config config(&event_log_); | |
| 360 CreateCall(config); | |
| 361 } | |
| 362 | |
| 363 void CreateCall(const Call::Config& config) { | |
| 364 std::unique_ptr<RtpTransportControllerSendInterface> fake_controller = | |
| 365 rtc::MakeUnique<FakeRtpTransportController>(&packet_router_, | |
| 366 mock_cc_.get()); | |
| 367 call_.reset(Call::Create(config, std::move(fake_controller))); | |
| 368 } | |
| 369 | |
| 370 std::unique_ptr<testing::NiceMock<MockSendSideCongestionController>> mock_cc_; | |
| 371 std::unique_ptr<Call> call_; | |
| 372 | |
| 373 webrtc::RtcEventLogNullImpl event_log_; | |
| 374 | |
| 375 private: | |
| 376 PacketRouter packet_router_; // TODO(zstein): fake? | |
| 377 }; | |
| 378 | |
| 379 using testing::_; | |
| 380 | |
| 381 TEST_F(CallBitrateTest, MinMaskPreferred) { | |
| 382 CreateCall(); | |
| 383 Call::Config::BitrateConfigMask mask; | |
| 384 mask.min_bitrate_bps = rtc::Optional<int>(1234); | |
| 385 | |
| 386 EXPECT_CALL(*mock_cc_, SetBweBitrates(*mask.min_bitrate_bps, _, _)); | |
| 387 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok()); | |
| 388 } | |
| 389 | |
| 390 TEST_F(CallBitrateTest, StartMaskPreferred) { | |
| 391 CreateCall(); | |
| 392 Call::Config::BitrateConfigMask mask; | |
| 393 mask.start_bitrate_bps = rtc::Optional<int>(1234); | |
| 394 | |
| 395 EXPECT_CALL(*mock_cc_, SetBweBitrates(_, *mask.start_bitrate_bps, _)); | |
| 396 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok()); | |
| 397 } | |
| 398 | |
| 399 TEST_F(CallBitrateTest, SmallerMaskMaxUsed) { | |
| 400 Call::Config config(&event_log_); | |
| 401 config.bitrate_config.max_bitrate_bps = | |
| 402 config.bitrate_config.start_bitrate_bps + 2000; | |
| 403 CreateCall(config); | |
| 404 | |
| 405 Call::Config::BitrateConfigMask mask; | |
| 406 mask.max_bitrate_bps = | |
| 407 rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 1000); | |
| 408 | |
| 409 EXPECT_CALL(*mock_cc_, SetBweBitrates(_, _, *mask.max_bitrate_bps)); | |
| 410 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok()); | |
| 411 } | |
| 412 | |
| 413 TEST_F(CallBitrateTest, SmallerConfigMaxUsed) { | |
| 414 Call::Config config(&event_log_); | |
| 415 config.bitrate_config.max_bitrate_bps = | |
| 416 config.bitrate_config.start_bitrate_bps + 1000; | |
| 417 CreateCall(config); | |
| 418 | |
| 419 Call::Config::BitrateConfigMask mask; | |
| 420 mask.max_bitrate_bps = | |
| 421 rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 2000); | |
| 422 | |
| 423 // Expect no calls because nothing changes | |
| 424 EXPECT_CALL(*mock_cc_, SetBweBitrates(_, _, _)).Times(0); | |
| 425 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok()); | |
| 426 } | |
| 427 | |
| 428 TEST_F(CallBitrateTest, MaskStartLessThanConfigMinFails) { | |
| 429 Call::Config config(&event_log_); | |
| 430 config.bitrate_config.min_bitrate_bps = 2000; | |
| 431 CreateCall(config); | |
| 432 | |
| 433 Call::Config::BitrateConfigMask mask; | |
| 434 mask.start_bitrate_bps = rtc::Optional<int>(1000); | |
| 435 | |
| 436 EXPECT_FALSE(call_->SetBitrateConfigMask(mask).ok()); | |
| 437 } | |
| 438 | |
| 439 TEST_F(CallBitrateTest, MaskMaxLessThanConfigStartFails) { | |
| 440 Call::Config config(&event_log_); | |
| 441 config.bitrate_config.start_bitrate_bps = 2000; | |
| 442 CreateCall(config); | |
| 443 | |
| 444 Call::Config::BitrateConfigMask mask; | |
| 445 mask.max_bitrate_bps = rtc::Optional<int>(1000); | |
| 446 | |
| 447 EXPECT_FALSE(call_->SetBitrateConfigMask(mask).ok()); | |
| 448 } | |
| 449 | |
| 450 TEST_F(CallBitrateTest, MaskMaxLessThanConfigMinFails) { | |
| 451 Call::Config config(&event_log_); | |
| 452 config.bitrate_config.min_bitrate_bps = 2000; | |
| 453 CreateCall(config); | |
| 454 | |
| 455 Call::Config::BitrateConfigMask mask; | |
| 456 mask.max_bitrate_bps = rtc::Optional<int>(1000); | |
| 457 | |
| 458 EXPECT_FALSE(call_->SetBitrateConfigMask(mask).ok()); | |
| 459 } | |
| 460 | |
| 461 TEST_F(CallBitrateTest, SettingStartForcesUpdate) { | |
| 462 CreateCall(); | |
| 463 | |
| 464 Call::Config::BitrateConfigMask mask; | |
| 465 mask.start_bitrate_bps = rtc::Optional<int>(1000); | |
| 466 | |
| 467 // SetBweBitrates should be called twice with the same params when | |
| 468 // start_bitrate_bps is set. | |
| 469 EXPECT_CALL(*mock_cc_, SetBweBitrates(_, 1000, _)).Times(2); | |
| 470 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok()); | |
| 471 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok()); | |
| 472 } | |
| 473 | |
| 474 // TODO(zstein): Delete or rename. | |
| 475 TEST_F(CallBitrateTest, TaylorCR) { | |
| 476 CreateCall(); | |
| 477 | |
| 478 Call::Config::BitrateConfig config1; | |
| 479 config1.min_bitrate_bps = 0; | |
| 480 config1.start_bitrate_bps = 1000; | |
| 481 config1.max_bitrate_bps = -1; | |
| 482 | |
| 483 Call::Config::BitrateConfig config2; | |
| 484 config2.min_bitrate_bps = 0; | |
| 485 config2.start_bitrate_bps = -1; | |
| 486 config2.max_bitrate_bps = -1; | |
| 487 | |
| 488 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1)); | |
| 489 call_->SetBitrateConfig(config1); | |
| 490 call_->SetBitrateConfig(config2); | |
| 491 } | |
| 492 | |
|
Taylor Brandstetter
2017/05/05 08:04:32
I have some other suggestions for tests. Can you t
Zach Stein
2017/05/09 00:41:26
Thanks, these are great test cases. Did you have t
Taylor Brandstetter
2017/05/09 15:51:54
One is passing, but two aren't. The issue is that
| |
| 308 } // namespace webrtc | 493 } // namespace webrtc |
| OLD | NEW |