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