Re-organizing ACM tests

The ACM tests needed re-writing, because all tests were not individual gtests, and the result was difficult to interpret.

While doing the re-write, I discovered a bug related to 48 kHz CNG. We can't have the 48 kHz CNG active at the moment. The bug is fixed in this CL.

I also needed to rewrite parts of the VAD/DTX implementation, so that the status of VAD and DTX (enabled or not) is propagated back from the function SetVAD().

BUG=issue2173
R=minyue@webrtc.org, turaj@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1961004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4625 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tina.legrand@webrtc.org
2013-08-27 07:33:51 +00:00
parent d6fef9d380
commit ee92b664b3
19 changed files with 496 additions and 1038 deletions

View File

@ -23,12 +23,11 @@
namespace webrtc {
TestFEC::TestFEC(int testMode)
TestFEC::TestFEC()
: _acmA(NULL),
_acmB(NULL),
_channelA2B(NULL),
_testCntr(0) {
_testMode = testMode;
}
TestFEC::~TestFEC() {
@ -47,35 +46,21 @@ TestFEC::~TestFEC() {
}
void TestFEC::Perform() {
if (_testMode == 0) {
printf("Running FEC Test");
WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1,
"---------- TestFEC ----------");
}
const std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
_inFileA.Open(file_name, 32000, "rb");
bool fecEnabled;
_acmA = AudioCodingModule::Create(0);
_acmB = AudioCodingModule::Create(1);
_acmA->InitializeReceiver();
_acmB->InitializeReceiver();
ASSERT_EQ(0, _acmA->InitializeReceiver());
ASSERT_EQ(0, _acmB->InitializeReceiver());
uint8_t numEncoders = _acmA->NumberOfCodecs();
CodecInst myCodecParam;
if (_testMode != 0) {
printf("Registering codecs at receiver... \n");
}
for (uint8_t n = 0; n < numEncoders; n++) {
_acmB->Codec(n, &myCodecParam);
if (_testMode != 0) {
printf("%s\n", myCodecParam.plname);
}
_acmB->RegisterReceiveCodec(myCodecParam);
EXPECT_EQ(0, _acmB->Codec(n, &myCodecParam));
EXPECT_EQ(0, _acmB->RegisterReceiveCodec(myCodecParam));
}
// Create and connect the channel
@ -83,333 +68,151 @@ void TestFEC::Perform() {
_acmA->RegisterTransportCallback(_channelA2B);
_channelA2B->RegisterReceiverACM(_acmB);
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
#ifndef WEBRTC_CODEC_G722
EXPECT_TRUE(false);
printf("G722 needs to be activated to run this test\n");
exit(-1);
return;
#endif
char nameG722[] = "G722";
RegisterSendCodec('A', nameG722, 16000);
EXPECT_EQ(0, RegisterSendCodec('A', nameG722, 16000));
char nameCN[] = "CN";
RegisterSendCodec('A', nameCN, 16000);
EXPECT_EQ(0, RegisterSendCodec('A', nameCN, 16000));
char nameRED[] = "RED";
RegisterSendCodec('A', nameRED);
EXPECT_EQ(0, RegisterSendCodec('A', nameRED));
OpenOutFile(_testCntr);
SetVAD(true, true, VADAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(true, true, VADAggr));
EXPECT_EQ(0, _acmA->SetFECStatus(false));
EXPECT_FALSE(_acmA->FECStatus());
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
char nameISAC[] = "iSAC";
RegisterSendCodec('A', nameISAC, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetFECStatus(false));
EXPECT_FALSE(_acmA->FECStatus());
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetFECStatus(false));
EXPECT_FALSE(_acmA->FECStatus());
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(false, false, VADNormal);
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(false, false, VADNormal));
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_TRUE(_acmA->FECStatus());
Run();
RegisterSendCodec('A', nameISAC, 32000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_TRUE(_acmA->FECStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_TRUE(_acmA->FECStatus());
Run();
_outFileB.Close();
_channelA2B->SetFECTestWithPacketLoss(true);
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameG722);
RegisterSendCodec('A', nameCN, 16000);
EXPECT_EQ(0, RegisterSendCodec('A', nameG722));
EXPECT_EQ(0, RegisterSendCodec('A', nameCN, 16000));
OpenOutFile(_testCntr);
SetVAD(true, true, VADAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(true, true, VADAggr));
EXPECT_EQ(0, _acmA->SetFECStatus(false));
EXPECT_FALSE(_acmA->FECStatus());
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 16000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetFECStatus(false));
EXPECT_FALSE(_acmA->FECStatus());
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(true, true, VADVeryAggr);
_acmA->SetFECStatus(false);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetFECStatus(false));
EXPECT_FALSE(_acmA->FECStatus());
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
if (_testMode != 0) {
printf("===============================================================\n");
printf("%d ", _testCntr++);
} else {
printf(".");
}
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
SetVAD(false, false, VADNormal);
_acmA->SetFECStatus(true);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_EQ(0, SetVAD(false, false, VADNormal));
EXPECT_EQ(0, _acmA->SetFECStatus(true));
EXPECT_TRUE(_acmA->FECStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_TRUE(_acmA->FECStatus());
Run();
RegisterSendCodec('A', nameISAC, 32000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_TRUE(_acmA->FECStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
fecEnabled = _acmA->FECStatus();
if (_testMode != 0) {
printf("FEC currently %s\n", (fecEnabled ? "ON" : "OFF"));
DisplaySendReceiveCodec();
}
EXPECT_TRUE(_acmA->FECStatus());
Run();
_outFileB.Close();
if (_testMode == 0) {
printf("Done!\n");
}
}
int32_t TestFEC::SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode) {
if (_testMode != 0) {
printf("DTX %s; VAD %s; VAD-Mode %d\n", enableDTX ? "ON" : "OFF",
enableVAD ? "ON" : "OFF", (int16_t) vadMode);
}
return _acmA->SetVAD(enableDTX, enableVAD, vadMode);
}
int16_t TestFEC::RegisterSendCodec(char side, char* codecName,
int32_t samplingFreqHz) {
if (_testMode != 0) {
if (samplingFreqHz > 0) {
printf("Registering %s-%d for side %c\n", codecName, samplingFreqHz,
side);
} else {
printf("Registering %s for side %c\n", codecName, side);
}
}
std::cout << std::flush;
AudioCodingModule* myACM;
switch (side) {
@ -430,13 +233,11 @@ int16_t TestFEC::RegisterSendCodec(char side, char* codecName,
return -1;
}
CodecInst myCodecParam;
EXPECT_GT(AudioCodingModule::Codec(codecName, &myCodecParam,
samplingFreqHz, 1), -1);
EXPECT_GT(myACM->RegisterSendCodec(myCodecParam), -1);
CHECK_ERROR(
AudioCodingModule::Codec(codecName, &myCodecParam, samplingFreqHz, 1));
CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam));
// initialization was succesful
// Initialization was successful.
return 0;
}
@ -448,25 +249,22 @@ void TestFEC::Run() {
int32_t outFreqHzB = _outFileB.SamplingFrequency();
while (!_inFileA.EndOfFile()) {
_inFileA.Read10MsData(audioFrame);
CHECK_ERROR(_acmA->Add10MsData(audioFrame));
CHECK_ERROR(_acmA->Process());
CHECK_ERROR(_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
EXPECT_GT(_acmA->Process(), -1);
EXPECT_EQ(0, _acmB->PlayoutData10Ms(outFreqHzB, &audioFrame));
_outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_);
msecPassed += 10;
if (msecPassed >= 1000) {
msecPassed = 0;
secPassed++;
}
// Test that toggling FEC on and off works.
if (((secPassed % 5) == 4) && (msecPassed == 0) && (_testCntr > 14)) {
printf("%3u:%3u ", secPassed, msecPassed);
_acmA->SetFECStatus(false);
printf("FEC currently %s\n", (_acmA->FECStatus() ? "ON" : "OFF"));
EXPECT_EQ(0, _acmA->SetFECStatus(false));
}
if (((secPassed % 5) == 4) && (msecPassed >= 990) && (_testCntr > 14)) {
printf("%3u:%3u ", secPassed, msecPassed);
_acmA->SetFECStatus(true);
printf("FEC currently %s\n", (_acmA->FECStatus() ? "ON" : "OFF"));
EXPECT_EQ(0, _acmA->SetFECStatus(true));
}
}
_inFileA.Rewind();
@ -476,22 +274,10 @@ void TestFEC::OpenOutFile(int16_t test_number) {
std::string file_name;
std::stringstream file_stream;
file_stream << webrtc::test::OutputPath();
if (_testMode == 0) {
file_stream << "TestFEC_autoFile_";
} else {
file_stream << "TestFEC_outFile_";
}
file_stream << "TestFEC_outFile_";
file_stream << test_number << ".pcm";
file_name = file_stream.str();
_outFileB.Open(file_name, 16000, "wb");
}
void TestFEC::DisplaySendReceiveCodec() {
CodecInst myCodecParam;
_acmA->SendCodec(&myCodecParam);
printf("%s -> ", myCodecParam.plname);
_acmB->ReceiveCodec(&myCodecParam);
printf("%s\n", myCodecParam.plname);
}
} // namespace webrtc