OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate()); | 90 EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate()); |
91 // Set rates from 1000 up to 32000 bps. | 91 // Set rates from 1000 up to 32000 bps. |
92 for (int rate = 1000; rate <= 32000; rate += 1000) { | 92 for (int rate = 1000; rate <= 32000; rate += 1000) { |
93 encoder_->SetTargetBitrate(rate); | 93 encoder_->SetTargetBitrate(rate); |
94 EXPECT_EQ(rate, encoder_->GetTargetBitrate()); | 94 EXPECT_EQ(rate, encoder_->GetTargetBitrate()); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 namespace { | 98 namespace { |
99 | 99 |
100 // These constants correspond to those used in | 100 // If a < b, returns a vector with the n evenly-spaced numbers min(a,b) + eps, |
minyue-webrtc
2015/09/09 11:40:29
do you add/minus eps in this function?
kwiberg-webrtc
2015/09/09 11:51:42
I used to, but then I changed it. Patch set #2 cha
| |
101 // AudioEncoderOpus::SetProjectedPacketLossRate. | 101 // ..., max(a,b) - eps. If a > b, returns the same vector reversed. |
102 const double kPacketLossRate20 = 0.20; | 102 std::vector<double> IntervalSteps(double a, double b, size_t n) { |
103 const double kPacketLossRate10 = 0.10; | 103 DCHECK_GT(n, 1u); |
104 const double kPacketLossRate5 = 0.05; | 104 if (a > b) { |
105 const double kPacketLossRate1 = 0.01; | 105 auto r = IntervalSteps(b, a, n); |
106 const double kLossRate20Margin = 0.02; | 106 std::reverse(r.begin(), r.end()); |
107 const double kLossRate10Margin = 0.01; | 107 return r; |
108 const double kLossRate5Margin = 0.01; | 108 } |
109 DCHECK_LT(a, b); | |
110 const double step = (b - a) / (n - 1); | |
111 DCHECK_GT(step, 0.0); | |
112 std::vector<double> points; | |
113 for (size_t i = 0; i < n; ++i) | |
114 points.push_back(std::min(b, std::max(a, a + i * step))); | |
115 return points; | |
minyue-webrtc
2015/09/09 11:40:29
does't returning std::vector involves a copy ctor?
kwiberg-webrtc
2015/09/09 11:51:42
Yes, in principle. But (1) this is a test, so we c
minyue-webrtc
2015/09/09 12:13:39
Acknowledged.
| |
116 } | |
109 | 117 |
110 // Repeatedly sets packet loss rates in the range [from, to], increasing by | 118 // Sets the packet loss rate to each number in the vector in turn, and verifies |
111 // 0.01 in each step. The function verifies that the actual loss rate is | 119 // that the loss rate as reported by the encoder is |expected_return| for all |
112 // |expected_return|. | 120 // of them. |
113 void TestSetPacketLossRate(AudioEncoderOpus* encoder, | 121 void TestSetPacketLossRate(AudioEncoderOpus* encoder, |
114 double from, | 122 const std::vector<double>& losses, |
115 double to, | |
116 double expected_return) { | 123 double expected_return) { |
117 for (double loss = from; loss <= to; | 124 for (double loss : losses) { |
minyue-webrtc
2015/09/09 11:40:29
all right, this was silly. Nice pick!
| |
118 (to >= from) ? loss += 0.01 : loss -= 0.01) { | |
119 encoder->SetProjectedPacketLossRate(loss); | 125 encoder->SetProjectedPacketLossRate(loss); |
120 EXPECT_DOUBLE_EQ(expected_return, encoder->packet_loss_rate()); | 126 EXPECT_DOUBLE_EQ(expected_return, encoder->packet_loss_rate()); |
121 } | 127 } |
122 } | 128 } |
123 | 129 |
124 } // namespace | 130 } // namespace |
125 | 131 |
126 TEST_F(AudioEncoderOpusTest, PacketLossRateOptimized) { | 132 TEST_F(AudioEncoderOpusTest, PacketLossRateOptimized) { |
127 CreateCodec(1); | 133 CreateCodec(1); |
134 auto I = [](double a, double b) { return IntervalSteps(a, b, 10); }; | |
135 const double eps = 1e-15; | |
128 | 136 |
129 // Note that the order of the following calls is critical. | 137 // Note that the order of the following calls is critical. |
130 TestSetPacketLossRate(encoder_.get(), 0.0, 0.0, 0.0); | 138 |
131 TestSetPacketLossRate(encoder_.get(), kPacketLossRate1, | 139 // clang-format off |
132 kPacketLossRate5 + kLossRate5Margin - 0.01, | 140 TestSetPacketLossRate(encoder_.get(), I(0.00 , 0.01 - eps), 0.00); |
133 kPacketLossRate1); | 141 TestSetPacketLossRate(encoder_.get(), I(0.01 + eps, 0.06 - eps), 0.01); |
134 TestSetPacketLossRate(encoder_.get(), kPacketLossRate5 + kLossRate5Margin, | 142 TestSetPacketLossRate(encoder_.get(), I(0.06 + eps, 0.11 - eps), 0.05); |
135 kPacketLossRate10 + kLossRate10Margin - 0.01, | 143 TestSetPacketLossRate(encoder_.get(), I(0.11 + eps, 0.22 - eps), 0.10); |
136 kPacketLossRate5); | 144 TestSetPacketLossRate(encoder_.get(), I(0.22 + eps, 1.00 ), 0.20); |
137 TestSetPacketLossRate(encoder_.get(), kPacketLossRate10 + kLossRate10Margin, | 145 |
138 kPacketLossRate20 + kLossRate20Margin - 0.01, | 146 TestSetPacketLossRate(encoder_.get(), I(1.00 , 0.18 + eps), 0.20); |
139 kPacketLossRate10); | 147 TestSetPacketLossRate(encoder_.get(), I(0.18 - eps, 0.09 + eps), 0.10); |
140 TestSetPacketLossRate(encoder_.get(), kPacketLossRate20 + kLossRate20Margin, | 148 TestSetPacketLossRate(encoder_.get(), I(0.09 - eps, 0.04 + eps), 0.05); |
141 1.0, kPacketLossRate20); | 149 TestSetPacketLossRate(encoder_.get(), I(0.04 - eps, 0.01 + eps), 0.01); |
142 TestSetPacketLossRate(encoder_.get(), kPacketLossRate20 + kLossRate20Margin, | 150 TestSetPacketLossRate(encoder_.get(), I(0.01 - eps, 0.00 ), 0.00); |
143 kPacketLossRate20 - kLossRate20Margin, | 151 // clang-format on |
144 kPacketLossRate20); | |
145 TestSetPacketLossRate( | |
146 encoder_.get(), kPacketLossRate20 - kLossRate20Margin - 0.01, | |
147 kPacketLossRate10 - kLossRate10Margin, kPacketLossRate10); | |
148 TestSetPacketLossRate(encoder_.get(), | |
149 kPacketLossRate10 - kLossRate10Margin - 0.01, | |
150 kPacketLossRate5 - kLossRate5Margin, kPacketLossRate5); | |
151 TestSetPacketLossRate(encoder_.get(), | |
152 kPacketLossRate5 - kLossRate5Margin - 0.01, | |
153 kPacketLossRate1, kPacketLossRate1); | |
154 TestSetPacketLossRate(encoder_.get(), 0.0, 0.0, 0.0); | |
155 } | 152 } |
156 | 153 |
157 } // namespace webrtc | 154 } // namespace webrtc |
OLD | NEW |