niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/main/test/TestVADDTX.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | #include <iostream> |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 14 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 15 | #include "webrtc/common_types.h" |
| 16 | #include "webrtc/engine_configurations.h" |
| 17 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h" |
| 18 | #include "webrtc/modules/audio_coding/main/test/utility.h" |
| 19 | #include "webrtc/modules/audio_coding/main/source/acm_common_defs.h" |
| 20 | #include "webrtc/test/testsupport/fileutils.h" |
| 21 | #include "webrtc/system_wrappers/interface/trace.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 23 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | TestVADDTX::TestVADDTX(int testMode): |
| 26 | _acmA(NULL), |
| 27 | _acmB(NULL), |
| 28 | _channelA2B(NULL), |
| 29 | _testResults(0) |
| 30 | { |
| 31 | //testMode == 1 for more extensive testing |
| 32 | //testMode == 0 for quick test (autotest) |
| 33 | _testMode = testMode; |
| 34 | } |
| 35 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | TestVADDTX::~TestVADDTX() |
| 37 | { |
| 38 | if(_acmA != NULL) |
| 39 | { |
| 40 | AudioCodingModule::Destroy(_acmA); |
| 41 | _acmA = NULL; |
| 42 | } |
| 43 | if(_acmB != NULL) |
| 44 | { |
| 45 | AudioCodingModule::Destroy(_acmB); |
| 46 | _acmB = NULL; |
| 47 | } |
| 48 | if(_channelA2B != NULL) |
| 49 | { |
| 50 | delete _channelA2B; |
| 51 | _channelA2B = NULL; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void TestVADDTX::Perform() |
| 56 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | if(_testMode == 0) |
| 58 | { |
| 59 | printf("Running VAD/DTX Test"); |
| 60 | WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1, |
| 61 | "---------- TestVADDTX ----------"); |
| 62 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 63 | |
| 64 | const std::string file_name = |
| 65 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
| 66 | _inFileA.Open(file_name, 32000, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
| 68 | _acmA = AudioCodingModule::Create(0); |
| 69 | _acmB = AudioCodingModule::Create(1); |
| 70 | |
| 71 | _acmA->InitializeReceiver(); |
| 72 | _acmB->InitializeReceiver(); |
| 73 | |
| 74 | WebRtc_UWord8 numEncoders = _acmA->NumberOfCodecs(); |
| 75 | CodecInst myCodecParam; |
| 76 | if(_testMode != 0) |
| 77 | { |
| 78 | printf("Registering codecs at receiver... \n"); |
| 79 | } |
| 80 | for(WebRtc_UWord8 n = 0; n < numEncoders; n++) |
| 81 | { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 82 | _acmB->Codec(n, &myCodecParam); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | if(_testMode != 0) |
| 84 | { |
| 85 | printf("%s\n", myCodecParam.plname); |
| 86 | } |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 87 | if (!strcmp(myCodecParam.plname, "opus")) { |
| 88 | // Use mono decoding for Opus in the VAD/DTX test. |
| 89 | myCodecParam.channels = 1; |
| 90 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | _acmB->RegisterReceiveCodec(myCodecParam); |
| 92 | } |
| 93 | |
| 94 | // Create and connect the channel |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 95 | _channelA2B = new Channel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | _acmA->RegisterTransportCallback(_channelA2B); |
| 97 | _channelA2B->RegisterReceiverACM(_acmB); |
| 98 | |
| 99 | _acmA->RegisterVADCallback(&_monitor); |
| 100 | |
| 101 | |
| 102 | WebRtc_Word16 testCntr = 1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | WebRtc_Word16 testResults = 0; |
| 104 | |
| 105 | #ifdef WEBRTC_CODEC_ISAC |
| 106 | // Open outputfile |
| 107 | OpenOutFile(testCntr++); |
| 108 | |
| 109 | // Register iSAC WB as send codec |
| 110 | char nameISAC[] = "ISAC"; |
| 111 | RegisterSendCodec('A', nameISAC, 16000); |
| 112 | |
| 113 | // Run the five test cased |
| 114 | runTestCases(); |
| 115 | |
| 116 | // Close file |
| 117 | _outFileB.Close(); |
| 118 | |
| 119 | // Open outputfile |
| 120 | OpenOutFile(testCntr++); |
| 121 | |
| 122 | // Register iSAC SWB as send codec |
| 123 | RegisterSendCodec('A', nameISAC, 32000); |
| 124 | |
| 125 | // Run the five test cased |
| 126 | runTestCases(); |
| 127 | |
| 128 | // Close file |
| 129 | _outFileB.Close(); |
| 130 | #endif |
| 131 | #ifdef WEBRTC_CODEC_ILBC |
| 132 | // Open outputfile |
| 133 | OpenOutFile(testCntr++); |
| 134 | |
| 135 | // Register iLBC as send codec |
| 136 | char nameILBC[] = "ilbc"; |
| 137 | RegisterSendCodec('A', nameILBC); |
| 138 | |
| 139 | // Run the five test cased |
| 140 | runTestCases(); |
| 141 | |
| 142 | // Close file |
| 143 | _outFileB.Close(); |
| 144 | |
| 145 | #endif |
tina.legrand@webrtc.org | a7d8387 | 2012-10-18 10:00:52 +0000 | [diff] [blame] | 146 | #ifdef WEBRTC_CODEC_OPUS |
| 147 | // Open outputfile |
| 148 | OpenOutFile(testCntr++); |
| 149 | |
| 150 | // Register Opus as send codec |
| 151 | char nameOPUS[] = "opus"; |
| 152 | RegisterSendCodec('A', nameOPUS); |
| 153 | |
| 154 | // Run the five test cased |
| 155 | runTestCases(); |
| 156 | |
| 157 | // Close file |
| 158 | _outFileB.Close(); |
| 159 | |
| 160 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | if(_testMode) { |
| 162 | printf("Done!\n"); |
| 163 | } |
| 164 | |
| 165 | printf("VAD/DTX test completed with %d subtests failed\n", testResults); |
| 166 | if (testResults > 0) |
| 167 | { |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 168 | printf("Press return\n\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | getchar(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | void TestVADDTX::runTestCases() |
| 174 | { |
| 175 | if(_testMode != 0) |
| 176 | { |
| 177 | CodecInst myCodecParam; |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 178 | _acmA->SendCodec(&myCodecParam); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | printf("%s\n", myCodecParam.plname); |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | printf("."); |
| 184 | } |
| 185 | // #1 DTX = OFF, VAD = ON, VADNormal |
| 186 | if(_testMode != 0) |
| 187 | printf("Test #1 "); |
| 188 | SetVAD(false, true, VADNormal); |
| 189 | Run(); |
| 190 | _testResults += VerifyTest(); |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 191 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | // #2 DTX = OFF, VAD = ON, VADAggr |
| 193 | if(_testMode != 0) |
| 194 | printf("Test #2 "); |
| 195 | SetVAD(false, true, VADAggr); |
| 196 | Run(); |
| 197 | _testResults += VerifyTest(); |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 198 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | // #3 DTX = ON, VAD = ON, VADLowBitrate |
| 200 | if(_testMode != 0) |
| 201 | printf("Test #3 "); |
| 202 | SetVAD(true, true, VADLowBitrate); |
| 203 | Run(); |
| 204 | _testResults += VerifyTest(); |
| 205 | |
| 206 | // #4 DTX = ON, VAD = ON, VADVeryAggr |
| 207 | if(_testMode != 0) |
| 208 | printf("Test #4 "); |
| 209 | SetVAD(true, true, VADVeryAggr); |
| 210 | Run(); |
| 211 | _testResults += VerifyTest(); |
| 212 | |
| 213 | // #5 DTX = ON, VAD = OFF, VADNormal |
| 214 | if(_testMode != 0) |
| 215 | printf("Test #5 "); |
| 216 | SetVAD(true, false, VADNormal); |
| 217 | Run(); |
| 218 | _testResults += VerifyTest(); |
| 219 | |
| 220 | } |
| 221 | void TestVADDTX::runTestInternalDTX() |
| 222 | { |
| 223 | // #6 DTX = ON, VAD = ON, VADNormal |
| 224 | if(_testMode != 0) |
| 225 | printf("Test #6 "); |
| 226 | |
| 227 | SetVAD(true, true, VADNormal); |
| 228 | if(_acmA->ReplaceInternalDTXWithWebRtc(true) < 0) { |
| 229 | printf("Was not able to replace DTX since CN was not registered\n"); |
| 230 | } |
| 231 | Run(); |
| 232 | _testResults += VerifyTest(); |
| 233 | } |
| 234 | |
| 235 | void TestVADDTX::SetVAD(bool statusDTX, bool statusVAD, WebRtc_Word16 vadMode) |
| 236 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 237 | bool dtxEnabled, vadEnabled; |
| 238 | ACMVADMode vadModeSet; |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 239 | |
| 240 | if (_acmA->SetVAD(statusDTX, statusVAD, (ACMVADMode) vadMode) < 0) { |
| 241 | assert(false); |
| 242 | } |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 243 | if (_acmA->VAD(&dtxEnabled, &vadEnabled, &vadModeSet) < 0) { |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 244 | assert(false); |
| 245 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 246 | |
| 247 | if(_testMode != 0) |
| 248 | { |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 249 | if(statusDTX != dtxEnabled) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | { |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 251 | printf("DTX: %s not the same as requested: %s\n", |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 252 | dtxEnabled? "ON":"OFF", dtxEnabled? "OFF":"ON"); |
| 253 | } |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 254 | if(((statusVAD == true) && (vadEnabled == false)) || |
| 255 | ((statusVAD == false) && (vadEnabled == false) && |
| 256 | (statusDTX == true))) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 257 | { |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 258 | printf("VAD: %s not the same as requested: %s\n", |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 259 | vadEnabled? "ON":"OFF", vadEnabled? "OFF":"ON"); |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 260 | } |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 261 | if(vadModeSet != vadMode) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 262 | { |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 263 | printf("VAD mode: %d not the same as requested: %d\n", |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 264 | (WebRtc_Word16)vadModeSet, (WebRtc_Word16)vadMode); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // Requested VAD/DTX settings |
| 269 | _setStruct.statusDTX = statusDTX; |
| 270 | _setStruct.statusVAD = statusVAD; |
| 271 | _setStruct.vadMode = (ACMVADMode) vadMode; |
| 272 | |
| 273 | // VAD settings after setting VAD in ACM |
| 274 | _getStruct.statusDTX = dtxEnabled; |
| 275 | _getStruct.statusVAD = vadEnabled; |
| 276 | _getStruct.vadMode = vadModeSet; |
| 277 | |
| 278 | } |
| 279 | |
| 280 | VADDTXstruct TestVADDTX::GetVAD() |
| 281 | { |
| 282 | VADDTXstruct retStruct; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 283 | bool dtxEnabled, vadEnabled; |
| 284 | ACMVADMode vadModeSet; |
| 285 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 286 | if (_acmA->VAD(&dtxEnabled, &vadEnabled, &vadModeSet) < 0) { |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 287 | assert(false); |
| 288 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 289 | |
| 290 | retStruct.statusDTX = dtxEnabled; |
| 291 | retStruct.statusVAD = vadEnabled; |
| 292 | retStruct.vadMode = vadModeSet; |
| 293 | return retStruct; |
| 294 | } |
| 295 | |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 296 | WebRtc_Word16 TestVADDTX::RegisterSendCodec(char side, |
| 297 | char* codecName, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 298 | WebRtc_Word32 samplingFreqHz, |
| 299 | WebRtc_Word32 rateKbps) |
| 300 | { |
| 301 | if(_testMode != 0) |
| 302 | { |
| 303 | printf("Registering %s for side %c\n", codecName, side); |
| 304 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 305 | std::cout << std::flush; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 306 | AudioCodingModule* myACM; |
| 307 | switch(side) |
| 308 | { |
| 309 | case 'A': |
| 310 | { |
| 311 | myACM = _acmA; |
| 312 | break; |
| 313 | } |
| 314 | case 'B': |
| 315 | { |
| 316 | myACM = _acmB; |
| 317 | break; |
| 318 | } |
| 319 | default: |
| 320 | return -1; |
| 321 | } |
| 322 | |
| 323 | if(myACM == NULL) |
| 324 | { |
| 325 | return -1; |
| 326 | } |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 327 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 328 | CodecInst myCodecParam; |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 329 | for(WebRtc_Word16 codecCntr = 0; codecCntr < myACM->NumberOfCodecs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | codecCntr++) |
| 331 | { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 332 | CHECK_ERROR(myACM->Codec((WebRtc_UWord8)codecCntr, &myCodecParam)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 333 | if(!STR_CASE_CMP(myCodecParam.plname, codecName)) |
| 334 | { |
| 335 | if((samplingFreqHz == -1) || (myCodecParam.plfreq == samplingFreqHz)) |
| 336 | { |
| 337 | if((rateKbps == -1) || (myCodecParam.rate == rateKbps)) |
| 338 | { |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
tina.legrand@webrtc.org | c459058 | 2012-11-28 12:23:29 +0000 | [diff] [blame] | 345 | // We only allow VAD/DTX when sending mono. |
| 346 | myCodecParam.channels = 1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam)); |
| 348 | |
| 349 | // initialization was succesful |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | void TestVADDTX::Run() |
| 354 | { |
| 355 | AudioFrame audioFrame; |
| 356 | |
| 357 | WebRtc_UWord16 SamplesIn10MsecA = _inFileA.PayloadLength10Ms(); |
| 358 | WebRtc_UWord32 timestampA = 1; |
| 359 | WebRtc_Word32 outFreqHzB = _outFileB.SamplingFrequency(); |
| 360 | |
| 361 | while(!_inFileA.EndOfFile()) |
| 362 | { |
| 363 | _inFileA.Read10MsData(audioFrame); |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 364 | audioFrame.timestamp_ = timestampA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 365 | timestampA += SamplesIn10MsecA; |
| 366 | CHECK_ERROR(_acmA->Add10MsData(audioFrame)); |
| 367 | |
| 368 | CHECK_ERROR(_acmA->Process()); |
| 369 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 370 | CHECK_ERROR(_acmB->PlayoutData10Ms(outFreqHzB, &audioFrame)); |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 371 | _outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 372 | } |
| 373 | #ifdef PRINT_STAT |
| 374 | _monitor.PrintStatistics(_testMode); |
| 375 | #endif |
| 376 | _inFileA.Rewind(); |
| 377 | _monitor.GetStatistics(_statCounter); |
| 378 | _monitor.ResetStatistics(); |
| 379 | } |
| 380 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 381 | void TestVADDTX::OpenOutFile(WebRtc_Word16 test_number) { |
| 382 | std::string file_name; |
| 383 | std::stringstream file_stream; |
| 384 | file_stream << webrtc::test::OutputPath(); |
| 385 | if (_testMode == 0) { |
| 386 | file_stream << "testVADDTX_autoFile_"; |
| 387 | } else { |
| 388 | file_stream << "testVADDTX_outFile_"; |
| 389 | } |
| 390 | file_stream << test_number << ".pcm"; |
| 391 | file_name = file_stream.str(); |
| 392 | _outFileB.Open(file_name, 16000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
| 396 | WebRtc_Word16 TestVADDTX::VerifyTest() |
| 397 | { |
| 398 | // Verify empty frame result |
| 399 | WebRtc_UWord8 statusEF = 0; |
| 400 | WebRtc_UWord8 vadPattern = 0; |
| 401 | WebRtc_UWord8 emptyFramePattern[6]; |
| 402 | CodecInst myCodecParam; |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 403 | _acmA->SendCodec(&myCodecParam); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 404 | bool dtxInUse = true; |
| 405 | bool isReplaced = false; |
| 406 | if ((STR_CASE_CMP(myCodecParam.plname,"G729") == 0) || |
| 407 | (STR_CASE_CMP(myCodecParam.plname,"G723") == 0) || |
| 408 | (STR_CASE_CMP(myCodecParam.plname,"AMR") == 0) || |
| 409 | (STR_CASE_CMP(myCodecParam.plname,"AMR-wb") == 0) || |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 410 | (STR_CASE_CMP(myCodecParam.plname,"speex") == 0)) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 411 | { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 412 | _acmA->IsInternalDTXReplacedWithWebRtc(&isReplaced); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 413 | if (!isReplaced) |
| 414 | { |
| 415 | dtxInUse = false; |
| 416 | } |
| 417 | } |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 418 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 419 | // Check for error in VAD/DTX settings |
| 420 | if (_getStruct.statusDTX != _setStruct.statusDTX){ |
| 421 | // DTX status doesn't match expected |
| 422 | vadPattern |= 4; |
| 423 | } |
| 424 | if (_getStruct.statusDTX){ |
| 425 | if ((!_getStruct.statusVAD && dtxInUse) || (!dtxInUse && (_getStruct.statusVAD !=_setStruct.statusVAD))) |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 426 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 427 | // Missmatch in VAD setting |
| 428 | vadPattern |= 2; |
| 429 | } |
| 430 | } else { |
| 431 | if (_getStruct.statusVAD != _setStruct.statusVAD){ |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 432 | // VAD status doesn't match expected |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 433 | vadPattern |= 2; |
| 434 | } |
| 435 | } |
| 436 | if (_getStruct.vadMode != _setStruct.vadMode){ |
| 437 | // VAD Mode doesn't match expected |
| 438 | vadPattern |= 1; |
| 439 | } |
| 440 | |
| 441 | // Set expected empty frame pattern |
| 442 | int ii; |
| 443 | for (ii = 0; ii < 6; ii++) { |
| 444 | emptyFramePattern[ii] = 0; |
| 445 | } |
| 446 | emptyFramePattern[0] = 1; // "kNoEncoding", not important to check. Codecs with packetsize != 80 samples will get this output. |
| 447 | emptyFramePattern[1] = 1; // Expect to always receive some frames labeled "kActiveNormalEncoded" |
| 448 | emptyFramePattern[2] = (((!_getStruct.statusDTX && _getStruct.statusVAD) || (!dtxInUse && _getStruct.statusDTX))); // "kPassiveNormalEncoded" |
| 449 | emptyFramePattern[3] = ((_getStruct.statusDTX && dtxInUse && (_acmA->SendFrequency() == 8000))); // "kPassiveDTXNB" |
| 450 | emptyFramePattern[4] = ((_getStruct.statusDTX && dtxInUse && (_acmA->SendFrequency() == 16000))); // "kPassiveDTXWB" |
| 451 | emptyFramePattern[5] = ((_getStruct.statusDTX && dtxInUse && (_acmA->SendFrequency() == 32000))); // "kPassiveDTXSWB" |
| 452 | |
| 453 | // Check pattern 1-5 (skip 0) |
| 454 | for (int ii = 1; ii < 6; ii++) |
| 455 | { |
| 456 | if (emptyFramePattern[ii]) |
| 457 | { |
| 458 | statusEF |= (_statCounter[ii] == 0); |
| 459 | } |
| 460 | else |
| 461 | { |
| 462 | statusEF |= (_statCounter[ii] > 0); |
| 463 | } |
| 464 | } |
| 465 | if ((statusEF == 0) && (vadPattern == 0)) |
| 466 | { |
| 467 | if(_testMode != 0) |
| 468 | { |
| 469 | printf(" Test OK!\n"); |
| 470 | } |
| 471 | return 0; |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | if (statusEF) |
| 476 | { |
| 477 | printf("\t\t\tUnexpected empty frame result!\n"); |
| 478 | } |
| 479 | if (vadPattern) |
| 480 | { |
| 481 | printf("\t\t\tUnexpected SetVAD() result!\tDTX: %d\tVAD: %d\tMode: %d\n", (vadPattern >> 2) & 1, (vadPattern >> 1) & 1, vadPattern & 1); |
| 482 | } |
| 483 | return 1; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | ActivityMonitor::ActivityMonitor() |
| 488 | { |
| 489 | _counter[0] = _counter[1] = _counter[2] = _counter[3] = _counter[4] = _counter[5] = 0; |
| 490 | } |
| 491 | |
| 492 | ActivityMonitor::~ActivityMonitor() |
| 493 | { |
| 494 | } |
| 495 | |
| 496 | WebRtc_Word32 ActivityMonitor::InFrameType(WebRtc_Word16 frameType) |
| 497 | { |
| 498 | _counter[frameType]++; |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | void ActivityMonitor::PrintStatistics(int testMode) |
| 503 | { |
| 504 | if(testMode != 0) |
| 505 | { |
| 506 | printf("\n"); |
| 507 | printf("kActiveNormalEncoded kPassiveNormalEncoded kPassiveDTXWB kPassiveDTXNB kPassiveDTXSWB kFrameEmpty\n"); |
| 508 | |
| 509 | printf("%19u", _counter[1]); |
| 510 | printf("%22u", _counter[2]); |
| 511 | printf("%14u", _counter[3]); |
| 512 | printf("%14u", _counter[4]); |
| 513 | printf("%14u", _counter[5]); |
| 514 | printf("%11u", _counter[0]); |
| 515 | |
| 516 | printf("\n\n"); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | void ActivityMonitor::ResetStatistics() |
| 521 | { |
| 522 | _counter[0] = _counter[1] = _counter[2] = _counter[3] = _counter[4] = _counter[5] = 0; |
| 523 | } |
| 524 | |
| 525 | void ActivityMonitor::GetStatistics(WebRtc_UWord32* getCounter) |
| 526 | { |
| 527 | for (int ii = 0; ii < 6; ii++) |
| 528 | { |
| 529 | getCounter[ii] = _counter[ii]; |
| 530 | } |
| 531 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 532 | |
| 533 | } // namespace webrtc |