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 TEST(AudioEncoderOpusTest, SetReceiverFrameLengthRange) { |
| 227 auto states = CreateCodec(2); |
| 228 // Before calling to |SetReceiverFrameLengthRange|, |
| 229 // |supported_frame_lengths_ms| should contain only the frame length being |
| 230 // used. |
| 231 EXPECT_EQ(std::vector<int>({states.encoder->next_frame_length_ms()}), |
| 232 states.encoder->supported_frame_lengths_ms()); |
| 233 states.encoder->SetReceiverFrameLengthRange(0, 12345); |
| 234 EXPECT_EQ(std::vector<int>({20, 60}), |
| 235 states.encoder->supported_frame_lengths_ms()); |
| 236 states.encoder->SetReceiverFrameLengthRange(21, 60); |
| 237 EXPECT_EQ(std::vector<int>({60}), |
| 238 states.encoder->supported_frame_lengths_ms()); |
| 239 states.encoder->SetReceiverFrameLengthRange(20, 59); |
| 240 EXPECT_EQ(std::vector<int>({20}), |
| 241 states.encoder->supported_frame_lengths_ms()); |
| 242 } |
| 243 |
225 TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnSetUplinkBandwidth) { | 244 TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnSetUplinkBandwidth) { |
226 auto states = CreateCodec(2); | 245 auto states = CreateCodec(2); |
227 printf("passed!\n"); | |
228 states.encoder->EnableAudioNetworkAdaptor("", nullptr); | 246 states.encoder->EnableAudioNetworkAdaptor("", nullptr); |
229 | 247 |
230 auto config = CreateEncoderRuntimeConfig(); | 248 auto config = CreateEncoderRuntimeConfig(); |
231 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) | 249 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) |
232 .WillOnce(Return(config)); | 250 .WillOnce(Return(config)); |
233 | 251 |
234 // Since using mock audio network adaptor, any bandwidth value is fine. | 252 // Since using mock audio network adaptor, any bandwidth value is fine. |
235 constexpr int kUplinkBandwidth = 50000; | 253 constexpr int kUplinkBandwidth = 50000; |
236 EXPECT_CALL(**states.mock_audio_network_adaptor, | 254 EXPECT_CALL(**states.mock_audio_network_adaptor, |
237 SetUplinkBandwidth(kUplinkBandwidth)); | 255 SetUplinkBandwidth(kUplinkBandwidth)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 303 |
286 // Since using mock audio network adaptor, any rtt is fine. | 304 // Since using mock audio network adaptor, any rtt is fine. |
287 constexpr int kRtt = 30; | 305 constexpr int kRtt = 30; |
288 EXPECT_CALL(**states.mock_audio_network_adaptor, SetRtt(kRtt)); | 306 EXPECT_CALL(**states.mock_audio_network_adaptor, SetRtt(kRtt)); |
289 states.encoder->OnReceivedRtt(kRtt); | 307 states.encoder->OnReceivedRtt(kRtt); |
290 | 308 |
291 CheckEncoderRuntimeConfig(states.encoder.get(), config); | 309 CheckEncoderRuntimeConfig(states.encoder.get(), config); |
292 } | 310 } |
293 | 311 |
294 TEST(AudioEncoderOpusTest, | 312 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) { | 313 PacketLossFractionSmoothedOnSetUplinkPacketLossFraction) { |
314 auto states = CreateCodec(2); | 314 auto states = CreateCodec(2); |
315 | 315 |
316 // The values are carefully chosen so that if no smoothing is made, the test | 316 // The values are carefully chosen so that if no smoothing is made, the test |
317 // will fail. | 317 // will fail. |
318 constexpr float kPacketLossFraction_1 = 0.02f; | 318 constexpr float kPacketLossFraction_1 = 0.02f; |
319 constexpr float kPacketLossFraction_2 = 0.198f; | 319 constexpr float kPacketLossFraction_2 = 0.198f; |
320 // |kSecondSampleTimeMs| is chose to ease the calculation since | 320 // |kSecondSampleTimeMs| is chose to ease the calculation since |
321 // 0.9999 ^ 6931 = 0.5. | 321 // 0.9999 ^ 6931 = 0.5. |
322 constexpr float kSecondSampleTimeMs = 6931; | 322 constexpr float kSecondSampleTimeMs = 6931; |
323 | 323 |
324 // First time, no filtering. | 324 // First time, no filtering. |
325 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_1); | 325 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_1); |
326 EXPECT_DOUBLE_EQ(0.01, states.encoder->packet_loss_rate()); | 326 EXPECT_DOUBLE_EQ(0.01, states.encoder->packet_loss_rate()); |
327 | 327 |
328 states.simulated_clock->AdvanceTimeMilliseconds(kSecondSampleTimeMs); | 328 states.simulated_clock->AdvanceTimeMilliseconds(kSecondSampleTimeMs); |
329 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_2); | 329 states.encoder->OnReceivedUplinkPacketLossFraction(kPacketLossFraction_2); |
330 | 330 |
331 // Now the output of packet loss fraction smoother should be | 331 // 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 | 332 // (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 | 333 // 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. | 334 // optimized packet loss rate should have been increase to 0.1. |
335 EXPECT_DOUBLE_EQ(0.05, states.encoder->packet_loss_rate()); | 335 EXPECT_DOUBLE_EQ(0.05, states.encoder->packet_loss_rate()); |
336 } | 336 } |
337 | 337 |
338 } // namespace webrtc | 338 } // namespace webrtc |
OLD | NEW |