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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 namespace webrtc { | 27 namespace webrtc { |
28 using ::testing::NiceMock; | 28 using ::testing::NiceMock; |
29 using ::testing::Return; | 29 using ::testing::Return; |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const CodecInst kDefaultOpusSettings = {105, "opus", 48000, 960, 1, 32000}; | 33 const CodecInst kDefaultOpusSettings = {105, "opus", 48000, 960, 1, 32000}; |
34 constexpr int64_t kInitialTimeUs = 12345678; | 34 constexpr int64_t kInitialTimeUs = 12345678; |
35 | 35 |
36 AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) { | 36 AudioEncoderOpusConfig CreateConfig(const CodecInst& codec_inst) { |
37 AudioEncoderOpus::Config config; | 37 AudioEncoderOpusConfig config; |
38 config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48); | 38 config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 48); |
39 config.num_channels = codec_inst.channels; | 39 config.num_channels = codec_inst.channels; |
40 config.bitrate_bps = rtc::Optional<int>(codec_inst.rate); | 40 config.bitrate_bps = codec_inst.rate; |
41 config.payload_type = codec_inst.pltype; | 41 config.application = config.num_channels == 1 |
42 config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip | 42 ? AudioEncoderOpusConfig::ApplicationMode::kVoip |
43 : AudioEncoderOpus::kAudio; | 43 : AudioEncoderOpusConfig::ApplicationMode::kAudio; |
44 config.supported_frame_lengths_ms.push_back(config.frame_size_ms); | 44 config.supported_frame_lengths_ms.push_back(config.frame_size_ms); |
45 return config; | 45 return config; |
46 } | 46 } |
47 | 47 |
48 AudioEncoderOpus::Config CreateConfigWithParameters( | 48 AudioEncoderOpusConfig CreateConfigWithParameters( |
49 const SdpAudioFormat::Parameters& params) { | 49 const SdpAudioFormat::Parameters& params) { |
50 SdpAudioFormat format("opus", 48000, 2, params); | 50 const SdpAudioFormat format("opus", 48000, 2, params); |
51 return AudioEncoderOpus::CreateConfig(0, format); | 51 return *AudioEncoderOpusImpl::SdpToConfig(format); |
52 } | 52 } |
53 | 53 |
54 struct AudioEncoderOpusStates { | 54 struct AudioEncoderOpusStates { |
55 std::shared_ptr<MockAudioNetworkAdaptor*> mock_audio_network_adaptor; | 55 std::shared_ptr<MockAudioNetworkAdaptor*> mock_audio_network_adaptor; |
56 MockSmoothingFilter* mock_bitrate_smoother; | 56 MockSmoothingFilter* mock_bitrate_smoother; |
57 std::unique_ptr<AudioEncoderOpus> encoder; | 57 std::unique_ptr<AudioEncoderOpusImpl> encoder; |
58 std::unique_ptr<rtc::ScopedFakeClock> fake_clock; | 58 std::unique_ptr<rtc::ScopedFakeClock> fake_clock; |
59 AudioEncoderOpus::Config config; | 59 AudioEncoderOpusConfig config; |
60 }; | 60 }; |
61 | 61 |
62 AudioEncoderOpusStates CreateCodec(size_t num_channels) { | 62 AudioEncoderOpusStates CreateCodec(size_t num_channels) { |
63 AudioEncoderOpusStates states; | 63 AudioEncoderOpusStates states; |
64 states.mock_audio_network_adaptor = | 64 states.mock_audio_network_adaptor = |
65 std::make_shared<MockAudioNetworkAdaptor*>(nullptr); | 65 std::make_shared<MockAudioNetworkAdaptor*>(nullptr); |
66 states.fake_clock.reset(new rtc::ScopedFakeClock()); | 66 states.fake_clock.reset(new rtc::ScopedFakeClock()); |
67 states.fake_clock->SetTimeMicros(kInitialTimeUs); | 67 states.fake_clock->SetTimeMicros(kInitialTimeUs); |
68 std::weak_ptr<MockAudioNetworkAdaptor*> mock_ptr( | 68 std::weak_ptr<MockAudioNetworkAdaptor*> mock_ptr( |
69 states.mock_audio_network_adaptor); | 69 states.mock_audio_network_adaptor); |
70 AudioEncoderOpus::AudioNetworkAdaptorCreator creator = | 70 AudioEncoderOpusImpl::AudioNetworkAdaptorCreator creator = |
71 [mock_ptr](const std::string&, RtcEventLog* event_log) { | 71 [mock_ptr](const std::string&, RtcEventLog* event_log) { |
72 std::unique_ptr<MockAudioNetworkAdaptor> adaptor( | 72 std::unique_ptr<MockAudioNetworkAdaptor> adaptor( |
73 new NiceMock<MockAudioNetworkAdaptor>()); | 73 new NiceMock<MockAudioNetworkAdaptor>()); |
74 EXPECT_CALL(*adaptor, Die()); | 74 EXPECT_CALL(*adaptor, Die()); |
75 if (auto sp = mock_ptr.lock()) { | 75 if (auto sp = mock_ptr.lock()) { |
76 *sp = adaptor.get(); | 76 *sp = adaptor.get(); |
77 } else { | 77 } else { |
78 RTC_NOTREACHED(); | 78 RTC_NOTREACHED(); |
79 } | 79 } |
80 return adaptor; | 80 return adaptor; |
81 }; | 81 }; |
82 | 82 |
83 CodecInst codec_inst = kDefaultOpusSettings; | 83 CodecInst codec_inst = kDefaultOpusSettings; |
84 codec_inst.channels = num_channels; | 84 codec_inst.channels = num_channels; |
85 states.config = CreateConfig(codec_inst); | 85 states.config = CreateConfig(codec_inst); |
86 std::unique_ptr<MockSmoothingFilter> bitrate_smoother( | 86 std::unique_ptr<MockSmoothingFilter> bitrate_smoother( |
87 new MockSmoothingFilter()); | 87 new MockSmoothingFilter()); |
88 states.mock_bitrate_smoother = bitrate_smoother.get(); | 88 states.mock_bitrate_smoother = bitrate_smoother.get(); |
89 | 89 |
90 states.encoder.reset(new AudioEncoderOpus(states.config, std::move(creator), | 90 states.encoder.reset(new AudioEncoderOpusImpl( |
91 std::move(bitrate_smoother))); | 91 states.config, codec_inst.pltype, std::move(creator), |
| 92 std::move(bitrate_smoother))); |
92 return states; | 93 return states; |
93 } | 94 } |
94 | 95 |
95 AudioEncoderRuntimeConfig CreateEncoderRuntimeConfig() { | 96 AudioEncoderRuntimeConfig CreateEncoderRuntimeConfig() { |
96 constexpr int kBitrate = 40000; | 97 constexpr int kBitrate = 40000; |
97 constexpr int kFrameLength = 60; | 98 constexpr int kFrameLength = 60; |
98 constexpr bool kEnableFec = true; | 99 constexpr bool kEnableFec = true; |
99 constexpr bool kEnableDtx = false; | 100 constexpr bool kEnableDtx = false; |
100 constexpr size_t kNumChannels = 1; | 101 constexpr size_t kNumChannels = 1; |
101 constexpr float kPacketLossFraction = 0.1f; | 102 constexpr float kPacketLossFraction = 0.1f; |
102 AudioEncoderRuntimeConfig config; | 103 AudioEncoderRuntimeConfig config; |
103 config.bitrate_bps = rtc::Optional<int>(kBitrate); | 104 config.bitrate_bps = rtc::Optional<int>(kBitrate); |
104 config.frame_length_ms = rtc::Optional<int>(kFrameLength); | 105 config.frame_length_ms = rtc::Optional<int>(kFrameLength); |
105 config.enable_fec = rtc::Optional<bool>(kEnableFec); | 106 config.enable_fec = rtc::Optional<bool>(kEnableFec); |
106 config.enable_dtx = rtc::Optional<bool>(kEnableDtx); | 107 config.enable_dtx = rtc::Optional<bool>(kEnableDtx); |
107 config.num_channels = rtc::Optional<size_t>(kNumChannels); | 108 config.num_channels = rtc::Optional<size_t>(kNumChannels); |
108 config.uplink_packet_loss_fraction = | 109 config.uplink_packet_loss_fraction = |
109 rtc::Optional<float>(kPacketLossFraction); | 110 rtc::Optional<float>(kPacketLossFraction); |
110 return config; | 111 return config; |
111 } | 112 } |
112 | 113 |
113 void CheckEncoderRuntimeConfig(const AudioEncoderOpus* encoder, | 114 void CheckEncoderRuntimeConfig(const AudioEncoderOpusImpl* encoder, |
114 const AudioEncoderRuntimeConfig& config) { | 115 const AudioEncoderRuntimeConfig& config) { |
115 EXPECT_EQ(*config.bitrate_bps, encoder->GetTargetBitrate()); | 116 EXPECT_EQ(*config.bitrate_bps, encoder->GetTargetBitrate()); |
116 EXPECT_EQ(*config.frame_length_ms, encoder->next_frame_length_ms()); | 117 EXPECT_EQ(*config.frame_length_ms, encoder->next_frame_length_ms()); |
117 EXPECT_EQ(*config.enable_fec, encoder->fec_enabled()); | 118 EXPECT_EQ(*config.enable_fec, encoder->fec_enabled()); |
118 EXPECT_EQ(*config.enable_dtx, encoder->GetDtx()); | 119 EXPECT_EQ(*config.enable_dtx, encoder->GetDtx()); |
119 EXPECT_EQ(*config.num_channels, encoder->num_channels_to_encode()); | 120 EXPECT_EQ(*config.num_channels, encoder->num_channels_to_encode()); |
120 } | 121 } |
121 | 122 |
122 // Create 10ms audio data blocks for a total packet size of "packet_size_ms". | 123 // Create 10ms audio data blocks for a total packet size of "packet_size_ms". |
123 std::unique_ptr<test::AudioLoop> Create10msAudioBlocks( | 124 std::unique_ptr<test::AudioLoop> Create10msAudioBlocks( |
124 const std::unique_ptr<AudioEncoderOpus>& encoder, | 125 const std::unique_ptr<AudioEncoderOpusImpl>& encoder, |
125 int packet_size_ms) { | 126 int packet_size_ms) { |
126 const std::string file_name = | 127 const std::string file_name = |
127 test::ResourcePath("audio_coding/testfile32kHz", "pcm"); | 128 test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
128 | 129 |
129 std::unique_ptr<test::AudioLoop> speech_data(new test::AudioLoop()); | 130 std::unique_ptr<test::AudioLoop> speech_data(new test::AudioLoop()); |
130 int audio_samples_per_ms = | 131 int audio_samples_per_ms = |
131 rtc::CheckedDivExact(encoder->SampleRateHz(), 1000); | 132 rtc::CheckedDivExact(encoder->SampleRateHz(), 1000); |
132 if (!speech_data->Init( | 133 if (!speech_data->Init( |
133 file_name, | 134 file_name, |
134 packet_size_ms * audio_samples_per_ms * | 135 packet_size_ms * audio_samples_per_ms * |
135 encoder->num_channels_to_encode(), | 136 encoder->num_channels_to_encode(), |
136 10 * audio_samples_per_ms * encoder->num_channels_to_encode())) | 137 10 * audio_samples_per_ms * encoder->num_channels_to_encode())) |
137 return nullptr; | 138 return nullptr; |
138 return speech_data; | 139 return speech_data; |
139 } | 140 } |
140 | 141 |
141 } // namespace | 142 } // namespace |
142 | 143 |
143 TEST(AudioEncoderOpusTest, DefaultApplicationModeMono) { | 144 TEST(AudioEncoderOpusTest, DefaultApplicationModeMono) { |
144 auto states = CreateCodec(1); | 145 auto states = CreateCodec(1); |
145 EXPECT_EQ(AudioEncoderOpus::kVoip, states.encoder->application()); | 146 EXPECT_EQ(AudioEncoderOpusConfig::ApplicationMode::kVoip, |
| 147 states.encoder->application()); |
146 } | 148 } |
147 | 149 |
148 TEST(AudioEncoderOpusTest, DefaultApplicationModeStereo) { | 150 TEST(AudioEncoderOpusTest, DefaultApplicationModeStereo) { |
149 auto states = CreateCodec(2); | 151 auto states = CreateCodec(2); |
150 EXPECT_EQ(AudioEncoderOpus::kAudio, states.encoder->application()); | 152 EXPECT_EQ(AudioEncoderOpusConfig::ApplicationMode::kAudio, |
| 153 states.encoder->application()); |
151 } | 154 } |
152 | 155 |
153 TEST(AudioEncoderOpusTest, ChangeApplicationMode) { | 156 TEST(AudioEncoderOpusTest, ChangeApplicationMode) { |
154 auto states = CreateCodec(2); | 157 auto states = CreateCodec(2); |
155 EXPECT_TRUE( | 158 EXPECT_TRUE( |
156 states.encoder->SetApplication(AudioEncoder::Application::kSpeech)); | 159 states.encoder->SetApplication(AudioEncoder::Application::kSpeech)); |
157 EXPECT_EQ(AudioEncoderOpus::kVoip, states.encoder->application()); | 160 EXPECT_EQ(AudioEncoderOpusConfig::ApplicationMode::kVoip, |
| 161 states.encoder->application()); |
158 } | 162 } |
159 | 163 |
160 TEST(AudioEncoderOpusTest, ResetWontChangeApplicationMode) { | 164 TEST(AudioEncoderOpusTest, ResetWontChangeApplicationMode) { |
161 auto states = CreateCodec(2); | 165 auto states = CreateCodec(2); |
162 | 166 |
163 // Trigger a reset. | 167 // Trigger a reset. |
164 states.encoder->Reset(); | 168 states.encoder->Reset(); |
165 // Verify that the mode is still kAudio. | 169 // Verify that the mode is still kAudio. |
166 EXPECT_EQ(AudioEncoderOpus::kAudio, states.encoder->application()); | 170 EXPECT_EQ(AudioEncoderOpusConfig::ApplicationMode::kAudio, |
| 171 states.encoder->application()); |
167 | 172 |
168 // Now change to kVoip. | 173 // Now change to kVoip. |
169 EXPECT_TRUE( | 174 EXPECT_TRUE( |
170 states.encoder->SetApplication(AudioEncoder::Application::kSpeech)); | 175 states.encoder->SetApplication(AudioEncoder::Application::kSpeech)); |
171 EXPECT_EQ(AudioEncoderOpus::kVoip, states.encoder->application()); | 176 EXPECT_EQ(AudioEncoderOpusConfig::ApplicationMode::kVoip, |
| 177 states.encoder->application()); |
172 | 178 |
173 // Trigger a reset again. | 179 // Trigger a reset again. |
174 states.encoder->Reset(); | 180 states.encoder->Reset(); |
175 // Verify that the mode is still kVoip. | 181 // Verify that the mode is still kVoip. |
176 EXPECT_EQ(AudioEncoderOpus::kVoip, states.encoder->application()); | 182 EXPECT_EQ(AudioEncoderOpusConfig::ApplicationMode::kVoip, |
| 183 states.encoder->application()); |
177 } | 184 } |
178 | 185 |
179 TEST(AudioEncoderOpusTest, ToggleDtx) { | 186 TEST(AudioEncoderOpusTest, ToggleDtx) { |
180 auto states = CreateCodec(2); | 187 auto states = CreateCodec(2); |
181 // Enable DTX | 188 // Enable DTX |
182 EXPECT_TRUE(states.encoder->SetDtx(true)); | 189 EXPECT_TRUE(states.encoder->SetDtx(true)); |
183 EXPECT_TRUE(states.encoder->GetDtx()); | 190 EXPECT_TRUE(states.encoder->GetDtx()); |
184 // Turn off DTX. | 191 // Turn off DTX. |
185 EXPECT_TRUE(states.encoder->SetDtx(false)); | 192 EXPECT_TRUE(states.encoder->SetDtx(false)); |
186 EXPECT_FALSE(states.encoder->GetDtx()); | 193 EXPECT_FALSE(states.encoder->GetDtx()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 238 } |
232 | 239 |
233 // Sets the packet loss rate to each number in the vector in turn, and verifies | 240 // Sets the packet loss rate to each number in the vector in turn, and verifies |
234 // that the loss rate as reported by the encoder is |expected_return| for all | 241 // that the loss rate as reported by the encoder is |expected_return| for all |
235 // of them. | 242 // of them. |
236 void TestSetPacketLossRate(AudioEncoderOpusStates* states, | 243 void TestSetPacketLossRate(AudioEncoderOpusStates* states, |
237 const std::vector<float>& losses, | 244 const std::vector<float>& losses, |
238 float expected_return) { | 245 float expected_return) { |
239 // |kSampleIntervalMs| is chosen to ease the calculation since | 246 // |kSampleIntervalMs| is chosen to ease the calculation since |
240 // 0.9999 ^ 184198 = 1e-8. Which minimizes the effect of | 247 // 0.9999 ^ 184198 = 1e-8. Which minimizes the effect of |
241 // PacketLossFractionSmoother used in AudioEncoderOpus. | 248 // PacketLossFractionSmoother used in AudioEncoderOpusImpl. |
242 constexpr int64_t kSampleIntervalMs = 184198; | 249 constexpr int64_t kSampleIntervalMs = 184198; |
243 for (float loss : losses) { | 250 for (float loss : losses) { |
244 states->encoder->OnReceivedUplinkPacketLossFraction(loss); | 251 states->encoder->OnReceivedUplinkPacketLossFraction(loss); |
245 states->fake_clock->AdvanceTime( | 252 states->fake_clock->AdvanceTime( |
246 rtc::TimeDelta::FromMilliseconds(kSampleIntervalMs)); | 253 rtc::TimeDelta::FromMilliseconds(kSampleIntervalMs)); |
247 EXPECT_FLOAT_EQ(expected_return, states->encoder->packet_loss_rate()); | 254 EXPECT_FLOAT_EQ(expected_return, states->encoder->packet_loss_rate()); |
248 } | 255 } |
249 } | 256 } |
250 | 257 |
251 } // namespace | 258 } // namespace |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 // subtracted. The eventual codec rate should be bounded by |kMaxBitrateBps|. | 452 // subtracted. The eventual codec rate should be bounded by |kMaxBitrateBps|. |
446 target_bitrate = | 453 target_bitrate = |
447 kOverheadBytesPerPacket * 8 * packet_rate + kMaxBitrateBps + 1; | 454 kOverheadBytesPerPacket * 8 * packet_rate + kMaxBitrateBps + 1; |
448 states.encoder->OnReceivedUplinkBandwidth(target_bitrate, | 455 states.encoder->OnReceivedUplinkBandwidth(target_bitrate, |
449 rtc::Optional<int64_t>()); | 456 rtc::Optional<int64_t>()); |
450 EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate()); | 457 EXPECT_EQ(kMaxBitrateBps, states.encoder->GetTargetBitrate()); |
451 } | 458 } |
452 | 459 |
453 // Verifies that the complexity adaptation in the config works as intended. | 460 // Verifies that the complexity adaptation in the config works as intended. |
454 TEST(AudioEncoderOpusTest, ConfigComplexityAdaptation) { | 461 TEST(AudioEncoderOpusTest, ConfigComplexityAdaptation) { |
455 AudioEncoderOpus::Config config; | 462 AudioEncoderOpusConfig config; |
456 config.low_rate_complexity = 8; | 463 config.low_rate_complexity = 8; |
457 config.complexity = 6; | 464 config.complexity = 6; |
458 | 465 |
459 // Bitrate within hysteresis window. Expect empty output. | 466 // Bitrate within hysteresis window. Expect empty output. |
460 config.bitrate_bps = rtc::Optional<int>(12500); | 467 config.bitrate_bps = 12500; |
461 EXPECT_EQ(rtc::Optional<int>(), config.GetNewComplexity()); | 468 EXPECT_EQ(rtc::Optional<int>(), |
| 469 AudioEncoderOpusImpl::GetNewComplexity(config)); |
462 | 470 |
463 // Bitrate below hysteresis window. Expect higher complexity. | 471 // Bitrate below hysteresis window. Expect higher complexity. |
464 config.bitrate_bps = rtc::Optional<int>(10999); | 472 config.bitrate_bps = 10999; |
465 EXPECT_EQ(rtc::Optional<int>(8), config.GetNewComplexity()); | 473 EXPECT_EQ(rtc::Optional<int>(8), |
| 474 AudioEncoderOpusImpl::GetNewComplexity(config)); |
466 | 475 |
467 // Bitrate within hysteresis window. Expect empty output. | 476 // Bitrate within hysteresis window. Expect empty output. |
468 config.bitrate_bps = rtc::Optional<int>(12500); | 477 config.bitrate_bps = 12500; |
469 EXPECT_EQ(rtc::Optional<int>(), config.GetNewComplexity()); | 478 EXPECT_EQ(rtc::Optional<int>(), |
| 479 AudioEncoderOpusImpl::GetNewComplexity(config)); |
470 | 480 |
471 // Bitrate above hysteresis window. Expect lower complexity. | 481 // Bitrate above hysteresis window. Expect lower complexity. |
472 config.bitrate_bps = rtc::Optional<int>(14001); | 482 config.bitrate_bps = 14001; |
473 EXPECT_EQ(rtc::Optional<int>(6), config.GetNewComplexity()); | 483 EXPECT_EQ(rtc::Optional<int>(6), |
| 484 AudioEncoderOpusImpl::GetNewComplexity(config)); |
474 } | 485 } |
475 | 486 |
476 TEST(AudioEncoderOpusTest, EmptyConfigDoesNotAffectEncoderSettings) { | 487 TEST(AudioEncoderOpusTest, EmptyConfigDoesNotAffectEncoderSettings) { |
477 auto states = CreateCodec(2); | 488 auto states = CreateCodec(2); |
478 states.encoder->EnableAudioNetworkAdaptor("", nullptr); | 489 states.encoder->EnableAudioNetworkAdaptor("", nullptr); |
479 | 490 |
480 auto config = CreateEncoderRuntimeConfig(); | 491 auto config = CreateEncoderRuntimeConfig(); |
481 AudioEncoderRuntimeConfig empty_config; | 492 AudioEncoderRuntimeConfig empty_config; |
482 | 493 |
483 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) | 494 EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig()) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 556 |
546 // Should encode now. | 557 // Should encode now. |
547 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), | 558 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), |
548 &encoded); | 559 &encoded); |
549 EXPECT_GT(encoded.size(), 0u); | 560 EXPECT_GT(encoded.size(), 0u); |
550 encoded.Clear(); | 561 encoded.Clear(); |
551 } | 562 } |
552 } | 563 } |
553 | 564 |
554 TEST(AudioEncoderOpusTest, TestConfigDefaults) { | 565 TEST(AudioEncoderOpusTest, TestConfigDefaults) { |
555 const AudioEncoderOpus::Config config = | 566 const auto config_opt = AudioEncoderOpusImpl::SdpToConfig({"opus", 48000, 2}); |
556 AudioEncoderOpus::CreateConfig(0, {"opus", 48000, 2}); | 567 ASSERT_TRUE(config_opt); |
557 | 568 EXPECT_EQ(48000, config_opt->max_playback_rate_hz); |
558 EXPECT_EQ(48000, config.max_playback_rate_hz); | 569 EXPECT_EQ(1u, config_opt->num_channels); |
559 EXPECT_EQ(1u, config.num_channels); | 570 EXPECT_FALSE(config_opt->fec_enabled); |
560 EXPECT_FALSE(config.fec_enabled); | 571 EXPECT_FALSE(config_opt->dtx_enabled); |
561 EXPECT_FALSE(config.dtx_enabled); | 572 EXPECT_EQ(20, config_opt->frame_size_ms); |
562 EXPECT_EQ(20, config.frame_size_ms); | |
563 } | 573 } |
564 | 574 |
565 TEST(AudioEncoderOpusTest, TestConfigFromParams) { | 575 TEST(AudioEncoderOpusTest, TestConfigFromParams) { |
566 AudioEncoderOpus::Config config; | 576 const auto config1 = CreateConfigWithParameters({{"stereo", "0"}}); |
| 577 EXPECT_EQ(1U, config1.num_channels); |
567 | 578 |
568 config = CreateConfigWithParameters({{"stereo", "0"}}); | 579 const auto config2 = CreateConfigWithParameters({{"stereo", "1"}}); |
569 EXPECT_EQ(1U, config.num_channels); | 580 EXPECT_EQ(2U, config2.num_channels); |
570 | 581 |
571 config = CreateConfigWithParameters({{"stereo", "1"}}); | 582 const auto config3 = CreateConfigWithParameters({{"useinbandfec", "0"}}); |
572 EXPECT_EQ(2U, config.num_channels); | 583 EXPECT_FALSE(config3.fec_enabled); |
573 | 584 |
574 config = CreateConfigWithParameters({{"useinbandfec", "0"}}); | 585 const auto config4 = CreateConfigWithParameters({{"useinbandfec", "1"}}); |
575 EXPECT_FALSE(config.fec_enabled); | 586 EXPECT_TRUE(config4.fec_enabled); |
576 | 587 |
577 config = CreateConfigWithParameters({{"useinbandfec", "1"}}); | 588 const auto config5 = CreateConfigWithParameters({{"usedtx", "0"}}); |
578 EXPECT_TRUE(config.fec_enabled); | 589 EXPECT_FALSE(config5.dtx_enabled); |
579 | 590 |
580 config = CreateConfigWithParameters({{"usedtx", "0"}}); | 591 const auto config6 = CreateConfigWithParameters({{"usedtx", "1"}}); |
581 EXPECT_FALSE(config.dtx_enabled); | 592 EXPECT_TRUE(config6.dtx_enabled); |
582 | 593 |
583 config = CreateConfigWithParameters({{"usedtx", "1"}}); | 594 const auto config7 = CreateConfigWithParameters({{"cbr", "0"}}); |
584 EXPECT_TRUE(config.dtx_enabled); | 595 EXPECT_FALSE(config7.cbr_enabled); |
585 | 596 |
586 config = CreateConfigWithParameters({{"cbr", "0"}}); | 597 const auto config8 = CreateConfigWithParameters({{"cbr", "1"}}); |
587 EXPECT_FALSE(config.cbr_enabled); | 598 EXPECT_TRUE(config8.cbr_enabled); |
588 | 599 |
589 config = CreateConfigWithParameters({{"cbr", "1"}}); | 600 const auto config9 = |
590 EXPECT_TRUE(config.cbr_enabled); | 601 CreateConfigWithParameters({{"maxplaybackrate", "12345"}}); |
| 602 EXPECT_EQ(12345, config9.max_playback_rate_hz); |
591 | 603 |
592 config = CreateConfigWithParameters({{"maxplaybackrate", "12345"}}); | 604 const auto config10 = |
593 EXPECT_EQ(12345, config.max_playback_rate_hz); | 605 CreateConfigWithParameters({{"maxaveragebitrate", "96000"}}); |
| 606 EXPECT_EQ(96000, config10.bitrate_bps); |
594 | 607 |
595 config = CreateConfigWithParameters({{"maxaveragebitrate", "96000"}}); | 608 const auto config11 = CreateConfigWithParameters({{"maxptime", "40"}}); |
596 EXPECT_EQ(96000, config.bitrate_bps); | 609 for (int frame_length : config11.supported_frame_lengths_ms) { |
597 | |
598 config = CreateConfigWithParameters({{"maxptime", "40"}}); | |
599 for (int frame_length : config.supported_frame_lengths_ms) { | |
600 EXPECT_LE(frame_length, 40); | 610 EXPECT_LE(frame_length, 40); |
601 } | 611 } |
602 | 612 |
603 config = CreateConfigWithParameters({{"minptime", "40"}}); | 613 const auto config12 = CreateConfigWithParameters({{"minptime", "40"}}); |
604 for (int frame_length : config.supported_frame_lengths_ms) { | 614 for (int frame_length : config12.supported_frame_lengths_ms) { |
605 EXPECT_GE(frame_length, 40); | 615 EXPECT_GE(frame_length, 40); |
606 } | 616 } |
607 | 617 |
608 config = CreateConfigWithParameters({{"ptime", "40"}}); | 618 const auto config13 = CreateConfigWithParameters({{"ptime", "40"}}); |
609 EXPECT_EQ(40, config.frame_size_ms); | 619 EXPECT_EQ(40, config13.frame_size_ms); |
610 | 620 |
611 constexpr int kMinSupportedFrameLength = 10; | 621 constexpr int kMinSupportedFrameLength = 10; |
612 constexpr int kMaxSupportedFrameLength = | 622 constexpr int kMaxSupportedFrameLength = |
613 WEBRTC_OPUS_SUPPORT_120MS_PTIME ? 120 : 60; | 623 WEBRTC_OPUS_SUPPORT_120MS_PTIME ? 120 : 60; |
614 | 624 |
615 config = CreateConfigWithParameters({{"ptime", "1"}}); | 625 const auto config14 = CreateConfigWithParameters({{"ptime", "1"}}); |
616 EXPECT_EQ(kMinSupportedFrameLength, config.frame_size_ms); | 626 EXPECT_EQ(kMinSupportedFrameLength, config14.frame_size_ms); |
617 | 627 |
618 config = CreateConfigWithParameters({{"ptime", "2000"}}); | 628 const auto config15 = CreateConfigWithParameters({{"ptime", "2000"}}); |
619 EXPECT_EQ(kMaxSupportedFrameLength, config.frame_size_ms); | 629 EXPECT_EQ(kMaxSupportedFrameLength, config15.frame_size_ms); |
620 } | 630 } |
621 | 631 |
622 TEST(AudioEncoderOpusTest, TestConfigFromInvalidParams) { | 632 TEST(AudioEncoderOpusTest, TestConfigFromInvalidParams) { |
623 const webrtc::SdpAudioFormat format("opus", 48000, 2); | 633 const webrtc::SdpAudioFormat format("opus", 48000, 2); |
624 const AudioEncoderOpus::Config default_config = | 634 const auto default_config = *AudioEncoderOpusImpl::SdpToConfig(format); |
625 AudioEncoderOpus::CreateConfig(0, format); | |
626 #if WEBRTC_OPUS_SUPPORT_120MS_PTIME | 635 #if WEBRTC_OPUS_SUPPORT_120MS_PTIME |
627 const std::vector<int> default_supported_frame_lengths_ms({20, 60, 120}); | 636 const std::vector<int> default_supported_frame_lengths_ms({20, 60, 120}); |
628 #else | 637 #else |
629 const std::vector<int> default_supported_frame_lengths_ms({20, 60}); | 638 const std::vector<int> default_supported_frame_lengths_ms({20, 60}); |
630 #endif | 639 #endif |
631 | 640 |
632 AudioEncoderOpus::Config config; | 641 AudioEncoderOpusConfig config; |
633 config = CreateConfigWithParameters({{"stereo", "invalid"}}); | 642 config = CreateConfigWithParameters({{"stereo", "invalid"}}); |
634 EXPECT_EQ(default_config.num_channels, config.num_channels); | 643 EXPECT_EQ(default_config.num_channels, config.num_channels); |
635 | 644 |
636 config = CreateConfigWithParameters({{"useinbandfec", "invalid"}}); | 645 config = CreateConfigWithParameters({{"useinbandfec", "invalid"}}); |
637 EXPECT_EQ(default_config.fec_enabled, config.fec_enabled); | 646 EXPECT_EQ(default_config.fec_enabled, config.fec_enabled); |
638 | 647 |
639 config = CreateConfigWithParameters({{"usedtx", "invalid"}}); | 648 config = CreateConfigWithParameters({{"usedtx", "invalid"}}); |
640 EXPECT_EQ(default_config.dtx_enabled, config.dtx_enabled); | 649 EXPECT_EQ(default_config.dtx_enabled, config.dtx_enabled); |
641 | 650 |
642 config = CreateConfigWithParameters({{"cbr", "invalid"}}); | 651 config = CreateConfigWithParameters({{"cbr", "invalid"}}); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 config = CreateConfigWithParameters({{"ptime", "invalid"}}); | 683 config = CreateConfigWithParameters({{"ptime", "invalid"}}); |
675 EXPECT_EQ(default_supported_frame_lengths_ms, | 684 EXPECT_EQ(default_supported_frame_lengths_ms, |
676 config.supported_frame_lengths_ms); | 685 config.supported_frame_lengths_ms); |
677 } | 686 } |
678 | 687 |
679 // Test that bitrate will be overridden by the "maxaveragebitrate" parameter. | 688 // Test that bitrate will be overridden by the "maxaveragebitrate" parameter. |
680 // Also test that the "maxaveragebitrate" can't be set to values outside the | 689 // Also test that the "maxaveragebitrate" can't be set to values outside the |
681 // range of 6000 and 510000 | 690 // range of 6000 and 510000 |
682 TEST(AudioEncoderOpusTest, SetSendCodecOpusMaxAverageBitrate) { | 691 TEST(AudioEncoderOpusTest, SetSendCodecOpusMaxAverageBitrate) { |
683 // Ignore if less than 6000. | 692 // Ignore if less than 6000. |
684 const AudioEncoderOpus::Config config1 = AudioEncoderOpus::CreateConfig( | 693 const auto config1 = AudioEncoderOpusImpl::SdpToConfig( |
685 0, {"opus", 48000, 2, {{"maxaveragebitrate", "5999"}}}); | 694 {"opus", 48000, 2, {{"maxaveragebitrate", "5999"}}}); |
686 EXPECT_EQ(6000, config1.bitrate_bps); | 695 EXPECT_EQ(6000, config1->bitrate_bps); |
687 | 696 |
688 // Ignore if larger than 510000. | 697 // Ignore if larger than 510000. |
689 const AudioEncoderOpus::Config config2 = AudioEncoderOpus::CreateConfig( | 698 const auto config2 = AudioEncoderOpusImpl::SdpToConfig( |
690 0, {"opus", 48000, 2, {{"maxaveragebitrate", "510001"}}}); | 699 {"opus", 48000, 2, {{"maxaveragebitrate", "510001"}}}); |
691 EXPECT_EQ(510000, config2.bitrate_bps); | 700 EXPECT_EQ(510000, config2->bitrate_bps); |
692 | 701 |
693 const AudioEncoderOpus::Config config3 = AudioEncoderOpus::CreateConfig( | 702 const auto config3 = AudioEncoderOpusImpl::SdpToConfig( |
694 0, {"opus", 48000, 2, {{"maxaveragebitrate", "200000"}}}); | 703 {"opus", 48000, 2, {{"maxaveragebitrate", "200000"}}}); |
695 EXPECT_EQ(200000, config3.bitrate_bps); | 704 EXPECT_EQ(200000, config3->bitrate_bps); |
696 } | 705 } |
697 | 706 |
698 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode. | 707 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode. |
699 TEST(AudioEncoderOpusTest, SetMaxPlaybackRateNb) { | 708 TEST(AudioEncoderOpusTest, SetMaxPlaybackRateNb) { |
700 auto config = CreateConfigWithParameters({{"maxplaybackrate", "8000"}}); | 709 auto config = CreateConfigWithParameters({{"maxplaybackrate", "8000"}}); |
701 EXPECT_EQ(8000, config.max_playback_rate_hz); | 710 EXPECT_EQ(8000, config.max_playback_rate_hz); |
702 EXPECT_EQ(12000, config.bitrate_bps); | 711 EXPECT_EQ(12000, config.bitrate_bps); |
703 | 712 |
704 config = CreateConfigWithParameters({{"maxplaybackrate", "8000"}, | 713 config = CreateConfigWithParameters({{"maxplaybackrate", "8000"}, |
705 {"stereo", "1"}}); | 714 {"stereo", "1"}}); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 EXPECT_EQ(24001, config.max_playback_rate_hz); | 758 EXPECT_EQ(24001, config.max_playback_rate_hz); |
750 EXPECT_EQ(32000, config.bitrate_bps); | 759 EXPECT_EQ(32000, config.bitrate_bps); |
751 | 760 |
752 config = CreateConfigWithParameters({{"maxplaybackrate", "24001"}, | 761 config = CreateConfigWithParameters({{"maxplaybackrate", "24001"}, |
753 {"stereo", "1"}}); | 762 {"stereo", "1"}}); |
754 EXPECT_EQ(24001, config.max_playback_rate_hz); | 763 EXPECT_EQ(24001, config.max_playback_rate_hz); |
755 EXPECT_EQ(64000, config.bitrate_bps); | 764 EXPECT_EQ(64000, config.bitrate_bps); |
756 } | 765 } |
757 | 766 |
758 } // namespace webrtc | 767 } // namespace webrtc |
OLD | NEW |