aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_coding/codecs
diff options
context:
space:
mode:
authorkwiberg <kwiberg@webrtc.org>2015-09-09 06:42:56 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-09 13:43:04 +0000
commit942a699f14317927f9069a908e74c28338c5c5a8 (patch)
tree4d4434ed5c4d94366cab6c7e2f45efbe49fc17eb /webrtc/modules/audio_coding/codecs
parent2feafdb742226f57588d9c95bc25b2202166688f (diff)
downloadwebrtc-942a699f14317927f9069a908e74c28338c5c5a8.tar.gz
AudioEncoderOpusTest.PacketLossRateOptimized: Fix bug and make prettier
Fix bug 4981, which caused the second half (decreasing loss rates) to not test anything. In the process, the test is changed slightly to make it less dependent on the exact rounding behavior of doubles (by not testing exactly at the the points where the effective loss rate goes through a step---just very very close). A bunch of symbolic constants are also replaced with easy-to-read literal numbers. BUG=4981 Review URL: https://codereview.webrtc.org/1316673010 Cr-Commit-Position: refs/heads/master@{#9908}
Diffstat (limited to 'webrtc/modules/audio_coding/codecs')
-rw-r--r--webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc74
1 files changed, 32 insertions, 42 deletions
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 71c89bf099..5648c18f5b 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
@@ -101,25 +101,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());
}
@@ -129,33 +128,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