1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "call/adaptation/video_source_restrictions.h"
#include <cstddef>
#include <optional>
#include "test/gtest.h"
namespace webrtc {
namespace {
const size_t kHdPixels = 1280 * 720;
const VideoSourceRestrictions kUnlimited;
const VideoSourceRestrictions k15fps(std::nullopt, std::nullopt, 15.0);
const VideoSourceRestrictions kHd(kHdPixels, kHdPixels, std::nullopt);
const VideoSourceRestrictions kHd15fps(kHdPixels, kHdPixels, 15.0);
const VideoSourceRestrictions kVga7fps(kHdPixels / 2, kHdPixels / 2, 7.0);
VideoSourceRestrictions RestrictionsFromMaxPixelsPerFrame(
size_t max_pixels_per_frame) {
return VideoSourceRestrictions(max_pixels_per_frame, std::nullopt,
std::nullopt);
}
VideoSourceRestrictions RestrictionsFromMaxFrameRate(double max_frame_rate) {
return VideoSourceRestrictions(std::nullopt, std::nullopt, max_frame_rate);
}
} // namespace
TEST(VideoSourceRestrictionsTest, DidIncreaseResolution) {
// smaller restrictions -> larger restrictions
EXPECT_TRUE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
RestrictionsFromMaxPixelsPerFrame(11)));
// unrestricted -> restricted
EXPECT_FALSE(DidIncreaseResolution(VideoSourceRestrictions(),
RestrictionsFromMaxPixelsPerFrame(10)));
// restricted -> unrestricted
EXPECT_TRUE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
VideoSourceRestrictions()));
// restricted -> equally restricted
EXPECT_FALSE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
RestrictionsFromMaxPixelsPerFrame(10)));
// unrestricted -> unrestricted
EXPECT_FALSE(DidIncreaseResolution(VideoSourceRestrictions(),
VideoSourceRestrictions()));
// larger restrictions -> smaller restrictions
EXPECT_FALSE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
RestrictionsFromMaxPixelsPerFrame(9)));
}
TEST(VideoSourceRestrictionsTest, DidDecreaseFrameRate) {
// samller restrictions -> larger restrictions
EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
RestrictionsFromMaxFrameRate(11)));
// unrestricted -> restricted
EXPECT_TRUE(DidDecreaseFrameRate(VideoSourceRestrictions(),
RestrictionsFromMaxFrameRate(10)));
// restricted -> unrestricted
EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
VideoSourceRestrictions()));
// restricted -> equally restricted
EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
RestrictionsFromMaxFrameRate(10)));
// unrestricted -> unrestricted
EXPECT_FALSE(DidDecreaseFrameRate(VideoSourceRestrictions(),
VideoSourceRestrictions()));
// larger restrictions -> samller restrictions
EXPECT_TRUE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
RestrictionsFromMaxFrameRate(9)));
}
TEST(VideoSourceRestrictionsTest, DidRestrictionsChangeFalseForSame) {
EXPECT_FALSE(DidRestrictionsDecrease(kUnlimited, kUnlimited));
EXPECT_FALSE(DidRestrictionsIncrease(kUnlimited, kUnlimited));
// Both resolution and fps restricted.
EXPECT_FALSE(DidRestrictionsDecrease(kHd15fps, kHd15fps));
EXPECT_FALSE(DidRestrictionsIncrease(kHd15fps, kHd15fps));
}
TEST(VideoSourceRestrictions,
DidRestrictionsIncreaseTrueWhenPixelsOrFrameRateDecreased) {
// Unlimited > Limited resolution.
EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, kHd));
// Unlimited > limited fps.
EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, k15fps));
// Unlimited > limited resolution + limited fps.
EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, kHd15fps));
// Limited resolution > limited resolution + limited fps.
EXPECT_TRUE(DidRestrictionsIncrease(kHd, kHd15fps));
// Limited fps > limited resolution + limited fps.
EXPECT_TRUE(DidRestrictionsIncrease(k15fps, kHd15fps));
// Limited resolution + fps > More limited resolution + more limited fps
EXPECT_TRUE(DidRestrictionsIncrease(kHd15fps, kVga7fps));
}
TEST(VideoSourceRestrictions,
DidRestrictionsDecreaseTrueWhenPixelsOrFrameRateIncreased) {
// Limited resolution < Unlimited.
EXPECT_TRUE(DidRestrictionsDecrease(kHd, kUnlimited));
// Limited fps < Unlimited.
EXPECT_TRUE(DidRestrictionsDecrease(k15fps, kUnlimited));
// Limited resolution + limited fps < unlimited.
EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, kUnlimited));
// Limited resolution + limited fps < limited resolution.
EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, kHd));
// Limited resolution + limited fps < limited fps.
EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, k15fps));
// More limited resolution + more limited fps < limited resolution + fps
EXPECT_TRUE(DidRestrictionsDecrease(kVga7fps, kHd15fps));
}
TEST(VideoSourceRestrictions,
DidRestrictionsChangeFalseWhenFrameRateAndPixelsChangeDifferently) {
// One changed framerate, the other resolution; not an increase or decrease.
EXPECT_FALSE(DidRestrictionsIncrease(kHd, k15fps));
EXPECT_FALSE(DidRestrictionsDecrease(kHd, k15fps));
}
TEST(VideoSourceRestrictions, UpdateMin) {
VideoSourceRestrictions one(kHdPixels / 2, kHdPixels, 7.0);
VideoSourceRestrictions two(kHdPixels, kHdPixels / 3, 15.0);
one.UpdateMin(two);
EXPECT_EQ(one.max_pixels_per_frame(), kHdPixels / 2);
EXPECT_EQ(one.target_pixels_per_frame(), kHdPixels / 3);
EXPECT_EQ(one.max_frame_rate(), 7.0);
two.UpdateMin(one);
EXPECT_EQ(two.max_pixels_per_frame(), kHdPixels / 2);
EXPECT_EQ(two.target_pixels_per_frame(), kHdPixels / 3);
EXPECT_EQ(two.max_frame_rate(), 7.0);
}
} // namespace webrtc
|