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