Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 20 matching lines...) Expand all Loading... | |
| 31 #endif | 31 #endif |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace webrtc { | 34 namespace webrtc { |
| 35 | 35 |
| 36 using DegredationPreference = VideoSendStream::DegradationPreference; | 36 using DegredationPreference = VideoSendStream::DegradationPreference; |
| 37 using ScaleReason = ScalingObserverInterface::ScaleReason; | 37 using ScaleReason = ScalingObserverInterface::ScaleReason; |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 const size_t kMaxPayloadLength = 1440; | 40 const size_t kMaxPayloadLength = 1440; |
| 41 const int kTargetBitrateBps = 100000; | 41 const int kTargetBitrateBps = 1000000; |
| 42 | 42 |
| 43 class TestBuffer : public webrtc::I420Buffer { | 43 class TestBuffer : public webrtc::I420Buffer { |
| 44 public: | 44 public: |
| 45 TestBuffer(rtc::Event* event, int width, int height) | 45 TestBuffer(rtc::Event* event, int width, int height) |
| 46 : I420Buffer(width, height), event_(event) {} | 46 : I420Buffer(width, height), event_(event) {} |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 friend class rtc::RefCountedObject<TestBuffer>; | 49 friend class rtc::RefCountedObject<TestBuffer>; |
| 50 ~TestBuffer() override { | 50 ~TestBuffer() override { |
| 51 if (event_) | 51 if (event_) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 137 |
| 138 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, | 138 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
| 139 bool nack_enabled) { | 139 bool nack_enabled) { |
| 140 if (vie_encoder_) | 140 if (vie_encoder_) |
| 141 vie_encoder_->Stop(); | 141 vie_encoder_->Stop(); |
| 142 vie_encoder_.reset(new ViEEncoderUnderTest( | 142 vie_encoder_.reset(new ViEEncoderUnderTest( |
| 143 stats_proxy_.get(), video_send_config_.encoder_settings)); | 143 stats_proxy_.get(), video_send_config_.encoder_settings)); |
| 144 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 144 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
| 145 vie_encoder_->SetSource(&video_source_, | 145 vie_encoder_->SetSource(&video_source_, |
| 146 VideoSendStream::DegradationPreference::kBalanced); | 146 VideoSendStream::DegradationPreference::kBalanced); |
| 147 vie_encoder_->SetStartBitrate(10000); | 147 vie_encoder_->SetStartBitrate(kTargetBitrateBps); |
| 148 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 148 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 149 kMaxPayloadLength, nack_enabled); | 149 kMaxPayloadLength, nack_enabled); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void ResetEncoder(const std::string& payload_name, | 152 void ResetEncoder(const std::string& payload_name, |
| 153 size_t num_streams, | 153 size_t num_streams, |
| 154 size_t num_temporal_layers, | 154 size_t num_temporal_layers, |
| 155 bool nack_enabled) { | 155 bool nack_enabled) { |
| 156 video_send_config_.encoder_settings.payload_name = payload_name; | 156 video_send_config_.encoder_settings.payload_name = payload_name; |
| 157 | 157 |
| 158 VideoEncoderConfig video_encoder_config; | 158 VideoEncoderConfig video_encoder_config; |
| 159 video_encoder_config.number_of_streams = num_streams; | 159 video_encoder_config.number_of_streams = num_streams; |
| 160 video_encoder_config.max_bitrate_bps = 1000000; | 160 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
| 161 video_encoder_config.video_stream_factory = | 161 video_encoder_config.video_stream_factory = |
| 162 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); | 162 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); |
| 163 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); | 163 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
| 164 } | 164 } |
| 165 | 165 |
| 166 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { | 166 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { |
| 167 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 167 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
| 168 destruction_event, codec_width_, codec_height_), | 168 destruction_event, codec_width_, codec_height_), |
| 169 99, 99, kVideoRotation_0); | 169 99, 99, kVideoRotation_0); |
| 170 frame.set_ntp_time_ms(ntp_ts); | 170 frame.set_ntp_time_ms(ntp_ts); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 sink_.WaitForEncodedFrame(3); | 666 sink_.WaitForEncodedFrame(3); |
| 667 | 667 |
| 668 stats = stats_proxy_->GetStats(); | 668 stats = stats_proxy_->GetStats(); |
| 669 EXPECT_FALSE(stats.cpu_limited_resolution); | 669 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 670 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 670 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 671 | 671 |
| 672 vie_encoder_->Stop(); | 672 vie_encoder_->Stop(); |
| 673 } | 673 } |
| 674 | 674 |
| 675 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { | 675 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { |
| 676 const int kTargetBitrateBps = 100000; | |
| 677 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 676 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 678 | 677 |
| 679 int frame_width = 1280; | 678 int frame_width = 1280; |
| 680 int frame_height = 720; | 679 int frame_height = 720; |
| 681 video_source_.IncomingCapturedFrame( | 680 video_source_.IncomingCapturedFrame( |
| 682 CreateFrame(1, frame_width, frame_height)); | 681 CreateFrame(1, frame_width, frame_height)); |
| 683 sink_.WaitForEncodedFrame(1); | 682 sink_.WaitForEncodedFrame(1); |
| 684 | 683 |
| 685 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 684 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 686 EXPECT_FALSE(stats.cpu_limited_resolution); | 685 EXPECT_FALSE(stats.cpu_limited_resolution); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 CreateFrame(6, frame_width, frame_height)); | 735 CreateFrame(6, frame_width, frame_height)); |
| 737 sink_.WaitForEncodedFrame(6); | 736 sink_.WaitForEncodedFrame(6); |
| 738 stats = stats_proxy_->GetStats(); | 737 stats = stats_proxy_->GetStats(); |
| 739 EXPECT_FALSE(stats.cpu_limited_resolution); | 738 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 740 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 739 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 741 | 740 |
| 742 vie_encoder_->Stop(); | 741 vie_encoder_->Stop(); |
| 743 } | 742 } |
| 744 | 743 |
| 745 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 744 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
| 746 const int kTargetBitrateBps = 100000; | |
| 747 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 745 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 748 | 746 |
| 749 int frame_width = 1280; | 747 int frame_width = 1280; |
| 750 int frame_height = 720; | 748 int frame_height = 720; |
| 751 video_source_.IncomingCapturedFrame( | 749 video_source_.IncomingCapturedFrame( |
| 752 CreateFrame(1, frame_width, frame_height)); | 750 CreateFrame(1, frame_width, frame_height)); |
| 753 sink_.WaitForEncodedFrame(1); | 751 sink_.WaitForEncodedFrame(1); |
| 754 | 752 |
| 755 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 753 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 756 EXPECT_FALSE(stats.cpu_limited_resolution); | 754 EXPECT_FALSE(stats.cpu_limited_resolution); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 sink_.WaitForEncodedFrame(1); | 870 sink_.WaitForEncodedFrame(1); |
| 873 | 871 |
| 874 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 872 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 875 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 873 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
| 876 stats.preferred_media_bitrate_bps); | 874 stats.preferred_media_bitrate_bps); |
| 877 | 875 |
| 878 vie_encoder_->Stop(); | 876 vie_encoder_->Stop(); |
| 879 } | 877 } |
| 880 | 878 |
| 881 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 879 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
| 882 const int kTargetBitrateBps = 100000; | |
| 883 int frame_width = 1280; | 880 int frame_width = 1280; |
| 884 int frame_height = 720; | 881 int frame_height = 720; |
| 885 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 882 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 886 | 883 |
| 887 // Expect no scaling to begin with | 884 // Expect no scaling to begin with |
| 888 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | 885 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 889 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); | 886 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
| 890 | 887 |
| 891 video_source_.IncomingCapturedFrame( | 888 video_source_.IncomingCapturedFrame( |
| 892 CreateFrame(1, frame_width, frame_height)); | 889 CreateFrame(1, frame_width, frame_height)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 CreateFrame(4, frame_width, frame_height)); | 922 CreateFrame(4, frame_width, frame_height)); |
| 926 sink_.WaitForEncodedFrame(4); | 923 sink_.WaitForEncodedFrame(4); |
| 927 | 924 |
| 928 // Expect nothing to change, still no scaling | 925 // Expect nothing to change, still no scaling |
| 929 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 926 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 930 | 927 |
| 931 vie_encoder_->Stop(); | 928 vie_encoder_->Stop(); |
| 932 } | 929 } |
| 933 | 930 |
| 934 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { | 931 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { |
| 935 const int kTargetBitrateBps = 100000; | |
| 936 int frame_width = 1280; | 932 int frame_width = 1280; |
| 937 int frame_height = 720; | 933 int frame_height = 720; |
| 938 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 934 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 939 | 935 |
| 940 for (size_t i = 1; i <= 10; i++) { | 936 for (size_t i = 1; i <= 10; i++) { |
| 941 video_source_.IncomingCapturedFrame( | 937 video_source_.IncomingCapturedFrame( |
| 942 CreateFrame(i, frame_width, frame_height)); | 938 CreateFrame(i, frame_width, frame_height)); |
| 943 sink_.WaitForEncodedFrame(i); | 939 sink_.WaitForEncodedFrame(i); |
| 944 // Trigger scale down | 940 // Trigger scale down |
| 945 vie_encoder_->TriggerQualityLow(); | 941 vie_encoder_->TriggerQualityLow(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 972 | 968 |
| 973 vie_encoder_->Stop(); | 969 vie_encoder_->Stop(); |
| 974 | 970 |
| 975 stats_proxy_.reset(); | 971 stats_proxy_.reset(); |
| 976 EXPECT_EQ(1, | 972 EXPECT_EQ(1, |
| 977 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 973 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
| 978 EXPECT_EQ( | 974 EXPECT_EQ( |
| 979 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 975 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
| 980 } | 976 } |
| 981 | 977 |
| 978 TEST_F(ViEEncoderTest, DropsFramesUntilTartgetBitrateIsReached) { | |
| 979 vie_encoder_->OnBitrateUpdated(100000, 0, 0); | |
| 980 int frame_width = 1000; | |
| 981 int frame_height = 1000; | |
| 982 int dropped_frames = 0; | |
| 983 | |
| 984 rtc::Event ev(false, false); | |
| 985 for (int i = 1; i <= 10; ++i) { | |
| 986 video_source_.IncomingCapturedFrame( | |
| 987 CreateFrame(i, frame_width, frame_height)); | |
| 988 // Don't wait for the dropped frames. | |
| 989 ev.Wait(10); | |
| 990 if (*video_source_.sink_wants().max_pixel_count < | |
| 991 frame_width * frame_height) | |
| 992 dropped_frames++; | |
|
sprang_webrtc
2017/01/16 16:48:35
nit: {} for multi-line if
| |
| 993 frame_width = frame_height = | |
| 994 std::sqrt(*video_source_.sink_wants().max_pixel_count); | |
| 995 } | |
| 996 sink_.WaitForEncodedFrame(10); | |
|
perkj_webrtc
2017/01/17 08:53:10
So you only expect one frame to be encoded.
Can y
kthelgason
2017/01/18 09:16:16
Good comments, thanks. I added some more thorough
| |
| 997 EXPECT_GT(dropped_frames, 0); | |
| 998 | |
| 999 // Expect the sink_wants to specify a scaled frame. | |
| 1000 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | |
| 1001 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); | |
| 1002 | |
| 1003 const auto stats = stats_proxy_->GetStats(); | |
| 1004 EXPECT_FALSE(stats.cpu_limited_resolution); | |
| 1005 EXPECT_TRUE(stats.bw_limited_resolution); | |
| 1006 | |
| 1007 vie_encoder_->Stop(); | |
| 1008 } | |
| 1009 | |
| 982 } // namespace webrtc | 1010 } // namespace webrtc |
| OLD | NEW |