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 |
| 11 #include <limits> |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/system_wrappers/include/metrics_default.h" |
14 #include "webrtc/test/encoder_settings.h" | 16 #include "webrtc/test/encoder_settings.h" |
15 #include "webrtc/test/fake_encoder.h" | 17 #include "webrtc/test/fake_encoder.h" |
16 #include "webrtc/test/frame_generator.h" | 18 #include "webrtc/test/frame_generator.h" |
17 #include "webrtc/test/gtest.h" | 19 #include "webrtc/test/gtest.h" |
18 #include "webrtc/video/send_statistics_proxy.h" | 20 #include "webrtc/video/send_statistics_proxy.h" |
19 #include "webrtc/video/vie_encoder.h" | 21 #include "webrtc/video/vie_encoder.h" |
20 | 22 |
21 namespace webrtc { | 23 namespace webrtc { |
22 | 24 |
| 25 namespace { |
| 26 class TestBuffer : public webrtc::I420Buffer { |
| 27 public: |
| 28 TestBuffer(rtc::Event* event, int width, int height) |
| 29 : I420Buffer(width, height), event_(event) {} |
| 30 |
| 31 private: |
| 32 friend class rtc::RefCountedObject<TestBuffer>; |
| 33 ~TestBuffer() override { |
| 34 if (event_) |
| 35 event_->Set(); |
| 36 } |
| 37 rtc::Event* const event_; |
| 38 }; |
| 39 |
| 40 class ViEEncoderUnderTest : public ViEEncoder { |
| 41 public: |
| 42 ViEEncoderUnderTest( |
| 43 SendStatisticsProxy* stats_proxy, |
| 44 const webrtc::VideoSendStream::Config::EncoderSettings& settings) |
| 45 : ViEEncoder(1 /* number_of_cores */, |
| 46 stats_proxy, |
| 47 settings, |
| 48 nullptr /* pre_encode_callback */, |
| 49 nullptr /* encoder_timing */) {} |
| 50 |
| 51 void TriggerCpuOveruse() { |
| 52 rtc::Event event(false, false); |
| 53 encoder_queue()->PostTask([this, &event] { |
| 54 OveruseDetected(); |
| 55 event.Set(); |
| 56 }); |
| 57 event.Wait(rtc::Event::kForever); |
| 58 } |
| 59 |
| 60 void TriggerCpuNormalUsage() { |
| 61 rtc::Event event(false, false); |
| 62 encoder_queue()->PostTask([this, &event] { |
| 63 NormalUsage(); |
| 64 event.Set(); |
| 65 }); |
| 66 event.Wait(rtc::Event::kForever); |
| 67 } |
| 68 }; |
| 69 |
| 70 } // namespace |
| 71 |
23 class ViEEncoderTest : public ::testing::Test { | 72 class ViEEncoderTest : public ::testing::Test { |
24 public: | 73 public: |
25 static const int kDefaultTimeoutMs = 30 * 1000; | 74 static const int kDefaultTimeoutMs = 30 * 1000; |
26 | 75 |
27 ViEEncoderTest() | 76 ViEEncoderTest() |
28 : video_send_config_(VideoSendStream::Config(nullptr)), | 77 : video_send_config_(VideoSendStream::Config(nullptr)), |
29 codec_width_(320), | 78 codec_width_(320), |
30 codec_height_(240), | 79 codec_height_(240), |
31 fake_encoder_(), | 80 fake_encoder_(), |
32 stats_proxy_(Clock::GetRealTimeClock(), | 81 stats_proxy_(new SendStatisticsProxy( |
33 video_send_config_, | 82 Clock::GetRealTimeClock(), |
34 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo), | 83 video_send_config_, |
| 84 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), |
35 sink_(&fake_encoder_) {} | 85 sink_(&fake_encoder_) {} |
36 | 86 |
37 void SetUp() override { | 87 void SetUp() override { |
| 88 metrics::Reset(); |
38 video_send_config_ = VideoSendStream::Config(nullptr); | 89 video_send_config_ = VideoSendStream::Config(nullptr); |
39 video_send_config_.encoder_settings.encoder = &fake_encoder_; | 90 video_send_config_.encoder_settings.encoder = &fake_encoder_; |
40 video_send_config_.encoder_settings.payload_name = "FAKE"; | 91 video_send_config_.encoder_settings.payload_name = "FAKE"; |
41 video_send_config_.encoder_settings.payload_type = 125; | 92 video_send_config_.encoder_settings.payload_type = 125; |
42 | 93 |
43 VideoEncoderConfig video_encoder_config; | 94 VideoEncoderConfig video_encoder_config; |
44 test::FillEncoderConfiguration(1, &video_encoder_config); | 95 test::FillEncoderConfiguration(1, &video_encoder_config); |
45 vie_encoder_.reset(new ViEEncoder( | 96 vie_encoder_.reset(new ViEEncoderUnderTest( |
46 1 /* number_of_cores */, &stats_proxy_, | 97 stats_proxy_.get(), video_send_config_.encoder_settings)); |
47 video_send_config_.encoder_settings, nullptr /* pre_encode_callback */, | 98 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
48 nullptr /* overuse_callback */, nullptr /* encoder_timing */)); | 99 vie_encoder_->SetSource(&video_source_, |
49 vie_encoder_->SetSink(&sink_); | 100 VideoSendStream::DegradationPreference::kBalanced); |
50 vie_encoder_->SetSource(&video_source_); | |
51 vie_encoder_->SetStartBitrate(10000); | 101 vie_encoder_->SetStartBitrate(10000); |
52 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), 1440); | 102 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), 1440); |
53 } | 103 } |
54 | 104 |
55 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { | 105 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { |
56 class TestBuffer : public webrtc::I420Buffer { | |
57 public: | |
58 TestBuffer(rtc::Event* event, int width, int height) | |
59 : I420Buffer(width, height), event_(event) {} | |
60 | |
61 private: | |
62 friend class rtc::RefCountedObject<TestBuffer>; | |
63 ~TestBuffer() override { | |
64 if (event_) | |
65 event_->Set(); | |
66 } | |
67 rtc::Event* const event_; | |
68 }; | |
69 | |
70 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 106 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
71 destruction_event, codec_width_, codec_height_), | 107 destruction_event, codec_width_, codec_height_), |
72 99, 99, kVideoRotation_0); | 108 99, 99, kVideoRotation_0); |
73 frame.set_ntp_time_ms(ntp_ts); | 109 frame.set_ntp_time_ms(ntp_ts); |
74 return frame; | 110 return frame; |
75 } | 111 } |
76 | 112 |
| 113 VideoFrame CreateFrame(int64_t ntp_ts, int width, int height) const { |
| 114 VideoFrame frame( |
| 115 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, |
| 116 kVideoRotation_0); |
| 117 frame.set_ntp_time_ms(ntp_ts); |
| 118 return frame; |
| 119 } |
| 120 |
77 class TestEncoder : public test::FakeEncoder { | 121 class TestEncoder : public test::FakeEncoder { |
78 public: | 122 public: |
79 TestEncoder() | 123 TestEncoder() |
80 : FakeEncoder(Clock::GetRealTimeClock()), | 124 : FakeEncoder(Clock::GetRealTimeClock()), |
81 continue_encode_event_(false, false) {} | 125 continue_encode_event_(false, false) {} |
82 | 126 |
83 VideoCodec codec_config() { | 127 VideoCodec codec_config() { |
84 rtc::CritScope lock(&crit_); | 128 rtc::CritScope lock(&crit_); |
85 return config_; | 129 return config_; |
86 } | 130 } |
(...skipping 18 matching lines...) Expand all Loading... |
105 const std::vector<FrameType>* frame_types) override { | 149 const std::vector<FrameType>* frame_types) override { |
106 bool block_encode; | 150 bool block_encode; |
107 { | 151 { |
108 rtc::CritScope lock(&crit_); | 152 rtc::CritScope lock(&crit_); |
109 EXPECT_GT(input_image.timestamp(), timestamp_); | 153 EXPECT_GT(input_image.timestamp(), timestamp_); |
110 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); | 154 EXPECT_GT(input_image.ntp_time_ms(), ntp_time_ms_); |
111 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90); | 155 EXPECT_EQ(input_image.timestamp(), input_image.ntp_time_ms() * 90); |
112 | 156 |
113 timestamp_ = input_image.timestamp(); | 157 timestamp_ = input_image.timestamp(); |
114 ntp_time_ms_ = input_image.ntp_time_ms(); | 158 ntp_time_ms_ = input_image.ntp_time_ms(); |
| 159 last_input_width_ = input_image.width(); |
| 160 last_input_height_ = input_image.height(); |
115 block_encode = block_next_encode_; | 161 block_encode = block_next_encode_; |
116 block_next_encode_ = false; | 162 block_next_encode_ = false; |
117 } | 163 } |
118 int32_t result = | 164 int32_t result = |
119 FakeEncoder::Encode(input_image, codec_specific_info, frame_types); | 165 FakeEncoder::Encode(input_image, codec_specific_info, frame_types); |
120 if (block_encode) | 166 if (block_encode) |
121 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs)); | 167 EXPECT_TRUE(continue_encode_event_.Wait(kDefaultTimeoutMs)); |
122 return result; | 168 return result; |
123 } | 169 } |
124 | 170 |
125 | |
126 | |
127 rtc::CriticalSection crit_; | 171 rtc::CriticalSection crit_; |
128 bool block_next_encode_ = false; | 172 bool block_next_encode_ = false; |
129 rtc::Event continue_encode_event_; | 173 rtc::Event continue_encode_event_; |
130 uint32_t timestamp_ = 0; | 174 uint32_t timestamp_ = 0; |
131 int64_t ntp_time_ms_ = 0; | 175 int64_t ntp_time_ms_ = 0; |
| 176 int last_input_width_ = 0; |
| 177 int last_input_height_ = 0; |
132 }; | 178 }; |
133 | 179 |
134 class TestSink : public ViEEncoder::EncoderSink { | 180 class TestSink : public ViEEncoder::EncoderSink { |
135 public: | 181 public: |
136 explicit TestSink(TestEncoder* test_encoder) | 182 explicit TestSink(TestEncoder* test_encoder) |
137 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} | 183 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} |
138 | 184 |
139 void WaitForEncodedFrame(int64_t expected_ntp_time) { | 185 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
140 uint32_t timestamp = 0; | 186 uint32_t timestamp = 0; |
141 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 187 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 uint32_t timestamp_ = 0; | 231 uint32_t timestamp_ = 0; |
186 bool expect_frames_ = true; | 232 bool expect_frames_ = true; |
187 int number_of_reconfigurations_ = 0; | 233 int number_of_reconfigurations_ = 0; |
188 int min_transmit_bitrate_bps_ = 0; | 234 int min_transmit_bitrate_bps_ = 0; |
189 }; | 235 }; |
190 | 236 |
191 VideoSendStream::Config video_send_config_; | 237 VideoSendStream::Config video_send_config_; |
192 int codec_width_; | 238 int codec_width_; |
193 int codec_height_; | 239 int codec_height_; |
194 TestEncoder fake_encoder_; | 240 TestEncoder fake_encoder_; |
195 SendStatisticsProxy stats_proxy_; | 241 std::unique_ptr<SendStatisticsProxy> stats_proxy_; |
196 TestSink sink_; | 242 TestSink sink_; |
197 test::FrameForwarder video_source_; | 243 test::FrameForwarder video_source_; |
198 std::unique_ptr<ViEEncoder> vie_encoder_; | 244 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; |
199 }; | 245 }; |
200 | 246 |
201 TEST_F(ViEEncoderTest, EncodeOneFrame) { | 247 TEST_F(ViEEncoderTest, EncodeOneFrame) { |
202 const int kTargetBitrateBps = 100000; | 248 const int kTargetBitrateBps = 100000; |
203 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 249 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
204 rtc::Event frame_destroyed_event(false, false); | 250 rtc::Event frame_destroyed_event(false, false); |
205 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 251 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
206 sink_.WaitForEncodedFrame(1); | 252 sink_.WaitForEncodedFrame(1); |
207 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 253 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
208 vie_encoder_->Stop(); | 254 vie_encoder_->Stop(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // with the encoder thread. | 373 // with the encoder thread. |
328 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 374 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
329 sink_.WaitForEncodedFrame(2); | 375 sink_.WaitForEncodedFrame(2); |
330 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 376 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
331 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 377 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
332 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 378 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
333 | 379 |
334 vie_encoder_->Stop(); | 380 vie_encoder_->Stop(); |
335 } | 381 } |
336 | 382 |
| 383 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) { |
| 384 EXPECT_TRUE(video_source_.has_sinks()); |
| 385 test::FrameForwarder new_video_source; |
| 386 vie_encoder_->SetSource(&new_video_source, |
| 387 VideoSendStream::DegradationPreference::kBalanced); |
| 388 EXPECT_FALSE(video_source_.has_sinks()); |
| 389 EXPECT_TRUE(new_video_source.has_sinks()); |
| 390 |
| 391 vie_encoder_->Stop(); |
| 392 } |
| 393 |
| 394 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { |
| 395 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); |
| 396 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); |
| 397 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); |
| 398 vie_encoder_->Stop(); |
| 399 } |
| 400 |
| 401 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
| 402 const int kTargetBitrateBps = 100000; |
| 403 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 404 |
| 405 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 406 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
| 407 |
| 408 int frame_width = 1280; |
| 409 int frame_height = 720; |
| 410 |
| 411 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
| 412 // request lower resolution. |
| 413 for (int i = 1; i <= ViEEncoder::kMaxCpuDowngrades; ++i) { |
| 414 video_source_.IncomingCapturedFrame( |
| 415 CreateFrame(i, frame_width, frame_height)); |
| 416 sink_.WaitForEncodedFrame(i); |
| 417 |
| 418 vie_encoder_->TriggerCpuOveruse(); |
| 419 |
| 420 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( |
| 421 std::numeric_limits<int>::max()), |
| 422 frame_width * frame_height); |
| 423 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
| 424 |
| 425 frame_width /= 2; |
| 426 frame_height /= 2; |
| 427 } |
| 428 |
| 429 // Trigger CPU overuse a one more time. This should not trigger request for |
| 430 // lower resolution. |
| 431 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
| 432 video_source_.IncomingCapturedFrame(CreateFrame( |
| 433 ViEEncoder::kMaxCpuDowngrades + 1, frame_width, frame_height)); |
| 434 sink_.WaitForEncodedFrame(ViEEncoder::kMaxCpuDowngrades + 1); |
| 435 vie_encoder_->TriggerCpuOveruse(); |
| 436 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
| 437 current_wants.max_pixel_count); |
| 438 EXPECT_EQ(video_source_.sink_wants().max_pixel_count_step_up, |
| 439 current_wants.max_pixel_count_step_up); |
| 440 |
| 441 // Trigger CPU normal use. |
| 442 vie_encoder_->TriggerCpuNormalUsage(); |
| 443 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 444 EXPECT_EQ(video_source_.sink_wants().max_pixel_count_step_up.value_or(0), |
| 445 frame_width * frame_height); |
| 446 |
| 447 vie_encoder_->Stop(); |
| 448 } |
| 449 |
| 450 TEST_F(ViEEncoderTest, |
| 451 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { |
| 452 const int kTargetBitrateBps = 100000; |
| 453 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 454 |
| 455 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
| 456 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
| 457 |
| 458 int frame_width = 1280; |
| 459 int frame_height = 720; |
| 460 |
| 461 // Trigger CPU overuse. |
| 462 vie_encoder_->TriggerCpuOveruse(); |
| 463 |
| 464 video_source_.IncomingCapturedFrame( |
| 465 CreateFrame(1, frame_width, frame_height)); |
| 466 sink_.WaitForEncodedFrame(1); |
| 467 EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( |
| 468 std::numeric_limits<int>::max()), |
| 469 frame_width * frame_height); |
| 470 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
| 471 |
| 472 // Set new source. |
| 473 test::FrameForwarder new_video_source; |
| 474 vie_encoder_->SetSource( |
| 475 &new_video_source, |
| 476 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 477 |
| 478 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 479 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); |
| 480 |
| 481 new_video_source.IncomingCapturedFrame( |
| 482 CreateFrame(2, frame_width, frame_height)); |
| 483 sink_.WaitForEncodedFrame(2); |
| 484 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
| 485 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); |
| 486 |
| 487 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
| 488 vie_encoder_->SetSource(&new_video_source, |
| 489 VideoSendStream::DegradationPreference::kBalanced); |
| 490 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( |
| 491 std::numeric_limits<int>::max()), |
| 492 frame_width * frame_height); |
| 493 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); |
| 494 |
| 495 vie_encoder_->Stop(); |
| 496 } |
| 497 |
| 498 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { |
| 499 const int kTargetBitrateBps = 100000; |
| 500 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 501 |
| 502 int frame_width = 1280; |
| 503 int frame_height = 720; |
| 504 |
| 505 video_source_.IncomingCapturedFrame( |
| 506 CreateFrame(1, frame_width, frame_height)); |
| 507 sink_.WaitForEncodedFrame(1); |
| 508 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 509 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 510 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
| 511 |
| 512 // Trigger CPU overuse. |
| 513 vie_encoder_->TriggerCpuOveruse(); |
| 514 video_source_.IncomingCapturedFrame( |
| 515 CreateFrame(2, frame_width, frame_height)); |
| 516 sink_.WaitForEncodedFrame(2); |
| 517 |
| 518 stats = stats_proxy_->GetStats(); |
| 519 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 520 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 521 |
| 522 // Trigger CPU normal use. |
| 523 vie_encoder_->TriggerCpuNormalUsage(); |
| 524 video_source_.IncomingCapturedFrame( |
| 525 CreateFrame(3, frame_width, frame_height)); |
| 526 sink_.WaitForEncodedFrame(3); |
| 527 |
| 528 stats = stats_proxy_->GetStats(); |
| 529 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 530 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 531 |
| 532 vie_encoder_->Stop(); |
| 533 } |
| 534 |
| 535 TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) { |
| 536 const int kTargetBitrateBps = 100000; |
| 537 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 538 |
| 539 // Trigger CPU overuse. |
| 540 vie_encoder_->TriggerCpuOveruse(); |
| 541 int frame_width = 1280; |
| 542 int frame_height = 720; |
| 543 |
| 544 video_source_.IncomingCapturedFrame( |
| 545 CreateFrame(1, frame_width, frame_height)); |
| 546 sink_.WaitForEncodedFrame(1); |
| 547 |
| 548 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
| 549 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 550 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 551 |
| 552 // Set new source with adaptation still enabled. |
| 553 test::FrameForwarder new_video_source; |
| 554 vie_encoder_->SetSource(&new_video_source, |
| 555 VideoSendStream::DegradationPreference::kBalanced); |
| 556 |
| 557 new_video_source.IncomingCapturedFrame( |
| 558 CreateFrame(2, frame_width, frame_height)); |
| 559 sink_.WaitForEncodedFrame(2); |
| 560 stats = stats_proxy_->GetStats(); |
| 561 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 562 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 563 |
| 564 // Set adaptation disabled. |
| 565 vie_encoder_->SetSource( |
| 566 &new_video_source, |
| 567 VideoSendStream::DegradationPreference::kMaintainResolution); |
| 568 new_video_source.IncomingCapturedFrame( |
| 569 CreateFrame(3, frame_width, frame_height)); |
| 570 sink_.WaitForEncodedFrame(3); |
| 571 stats = stats_proxy_->GetStats(); |
| 572 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 573 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 574 |
| 575 // Switch back the source with adaptation enabled. |
| 576 vie_encoder_->SetSource(&video_source_, |
| 577 VideoSendStream::DegradationPreference::kBalanced); |
| 578 video_source_.IncomingCapturedFrame( |
| 579 CreateFrame(4, frame_width, frame_height)); |
| 580 sink_.WaitForEncodedFrame(4); |
| 581 stats = stats_proxy_->GetStats(); |
| 582 EXPECT_TRUE(stats.cpu_limited_resolution); |
| 583 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
| 584 |
| 585 // Trigger CPU normal usage. |
| 586 vie_encoder_->TriggerCpuNormalUsage(); |
| 587 video_source_.IncomingCapturedFrame( |
| 588 CreateFrame(5, frame_width, frame_height)); |
| 589 sink_.WaitForEncodedFrame(5); |
| 590 stats = stats_proxy_->GetStats(); |
| 591 EXPECT_FALSE(stats.cpu_limited_resolution); |
| 592 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
| 593 |
| 594 vie_encoder_->Stop(); |
| 595 } |
| 596 |
| 597 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { |
| 598 const int kTargetBitrateBps = 100000; |
| 599 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 600 |
| 601 int frame_width = 640; |
| 602 int frame_height = 360; |
| 603 |
| 604 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
| 605 video_source_.IncomingCapturedFrame( |
| 606 CreateFrame(i, frame_width, frame_height)); |
| 607 sink_.WaitForEncodedFrame(i); |
| 608 } |
| 609 |
| 610 vie_encoder_->TriggerCpuOveruse(); |
| 611 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
| 612 video_source_.IncomingCapturedFrame( |
| 613 CreateFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i, |
| 614 frame_width, frame_height)); |
| 615 sink_.WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + |
| 616 i); |
| 617 } |
| 618 |
| 619 vie_encoder_->Stop(); |
| 620 |
| 621 stats_proxy_.reset(); |
| 622 EXPECT_EQ(1, |
| 623 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
| 624 EXPECT_EQ( |
| 625 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
| 626 } |
| 627 |
337 } // namespace webrtc | 628 } // namespace webrtc |
OLD | NEW |