OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include <algorithm> | 10 #include <algorithm> |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 if (first_time_in_sync_ == -1) { | 167 if (first_time_in_sync_ == -1) { |
168 first_time_in_sync_ = now_ms; | 168 first_time_in_sync_ = now_ms; |
169 webrtc::test::PrintResult("sync_convergence_time", | 169 webrtc::test::PrintResult("sync_convergence_time", |
170 "", | 170 "", |
171 "synchronization", | 171 "synchronization", |
172 time_since_creation, | 172 time_since_creation, |
173 "ms", | 173 "ms", |
174 false); | 174 false); |
175 } | 175 } |
176 if (time_since_creation > kMinRunTimeMs) | 176 if (time_since_creation > kMinRunTimeMs) |
177 observation_complete_->Set(); | 177 observation_complete_.Set(); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 bool IsTextureSupported() const override { return false; } | 181 bool IsTextureSupported() const override { return false; } |
182 | 182 |
183 private: | 183 private: |
184 Clock* const clock_; | 184 Clock* const clock_; |
185 const int voe_channel_; | 185 const int voe_channel_; |
186 VoEVideoSync* const voe_sync_; | 186 VoEVideoSync* const voe_sync_; |
187 SyncRtcpObserver* const audio_observer_; | 187 SyncRtcpObserver* const audio_observer_; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 327 |
328 CreateFrameGeneratorCapturer(); | 328 CreateFrameGeneratorCapturer(); |
329 | 329 |
330 Start(); | 330 Start(); |
331 | 331 |
332 fake_audio_device.Start(); | 332 fake_audio_device.Start(); |
333 EXPECT_EQ(0, voe_base->StartPlayout(recv_channel_id)); | 333 EXPECT_EQ(0, voe_base->StartPlayout(recv_channel_id)); |
334 EXPECT_EQ(0, voe_base->StartReceive(recv_channel_id)); | 334 EXPECT_EQ(0, voe_base->StartReceive(recv_channel_id)); |
335 EXPECT_EQ(0, voe_base->StartSend(send_channel_id)); | 335 EXPECT_EQ(0, voe_base->StartSend(send_channel_id)); |
336 | 336 |
337 EXPECT_EQ(kEventSignaled, observer.Wait()) | 337 EXPECT_TRUE(observer.Wait()) |
338 << "Timed out while waiting for audio and video to be synchronized."; | 338 << "Timed out while waiting for audio and video to be synchronized."; |
339 | 339 |
340 EXPECT_EQ(0, voe_base->StopSend(send_channel_id)); | 340 EXPECT_EQ(0, voe_base->StopSend(send_channel_id)); |
341 EXPECT_EQ(0, voe_base->StopReceive(recv_channel_id)); | 341 EXPECT_EQ(0, voe_base->StopReceive(recv_channel_id)); |
342 EXPECT_EQ(0, voe_base->StopPlayout(recv_channel_id)); | 342 EXPECT_EQ(0, voe_base->StopPlayout(recv_channel_id)); |
343 fake_audio_device.Stop(); | 343 fake_audio_device.Stop(); |
344 | 344 |
345 Stop(); | 345 Stop(); |
346 sync_send_transport.StopSending(); | 346 sync_send_transport.StopSending(); |
347 sync_receive_transport.StopSending(); | 347 sync_receive_transport.StopSending(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 406 } |
407 | 407 |
408 int64_t now_ms = clock_->TimeInMilliseconds(); | 408 int64_t now_ms = clock_->TimeInMilliseconds(); |
409 int64_t time_since_creation = now_ms - creation_time_ms_; | 409 int64_t time_since_creation = now_ms - creation_time_ms_; |
410 if (time_since_creation < start_time_ms_) { | 410 if (time_since_creation < start_time_ms_) { |
411 // Wait for |start_time_ms_| before start measuring. | 411 // Wait for |start_time_ms_| before start measuring. |
412 return; | 412 return; |
413 } | 413 } |
414 | 414 |
415 if (time_since_creation > run_time_ms_) { | 415 if (time_since_creation > run_time_ms_) { |
416 observation_complete_->Set(); | 416 observation_complete_.Set(); |
417 } | 417 } |
418 | 418 |
419 FrameCaptureTimeList::iterator iter = | 419 FrameCaptureTimeList::iterator iter = |
420 capture_time_list_.find(video_frame.timestamp()); | 420 capture_time_list_.find(video_frame.timestamp()); |
421 EXPECT_TRUE(iter != capture_time_list_.end()); | 421 EXPECT_TRUE(iter != capture_time_list_.end()); |
422 | 422 |
423 // The real capture time has been wrapped to uint32_t before converted | 423 // The real capture time has been wrapped to uint32_t before converted |
424 // to rtp timestamp in the sender side. So here we convert the estimated | 424 // to rtp timestamp in the sender side. So here we convert the estimated |
425 // capture time to a uint32_t 90k timestamp also for comparing. | 425 // capture time to a uint32_t 90k timestamp also for comparing. |
426 uint32_t estimated_capture_timestamp = | 426 uint32_t estimated_capture_timestamp = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 466 |
467 void ModifyConfigs(VideoSendStream::Config* send_config, | 467 void ModifyConfigs(VideoSendStream::Config* send_config, |
468 std::vector<VideoReceiveStream::Config>* receive_configs, | 468 std::vector<VideoReceiveStream::Config>* receive_configs, |
469 VideoEncoderConfig* encoder_config) override { | 469 VideoEncoderConfig* encoder_config) override { |
470 (*receive_configs)[0].renderer = this; | 470 (*receive_configs)[0].renderer = this; |
471 // Enable the receiver side rtt calculation. | 471 // Enable the receiver side rtt calculation. |
472 (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true; | 472 (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true; |
473 } | 473 } |
474 | 474 |
475 void PerformTest() override { | 475 void PerformTest() override { |
476 EXPECT_EQ(kEventSignaled, Wait()) << "Timed out while waiting for " | 476 EXPECT_TRUE(Wait()) << "Timed out while waiting for " |
477 "estimated capture NTP time to be " | 477 "estimated capture NTP time to be " |
478 "within bounds."; | 478 "within bounds."; |
479 } | 479 } |
480 | 480 |
481 rtc::CriticalSection crit_; | 481 rtc::CriticalSection crit_; |
482 Clock* const clock_; | 482 Clock* const clock_; |
483 int threshold_ms_; | 483 int threshold_ms_; |
484 int start_time_ms_; | 484 int start_time_ms_; |
485 int run_time_ms_; | 485 int run_time_ms_; |
486 int64_t creation_time_ms_; | 486 int64_t creation_time_ms_; |
487 test::FrameGeneratorCapturer* capturer_; | 487 test::FrameGeneratorCapturer* capturer_; |
488 bool rtp_start_timestamp_set_; | 488 bool rtp_start_timestamp_set_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 int encode_delay_ms) { | 521 int encode_delay_ms) { |
522 class LoadObserver : public test::SendTest, public webrtc::LoadObserver { | 522 class LoadObserver : public test::SendTest, public webrtc::LoadObserver { |
523 public: | 523 public: |
524 LoadObserver(LoadObserver::Load tested_load, int encode_delay_ms) | 524 LoadObserver(LoadObserver::Load tested_load, int encode_delay_ms) |
525 : SendTest(kLongTimeoutMs), | 525 : SendTest(kLongTimeoutMs), |
526 tested_load_(tested_load), | 526 tested_load_(tested_load), |
527 encoder_(Clock::GetRealTimeClock(), encode_delay_ms) {} | 527 encoder_(Clock::GetRealTimeClock(), encode_delay_ms) {} |
528 | 528 |
529 void OnLoadUpdate(Load load) override { | 529 void OnLoadUpdate(Load load) override { |
530 if (load == tested_load_) | 530 if (load == tested_load_) |
531 observation_complete_->Set(); | 531 observation_complete_.Set(); |
532 } | 532 } |
533 | 533 |
534 void ModifyConfigs(VideoSendStream::Config* send_config, | 534 void ModifyConfigs(VideoSendStream::Config* send_config, |
535 std::vector<VideoReceiveStream::Config>* receive_configs, | 535 std::vector<VideoReceiveStream::Config>* receive_configs, |
536 VideoEncoderConfig* encoder_config) override { | 536 VideoEncoderConfig* encoder_config) override { |
537 send_config->overuse_callback = this; | 537 send_config->overuse_callback = this; |
538 send_config->encoder_settings.encoder = &encoder_; | 538 send_config->encoder_settings.encoder = &encoder_; |
539 } | 539 } |
540 | 540 |
541 void PerformTest() override { | 541 void PerformTest() override { |
542 EXPECT_EQ(kEventSignaled, Wait()) | 542 EXPECT_TRUE(Wait()) << "Timed out before receiving an overuse callback."; |
543 << "Timed out before receiving an overuse callback."; | |
544 } | 543 } |
545 | 544 |
546 LoadObserver::Load tested_load_; | 545 LoadObserver::Load tested_load_; |
547 test::DelayedEncoder encoder_; | 546 test::DelayedEncoder encoder_; |
548 } test(tested_load, encode_delay_ms); | 547 } test(tested_load, encode_delay_ms); |
549 | 548 |
550 RunBaseTest(&test, FakeNetworkPipe::Config()); | 549 RunBaseTest(&test, FakeNetworkPipe::Config()); |
551 } | 550 } |
552 | 551 |
553 TEST_F(CallPerfTest, ReceivesCpuUnderuse) { | 552 TEST_F(CallPerfTest, ReceivesCpuUnderuse) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 // Expect bitrate stats to roughly match the max encode bitrate. | 600 // Expect bitrate stats to roughly match the max encode bitrate. |
602 if (bitrate_kbps > (kMaxEncodeBitrateKbps - | 601 if (bitrate_kbps > (kMaxEncodeBitrateKbps - |
603 kAcceptableBitrateErrorMargin / 2) && | 602 kAcceptableBitrateErrorMargin / 2) && |
604 bitrate_kbps < (kMaxEncodeBitrateKbps + | 603 bitrate_kbps < (kMaxEncodeBitrateKbps + |
605 kAcceptableBitrateErrorMargin / 2)) { | 604 kAcceptableBitrateErrorMargin / 2)) { |
606 ++num_bitrate_observations_in_range_; | 605 ++num_bitrate_observations_in_range_; |
607 } | 606 } |
608 } | 607 } |
609 if (num_bitrate_observations_in_range_ == | 608 if (num_bitrate_observations_in_range_ == |
610 kNumBitrateObservationsInRange) | 609 kNumBitrateObservationsInRange) |
611 observation_complete_->Set(); | 610 observation_complete_.Set(); |
612 } | 611 } |
613 } | 612 } |
614 return SEND_PACKET; | 613 return SEND_PACKET; |
615 } | 614 } |
616 | 615 |
617 void OnStreamsCreated( | 616 void OnStreamsCreated( |
618 VideoSendStream* send_stream, | 617 VideoSendStream* send_stream, |
619 const std::vector<VideoReceiveStream*>& receive_streams) override { | 618 const std::vector<VideoReceiveStream*>& receive_streams) override { |
620 send_stream_ = send_stream; | 619 send_stream_ = send_stream; |
621 } | 620 } |
622 | 621 |
623 void ModifyConfigs(VideoSendStream::Config* send_config, | 622 void ModifyConfigs(VideoSendStream::Config* send_config, |
624 std::vector<VideoReceiveStream::Config>* receive_configs, | 623 std::vector<VideoReceiveStream::Config>* receive_configs, |
625 VideoEncoderConfig* encoder_config) override { | 624 VideoEncoderConfig* encoder_config) override { |
626 if (pad_to_min_bitrate_) { | 625 if (pad_to_min_bitrate_) { |
627 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 626 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
628 } else { | 627 } else { |
629 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); | 628 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps); |
630 } | 629 } |
631 } | 630 } |
632 | 631 |
633 void PerformTest() override { | 632 void PerformTest() override { |
634 EXPECT_EQ(kEventSignaled, Wait()) | 633 EXPECT_TRUE(Wait()) << "Timeout while waiting for send-bitrate stats."; |
635 << "Timeout while waiting for send-bitrate stats."; | |
636 } | 634 } |
637 | 635 |
638 VideoSendStream* send_stream_; | 636 VideoSendStream* send_stream_; |
639 const bool pad_to_min_bitrate_; | 637 const bool pad_to_min_bitrate_; |
640 int num_bitrate_observations_in_range_; | 638 int num_bitrate_observations_in_range_; |
641 } test(pad_to_min_bitrate); | 639 } test(pad_to_min_bitrate); |
642 | 640 |
643 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps); | 641 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps); |
644 RunBaseTest(&test, FakeNetworkPipe::Config()); | 642 RunBaseTest(&test, FakeNetworkPipe::Config()); |
645 } | 643 } |
646 | 644 |
647 TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); } | 645 TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); } |
648 | 646 |
649 TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) { | 647 TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) { |
650 TestMinTransmitBitrate(false); | 648 TestMinTransmitBitrate(false); |
651 } | 649 } |
652 | 650 |
653 TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) { | 651 TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) { |
654 static const uint32_t kInitialBitrateKbps = 400; | 652 static const uint32_t kInitialBitrateKbps = 400; |
655 static const uint32_t kReconfigureThresholdKbps = 600; | 653 static const uint32_t kReconfigureThresholdKbps = 600; |
656 static const uint32_t kPermittedReconfiguredBitrateDiffKbps = 100; | 654 static const uint32_t kPermittedReconfiguredBitrateDiffKbps = 100; |
657 | 655 |
658 class BitrateObserver : public test::EndToEndTest, public test::FakeEncoder { | 656 class BitrateObserver : public test::EndToEndTest, public test::FakeEncoder { |
659 public: | 657 public: |
660 BitrateObserver() | 658 BitrateObserver() |
661 : EndToEndTest(kDefaultTimeoutMs), | 659 : EndToEndTest(kDefaultTimeoutMs), |
662 FakeEncoder(Clock::GetRealTimeClock()), | 660 FakeEncoder(Clock::GetRealTimeClock()), |
663 time_to_reconfigure_(webrtc::EventWrapper::Create()), | 661 time_to_reconfigure_(false, false), |
664 encoder_inits_(0), | 662 encoder_inits_(0), |
665 last_set_bitrate_(0), | 663 last_set_bitrate_(0), |
666 send_stream_(nullptr) {} | 664 send_stream_(nullptr) {} |
667 | 665 |
668 int32_t InitEncode(const VideoCodec* config, | 666 int32_t InitEncode(const VideoCodec* config, |
669 int32_t number_of_cores, | 667 int32_t number_of_cores, |
670 size_t max_payload_size) override { | 668 size_t max_payload_size) override { |
671 if (encoder_inits_ == 0) { | 669 if (encoder_inits_ == 0) { |
672 EXPECT_EQ(kInitialBitrateKbps, config->startBitrate) | 670 EXPECT_EQ(kInitialBitrateKbps, config->startBitrate) |
673 << "Encoder not initialized at expected bitrate."; | 671 << "Encoder not initialized at expected bitrate."; |
674 } | 672 } |
675 ++encoder_inits_; | 673 ++encoder_inits_; |
676 if (encoder_inits_ == 2) { | 674 if (encoder_inits_ == 2) { |
677 EXPECT_GE(last_set_bitrate_, kReconfigureThresholdKbps); | 675 EXPECT_GE(last_set_bitrate_, kReconfigureThresholdKbps); |
678 EXPECT_NEAR(config->startBitrate, | 676 EXPECT_NEAR(config->startBitrate, |
679 last_set_bitrate_, | 677 last_set_bitrate_, |
680 kPermittedReconfiguredBitrateDiffKbps) | 678 kPermittedReconfiguredBitrateDiffKbps) |
681 << "Encoder reconfigured with bitrate too far away from last set."; | 679 << "Encoder reconfigured with bitrate too far away from last set."; |
682 observation_complete_->Set(); | 680 observation_complete_.Set(); |
683 } | 681 } |
684 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 682 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
685 } | 683 } |
686 | 684 |
687 int32_t SetRates(uint32_t new_target_bitrate_kbps, | 685 int32_t SetRates(uint32_t new_target_bitrate_kbps, |
688 uint32_t framerate) override { | 686 uint32_t framerate) override { |
689 last_set_bitrate_ = new_target_bitrate_kbps; | 687 last_set_bitrate_ = new_target_bitrate_kbps; |
690 if (encoder_inits_ == 1 && | 688 if (encoder_inits_ == 1 && |
691 new_target_bitrate_kbps > kReconfigureThresholdKbps) { | 689 new_target_bitrate_kbps > kReconfigureThresholdKbps) { |
692 time_to_reconfigure_->Set(); | 690 time_to_reconfigure_.Set(); |
693 } | 691 } |
694 return FakeEncoder::SetRates(new_target_bitrate_kbps, framerate); | 692 return FakeEncoder::SetRates(new_target_bitrate_kbps, framerate); |
695 } | 693 } |
696 | 694 |
697 Call::Config GetSenderCallConfig() override { | 695 Call::Config GetSenderCallConfig() override { |
698 Call::Config config = EndToEndTest::GetSenderCallConfig(); | 696 Call::Config config = EndToEndTest::GetSenderCallConfig(); |
699 config.bitrate_config.start_bitrate_bps = kInitialBitrateKbps * 1000; | 697 config.bitrate_config.start_bitrate_bps = kInitialBitrateKbps * 1000; |
700 return config; | 698 return config; |
701 } | 699 } |
702 | 700 |
703 void ModifyConfigs(VideoSendStream::Config* send_config, | 701 void ModifyConfigs(VideoSendStream::Config* send_config, |
704 std::vector<VideoReceiveStream::Config>* receive_configs, | 702 std::vector<VideoReceiveStream::Config>* receive_configs, |
705 VideoEncoderConfig* encoder_config) override { | 703 VideoEncoderConfig* encoder_config) override { |
706 send_config->encoder_settings.encoder = this; | 704 send_config->encoder_settings.encoder = this; |
707 encoder_config->streams[0].min_bitrate_bps = 50000; | 705 encoder_config->streams[0].min_bitrate_bps = 50000; |
708 encoder_config->streams[0].target_bitrate_bps = | 706 encoder_config->streams[0].target_bitrate_bps = |
709 encoder_config->streams[0].max_bitrate_bps = 2000000; | 707 encoder_config->streams[0].max_bitrate_bps = 2000000; |
710 | 708 |
711 encoder_config_ = *encoder_config; | 709 encoder_config_ = *encoder_config; |
712 } | 710 } |
713 | 711 |
714 void OnStreamsCreated( | 712 void OnStreamsCreated( |
715 VideoSendStream* send_stream, | 713 VideoSendStream* send_stream, |
716 const std::vector<VideoReceiveStream*>& receive_streams) override { | 714 const std::vector<VideoReceiveStream*>& receive_streams) override { |
717 send_stream_ = send_stream; | 715 send_stream_ = send_stream; |
718 } | 716 } |
719 | 717 |
720 void PerformTest() override { | 718 void PerformTest() override { |
721 ASSERT_EQ(kEventSignaled, time_to_reconfigure_->Wait(kDefaultTimeoutMs)) | 719 ASSERT_TRUE(time_to_reconfigure_.Wait(kDefaultTimeoutMs)) |
722 << "Timed out before receiving an initial high bitrate."; | 720 << "Timed out before receiving an initial high bitrate."; |
723 encoder_config_.streams[0].width *= 2; | 721 encoder_config_.streams[0].width *= 2; |
724 encoder_config_.streams[0].height *= 2; | 722 encoder_config_.streams[0].height *= 2; |
725 EXPECT_TRUE(send_stream_->ReconfigureVideoEncoder(encoder_config_)); | 723 EXPECT_TRUE(send_stream_->ReconfigureVideoEncoder(encoder_config_)); |
726 EXPECT_EQ(kEventSignaled, Wait()) | 724 EXPECT_TRUE(Wait()) |
727 << "Timed out while waiting for a couple of high bitrate estimates " | 725 << "Timed out while waiting for a couple of high bitrate estimates " |
728 "after reconfiguring the send stream."; | 726 "after reconfiguring the send stream."; |
729 } | 727 } |
730 | 728 |
731 private: | 729 private: |
732 rtc::scoped_ptr<webrtc::EventWrapper> time_to_reconfigure_; | 730 rtc::Event time_to_reconfigure_; |
733 int encoder_inits_; | 731 int encoder_inits_; |
734 uint32_t last_set_bitrate_; | 732 uint32_t last_set_bitrate_; |
735 VideoSendStream* send_stream_; | 733 VideoSendStream* send_stream_; |
736 VideoEncoderConfig encoder_config_; | 734 VideoEncoderConfig encoder_config_; |
737 } test; | 735 } test; |
738 | 736 |
739 RunBaseTest(&test, FakeNetworkPipe::Config()); | 737 RunBaseTest(&test, FakeNetworkPipe::Config()); |
740 } | 738 } |
741 | 739 |
742 } // namespace webrtc | 740 } // namespace webrtc |
OLD | NEW |