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