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