VAD/DTX tests: Don't let the ACM create audio encoders
It will soon lose the ability to do so. Bug: webrtc:8396 Change-Id: I06dce417bba855b57130bd1a052988b2f235dcbd Reviewed-on: https://webrtc-review.googlesource.com/102882 Commit-Queue: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Ivo Creusen <ivoc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24921}
This commit is contained in:
@ -1325,6 +1325,7 @@ if (rtc_include_tests) {
|
|||||||
":audio_coding",
|
":audio_coding",
|
||||||
":audio_coding_module_typedefs",
|
":audio_coding_module_typedefs",
|
||||||
":audio_format_conversion",
|
":audio_format_conversion",
|
||||||
|
":cng",
|
||||||
":pcm16b_c",
|
":pcm16b_c",
|
||||||
"..:module_api",
|
"..:module_api",
|
||||||
"../..:webrtc_common",
|
"../..:webrtc_common",
|
||||||
@ -1332,7 +1333,13 @@ if (rtc_include_tests) {
|
|||||||
"../../api/audio_codecs:audio_codecs_api",
|
"../../api/audio_codecs:audio_codecs_api",
|
||||||
"../../api/audio_codecs:builtin_audio_decoder_factory",
|
"../../api/audio_codecs:builtin_audio_decoder_factory",
|
||||||
"../../api/audio_codecs:builtin_audio_encoder_factory",
|
"../../api/audio_codecs:builtin_audio_encoder_factory",
|
||||||
|
"../../api/audio_codecs/ilbc:audio_decoder_ilbc",
|
||||||
|
"../../api/audio_codecs/ilbc:audio_encoder_ilbc",
|
||||||
|
"../../api/audio_codecs/isac:audio_decoder_isac_float",
|
||||||
"../../api/audio_codecs/isac:audio_encoder_isac_float",
|
"../../api/audio_codecs/isac:audio_encoder_isac_float",
|
||||||
|
"../../api/audio_codecs/opus:audio_decoder_opus",
|
||||||
|
"../../api/audio_codecs/opus:audio_encoder_opus",
|
||||||
|
"../../common_audio",
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
"../../rtc_base:rtc_base_approved",
|
"../../rtc_base:rtc_base_approved",
|
||||||
"../../rtc_base/synchronization:rw_lock_wrapper",
|
"../../rtc_base/synchronization:rw_lock_wrapper",
|
||||||
|
@ -12,8 +12,15 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
#include "api/audio_codecs/audio_decoder_factory_template.h"
|
||||||
#include "modules/audio_coding/codecs/audio_format_conversion.h"
|
#include "api/audio_codecs/audio_encoder_factory_template.h"
|
||||||
|
#include "api/audio_codecs/ilbc/audio_decoder_ilbc.h"
|
||||||
|
#include "api/audio_codecs/ilbc/audio_encoder_ilbc.h"
|
||||||
|
#include "api/audio_codecs/isac/audio_decoder_isac_float.h"
|
||||||
|
#include "api/audio_codecs/isac/audio_encoder_isac_float.h"
|
||||||
|
#include "api/audio_codecs/opus/audio_decoder_opus.h"
|
||||||
|
#include "api/audio_codecs/opus/audio_encoder_opus.h"
|
||||||
|
#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
|
||||||
#include "modules/audio_coding/test/PCMFile.h"
|
#include "modules/audio_coding/test/PCMFile.h"
|
||||||
#include "modules/audio_coding/test/utility.h"
|
#include "modules/audio_coding/test/utility.h"
|
||||||
#include "rtc_base/strings/string_builder.h"
|
#include "rtc_base/strings/string_builder.h"
|
||||||
@ -21,20 +28,6 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
#ifdef WEBRTC_CODEC_ISAC
|
|
||||||
const CodecInst kIsacWb = {103, "ISAC", 16000, 480, 1, 32000};
|
|
||||||
const CodecInst kIsacSwb = {104, "ISAC", 32000, 960, 1, 56000};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WEBRTC_CODEC_ILBC
|
|
||||||
const CodecInst kIlbc = {102, "ILBC", 8000, 240, 1, 13300};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WEBRTC_CODEC_OPUS
|
|
||||||
const CodecInst kOpus = {120, "opus", 48000, 960, 1, 64000};
|
|
||||||
const CodecInst kOpusStereo = {120, "opus", 48000, 960, 2, 64000};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ActivityMonitor::ActivityMonitor() {
|
ActivityMonitor::ActivityMonitor() {
|
||||||
ResetStatistics();
|
ResetStatistics();
|
||||||
}
|
}
|
||||||
@ -63,10 +56,16 @@ void ActivityMonitor::GetStatistics(uint32_t* counter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestVadDtx::TestVadDtx()
|
TestVadDtx::TestVadDtx()
|
||||||
: acm_send_(AudioCodingModule::Create(
|
: encoder_factory_(CreateAudioEncoderFactory<AudioEncoderIlbc,
|
||||||
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
|
AudioEncoderIsacFloat,
|
||||||
|
AudioEncoderOpus>()),
|
||||||
|
decoder_factory_(CreateAudioDecoderFactory<AudioDecoderIlbc,
|
||||||
|
AudioDecoderIsacFloat,
|
||||||
|
AudioDecoderOpus>()),
|
||||||
|
acm_send_(AudioCodingModule::Create(
|
||||||
|
AudioCodingModule::Config(decoder_factory_))),
|
||||||
acm_receive_(AudioCodingModule::Create(
|
acm_receive_(AudioCodingModule::Create(
|
||||||
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
|
AudioCodingModule::Config(decoder_factory_))),
|
||||||
channel_(new Channel),
|
channel_(new Channel),
|
||||||
monitor_(new ActivityMonitor) {
|
monitor_(new ActivityMonitor) {
|
||||||
EXPECT_EQ(0, acm_send_->RegisterTransportCallback(channel_.get()));
|
EXPECT_EQ(0, acm_send_->RegisterTransportCallback(channel_.get()));
|
||||||
@ -74,12 +73,29 @@ TestVadDtx::TestVadDtx()
|
|||||||
EXPECT_EQ(0, acm_send_->RegisterVADCallback(monitor_.get()));
|
EXPECT_EQ(0, acm_send_->RegisterVADCallback(monitor_.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestVadDtx::RegisterCodec(CodecInst codec_param) {
|
bool TestVadDtx::RegisterCodec(const SdpAudioFormat& codec_format,
|
||||||
// Set the codec for sending and receiving.
|
absl::optional<Vad::Aggressiveness> vad_mode) {
|
||||||
EXPECT_EQ(0, acm_send_->RegisterSendCodec(codec_param));
|
constexpr int payload_type = 17, cn_payload_type = 117;
|
||||||
EXPECT_EQ(true, acm_receive_->RegisterReceiveCodec(
|
bool added_comfort_noise = false;
|
||||||
codec_param.pltype, CodecInstToSdp(codec_param)));
|
|
||||||
channel_->SetIsStereo(codec_param.channels > 1);
|
auto encoder = encoder_factory_->MakeAudioEncoder(payload_type, codec_format,
|
||||||
|
absl::nullopt);
|
||||||
|
if (vad_mode.has_value() &&
|
||||||
|
STR_CASE_CMP(codec_format.name.c_str(), "opus") != 0) {
|
||||||
|
AudioEncoderCng::Config config;
|
||||||
|
config.speech_encoder = std::move(encoder);
|
||||||
|
config.num_channels = 1;
|
||||||
|
config.payload_type = cn_payload_type;
|
||||||
|
config.vad_mode = vad_mode.value();
|
||||||
|
encoder = absl::make_unique<AudioEncoderCng>(std::move(config));
|
||||||
|
added_comfort_noise = true;
|
||||||
|
}
|
||||||
|
channel_->SetIsStereo(encoder->NumChannels() > 1);
|
||||||
|
acm_send_->SetEncoder(std::move(encoder));
|
||||||
|
|
||||||
|
EXPECT_EQ(true,
|
||||||
|
acm_receive_->RegisterReceiveCodec(payload_type, codec_format));
|
||||||
|
return added_comfort_noise;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encoding a file and see if the numbers that various packets occur follow
|
// Encoding a file and see if the numbers that various packets occur follow
|
||||||
@ -148,60 +164,36 @@ void TestVadDtx::Run(std::string in_filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Following is the implementation of TestWebRtcVadDtx.
|
// Following is the implementation of TestWebRtcVadDtx.
|
||||||
TestWebRtcVadDtx::TestWebRtcVadDtx()
|
TestWebRtcVadDtx::TestWebRtcVadDtx() : output_file_num_(0) {}
|
||||||
: vad_enabled_(false), dtx_enabled_(false), output_file_num_(0) {}
|
|
||||||
|
|
||||||
void TestWebRtcVadDtx::Perform() {
|
void TestWebRtcVadDtx::Perform() {
|
||||||
// Go through various test cases.
|
RunTestCases({"ISAC", 16000, 1});
|
||||||
#ifdef WEBRTC_CODEC_ISAC
|
RunTestCases({"ISAC", 32000, 1});
|
||||||
// Register iSAC WB as send codec
|
RunTestCases({"ILBC", 8000, 1});
|
||||||
RegisterCodec(kIsacWb);
|
RunTestCases({"opus", 48000, 2});
|
||||||
RunTestCases();
|
|
||||||
|
|
||||||
// Register iSAC SWB as send codec
|
|
||||||
RegisterCodec(kIsacSwb);
|
|
||||||
RunTestCases();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WEBRTC_CODEC_ILBC
|
|
||||||
// Register iLBC as send codec
|
|
||||||
RegisterCodec(kIlbc);
|
|
||||||
RunTestCases();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WEBRTC_CODEC_OPUS
|
|
||||||
// Register Opus as send codec
|
|
||||||
RegisterCodec(kOpus);
|
|
||||||
RunTestCases();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test various configurations on VAD/DTX.
|
// Test various configurations on VAD/DTX.
|
||||||
void TestWebRtcVadDtx::RunTestCases() {
|
void TestWebRtcVadDtx::RunTestCases(const SdpAudioFormat& codec_format) {
|
||||||
// #1 DTX = OFF, VAD = OFF, VADNormal
|
Test(/*new_outfile=*/true,
|
||||||
SetVAD(false, false, VADNormal);
|
/*expect_dtx_enabled=*/RegisterCodec(codec_format, absl::nullopt));
|
||||||
Test(true);
|
|
||||||
|
|
||||||
// #2 DTX = ON, VAD = ON, VADAggr
|
Test(/*new_outfile=*/false,
|
||||||
SetVAD(true, true, VADAggr);
|
/*expect_dtx_enabled=*/RegisterCodec(codec_format, Vad::kVadAggressive));
|
||||||
Test(false);
|
|
||||||
|
|
||||||
// #3 DTX = ON, VAD = ON, VADLowBitrate
|
Test(/*new_outfile=*/false,
|
||||||
SetVAD(true, true, VADLowBitrate);
|
/*expect_dtx_enabled=*/RegisterCodec(codec_format, Vad::kVadLowBitrate));
|
||||||
Test(false);
|
|
||||||
|
|
||||||
// #4 DTX = ON, VAD = ON, VADVeryAggr
|
Test(/*new_outfile=*/false, /*expect_dtx_enabled=*/RegisterCodec(
|
||||||
SetVAD(true, true, VADVeryAggr);
|
codec_format, Vad::kVadVeryAggressive));
|
||||||
Test(false);
|
|
||||||
|
|
||||||
// #5 DTX = ON, VAD = ON, VADNormal
|
Test(/*new_outfile=*/false,
|
||||||
SetVAD(true, true, VADNormal);
|
/*expect_dtx_enabled=*/RegisterCodec(codec_format, Vad::kVadNormal));
|
||||||
Test(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the expectation and run the test.
|
// Set the expectation and run the test.
|
||||||
void TestWebRtcVadDtx::Test(bool new_outfile) {
|
void TestWebRtcVadDtx::Test(bool new_outfile, bool expect_dtx_enabled) {
|
||||||
int expects[] = {-1, 1, dtx_enabled_, 0, 0};
|
int expects[] = {-1, 1, expect_dtx_enabled, 0, 0};
|
||||||
if (new_outfile) {
|
if (new_outfile) {
|
||||||
output_file_num_++;
|
output_file_num_++;
|
||||||
}
|
}
|
||||||
@ -212,46 +204,19 @@ void TestWebRtcVadDtx::Test(bool new_outfile) {
|
|||||||
out_filename.str(), !new_outfile, expects);
|
out_filename.str(), !new_outfile, expects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestWebRtcVadDtx::SetVAD(bool enable_dtx,
|
|
||||||
bool enable_vad,
|
|
||||||
ACMVADMode vad_mode) {
|
|
||||||
ACMVADMode mode;
|
|
||||||
EXPECT_EQ(0, acm_send_->SetVAD(enable_dtx, enable_vad, vad_mode));
|
|
||||||
EXPECT_EQ(0, acm_send_->VAD(&dtx_enabled_, &vad_enabled_, &mode));
|
|
||||||
|
|
||||||
auto codec_param = acm_send_->SendCodec();
|
|
||||||
ASSERT_TRUE(codec_param);
|
|
||||||
if (STR_CASE_CMP(codec_param->plname, "opus") == 0) {
|
|
||||||
// If send codec is Opus, WebRTC VAD/DTX cannot be used.
|
|
||||||
enable_dtx = enable_vad = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_EQ(dtx_enabled_, enable_dtx); // DTX should be set as expected.
|
|
||||||
|
|
||||||
if (dtx_enabled_) {
|
|
||||||
EXPECT_TRUE(vad_enabled_); // WebRTC DTX cannot run without WebRTC VAD.
|
|
||||||
} else {
|
|
||||||
// Using no DTX should not affect setting of VAD.
|
|
||||||
EXPECT_EQ(enable_vad, vad_enabled_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Following is the implementation of TestOpusDtx.
|
// Following is the implementation of TestOpusDtx.
|
||||||
void TestOpusDtx::Perform() {
|
void TestOpusDtx::Perform() {
|
||||||
#ifdef WEBRTC_CODEC_ISAC
|
|
||||||
// If we set other codec than Opus, DTX cannot be switched on.
|
// If we set other codec than Opus, DTX cannot be switched on.
|
||||||
RegisterCodec(kIsacWb);
|
RegisterCodec({"ISAC", 16000, 1}, absl::nullopt);
|
||||||
EXPECT_EQ(-1, acm_send_->EnableOpusDtx());
|
EXPECT_EQ(-1, acm_send_->EnableOpusDtx());
|
||||||
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
|
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WEBRTC_CODEC_OPUS
|
|
||||||
int expects[] = {0, 1, 0, 0, 0};
|
int expects[] = {0, 1, 0, 0, 0};
|
||||||
|
|
||||||
// Register Opus as send codec
|
// Register Opus as send codec
|
||||||
std::string out_filename =
|
std::string out_filename =
|
||||||
webrtc::test::OutputPath() + "testOpusDtx_outFile_mono.pcm";
|
webrtc::test::OutputPath() + "testOpusDtx_outFile_mono.pcm";
|
||||||
RegisterCodec(kOpus);
|
RegisterCodec({"opus", 48000, 2}, absl::nullopt);
|
||||||
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
|
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
|
||||||
|
|
||||||
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1,
|
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1,
|
||||||
@ -265,7 +230,7 @@ void TestOpusDtx::Perform() {
|
|||||||
|
|
||||||
// Register stereo Opus as send codec
|
// Register stereo Opus as send codec
|
||||||
out_filename = webrtc::test::OutputPath() + "testOpusDtx_outFile_stereo.pcm";
|
out_filename = webrtc::test::OutputPath() + "testOpusDtx_outFile_stereo.pcm";
|
||||||
RegisterCodec(kOpusStereo);
|
RegisterCodec({"opus", 48000, 2, {{"stereo", "1"}}}, absl::nullopt);
|
||||||
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
|
EXPECT_EQ(0, acm_send_->DisableOpusDtx());
|
||||||
expects[kEmptyFrame] = 0;
|
expects[kEmptyFrame] = 0;
|
||||||
expects[kAudioFrameCN] = 0;
|
expects[kAudioFrameCN] = 0;
|
||||||
@ -278,7 +243,6 @@ void TestOpusDtx::Perform() {
|
|||||||
expects[kAudioFrameCN] = 1;
|
expects[kAudioFrameCN] = 1;
|
||||||
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000,
|
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000,
|
||||||
2, out_filename, true, expects);
|
2, out_filename, true, expects);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||||
|
#include "api/audio_codecs/audio_encoder_factory.h"
|
||||||
|
#include "common_audio/vad/include/vad.h"
|
||||||
#include "common_types.h" // NOLINT(build/include)
|
#include "common_types.h" // NOLINT(build/include)
|
||||||
#include "modules/audio_coding/include/audio_coding_module.h"
|
#include "modules/audio_coding/include/audio_coding_module.h"
|
||||||
#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
|
#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
|
||||||
@ -48,7 +51,9 @@ class TestVadDtx {
|
|||||||
TestVadDtx();
|
TestVadDtx();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void RegisterCodec(CodecInst codec_param);
|
// Returns true iff CN was added.
|
||||||
|
bool RegisterCodec(const SdpAudioFormat& codec_format,
|
||||||
|
absl::optional<Vad::Aggressiveness> vad_mode);
|
||||||
|
|
||||||
// Encoding a file and see if the numbers that various packets occur follow
|
// Encoding a file and see if the numbers that various packets occur follow
|
||||||
// the expectation. Saves result to a file.
|
// the expectation. Saves result to a file.
|
||||||
@ -69,6 +74,8 @@ class TestVadDtx {
|
|||||||
bool append,
|
bool append,
|
||||||
const int* expects);
|
const int* expects);
|
||||||
|
|
||||||
|
const rtc::scoped_refptr<AudioEncoderFactory> encoder_factory_;
|
||||||
|
const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
|
||||||
std::unique_ptr<AudioCodingModule> acm_send_;
|
std::unique_ptr<AudioCodingModule> acm_send_;
|
||||||
std::unique_ptr<AudioCodingModule> acm_receive_;
|
std::unique_ptr<AudioCodingModule> acm_receive_;
|
||||||
std::unique_ptr<Channel> channel_;
|
std::unique_ptr<Channel> channel_;
|
||||||
@ -84,12 +91,9 @@ class TestWebRtcVadDtx final : public TestVadDtx {
|
|||||||
void Perform();
|
void Perform();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RunTestCases();
|
void RunTestCases(const SdpAudioFormat& codec_format);
|
||||||
void Test(bool new_outfile);
|
void Test(bool new_outfile, bool expect_dtx_enabled);
|
||||||
void SetVAD(bool enable_dtx, bool enable_vad, ACMVADMode vad_mode);
|
|
||||||
|
|
||||||
bool vad_enabled_;
|
|
||||||
bool dtx_enabled_;
|
|
||||||
int output_file_num_;
|
int output_file_num_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -79,12 +79,7 @@ TEST(AudioCodingModuleTest, TestStereo) {
|
|||||||
webrtc::TestStereo(ACM_TEST_MODE).Perform();
|
webrtc::TestStereo(ACM_TEST_MODE).Perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disabled on ios as flaky, see https://crbug.com/webrtc/7057
|
|
||||||
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
|
|
||||||
TEST(AudioCodingModuleTest, DISABLED_TestWebRtcVadDtx) {
|
|
||||||
#else
|
|
||||||
TEST(AudioCodingModuleTest, TestWebRtcVadDtx) {
|
TEST(AudioCodingModuleTest, TestWebRtcVadDtx) {
|
||||||
#endif
|
|
||||||
webrtc::TestWebRtcVadDtx().Perform();
|
webrtc::TestWebRtcVadDtx().Perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user