1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_coding/main/test/TestRedFec.h"
#include <assert.h>
#include "webrtc/common.h"
#include "webrtc/common_types.h"
#include "webrtc/engine_configurations.h"
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
#include "webrtc/modules/audio_coding/main/test/utility.h"
#include "webrtc/system_wrappers/interface/trace.h"
#include "webrtc/test/testsupport/fileutils.h"
namespace webrtc {
TestRedFec::TestRedFec()
: _acmA(AudioCodingModule::Create(0)),
_acmB(AudioCodingModule::Create(1)),
_channelA2B(NULL),
_testCntr(0) {
}
TestRedFec::~TestRedFec() {
if (_channelA2B != NULL) {
delete _channelA2B;
_channelA2B = NULL;
}
}
void TestRedFec::Perform() {
const std::string file_name = webrtc::test::ResourcePath(
"audio_coding/testfile32kHz", "pcm");
_inFileA.Open(file_name, 32000, "rb");
ASSERT_EQ(0, _acmA->InitializeReceiver());
ASSERT_EQ(0, _acmB->InitializeReceiver());
uint8_t numEncoders = _acmA->NumberOfCodecs();
CodecInst myCodecParam;
for (uint8_t n = 0; n < numEncoders; n++) {
EXPECT_EQ(0, _acmB->Codec(n, &myCodecParam));
// Default number of channels is 2 for opus, so we change to 1 in this test.
if (!strcmp(myCodecParam.plname, "opus")) {
myCodecParam.channels = 1;
}
EXPECT_EQ(0, _acmB->RegisterReceiveCodec(myCodecParam));
}
// Create and connect the channel
_channelA2B = new Channel;
_acmA->RegisterTransportCallback(_channelA2B);
_channelA2B->RegisterReceiverACM(_acmB.get());
#ifndef WEBRTC_CODEC_G722
EXPECT_TRUE(false);
printf("G722 needs to be activated to run this test\n");
return;
#endif
char nameG722[] = "G722";
EXPECT_EQ(0, RegisterSendCodec('A', nameG722, 16000));
char nameCN[] = "CN";
EXPECT_EQ(0, RegisterSendCodec('A', nameCN, 16000));
char nameRED[] = "RED";
EXPECT_EQ(0, RegisterSendCodec('A', nameRED));
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(true, true, VADAggr));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
EXPECT_FALSE(_acmA->REDStatus());
Run();
_outFileB.Close();
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
char nameISAC[] = "iSAC";
RegisterSendCodec('A', nameISAC, 16000);
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
EXPECT_FALSE(_acmA->REDStatus());
Run();
_outFileB.Close();
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
EXPECT_FALSE(_acmA->REDStatus());
Run();
_outFileB.Close();
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(false, false, VADNormal));
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
EXPECT_TRUE(_acmA->REDStatus());
Run();
RegisterSendCodec('A', nameISAC, 32000);
EXPECT_TRUE(_acmA->REDStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
EXPECT_TRUE(_acmA->REDStatus());
Run();
_outFileB.Close();
_channelA2B->SetFECTestWithPacketLoss(true);
EXPECT_EQ(0, RegisterSendCodec('A', nameG722));
EXPECT_EQ(0, RegisterSendCodec('A', nameCN, 16000));
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(true, true, VADAggr));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
EXPECT_FALSE(_acmA->REDStatus());
Run();
_outFileB.Close();
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 16000);
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
EXPECT_FALSE(_acmA->REDStatus());
Run();
_outFileB.Close();
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
EXPECT_FALSE(_acmA->REDStatus());
Run();
_outFileB.Close();
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
OpenOutFile(_testCntr);
Run();
_outFileB.Close();
RegisterSendCodec('A', nameISAC, 32000);
OpenOutFile(_testCntr);
EXPECT_EQ(0, SetVAD(false, false, VADNormal));
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
EXPECT_TRUE(_acmA->REDStatus());
Run();
RegisterSendCodec('A', nameISAC, 32000);
EXPECT_TRUE(_acmA->REDStatus());
Run();
RegisterSendCodec('A', nameISAC, 16000);
EXPECT_TRUE(_acmA->REDStatus());
Run();
_outFileB.Close();
#ifndef WEBRTC_CODEC_OPUS
EXPECT_TRUE(false);
printf("Opus needs to be activated to run this test\n");
return;
#endif
char nameOpus[] = "opus";
RegisterSendCodec('A', nameOpus, 48000);
EXPECT_TRUE(_acmA->REDStatus());
// _channelA2B imposes 25% packet loss rate.
EXPECT_EQ(0, _acmA->SetPacketLossRate(25));
// Codec FEC and RED are mutually exclusive.
EXPECT_EQ(-1, _acmA->SetCodecFEC(true));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
EXPECT_EQ(0, _acmA->SetCodecFEC(true));
// Codec FEC and RED are mutually exclusive.
EXPECT_EQ(-1, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->CodecFEC());
OpenOutFile(_testCntr);
Run();
// Switch to ISAC with RED.
RegisterSendCodec('A', nameISAC, 32000);
EXPECT_EQ(0, SetVAD(false, false, VADNormal));
// ISAC does not support FEC, so FEC should be turned off automatically.
EXPECT_FALSE(_acmA->CodecFEC());
EXPECT_EQ(0, _acmA->SetREDStatus(true));
EXPECT_TRUE(_acmA->REDStatus());
Run();
// Switch to Opus again.
RegisterSendCodec('A', nameOpus, 48000);
EXPECT_EQ(0, _acmA->SetCodecFEC(false));
EXPECT_EQ(0, _acmA->SetREDStatus(false));
Run();
EXPECT_EQ(0, _acmA->SetCodecFEC(true));
_outFileB.Close();
// Codecs does not support internal FEC, cannot enable FEC.
RegisterSendCodec('A', nameG722, 16000);
EXPECT_FALSE(_acmA->REDStatus());
EXPECT_EQ(-1, _acmA->SetCodecFEC(true));
EXPECT_FALSE(_acmA->CodecFEC());
RegisterSendCodec('A', nameISAC, 16000);
EXPECT_FALSE(_acmA->REDStatus());
EXPECT_EQ(-1, _acmA->SetCodecFEC(true));
EXPECT_FALSE(_acmA->CodecFEC());
// Codecs does not support internal FEC, disable FEC does not trigger failure.
RegisterSendCodec('A', nameG722, 16000);
EXPECT_FALSE(_acmA->REDStatus());
EXPECT_EQ(0, _acmA->SetCodecFEC(false));
EXPECT_FALSE(_acmA->CodecFEC());
RegisterSendCodec('A', nameISAC, 16000);
EXPECT_FALSE(_acmA->REDStatus());
EXPECT_EQ(0, _acmA->SetCodecFEC(false));
EXPECT_FALSE(_acmA->CodecFEC());
}
int32_t TestRedFec::SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode) {
return _acmA->SetVAD(enableDTX, enableVAD, vadMode);
}
int16_t TestRedFec::RegisterSendCodec(char side, char* codecName,
int32_t samplingFreqHz) {
std::cout << std::flush;
AudioCodingModule* myACM;
switch (side) {
case 'A': {
myACM = _acmA.get();
break;
}
case 'B': {
myACM = _acmB.get();
break;
}
default:
return -1;
}
if (myACM == NULL) {
assert(false);
return -1;
}
CodecInst myCodecParam;
EXPECT_GT(AudioCodingModule::Codec(codecName, &myCodecParam,
samplingFreqHz, 1), -1);
EXPECT_GT(myACM->RegisterSendCodec(myCodecParam), -1);
// Initialization was successful.
return 0;
}
void TestRedFec::Run() {
AudioFrame audioFrame;
uint16_t msecPassed = 0;
uint32_t secPassed = 0;
int32_t outFreqHzB = _outFileB.SamplingFrequency();
while (!_inFileA.EndOfFile()) {
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 RED on and off works.
if (((secPassed % 5) == 4) && (msecPassed == 0) && (_testCntr > 14)) {
EXPECT_EQ(0, _acmA->SetREDStatus(false));
}
if (((secPassed % 5) == 4) && (msecPassed >= 990) && (_testCntr > 14)) {
EXPECT_EQ(0, _acmA->SetREDStatus(true));
}
}
_inFileA.Rewind();
}
void TestRedFec::OpenOutFile(int16_t test_number) {
std::string file_name;
std::stringstream file_stream;
file_stream << webrtc::test::OutputPath();
file_stream << "TestRedFec_outFile_";
file_stream << test_number << ".pcm";
file_name = file_stream.str();
_outFileB.Open(file_name, 16000, "wb");
}
} // namespace webrtc
|