| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 rtc::CritScope lock(&crit_sect_); | 244 rtc::CritScope lock(&crit_sect_); |
| 245 return config_; | 245 return config_; |
| 246 } | 246 } |
| 247 | 247 |
| 248 void BlockNextEncode() { | 248 void BlockNextEncode() { |
| 249 rtc::CritScope lock(&local_crit_sect_); | 249 rtc::CritScope lock(&local_crit_sect_); |
| 250 block_next_encode_ = true; | 250 block_next_encode_ = true; |
| 251 } | 251 } |
| 252 | 252 |
| 253 VideoEncoder::ScalingSettings GetScalingSettings() const override { | 253 VideoEncoder::ScalingSettings GetScalingSettings() const override { |
| 254 return VideoEncoder::ScalingSettings(true, 1, 2); | 254 if (quality_scaling_) |
| 255 return VideoEncoder::ScalingSettings(true, 1, 2); |
| 256 return VideoEncoder::ScalingSettings(false); |
| 255 } | 257 } |
| 256 | 258 |
| 257 void ContinueEncode() { continue_encode_event_.Set(); } | 259 void ContinueEncode() { continue_encode_event_.Set(); } |
| 258 | 260 |
| 259 void CheckLastTimeStampsMatch(int64_t ntp_time_ms, | 261 void CheckLastTimeStampsMatch(int64_t ntp_time_ms, |
| 260 uint32_t timestamp) const { | 262 uint32_t timestamp) const { |
| 261 rtc::CritScope lock(&local_crit_sect_); | 263 rtc::CritScope lock(&local_crit_sect_); |
| 262 EXPECT_EQ(timestamp_, timestamp); | 264 EXPECT_EQ(timestamp_, timestamp); |
| 263 EXPECT_EQ(ntp_time_ms_, ntp_time_ms); | 265 EXPECT_EQ(ntp_time_ms_, ntp_time_ms); |
| 264 } | 266 } |
| 265 | 267 |
| 268 void SetQualityScaling(bool b) { quality_scaling_ = b; } |
| 269 |
| 266 private: | 270 private: |
| 267 int32_t Encode(const VideoFrame& input_image, | 271 int32_t Encode(const VideoFrame& input_image, |
| 268 const CodecSpecificInfo* codec_specific_info, | 272 const CodecSpecificInfo* codec_specific_info, |
| 269 const std::vector<FrameType>* frame_types) override { | 273 const std::vector<FrameType>* frame_types) override { |
| 270 bool block_encode; | 274 bool block_encode; |
| 271 { | 275 { |
| 272 rtc::CritScope lock(&local_crit_sect_); | 276 rtc::CritScope lock(&local_crit_sect_); |
| 273 EXPECT_GT(input_image.timestamp(), timestamp_); | 277 EXPECT_GT(input_image.timestamp(), timestamp_); |
| 274 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); | 278 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); |
| 275 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90); | 279 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 288 return result; | 292 return result; |
| 289 } | 293 } |
| 290 | 294 |
| 291 rtc::CriticalSection local_crit_sect_; | 295 rtc::CriticalSection local_crit_sect_; |
| 292 bool block_next_encode_ = false; | 296 bool block_next_encode_ = false; |
| 293 rtc::Event continue_encode_event_; | 297 rtc::Event continue_encode_event_; |
| 294 uint32_t timestamp_ = 0; | 298 uint32_t timestamp_ = 0; |
| 295 int64_t ntp_time_ms_ = 0; | 299 int64_t ntp_time_ms_ = 0; |
| 296 int last_input_width_ = 0; | 300 int last_input_width_ = 0; |
| 297 int last_input_height_ = 0; | 301 int last_input_height_ = 0; |
| 302 bool quality_scaling_ = true; |
| 298 }; | 303 }; |
| 299 | 304 |
| 300 class TestSink : public ViEEncoder::EncoderSink { | 305 class TestSink : public ViEEncoder::EncoderSink { |
| 301 public: | 306 public: |
| 302 explicit TestSink(TestEncoder* test_encoder) | 307 explicit TestSink(TestEncoder* test_encoder) |
| 303 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} | 308 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} |
| 304 | 309 |
| 305 void WaitForEncodedFrame(int64_t expected_ntp_time) { | 310 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
| 306 uint32_t timestamp = 0; | 311 uint32_t timestamp = 0; |
| 307 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 312 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 VideoSendStream::DegradationPreference::kMaintainResolution); | 1164 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 1160 | 1165 |
| 1161 video_source_.IncomingCapturedFrame( | 1166 video_source_.IncomingCapturedFrame( |
| 1162 CreateFrame(1, frame_width, frame_height)); | 1167 CreateFrame(1, frame_width, frame_height)); |
| 1163 // Frame should not be dropped, even if it's too large. | 1168 // Frame should not be dropped, even if it's too large. |
| 1164 sink_.WaitForEncodedFrame(1); | 1169 sink_.WaitForEncodedFrame(1); |
| 1165 | 1170 |
| 1166 vie_encoder_->Stop(); | 1171 vie_encoder_->Stop(); |
| 1167 } | 1172 } |
| 1168 | 1173 |
| 1174 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { |
| 1175 int frame_width = 640; |
| 1176 int frame_height = 360; |
| 1177 fake_encoder_.SetQualityScaling(false); |
| 1178 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
| 1179 |
| 1180 video_source_.IncomingCapturedFrame( |
| 1181 CreateFrame(1, frame_width, frame_height)); |
| 1182 // Frame should not be dropped, even if it's too large. |
| 1183 sink_.WaitForEncodedFrame(1); |
| 1184 |
| 1185 vie_encoder_->Stop(); |
| 1186 fake_encoder_.SetQualityScaling(true); |
| 1187 } |
| 1188 |
| 1169 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 1189 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
| 1170 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { | 1190 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) { |
| 1171 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1191 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 1172 | 1192 |
| 1173 const int kFrameWidth = 1280; | 1193 const int kFrameWidth = 1280; |
| 1174 const int kFrameHeight = 720; | 1194 const int kFrameHeight = 720; |
| 1175 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 1195 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
| 1176 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 1196 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
| 1177 video_source_.set_adaptation_enabled(true); | 1197 video_source_.set_adaptation_enabled(true); |
| 1178 | 1198 |
| 1179 video_source_.IncomingCapturedFrame( | 1199 video_source_.IncomingCapturedFrame( |
| 1180 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1200 CreateFrame(1, kFrameWidth, kFrameHeight)); |
| 1181 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1201 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1182 | 1202 |
| 1183 // Trigger CPU overuse, downscale by 3/4. | 1203 // Trigger CPU overuse, downscale by 3/4. |
| 1184 vie_encoder_->TriggerCpuOveruse(); | 1204 vie_encoder_->TriggerCpuOveruse(); |
| 1185 video_source_.IncomingCapturedFrame( | 1205 video_source_.IncomingCapturedFrame( |
| 1186 CreateFrame(2, kFrameWidth, kFrameHeight)); | 1206 CreateFrame(2, kFrameWidth, kFrameHeight)); |
| 1187 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 1207 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
| 1188 | 1208 |
| 1189 // Trigger CPU normal use, return to original resoluton; | 1209 // Trigger CPU normal use, return to original resoluton; |
| 1190 vie_encoder_->TriggerCpuNormalUsage(); | 1210 vie_encoder_->TriggerCpuNormalUsage(); |
| 1191 video_source_.IncomingCapturedFrame( | 1211 video_source_.IncomingCapturedFrame( |
| 1192 CreateFrame(3, kFrameWidth, kFrameHeight)); | 1212 CreateFrame(3, kFrameWidth, kFrameHeight)); |
| 1193 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1213 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 1194 | 1214 |
| 1195 vie_encoder_->Stop(); | 1215 vie_encoder_->Stop(); |
| 1196 } | 1216 } |
| 1197 } // namespace webrtc | 1217 } // namespace webrtc |
| OLD | NEW |