| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 136 TEST(AudioEncoderOpusTest, ToggleDtx) { | 136 TEST(AudioEncoderOpusTest, ToggleDtx) { | 
| 137   auto states = CreateCodec(2); | 137   auto states = CreateCodec(2); | 
| 138   // Enable DTX | 138   // Enable DTX | 
| 139   EXPECT_TRUE(states.encoder->SetDtx(true)); | 139   EXPECT_TRUE(states.encoder->SetDtx(true)); | 
| 140   // Verify that the mode is still kAudio. | 140   // Verify that the mode is still kAudio. | 
| 141   EXPECT_EQ(AudioEncoderOpus::kAudio, states.encoder->application()); | 141   EXPECT_EQ(AudioEncoderOpus::kAudio, states.encoder->application()); | 
| 142   // Turn off DTX. | 142   // Turn off DTX. | 
| 143   EXPECT_TRUE(states.encoder->SetDtx(false)); | 143   EXPECT_TRUE(states.encoder->SetDtx(false)); | 
| 144 } | 144 } | 
| 145 | 145 | 
| 146 TEST(AudioEncoderOpusTest, SetBitrate) { | 146 TEST(AudioEncoderOpusTest, | 
|  | 147      OnReceivedTargetAudioBitrateWithoutAudioNetworkAdaptor) { | 
| 147   auto states = CreateCodec(1); | 148   auto states = CreateCodec(1); | 
| 148   // Constants are replicated from audio_states.encoderopus.cc. | 149   // Constants are replicated from audio_states.encoderopus.cc. | 
| 149   const int kMinBitrateBps = 500; | 150   const int kMinBitrateBps = 500; | 
| 150   const int kMaxBitrateBps = 512000; | 151   const int kMaxBitrateBps = 512000; | 
| 151   // Set a too low bitrate. | 152   // Set a too low bitrate. | 
| 152   states.encoder->SetTargetBitrate(kMinBitrateBps - 1); | 153   states.encoder->OnReceivedTargetAudioBitrate(kMinBitrateBps - 1); | 
| 153   EXPECT_EQ(kMinBitrateBps, states.encoder->GetTargetBitrate()); | 154   EXPECT_EQ(kMinBitrateBps, states.encoder->GetTargetBitrate()); | 
| 154   // Set a too high bitrate. | 155   // Set a too high bitrate. | 
| 155   states.encoder->SetTargetBitrate(kMaxBitrateBps + 1); | 156   states.encoder->OnReceivedTargetAudioBitrate(kMaxBitrateBps + 1); | 
| 156   EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate()); | 157   EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate()); | 
| 157   // Set the minimum rate. | 158   // Set the minimum rate. | 
| 158   states.encoder->SetTargetBitrate(kMinBitrateBps); | 159   states.encoder->OnReceivedTargetAudioBitrate(kMinBitrateBps); | 
| 159   EXPECT_EQ(kMinBitrateBps, states.encoder->GetTargetBitrate()); | 160   EXPECT_EQ(kMinBitrateBps, states.encoder->GetTargetBitrate()); | 
| 160   // Set the maximum rate. | 161   // Set the maximum rate. | 
| 161   states.encoder->SetTargetBitrate(kMaxBitrateBps); | 162   states.encoder->OnReceivedTargetAudioBitrate(kMaxBitrateBps); | 
| 162   EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate()); | 163   EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate()); | 
| 163   // Set rates from 1000 up to 32000 bps. | 164   // Set rates from 1000 up to 32000 bps. | 
| 164   for (int rate = 1000; rate <= 32000; rate += 1000) { | 165   for (int rate = 1000; rate <= 32000; rate += 1000) { | 
| 165     states.encoder->SetTargetBitrate(rate); | 166     states.encoder->OnReceivedTargetAudioBitrate(rate); | 
| 166     EXPECT_EQ(rate, states.encoder->GetTargetBitrate()); | 167     EXPECT_EQ(rate, states.encoder->GetTargetBitrate()); | 
| 167   } | 168   } | 
| 168 } | 169 } | 
| 169 | 170 | 
| 170 namespace { | 171 namespace { | 
| 171 | 172 | 
| 172 // Returns a vector with the n evenly-spaced numbers a, a + (b - a)/(n - 1), | 173 // Returns a vector with the n evenly-spaced numbers a, a + (b - a)/(n - 1), | 
| 173 // ..., b. | 174 // ..., b. | 
| 174 std::vector<double> IntervalSteps(double a, double b, size_t n) { | 175 std::vector<double> IntervalSteps(double a, double b, size_t n) { | 
| 175   RTC_DCHECK_GT(n, 1u); | 176   RTC_DCHECK_GT(n, 1u); | 
| 176   const double step = (b - a) / (n - 1); | 177   const double step = (b - a) / (n - 1); | 
| 177   std::vector<double> points; | 178   std::vector<double> points; | 
| 178   for (size_t i = 0; i < n; ++i) | 179   for (size_t i = 0; i < n; ++i) | 
| 179     points.push_back(a + i * step); | 180     points.push_back(a + i * step); | 
| 180   return points; | 181   return points; | 
| 181 } | 182 } | 
| 182 | 183 | 
| 183 // Sets the packet loss rate to each number in the vector in turn, and verifies | 184 // Sets the packet loss rate to each number in the vector in turn, and verifies | 
| 184 // that the loss rate as reported by the encoder is |expected_return| for all | 185 // that the loss rate as reported by the encoder is |expected_return| for all | 
| 185 // of them. | 186 // of them. | 
| 186 void TestSetPacketLossRate(AudioEncoderOpus* encoder, | 187 void TestSetPacketLossRate(AudioEncoderOpus* encoder, | 
| 187                            const std::vector<double>& losses, | 188                            const std::vector<double>& losses, | 
| 188                            double expected_return) { | 189                            double expected_return) { | 
| 189   for (double loss : losses) { | 190   for (double loss : losses) { | 
| 190     encoder->SetProjectedPacketLossRate(loss); | 191     encoder->OnReceivedUplinkPacketLossFraction(loss); | 
| 191     EXPECT_DOUBLE_EQ(expected_return, encoder->packet_loss_rate()); | 192     EXPECT_DOUBLE_EQ(expected_return, encoder->packet_loss_rate()); | 
| 192   } | 193   } | 
| 193 } | 194 } | 
| 194 | 195 | 
| 195 }  // namespace | 196 }  // namespace | 
| 196 | 197 | 
| 197 TEST(AudioEncoderOpusTest, PacketLossRateOptimized) { | 198 TEST(AudioEncoderOpusTest, PacketLossRateOptimized) { | 
| 198   auto states = CreateCodec(1); | 199   auto states = CreateCodec(1); | 
| 199   auto I = [](double a, double b) { return IntervalSteps(a, b, 10); }; | 200   auto I = [](double a, double b) { return IntervalSteps(a, b, 10); }; | 
| 200   const double eps = 1e-15; | 201   const double eps = 1e-15; | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 297   constexpr int kMinFrameLength = 10; | 298   constexpr int kMinFrameLength = 10; | 
| 298   constexpr int kMaxFrameLength = 60; | 299   constexpr int kMaxFrameLength = 60; | 
| 299   EXPECT_CALL(**states.mock_audio_network_adaptor, | 300   EXPECT_CALL(**states.mock_audio_network_adaptor, | 
| 300               SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength)); | 301               SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength)); | 
| 301   states.encoder->SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength); | 302   states.encoder->SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength); | 
| 302 | 303 | 
| 303   CheckEncoderRuntimeConfig(states.encoder.get(), config); | 304   CheckEncoderRuntimeConfig(states.encoder.get(), config); | 
| 304 } | 305 } | 
| 305 | 306 | 
| 306 }  // namespace webrtc | 307 }  // namespace webrtc | 
| OLD | NEW | 
|---|