| Index: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| index 6725f56978e3b72f31d2f8b015d4bc13378ad277..d3f92f37d6695614968c5ad737acdf630c07cb07 100644
|
| --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| @@ -97,25 +97,24 @@ TEST_F(AudioEncoderOpusTest, SetBitrate) {
|
|
|
| namespace {
|
|
|
| -// These constants correspond to those used in
|
| -// AudioEncoderOpus::SetProjectedPacketLossRate.
|
| -const double kPacketLossRate20 = 0.20;
|
| -const double kPacketLossRate10 = 0.10;
|
| -const double kPacketLossRate5 = 0.05;
|
| -const double kPacketLossRate1 = 0.01;
|
| -const double kLossRate20Margin = 0.02;
|
| -const double kLossRate10Margin = 0.01;
|
| -const double kLossRate5Margin = 0.01;
|
| -
|
| -// Repeatedly sets packet loss rates in the range [from, to], increasing by
|
| -// 0.01 in each step. The function verifies that the actual loss rate is
|
| -// |expected_return|.
|
| +// Returns a vector with the n evenly-spaced numbers a, a + (b - a)/(n - 1),
|
| +// ..., b.
|
| +std::vector<double> IntervalSteps(double a, double b, size_t n) {
|
| + DCHECK_GT(n, 1u);
|
| + const double step = (b - a) / (n - 1);
|
| + std::vector<double> points;
|
| + for (size_t i = 0; i < n; ++i)
|
| + points.push_back(a + i * step);
|
| + return points;
|
| +}
|
| +
|
| +// Sets the packet loss rate to each number in the vector in turn, and verifies
|
| +// that the loss rate as reported by the encoder is |expected_return| for all
|
| +// of them.
|
| void TestSetPacketLossRate(AudioEncoderOpus* encoder,
|
| - double from,
|
| - double to,
|
| + const std::vector<double>& losses,
|
| double expected_return) {
|
| - for (double loss = from; loss <= to;
|
| - (to >= from) ? loss += 0.01 : loss -= 0.01) {
|
| + for (double loss : losses) {
|
| encoder->SetProjectedPacketLossRate(loss);
|
| EXPECT_DOUBLE_EQ(expected_return, encoder->packet_loss_rate());
|
| }
|
| @@ -125,33 +124,24 @@ void TestSetPacketLossRate(AudioEncoderOpus* encoder,
|
|
|
| TEST_F(AudioEncoderOpusTest, PacketLossRateOptimized) {
|
| CreateCodec(1);
|
| + auto I = [](double a, double b) { return IntervalSteps(a, b, 10); };
|
| + const double eps = 1e-15;
|
|
|
| // Note that the order of the following calls is critical.
|
| - TestSetPacketLossRate(encoder_.get(), 0.0, 0.0, 0.0);
|
| - TestSetPacketLossRate(encoder_.get(), kPacketLossRate1,
|
| - kPacketLossRate5 + kLossRate5Margin - 0.01,
|
| - kPacketLossRate1);
|
| - TestSetPacketLossRate(encoder_.get(), kPacketLossRate5 + kLossRate5Margin,
|
| - kPacketLossRate10 + kLossRate10Margin - 0.01,
|
| - kPacketLossRate5);
|
| - TestSetPacketLossRate(encoder_.get(), kPacketLossRate10 + kLossRate10Margin,
|
| - kPacketLossRate20 + kLossRate20Margin - 0.01,
|
| - kPacketLossRate10);
|
| - TestSetPacketLossRate(encoder_.get(), kPacketLossRate20 + kLossRate20Margin,
|
| - 1.0, kPacketLossRate20);
|
| - TestSetPacketLossRate(encoder_.get(), kPacketLossRate20 + kLossRate20Margin,
|
| - kPacketLossRate20 - kLossRate20Margin,
|
| - kPacketLossRate20);
|
| - TestSetPacketLossRate(
|
| - encoder_.get(), kPacketLossRate20 - kLossRate20Margin - 0.01,
|
| - kPacketLossRate10 - kLossRate10Margin, kPacketLossRate10);
|
| - TestSetPacketLossRate(encoder_.get(),
|
| - kPacketLossRate10 - kLossRate10Margin - 0.01,
|
| - kPacketLossRate5 - kLossRate5Margin, kPacketLossRate5);
|
| - TestSetPacketLossRate(encoder_.get(),
|
| - kPacketLossRate5 - kLossRate5Margin - 0.01,
|
| - kPacketLossRate1, kPacketLossRate1);
|
| - TestSetPacketLossRate(encoder_.get(), 0.0, 0.0, 0.0);
|
| +
|
| + // clang-format off
|
| + TestSetPacketLossRate(encoder_.get(), I(0.00 , 0.01 - eps), 0.00);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.01 + eps, 0.06 - eps), 0.01);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.06 + eps, 0.11 - eps), 0.05);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.11 + eps, 0.22 - eps), 0.10);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.22 + eps, 1.00 ), 0.20);
|
| +
|
| + TestSetPacketLossRate(encoder_.get(), I(1.00 , 0.18 + eps), 0.20);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.18 - eps, 0.09 + eps), 0.10);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.09 - eps, 0.04 + eps), 0.05);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.04 - eps, 0.01 + eps), 0.01);
|
| + TestSetPacketLossRate(encoder_.get(), I(0.01 - eps, 0.00 ), 0.00);
|
| + // clang-format on
|
| }
|
|
|
| } // namespace webrtc
|
|
|