| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 namespace webrtc { | 38 namespace webrtc { |
| 39 | 39 |
| 40 using DegredationPreference = VideoSendStream::DegradationPreference; | 40 using DegredationPreference = VideoSendStream::DegradationPreference; |
| 41 using ScaleReason = AdaptationObserverInterface::AdaptReason; | 41 using ScaleReason = AdaptationObserverInterface::AdaptReason; |
| 42 using ::testing::_; | 42 using ::testing::_; |
| 43 using ::testing::Return; | 43 using ::testing::Return; |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 const size_t kMaxPayloadLength = 1440; | 46 const size_t kMaxPayloadLength = 1440; |
| 47 const int kTargetBitrateBps = 100000; | 47 const int kTargetBitrateBps = 1000000; |
| 48 const int kLowTargetBitrateBps = kTargetBitrateBps / 10; |
| 49 const int kMaxInitialFramedrop = 4; |
| 48 | 50 |
| 49 class TestBuffer : public webrtc::I420Buffer { | 51 class TestBuffer : public webrtc::I420Buffer { |
| 50 public: | 52 public: |
| 51 TestBuffer(rtc::Event* event, int width, int height) | 53 TestBuffer(rtc::Event* event, int width, int height) |
| 52 : I420Buffer(width, height), event_(event) {} | 54 : I420Buffer(width, height), event_(event) {} |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 friend class rtc::RefCountedObject<TestBuffer>; | 57 friend class rtc::RefCountedObject<TestBuffer>; |
| 56 ~TestBuffer() override { | 58 ~TestBuffer() override { |
| 57 if (event_) | 59 if (event_) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 191 |
| 190 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, | 192 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
| 191 bool nack_enabled) { | 193 bool nack_enabled) { |
| 192 if (vie_encoder_) | 194 if (vie_encoder_) |
| 193 vie_encoder_->Stop(); | 195 vie_encoder_->Stop(); |
| 194 vie_encoder_.reset(new ViEEncoderUnderTest( | 196 vie_encoder_.reset(new ViEEncoderUnderTest( |
| 195 stats_proxy_.get(), video_send_config_.encoder_settings)); | 197 stats_proxy_.get(), video_send_config_.encoder_settings)); |
| 196 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 198 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
| 197 vie_encoder_->SetSource(&video_source_, | 199 vie_encoder_->SetSource(&video_source_, |
| 198 VideoSendStream::DegradationPreference::kBalanced); | 200 VideoSendStream::DegradationPreference::kBalanced); |
| 199 vie_encoder_->SetStartBitrate(10000); | 201 vie_encoder_->SetStartBitrate(kTargetBitrateBps); |
| 200 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 202 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 201 kMaxPayloadLength, nack_enabled); | 203 kMaxPayloadLength, nack_enabled); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void ResetEncoder(const std::string& payload_name, | 206 void ResetEncoder(const std::string& payload_name, |
| 205 size_t num_streams, | 207 size_t num_streams, |
| 206 size_t num_temporal_layers, | 208 size_t num_temporal_layers, |
| 207 bool nack_enabled) { | 209 bool nack_enabled) { |
| 208 video_send_config_.encoder_settings.payload_name = payload_name; | 210 video_send_config_.encoder_settings.payload_name = payload_name; |
| 209 | 211 |
| 210 VideoEncoderConfig video_encoder_config; | 212 VideoEncoderConfig video_encoder_config; |
| 211 video_encoder_config.number_of_streams = num_streams; | 213 video_encoder_config.number_of_streams = num_streams; |
| 212 video_encoder_config.max_bitrate_bps = 1000000; | 214 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
| 213 video_encoder_config.video_stream_factory = | 215 video_encoder_config.video_stream_factory = |
| 214 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); | 216 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); |
| 215 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); | 217 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
| 216 } | 218 } |
| 217 | 219 |
| 218 VideoFrame CreateFrame(int64_t ntp_time_ms, | 220 VideoFrame CreateFrame(int64_t ntp_time_ms, |
| 219 rtc::Event* destruction_event) const { | 221 rtc::Event* destruction_event) const { |
| 220 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 222 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
| 221 destruction_event, codec_width_, codec_height_), | 223 destruction_event, codec_width_, codec_height_), |
| 222 99, 99, kVideoRotation_0); | 224 99, 99, kVideoRotation_0); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 319 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
| 318 { | 320 { |
| 319 rtc::CritScope lock(&crit_); | 321 rtc::CritScope lock(&crit_); |
| 320 width = last_width_; | 322 width = last_width_; |
| 321 height = last_height_; | 323 height = last_height_; |
| 322 } | 324 } |
| 323 EXPECT_EQ(expected_height, height); | 325 EXPECT_EQ(expected_height, height); |
| 324 EXPECT_EQ(expected_width, width); | 326 EXPECT_EQ(expected_width, width); |
| 325 } | 327 } |
| 326 | 328 |
| 329 void ExpectDroppedFrame() { EXPECT_FALSE(encoded_frame_event_.Wait(20)); } |
| 330 |
| 327 void SetExpectNoFrames() { | 331 void SetExpectNoFrames() { |
| 328 rtc::CritScope lock(&crit_); | 332 rtc::CritScope lock(&crit_); |
| 329 expect_frames_ = false; | 333 expect_frames_ = false; |
| 330 } | 334 } |
| 331 | 335 |
| 332 int number_of_reconfigurations() { | 336 int number_of_reconfigurations() { |
| 333 rtc::CritScope lock(&crit_); | 337 rtc::CritScope lock(&crit_); |
| 334 return number_of_reconfigurations_; | 338 return number_of_reconfigurations_; |
| 335 } | 339 } |
| 336 | 340 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 sink_.WaitForEncodedFrame(3); | 741 sink_.WaitForEncodedFrame(3); |
| 738 | 742 |
| 739 stats = stats_proxy_->GetStats(); | 743 stats = stats_proxy_->GetStats(); |
| 740 EXPECT_FALSE(stats.cpu_limited_resolution); | 744 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 741 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 745 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 742 | 746 |
| 743 vie_encoder_->Stop(); | 747 vie_encoder_->Stop(); |
| 744 } | 748 } |
| 745 | 749 |
| 746 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { | 750 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { |
| 747 const int kTargetBitrateBps = 100000; | |
| 748 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 751 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 749 | 752 |
| 750 int frame_width = 1280; | 753 int frame_width = 1280; |
| 751 int frame_height = 720; | 754 int frame_height = 720; |
| 752 video_source_.IncomingCapturedFrame( | 755 video_source_.IncomingCapturedFrame( |
| 753 CreateFrame(1, frame_width, frame_height)); | 756 CreateFrame(1, frame_width, frame_height)); |
| 754 sink_.WaitForEncodedFrame(1); | 757 sink_.WaitForEncodedFrame(1); |
| 755 | 758 |
| 756 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 759 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 757 EXPECT_FALSE(stats.cpu_limited_resolution); | 760 EXPECT_FALSE(stats.cpu_limited_resolution); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 CreateFrame(6, frame_width, frame_height)); | 810 CreateFrame(6, frame_width, frame_height)); |
| 808 sink_.WaitForEncodedFrame(6); | 811 sink_.WaitForEncodedFrame(6); |
| 809 stats = stats_proxy_->GetStats(); | 812 stats = stats_proxy_->GetStats(); |
| 810 EXPECT_FALSE(stats.cpu_limited_resolution); | 813 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 811 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 814 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 812 | 815 |
| 813 vie_encoder_->Stop(); | 816 vie_encoder_->Stop(); |
| 814 } | 817 } |
| 815 | 818 |
| 816 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 819 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
| 817 const int kTargetBitrateBps = 100000; | |
| 818 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 820 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 819 | 821 |
| 820 int frame_width = 1280; | 822 int frame_width = 1280; |
| 821 int frame_height = 720; | 823 int frame_height = 720; |
| 822 video_source_.IncomingCapturedFrame( | 824 video_source_.IncomingCapturedFrame( |
| 823 CreateFrame(1, frame_width, frame_height)); | 825 CreateFrame(1, frame_width, frame_height)); |
| 824 sink_.WaitForEncodedFrame(1); | 826 sink_.WaitForEncodedFrame(1); |
| 825 | 827 |
| 826 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 828 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 827 EXPECT_FALSE(stats.cpu_limited_resolution); | 829 EXPECT_FALSE(stats.cpu_limited_resolution); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 sink_.WaitForEncodedFrame(1); | 945 sink_.WaitForEncodedFrame(1); |
| 944 | 946 |
| 945 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 947 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 946 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 948 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
| 947 stats.preferred_media_bitrate_bps); | 949 stats.preferred_media_bitrate_bps); |
| 948 | 950 |
| 949 vie_encoder_->Stop(); | 951 vie_encoder_->Stop(); |
| 950 } | 952 } |
| 951 | 953 |
| 952 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 954 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
| 953 const int kTargetBitrateBps = 100000; | |
| 954 int frame_width = 1280; | 955 int frame_width = 1280; |
| 955 int frame_height = 720; | 956 int frame_height = 720; |
| 956 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 957 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 957 | 958 |
| 958 // Expect no scaling to begin with | 959 // Expect no scaling to begin with |
| 959 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | 960 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 960 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); | 961 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
| 961 | 962 |
| 962 video_source_.IncomingCapturedFrame( | 963 video_source_.IncomingCapturedFrame( |
| 963 CreateFrame(1, frame_width, frame_height)); | 964 CreateFrame(1, frame_width, frame_height)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 CreateFrame(4, frame_width, frame_height)); | 997 CreateFrame(4, frame_width, frame_height)); |
| 997 sink_.WaitForEncodedFrame(4); | 998 sink_.WaitForEncodedFrame(4); |
| 998 | 999 |
| 999 // Expect nothing to change, still no scaling | 1000 // Expect nothing to change, still no scaling |
| 1000 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); | 1001 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 1001 | 1002 |
| 1002 vie_encoder_->Stop(); | 1003 vie_encoder_->Stop(); |
| 1003 } | 1004 } |
| 1004 | 1005 |
| 1005 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { | 1006 TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { |
| 1006 const int kTargetBitrateBps = 100000; | |
| 1007 int frame_width = 1280; | 1007 int frame_width = 1280; |
| 1008 int frame_height = 720; | 1008 int frame_height = 720; |
| 1009 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1009 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1010 | 1010 |
| 1011 for (size_t i = 1; i <= 10; i++) { | 1011 for (size_t i = 1; i <= 10; i++) { |
| 1012 video_source_.IncomingCapturedFrame( | 1012 video_source_.IncomingCapturedFrame( |
| 1013 CreateFrame(i, frame_width, frame_height)); | 1013 CreateFrame(i, frame_width, frame_height)); |
| 1014 sink_.WaitForEncodedFrame(i); | 1014 sink_.WaitForEncodedFrame(i); |
| 1015 // Trigger scale down | 1015 // Trigger scale down |
| 1016 vie_encoder_->TriggerQualityLow(); | 1016 vie_encoder_->TriggerQualityLow(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 TEST_F(ViEEncoderTest, CallsBitrateObserver) { | 1053 TEST_F(ViEEncoderTest, CallsBitrateObserver) { |
| 1054 class MockBitrateObserver : public VideoBitrateAllocationObserver { | 1054 class MockBitrateObserver : public VideoBitrateAllocationObserver { |
| 1055 public: | 1055 public: |
| 1056 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); | 1056 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); |
| 1057 } bitrate_observer; | 1057 } bitrate_observer; |
| 1058 vie_encoder_->SetBitrateObserver(&bitrate_observer); | 1058 vie_encoder_->SetBitrateObserver(&bitrate_observer); |
| 1059 | 1059 |
| 1060 const int kDefaultFps = 30; | 1060 const int kDefaultFps = 30; |
| 1061 const BitrateAllocation expected_bitrate = | 1061 const BitrateAllocation expected_bitrate = |
| 1062 DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) | 1062 DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) |
| 1063 .GetAllocation(kTargetBitrateBps, kDefaultFps); | 1063 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); |
| 1064 | 1064 |
| 1065 // First called on bitrate updated, then again on first frame. | 1065 // First called on bitrate updated, then again on first frame. |
| 1066 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1066 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
| 1067 .Times(2); | 1067 .Times(2); |
| 1068 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1068 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 1069 | 1069 |
| 1070 const int64_t kStartTimeMs = 1; | 1070 const int64_t kStartTimeMs = 1; |
| 1071 video_source_.IncomingCapturedFrame( | 1071 video_source_.IncomingCapturedFrame( |
| 1072 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); | 1072 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); |
| 1073 sink_.WaitForEncodedFrame(kStartTimeMs); | 1073 sink_.WaitForEncodedFrame(kStartTimeMs); |
| 1074 | 1074 |
| 1075 // Not called on second frame. | 1075 // Not called on second frame. |
| 1076 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1076 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
| 1077 .Times(0); | 1077 .Times(0); |
| 1078 video_source_.IncomingCapturedFrame( | 1078 video_source_.IncomingCapturedFrame( |
| 1079 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); | 1079 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); |
| 1080 sink_.WaitForEncodedFrame(kStartTimeMs + 1); | 1080 sink_.WaitForEncodedFrame(kStartTimeMs + 1); |
| 1081 | 1081 |
| 1082 // Called after a process interval. | 1082 // Called after a process interval. |
| 1083 const int64_t kProcessIntervalMs = | 1083 const int64_t kProcessIntervalMs = |
| 1084 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; | 1084 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
| 1085 // TODO(sprang): ViEEncoder should die and/or get injectable clock. | 1085 // TODO(sprang): ViEEncoder should die and/or get injectable clock. |
| 1086 // Sleep for one processing interval plus one frame to avoid flakiness. | 1086 // Sleep for one processing interval plus one frame to avoid flakiness. |
| 1087 SleepMs(kProcessIntervalMs + 1000 / kDefaultFps); | 1087 SleepMs(kProcessIntervalMs + 1000 / kDefaultFps); |
| 1088 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1088 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
| 1089 .Times(1); | 1089 .Times(1); |
| 1090 video_source_.IncomingCapturedFrame(CreateFrame( | 1090 video_source_.IncomingCapturedFrame(CreateFrame( |
| 1091 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); | 1091 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); |
| 1092 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); | 1092 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
| 1093 | 1093 |
| 1094 vie_encoder_->Stop(); | 1094 vie_encoder_->Stop(); |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { |
| 1098 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 1099 int frame_width = 640; |
| 1100 int frame_height = 360; |
| 1101 |
| 1102 video_source_.IncomingCapturedFrame( |
| 1103 CreateFrame(1, frame_width, frame_height)); |
| 1104 |
| 1105 // Expect to drop this frame, the wait should time out. |
| 1106 sink_.ExpectDroppedFrame(); |
| 1107 |
| 1108 // Expect the sink_wants to specify a scaled frame. |
| 1109 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
| 1110 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); |
| 1111 |
| 1112 int last_pixel_count = *video_source_.sink_wants().max_pixel_count; |
| 1113 |
| 1114 // Next frame is scaled |
| 1115 video_source_.IncomingCapturedFrame( |
| 1116 CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); |
| 1117 |
| 1118 // Expect to drop this frame, the wait should time out. |
| 1119 sink_.ExpectDroppedFrame(); |
| 1120 |
| 1121 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, last_pixel_count); |
| 1122 |
| 1123 vie_encoder_->Stop(); |
| 1124 } |
| 1125 |
| 1126 TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { |
| 1127 // 1kbps. This can never be achieved. |
| 1128 vie_encoder_->OnBitrateUpdated(1000, 0, 0); |
| 1129 int frame_width = 640; |
| 1130 int frame_height = 360; |
| 1131 |
| 1132 // We expect the n initial frames to get dropped. |
| 1133 int i; |
| 1134 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
| 1135 video_source_.IncomingCapturedFrame( |
| 1136 CreateFrame(i, frame_width, frame_height)); |
| 1137 sink_.ExpectDroppedFrame(); |
| 1138 } |
| 1139 // The n+1th frame should not be dropped, even though it's size is too large. |
| 1140 video_source_.IncomingCapturedFrame( |
| 1141 CreateFrame(i, frame_width, frame_height)); |
| 1142 sink_.WaitForEncodedFrame(i); |
| 1143 |
| 1144 // Expect the sink_wants to specify a scaled frame. |
| 1145 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
| 1146 EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); |
| 1147 |
| 1148 vie_encoder_->Stop(); |
| 1149 } |
| 1150 |
| 1151 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { |
| 1152 int frame_width = 640; |
| 1153 int frame_height = 360; |
| 1154 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 1155 |
| 1156 // Set degradation preference. |
| 1157 vie_encoder_->SetSource( |
| 1158 &video_source_, |
| 1159 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1160 |
| 1161 video_source_.IncomingCapturedFrame( |
| 1162 CreateFrame(1, frame_width, frame_height)); |
| 1163 // Frame should not be dropped, even if it's too large. |
| 1164 sink_.WaitForEncodedFrame(1); |
| 1165 |
| 1166 vie_encoder_->Stop(); |
| 1167 } |
| 1168 |
| 1097 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 1169 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
| 1098 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { | 1170 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { |
| 1099 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1171 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1100 | 1172 |
| 1101 const int kFrameWidth = 1280; | 1173 const int kFrameWidth = 1280; |
| 1102 const int kFrameHeight = 720; | 1174 const int kFrameHeight = 720; |
| 1103 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 1175 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
| 1104 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 1176 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
| 1105 video_source_.set_adaptation_enabled(true); | 1177 video_source_.set_adaptation_enabled(true); |
| 1106 | 1178 |
| 1107 video_source_.IncomingCapturedFrame( | 1179 video_source_.IncomingCapturedFrame( |
| 1108 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1180 CreateFrame(1, kFrameWidth, kFrameHeight)); |
| 1109 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1181 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1110 | 1182 |
| 1111 // Trigger CPU overuse, downscale by 3/4. | 1183 // Trigger CPU overuse, downscale by 3/4. |
| 1112 vie_encoder_->TriggerCpuOveruse(); | 1184 vie_encoder_->TriggerCpuOveruse(); |
| 1113 video_source_.IncomingCapturedFrame( | 1185 video_source_.IncomingCapturedFrame( |
| 1114 CreateFrame(2, kFrameWidth, kFrameHeight)); | 1186 CreateFrame(2, kFrameWidth, kFrameHeight)); |
| 1115 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 1187 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
| 1116 | 1188 |
| 1117 // Trigger CPU normal use, return to original resoluton; | 1189 // Trigger CPU normal use, return to original resoluton; |
| 1118 vie_encoder_->TriggerCpuNormalUsage(); | 1190 vie_encoder_->TriggerCpuNormalUsage(); |
| 1119 video_source_.IncomingCapturedFrame( | 1191 video_source_.IncomingCapturedFrame( |
| 1120 CreateFrame(3, kFrameWidth, kFrameHeight)); | 1192 CreateFrame(3, kFrameWidth, kFrameHeight)); |
| 1121 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1193 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1122 | 1194 |
| 1123 vie_encoder_->Stop(); | 1195 vie_encoder_->Stop(); |
| 1124 } | 1196 } |
| 1125 } // namespace webrtc | 1197 } // namespace webrtc |
| OLD | NEW |