| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // that the loss rate as reported by the encoder is |expected_return| for all | 230 // that the loss rate as reported by the encoder is |expected_return| for all |
| 231 // of them. | 231 // of them. |
| 232 void TestSetPacketLossRate(AudioEncoderOpusStates* states, | 232 void TestSetPacketLossRate(AudioEncoderOpusStates* states, |
| 233 const std::vector<float>& losses, | 233 const std::vector<float>& losses, |
| 234 float expected_return) { | 234 float expected_return) { |
| 235 // |kSampleIntervalMs| is chosen to ease the calculation since | 235 // |kSampleIntervalMs| is chosen to ease the calculation since |
| 236 // 0.9999 ^ 184198 = 1e-8. Which minimizes the effect of | 236 // 0.9999 ^ 184198 = 1e-8. Which minimizes the effect of |
| 237 // PacketLossFractionSmoother used in AudioEncoderOpus. | 237 // PacketLossFractionSmoother used in AudioEncoderOpus. |
| 238 constexpr int64_t kSampleIntervalMs = 184198; | 238 constexpr int64_t kSampleIntervalMs = 184198; |
| 239 for (float loss : losses) { | 239 for (float loss : losses) { |
| 240 states->encoder->OnReceivedUplinkPacketLossFraction(loss); | 240 states->encoder->OnReceivedUplinkPacketLossFraction( |
| 241 rtc::Optional<float>(loss)); |
| 241 states->simulated_clock->AdvanceTimeMilliseconds(kSampleIntervalMs); | 242 states->simulated_clock->AdvanceTimeMilliseconds(kSampleIntervalMs); |
| 242 EXPECT_FLOAT_EQ(expected_return, states->encoder->packet_loss_rate()); | 243 EXPECT_FLOAT_EQ(expected_return, states->encoder->packet_loss_rate()); |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 | 246 |
| 246 } // namespace | 247 } // namespace |
| 247 | 248 |
| 248 TEST(AudioEncoderOpusTest, PacketLossRateOptimized) { | 249 TEST(AudioEncoderOpusTest, PacketLossRateOptimized) { |
| 249 auto states = CreateCodec(1); | 250 auto states = CreateCodec(1); |
| 250 auto I = [](float a, float b) { return IntervalSteps(a, b, 10); }; | 251 auto I = [](float a, float b) { return IntervalSteps(a, b, 10); }; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 TEST(AudioEncoderOpusTest, | 286 TEST(AudioEncoderOpusTest, |
| 286 InvokeAudioNetworkAdaptorOnReceivedUplinkPacketLossFraction) { | 287 InvokeAudioNetworkAdaptorOnReceivedUplinkPacketLossFraction) { |
| 287 auto states = CreateCodec(2); | 288 auto states = CreateCodec(2); |
| 288 states.encoder->EnableAudioNetworkAdaptor("", nullptr, nullptr); | 289 states.encoder->EnableAudioNetworkAdaptor("", nullptr, nullptr); |
| 289 | 290 |
| 290 auto config = CreateEncoderRuntimeConfig(); | 291 auto config = CreateEncoderRuntimeConfig(); |
| 291 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) | 292 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) |
| 292 .WillOnce(Return(config)); | 293 .WillOnce(Return(config)); |
| 293 | 294 |
| 294 // Since using mock audio network adaptor, any packet loss fraction is fine. | 295 // Since using mock audio network adaptor, any packet loss fraction is fine. |
| 295 constexpr float kUplinkPacketLoss = 0.1f; | 296 const auto kUplinkPacketLoss = rtc::Optional<float>(0.1f); |
| 296 EXPECT_CALL(**states.mock_audio_network_adaptor, | 297 EXPECT_CALL(**states.mock_audio_network_adaptor, |
| 297 SetUplinkPacketLossFraction(kUplinkPacketLoss)); | 298 SetUplinkPacketLossFraction(kUplinkPacketLoss)); |
| 298 states.encoder->OnReceivedUplinkPacketLossFraction(kUplinkPacketLoss); | 299 states.encoder->OnReceivedUplinkPacketLossFraction( |
| 300 rtc::Optional<float>(kUplinkPacketLoss)); |
| 299 | 301 |
| 300 CheckEncoderRuntimeConfig(states.encoder.get(), config); | 302 CheckEncoderRuntimeConfig(states.encoder.get(), config); |
| 301 } | 303 } |
| 302 | 304 |
| 303 TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnReceivedUplinkBandwidth) { | 305 TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnReceivedUplinkBandwidth) { |
| 304 auto states = CreateCodec(2); | 306 auto states = CreateCodec(2); |
| 305 states.encoder->EnableAudioNetworkAdaptor("", nullptr, nullptr); | 307 states.encoder->EnableAudioNetworkAdaptor("", nullptr, nullptr); |
| 306 | 308 |
| 307 auto config = CreateEncoderRuntimeConfig(); | 309 auto config = CreateEncoderRuntimeConfig(); |
| 308 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) | 310 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 355 |
| 354 CheckEncoderRuntimeConfig(states.encoder.get(), config); | 356 CheckEncoderRuntimeConfig(states.encoder.get(), config); |
| 355 } | 357 } |
| 356 | 358 |
| 357 TEST(AudioEncoderOpusTest, | 359 TEST(AudioEncoderOpusTest, |
| 358 PacketLossFractionSmoothedOnSetUplinkPacketLossFraction) { | 360 PacketLossFractionSmoothedOnSetUplinkPacketLossFraction) { |
| 359 auto states = CreateCodec(2); | 361 auto states = CreateCodec(2); |
| 360 | 362 |
| 361 // The values are carefully chosen so that if no smoothing is made, the test | 363 // The values are carefully chosen so that if no smoothing is made, the test |
| 362 // will fail. | 364 // will fail. |
| 363 constexpr float kPacketLossFraction_1 = 0.02f; | 365 const auto kPacketLossFraction_1 = rtc::Optional<float>(0.02f); |
| 364 constexpr float kPacketLossFraction_2 = 0.198f; | 366 const auto kPacketLossFraction_2 = rtc::Optional<float>(0.198f); |
| 365 // |kSecondSampleTimeMs| is chosen to ease the calculation since | 367 // |kSecondSampleTimeMs| is chosen to ease the calculation since |
| 366 // 0.9999 ^ 6931 = 0.5. | 368 // 0.9999 ^ 6931 = 0.5. |
| 367 constexpr int64_t kSecondSampleTimeMs = 6931; | 369 constexpr int64_t kSecondSampleTimeMs = 6931; |
| 368 | 370 |
| 369 // First time, no filtering. | 371 // First time, no filtering. |
| 370 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_1); | 372 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_1); |
| 371 EXPECT_FLOAT_EQ(0.01f, states.encoder->packet_loss_rate()); | 373 EXPECT_FLOAT_EQ(0.01f, states.encoder->packet_loss_rate()); |
| 372 | 374 |
| 373 states.simulated_clock->AdvanceTimeMilliseconds(kSecondSampleTimeMs); | 375 states.simulated_clock->AdvanceTimeMilliseconds(kSecondSampleTimeMs); |
| 374 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_2); | 376 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_2); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 542 |
| 541 // Should encode now. | 543 // Should encode now. |
| 542 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), | 544 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), |
| 543 &encoded); | 545 &encoded); |
| 544 EXPECT_GT(encoded.size(), 0u); | 546 EXPECT_GT(encoded.size(), 0u); |
| 545 encoded.Clear(); | 547 encoded.Clear(); |
| 546 } | 548 } |
| 547 } | 549 } |
| 548 | 550 |
| 549 } // namespace webrtc | 551 } // namespace webrtc |
| OLD | NEW |