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 | 10 |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 time_to_reconfigure_(false, false), | 641 time_to_reconfigure_(false, false), |
642 encoder_inits_(0), | 642 encoder_inits_(0), |
643 last_set_bitrate_(0), | 643 last_set_bitrate_(0), |
644 send_stream_(nullptr) {} | 644 send_stream_(nullptr) {} |
645 | 645 |
646 int32_t InitEncode(const VideoCodec* config, | 646 int32_t InitEncode(const VideoCodec* config, |
647 int32_t number_of_cores, | 647 int32_t number_of_cores, |
648 size_t max_payload_size) override { | 648 size_t max_payload_size) override { |
649 ++encoder_inits_; | 649 ++encoder_inits_; |
650 if (encoder_inits_ == 1) { | 650 if (encoder_inits_ == 1) { |
651 // First time initialization. Frame size is not known. | 651 // First time initialization. Frame size is known. |
652 EXPECT_EQ(kInitialBitrateKbps, config->startBitrate) | 652 // |expected_bitrate| is affected by bandwidth estimation before the |
| 653 // first frame arrives to the encoder. |
| 654 uint32_t expected_bitrate = |
| 655 last_set_bitrate_ > 0 ? last_set_bitrate_ : kInitialBitrateKbps; |
| 656 EXPECT_EQ(expected_bitrate, config->startBitrate) |
653 << "Encoder not initialized at expected bitrate."; | 657 << "Encoder not initialized at expected bitrate."; |
654 } else if (encoder_inits_ == 2) { | |
655 // First time initialization. Frame size is known. | |
656 EXPECT_EQ(kDefaultWidth, config->width); | 658 EXPECT_EQ(kDefaultWidth, config->width); |
657 EXPECT_EQ(kDefaultHeight, config->height); | 659 EXPECT_EQ(kDefaultHeight, config->height); |
658 } else if (encoder_inits_ == 3) { | 660 } else if (encoder_inits_ == 2) { |
659 EXPECT_EQ(2 * kDefaultWidth, config->width); | 661 EXPECT_EQ(2 * kDefaultWidth, config->width); |
660 EXPECT_EQ(2 * kDefaultHeight, config->height); | 662 EXPECT_EQ(2 * kDefaultHeight, config->height); |
661 EXPECT_GE(last_set_bitrate_, kReconfigureThresholdKbps); | 663 EXPECT_GE(last_set_bitrate_, kReconfigureThresholdKbps); |
662 EXPECT_NEAR(config->startBitrate, | 664 EXPECT_NEAR(config->startBitrate, |
663 last_set_bitrate_, | 665 last_set_bitrate_, |
664 kPermittedReconfiguredBitrateDiffKbps) | 666 kPermittedReconfiguredBitrateDiffKbps) |
665 << "Encoder reconfigured with bitrate too far away from last set."; | 667 << "Encoder reconfigured with bitrate too far away from last set."; |
666 observation_complete_.Set(); | 668 observation_complete_.Set(); |
667 } | 669 } |
668 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 670 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
669 } | 671 } |
670 | 672 |
671 int32_t SetRates(uint32_t new_target_bitrate_kbps, | 673 int32_t SetRates(uint32_t new_target_bitrate_kbps, |
672 uint32_t framerate) override { | 674 uint32_t framerate) override { |
673 last_set_bitrate_ = new_target_bitrate_kbps; | 675 last_set_bitrate_ = new_target_bitrate_kbps; |
674 if (encoder_inits_ == 2 && | 676 if (encoder_inits_ == 1 && |
675 new_target_bitrate_kbps > kReconfigureThresholdKbps) { | 677 new_target_bitrate_kbps > kReconfigureThresholdKbps) { |
676 time_to_reconfigure_.Set(); | 678 time_to_reconfigure_.Set(); |
677 } | 679 } |
678 return FakeEncoder::SetRates(new_target_bitrate_kbps, framerate); | 680 return FakeEncoder::SetRates(new_target_bitrate_kbps, framerate); |
679 } | 681 } |
680 | 682 |
681 Call::Config GetSenderCallConfig() override { | 683 Call::Config GetSenderCallConfig() override { |
682 Call::Config config = EndToEndTest::GetSenderCallConfig(); | 684 Call::Config config = EndToEndTest::GetSenderCallConfig(); |
683 config.event_log = &event_log_; | 685 config.event_log = &event_log_; |
684 config.bitrate_config.start_bitrate_bps = kInitialBitrateKbps * 1000; | 686 config.bitrate_config.start_bitrate_bps = kInitialBitrateKbps * 1000; |
685 return config; | 687 return config; |
686 } | 688 } |
687 | 689 |
688 void ModifyVideoConfigs( | 690 void ModifyVideoConfigs( |
689 VideoSendStream::Config* send_config, | 691 VideoSendStream::Config* send_config, |
690 std::vector<VideoReceiveStream::Config>* receive_configs, | 692 std::vector<VideoReceiveStream::Config>* receive_configs, |
691 VideoEncoderConfig* encoder_config) override { | 693 VideoEncoderConfig* encoder_config) override { |
692 send_config->encoder_settings.encoder = this; | 694 send_config->encoder_settings.encoder = this; |
| 695 encoder_config->max_bitrate_bps = 2 * kReconfigureThresholdKbps * 1000; |
693 encoder_config->video_stream_factory = | 696 encoder_config->video_stream_factory = |
694 new rtc::RefCountedObject<VideoStreamFactory>(); | 697 new rtc::RefCountedObject<VideoStreamFactory>(); |
695 | 698 |
696 encoder_config_ = encoder_config->Copy(); | 699 encoder_config_ = encoder_config->Copy(); |
697 } | 700 } |
698 | 701 |
699 void OnVideoStreamsCreated( | 702 void OnVideoStreamsCreated( |
700 VideoSendStream* send_stream, | 703 VideoSendStream* send_stream, |
701 const std::vector<VideoReceiveStream*>& receive_streams) override { | 704 const std::vector<VideoReceiveStream*>& receive_streams) override { |
702 send_stream_ = send_stream; | 705 send_stream_ = send_stream; |
(...skipping 20 matching lines...) Expand all Loading... |
723 uint32_t last_set_bitrate_; | 726 uint32_t last_set_bitrate_; |
724 VideoSendStream* send_stream_; | 727 VideoSendStream* send_stream_; |
725 test::FrameGeneratorCapturer* frame_generator_; | 728 test::FrameGeneratorCapturer* frame_generator_; |
726 VideoEncoderConfig encoder_config_; | 729 VideoEncoderConfig encoder_config_; |
727 } test; | 730 } test; |
728 | 731 |
729 RunBaseTest(&test); | 732 RunBaseTest(&test); |
730 } | 733 } |
731 | 734 |
732 } // namespace webrtc | 735 } // namespace webrtc |
OLD | NEW |