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