Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 constexpr int64_t kInitialTimeUs = 12345678; | 27 constexpr int64_t kInitialTimeUs = 12345678; |
| 28 | 28 |
| 29 AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) { | 29 AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) { |
| 30 AudioEncoderOpus::Config config; | 30 AudioEncoderOpus::Config config; |
| 31 config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48); | 31 config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48); |
| 32 config.num_channels = codec_inst.channels; | 32 config.num_channels = codec_inst.channels; |
| 33 config.bitrate_bps = rtc::Optional<int>(codec_inst.rate); | 33 config.bitrate_bps = rtc::Optional<int>(codec_inst.rate); |
| 34 config.payload_type = codec_inst.pltype; | 34 config.payload_type = codec_inst.pltype; |
| 35 config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip | 35 config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip |
| 36 : AudioEncoderOpus::kAudio; | 36 : AudioEncoderOpus::kAudio; |
| 37 config.supported_frame_lengths_ms.push_back(config.frame_size_ms); | |
| 37 return config; | 38 return config; |
| 38 } | 39 } |
| 39 | 40 |
| 40 struct AudioEncoderOpusStates { | 41 struct AudioEncoderOpusStates { |
| 41 std::shared_ptr<MockAudioNetworkAdaptor*> mock_audio_network_adaptor; | 42 std::shared_ptr<MockAudioNetworkAdaptor*> mock_audio_network_adaptor; |
| 42 std::unique_ptr<AudioEncoderOpus> encoder; | 43 std::unique_ptr<AudioEncoderOpus> encoder; |
| 43 std::unique_ptr<SimulatedClock> simulated_clock; | 44 std::unique_ptr<SimulatedClock> simulated_clock; |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 AudioEncoderOpusStates CreateCodec(size_t num_channels) { | 47 AudioEncoderOpusStates CreateCodec(size_t num_channels) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 TestSetPacketLossRate(states.encoder.get(), I(0.22 + eps, 1.00 ), 0.20); | 216 TestSetPacketLossRate(states.encoder.get(), I(0.22 + eps, 1.00 ), 0.20); |
| 216 | 217 |
| 217 TestSetPacketLossRate(states.encoder.get(), I(1.00 , 0.18 + eps), 0.20); | 218 TestSetPacketLossRate(states.encoder.get(), I(1.00 , 0.18 + eps), 0.20); |
| 218 TestSetPacketLossRate(states.encoder.get(), I(0.18 - eps, 0.09 + eps), 0.10); | 219 TestSetPacketLossRate(states.encoder.get(), I(0.18 - eps, 0.09 + eps), 0.10); |
| 219 TestSetPacketLossRate(states.encoder.get(), I(0.09 - eps, 0.04 + eps), 0.05); | 220 TestSetPacketLossRate(states.encoder.get(), I(0.09 - eps, 0.04 + eps), 0.05); |
| 220 TestSetPacketLossRate(states.encoder.get(), I(0.04 - eps, 0.01 + eps), 0.01); | 221 TestSetPacketLossRate(states.encoder.get(), I(0.04 - eps, 0.01 + eps), 0.01); |
| 221 TestSetPacketLossRate(states.encoder.get(), I(0.01 - eps, 0.00 ), 0.00); | 222 TestSetPacketLossRate(states.encoder.get(), I(0.01 - eps, 0.00 ), 0.00); |
| 222 // clang-format on | 223 // clang-format on |
| 223 } | 224 } |
| 224 | 225 |
| 226 namespace { | |
| 227 | |
| 228 void CheckArrayView(const std::vector<int>& expect_values, | |
| 229 const rtc::ArrayView<const int>& array_view) { | |
|
kwiberg-webrtc
2016/10/24 11:58:35
Pass ArrayView by value.
| |
| 230 EXPECT_THAT(expect_values, ::testing::ElementsAreArray(array_view.data(), | |
| 231 array_view.size())); | |
|
kwiberg-webrtc
2016/10/24 11:58:35
The actual value should be the first argument, and
| |
| 232 } | |
| 233 | |
| 234 } // namespace | |
| 235 | |
| 236 TEST(AudioEncoderOpusTest, SetReceiverFrameLengthRange) { | |
| 237 auto states = CreateCodec(2); | |
| 238 // Before calling to |SetReceiverFrameLengthRange|, | |
| 239 // |supported_frame_lengths_ms| should contain only the frame length being | |
| 240 // used. | |
| 241 CheckArrayView({states.encoder->next_frame_length_ms()}, | |
| 242 states.encoder->supported_frame_lengths_ms()); | |
|
kwiberg-webrtc
2016/10/24 11:58:35
I don't think you need the separate function:
EXP
| |
| 243 states.encoder->SetReceiverFrameLengthRange(0, 12345); | |
| 244 CheckArrayView({20, 60}, states.encoder->supported_frame_lengths_ms()); | |
|
kwiberg-webrtc
2016/10/24 11:58:35
EXPECT_THAT(states.encoder->supported_frame_length
| |
| 245 states.encoder->SetReceiverFrameLengthRange(21, 60); | |
| 246 CheckArrayView({60}, states.encoder->supported_frame_lengths_ms()); | |
| 247 states.encoder->SetReceiverFrameLengthRange(20, 59); | |
| 248 CheckArrayView({20}, states.encoder->supported_frame_lengths_ms()); | |
| 249 } | |
| 250 | |
| 225 TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnSetUplinkBandwidth) { | 251 TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnSetUplinkBandwidth) { |
| 226 auto states = CreateCodec(2); | 252 auto states = CreateCodec(2); |
| 227 printf("passed!\n"); | |
| 228 states.encoder->EnableAudioNetworkAdaptor("", nullptr); | 253 states.encoder->EnableAudioNetworkAdaptor("", nullptr); |
| 229 | 254 |
| 230 auto config = CreateEncoderRuntimeConfig(); | 255 auto config = CreateEncoderRuntimeConfig(); |
| 231 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) | 256 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) |
| 232 .WillOnce(Return(config)); | 257 .WillOnce(Return(config)); |
| 233 | 258 |
| 234 // Since using mock audio network adaptor, any bandwidth value is fine. | 259 // Since using mock audio network adaptor, any bandwidth value is fine. |
| 235 constexpr int kUplinkBandwidth = 50000; | 260 constexpr int kUplinkBandwidth = 50000; |
| 236 EXPECT_CALL(**states.mock_audio_network_adaptor, | 261 EXPECT_CALL(**states.mock_audio_network_adaptor, |
| 237 SetUplinkBandwidth(kUplinkBandwidth)); | 262 SetUplinkBandwidth(kUplinkBandwidth)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 | 310 |
| 286 // Since using mock audio network adaptor, any rtt is fine. | 311 // Since using mock audio network adaptor, any rtt is fine. |
| 287 constexpr int kRtt = 30; | 312 constexpr int kRtt = 30; |
| 288 EXPECT_CALL(**states.mock_audio_network_adaptor, SetRtt(kRtt)); | 313 EXPECT_CALL(**states.mock_audio_network_adaptor, SetRtt(kRtt)); |
| 289 states.encoder->OnReceivedRtt(kRtt); | 314 states.encoder->OnReceivedRtt(kRtt); |
| 290 | 315 |
| 291 CheckEncoderRuntimeConfig(states.encoder.get(), config); | 316 CheckEncoderRuntimeConfig(states.encoder.get(), config); |
| 292 } | 317 } |
| 293 | 318 |
| 294 TEST(AudioEncoderOpusTest, | 319 TEST(AudioEncoderOpusTest, |
| 295 InvokeAudioNetworkAdaptorOnSetReceiverFrameLengthRange) { | |
| 296 auto states = CreateCodec(2); | |
| 297 states.encoder->EnableAudioNetworkAdaptor("", nullptr); | |
| 298 | |
| 299 auto config = CreateEncoderRuntimeConfig(); | |
| 300 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) | |
| 301 .WillOnce(Return(config)); | |
| 302 | |
| 303 constexpr int kMinFrameLength = 10; | |
| 304 constexpr int kMaxFrameLength = 60; | |
| 305 EXPECT_CALL(**states.mock_audio_network_adaptor, | |
| 306 SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength)); | |
| 307 states.encoder->SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength); | |
| 308 | |
| 309 CheckEncoderRuntimeConfig(states.encoder.get(), config); | |
| 310 } | |
| 311 | |
| 312 TEST(AudioEncoderOpusTest, | |
| 313 PacketLossFractionSmoothedOnSetUplinkPacketLossFraction) { | 320 PacketLossFractionSmoothedOnSetUplinkPacketLossFraction) { |
| 314 auto states = CreateCodec(2); | 321 auto states = CreateCodec(2); |
| 315 | 322 |
| 316 // The values are carefully chosen so that if no smoothing is made, the test | 323 // The values are carefully chosen so that if no smoothing is made, the test |
| 317 // will fail. | 324 // will fail. |
| 318 constexpr float kPacketLossFraction_1 = 0.02f; | 325 constexpr float kPacketLossFraction_1 = 0.02f; |
| 319 constexpr float kPacketLossFraction_2 = 0.198f; | 326 constexpr float kPacketLossFraction_2 = 0.198f; |
| 320 // |kSecondSampleTimeMs| is chose to ease the calculation since | 327 // |kSecondSampleTimeMs| is chose to ease the calculation since |
| 321 // 0.9999 ^ 6931 = 0.5. | 328 // 0.9999 ^ 6931 = 0.5. |
| 322 constexpr float kSecondSampleTimeMs = 6931; | 329 constexpr float kSecondSampleTimeMs = 6931; |
| 323 | 330 |
| 324 // First time, no filtering. | 331 // First time, no filtering. |
| 325 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_1); | 332 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_1); |
| 326 EXPECT_DOUBLE_EQ(0.01, states.encoder->packet_loss_rate()); | 333 EXPECT_DOUBLE_EQ(0.01, states.encoder->packet_loss_rate()); |
| 327 | 334 |
| 328 states.simulated_clock->AdvanceTimeMilliseconds(kSecondSampleTimeMs); | 335 states.simulated_clock->AdvanceTimeMilliseconds(kSecondSampleTimeMs); |
| 329 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_2); | 336 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_2); |
| 330 | 337 |
| 331 // Now the output of packet loss fraction smoother should be | 338 // Now the output of packet loss fraction smoother should be |
| 332 // (0.02 + 0.198) / 2 = 0.109, which reach the threshold for the optimized | 339 // (0.02 + 0.198) / 2 = 0.109, which reach the threshold for the optimized |
| 333 // packet loss rate to increase to 0.05. If no smoothing has been made, the | 340 // packet loss rate to increase to 0.05. If no smoothing has been made, the |
| 334 // optimized packet loss rate should have been increase to 0.1. | 341 // optimized packet loss rate should have been increase to 0.1. |
| 335 EXPECT_DOUBLE_EQ(0.05, states.encoder->packet_loss_rate()); | 342 EXPECT_DOUBLE_EQ(0.05, states.encoder->packet_loss_rate()); |
| 336 } | 343 } |
| 337 | 344 |
| 338 } // namespace webrtc | 345 } // namespace webrtc |
| OLD | NEW |