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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } // namespace | 211 } // namespace |
212 | 212 |
213 class ViEEncoderTest : public ::testing::Test { | 213 class ViEEncoderTest : public ::testing::Test { |
214 public: | 214 public: |
215 static const int kDefaultTimeoutMs = 30 * 1000; | 215 static const int kDefaultTimeoutMs = 30 * 1000; |
216 | 216 |
217 ViEEncoderTest() | 217 ViEEncoderTest() |
218 : video_send_config_(VideoSendStream::Config(nullptr)), | 218 : video_send_config_(VideoSendStream::Config(nullptr)), |
219 codec_width_(320), | 219 codec_width_(320), |
220 codec_height_(240), | 220 codec_height_(240), |
221 max_framerate_(30), | |
222 fake_encoder_(), | 221 fake_encoder_(), |
223 stats_proxy_(new MockableSendStatisticsProxy( | 222 stats_proxy_(new MockableSendStatisticsProxy( |
224 Clock::GetRealTimeClock(), | 223 Clock::GetRealTimeClock(), |
225 video_send_config_, | 224 video_send_config_, |
226 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), | 225 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), |
227 sink_(&fake_encoder_) {} | 226 sink_(&fake_encoder_) {} |
228 | 227 |
229 void SetUp() override { | 228 void SetUp() override { |
230 metrics::Reset(); | 229 metrics::Reset(); |
231 video_send_config_ = VideoSendStream::Config(nullptr); | 230 video_send_config_ = VideoSendStream::Config(nullptr); |
232 video_send_config_.encoder_settings.encoder = &fake_encoder_; | 231 video_send_config_.encoder_settings.encoder = &fake_encoder_; |
233 video_send_config_.encoder_settings.payload_name = "FAKE"; | 232 video_send_config_.encoder_settings.payload_name = "FAKE"; |
234 video_send_config_.encoder_settings.payload_type = 125; | 233 video_send_config_.encoder_settings.payload_type = 125; |
235 | 234 |
236 VideoEncoderConfig video_encoder_config; | 235 VideoEncoderConfig video_encoder_config; |
237 test::FillEncoderConfiguration(1, &video_encoder_config); | 236 test::FillEncoderConfiguration(1, &video_encoder_config); |
238 video_encoder_config.video_stream_factory = | |
239 new rtc::RefCountedObject<VideoStreamFactory>(1); | |
240 video_encoder_config_ = video_encoder_config.Copy(); | 237 video_encoder_config_ = video_encoder_config.Copy(); |
241 | |
242 // Framerate limit is specified by the VideoStreamFactory. | |
243 std::vector<VideoStream> streams = | |
244 video_encoder_config.video_stream_factory->CreateEncoderStreams( | |
245 codec_width_, codec_height_, video_encoder_config); | |
246 max_framerate_ = streams[0].max_framerate; | |
247 fake_clock_.SetTimeMicros(1234); | |
248 | |
249 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); | 238 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); |
250 } | 239 } |
251 | 240 |
252 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, | 241 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
253 bool nack_enabled) { | 242 bool nack_enabled) { |
254 if (vie_encoder_) | 243 if (vie_encoder_) |
255 vie_encoder_->Stop(); | 244 vie_encoder_->Stop(); |
256 vie_encoder_.reset(new ViEEncoderUnderTest( | 245 vie_encoder_.reset(new ViEEncoderUnderTest( |
257 stats_proxy_.get(), video_send_config_.encoder_settings)); | 246 stats_proxy_.get(), video_send_config_.encoder_settings)); |
258 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 247 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
259 vie_encoder_->SetSource( | 248 vie_encoder_->SetSource( |
260 &video_source_, | 249 &video_source_, |
261 VideoSendStream::DegradationPreference::kMaintainFramerate); | 250 VideoSendStream::DegradationPreference::kMaintainFramerate); |
262 vie_encoder_->SetStartBitrate(kTargetBitrateBps); | 251 vie_encoder_->SetStartBitrate(kTargetBitrateBps); |
263 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 252 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
264 kMaxPayloadLength, nack_enabled); | 253 kMaxPayloadLength, nack_enabled); |
265 vie_encoder_->WaitUntilTaskQueueIsIdle(); | 254 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
266 } | 255 } |
267 | 256 |
268 void ResetEncoder(const std::string& payload_name, | 257 void ResetEncoder(const std::string& payload_name, |
269 size_t num_streams, | 258 size_t num_streams, |
270 size_t num_temporal_layers, | 259 size_t num_temporal_layers, |
271 bool nack_enabled, | 260 bool nack_enabled) { |
272 bool screenshare) { | |
273 video_send_config_.encoder_settings.payload_name = payload_name; | 261 video_send_config_.encoder_settings.payload_name = payload_name; |
274 | 262 |
275 VideoEncoderConfig video_encoder_config; | 263 VideoEncoderConfig video_encoder_config; |
276 video_encoder_config.number_of_streams = num_streams; | 264 video_encoder_config.number_of_streams = num_streams; |
277 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; | 265 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
278 video_encoder_config.video_stream_factory = | 266 video_encoder_config.video_stream_factory = |
279 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); | 267 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); |
280 video_encoder_config.content_type = | |
281 screenshare ? VideoEncoderConfig::ContentType::kScreen | |
282 : VideoEncoderConfig::ContentType::kRealtimeVideo; | |
283 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); | 268 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
284 } | 269 } |
285 | 270 |
286 VideoFrame CreateFrame(int64_t ntp_time_ms, | 271 VideoFrame CreateFrame(int64_t ntp_time_ms, |
287 rtc::Event* destruction_event) const { | 272 rtc::Event* destruction_event) const { |
288 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 273 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
289 destruction_event, codec_width_, codec_height_), | 274 destruction_event, codec_width_, codec_height_), |
290 99, 99, kVideoRotation_0); | 275 99, 99, kVideoRotation_0); |
291 frame.set_ntp_time_ms(ntp_time_ms); | 276 frame.set_ntp_time_ms(ntp_time_ms); |
292 return frame; | 277 return frame; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 EXPECT_LT(wants.max_pixel_count, pixel_count); | 317 EXPECT_LT(wants.max_pixel_count, pixel_count); |
333 EXPECT_GT(wants.max_pixel_count, 0); | 318 EXPECT_GT(wants.max_pixel_count, 0); |
334 } | 319 } |
335 | 320 |
336 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { | 321 void VerifyFpsLtResolutionMax(const rtc::VideoSinkWants& wants, int fps) { |
337 EXPECT_LT(wants.max_framerate_fps, fps); | 322 EXPECT_LT(wants.max_framerate_fps, fps); |
338 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); | 323 EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); |
339 EXPECT_FALSE(wants.target_pixel_count); | 324 EXPECT_FALSE(wants.target_pixel_count); |
340 } | 325 } |
341 | 326 |
342 void WaitForEncodedFrame(int64_t expected_ntp_time) { | |
343 sink_.WaitForEncodedFrame(expected_ntp_time); | |
344 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); | |
345 } | |
346 | |
347 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) { | |
348 bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms); | |
349 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); | |
350 return ok; | |
351 } | |
352 | |
353 void WaitForEncodedFrame(uint32_t expected_width, uint32_t expected_height) { | |
354 sink_.WaitForEncodedFrame(expected_width, expected_height); | |
355 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); | |
356 } | |
357 | |
358 void ExpectDroppedFrame() { | |
359 sink_.ExpectDroppedFrame(); | |
360 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); | |
361 } | |
362 | |
363 bool WaitForFrame(int64_t timeout_ms) { | |
364 bool ok = sink_.WaitForFrame(timeout_ms); | |
365 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); | |
366 return ok; | |
367 } | |
368 | |
369 class TestEncoder : public test::FakeEncoder { | 327 class TestEncoder : public test::FakeEncoder { |
370 public: | 328 public: |
371 TestEncoder() | 329 TestEncoder() |
372 : FakeEncoder(Clock::GetRealTimeClock()), | 330 : FakeEncoder(Clock::GetRealTimeClock()), |
373 continue_encode_event_(false, false) {} | 331 continue_encode_event_(false, false) {} |
374 | 332 |
375 VideoCodec codec_config() const { | 333 VideoCodec codec_config() const { |
376 rtc::CritScope lock(&crit_sect_); | 334 rtc::CritScope lock(&crit_sect_); |
377 return config_; | 335 return config_; |
378 } | 336 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 GUARDED_BY(local_crit_sect_); | 425 GUARDED_BY(local_crit_sect_); |
468 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; | 426 bool force_init_encode_failed_ GUARDED_BY(local_crit_sect_) = false; |
469 }; | 427 }; |
470 | 428 |
471 class TestSink : public ViEEncoder::EncoderSink { | 429 class TestSink : public ViEEncoder::EncoderSink { |
472 public: | 430 public: |
473 explicit TestSink(TestEncoder* test_encoder) | 431 explicit TestSink(TestEncoder* test_encoder) |
474 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} | 432 : test_encoder_(test_encoder), encoded_frame_event_(false, false) {} |
475 | 433 |
476 void WaitForEncodedFrame(int64_t expected_ntp_time) { | 434 void WaitForEncodedFrame(int64_t expected_ntp_time) { |
477 EXPECT_TRUE( | |
478 TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeoutMs)); | |
479 } | |
480 | |
481 bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, | |
482 int64_t timeout_ms) { | |
483 uint32_t timestamp = 0; | 435 uint32_t timestamp = 0; |
484 if (!encoded_frame_event_.Wait(timeout_ms)) | 436 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
485 return false; | |
486 { | 437 { |
487 rtc::CritScope lock(&crit_); | 438 rtc::CritScope lock(&crit_); |
488 timestamp = last_timestamp_; | 439 timestamp = last_timestamp_; |
489 } | 440 } |
490 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); | 441 test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); |
491 return true; | |
492 } | 442 } |
493 | 443 |
494 void WaitForEncodedFrame(uint32_t expected_width, | 444 void WaitForEncodedFrame(uint32_t expected_width, |
495 uint32_t expected_height) { | 445 uint32_t expected_height) { |
496 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); | 446 EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
497 CheckLastFrameSizeMathces(expected_width, expected_height); | 447 CheckLastFrameSizeMathces(expected_width, expected_height); |
498 } | 448 } |
499 | 449 |
500 void CheckLastFrameSizeMathces(uint32_t expected_width, | 450 void CheckLastFrameSizeMathces(uint32_t expected_width, |
501 uint32_t expected_height) { | 451 uint32_t expected_height) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 uint32_t last_width_ = 0; | 510 uint32_t last_width_ = 0; |
561 bool expect_frames_ = true; | 511 bool expect_frames_ = true; |
562 int number_of_reconfigurations_ = 0; | 512 int number_of_reconfigurations_ = 0; |
563 int min_transmit_bitrate_bps_ = 0; | 513 int min_transmit_bitrate_bps_ = 0; |
564 }; | 514 }; |
565 | 515 |
566 VideoSendStream::Config video_send_config_; | 516 VideoSendStream::Config video_send_config_; |
567 VideoEncoderConfig video_encoder_config_; | 517 VideoEncoderConfig video_encoder_config_; |
568 int codec_width_; | 518 int codec_width_; |
569 int codec_height_; | 519 int codec_height_; |
570 int max_framerate_; | |
571 TestEncoder fake_encoder_; | 520 TestEncoder fake_encoder_; |
572 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; | 521 std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; |
573 TestSink sink_; | 522 TestSink sink_; |
574 AdaptingFrameForwarder video_source_; | 523 AdaptingFrameForwarder video_source_; |
575 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; | 524 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; |
576 rtc::ScopedFakeClock fake_clock_; | |
577 }; | 525 }; |
578 | 526 |
579 TEST_F(ViEEncoderTest, EncodeOneFrame) { | 527 TEST_F(ViEEncoderTest, EncodeOneFrame) { |
580 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 528 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
581 rtc::Event frame_destroyed_event(false, false); | 529 rtc::Event frame_destroyed_event(false, false); |
582 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 530 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
583 WaitForEncodedFrame(1); | 531 sink_.WaitForEncodedFrame(1); |
584 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 532 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
585 vie_encoder_->Stop(); | 533 vie_encoder_->Stop(); |
586 } | 534 } |
587 | 535 |
588 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { | 536 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { |
589 // Dropped since no target bitrate has been set. | 537 // Dropped since no target bitrate has been set. |
590 rtc::Event frame_destroyed_event(false, false); | 538 rtc::Event frame_destroyed_event(false, false); |
591 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 539 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
592 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 540 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
593 | 541 |
594 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 542 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
595 | 543 |
596 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 544 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
597 WaitForEncodedFrame(2); | 545 sink_.WaitForEncodedFrame(2); |
598 vie_encoder_->Stop(); | 546 vie_encoder_->Stop(); |
599 } | 547 } |
600 | 548 |
601 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { | 549 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { |
602 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 550 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
603 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 551 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
604 WaitForEncodedFrame(1); | 552 sink_.WaitForEncodedFrame(1); |
605 | 553 |
606 vie_encoder_->OnBitrateUpdated(0, 0, 0); | 554 vie_encoder_->OnBitrateUpdated(0, 0, 0); |
607 // Dropped since bitrate is zero. | 555 // Dropped since bitrate is zero. |
608 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 556 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
609 | 557 |
610 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 558 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
611 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 559 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
612 WaitForEncodedFrame(3); | 560 sink_.WaitForEncodedFrame(3); |
613 vie_encoder_->Stop(); | 561 vie_encoder_->Stop(); |
614 } | 562 } |
615 | 563 |
616 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { | 564 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { |
617 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 565 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
618 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 566 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
619 WaitForEncodedFrame(1); | 567 sink_.WaitForEncodedFrame(1); |
620 | 568 |
621 // This frame will be dropped since it has the same ntp timestamp. | 569 // This frame will be dropped since it has the same ntp timestamp. |
622 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 570 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
623 | 571 |
624 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 572 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
625 WaitForEncodedFrame(2); | 573 sink_.WaitForEncodedFrame(2); |
626 vie_encoder_->Stop(); | 574 vie_encoder_->Stop(); |
627 } | 575 } |
628 | 576 |
629 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { | 577 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { |
630 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 578 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
631 | 579 |
632 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 580 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
633 WaitForEncodedFrame(1); | 581 sink_.WaitForEncodedFrame(1); |
634 | 582 |
635 vie_encoder_->Stop(); | 583 vie_encoder_->Stop(); |
636 sink_.SetExpectNoFrames(); | 584 sink_.SetExpectNoFrames(); |
637 rtc::Event frame_destroyed_event(false, false); | 585 rtc::Event frame_destroyed_event(false, false); |
638 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); | 586 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); |
639 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 587 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
640 } | 588 } |
641 | 589 |
642 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { | 590 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { |
643 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 591 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
644 | 592 |
645 fake_encoder_.BlockNextEncode(); | 593 fake_encoder_.BlockNextEncode(); |
646 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 594 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
647 WaitForEncodedFrame(1); | 595 sink_.WaitForEncodedFrame(1); |
648 // Here, the encoder thread will be blocked in the TestEncoder waiting for a | 596 // Here, the encoder thread will be blocked in the TestEncoder waiting for a |
649 // call to ContinueEncode. | 597 // call to ContinueEncode. |
650 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 598 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
651 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 599 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
652 fake_encoder_.ContinueEncode(); | 600 fake_encoder_.ContinueEncode(); |
653 WaitForEncodedFrame(3); | 601 sink_.WaitForEncodedFrame(3); |
654 | 602 |
655 vie_encoder_->Stop(); | 603 vie_encoder_->Stop(); |
656 } | 604 } |
657 | 605 |
658 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { | 606 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { |
659 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 607 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
660 EXPECT_EQ(0, sink_.number_of_reconfigurations()); | 608 EXPECT_EQ(0, sink_.number_of_reconfigurations()); |
661 | 609 |
662 // Capture a frame and wait for it to synchronize with the encoder thread. | 610 // Capture a frame and wait for it to synchronize with the encoder thread. |
663 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 611 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
664 WaitForEncodedFrame(1); | 612 sink_.WaitForEncodedFrame(1); |
665 // The encoder will have been configured once when the first frame is | 613 // The encoder will have been configured once when the first frame is |
666 // received. | 614 // received. |
667 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 615 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
668 | 616 |
669 VideoEncoderConfig video_encoder_config; | 617 VideoEncoderConfig video_encoder_config; |
670 test::FillEncoderConfiguration(1, &video_encoder_config); | 618 test::FillEncoderConfiguration(1, &video_encoder_config); |
671 video_encoder_config.min_transmit_bitrate_bps = 9999; | 619 video_encoder_config.min_transmit_bitrate_bps = 9999; |
672 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), | 620 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
673 kMaxPayloadLength, true /* nack_enabled */); | 621 kMaxPayloadLength, true /* nack_enabled */); |
674 | 622 |
675 // Capture a frame and wait for it to synchronize with the encoder thread. | 623 // Capture a frame and wait for it to synchronize with the encoder thread. |
676 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 624 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
677 WaitForEncodedFrame(2); | 625 sink_.WaitForEncodedFrame(2); |
678 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 626 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
679 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); | 627 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); |
680 | 628 |
681 vie_encoder_->Stop(); | 629 vie_encoder_->Stop(); |
682 } | 630 } |
683 | 631 |
684 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { | 632 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { |
685 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 633 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
686 | 634 |
687 // Capture a frame and wait for it to synchronize with the encoder thread. | 635 // Capture a frame and wait for it to synchronize with the encoder thread. |
688 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 636 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
689 WaitForEncodedFrame(1); | 637 sink_.WaitForEncodedFrame(1); |
690 // The encoder will have been configured once. | 638 // The encoder will have been configured once. |
691 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 639 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
692 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 640 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
693 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 641 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
694 | 642 |
695 codec_width_ *= 2; | 643 codec_width_ *= 2; |
696 codec_height_ *= 2; | 644 codec_height_ *= 2; |
697 // Capture a frame with a higher resolution and wait for it to synchronize | 645 // Capture a frame with a higher resolution and wait for it to synchronize |
698 // with the encoder thread. | 646 // with the encoder thread. |
699 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 647 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
700 WaitForEncodedFrame(2); | 648 sink_.WaitForEncodedFrame(2); |
701 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 649 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
702 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 650 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
703 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 651 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
704 | 652 |
705 vie_encoder_->Stop(); | 653 vie_encoder_->Stop(); |
706 } | 654 } |
707 | 655 |
708 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { | 656 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) { |
709 const bool kNackEnabled = true; | 657 const bool kNackEnabled = true; |
710 const size_t kNumStreams = 1; | 658 const size_t kNumStreams = 1; |
711 const size_t kNumTl = 1; | 659 const size_t kNumTl = 1; |
712 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 660 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
713 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 661 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
714 | 662 |
715 // Capture a frame and wait for it to synchronize with the encoder thread. | 663 // Capture a frame and wait for it to synchronize with the encoder thread. |
716 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 664 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
717 WaitForEncodedFrame(1); | 665 sink_.WaitForEncodedFrame(1); |
718 // The encoder have been configured once when the first frame is received. | 666 // The encoder have been configured once when the first frame is received. |
719 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 667 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
720 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 668 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
721 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 669 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
722 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 670 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
723 // Resilience is off for no temporal layers with nack on. | 671 // Resilience is off for no temporal layers with nack on. |
724 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 672 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
725 vie_encoder_->Stop(); | 673 vie_encoder_->Stop(); |
726 } | 674 } |
727 | 675 |
728 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { | 676 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) { |
729 const bool kNackEnabled = true; | 677 const bool kNackEnabled = true; |
730 const size_t kNumStreams = 2; | 678 const size_t kNumStreams = 2; |
731 const size_t kNumTl = 1; | 679 const size_t kNumTl = 1; |
732 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 680 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
733 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 681 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
734 | 682 |
735 // Capture a frame and wait for it to synchronize with the encoder thread. | 683 // Capture a frame and wait for it to synchronize with the encoder thread. |
736 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 684 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
737 WaitForEncodedFrame(1); | 685 sink_.WaitForEncodedFrame(1); |
738 // The encoder have been configured once when the first frame is received. | 686 // The encoder have been configured once when the first frame is received. |
739 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 687 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
740 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 688 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
741 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 689 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
742 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 690 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
743 // Resilience is off for no temporal layers and >1 streams with nack on. | 691 // Resilience is off for no temporal layers and >1 streams with nack on. |
744 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); | 692 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience); |
745 vie_encoder_->Stop(); | 693 vie_encoder_->Stop(); |
746 } | 694 } |
747 | 695 |
748 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { | 696 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) { |
749 const bool kNackEnabled = false; | 697 const bool kNackEnabled = false; |
750 const size_t kNumStreams = 1; | 698 const size_t kNumStreams = 1; |
751 const size_t kNumTl = 1; | 699 const size_t kNumTl = 1; |
752 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 700 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
753 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 701 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
754 | 702 |
755 // Capture a frame and wait for it to synchronize with the encoder thread. | 703 // Capture a frame and wait for it to synchronize with the encoder thread. |
756 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 704 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
757 WaitForEncodedFrame(1); | 705 sink_.WaitForEncodedFrame(1); |
758 // The encoder have been configured once when the first frame is received. | 706 // The encoder have been configured once when the first frame is received. |
759 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 707 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
760 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 708 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
761 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 709 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
762 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 710 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
763 // Resilience is on for no temporal layers with nack off. | 711 // Resilience is on for no temporal layers with nack off. |
764 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 712 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
765 vie_encoder_->Stop(); | 713 vie_encoder_->Stop(); |
766 } | 714 } |
767 | 715 |
768 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { | 716 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) { |
769 const bool kNackEnabled = true; | 717 const bool kNackEnabled = true; |
770 const size_t kNumStreams = 1; | 718 const size_t kNumStreams = 1; |
771 const size_t kNumTl = 2; | 719 const size_t kNumTl = 2; |
772 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); | 720 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
773 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 721 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
774 | 722 |
775 // Capture a frame and wait for it to synchronize with the encoder thread. | 723 // Capture a frame and wait for it to synchronize with the encoder thread. |
776 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 724 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
777 WaitForEncodedFrame(1); | 725 sink_.WaitForEncodedFrame(1); |
778 // The encoder have been configured once when the first frame is received. | 726 // The encoder have been configured once when the first frame is received. |
779 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 727 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
780 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); | 728 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
781 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); | 729 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
782 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); | 730 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
783 // Resilience is on for temporal layers. | 731 // Resilience is on for temporal layers. |
784 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); | 732 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience); |
785 vie_encoder_->Stop(); | 733 vie_encoder_->Stop(); |
786 } | 734 } |
787 | 735 |
(...skipping 23 matching lines...) Expand all Loading... |
811 VerifyNoLimitation(video_source_.sink_wants()); | 759 VerifyNoLimitation(video_source_.sink_wants()); |
812 | 760 |
813 int frame_width = 1280; | 761 int frame_width = 1280; |
814 int frame_height = 720; | 762 int frame_height = 720; |
815 | 763 |
816 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 764 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
817 // request lower resolution. | 765 // request lower resolution. |
818 for (int i = 1; i <= kMaxDowngrades; ++i) { | 766 for (int i = 1; i <= kMaxDowngrades; ++i) { |
819 video_source_.IncomingCapturedFrame( | 767 video_source_.IncomingCapturedFrame( |
820 CreateFrame(i, frame_width, frame_height)); | 768 CreateFrame(i, frame_width, frame_height)); |
821 WaitForEncodedFrame(i); | 769 sink_.WaitForEncodedFrame(i); |
822 | 770 |
823 vie_encoder_->TriggerCpuOveruse(); | 771 vie_encoder_->TriggerCpuOveruse(); |
824 | 772 |
825 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 773 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
826 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 774 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
827 frame_width * frame_height); | 775 frame_width * frame_height); |
828 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 776 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
829 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 777 EXPECT_EQ(i, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
830 | 778 |
831 frame_width /= 2; | 779 frame_width /= 2; |
832 frame_height /= 2; | 780 frame_height /= 2; |
833 } | 781 } |
834 | 782 |
835 // Trigger CPU overuse one more time. This should not trigger a request for | 783 // Trigger CPU overuse one more time. This should not trigger a request for |
836 // lower resolution. | 784 // lower resolution. |
837 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); | 785 rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
838 video_source_.IncomingCapturedFrame( | 786 video_source_.IncomingCapturedFrame( |
839 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); | 787 CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); |
840 WaitForEncodedFrame(kMaxDowngrades + 1); | 788 sink_.WaitForEncodedFrame(kMaxDowngrades + 1); |
841 vie_encoder_->TriggerCpuOveruse(); | 789 vie_encoder_->TriggerCpuOveruse(); |
842 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, | 790 EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
843 current_wants.target_pixel_count); | 791 current_wants.target_pixel_count); |
844 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, | 792 EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
845 current_wants.max_pixel_count); | 793 current_wants.max_pixel_count); |
846 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 794 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
847 EXPECT_EQ(kMaxDowngrades, | 795 EXPECT_EQ(kMaxDowngrades, |
848 stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 796 stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
849 | 797 |
850 // Trigger CPU normal use. | 798 // Trigger CPU normal use. |
(...skipping 14 matching lines...) Expand all Loading... |
865 VerifyNoLimitation(video_source_.sink_wants()); | 813 VerifyNoLimitation(video_source_.sink_wants()); |
866 | 814 |
867 const int kFrameWidth = 1280; | 815 const int kFrameWidth = 1280; |
868 const int kFrameHeight = 720; | 816 const int kFrameHeight = 720; |
869 const int kFrameIntervalMs = 1000 / 30; | 817 const int kFrameIntervalMs = 1000 / 30; |
870 | 818 |
871 int frame_timestamp = 1; | 819 int frame_timestamp = 1; |
872 | 820 |
873 video_source_.IncomingCapturedFrame( | 821 video_source_.IncomingCapturedFrame( |
874 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 822 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
875 WaitForEncodedFrame(frame_timestamp); | 823 sink_.WaitForEncodedFrame(frame_timestamp); |
876 frame_timestamp += kFrameIntervalMs; | 824 frame_timestamp += kFrameIntervalMs; |
877 | 825 |
878 // Trigger CPU overuse. | 826 // Trigger CPU overuse. |
879 vie_encoder_->TriggerCpuOveruse(); | 827 vie_encoder_->TriggerCpuOveruse(); |
880 video_source_.IncomingCapturedFrame( | 828 video_source_.IncomingCapturedFrame( |
881 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 829 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
882 WaitForEncodedFrame(frame_timestamp); | 830 sink_.WaitForEncodedFrame(frame_timestamp); |
883 frame_timestamp += kFrameIntervalMs; | 831 frame_timestamp += kFrameIntervalMs; |
884 | 832 |
885 // Default degradation preference is maintain-framerate, so will lower max | 833 // Default degradation preference is maintain-framerate, so will lower max |
886 // wanted resolution. | 834 // wanted resolution. |
887 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); | 835 EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
888 EXPECT_LT(video_source_.sink_wants().max_pixel_count, | 836 EXPECT_LT(video_source_.sink_wants().max_pixel_count, |
889 kFrameWidth * kFrameHeight); | 837 kFrameWidth * kFrameHeight); |
890 EXPECT_EQ(std::numeric_limits<int>::max(), | 838 EXPECT_EQ(std::numeric_limits<int>::max(), |
891 video_source_.sink_wants().max_framerate_fps); | 839 video_source_.sink_wants().max_framerate_fps); |
892 | 840 |
893 // Set new source, switch to maintain-resolution. | 841 // Set new source, switch to maintain-resolution. |
894 test::FrameForwarder new_video_source; | 842 test::FrameForwarder new_video_source; |
895 vie_encoder_->SetSource( | 843 vie_encoder_->SetSource( |
896 &new_video_source, | 844 &new_video_source, |
897 VideoSendStream::DegradationPreference::kMaintainResolution); | 845 VideoSendStream::DegradationPreference::kMaintainResolution); |
898 | 846 |
899 // Initially no degradation registered. | 847 // Initially no degradation registered. |
900 VerifyNoLimitation(new_video_source.sink_wants()); | 848 VerifyNoLimitation(new_video_source.sink_wants()); |
901 | 849 |
902 // Force an input frame rate to be available, or the adaptation call won't | 850 // Force an input frame rate to be available, or the adaptation call won't |
903 // know what framerate to adapt form. | 851 // know what framerate to adapt form. |
904 const int kInputFps = 30; | 852 const int kInputFps = 30; |
905 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 853 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
906 stats.input_frame_rate = kInputFps; | 854 stats.input_frame_rate = kInputFps; |
907 stats_proxy_->SetMockStats(stats); | 855 stats_proxy_->SetMockStats(stats); |
908 | 856 |
909 vie_encoder_->TriggerCpuOveruse(); | 857 vie_encoder_->TriggerCpuOveruse(); |
910 new_video_source.IncomingCapturedFrame( | 858 new_video_source.IncomingCapturedFrame( |
911 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 859 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
912 WaitForEncodedFrame(frame_timestamp); | 860 sink_.WaitForEncodedFrame(frame_timestamp); |
913 frame_timestamp += kFrameIntervalMs; | 861 frame_timestamp += kFrameIntervalMs; |
914 | 862 |
915 // Some framerate constraint should be set. | 863 // Some framerate constraint should be set. |
916 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); | 864 EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
917 EXPECT_EQ(std::numeric_limits<int>::max(), | 865 EXPECT_EQ(std::numeric_limits<int>::max(), |
918 new_video_source.sink_wants().max_pixel_count); | 866 new_video_source.sink_wants().max_pixel_count); |
919 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); | 867 EXPECT_LT(new_video_source.sink_wants().max_framerate_fps, kInputFps); |
920 | 868 |
921 // Turn off degradation completely. | 869 // Turn off degradation completely. |
922 vie_encoder_->SetSource( | 870 vie_encoder_->SetSource( |
923 &new_video_source, | 871 &new_video_source, |
924 VideoSendStream::DegradationPreference::kDegradationDisabled); | 872 VideoSendStream::DegradationPreference::kDegradationDisabled); |
925 VerifyNoLimitation(new_video_source.sink_wants()); | 873 VerifyNoLimitation(new_video_source.sink_wants()); |
926 | 874 |
927 vie_encoder_->TriggerCpuOveruse(); | 875 vie_encoder_->TriggerCpuOveruse(); |
928 new_video_source.IncomingCapturedFrame( | 876 new_video_source.IncomingCapturedFrame( |
929 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); | 877 CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
930 WaitForEncodedFrame(frame_timestamp); | 878 sink_.WaitForEncodedFrame(frame_timestamp); |
931 frame_timestamp += kFrameIntervalMs; | 879 frame_timestamp += kFrameIntervalMs; |
932 | 880 |
933 // Still no degradation. | 881 // Still no degradation. |
934 VerifyNoLimitation(new_video_source.sink_wants()); | 882 VerifyNoLimitation(new_video_source.sink_wants()); |
935 | 883 |
936 // Calling SetSource with resolution scaling enabled apply the old SinkWants. | 884 // Calling SetSource with resolution scaling enabled apply the old SinkWants. |
937 vie_encoder_->SetSource( | 885 vie_encoder_->SetSource( |
938 &new_video_source, | 886 &new_video_source, |
939 VideoSendStream::DegradationPreference::kMaintainFramerate); | 887 VideoSendStream::DegradationPreference::kMaintainFramerate); |
940 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, | 888 EXPECT_LT(new_video_source.sink_wants().max_pixel_count, |
(...skipping 13 matching lines...) Expand all Loading... |
954 | 902 |
955 vie_encoder_->Stop(); | 903 vie_encoder_->Stop(); |
956 } | 904 } |
957 | 905 |
958 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { | 906 TEST_F(ViEEncoderTest, StatsTracksQualityAdaptationStats) { |
959 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 907 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
960 | 908 |
961 const int kWidth = 1280; | 909 const int kWidth = 1280; |
962 const int kHeight = 720; | 910 const int kHeight = 720; |
963 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 911 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
964 WaitForEncodedFrame(1); | 912 sink_.WaitForEncodedFrame(1); |
965 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 913 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
966 EXPECT_FALSE(stats.bw_limited_resolution); | 914 EXPECT_FALSE(stats.bw_limited_resolution); |
967 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 915 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
968 | 916 |
969 // Trigger adapt down. | 917 // Trigger adapt down. |
970 vie_encoder_->TriggerQualityLow(); | 918 vie_encoder_->TriggerQualityLow(); |
971 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 919 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
972 WaitForEncodedFrame(2); | 920 sink_.WaitForEncodedFrame(2); |
973 | 921 |
974 stats = stats_proxy_->GetStats(); | 922 stats = stats_proxy_->GetStats(); |
975 EXPECT_TRUE(stats.bw_limited_resolution); | 923 EXPECT_TRUE(stats.bw_limited_resolution); |
976 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 924 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
977 | 925 |
978 // Trigger adapt up. | 926 // Trigger adapt up. |
979 vie_encoder_->TriggerQualityHigh(); | 927 vie_encoder_->TriggerQualityHigh(); |
980 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 928 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
981 WaitForEncodedFrame(3); | 929 sink_.WaitForEncodedFrame(3); |
982 | 930 |
983 stats = stats_proxy_->GetStats(); | 931 stats = stats_proxy_->GetStats(); |
984 EXPECT_FALSE(stats.bw_limited_resolution); | 932 EXPECT_FALSE(stats.bw_limited_resolution); |
985 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); | 933 EXPECT_EQ(2, stats.number_of_quality_adapt_changes); |
986 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 934 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
987 | 935 |
988 vie_encoder_->Stop(); | 936 vie_encoder_->Stop(); |
989 } | 937 } |
990 | 938 |
991 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { | 939 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStats) { |
992 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 940 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
993 | 941 |
994 const int kWidth = 1280; | 942 const int kWidth = 1280; |
995 const int kHeight = 720; | 943 const int kHeight = 720; |
996 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 944 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
997 WaitForEncodedFrame(1); | 945 sink_.WaitForEncodedFrame(1); |
998 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 946 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
999 EXPECT_FALSE(stats.cpu_limited_resolution); | 947 EXPECT_FALSE(stats.cpu_limited_resolution); |
1000 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 948 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1001 | 949 |
1002 // Trigger CPU overuse. | 950 // Trigger CPU overuse. |
1003 vie_encoder_->TriggerCpuOveruse(); | 951 vie_encoder_->TriggerCpuOveruse(); |
1004 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 952 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1005 WaitForEncodedFrame(2); | 953 sink_.WaitForEncodedFrame(2); |
1006 | 954 |
1007 stats = stats_proxy_->GetStats(); | 955 stats = stats_proxy_->GetStats(); |
1008 EXPECT_TRUE(stats.cpu_limited_resolution); | 956 EXPECT_TRUE(stats.cpu_limited_resolution); |
1009 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 957 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1010 | 958 |
1011 // Trigger CPU normal use. | 959 // Trigger CPU normal use. |
1012 vie_encoder_->TriggerCpuNormalUsage(); | 960 vie_encoder_->TriggerCpuNormalUsage(); |
1013 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 961 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1014 WaitForEncodedFrame(3); | 962 sink_.WaitForEncodedFrame(3); |
1015 | 963 |
1016 stats = stats_proxy_->GetStats(); | 964 stats = stats_proxy_->GetStats(); |
1017 EXPECT_FALSE(stats.cpu_limited_resolution); | 965 EXPECT_FALSE(stats.cpu_limited_resolution); |
1018 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 966 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1019 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 967 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1020 | 968 |
1021 vie_encoder_->Stop(); | 969 vie_encoder_->Stop(); |
1022 } | 970 } |
1023 | 971 |
1024 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { | 972 TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) { |
1025 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 973 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1026 | 974 |
1027 const int kWidth = 1280; | 975 const int kWidth = 1280; |
1028 const int kHeight = 720; | 976 const int kHeight = 720; |
1029 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 977 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1030 WaitForEncodedFrame(1); | 978 sink_.WaitForEncodedFrame(1); |
1031 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 979 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1032 EXPECT_FALSE(stats.bw_limited_resolution); | 980 EXPECT_FALSE(stats.bw_limited_resolution); |
1033 EXPECT_FALSE(stats.cpu_limited_resolution); | 981 EXPECT_FALSE(stats.cpu_limited_resolution); |
1034 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 982 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1035 | 983 |
1036 // Trigger CPU overuse. | 984 // Trigger CPU overuse. |
1037 vie_encoder_->TriggerCpuOveruse(); | 985 vie_encoder_->TriggerCpuOveruse(); |
1038 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 986 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1039 WaitForEncodedFrame(2); | 987 sink_.WaitForEncodedFrame(2); |
1040 stats = stats_proxy_->GetStats(); | 988 stats = stats_proxy_->GetStats(); |
1041 EXPECT_FALSE(stats.bw_limited_resolution); | 989 EXPECT_FALSE(stats.bw_limited_resolution); |
1042 EXPECT_TRUE(stats.cpu_limited_resolution); | 990 EXPECT_TRUE(stats.cpu_limited_resolution); |
1043 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 991 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1044 | 992 |
1045 // Set new source with adaptation still enabled. | 993 // Set new source with adaptation still enabled. |
1046 test::FrameForwarder new_video_source; | 994 test::FrameForwarder new_video_source; |
1047 vie_encoder_->SetSource( | 995 vie_encoder_->SetSource( |
1048 &new_video_source, | 996 &new_video_source, |
1049 VideoSendStream::DegradationPreference::kMaintainFramerate); | 997 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1050 | 998 |
1051 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 999 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1052 WaitForEncodedFrame(3); | 1000 sink_.WaitForEncodedFrame(3); |
1053 stats = stats_proxy_->GetStats(); | 1001 stats = stats_proxy_->GetStats(); |
1054 EXPECT_FALSE(stats.bw_limited_resolution); | 1002 EXPECT_FALSE(stats.bw_limited_resolution); |
1055 EXPECT_TRUE(stats.cpu_limited_resolution); | 1003 EXPECT_TRUE(stats.cpu_limited_resolution); |
1056 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1004 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1057 | 1005 |
1058 // Set adaptation disabled. | 1006 // Set adaptation disabled. |
1059 vie_encoder_->SetSource( | 1007 vie_encoder_->SetSource( |
1060 &new_video_source, | 1008 &new_video_source, |
1061 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1009 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1062 | 1010 |
1063 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1011 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1064 WaitForEncodedFrame(4); | 1012 sink_.WaitForEncodedFrame(4); |
1065 stats = stats_proxy_->GetStats(); | 1013 stats = stats_proxy_->GetStats(); |
1066 EXPECT_FALSE(stats.bw_limited_resolution); | 1014 EXPECT_FALSE(stats.bw_limited_resolution); |
1067 EXPECT_FALSE(stats.cpu_limited_resolution); | 1015 EXPECT_FALSE(stats.cpu_limited_resolution); |
1068 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1016 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1069 | 1017 |
1070 // Set adaptation back to enabled. | 1018 // Set adaptation back to enabled. |
1071 vie_encoder_->SetSource( | 1019 vie_encoder_->SetSource( |
1072 &new_video_source, | 1020 &new_video_source, |
1073 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1021 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1074 | 1022 |
1075 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1023 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1076 WaitForEncodedFrame(5); | 1024 sink_.WaitForEncodedFrame(5); |
1077 stats = stats_proxy_->GetStats(); | 1025 stats = stats_proxy_->GetStats(); |
1078 EXPECT_FALSE(stats.bw_limited_resolution); | 1026 EXPECT_FALSE(stats.bw_limited_resolution); |
1079 EXPECT_TRUE(stats.cpu_limited_resolution); | 1027 EXPECT_TRUE(stats.cpu_limited_resolution); |
1080 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1028 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1081 | 1029 |
1082 // Trigger CPU normal use. | 1030 // Trigger CPU normal use. |
1083 vie_encoder_->TriggerCpuNormalUsage(); | 1031 vie_encoder_->TriggerCpuNormalUsage(); |
1084 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 1032 new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
1085 WaitForEncodedFrame(6); | 1033 sink_.WaitForEncodedFrame(6); |
1086 stats = stats_proxy_->GetStats(); | 1034 stats = stats_proxy_->GetStats(); |
1087 EXPECT_FALSE(stats.bw_limited_resolution); | 1035 EXPECT_FALSE(stats.bw_limited_resolution); |
1088 EXPECT_FALSE(stats.cpu_limited_resolution); | 1036 EXPECT_FALSE(stats.cpu_limited_resolution); |
1089 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1037 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1090 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1038 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1091 | 1039 |
1092 vie_encoder_->Stop(); | 1040 vie_encoder_->Stop(); |
1093 } | 1041 } |
1094 | 1042 |
1095 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { | 1043 TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) { |
1096 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1044 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1097 | 1045 |
1098 const int kWidth = 1280; | 1046 const int kWidth = 1280; |
1099 const int kHeight = 720; | 1047 const int kHeight = 720; |
1100 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1048 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1101 WaitForEncodedFrame(1); | 1049 sink_.WaitForEncodedFrame(1); |
1102 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1050 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1103 EXPECT_FALSE(stats.bw_limited_resolution); | 1051 EXPECT_FALSE(stats.bw_limited_resolution); |
1104 EXPECT_FALSE(stats.bw_limited_framerate); | 1052 EXPECT_FALSE(stats.bw_limited_framerate); |
1105 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1053 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1106 | 1054 |
1107 // Set new source with adaptation still enabled. | 1055 // Set new source with adaptation still enabled. |
1108 test::FrameForwarder new_video_source; | 1056 test::FrameForwarder new_video_source; |
1109 vie_encoder_->SetSource(&new_video_source, | 1057 vie_encoder_->SetSource(&new_video_source, |
1110 VideoSendStream::DegradationPreference::kBalanced); | 1058 VideoSendStream::DegradationPreference::kBalanced); |
1111 | 1059 |
1112 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1060 new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1113 WaitForEncodedFrame(2); | 1061 sink_.WaitForEncodedFrame(2); |
1114 stats = stats_proxy_->GetStats(); | 1062 stats = stats_proxy_->GetStats(); |
1115 EXPECT_FALSE(stats.bw_limited_resolution); | 1063 EXPECT_FALSE(stats.bw_limited_resolution); |
1116 EXPECT_FALSE(stats.bw_limited_framerate); | 1064 EXPECT_FALSE(stats.bw_limited_framerate); |
1117 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1065 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1118 | 1066 |
1119 // Trigger adapt down. | 1067 // Trigger adapt down. |
1120 vie_encoder_->TriggerQualityLow(); | 1068 vie_encoder_->TriggerQualityLow(); |
1121 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1069 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1122 WaitForEncodedFrame(3); | 1070 sink_.WaitForEncodedFrame(3); |
1123 stats = stats_proxy_->GetStats(); | 1071 stats = stats_proxy_->GetStats(); |
1124 EXPECT_TRUE(stats.bw_limited_resolution); | 1072 EXPECT_TRUE(stats.bw_limited_resolution); |
1125 EXPECT_FALSE(stats.bw_limited_framerate); | 1073 EXPECT_FALSE(stats.bw_limited_framerate); |
1126 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1074 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1127 | 1075 |
1128 // Set new source with adaptation still enabled. | 1076 // Set new source with adaptation still enabled. |
1129 vie_encoder_->SetSource(&new_video_source, | 1077 vie_encoder_->SetSource(&new_video_source, |
1130 VideoSendStream::DegradationPreference::kBalanced); | 1078 VideoSendStream::DegradationPreference::kBalanced); |
1131 | 1079 |
1132 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1080 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1133 WaitForEncodedFrame(4); | 1081 sink_.WaitForEncodedFrame(4); |
1134 stats = stats_proxy_->GetStats(); | 1082 stats = stats_proxy_->GetStats(); |
1135 EXPECT_TRUE(stats.bw_limited_resolution); | 1083 EXPECT_TRUE(stats.bw_limited_resolution); |
1136 EXPECT_FALSE(stats.bw_limited_framerate); | 1084 EXPECT_FALSE(stats.bw_limited_framerate); |
1137 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1085 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1138 | 1086 |
1139 // Disable resolution scaling. | 1087 // Disable resolution scaling. |
1140 vie_encoder_->SetSource( | 1088 vie_encoder_->SetSource( |
1141 &new_video_source, | 1089 &new_video_source, |
1142 VideoSendStream::DegradationPreference::kMaintainResolution); | 1090 VideoSendStream::DegradationPreference::kMaintainResolution); |
1143 | 1091 |
1144 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1092 new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1145 WaitForEncodedFrame(5); | 1093 sink_.WaitForEncodedFrame(5); |
1146 stats = stats_proxy_->GetStats(); | 1094 stats = stats_proxy_->GetStats(); |
1147 EXPECT_FALSE(stats.bw_limited_resolution); | 1095 EXPECT_FALSE(stats.bw_limited_resolution); |
1148 EXPECT_FALSE(stats.bw_limited_framerate); | 1096 EXPECT_FALSE(stats.bw_limited_framerate); |
1149 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); | 1097 EXPECT_EQ(1, stats.number_of_quality_adapt_changes); |
1150 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1098 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1151 | 1099 |
1152 vie_encoder_->Stop(); | 1100 vie_encoder_->Stop(); |
1153 } | 1101 } |
1154 | 1102 |
1155 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { | 1103 TEST_F(ViEEncoderTest, QualityAdaptationStatsAreResetWhenScalerIsDisabled) { |
1156 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1104 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1157 | 1105 |
1158 const int kWidth = 1280; | 1106 const int kWidth = 1280; |
1159 const int kHeight = 720; | 1107 const int kHeight = 720; |
1160 video_source_.set_adaptation_enabled(true); | 1108 video_source_.set_adaptation_enabled(true); |
1161 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1109 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1162 WaitForEncodedFrame(1); | 1110 sink_.WaitForEncodedFrame(1); |
1163 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1111 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1164 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1112 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1165 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1113 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1166 | 1114 |
1167 // Trigger adapt down. | 1115 // Trigger adapt down. |
1168 vie_encoder_->TriggerQualityLow(); | 1116 vie_encoder_->TriggerQualityLow(); |
1169 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1117 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1170 WaitForEncodedFrame(2); | 1118 sink_.WaitForEncodedFrame(2); |
1171 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1119 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1172 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1120 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1173 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1121 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1174 | 1122 |
1175 // Trigger overuse. | 1123 // Trigger overuse. |
1176 vie_encoder_->TriggerCpuOveruse(); | 1124 vie_encoder_->TriggerCpuOveruse(); |
1177 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1125 video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1178 WaitForEncodedFrame(3); | 1126 sink_.WaitForEncodedFrame(3); |
1179 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1127 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1180 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1128 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1181 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1129 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1182 | 1130 |
1183 // Set source with adaptation still enabled but quality scaler is off. | 1131 // Set source with adaptation still enabled but quality scaler is off. |
1184 fake_encoder_.SetQualityScaling(false); | 1132 fake_encoder_.SetQualityScaling(false); |
1185 vie_encoder_->SetSource( | 1133 vie_encoder_->SetSource( |
1186 &video_source_, | 1134 &video_source_, |
1187 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1135 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1188 | 1136 |
1189 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1137 video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1190 WaitForEncodedFrame(4); | 1138 sink_.WaitForEncodedFrame(4); |
1191 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1139 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1192 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1140 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1193 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1141 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1194 | 1142 |
1195 vie_encoder_->Stop(); | 1143 vie_encoder_->Stop(); |
1196 } | 1144 } |
1197 | 1145 |
1198 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStatsWhenSwitchingSource) { | 1146 TEST_F(ViEEncoderTest, StatsTracksCpuAdaptationStatsWhenSwitchingSource) { |
1199 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1147 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1200 | 1148 |
1201 const int kWidth = 1280; | 1149 const int kWidth = 1280; |
1202 const int kHeight = 720; | 1150 const int kHeight = 720; |
1203 int sequence = 1; | 1151 int sequence = 1; |
1204 | 1152 |
1205 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1153 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1206 WaitForEncodedFrame(sequence++); | 1154 sink_.WaitForEncodedFrame(sequence++); |
1207 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1155 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1208 EXPECT_FALSE(stats.cpu_limited_resolution); | 1156 EXPECT_FALSE(stats.cpu_limited_resolution); |
1209 EXPECT_FALSE(stats.cpu_limited_framerate); | 1157 EXPECT_FALSE(stats.cpu_limited_framerate); |
1210 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); | 1158 EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
1211 | 1159 |
1212 // Trigger CPU overuse, should now adapt down. | 1160 // Trigger CPU overuse, should now adapt down. |
1213 vie_encoder_->TriggerCpuOveruse(); | 1161 vie_encoder_->TriggerCpuOveruse(); |
1214 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1162 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1215 WaitForEncodedFrame(sequence++); | 1163 sink_.WaitForEncodedFrame(sequence++); |
1216 stats = stats_proxy_->GetStats(); | 1164 stats = stats_proxy_->GetStats(); |
1217 EXPECT_TRUE(stats.cpu_limited_resolution); | 1165 EXPECT_TRUE(stats.cpu_limited_resolution); |
1218 EXPECT_FALSE(stats.cpu_limited_framerate); | 1166 EXPECT_FALSE(stats.cpu_limited_framerate); |
1219 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1167 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1220 | 1168 |
1221 // Set new source with adaptation still enabled. | 1169 // Set new source with adaptation still enabled. |
1222 test::FrameForwarder new_video_source; | 1170 test::FrameForwarder new_video_source; |
1223 vie_encoder_->SetSource( | 1171 vie_encoder_->SetSource( |
1224 &new_video_source, | 1172 &new_video_source, |
1225 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1173 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1226 | 1174 |
1227 new_video_source.IncomingCapturedFrame( | 1175 new_video_source.IncomingCapturedFrame( |
1228 CreateFrame(sequence, kWidth, kHeight)); | 1176 CreateFrame(sequence, kWidth, kHeight)); |
1229 WaitForEncodedFrame(sequence++); | 1177 sink_.WaitForEncodedFrame(sequence++); |
1230 stats = stats_proxy_->GetStats(); | 1178 stats = stats_proxy_->GetStats(); |
1231 EXPECT_TRUE(stats.cpu_limited_resolution); | 1179 EXPECT_TRUE(stats.cpu_limited_resolution); |
1232 EXPECT_FALSE(stats.cpu_limited_framerate); | 1180 EXPECT_FALSE(stats.cpu_limited_framerate); |
1233 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1181 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1234 | 1182 |
1235 // Set cpu adaptation by frame dropping. | 1183 // Set cpu adaptation by frame dropping. |
1236 vie_encoder_->SetSource( | 1184 vie_encoder_->SetSource( |
1237 &new_video_source, | 1185 &new_video_source, |
1238 VideoSendStream::DegradationPreference::kMaintainResolution); | 1186 VideoSendStream::DegradationPreference::kMaintainResolution); |
1239 new_video_source.IncomingCapturedFrame( | 1187 new_video_source.IncomingCapturedFrame( |
1240 CreateFrame(sequence, kWidth, kHeight)); | 1188 CreateFrame(sequence, kWidth, kHeight)); |
1241 WaitForEncodedFrame(sequence++); | 1189 sink_.WaitForEncodedFrame(sequence++); |
1242 stats = stats_proxy_->GetStats(); | 1190 stats = stats_proxy_->GetStats(); |
1243 // Not adapted at first. | 1191 // Not adapted at first. |
1244 EXPECT_FALSE(stats.cpu_limited_resolution); | 1192 EXPECT_FALSE(stats.cpu_limited_resolution); |
1245 EXPECT_FALSE(stats.cpu_limited_framerate); | 1193 EXPECT_FALSE(stats.cpu_limited_framerate); |
1246 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); | 1194 EXPECT_EQ(1, stats.number_of_cpu_adapt_changes); |
1247 | 1195 |
1248 // Force an input frame rate to be available, or the adaptation call won't | 1196 // Force an input frame rate to be available, or the adaptation call won't |
1249 // know what framerate to adapt from. | 1197 // know what framerate to adapt from. |
1250 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); | 1198 VideoSendStream::Stats mock_stats = stats_proxy_->GetStats(); |
1251 mock_stats.input_frame_rate = 30; | 1199 mock_stats.input_frame_rate = 30; |
1252 stats_proxy_->SetMockStats(mock_stats); | 1200 stats_proxy_->SetMockStats(mock_stats); |
1253 vie_encoder_->TriggerCpuOveruse(); | 1201 vie_encoder_->TriggerCpuOveruse(); |
1254 stats_proxy_->ResetMockStats(); | 1202 stats_proxy_->ResetMockStats(); |
1255 | 1203 |
1256 new_video_source.IncomingCapturedFrame( | 1204 new_video_source.IncomingCapturedFrame( |
1257 CreateFrame(sequence, kWidth, kHeight)); | 1205 CreateFrame(sequence, kWidth, kHeight)); |
1258 WaitForEncodedFrame(sequence++); | 1206 sink_.WaitForEncodedFrame(sequence++); |
1259 | 1207 |
1260 // Framerate now adapted. | 1208 // Framerate now adapted. |
1261 stats = stats_proxy_->GetStats(); | 1209 stats = stats_proxy_->GetStats(); |
1262 EXPECT_FALSE(stats.cpu_limited_resolution); | 1210 EXPECT_FALSE(stats.cpu_limited_resolution); |
1263 EXPECT_TRUE(stats.cpu_limited_framerate); | 1211 EXPECT_TRUE(stats.cpu_limited_framerate); |
1264 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1212 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1265 | 1213 |
1266 // Disable CPU adaptation. | 1214 // Disable CPU adaptation. |
1267 vie_encoder_->SetSource( | 1215 vie_encoder_->SetSource( |
1268 &new_video_source, | 1216 &new_video_source, |
1269 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1217 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1270 new_video_source.IncomingCapturedFrame( | 1218 new_video_source.IncomingCapturedFrame( |
1271 CreateFrame(sequence, kWidth, kHeight)); | 1219 CreateFrame(sequence, kWidth, kHeight)); |
1272 WaitForEncodedFrame(sequence++); | 1220 sink_.WaitForEncodedFrame(sequence++); |
1273 | 1221 |
1274 stats = stats_proxy_->GetStats(); | 1222 stats = stats_proxy_->GetStats(); |
1275 EXPECT_FALSE(stats.cpu_limited_resolution); | 1223 EXPECT_FALSE(stats.cpu_limited_resolution); |
1276 EXPECT_FALSE(stats.cpu_limited_framerate); | 1224 EXPECT_FALSE(stats.cpu_limited_framerate); |
1277 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1225 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1278 | 1226 |
1279 // Try to trigger overuse. Should not succeed. | 1227 // Try to trigger overuse. Should not succeed. |
1280 stats_proxy_->SetMockStats(mock_stats); | 1228 stats_proxy_->SetMockStats(mock_stats); |
1281 vie_encoder_->TriggerCpuOveruse(); | 1229 vie_encoder_->TriggerCpuOveruse(); |
1282 stats_proxy_->ResetMockStats(); | 1230 stats_proxy_->ResetMockStats(); |
1283 | 1231 |
1284 stats = stats_proxy_->GetStats(); | 1232 stats = stats_proxy_->GetStats(); |
1285 EXPECT_FALSE(stats.cpu_limited_resolution); | 1233 EXPECT_FALSE(stats.cpu_limited_resolution); |
1286 EXPECT_FALSE(stats.cpu_limited_framerate); | 1234 EXPECT_FALSE(stats.cpu_limited_framerate); |
1287 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1235 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1288 | 1236 |
1289 // Switch back the source with resolution adaptation enabled. | 1237 // Switch back the source with resolution adaptation enabled. |
1290 vie_encoder_->SetSource( | 1238 vie_encoder_->SetSource( |
1291 &video_source_, | 1239 &video_source_, |
1292 VideoSendStream::DegradationPreference::kMaintainFramerate); | 1240 VideoSendStream::DegradationPreference::kMaintainFramerate); |
1293 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1241 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1294 WaitForEncodedFrame(sequence++); | 1242 sink_.WaitForEncodedFrame(sequence++); |
1295 stats = stats_proxy_->GetStats(); | 1243 stats = stats_proxy_->GetStats(); |
1296 EXPECT_TRUE(stats.cpu_limited_resolution); | 1244 EXPECT_TRUE(stats.cpu_limited_resolution); |
1297 EXPECT_FALSE(stats.cpu_limited_framerate); | 1245 EXPECT_FALSE(stats.cpu_limited_framerate); |
1298 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 1246 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
1299 | 1247 |
1300 // Trigger CPU normal usage. | 1248 // Trigger CPU normal usage. |
1301 vie_encoder_->TriggerCpuNormalUsage(); | 1249 vie_encoder_->TriggerCpuNormalUsage(); |
1302 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); | 1250 video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
1303 WaitForEncodedFrame(sequence++); | 1251 sink_.WaitForEncodedFrame(sequence++); |
1304 stats = stats_proxy_->GetStats(); | 1252 stats = stats_proxy_->GetStats(); |
1305 EXPECT_FALSE(stats.cpu_limited_resolution); | 1253 EXPECT_FALSE(stats.cpu_limited_resolution); |
1306 EXPECT_FALSE(stats.cpu_limited_framerate); | 1254 EXPECT_FALSE(stats.cpu_limited_framerate); |
1307 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1255 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1308 | 1256 |
1309 // Back to the source with adaptation off, set it back to maintain-resolution. | 1257 // Back to the source with adaptation off, set it back to maintain-resolution. |
1310 vie_encoder_->SetSource( | 1258 vie_encoder_->SetSource( |
1311 &new_video_source, | 1259 &new_video_source, |
1312 VideoSendStream::DegradationPreference::kMaintainResolution); | 1260 VideoSendStream::DegradationPreference::kMaintainResolution); |
1313 new_video_source.IncomingCapturedFrame( | 1261 new_video_source.IncomingCapturedFrame( |
1314 CreateFrame(sequence, kWidth, kHeight)); | 1262 CreateFrame(sequence, kWidth, kHeight)); |
1315 WaitForEncodedFrame(sequence++); | 1263 sink_.WaitForEncodedFrame(sequence++); |
1316 stats = stats_proxy_->GetStats(); | 1264 stats = stats_proxy_->GetStats(); |
1317 // Disabled, since we previously switched the source to disabled. | 1265 // Disabled, since we previously switched the source to disabled. |
1318 EXPECT_FALSE(stats.cpu_limited_resolution); | 1266 EXPECT_FALSE(stats.cpu_limited_resolution); |
1319 EXPECT_TRUE(stats.cpu_limited_framerate); | 1267 EXPECT_TRUE(stats.cpu_limited_framerate); |
1320 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); | 1268 EXPECT_EQ(3, stats.number_of_cpu_adapt_changes); |
1321 | 1269 |
1322 // Trigger CPU normal usage. | 1270 // Trigger CPU normal usage. |
1323 vie_encoder_->TriggerCpuNormalUsage(); | 1271 vie_encoder_->TriggerCpuNormalUsage(); |
1324 new_video_source.IncomingCapturedFrame( | 1272 new_video_source.IncomingCapturedFrame( |
1325 CreateFrame(sequence, kWidth, kHeight)); | 1273 CreateFrame(sequence, kWidth, kHeight)); |
1326 WaitForEncodedFrame(sequence++); | 1274 sink_.WaitForEncodedFrame(sequence++); |
1327 stats = stats_proxy_->GetStats(); | 1275 stats = stats_proxy_->GetStats(); |
1328 EXPECT_FALSE(stats.cpu_limited_resolution); | 1276 EXPECT_FALSE(stats.cpu_limited_resolution); |
1329 EXPECT_FALSE(stats.cpu_limited_framerate); | 1277 EXPECT_FALSE(stats.cpu_limited_framerate); |
1330 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); | 1278 EXPECT_EQ(4, stats.number_of_cpu_adapt_changes); |
1331 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); | 1279 EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
1332 | 1280 |
1333 vie_encoder_->Stop(); | 1281 vie_encoder_->Stop(); |
1334 } | 1282 } |
1335 | 1283 |
1336 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { | 1284 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { |
1337 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1285 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1338 | 1286 |
1339 const int kWidth = 1280; | 1287 const int kWidth = 1280; |
1340 const int kHeight = 720; | 1288 const int kHeight = 720; |
1341 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1289 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1342 WaitForEncodedFrame(1); | 1290 sink_.WaitForEncodedFrame(1); |
1343 | 1291 |
1344 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 1292 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
1345 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, | 1293 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
1346 stats.preferred_media_bitrate_bps); | 1294 stats.preferred_media_bitrate_bps); |
1347 | 1295 |
1348 vie_encoder_->Stop(); | 1296 vie_encoder_->Stop(); |
1349 } | 1297 } |
1350 | 1298 |
1351 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { | 1299 TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
1352 const int kWidth = 1280; | 1300 const int kWidth = 1280; |
1353 const int kHeight = 720; | 1301 const int kHeight = 720; |
1354 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1302 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1355 | 1303 |
1356 // Expect no scaling to begin with. | 1304 // Expect no scaling to begin with. |
1357 VerifyNoLimitation(video_source_.sink_wants()); | 1305 VerifyNoLimitation(video_source_.sink_wants()); |
1358 | 1306 |
1359 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1307 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1360 WaitForEncodedFrame(1); | 1308 sink_.WaitForEncodedFrame(1); |
1361 | 1309 |
1362 // Trigger scale down. | 1310 // Trigger scale down. |
1363 vie_encoder_->TriggerQualityLow(); | 1311 vie_encoder_->TriggerQualityLow(); |
1364 | 1312 |
1365 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1313 video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1366 WaitForEncodedFrame(2); | 1314 sink_.WaitForEncodedFrame(2); |
1367 | 1315 |
1368 // Expect a scale down. | 1316 // Expect a scale down. |
1369 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); | 1317 EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
1370 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1318 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1371 | 1319 |
1372 // Set resolution scaling disabled. | 1320 // Set resolution scaling disabled. |
1373 test::FrameForwarder new_video_source; | 1321 test::FrameForwarder new_video_source; |
1374 vie_encoder_->SetSource( | 1322 vie_encoder_->SetSource( |
1375 &new_video_source, | 1323 &new_video_source, |
1376 VideoSendStream::DegradationPreference::kMaintainResolution); | 1324 VideoSendStream::DegradationPreference::kMaintainResolution); |
1377 | 1325 |
1378 // Trigger scale down. | 1326 // Trigger scale down. |
1379 vie_encoder_->TriggerQualityLow(); | 1327 vie_encoder_->TriggerQualityLow(); |
1380 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1328 new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1381 WaitForEncodedFrame(3); | 1329 sink_.WaitForEncodedFrame(3); |
1382 | 1330 |
1383 // Expect no scaling. | 1331 // Expect no scaling. |
1384 EXPECT_EQ(std::numeric_limits<int>::max(), | 1332 EXPECT_EQ(std::numeric_limits<int>::max(), |
1385 new_video_source.sink_wants().max_pixel_count); | 1333 new_video_source.sink_wants().max_pixel_count); |
1386 | 1334 |
1387 // Trigger scale up. | 1335 // Trigger scale up. |
1388 vie_encoder_->TriggerQualityHigh(); | 1336 vie_encoder_->TriggerQualityHigh(); |
1389 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1337 new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1390 WaitForEncodedFrame(4); | 1338 sink_.WaitForEncodedFrame(4); |
1391 | 1339 |
1392 // Expect nothing to change, still no scaling. | 1340 // Expect nothing to change, still no scaling. |
1393 EXPECT_EQ(std::numeric_limits<int>::max(), | 1341 EXPECT_EQ(std::numeric_limits<int>::max(), |
1394 new_video_source.sink_wants().max_pixel_count); | 1342 new_video_source.sink_wants().max_pixel_count); |
1395 | 1343 |
1396 vie_encoder_->Stop(); | 1344 vie_encoder_->Stop(); |
1397 } | 1345 } |
1398 | 1346 |
1399 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { | 1347 TEST_F(ViEEncoderTest, SkipsSameAdaptDownRequest_MaintainFramerateMode) { |
1400 const int kWidth = 1280; | 1348 const int kWidth = 1280; |
1401 const int kHeight = 720; | 1349 const int kHeight = 720; |
1402 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1350 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1403 | 1351 |
1404 // Enable kMaintainFramerate preference, no initial limitation. | 1352 // Enable kMaintainFramerate preference, no initial limitation. |
1405 test::FrameForwarder source; | 1353 test::FrameForwarder source; |
1406 vie_encoder_->SetSource( | 1354 vie_encoder_->SetSource( |
1407 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1355 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1408 | 1356 |
1409 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1357 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1410 WaitForEncodedFrame(1); | 1358 sink_.WaitForEncodedFrame(1); |
1411 VerifyNoLimitation(source.sink_wants()); | 1359 VerifyNoLimitation(source.sink_wants()); |
1412 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1360 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1413 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1361 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1414 | 1362 |
1415 // Trigger adapt down, expect scaled down resolution. | 1363 // Trigger adapt down, expect scaled down resolution. |
1416 vie_encoder_->TriggerCpuOveruse(); | 1364 vie_encoder_->TriggerCpuOveruse(); |
1417 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1365 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1418 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; | 1366 const int kLastMaxPixelCount = source.sink_wants().max_pixel_count; |
1419 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1367 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1420 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1368 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
(...skipping 11 matching lines...) Expand all Loading... |
1432 const int kWidth = 1280; | 1380 const int kWidth = 1280; |
1433 const int kHeight = 720; | 1381 const int kHeight = 720; |
1434 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1382 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1435 | 1383 |
1436 // Enable kMaintainFramerate preference, no initial limitation. | 1384 // Enable kMaintainFramerate preference, no initial limitation. |
1437 test::FrameForwarder source; | 1385 test::FrameForwarder source; |
1438 vie_encoder_->SetSource( | 1386 vie_encoder_->SetSource( |
1439 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1387 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1440 | 1388 |
1441 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1389 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1442 WaitForEncodedFrame(kWidth, kHeight); | 1390 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1443 VerifyNoLimitation(source.sink_wants()); | 1391 VerifyNoLimitation(source.sink_wants()); |
1444 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1392 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1445 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1393 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1446 | 1394 |
1447 // Trigger adapt up, expect no change. | 1395 // Trigger adapt up, expect no change. |
1448 vie_encoder_->TriggerCpuNormalUsage(); | 1396 vie_encoder_->TriggerCpuNormalUsage(); |
1449 VerifyNoLimitation(source.sink_wants()); | 1397 VerifyNoLimitation(source.sink_wants()); |
1450 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1398 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1451 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1399 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1452 | 1400 |
1453 vie_encoder_->Stop(); | 1401 vie_encoder_->Stop(); |
1454 } | 1402 } |
1455 | 1403 |
1456 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainResolutionMode) { | 1404 TEST_F(ViEEncoderTest, NoChangeForInitialNormalUsage_MaintainResolutionMode) { |
1457 const int kWidth = 1280; | 1405 const int kWidth = 1280; |
1458 const int kHeight = 720; | 1406 const int kHeight = 720; |
1459 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1407 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1460 | 1408 |
1461 // Enable kMaintainResolution preference, no initial limitation. | 1409 // Enable kMaintainResolution preference, no initial limitation. |
1462 test::FrameForwarder source; | 1410 test::FrameForwarder source; |
1463 vie_encoder_->SetSource( | 1411 vie_encoder_->SetSource( |
1464 &source, VideoSendStream::DegradationPreference::kMaintainResolution); | 1412 &source, VideoSendStream::DegradationPreference::kMaintainResolution); |
1465 | 1413 |
1466 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1414 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1467 WaitForEncodedFrame(kWidth, kHeight); | 1415 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1468 VerifyNoLimitation(source.sink_wants()); | 1416 VerifyNoLimitation(source.sink_wants()); |
1469 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1417 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1470 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1418 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1471 | 1419 |
1472 // Trigger adapt up, expect no change. | 1420 // Trigger adapt up, expect no change. |
1473 vie_encoder_->TriggerCpuNormalUsage(); | 1421 vie_encoder_->TriggerCpuNormalUsage(); |
1474 VerifyNoLimitation(source.sink_wants()); | 1422 VerifyNoLimitation(source.sink_wants()); |
1475 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); | 1423 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
1476 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1424 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1477 | 1425 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 const int kHeight = 720; | 1458 const int kHeight = 720; |
1511 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1459 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1512 | 1460 |
1513 // Enable kMaintainFramerate preference, no initial limitation. | 1461 // Enable kMaintainFramerate preference, no initial limitation. |
1514 AdaptingFrameForwarder source; | 1462 AdaptingFrameForwarder source; |
1515 source.set_adaptation_enabled(true); | 1463 source.set_adaptation_enabled(true); |
1516 vie_encoder_->SetSource( | 1464 vie_encoder_->SetSource( |
1517 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1465 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1518 | 1466 |
1519 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1467 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1520 WaitForEncodedFrame(1); | 1468 sink_.WaitForEncodedFrame(1); |
1521 VerifyNoLimitation(source.sink_wants()); | 1469 VerifyNoLimitation(source.sink_wants()); |
1522 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1470 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1523 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1471 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1524 | 1472 |
1525 // Trigger adapt down, expect scaled down resolution. | 1473 // Trigger adapt down, expect scaled down resolution. |
1526 vie_encoder_->TriggerQualityLow(); | 1474 vie_encoder_->TriggerQualityLow(); |
1527 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1475 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1528 WaitForEncodedFrame(2); | 1476 sink_.WaitForEncodedFrame(2); |
1529 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1477 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1530 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1478 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1531 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1479 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1532 | 1480 |
1533 // Trigger adapt up, expect no restriction. | 1481 // Trigger adapt up, expect no restriction. |
1534 vie_encoder_->TriggerQualityHigh(); | 1482 vie_encoder_->TriggerQualityHigh(); |
1535 VerifyNoLimitation(source.sink_wants()); | 1483 VerifyNoLimitation(source.sink_wants()); |
1536 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1484 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1537 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1485 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1538 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1486 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 // Enable adapter, expected input resolutions when downscaling: | 1539 // Enable adapter, expected input resolutions when downscaling: |
1592 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) | 1540 // 1280x720 -> 960x540 -> 640x360 -> 480x270 -> 320x180 (min resolution limit) |
1593 video_source_.set_adaptation_enabled(true); | 1541 video_source_.set_adaptation_enabled(true); |
1594 | 1542 |
1595 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1543 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1596 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1544 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1597 | 1545 |
1598 int downscales = 0; | 1546 int downscales = 0; |
1599 for (size_t i = 1; i <= kNumFrames; i++) { | 1547 for (size_t i = 1; i <= kNumFrames; i++) { |
1600 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1548 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1601 WaitForEncodedFrame(i); | 1549 sink_.WaitForEncodedFrame(i); |
1602 | 1550 |
1603 // Trigger scale down. | 1551 // Trigger scale down. |
1604 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); | 1552 rtc::VideoSinkWants last_wants = video_source_.sink_wants(); |
1605 vie_encoder_->TriggerQualityLow(); | 1553 vie_encoder_->TriggerQualityLow(); |
1606 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); | 1554 EXPECT_GE(video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
1607 | 1555 |
1608 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) | 1556 if (video_source_.sink_wants().max_pixel_count < last_wants.max_pixel_count) |
1609 ++downscales; | 1557 ++downscales; |
1610 | 1558 |
1611 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1559 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
(...skipping 10 matching lines...) Expand all Loading... |
1622 const int kHeight = 720; | 1570 const int kHeight = 720; |
1623 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1571 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1624 | 1572 |
1625 // Enable kMaintainFramerate preference, no initial limitation. | 1573 // Enable kMaintainFramerate preference, no initial limitation. |
1626 AdaptingFrameForwarder source; | 1574 AdaptingFrameForwarder source; |
1627 source.set_adaptation_enabled(true); | 1575 source.set_adaptation_enabled(true); |
1628 vie_encoder_->SetSource( | 1576 vie_encoder_->SetSource( |
1629 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1577 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1630 | 1578 |
1631 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1579 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1632 WaitForEncodedFrame(kWidth, kHeight); | 1580 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1633 VerifyNoLimitation(source.sink_wants()); | 1581 VerifyNoLimitation(source.sink_wants()); |
1634 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1582 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1635 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1583 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1636 | 1584 |
1637 // Trigger adapt down, expect scaled down resolution. | 1585 // Trigger adapt down, expect scaled down resolution. |
1638 vie_encoder_->TriggerCpuOveruse(); | 1586 vie_encoder_->TriggerCpuOveruse(); |
1639 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1587 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1640 WaitForEncodedFrame(2); | 1588 sink_.WaitForEncodedFrame(2); |
1641 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1589 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1642 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1590 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1643 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1591 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1644 | 1592 |
1645 // Trigger adapt up, expect no restriction. | 1593 // Trigger adapt up, expect no restriction. |
1646 vie_encoder_->TriggerCpuNormalUsage(); | 1594 vie_encoder_->TriggerCpuNormalUsage(); |
1647 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1595 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1648 WaitForEncodedFrame(kWidth, kHeight); | 1596 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1649 VerifyNoLimitation(source.sink_wants()); | 1597 VerifyNoLimitation(source.sink_wants()); |
1650 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1598 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1651 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1599 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1652 | 1600 |
1653 // Trigger adapt down, expect scaled down resolution. | 1601 // Trigger adapt down, expect scaled down resolution. |
1654 vie_encoder_->TriggerCpuOveruse(); | 1602 vie_encoder_->TriggerCpuOveruse(); |
1655 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1603 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1656 WaitForEncodedFrame(4); | 1604 sink_.WaitForEncodedFrame(4); |
1657 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1605 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1658 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1606 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1659 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1607 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1660 | 1608 |
1661 // Trigger adapt up, expect no restriction. | 1609 // Trigger adapt up, expect no restriction. |
1662 vie_encoder_->TriggerCpuNormalUsage(); | 1610 vie_encoder_->TriggerCpuNormalUsage(); |
1663 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1611 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1664 sink_.WaitForEncodedFrame(kWidth, kHeight); | 1612 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1665 VerifyNoLimitation(source.sink_wants()); | 1613 VerifyNoLimitation(source.sink_wants()); |
1666 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1614 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1667 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1615 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1668 | 1616 |
1669 vie_encoder_->Stop(); | 1617 vie_encoder_->Stop(); |
1670 } | 1618 } |
1671 | 1619 |
1672 TEST_F(ViEEncoderTest, | 1620 TEST_F(ViEEncoderTest, |
1673 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { | 1621 AdaptsResolutionOnOveruseAndLowQuality_MaintainFramerateMode) { |
1674 const int kWidth = 1280; | 1622 const int kWidth = 1280; |
1675 const int kHeight = 720; | 1623 const int kHeight = 720; |
1676 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1624 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1677 | 1625 |
1678 // Enable kMaintainFramerate preference, no initial limitation. | 1626 // Enable kMaintainFramerate preference, no initial limitation. |
1679 AdaptingFrameForwarder source; | 1627 AdaptingFrameForwarder source; |
1680 source.set_adaptation_enabled(true); | 1628 source.set_adaptation_enabled(true); |
1681 vie_encoder_->SetSource( | 1629 vie_encoder_->SetSource( |
1682 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1630 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1683 | 1631 |
1684 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1632 source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1685 WaitForEncodedFrame(kWidth, kHeight); | 1633 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1686 VerifyNoLimitation(source.sink_wants()); | 1634 VerifyNoLimitation(source.sink_wants()); |
1687 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1635 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1688 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1636 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1689 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1637 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1690 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1638 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1691 | 1639 |
1692 // Trigger cpu adapt down, expect scaled down resolution (960x540). | 1640 // Trigger cpu adapt down, expect scaled down resolution (960x540). |
1693 vie_encoder_->TriggerCpuOveruse(); | 1641 vie_encoder_->TriggerCpuOveruse(); |
1694 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); | 1642 source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
1695 WaitForEncodedFrame(2); | 1643 sink_.WaitForEncodedFrame(2); |
1696 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); | 1644 VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
1697 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1645 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1698 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1646 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1699 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1647 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1700 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1648 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1701 | 1649 |
1702 // Trigger cpu adapt down, expect scaled down resolution (640x360). | 1650 // Trigger cpu adapt down, expect scaled down resolution (640x360). |
1703 vie_encoder_->TriggerCpuOveruse(); | 1651 vie_encoder_->TriggerCpuOveruse(); |
1704 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); | 1652 source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
1705 WaitForEncodedFrame(3); | 1653 sink_.WaitForEncodedFrame(3); |
1706 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 1654 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
1707 rtc::VideoSinkWants last_wants = source.sink_wants(); | 1655 rtc::VideoSinkWants last_wants = source.sink_wants(); |
1708 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1656 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1709 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1657 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1710 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1658 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1711 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1659 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1712 | 1660 |
1713 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. | 1661 // Trigger cpu adapt down, max cpu downgrades reached, expect no change. |
1714 vie_encoder_->TriggerCpuOveruse(); | 1662 vie_encoder_->TriggerCpuOveruse(); |
1715 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); | 1663 source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
1716 WaitForEncodedFrame(4); | 1664 sink_.WaitForEncodedFrame(4); |
1717 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 1665 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
1718 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1666 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1719 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1667 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1720 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1668 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1721 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1669 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1722 | 1670 |
1723 // Trigger quality adapt down, expect scaled down resolution (480x270). | 1671 // Trigger quality adapt down, expect scaled down resolution (480x270). |
1724 vie_encoder_->TriggerQualityLow(); | 1672 vie_encoder_->TriggerQualityLow(); |
1725 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); | 1673 source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
1726 WaitForEncodedFrame(5); | 1674 sink_.WaitForEncodedFrame(5); |
1727 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); | 1675 VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
1728 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1676 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1729 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1677 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1730 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1678 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1731 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1679 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1732 | 1680 |
1733 // Trigger cpu adapt up, expect upscaled resolution (640x360). | 1681 // Trigger cpu adapt up, expect upscaled resolution (640x360). |
1734 vie_encoder_->TriggerCpuNormalUsage(); | 1682 vie_encoder_->TriggerCpuNormalUsage(); |
1735 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); | 1683 source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
1736 WaitForEncodedFrame(6); | 1684 sink_.WaitForEncodedFrame(6); |
1737 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 1685 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
1738 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); | 1686 EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
1739 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1687 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1740 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1688 EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1741 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1689 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1742 | 1690 |
1743 // Trigger cpu adapt up, expect upscaled resolution (960x540). | 1691 // Trigger cpu adapt up, expect upscaled resolution (960x540). |
1744 vie_encoder_->TriggerCpuNormalUsage(); | 1692 vie_encoder_->TriggerCpuNormalUsage(); |
1745 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); | 1693 source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); |
1746 WaitForEncodedFrame(7); | 1694 sink_.WaitForEncodedFrame(7); |
1747 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 1695 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
1748 last_wants = source.sink_wants(); | 1696 last_wants = source.sink_wants(); |
1749 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1697 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1750 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1698 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1751 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1699 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1752 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1700 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1753 | 1701 |
1754 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). | 1702 // Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). |
1755 vie_encoder_->TriggerCpuNormalUsage(); | 1703 vie_encoder_->TriggerCpuNormalUsage(); |
1756 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); | 1704 source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); |
1757 WaitForEncodedFrame(8); | 1705 sink_.WaitForEncodedFrame(8); |
1758 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); | 1706 VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
1759 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1707 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1760 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); | 1708 EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
1761 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1709 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1762 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1710 EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1763 | 1711 |
1764 // Trigger quality adapt up, expect no restriction (1280x720). | 1712 // Trigger quality adapt up, expect no restriction (1280x720). |
1765 vie_encoder_->TriggerQualityHigh(); | 1713 vie_encoder_->TriggerQualityHigh(); |
1766 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); | 1714 source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); |
1767 WaitForEncodedFrame(kWidth, kHeight); | 1715 sink_.WaitForEncodedFrame(kWidth, kHeight); |
1768 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); | 1716 VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
1769 VerifyNoLimitation(source.sink_wants()); | 1717 VerifyNoLimitation(source.sink_wants()); |
1770 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1718 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1771 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); | 1719 EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
1772 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1720 EXPECT_EQ(4, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1773 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 1721 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
1774 | 1722 |
1775 vie_encoder_->Stop(); | 1723 vie_encoder_->Stop(); |
1776 } | 1724 } |
1777 | 1725 |
1778 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { | 1726 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { |
| 1727 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1779 const int kWidth = 640; | 1728 const int kWidth = 640; |
1780 const int kHeight = 360; | 1729 const int kHeight = 360; |
1781 | 1730 |
1782 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
1783 | |
1784 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1731 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1785 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1732 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1786 WaitForEncodedFrame(i); | 1733 sink_.WaitForEncodedFrame(i); |
1787 } | 1734 } |
1788 | 1735 |
1789 vie_encoder_->TriggerCpuOveruse(); | 1736 vie_encoder_->TriggerCpuOveruse(); |
1790 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1737 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1791 video_source_.IncomingCapturedFrame(CreateFrame( | 1738 video_source_.IncomingCapturedFrame(CreateFrame( |
1792 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); | 1739 SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); |
1793 WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i); | 1740 sink_.WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + |
| 1741 i); |
1794 } | 1742 } |
1795 | 1743 |
1796 vie_encoder_->Stop(); | 1744 vie_encoder_->Stop(); |
1797 vie_encoder_.reset(); | 1745 vie_encoder_.reset(); |
1798 stats_proxy_.reset(); | 1746 stats_proxy_.reset(); |
1799 | 1747 |
1800 EXPECT_EQ(1, | 1748 EXPECT_EQ(1, |
1801 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 1749 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
1802 EXPECT_EQ( | 1750 EXPECT_EQ( |
1803 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 1751 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
1804 } | 1752 } |
1805 | 1753 |
1806 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsNotReportedForDisabledDegradation) { | 1754 TEST_F(ViEEncoderTest, CpuLimitedHistogramIsNotReportedForDisabledDegradation) { |
1807 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1755 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1808 const int kWidth = 640; | 1756 const int kWidth = 640; |
1809 const int kHeight = 360; | 1757 const int kHeight = 360; |
1810 | 1758 |
1811 vie_encoder_->SetSource( | 1759 vie_encoder_->SetSource( |
1812 &video_source_, | 1760 &video_source_, |
1813 VideoSendStream::DegradationPreference::kDegradationDisabled); | 1761 VideoSendStream::DegradationPreference::kDegradationDisabled); |
1814 | 1762 |
1815 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 1763 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
1816 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1764 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1817 WaitForEncodedFrame(i); | 1765 sink_.WaitForEncodedFrame(i); |
1818 } | 1766 } |
1819 | 1767 |
1820 vie_encoder_->Stop(); | 1768 vie_encoder_->Stop(); |
1821 vie_encoder_.reset(); | 1769 vie_encoder_.reset(); |
1822 stats_proxy_.reset(); | 1770 stats_proxy_.reset(); |
1823 | 1771 |
1824 EXPECT_EQ(0, | 1772 EXPECT_EQ(0, |
1825 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 1773 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
1826 } | 1774 } |
1827 | 1775 |
(...skipping 10 matching lines...) Expand all Loading... |
1838 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); | 1786 .GetAllocation(kLowTargetBitrateBps, kDefaultFps); |
1839 | 1787 |
1840 // First called on bitrate updated, then again on first frame. | 1788 // First called on bitrate updated, then again on first frame. |
1841 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1789 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
1842 .Times(2); | 1790 .Times(2); |
1843 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1791 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1844 | 1792 |
1845 const int64_t kStartTimeMs = 1; | 1793 const int64_t kStartTimeMs = 1; |
1846 video_source_.IncomingCapturedFrame( | 1794 video_source_.IncomingCapturedFrame( |
1847 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); | 1795 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); |
1848 WaitForEncodedFrame(kStartTimeMs); | 1796 sink_.WaitForEncodedFrame(kStartTimeMs); |
1849 | 1797 |
1850 // Not called on second frame. | 1798 // Not called on second frame. |
1851 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1799 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
1852 .Times(0); | 1800 .Times(0); |
1853 video_source_.IncomingCapturedFrame( | 1801 video_source_.IncomingCapturedFrame( |
1854 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); | 1802 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); |
1855 WaitForEncodedFrame(kStartTimeMs + 1); | 1803 sink_.WaitForEncodedFrame(kStartTimeMs + 1); |
1856 | 1804 |
1857 // Called after a process interval. | 1805 // Called after a process interval. |
1858 const int64_t kProcessIntervalMs = | 1806 const int64_t kProcessIntervalMs = |
1859 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; | 1807 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
1860 fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * | 1808 // TODO(sprang): ViEEncoder should die and/or get injectable clock. |
1861 (kProcessIntervalMs + (1000 / kDefaultFps))); | 1809 // Sleep for one processing interval plus one frame to avoid flakiness. |
| 1810 SleepMs(kProcessIntervalMs + 1000 / kDefaultFps); |
1862 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | 1811 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
1863 .Times(1); | 1812 .Times(1); |
1864 video_source_.IncomingCapturedFrame(CreateFrame( | 1813 video_source_.IncomingCapturedFrame(CreateFrame( |
1865 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); | 1814 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); |
1866 WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); | 1815 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
1867 | 1816 |
1868 vie_encoder_->Stop(); | 1817 vie_encoder_->Stop(); |
1869 } | 1818 } |
1870 | 1819 |
1871 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { | 1820 TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { |
1872 const int kTooLowBitrateForFrameSizeBps = 10000; | 1821 const int kTooLowBitrateForFrameSizeBps = 10000; |
1873 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 1822 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
1874 const int kWidth = 640; | 1823 const int kWidth = 640; |
1875 const int kHeight = 360; | 1824 const int kHeight = 360; |
1876 | 1825 |
1877 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1826 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1878 | 1827 |
1879 // Expect to drop this frame, the wait should time out. | 1828 // Expect to drop this frame, the wait should time out. |
1880 ExpectDroppedFrame(); | 1829 sink_.ExpectDroppedFrame(); |
1881 | 1830 |
1882 // Expect the sink_wants to specify a scaled frame. | 1831 // Expect the sink_wants to specify a scaled frame. |
1883 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1832 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1884 | 1833 |
1885 int last_pixel_count = video_source_.sink_wants().max_pixel_count; | 1834 int last_pixel_count = video_source_.sink_wants().max_pixel_count; |
1886 | 1835 |
1887 // Next frame is scaled. | 1836 // Next frame is scaled. |
1888 video_source_.IncomingCapturedFrame( | 1837 video_source_.IncomingCapturedFrame( |
1889 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); | 1838 CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); |
1890 | 1839 |
1891 // Expect to drop this frame, the wait should time out. | 1840 // Expect to drop this frame, the wait should time out. |
1892 ExpectDroppedFrame(); | 1841 sink_.ExpectDroppedFrame(); |
1893 | 1842 |
1894 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); | 1843 EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); |
1895 | 1844 |
1896 vie_encoder_->Stop(); | 1845 vie_encoder_->Stop(); |
1897 } | 1846 } |
1898 | 1847 |
1899 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { | 1848 TEST_F(ViEEncoderTest, NumberOfDroppedFramesLimitedWhenBitrateIsTooLow) { |
1900 const int kTooLowBitrateForFrameSizeBps = 10000; | 1849 const int kTooLowBitrateForFrameSizeBps = 10000; |
1901 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); | 1850 vie_encoder_->OnBitrateUpdated(kTooLowBitrateForFrameSizeBps, 0, 0); |
1902 const int kWidth = 640; | 1851 const int kWidth = 640; |
1903 const int kHeight = 360; | 1852 const int kHeight = 360; |
1904 | 1853 |
1905 // We expect the n initial frames to get dropped. | 1854 // We expect the n initial frames to get dropped. |
1906 int i; | 1855 int i; |
1907 for (i = 1; i <= kMaxInitialFramedrop; ++i) { | 1856 for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
1908 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1857 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1909 ExpectDroppedFrame(); | 1858 sink_.ExpectDroppedFrame(); |
1910 } | 1859 } |
1911 // The n+1th frame should not be dropped, even though it's size is too large. | 1860 // The n+1th frame should not be dropped, even though it's size is too large. |
1912 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); | 1861 video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
1913 WaitForEncodedFrame(i); | 1862 sink_.WaitForEncodedFrame(i); |
1914 | 1863 |
1915 // Expect the sink_wants to specify a scaled frame. | 1864 // Expect the sink_wants to specify a scaled frame. |
1916 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); | 1865 EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
1917 | 1866 |
1918 vie_encoder_->Stop(); | 1867 vie_encoder_->Stop(); |
1919 } | 1868 } |
1920 | 1869 |
1921 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { | 1870 TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) { |
1922 const int kWidth = 640; | 1871 const int kWidth = 640; |
1923 const int kHeight = 360; | 1872 const int kHeight = 360; |
1924 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1873 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1925 | 1874 |
1926 // Set degradation preference. | 1875 // Set degradation preference. |
1927 vie_encoder_->SetSource( | 1876 vie_encoder_->SetSource( |
1928 &video_source_, | 1877 &video_source_, |
1929 VideoSendStream::DegradationPreference::kMaintainResolution); | 1878 VideoSendStream::DegradationPreference::kMaintainResolution); |
1930 | 1879 |
1931 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1880 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1932 // Frame should not be dropped, even if it's too large. | 1881 // Frame should not be dropped, even if it's too large. |
1933 WaitForEncodedFrame(1); | 1882 sink_.WaitForEncodedFrame(1); |
1934 | 1883 |
1935 vie_encoder_->Stop(); | 1884 vie_encoder_->Stop(); |
1936 } | 1885 } |
1937 | 1886 |
1938 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { | 1887 TEST_F(ViEEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { |
1939 const int kWidth = 640; | 1888 const int kWidth = 640; |
1940 const int kHeight = 360; | 1889 const int kHeight = 360; |
1941 fake_encoder_.SetQualityScaling(false); | 1890 fake_encoder_.SetQualityScaling(false); |
1942 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); | 1891 vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0); |
1943 | 1892 |
1944 // Force quality scaler reconfiguration by resetting the source. | 1893 // Force quality scaler reconfiguration by resetting the source. |
1945 vie_encoder_->SetSource(&video_source_, | 1894 vie_encoder_->SetSource(&video_source_, |
1946 VideoSendStream::DegradationPreference::kBalanced); | 1895 VideoSendStream::DegradationPreference::kBalanced); |
1947 | 1896 |
1948 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); | 1897 video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
1949 // Frame should not be dropped, even if it's too large. | 1898 // Frame should not be dropped, even if it's too large. |
1950 WaitForEncodedFrame(1); | 1899 sink_.WaitForEncodedFrame(1); |
1951 | 1900 |
1952 vie_encoder_->Stop(); | 1901 vie_encoder_->Stop(); |
1953 fake_encoder_.SetQualityScaling(true); | 1902 fake_encoder_.SetQualityScaling(true); |
1954 } | 1903 } |
1955 | 1904 |
1956 TEST_F(ViEEncoderTest, | 1905 TEST_F(ViEEncoderTest, |
1957 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { | 1906 ResolutionNotAdaptedForTooSmallFrame_MaintainFramerateMode) { |
1958 const int kTooSmallWidth = 10; | 1907 const int kTooSmallWidth = 10; |
1959 const int kTooSmallHeight = 10; | 1908 const int kTooSmallHeight = 10; |
1960 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1909 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1961 | 1910 |
1962 // Enable kMaintainFramerate preference, no initial limitation. | 1911 // Enable kMaintainFramerate preference, no initial limitation. |
1963 test::FrameForwarder source; | 1912 test::FrameForwarder source; |
1964 vie_encoder_->SetSource( | 1913 vie_encoder_->SetSource( |
1965 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); | 1914 &source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
1966 VerifyNoLimitation(source.sink_wants()); | 1915 VerifyNoLimitation(source.sink_wants()); |
1967 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1916 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1968 | 1917 |
1969 // Trigger adapt down, too small frame, expect no change. | 1918 // Trigger adapt down, too small frame, expect no change. |
1970 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); | 1919 source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
1971 WaitForEncodedFrame(1); | 1920 sink_.WaitForEncodedFrame(1); |
1972 vie_encoder_->TriggerCpuOveruse(); | 1921 vie_encoder_->TriggerCpuOveruse(); |
1973 VerifyNoLimitation(source.sink_wants()); | 1922 VerifyNoLimitation(source.sink_wants()); |
1974 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); | 1923 EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
1975 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 1924 EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
1976 | 1925 |
1977 vie_encoder_->Stop(); | 1926 vie_encoder_->Stop(); |
1978 } | 1927 } |
1979 | 1928 |
1980 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { | 1929 TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
1981 fake_encoder_.ForceInitEncodeFailure(true); | 1930 fake_encoder_.ForceInitEncodeFailure(true); |
1982 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1931 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1983 ResetEncoder("VP8", 2, 1, true, false); | 1932 ResetEncoder("VP8", 2, 1, true); |
1984 const int kFrameWidth = 1280; | 1933 const int kFrameWidth = 1280; |
1985 const int kFrameHeight = 720; | 1934 const int kFrameHeight = 720; |
1986 video_source_.IncomingCapturedFrame( | 1935 video_source_.IncomingCapturedFrame( |
1987 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1936 CreateFrame(1, kFrameWidth, kFrameHeight)); |
1988 ExpectDroppedFrame(); | 1937 sink_.ExpectDroppedFrame(); |
1989 vie_encoder_->Stop(); | 1938 vie_encoder_->Stop(); |
1990 } | 1939 } |
1991 | 1940 |
1992 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. | 1941 // TODO(sprang): Extend this with fps throttling and any "balanced" extensions. |
1993 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { | 1942 TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse_MaintainFramerateMode) { |
1994 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1943 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
1995 | 1944 |
1996 const int kFrameWidth = 1280; | 1945 const int kFrameWidth = 1280; |
1997 const int kFrameHeight = 720; | 1946 const int kFrameHeight = 720; |
1998 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as | 1947 // Enabled default VideoAdapter downscaling. First step is 3/4, not 3/5 as |
1999 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). | 1948 // requested by ViEEncoder::VideoSourceProxy::RequestResolutionLowerThan(). |
2000 video_source_.set_adaptation_enabled(true); | 1949 video_source_.set_adaptation_enabled(true); |
2001 | 1950 |
2002 video_source_.IncomingCapturedFrame( | 1951 video_source_.IncomingCapturedFrame( |
2003 CreateFrame(1, kFrameWidth, kFrameHeight)); | 1952 CreateFrame(1, kFrameWidth, kFrameHeight)); |
2004 WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1953 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
2005 | 1954 |
2006 // Trigger CPU overuse, downscale by 3/4. | 1955 // Trigger CPU overuse, downscale by 3/4. |
2007 vie_encoder_->TriggerCpuOveruse(); | 1956 vie_encoder_->TriggerCpuOveruse(); |
2008 video_source_.IncomingCapturedFrame( | 1957 video_source_.IncomingCapturedFrame( |
2009 CreateFrame(2, kFrameWidth, kFrameHeight)); | 1958 CreateFrame(2, kFrameWidth, kFrameHeight)); |
2010 WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); | 1959 sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
2011 | 1960 |
2012 // Trigger CPU normal use, return to original resolution. | 1961 // Trigger CPU normal use, return to original resolution. |
2013 vie_encoder_->TriggerCpuNormalUsage(); | 1962 vie_encoder_->TriggerCpuNormalUsage(); |
2014 video_source_.IncomingCapturedFrame( | 1963 video_source_.IncomingCapturedFrame( |
2015 CreateFrame(3, kFrameWidth, kFrameHeight)); | 1964 CreateFrame(3, kFrameWidth, kFrameHeight)); |
2016 WaitForEncodedFrame(kFrameWidth, kFrameHeight); | 1965 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
2017 | 1966 |
2018 vie_encoder_->Stop(); | 1967 vie_encoder_->Stop(); |
2019 } | 1968 } |
2020 | 1969 |
2021 TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { | 1970 TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { |
2022 // const int kDefaultFramerateFps = 30; | 1971 const int kDefaultFramerateFps = 30; |
| 1972 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kDefaultFramerateFps; |
2023 const int kFrameWidth = 1280; | 1973 const int kFrameWidth = 1280; |
2024 const int kFrameHeight = 720; | 1974 const int kFrameHeight = 720; |
2025 int kFrameIntervalMs = rtc::kNumMillisecsPerSec / max_framerate_; | 1975 rtc::ScopedFakeClock fake_clock; |
2026 | 1976 |
2027 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 1977 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2028 vie_encoder_->SetSource( | 1978 vie_encoder_->SetSource( |
2029 &video_source_, | 1979 &video_source_, |
2030 VideoSendStream::DegradationPreference::kMaintainResolution); | 1980 VideoSendStream::DegradationPreference::kMaintainResolution); |
2031 video_source_.set_adaptation_enabled(true); | 1981 video_source_.set_adaptation_enabled(true); |
2032 | 1982 |
2033 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; | 1983 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); |
| 1984 int64_t timestamp_ms = kFrameIntervalMs; |
2034 | 1985 |
2035 video_source_.IncomingCapturedFrame( | 1986 video_source_.IncomingCapturedFrame( |
2036 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 1987 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2037 WaitForEncodedFrame(timestamp_ms); | 1988 sink_.WaitForEncodedFrame(timestamp_ms); |
2038 | 1989 |
2039 // Try to trigger overuse. No fps estimate available => no effect. | 1990 // Try to trigger overuse. No fps estimate available => no effect. |
2040 vie_encoder_->TriggerCpuOveruse(); | 1991 vie_encoder_->TriggerCpuOveruse(); |
2041 | 1992 |
2042 // Insert frames for one second to get a stable estimate. | 1993 // Insert frames for one second to get a stable estimate. |
2043 for (int i = 0; i < max_framerate_; ++i) { | 1994 for (int i = 0; i < kDefaultFramerateFps; ++i) { |
2044 timestamp_ms += kFrameIntervalMs; | 1995 timestamp_ms += kFrameIntervalMs; |
| 1996 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
2045 video_source_.IncomingCapturedFrame( | 1997 video_source_.IncomingCapturedFrame( |
2046 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 1998 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2047 WaitForEncodedFrame(timestamp_ms); | 1999 sink_.WaitForEncodedFrame(timestamp_ms); |
2048 } | 2000 } |
2049 | 2001 |
2050 // Trigger CPU overuse, reduce framerate by 2/3. | 2002 // Trigger CPU overuse, reduce framerate by 2/3. |
2051 vie_encoder_->TriggerCpuOveruse(); | 2003 vie_encoder_->TriggerCpuOveruse(); |
2052 int num_frames_dropped = 0; | 2004 int num_frames_dropped = 0; |
2053 for (int i = 0; i < max_framerate_; ++i) { | 2005 for (int i = 0; i < kDefaultFramerateFps; ++i) { |
2054 timestamp_ms += kFrameIntervalMs; | 2006 timestamp_ms += kFrameIntervalMs; |
| 2007 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
2055 video_source_.IncomingCapturedFrame( | 2008 video_source_.IncomingCapturedFrame( |
2056 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2009 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2057 if (!WaitForFrame(kFrameTimeoutMs)) { | 2010 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
2058 ++num_frames_dropped; | 2011 ++num_frames_dropped; |
2059 } else { | 2012 } else { |
2060 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2013 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2061 } | 2014 } |
2062 } | 2015 } |
2063 | 2016 |
2064 // Add some slack to account for frames dropped by the frame dropper. | 2017 // TODO(sprang): Find where there's rounding errors or stuff causing the |
2065 const int kErrorMargin = 1; | 2018 // margin here to be a little larger than we'd like (input fps estimate is |
2066 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), | 2019 // off) and the frame dropping is a little too aggressive. |
| 2020 const int kErrorMargin = 5; |
| 2021 EXPECT_NEAR(num_frames_dropped, |
| 2022 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), |
2067 kErrorMargin); | 2023 kErrorMargin); |
2068 | 2024 |
2069 // Trigger CPU overuse, reduce framerate by 2/3 again. | 2025 // Trigger CPU overuse, reduce framerate by 2/3 again. |
2070 vie_encoder_->TriggerCpuOveruse(); | 2026 vie_encoder_->TriggerCpuOveruse(); |
2071 num_frames_dropped = 0; | 2027 num_frames_dropped = 0; |
2072 for (int i = 0; i < max_framerate_; ++i) { | 2028 for (int i = 0; i < kDefaultFramerateFps; ++i) { |
2073 timestamp_ms += kFrameIntervalMs; | 2029 timestamp_ms += kFrameIntervalMs; |
| 2030 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
2074 video_source_.IncomingCapturedFrame( | 2031 video_source_.IncomingCapturedFrame( |
2075 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2032 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2076 if (!WaitForFrame(kFrameTimeoutMs)) { | 2033 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
2077 ++num_frames_dropped; | 2034 ++num_frames_dropped; |
2078 } else { | 2035 } else { |
2079 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2036 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2080 } | 2037 } |
2081 } | 2038 } |
2082 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 4 / 9), | 2039 EXPECT_NEAR(num_frames_dropped, |
| 2040 kDefaultFramerateFps - (kDefaultFramerateFps * 4 / 9), |
2083 kErrorMargin); | 2041 kErrorMargin); |
2084 | 2042 |
2085 // Go back up one step. | 2043 // Go back up one step. |
2086 vie_encoder_->TriggerCpuNormalUsage(); | 2044 vie_encoder_->TriggerCpuNormalUsage(); |
2087 num_frames_dropped = 0; | 2045 num_frames_dropped = 0; |
2088 for (int i = 0; i < max_framerate_; ++i) { | 2046 for (int i = 0; i < kDefaultFramerateFps; ++i) { |
2089 timestamp_ms += kFrameIntervalMs; | 2047 timestamp_ms += kFrameIntervalMs; |
| 2048 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
2090 video_source_.IncomingCapturedFrame( | 2049 video_source_.IncomingCapturedFrame( |
2091 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2050 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2092 if (!WaitForFrame(kFrameTimeoutMs)) { | 2051 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
2093 ++num_frames_dropped; | 2052 ++num_frames_dropped; |
2094 } else { | 2053 } else { |
2095 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2054 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2096 } | 2055 } |
2097 } | 2056 } |
2098 EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), | 2057 EXPECT_NEAR(num_frames_dropped, |
| 2058 kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), |
2099 kErrorMargin); | 2059 kErrorMargin); |
2100 | 2060 |
2101 // Go back up to original mode. | 2061 // Go back up to original mode. |
2102 vie_encoder_->TriggerCpuNormalUsage(); | 2062 vie_encoder_->TriggerCpuNormalUsage(); |
2103 num_frames_dropped = 0; | 2063 num_frames_dropped = 0; |
2104 for (int i = 0; i < max_framerate_; ++i) { | 2064 for (int i = 0; i < kDefaultFramerateFps; ++i) { |
2105 timestamp_ms += kFrameIntervalMs; | 2065 timestamp_ms += kFrameIntervalMs; |
| 2066 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
2106 video_source_.IncomingCapturedFrame( | 2067 video_source_.IncomingCapturedFrame( |
2107 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2068 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2108 if (!WaitForFrame(kFrameTimeoutMs)) { | 2069 if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
2109 ++num_frames_dropped; | 2070 ++num_frames_dropped; |
2110 } else { | 2071 } else { |
2111 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); | 2072 sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
2112 } | 2073 } |
2113 } | 2074 } |
2114 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); | 2075 EXPECT_NEAR(num_frames_dropped, 0, kErrorMargin); |
2115 | 2076 |
2116 vie_encoder_->Stop(); | 2077 vie_encoder_->Stop(); |
2117 } | 2078 } |
2118 | 2079 |
2119 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { | 2080 TEST_F(ViEEncoderTest, DoesntAdaptDownPastMinFramerate) { |
2120 const int kFramerateFps = 5; | 2081 const int kFramerateFps = 5; |
2121 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; | 2082 const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kFramerateFps; |
2122 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; | 2083 const int kMinFpsFrameInterval = rtc::kNumMillisecsPerSec / kMinFramerateFps; |
2123 const int kFrameWidth = 1280; | 2084 const int kFrameWidth = 1280; |
2124 const int kFrameHeight = 720; | 2085 const int kFrameHeight = 720; |
2125 | 2086 |
2126 // Reconfigure encoder with two temporal layers and screensharing, which will | 2087 rtc::ScopedFakeClock fake_clock; |
2127 // disable frame dropping and make testing easier. | |
2128 ResetEncoder("VP8", 1, 2, true, true); | |
2129 | |
2130 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 2088 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
2131 vie_encoder_->SetSource( | 2089 vie_encoder_->SetSource( |
2132 &video_source_, | 2090 &video_source_, |
2133 VideoSendStream::DegradationPreference::kMaintainResolution); | 2091 VideoSendStream::DegradationPreference::kMaintainResolution); |
2134 video_source_.set_adaptation_enabled(true); | 2092 video_source_.set_adaptation_enabled(true); |
2135 | 2093 |
2136 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; | 2094 fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); |
| 2095 int64_t timestamp_ms = kFrameIntervalMs; |
2137 | 2096 |
2138 // Trigger overuse as much as we can. | 2097 // Trigger overuse as much as we can. |
2139 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { | 2098 for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { |
2140 // Insert frames to get a new fps estimate... | 2099 // Insert frames to get a new fps estimate... |
2141 for (int j = 0; j < kFramerateFps; ++j) { | 2100 for (int j = 0; j < kFramerateFps; ++j) { |
2142 video_source_.IncomingCapturedFrame( | 2101 video_source_.IncomingCapturedFrame( |
2143 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2102 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2144 timestamp_ms += kFrameIntervalMs; | 2103 timestamp_ms += kFrameIntervalMs; |
| 2104 fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
2145 } | 2105 } |
2146 // ...and then try to adapt again. | 2106 // ...and then try to adapt again. |
2147 vie_encoder_->TriggerCpuOveruse(); | 2107 vie_encoder_->TriggerCpuOveruse(); |
2148 } | 2108 } |
2149 | 2109 |
2150 // Drain any frame in the pipeline. | 2110 // Drain any frame in the pipeline. |
2151 WaitForFrame(kDefaultTimeoutMs); | 2111 sink_.WaitForFrame(kDefaultTimeoutMs); |
2152 | 2112 |
2153 // Insert frames at min fps, all should go through. | 2113 // Insert frames at min fps, all should go through. |
2154 for (int i = 0; i < 10; ++i) { | 2114 for (int i = 0; i < 10; ++i) { |
2155 timestamp_ms += kMinFpsFrameInterval; | 2115 timestamp_ms += kMinFpsFrameInterval; |
| 2116 fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); |
2156 video_source_.IncomingCapturedFrame( | 2117 video_source_.IncomingCapturedFrame( |
2157 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | 2118 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
2158 WaitForEncodedFrame(timestamp_ms); | 2119 sink_.WaitForEncodedFrame(timestamp_ms); |
2159 } | 2120 } |
2160 vie_encoder_->Stop(); | 2121 vie_encoder_->Stop(); |
2161 } | 2122 } |
2162 | |
2163 TEST_F(ViEEncoderTest, PriodicallyUpdatesChannelParameters) { | |
2164 const int kFrameWidth = 1280; | |
2165 const int kFrameHeight = 720; | |
2166 const int kLowFps = 2; | |
2167 const int kHighFps = 30; | |
2168 | |
2169 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
2170 | |
2171 int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; | |
2172 max_framerate_ = kLowFps; | |
2173 | |
2174 // Insert 2 seconds of 2fps video. | |
2175 for (int i = 0; i < kLowFps * 2; ++i) { | |
2176 video_source_.IncomingCapturedFrame( | |
2177 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
2178 WaitForEncodedFrame(timestamp_ms); | |
2179 timestamp_ms += 1000 / kLowFps; | |
2180 } | |
2181 | |
2182 // Make sure encoder is updated with new target. | |
2183 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
2184 video_source_.IncomingCapturedFrame( | |
2185 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
2186 WaitForEncodedFrame(timestamp_ms); | |
2187 timestamp_ms += 1000 / kLowFps; | |
2188 | |
2189 EXPECT_EQ(kLowFps, fake_encoder_.GetConfiguredInputFramerate()); | |
2190 | |
2191 // Insert 30fps frames for just a little more than the forced update period. | |
2192 const int kVcmTimerIntervalFrames = | |
2193 (vcm::VCMProcessTimer::kDefaultProcessIntervalMs * kHighFps) / 1000; | |
2194 const int kFrameIntervalMs = 1000 / kHighFps; | |
2195 max_framerate_ = kHighFps; | |
2196 for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) { | |
2197 video_source_.IncomingCapturedFrame( | |
2198 CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); | |
2199 // Wait for encoded frame, but skip ahead if it doesn't arrive as it might | |
2200 // be dropped if the encoder hans't been updated with the new higher target | |
2201 // framerate yet, causing it to overshoot the target bitrate and then | |
2202 // suffering the wrath of the media optimizer. | |
2203 TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); | |
2204 timestamp_ms += kFrameIntervalMs; | |
2205 } | |
2206 | |
2207 // Don expect correct measurement just yet, but it should be higher than | |
2208 // before. | |
2209 EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps); | |
2210 | |
2211 vie_encoder_->Stop(); | |
2212 } | |
2213 } // namespace webrtc | 2123 } // namespace webrtc |
OLD | NEW |