| Index: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| index 11456f21793c34ec53f591c1d0de7ceb74a015bb..80c66ae18d1022f49346476ad74dd80829aae92d 100644
|
| --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc
|
| @@ -45,6 +45,12 @@ AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) {
|
| return config;
|
| }
|
|
|
| +AudioEncoderOpus::Config CreateConfigWithParameters(
|
| + const SdpAudioFormat::Parameters& params) {
|
| + webrtc::SdpAudioFormat format("opus", 48000, 2, params);
|
| + return AudioEncoderOpus::CreateConfig(0, format);
|
| +}
|
| +
|
| struct AudioEncoderOpusStates {
|
| std::shared_ptr<MockAudioNetworkAdaptor*> mock_audio_network_adaptor;
|
| MockSmoothingFilter* mock_bitrate_smoother;
|
| @@ -545,4 +551,182 @@ TEST(AudioEncoderOpusTest, EncodeAtMinBitrate) {
|
| }
|
| }
|
|
|
| +TEST(AudioEncoderOpusTest, TestConfigDefaults) {
|
| + const AudioEncoderOpus::Config config =
|
| + AudioEncoderOpus::CreateConfig(0, {"opus", 48000, 2});
|
| +
|
| + EXPECT_EQ(48000, config.max_playback_rate_hz);
|
| + EXPECT_EQ(1U, config.num_channels);
|
| + EXPECT_FALSE(config.fec_enabled);
|
| + EXPECT_FALSE(config.dtx_enabled);
|
| + EXPECT_EQ(20, config.frame_size_ms);
|
| +}
|
| +
|
| +TEST(AudioEncoderOpusTest, TestConfigFromParams) {
|
| + AudioEncoderOpus::Config config;
|
| +
|
| + config = CreateConfigWithParameters({{"stereo", "0"}});
|
| + EXPECT_EQ(1U, config.num_channels);
|
| +
|
| + config = CreateConfigWithParameters({{"stereo", "1"}});
|
| + EXPECT_EQ(2U, config.num_channels);
|
| +
|
| + config = CreateConfigWithParameters({{"useinbandfec", "0"}});
|
| + EXPECT_EQ(false, config.fec_enabled);
|
| +
|
| + config = CreateConfigWithParameters({{"useinbandfec", "1"}});
|
| + EXPECT_EQ(true, config.fec_enabled);
|
| +
|
| + config = CreateConfigWithParameters({{"usedtx", "0"}});
|
| + EXPECT_EQ(false, config.dtx_enabled);
|
| +
|
| + config = CreateConfigWithParameters({{"usedtx", "1"}});
|
| + EXPECT_EQ(true, config.dtx_enabled);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "12345"}});
|
| + EXPECT_EQ(12345, config.max_playback_rate_hz);
|
| +
|
| + config = CreateConfigWithParameters({{"maxaveragebitrate", "96000"}});
|
| + EXPECT_EQ(96000, config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxptime", "40"}});
|
| + for (int frame_length : config.supported_frame_lengths_ms) {
|
| + EXPECT_LE(frame_length, 40);
|
| + }
|
| +
|
| + config = CreateConfigWithParameters({{"minptime", "40"}});
|
| + for (int frame_length : config.supported_frame_lengths_ms) {
|
| + EXPECT_GE(frame_length, 40);
|
| + }
|
| +
|
| + config = CreateConfigWithParameters({{"ptime", "40"}});
|
| + EXPECT_EQ(40, config.frame_size_ms);
|
| +}
|
| +
|
| +TEST(AudioEncoderOpusTest, TestConfigFromInvalidParams) {
|
| + const webrtc::SdpAudioFormat format("opus", 48000, 2);
|
| + const AudioEncoderOpus::Config default_config =
|
| + AudioEncoderOpus::CreateConfig(0, format);
|
| + const std::vector<int> default_supported_frame_lengths_ms({20, 60});
|
| +
|
| + AudioEncoderOpus::Config config;
|
| + config = CreateConfigWithParameters({{"stereo", "invalid"}});
|
| + EXPECT_EQ(default_config.num_channels, config.num_channels);
|
| +
|
| + config = CreateConfigWithParameters({{"useinbandfec", "invalid"}});
|
| + EXPECT_EQ(default_config.fec_enabled, config.fec_enabled);
|
| +
|
| + config = CreateConfigWithParameters({{"usedtx", "invalid"}});
|
| + EXPECT_EQ(default_config.dtx_enabled, config.dtx_enabled);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "0"}});
|
| + EXPECT_EQ(default_config.max_playback_rate_hz, config.max_playback_rate_hz);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "-23"}});
|
| + EXPECT_EQ(default_config.max_playback_rate_hz, config.max_playback_rate_hz);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "not a number!"}});
|
| + EXPECT_EQ(default_config.max_playback_rate_hz, config.max_playback_rate_hz);
|
| +
|
| + config = CreateConfigWithParameters({{"maxaveragebitrate", "0"}});
|
| + EXPECT_EQ(default_config.bitrate_bps, config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxaveragebitrate", "-1000"}});
|
| + EXPECT_EQ(default_config.bitrate_bps, config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxaveragebitrate", "not a number!"}});
|
| + EXPECT_EQ(default_config.bitrate_bps, config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxptime", "invalid"}});
|
| + EXPECT_EQ(default_supported_frame_lengths_ms,
|
| + config.supported_frame_lengths_ms);
|
| +
|
| + config = CreateConfigWithParameters({{"minptime", "invalid"}});
|
| + EXPECT_EQ(default_supported_frame_lengths_ms,
|
| + config.supported_frame_lengths_ms);
|
| +
|
| + config = CreateConfigWithParameters({{"ptime", "invalid"}});
|
| + EXPECT_EQ(default_supported_frame_lengths_ms,
|
| + config.supported_frame_lengths_ms);
|
| +}
|
| +
|
| +// Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
|
| +// Also test that the "maxaveragebitrate" can't be set to values outside the
|
| +// range of 6000 and 510000
|
| +TEST(AudioEncoderOpusTest, SetSendCodecOpusMaxAverageBitrate) {
|
| + // Ignore if less than 6000.
|
| + const AudioEncoderOpus::Config config1 = AudioEncoderOpus::CreateConfig(
|
| + 0, {"opus", 48000, 2, {{"maxaveragebitrate", "5999"}}});
|
| + EXPECT_EQ(6000, *config1.bitrate_bps);
|
| +
|
| + // Ignore if larger than 510000.
|
| + const AudioEncoderOpus::Config config2 = AudioEncoderOpus::CreateConfig(
|
| + 0, {"opus", 48000, 2, {{"maxaveragebitrate", "510001"}}});
|
| + EXPECT_EQ(510000, *config2.bitrate_bps);
|
| +
|
| + const AudioEncoderOpus::Config config3 = AudioEncoderOpus::CreateConfig(
|
| + 0, {"opus", 48000, 2, {{"maxaveragebitrate", "200000"}}});
|
| + EXPECT_EQ(200000, *config3.bitrate_bps);
|
| +}
|
| +
|
| +// Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
|
| +TEST(AudioEncoderOpusTest, SetMaxPlaybackRateNb) {
|
| + auto config = CreateConfigWithParameters({{"maxplaybackrate", "8000"}});
|
| + EXPECT_EQ(8000, config.max_playback_rate_hz);
|
| + EXPECT_EQ(12000, *config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "8000"},
|
| + {"stereo", "1"}});
|
| + EXPECT_EQ(8000, config.max_playback_rate_hz);
|
| + EXPECT_EQ(24000, *config.bitrate_bps);
|
| +}
|
| +
|
| +// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
|
| +TEST(AudioEncoderOpusTest, SetMaxPlaybackRateMb) {
|
| + auto config = CreateConfigWithParameters({{"maxplaybackrate", "8001"}});
|
| + EXPECT_EQ(8001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(20000, *config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "8001"},
|
| + {"stereo", "1"}});
|
| + EXPECT_EQ(8001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(40000, *config.bitrate_bps);
|
| +}
|
| +
|
| +// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
|
| +TEST(AudioEncoderOpusTest, SetMaxPlaybackRateWb) {
|
| + auto config = CreateConfigWithParameters({{"maxplaybackrate", "12001"}});
|
| + EXPECT_EQ(12001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(20000, *config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "12001"},
|
| + {"stereo", "1"}});
|
| + EXPECT_EQ(12001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(40000, *config.bitrate_bps);
|
| +}
|
| +
|
| +// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
|
| +TEST(AudioEncoderOpusTest, SetMaxPlaybackRateSwb) {
|
| + auto config = CreateConfigWithParameters({{"maxplaybackrate", "16001"}});
|
| + EXPECT_EQ(16001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(32000, *config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "16001"},
|
| + {"stereo", "1"}});
|
| + EXPECT_EQ(16001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(64000, *config.bitrate_bps);
|
| +}
|
| +
|
| +// Test 24000 < maxplaybackrate triggers Opus full band mode.
|
| +TEST(AudioEncoderOpusTest, SetMaxPlaybackRateFb) {
|
| + auto config = CreateConfigWithParameters({{"maxplaybackrate", "24001"}});
|
| + EXPECT_EQ(24001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(32000, *config.bitrate_bps);
|
| +
|
| + config = CreateConfigWithParameters({{"maxplaybackrate", "24001"},
|
| + {"stereo", "1"}});
|
| + EXPECT_EQ(24001, config.max_playback_rate_hz);
|
| + EXPECT_EQ(64000, *config.bitrate_bps);
|
| +}
|
| +
|
| } // namespace webrtc
|
|
|