OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 11 matching lines...) Expand all Loading... |
22 #include "webrtc/test/field_trial.h" | 22 #include "webrtc/test/field_trial.h" |
23 #include "webrtc/test/gtest.h" | 23 #include "webrtc/test/gtest.h" |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 namespace { | 26 namespace { |
27 const int kWidth = 320; | 27 const int kWidth = 320; |
28 const int kHeight = 240; | 28 const int kHeight = 240; |
29 const int kNumCores = 2; | 29 const int kNumCores = 2; |
30 const uint32_t kFramerate = 30; | 30 const uint32_t kFramerate = 30; |
31 const size_t kMaxPayloadSize = 800; | 31 const size_t kMaxPayloadSize = 800; |
| 32 const int kDefaultMinPixelsPerFrame = 320 * 180; |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { | 35 class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { |
35 protected: | 36 protected: |
36 VideoEncoderSoftwareFallbackWrapperTest() | 37 VideoEncoderSoftwareFallbackWrapperTest() |
37 : VideoEncoderSoftwareFallbackWrapperTest("") {} | 38 : VideoEncoderSoftwareFallbackWrapperTest("") {} |
38 explicit VideoEncoderSoftwareFallbackWrapperTest( | 39 explicit VideoEncoderSoftwareFallbackWrapperTest( |
39 const std::string& field_trials) | 40 const std::string& field_trials) |
40 : override_field_trials_(field_trials), | 41 : override_field_trials_(field_trials), |
41 fallback_wrapper_(cricket::VideoCodec("VP8"), &fake_encoder_) {} | 42 fallback_wrapper_(cricket::VideoCodec("VP8"), &fake_encoder_) {} |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 87 |
87 bool SupportsNativeHandle() const override { | 88 bool SupportsNativeHandle() const override { |
88 ++supports_native_handle_count_; | 89 ++supports_native_handle_count_; |
89 return supports_native_handle_; | 90 return supports_native_handle_; |
90 } | 91 } |
91 | 92 |
92 const char* ImplementationName() const override { | 93 const char* ImplementationName() const override { |
93 return "fake-encoder"; | 94 return "fake-encoder"; |
94 } | 95 } |
95 | 96 |
| 97 VideoEncoder::ScalingSettings GetScalingSettings() const override { |
| 98 return VideoEncoder::ScalingSettings(true); |
| 99 } |
| 100 |
96 int init_encode_count_ = 0; | 101 int init_encode_count_ = 0; |
97 int32_t init_encode_return_code_ = WEBRTC_VIDEO_CODEC_OK; | 102 int32_t init_encode_return_code_ = WEBRTC_VIDEO_CODEC_OK; |
98 int32_t encode_return_code_ = WEBRTC_VIDEO_CODEC_OK; | 103 int32_t encode_return_code_ = WEBRTC_VIDEO_CODEC_OK; |
99 int encode_count_ = 0; | 104 int encode_count_ = 0; |
100 EncodedImageCallback* encode_complete_callback_ = nullptr; | 105 EncodedImageCallback* encode_complete_callback_ = nullptr; |
101 int release_count_ = 0; | 106 int release_count_ = 0; |
102 int set_channel_parameters_count_ = 0; | 107 int set_channel_parameters_count_ = 0; |
103 int set_rates_count_ = 0; | 108 int set_rates_count_ = 0; |
104 mutable int supports_native_handle_count_ = 0; | 109 mutable int supports_native_handle_count_ = 0; |
105 bool supports_native_handle_ = false; | 110 bool supports_native_handle_ = false; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 UtilizeFallbackEncoder(); | 316 UtilizeFallbackEncoder(); |
312 // Hard coded expected value since libvpx is the software implementation name | 317 // Hard coded expected value since libvpx is the software implementation name |
313 // for VP8. Change accordingly if the underlying implementation does. | 318 // for VP8. Change accordingly if the underlying implementation does. |
314 CheckLastEncoderName("libvpx"); | 319 CheckLastEncoderName("libvpx"); |
315 } | 320 } |
316 | 321 |
317 namespace { | 322 namespace { |
318 const int kLowKbps = 220; | 323 const int kLowKbps = 220; |
319 const int kHighKbps = 300; | 324 const int kHighKbps = 300; |
320 const int kMinLowDurationMs = 4000; | 325 const int kMinLowDurationMs = 4000; |
| 326 const int kMinPixelsPerFrame = 1; |
| 327 const int kMinPixelsStop = 320 * 180; |
321 const std::string kFieldTrial = "WebRTC-VP8-Forced-Fallback-Encoder"; | 328 const std::string kFieldTrial = "WebRTC-VP8-Forced-Fallback-Encoder"; |
322 } // namespace | 329 } // namespace |
323 | 330 |
324 class ForcedFallbackTest : public VideoEncoderSoftwareFallbackWrapperTest { | 331 class ForcedFallbackTest : public VideoEncoderSoftwareFallbackWrapperTest { |
325 public: | 332 public: |
326 ForcedFallbackTest(const std::string& field_trials) | 333 ForcedFallbackTest(const std::string& field_trials) |
327 : VideoEncoderSoftwareFallbackWrapperTest(field_trials) {} | 334 : VideoEncoderSoftwareFallbackWrapperTest(field_trials) {} |
328 | 335 |
329 ~ForcedFallbackTest() override {} | 336 ~ForcedFallbackTest() override {} |
330 | 337 |
(...skipping 12 matching lines...) Expand all Loading... |
343 | 350 |
344 void ConfigureVp8Codec() { | 351 void ConfigureVp8Codec() { |
345 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); | 352 fallback_wrapper_.RegisterEncodeCompleteCallback(&callback_); |
346 std::unique_ptr<TemporalLayersFactory> tl_factory( | 353 std::unique_ptr<TemporalLayersFactory> tl_factory( |
347 new TemporalLayersFactory()); | 354 new TemporalLayersFactory()); |
348 codec_.codecType = kVideoCodecVP8; | 355 codec_.codecType = kVideoCodecVP8; |
349 codec_.maxFramerate = kFramerate; | 356 codec_.maxFramerate = kFramerate; |
350 codec_.width = kWidth; | 357 codec_.width = kWidth; |
351 codec_.height = kHeight; | 358 codec_.height = kHeight; |
352 codec_.VP8()->numberOfTemporalLayers = 1; | 359 codec_.VP8()->numberOfTemporalLayers = 1; |
| 360 codec_.VP8()->automaticResizeOn = true; |
| 361 codec_.VP8()->frameDroppingOn = true; |
353 codec_.VP8()->tl_factory = tl_factory.get(); | 362 codec_.VP8()->tl_factory = tl_factory.get(); |
354 rate_allocator_.reset( | 363 rate_allocator_.reset( |
355 new SimulcastRateAllocator(codec_, std::move(tl_factory))); | 364 new SimulcastRateAllocator(codec_, std::move(tl_factory))); |
356 } | 365 } |
357 | 366 |
358 void SetRateAllocation(uint32_t bitrate_kbps) { | 367 void SetRateAllocation(uint32_t bitrate_kbps) { |
359 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRateAllocation( | 368 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, fallback_wrapper_.SetRateAllocation( |
360 rate_allocator_->GetAllocation( | 369 rate_allocator_->GetAllocation( |
361 bitrate_kbps * 1000, kFramerate), | 370 bitrate_kbps * 1000, kFramerate), |
362 kFramerate)); | 371 kFramerate)); |
(...skipping 11 matching lines...) Expand all Loading... |
374 | 383 |
375 rtc::ScopedFakeClock clock_; | 384 rtc::ScopedFakeClock clock_; |
376 }; | 385 }; |
377 | 386 |
378 class ForcedFallbackTestEnabled : public ForcedFallbackTest { | 387 class ForcedFallbackTestEnabled : public ForcedFallbackTest { |
379 public: | 388 public: |
380 ForcedFallbackTestEnabled() | 389 ForcedFallbackTestEnabled() |
381 : ForcedFallbackTest(kFieldTrial + "/Enabled-" + | 390 : ForcedFallbackTest(kFieldTrial + "/Enabled-" + |
382 std::to_string(kLowKbps) + "," + | 391 std::to_string(kLowKbps) + "," + |
383 std::to_string(kHighKbps) + "," + | 392 std::to_string(kHighKbps) + "," + |
384 std::to_string(kMinLowDurationMs) + "/") {} | 393 std::to_string(kMinLowDurationMs) + "," + |
| 394 std::to_string(kMinPixelsPerFrame) + "/") {} |
385 }; | 395 }; |
386 | 396 |
387 class ForcedFallbackTestDisabled : public ForcedFallbackTest { | 397 class ForcedFallbackTestDisabled : public ForcedFallbackTest { |
388 public: | 398 public: |
389 ForcedFallbackTestDisabled() | 399 ForcedFallbackTestDisabled() |
390 : ForcedFallbackTest(kFieldTrial + "/Disabled/") {} | 400 : ForcedFallbackTest(kFieldTrial + "/Disabled/") {} |
391 }; | 401 }; |
392 | 402 |
393 TEST_F(ForcedFallbackTestDisabled, NoFallbackWithoutFieldTrial) { | 403 TEST_F(ForcedFallbackTestDisabled, NoFallbackWithoutFieldTrial) { |
394 // Bitrate at low threshold. | 404 // Bitrate at low threshold. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 fallback_wrapper_.InitEncode(&codec_, kNumCores, kMaxPayloadSize)); | 578 fallback_wrapper_.InitEncode(&codec_, kNumCores, kMaxPayloadSize)); |
569 EXPECT_EQ(3, fake_encoder_.init_encode_count_); | 579 EXPECT_EQ(3, fake_encoder_.init_encode_count_); |
570 // Bitrate at low threshold. | 580 // Bitrate at low threshold. |
571 SetRateAllocation(kLowKbps); | 581 SetRateAllocation(kLowKbps); |
572 EncodeFrameAndVerifyLastName("fake-encoder"); | 582 EncodeFrameAndVerifyLastName("fake-encoder"); |
573 // Duration passed, expect no fallback. | 583 // Duration passed, expect no fallback. |
574 clock_.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kMinLowDurationMs)); | 584 clock_.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kMinLowDurationMs)); |
575 EncodeFrameAndVerifyLastName("fake-encoder"); | 585 EncodeFrameAndVerifyLastName("fake-encoder"); |
576 } | 586 } |
577 | 587 |
| 588 TEST_F(ForcedFallbackTestEnabled, GetScaleSettingsWithoutFallback) { |
| 589 // Bitrate at low threshold. |
| 590 SetRateAllocation(kLowKbps); |
| 591 EncodeFrameAndVerifyLastName("fake-encoder"); |
| 592 // Default min pixels per frame should be used. |
| 593 const auto settings = fallback_wrapper_.GetScalingSettings(); |
| 594 EXPECT_TRUE(settings.enabled); |
| 595 EXPECT_EQ(kDefaultMinPixelsPerFrame, settings.min_pixels_per_frame); |
| 596 } |
| 597 |
| 598 TEST_F(ForcedFallbackTestEnabled, GetScaleSettingsWithFallback) { |
| 599 // Bitrate at low threshold. |
| 600 SetRateAllocation(kLowKbps); |
| 601 EncodeFrameAndVerifyLastName("fake-encoder"); |
| 602 // Duration passed, expect fallback. |
| 603 clock_.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kMinLowDurationMs)); |
| 604 EncodeFrameAndVerifyLastName("libvpx"); |
| 605 // Configured min pixels per frame should be used. |
| 606 const auto settings = fallback_wrapper_.GetScalingSettings(); |
| 607 EXPECT_TRUE(settings.enabled); |
| 608 EXPECT_EQ(kMinPixelsPerFrame, settings.min_pixels_per_frame); |
| 609 } |
| 610 |
| 611 TEST_F(ForcedFallbackTestEnabled, FallbackIsKeptIfResolutionIsTooSmall) { |
| 612 // Bitrate at low threshold. |
| 613 SetRateAllocation(kLowKbps); |
| 614 EncodeFrameAndVerifyLastName("fake-encoder"); |
| 615 // Duration passed, expect fallback. |
| 616 clock_.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kMinLowDurationMs)); |
| 617 EncodeFrameAndVerifyLastName("libvpx"); |
| 618 |
| 619 // Re-initialize encoder with a resolution less than |kMinPixelsStop|. |
| 620 codec_.height = kMinPixelsStop / codec_.width - 1; |
| 621 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 622 fallback_wrapper_.InitEncode(&codec_, kNumCores, kMaxPayloadSize)); |
| 623 EXPECT_EQ(1, fake_encoder_.init_encode_count_); // No change |
| 624 SetRateAllocation(kHighKbps - 1); |
| 625 EncodeFrameAndVerifyLastName("libvpx"); |
| 626 // Bitrate at high threshold but resolution too small for fallback to end. |
| 627 SetRateAllocation(kHighKbps); |
| 628 EncodeFrameAndVerifyLastName("libvpx"); |
| 629 |
| 630 // Re-initialize encoder with a resolution equal to |kMinPixelsStop|. |
| 631 codec_.height++; |
| 632 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 633 fallback_wrapper_.InitEncode(&codec_, kNumCores, kMaxPayloadSize)); |
| 634 EXPECT_EQ(1, fake_encoder_.init_encode_count_); // No change |
| 635 SetRateAllocation(kHighKbps - 1); |
| 636 EncodeFrameAndVerifyLastName("libvpx"); |
| 637 // Bitrate at high threshold and resolution large enough for fallback to end. |
| 638 SetRateAllocation(kHighKbps); |
| 639 EncodeFrameAndVerifyLastName("fake-encoder"); |
| 640 } |
| 641 |
578 } // namespace webrtc | 642 } // namespace webrtc |
OLD | NEW |