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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
/*
* Copyright (c) 2018 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/rtp_bitrate_configurator.h"
#include <memory>
#include <optional>
#include "api/transport/bitrate_settings.h"
#include "test/gtest.h"
namespace webrtc {
using std::nullopt;
class RtpBitrateConfiguratorTest : public ::testing::Test {
public:
RtpBitrateConfiguratorTest()
: configurator_(new RtpBitrateConfigurator(BitrateConstraints())) {}
std::unique_ptr<RtpBitrateConfigurator> configurator_;
void UpdateConfigMatches(BitrateConstraints bitrate_config,
std::optional<int> min_bitrate_bps,
std::optional<int> start_bitrate_bps,
std::optional<int> max_bitrate_bps) {
std::optional<BitrateConstraints> result =
configurator_->UpdateWithSdpParameters(bitrate_config);
EXPECT_TRUE(result.has_value());
if (start_bitrate_bps.has_value())
EXPECT_EQ(result->start_bitrate_bps, start_bitrate_bps);
if (min_bitrate_bps.has_value())
EXPECT_EQ(result->min_bitrate_bps, min_bitrate_bps);
if (max_bitrate_bps.has_value())
EXPECT_EQ(result->max_bitrate_bps, max_bitrate_bps);
}
void UpdateMaskMatches(BitrateSettings bitrate_mask,
std::optional<int> min_bitrate_bps,
std::optional<int> start_bitrate_bps,
std::optional<int> max_bitrate_bps) {
std::optional<BitrateConstraints> result =
configurator_->UpdateWithClientPreferences(bitrate_mask);
EXPECT_TRUE(result.has_value());
if (start_bitrate_bps.has_value())
EXPECT_EQ(result->start_bitrate_bps, start_bitrate_bps);
if (min_bitrate_bps.has_value())
EXPECT_EQ(result->min_bitrate_bps, min_bitrate_bps);
if (max_bitrate_bps.has_value())
EXPECT_EQ(result->max_bitrate_bps, max_bitrate_bps);
}
};
TEST_F(RtpBitrateConfiguratorTest, NewConfigWithValidConfigReturnsNewConfig) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 1;
bitrate_config.start_bitrate_bps = 2;
bitrate_config.max_bitrate_bps = 3;
UpdateConfigMatches(bitrate_config, 1, 2, 3);
}
TEST_F(RtpBitrateConfiguratorTest, NewConfigWithDifferentMinReturnsNewConfig) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 10;
bitrate_config.start_bitrate_bps = 20;
bitrate_config.max_bitrate_bps = 30;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
bitrate_config.min_bitrate_bps = 11;
UpdateConfigMatches(bitrate_config, 11, -1, 30);
}
TEST_F(RtpBitrateConfiguratorTest,
NewConfigWithDifferentStartReturnsNewConfig) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 10;
bitrate_config.start_bitrate_bps = 20;
bitrate_config.max_bitrate_bps = 30;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
bitrate_config.start_bitrate_bps = 21;
UpdateConfigMatches(bitrate_config, 10, 21, 30);
}
TEST_F(RtpBitrateConfiguratorTest, NewConfigWithDifferentMaxReturnsNewConfig) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 10;
bitrate_config.start_bitrate_bps = 20;
bitrate_config.max_bitrate_bps = 30;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
bitrate_config.max_bitrate_bps = 31;
UpdateConfigMatches(bitrate_config, 10, -1, 31);
}
TEST_F(RtpBitrateConfiguratorTest, NewConfigWithSameConfigElidesSecondCall) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 1;
bitrate_config.start_bitrate_bps = 2;
bitrate_config.max_bitrate_bps = 3;
UpdateConfigMatches(bitrate_config, 1, 2, 3);
EXPECT_FALSE(
configurator_->UpdateWithSdpParameters(bitrate_config).has_value());
}
TEST_F(RtpBitrateConfiguratorTest,
NewConfigWithSameMinMaxAndNegativeStartElidesSecondCall) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 1;
bitrate_config.start_bitrate_bps = 2;
bitrate_config.max_bitrate_bps = 3;
UpdateConfigMatches(bitrate_config, 1, 2, 3);
bitrate_config.start_bitrate_bps = -1;
EXPECT_FALSE(
configurator_->UpdateWithSdpParameters(bitrate_config).has_value());
}
TEST_F(RtpBitrateConfiguratorTest, BiggerMaskMinUsed) {
BitrateSettings mask;
mask.min_bitrate_bps = 1234;
UpdateMaskMatches(mask, *mask.min_bitrate_bps, nullopt, nullopt);
}
TEST_F(RtpBitrateConfiguratorTest, BiggerConfigMinUsed) {
BitrateSettings mask;
mask.min_bitrate_bps = 1000;
UpdateMaskMatches(mask, 1000, nullopt, nullopt);
BitrateConstraints config;
config.min_bitrate_bps = 1234;
UpdateConfigMatches(config, 1234, nullopt, nullopt);
}
// The last call to set start should be used.
TEST_F(RtpBitrateConfiguratorTest, LatestStartMaskPreferred) {
BitrateSettings mask;
mask.start_bitrate_bps = 1300;
UpdateMaskMatches(mask, nullopt, *mask.start_bitrate_bps, nullopt);
BitrateConstraints bitrate_config;
bitrate_config.start_bitrate_bps = 1200;
UpdateConfigMatches(bitrate_config, nullopt, bitrate_config.start_bitrate_bps,
nullopt);
}
TEST_F(RtpBitrateConfiguratorTest, SmallerMaskMaxUsed) {
BitrateConstraints bitrate_config;
bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 2000;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
BitrateSettings mask;
mask.max_bitrate_bps = bitrate_config.start_bitrate_bps + 1000;
UpdateMaskMatches(mask, nullopt, nullopt, *mask.max_bitrate_bps);
}
TEST_F(RtpBitrateConfiguratorTest, SmallerConfigMaxUsed) {
BitrateConstraints bitrate_config;
bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 1000;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
BitrateSettings mask;
mask.max_bitrate_bps = bitrate_config.start_bitrate_bps + 2000;
// Expect no return because nothing changes
EXPECT_FALSE(configurator_->UpdateWithClientPreferences(mask).has_value());
}
TEST_F(RtpBitrateConfiguratorTest, MaskStartLessThanConfigMinClamped) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 2000;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
BitrateSettings mask;
mask.start_bitrate_bps = 1000;
UpdateMaskMatches(mask, 2000, 2000, nullopt);
}
TEST_F(RtpBitrateConfiguratorTest, MaskStartGreaterThanConfigMaxClamped) {
BitrateConstraints bitrate_config;
bitrate_config.start_bitrate_bps = 2000;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
BitrateSettings mask;
mask.max_bitrate_bps = 1000;
UpdateMaskMatches(mask, nullopt, -1, 1000);
}
TEST_F(RtpBitrateConfiguratorTest, MaskMinGreaterThanConfigMaxClamped) {
BitrateConstraints bitrate_config;
bitrate_config.min_bitrate_bps = 2000;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
BitrateSettings mask;
mask.max_bitrate_bps = 1000;
UpdateMaskMatches(mask, 1000, nullopt, 1000);
}
TEST_F(RtpBitrateConfiguratorTest, SettingMaskStartForcesUpdate) {
BitrateSettings mask;
mask.start_bitrate_bps = 1000;
// Config should be returned twice with the same params since
// start_bitrate_bps is set.
UpdateMaskMatches(mask, nullopt, 1000, nullopt);
UpdateMaskMatches(mask, nullopt, 1000, nullopt);
}
TEST_F(RtpBitrateConfiguratorTest, NewConfigWithNoChangesDoesNotCallNewConfig) {
BitrateConstraints config1;
config1.min_bitrate_bps = 0;
config1.start_bitrate_bps = 1000;
config1.max_bitrate_bps = -1;
BitrateConstraints config2;
config2.min_bitrate_bps = 0;
config2.start_bitrate_bps = -1;
config2.max_bitrate_bps = -1;
// The second call should not return anything because it doesn't
// change any values.
UpdateConfigMatches(config1, 0, 1000, -1);
EXPECT_FALSE(configurator_->UpdateWithSdpParameters(config2).has_value());
}
// If config changes the max, but not the effective max,
// new config shouldn't be returned, to avoid unnecessary encoder
// reconfigurations.
TEST_F(RtpBitrateConfiguratorTest,
NewConfigNotReturnedWhenEffectiveMaxUnchanged) {
BitrateConstraints config;
config.min_bitrate_bps = 0;
config.start_bitrate_bps = -1;
config.max_bitrate_bps = 2000;
UpdateConfigMatches(config, nullopt, nullopt, 2000);
// Reduce effective max to 1000 with the mask.
BitrateSettings mask;
mask.max_bitrate_bps = 1000;
UpdateMaskMatches(mask, nullopt, nullopt, 1000);
// This leaves the effective max unchanged, so new config shouldn't be
// returned again.
config.max_bitrate_bps = 1000;
EXPECT_FALSE(configurator_->UpdateWithSdpParameters(config).has_value());
}
// When the "start bitrate" mask is removed, new config shouldn't be returned
// again, since nothing's changing.
TEST_F(RtpBitrateConfiguratorTest, NewConfigNotReturnedWhenStartMaskRemoved) {
BitrateSettings mask;
mask.start_bitrate_bps = 1000;
UpdateMaskMatches(mask, 0, 1000, -1);
mask.start_bitrate_bps.reset();
EXPECT_FALSE(configurator_->UpdateWithClientPreferences(mask).has_value());
}
// Test that if a new config is returned after BitrateSettings applies a
// "start" value, the new config won't return that start value a
// second time.
TEST_F(RtpBitrateConfiguratorTest, NewConfigAfterBitrateConfigMaskWithStart) {
BitrateSettings mask;
mask.start_bitrate_bps = 1000;
UpdateMaskMatches(mask, 0, 1000, -1);
BitrateConstraints config;
config.min_bitrate_bps = 0;
config.start_bitrate_bps = -1;
config.max_bitrate_bps = 5000;
// The start value isn't changing, so new config should be returned with
// -1.
UpdateConfigMatches(config, 0, -1, 5000);
}
TEST_F(RtpBitrateConfiguratorTest,
NewConfigNotReturnedWhenClampedMinUnchanged) {
BitrateConstraints bitrate_config;
bitrate_config.start_bitrate_bps = 500;
bitrate_config.max_bitrate_bps = 1000;
configurator_.reset(new RtpBitrateConfigurator(bitrate_config));
// Set min to 2000; it is clamped to the max (1000).
BitrateSettings mask;
mask.min_bitrate_bps = 2000;
UpdateMaskMatches(mask, 1000, -1, 1000);
// Set min to 3000; the clamped value stays the same so nothing happens.
mask.min_bitrate_bps = 3000;
EXPECT_FALSE(configurator_->UpdateWithClientPreferences(mask).has_value());
}
} // namespace webrtc
|