OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/video_coding/utility/quality_scaler.h" | 11 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
12 | 12 |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 namespace { | 16 namespace { |
17 static const int kNumSeconds = 10; | 17 static const int kNumSeconds = 10; |
18 static const int kWidth = 1920; | 18 static const int kWidth = 1920; |
19 static const int kWidthVga = 640; | |
20 static const int kHalfWidth = kWidth / 2; | 19 static const int kHalfWidth = kWidth / 2; |
21 static const int kHeight = 1080; | 20 static const int kHeight = 1080; |
22 static const int kHeightVga = 480; | |
23 static const int kFramerate = 30; | 21 static const int kFramerate = 30; |
24 static const int kLowQp = 15; | 22 static const int kLowQp = 15; |
25 static const int kNormalQp = 30; | 23 static const int kNormalQp = 30; |
26 static const int kLowQpThreshold = 18; | 24 static const int kLowQpThreshold = 18; |
27 static const int kHighQp = 40; | 25 static const int kHighQp = 40; |
28 static const int kDisabledBadQpThreshold = 64; | 26 static const int kDisabledBadQpThreshold = 64; |
29 static const int kLowInitialBitrateKbps = 300; | 27 static const int kLowInitialBitrateKbps = 300; |
30 // These values need to be in sync with corresponding constants | 28 // These values need to be in sync with corresponding constants |
31 // in quality_scaler.cc | 29 // in quality_scaler.cc |
32 static const int kMeasureSecondsFastUpscale = 2; | 30 static const int kMeasureSecondsFastUpscale = 2; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 DoesNotDownscaleFrameDimensions( | 371 DoesNotDownscaleFrameDimensions( |
374 2 * kMinDownscaleDimension - 1, 1000); | 372 2 * kMinDownscaleDimension - 1, 1000); |
375 } | 373 } |
376 | 374 |
377 TEST_F(QualityScalerTest, DoesNotDownscaleBelow2xDefaultMinDimensionsHeight) { | 375 TEST_F(QualityScalerTest, DoesNotDownscaleBelow2xDefaultMinDimensionsHeight) { |
378 DoesNotDownscaleFrameDimensions( | 376 DoesNotDownscaleFrameDimensions( |
379 1000, 2 * kMinDownscaleDimension - 1); | 377 1000, 2 * kMinDownscaleDimension - 1); |
380 } | 378 } |
381 | 379 |
382 TEST_F(QualityScalerTest, DownscaleToVgaOnLowInitialBitrate) { | 380 TEST_F(QualityScalerTest, DownscaleToVgaOnLowInitialBitrate) { |
383 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, true, | 381 static const int kWidth720p = 1280; |
384 kLowInitialBitrateKbps, kWidth, kHeight, kFramerate); | 382 static const int kHeight720p = 720; |
| 383 static const int kInitialBitrateKbps = 300; |
| 384 input_frame_.CreateEmptyFrame(kWidth720p, kHeight720p, kWidth720p, |
| 385 kWidth720p / 2, kWidth720p / 2); |
| 386 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, true, kInitialBitrateKbps, |
| 387 kWidth720p, kHeight720p, kFramerate); |
385 qs_.OnEncodeFrame(input_frame_); | 388 qs_.OnEncodeFrame(input_frame_); |
386 int init_width = qs_.GetScaledResolution().width; | 389 int init_width = qs_.GetScaledResolution().width; |
387 int init_height = qs_.GetScaledResolution().height; | 390 int init_height = qs_.GetScaledResolution().height; |
388 EXPECT_LE(init_width, kWidthVga); | 391 EXPECT_EQ(640, init_width); |
389 EXPECT_LE(init_height, kHeightVga); | 392 EXPECT_EQ(360, init_height); |
| 393 } |
| 394 |
| 395 TEST_F(QualityScalerTest, DownscaleToQvgaOnLowerInitialBitrate) { |
| 396 static const int kWidth720p = 1280; |
| 397 static const int kHeight720p = 720; |
| 398 static const int kInitialBitrateKbps = 200; |
| 399 input_frame_.CreateEmptyFrame(kWidth720p, kHeight720p, kWidth720p, |
| 400 kWidth720p / 2, kWidth720p / 2); |
| 401 qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, true, kInitialBitrateKbps, |
| 402 kWidth720p, kHeight720p, kFramerate); |
| 403 qs_.OnEncodeFrame(input_frame_); |
| 404 int init_width = qs_.GetScaledResolution().width; |
| 405 int init_height = qs_.GetScaledResolution().height; |
| 406 EXPECT_EQ(320, init_width); |
| 407 EXPECT_EQ(180, init_height); |
390 } | 408 } |
391 | 409 |
392 TEST_F(QualityScalerTest, DownscaleAfterMeasuredSecondsThenSlowerBackUp) { | 410 TEST_F(QualityScalerTest, DownscaleAfterMeasuredSecondsThenSlowerBackUp) { |
393 QualityScalerTest::Resolution initial_res; | 411 QualityScalerTest::Resolution initial_res; |
394 qs_.Init(kLowQpThreshold, kHighQp, false, 0, kWidth, kHeight, kFramerate); | 412 qs_.Init(kLowQpThreshold, kHighQp, false, 0, kWidth, kHeight, kFramerate); |
395 qs_.OnEncodeFrame(input_frame_); | 413 qs_.OnEncodeFrame(input_frame_); |
396 initial_res.width = qs_.GetScaledResolution().width; | 414 initial_res.width = qs_.GetScaledResolution().width; |
397 initial_res.height = qs_.GetScaledResolution().height; | 415 initial_res.height = qs_.GetScaledResolution().height; |
398 | 416 |
399 // Should not downscale if less than kMeasureSecondsDownscale seconds passed. | 417 // Should not downscale if less than kMeasureSecondsDownscale seconds passed. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 506 |
489 TEST_F(QualityScalerTest, DownscalesFrom1280x720To320x180) { | 507 TEST_F(QualityScalerTest, DownscalesFrom1280x720To320x180) { |
490 DownscaleEndsAt(1280, 720, 320, 180); | 508 DownscaleEndsAt(1280, 720, 320, 180); |
491 } | 509 } |
492 | 510 |
493 TEST_F(QualityScalerTest, DoesntDownscaleInitialQvga) { | 511 TEST_F(QualityScalerTest, DoesntDownscaleInitialQvga) { |
494 DownscaleEndsAt(320, 180, 320, 180); | 512 DownscaleEndsAt(320, 180, 320, 180); |
495 } | 513 } |
496 | 514 |
497 } // namespace webrtc | 515 } // namespace webrtc |
OLD | NEW |