Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1385)

Unified Diff: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus_unittest.cc

Issue 2695243005: Injectable audio encoders: BuiltinAudioEncoderFactory (Closed)
Patch Set: Fix build problems on Windows, Android and downstream. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 04c0cf17c4abaab2d6111753831b04611af07343..55d3c9204b54f39ee206df633760a9e3b765b141 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
@@ -10,6 +10,7 @@
#include <array>
#include <memory>
+#include <utility>
#include "webrtc/base/checks.h"
#include "webrtc/base/fakeclock.h"
@@ -45,6 +46,12 @@ AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) {
return config;
}
+AudioEncoderOpus::Config CreateConfigWithParameters(
+ const SdpAudioFormat::Parameters& params) {
+ 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;
@@ -186,7 +193,7 @@ TEST(AudioEncoderOpusTest,
auto states = CreateCodec(1);
// Constants are replicated from audio_states.encoderopus.cc.
const int kMinBitrateBps = 6000;
- const int kMaxBitrateBps = 512000;
+ const int kMaxBitrateBps = 510000;
// Set a too low bitrate.
states.encoder->OnReceivedUplinkBandwidth(kMinBitrateBps - 1,
rtc::Optional<int64_t>());
@@ -417,7 +424,7 @@ TEST(AudioEncoderOpusTest, BitrateBounded) {
"WebRTC-SendSideBwe-WithOverhead/Enabled/");
constexpr int kMinBitrateBps = 6000;
- constexpr int kMaxBitrateBps = 512000;
+ constexpr int kMaxBitrateBps = 510000;
auto states = CreateCodec(2);
@@ -545,4 +552,199 @@ 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_FALSE(config.fec_enabled);
+
+ config = CreateConfigWithParameters({{"useinbandfec", "1"}});
+ EXPECT_TRUE(config.fec_enabled);
+
+ config = CreateConfigWithParameters({{"usedtx", "0"}});
+ EXPECT_FALSE(config.dtx_enabled);
+
+ config = CreateConfigWithParameters({{"usedtx", "1"}});
+ EXPECT_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);
+
+ constexpr int kMinSupportedFrameLength = 10;
+ constexpr int kMaxSupportedFrameLength =
+ WEBRTC_OPUS_SUPPORT_120MS_PTIME ? 120 : 60;
+
+ config = CreateConfigWithParameters({{"ptime", "1"}});
+ EXPECT_EQ(kMinSupportedFrameLength, config.frame_size_ms);
+
+ config = CreateConfigWithParameters({{"ptime", "2000"}});
+ EXPECT_EQ(kMaxSupportedFrameLength, config.frame_size_ms);
+}
+
+TEST(AudioEncoderOpusTest, TestConfigFromInvalidParams) {
+ const webrtc::SdpAudioFormat format("opus", 48000, 2);
+ const AudioEncoderOpus::Config default_config =
+ AudioEncoderOpus::CreateConfig(0, format);
+#if WEBRTC_OPUS_SUPPORT_120MS_PTIME
+ const std::vector<int> default_supported_frame_lengths_ms({20, 60, 120});
+#else
+ const std::vector<int> default_supported_frame_lengths_ms({20, 60});
+#endif
+
+ 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(6000, config.bitrate_bps);
+
+ config = CreateConfigWithParameters({{"maxaveragebitrate", "-1000"}});
+ EXPECT_EQ(6000, config.bitrate_bps);
+
+ config = CreateConfigWithParameters({{"maxaveragebitrate", "1024000"}});
+ EXPECT_EQ(510000, 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

Powered by Google App Engine
This is Rietveld 408576698