Henrik Boström | 722fa4d | 2020-04-29 16:46:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "call/adaptation/video_source_restrictions.h" |
| 12 | |
| 13 | #include "test/gtest.h" |
| 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | namespace { |
| 18 | |
Evan Shrubsole | 3b6afee | 2020-05-07 13:55:54 +0200 | [diff] [blame] | 19 | const size_t kHdPixels = 1280 * 720; |
| 20 | |
| 21 | const VideoSourceRestrictions kUnlimited; |
| 22 | const VideoSourceRestrictions k15fps(absl::nullopt, absl::nullopt, 15.0); |
| 23 | const VideoSourceRestrictions kHd(kHdPixels, kHdPixels, absl::nullopt); |
| 24 | const VideoSourceRestrictions kHd15fps(kHdPixels, kHdPixels, 15.0); |
| 25 | const VideoSourceRestrictions kVga7fps(kHdPixels / 2, kHdPixels / 2, 7.0); |
| 26 | |
Henrik Boström | 722fa4d | 2020-04-29 16:46:30 +0200 | [diff] [blame] | 27 | VideoSourceRestrictions RestrictionsFromMaxPixelsPerFrame( |
| 28 | size_t max_pixels_per_frame) { |
| 29 | return VideoSourceRestrictions(max_pixels_per_frame, absl::nullopt, |
| 30 | absl::nullopt); |
| 31 | } |
| 32 | |
| 33 | VideoSourceRestrictions RestrictionsFromMaxFrameRate(double max_frame_rate) { |
| 34 | return VideoSourceRestrictions(absl::nullopt, absl::nullopt, max_frame_rate); |
| 35 | } |
| 36 | |
| 37 | } // namespace |
| 38 | |
| 39 | TEST(VideoSourceRestrictionsTest, DidIncreaseResolution) { |
| 40 | // smaller restrictions -> larger restrictions |
| 41 | EXPECT_TRUE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10), |
| 42 | RestrictionsFromMaxPixelsPerFrame(11))); |
| 43 | // unrestricted -> restricted |
| 44 | EXPECT_FALSE(DidIncreaseResolution(VideoSourceRestrictions(), |
| 45 | RestrictionsFromMaxPixelsPerFrame(10))); |
| 46 | // restricted -> unrestricted |
| 47 | EXPECT_TRUE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10), |
| 48 | VideoSourceRestrictions())); |
| 49 | // restricted -> equally restricted |
| 50 | EXPECT_FALSE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10), |
| 51 | RestrictionsFromMaxPixelsPerFrame(10))); |
| 52 | // unrestricted -> unrestricted |
| 53 | EXPECT_FALSE(DidIncreaseResolution(VideoSourceRestrictions(), |
| 54 | VideoSourceRestrictions())); |
| 55 | // larger restrictions -> smaller restrictions |
| 56 | EXPECT_FALSE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10), |
| 57 | RestrictionsFromMaxPixelsPerFrame(9))); |
| 58 | } |
| 59 | |
| 60 | TEST(VideoSourceRestrictionsTest, DidDecreaseFrameRate) { |
| 61 | // samller restrictions -> larger restrictions |
| 62 | EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10), |
| 63 | RestrictionsFromMaxFrameRate(11))); |
| 64 | // unrestricted -> restricted |
| 65 | EXPECT_TRUE(DidDecreaseFrameRate(VideoSourceRestrictions(), |
| 66 | RestrictionsFromMaxFrameRate(10))); |
| 67 | // restricted -> unrestricted |
| 68 | EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10), |
| 69 | VideoSourceRestrictions())); |
| 70 | // restricted -> equally restricted |
| 71 | EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10), |
| 72 | RestrictionsFromMaxFrameRate(10))); |
| 73 | // unrestricted -> unrestricted |
| 74 | EXPECT_FALSE(DidDecreaseFrameRate(VideoSourceRestrictions(), |
| 75 | VideoSourceRestrictions())); |
| 76 | // larger restrictions -> samller restrictions |
| 77 | EXPECT_TRUE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10), |
| 78 | RestrictionsFromMaxFrameRate(9))); |
| 79 | } |
| 80 | |
Evan Shrubsole | 3b6afee | 2020-05-07 13:55:54 +0200 | [diff] [blame] | 81 | TEST(VideoSourceRestrictionsTest, DidRestrictionsChangeFalseForSame) { |
| 82 | EXPECT_FALSE(DidRestrictionsDecrease(kUnlimited, kUnlimited)); |
| 83 | EXPECT_FALSE(DidRestrictionsIncrease(kUnlimited, kUnlimited)); |
| 84 | |
| 85 | // Both resolution and fps restricted. |
| 86 | EXPECT_FALSE(DidRestrictionsDecrease(kHd15fps, kHd15fps)); |
| 87 | EXPECT_FALSE(DidRestrictionsIncrease(kHd15fps, kHd15fps)); |
| 88 | } |
| 89 | |
| 90 | TEST(VideoSourceRestrictions, |
| 91 | DidRestrictionsIncreaseTrueWhenPixelsOrFrameRateDecreased) { |
| 92 | // Unlimited > Limited resolution. |
| 93 | EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, kHd)); |
| 94 | // Unlimited > limited fps. |
| 95 | EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, k15fps)); |
| 96 | // Unlimited > limited resolution + limited fps. |
| 97 | EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, kHd15fps)); |
| 98 | // Limited resolution > limited resolution + limited fps. |
| 99 | EXPECT_TRUE(DidRestrictionsIncrease(kHd, kHd15fps)); |
| 100 | // Limited fps > limited resolution + limited fps. |
| 101 | EXPECT_TRUE(DidRestrictionsIncrease(k15fps, kHd15fps)); |
| 102 | // Limited resolution + fps > More limited resolution + more limited fps |
| 103 | EXPECT_TRUE(DidRestrictionsIncrease(kHd15fps, kVga7fps)); |
| 104 | } |
| 105 | |
| 106 | TEST(VideoSourceRestrictions, |
| 107 | DidRestrictionsDecreaseTrueWhenPixelsOrFrameRateIncreased) { |
| 108 | // Limited resolution < Unlimited. |
| 109 | EXPECT_TRUE(DidRestrictionsDecrease(kHd, kUnlimited)); |
| 110 | // Limited fps < Unlimited. |
| 111 | EXPECT_TRUE(DidRestrictionsDecrease(k15fps, kUnlimited)); |
| 112 | // Limited resolution + limited fps < unlimited. |
| 113 | EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, kUnlimited)); |
| 114 | // Limited resolution + limited fps < limited resolution. |
| 115 | EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, kHd)); |
| 116 | // Limited resolution + limited fps < limited fps. |
| 117 | EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, k15fps)); |
| 118 | // More limited resolution + more limited fps < limited resolution + fps |
| 119 | EXPECT_TRUE(DidRestrictionsDecrease(kVga7fps, kHd15fps)); |
| 120 | } |
| 121 | |
| 122 | TEST(VideoSourceRestrictions, |
| 123 | DidRestrictionsChangeFalseWhenFrameRateAndPixelsChangeDifferently) { |
| 124 | // One changed framerate, the other resolution; not an increase or decrease. |
| 125 | EXPECT_FALSE(DidRestrictionsIncrease(kHd, k15fps)); |
| 126 | EXPECT_FALSE(DidRestrictionsDecrease(kHd, k15fps)); |
| 127 | } |
| 128 | |
Henrik Boström | 722fa4d | 2020-04-29 16:46:30 +0200 | [diff] [blame] | 129 | } // namespace webrtc |