minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 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 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/test/TestRedFec.h" |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 12 | |
| 13 | #include <assert.h> |
| 14 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 15 | #include "webrtc/common_types.h" |
| 16 | #include "webrtc/engine_configurations.h" |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 17 | #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 18 | #include "webrtc/modules/audio_coding/test/utility.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/include/trace.h" |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 20 | #include "webrtc/test/testsupport/fileutils.h" |
| 21 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 22 | #ifdef SUPPORT_RED_WB |
| 23 | #undef SUPPORT_RED_WB |
| 24 | #endif |
| 25 | |
| 26 | #ifdef SUPPORT_RED_SWB |
| 27 | #undef SUPPORT_RED_SWB |
| 28 | #endif |
| 29 | |
| 30 | #ifdef SUPPORT_RED_FB |
| 31 | #undef SUPPORT_RED_FB |
| 32 | #endif |
| 33 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 34 | namespace webrtc { |
| 35 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 36 | namespace { |
| 37 | const char kNameL16[] = "L16"; |
| 38 | const char kNamePCMU[] = "PCMU"; |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 39 | const char kNameCN[] = "CN"; |
| 40 | const char kNameRED[] = "RED"; |
| 41 | |
| 42 | // These three are only used by code #ifdeffed on WEBRTC_CODEC_G722. |
| 43 | #ifdef WEBRTC_CODEC_G722 |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 44 | const char kNameISAC[] = "ISAC"; |
| 45 | const char kNameG722[] = "G722"; |
| 46 | const char kNameOPUS[] = "opus"; |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 47 | #endif |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 48 | } |
| 49 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 50 | TestRedFec::TestRedFec() |
| 51 | : _acmA(AudioCodingModule::Create(0)), |
| 52 | _acmB(AudioCodingModule::Create(1)), |
| 53 | _channelA2B(NULL), |
| 54 | _testCntr(0) { |
| 55 | } |
| 56 | |
| 57 | TestRedFec::~TestRedFec() { |
| 58 | if (_channelA2B != NULL) { |
| 59 | delete _channelA2B; |
| 60 | _channelA2B = NULL; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void TestRedFec::Perform() { |
| 65 | const std::string file_name = webrtc::test::ResourcePath( |
| 66 | "audio_coding/testfile32kHz", "pcm"); |
| 67 | _inFileA.Open(file_name, 32000, "rb"); |
| 68 | |
| 69 | ASSERT_EQ(0, _acmA->InitializeReceiver()); |
| 70 | ASSERT_EQ(0, _acmB->InitializeReceiver()); |
| 71 | |
| 72 | uint8_t numEncoders = _acmA->NumberOfCodecs(); |
| 73 | CodecInst myCodecParam; |
| 74 | for (uint8_t n = 0; n < numEncoders; n++) { |
| 75 | EXPECT_EQ(0, _acmB->Codec(n, &myCodecParam)); |
| 76 | // Default number of channels is 2 for opus, so we change to 1 in this test. |
| 77 | if (!strcmp(myCodecParam.plname, "opus")) { |
| 78 | myCodecParam.channels = 1; |
| 79 | } |
| 80 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(myCodecParam)); |
| 81 | } |
| 82 | |
| 83 | // Create and connect the channel |
| 84 | _channelA2B = new Channel; |
| 85 | _acmA->RegisterTransportCallback(_channelA2B); |
| 86 | _channelA2B->RegisterReceiverACM(_acmB.get()); |
| 87 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 88 | EXPECT_EQ(0, RegisterSendCodec('A', kNameL16, 8000)); |
| 89 | EXPECT_EQ(0, RegisterSendCodec('A', kNameCN, 8000)); |
| 90 | EXPECT_EQ(0, RegisterSendCodec('A', kNameRED)); |
| 91 | EXPECT_EQ(0, SetVAD(true, true, VADAggr)); |
| 92 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 93 | EXPECT_TRUE(_acmA->REDStatus()); |
| 94 | |
| 95 | OpenOutFile(_testCntr); |
| 96 | Run(); |
| 97 | _outFileB.Close(); |
| 98 | |
| 99 | RegisterSendCodec('A', kNamePCMU, 8000); |
| 100 | // Switch to another 8 kHz codec, RED should remain switched on. |
| 101 | EXPECT_TRUE(_acmA->REDStatus()); |
| 102 | OpenOutFile(_testCntr); |
| 103 | Run(); |
| 104 | _outFileB.Close(); |
| 105 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 106 | #ifndef WEBRTC_CODEC_G722 |
| 107 | EXPECT_TRUE(false); |
| 108 | printf("G722 needs to be activated to run this test\n"); |
| 109 | return; |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 110 | #else |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 111 | EXPECT_EQ(0, RegisterSendCodec('A', kNameG722, 16000)); |
| 112 | EXPECT_EQ(0, RegisterSendCodec('A', kNameCN, 16000)); |
| 113 | |
| 114 | #ifdef SUPPORT_RED_WB |
| 115 | // Switch codec, RED should remain. |
| 116 | EXPECT_TRUE(_acmA->REDStatus()); |
| 117 | #else |
| 118 | // Switch to a 16 kHz codec, RED should have been switched off. |
| 119 | EXPECT_FALSE(_acmA->REDStatus()); |
| 120 | #endif |
| 121 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 122 | OpenOutFile(_testCntr); |
| 123 | EXPECT_EQ(0, SetVAD(true, true, VADAggr)); |
| 124 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
| 125 | EXPECT_FALSE(_acmA->REDStatus()); |
| 126 | Run(); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 127 | #ifdef SUPPORT_RED_WB |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 128 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 129 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 130 | #else |
| 131 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 132 | EXPECT_FALSE(_acmA->REDStatus()); |
| 133 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 134 | Run(); |
| 135 | _outFileB.Close(); |
| 136 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 137 | RegisterSendCodec('A', kNameISAC, 16000); |
| 138 | |
| 139 | #ifdef SUPPORT_RED_WB |
| 140 | // Switch codec, RED should remain. |
| 141 | EXPECT_TRUE(_acmA->REDStatus()); |
| 142 | #else |
| 143 | EXPECT_FALSE(_acmA->REDStatus()); |
| 144 | #endif |
| 145 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 146 | OpenOutFile(_testCntr); |
| 147 | EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr)); |
| 148 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
| 149 | EXPECT_FALSE(_acmA->REDStatus()); |
| 150 | Run(); |
| 151 | _outFileB.Close(); |
| 152 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 153 | #ifdef SUPPORT_RED_WB |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 154 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 155 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 156 | #else |
| 157 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 158 | EXPECT_FALSE(_acmA->REDStatus()); |
| 159 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 160 | OpenOutFile(_testCntr); |
| 161 | Run(); |
| 162 | _outFileB.Close(); |
| 163 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 164 | RegisterSendCodec('A', kNameISAC, 32000); |
| 165 | |
| 166 | #if defined(SUPPORT_RED_SWB) && defined(SUPPORT_RED_WB) |
| 167 | // Switch codec, RED should remain. |
| 168 | EXPECT_TRUE(_acmA->REDStatus()); |
| 169 | #else |
| 170 | // Switch to a 32 kHz codec, RED should have been switched off. |
| 171 | EXPECT_FALSE(_acmA->REDStatus()); |
| 172 | #endif |
| 173 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 174 | OpenOutFile(_testCntr); |
| 175 | EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr)); |
| 176 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
| 177 | EXPECT_FALSE(_acmA->REDStatus()); |
| 178 | Run(); |
| 179 | _outFileB.Close(); |
| 180 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 181 | #ifdef SUPPORT_RED_SWB |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 182 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 183 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 184 | #else |
| 185 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 186 | EXPECT_FALSE(_acmA->REDStatus()); |
| 187 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 188 | OpenOutFile(_testCntr); |
| 189 | Run(); |
| 190 | _outFileB.Close(); |
| 191 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 192 | RegisterSendCodec('A', kNameISAC, 32000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 193 | EXPECT_EQ(0, SetVAD(false, false, VADNormal)); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 194 | |
| 195 | #if defined(SUPPORT_RED_SWB) && defined(SUPPORT_RED_WB) |
| 196 | OpenOutFile(_testCntr); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 197 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 198 | EXPECT_TRUE(_acmA->REDStatus()); |
| 199 | Run(); |
| 200 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 201 | RegisterSendCodec('A', kNameISAC, 16000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 202 | EXPECT_TRUE(_acmA->REDStatus()); |
| 203 | Run(); |
| 204 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 205 | RegisterSendCodec('A', kNameISAC, 32000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 206 | EXPECT_TRUE(_acmA->REDStatus()); |
| 207 | Run(); |
| 208 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 209 | RegisterSendCodec('A', kNameISAC, 16000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 210 | EXPECT_TRUE(_acmA->REDStatus()); |
| 211 | Run(); |
| 212 | _outFileB.Close(); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 213 | #else |
| 214 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 215 | EXPECT_FALSE(_acmA->REDStatus()); |
| 216 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 217 | |
| 218 | _channelA2B->SetFECTestWithPacketLoss(true); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 219 | // Following tests are under packet losses. |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 220 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 221 | EXPECT_EQ(0, RegisterSendCodec('A', kNameG722)); |
| 222 | EXPECT_EQ(0, RegisterSendCodec('A', kNameCN, 16000)); |
| 223 | |
| 224 | #if defined(SUPPORT_RED_WB) && defined(SUPPORT_RED_SWB) |
| 225 | // Switch codec, RED should remain. |
| 226 | EXPECT_TRUE(_acmA->REDStatus()); |
| 227 | #else |
| 228 | // Switch to a 16 kHz codec, RED should have been switched off. |
| 229 | EXPECT_FALSE(_acmA->REDStatus()); |
| 230 | #endif |
| 231 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 232 | OpenOutFile(_testCntr); |
| 233 | EXPECT_EQ(0, SetVAD(true, true, VADAggr)); |
| 234 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
| 235 | EXPECT_FALSE(_acmA->REDStatus()); |
| 236 | Run(); |
| 237 | _outFileB.Close(); |
| 238 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 239 | #ifdef SUPPORT_RED_WB |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 240 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 241 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 242 | #else |
| 243 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 244 | EXPECT_FALSE(_acmA->REDStatus()); |
| 245 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 246 | OpenOutFile(_testCntr); |
| 247 | Run(); |
| 248 | _outFileB.Close(); |
| 249 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 250 | RegisterSendCodec('A', kNameISAC, 16000); |
| 251 | |
| 252 | #ifdef SUPPORT_RED_WB |
| 253 | // Switch codec, RED should remain. |
| 254 | EXPECT_TRUE(_acmA->REDStatus()); |
| 255 | #else |
| 256 | // Switch to a 16 kHz codec, RED should have been switched off. |
| 257 | EXPECT_FALSE(_acmA->REDStatus()); |
| 258 | #endif |
| 259 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 260 | OpenOutFile(_testCntr); |
| 261 | EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr)); |
| 262 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
| 263 | EXPECT_FALSE(_acmA->REDStatus()); |
| 264 | Run(); |
| 265 | _outFileB.Close(); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 266 | #ifdef SUPPORT_RED_WB |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 267 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 268 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 269 | #else |
| 270 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 271 | EXPECT_FALSE(_acmA->REDStatus()); |
| 272 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 273 | OpenOutFile(_testCntr); |
| 274 | Run(); |
| 275 | _outFileB.Close(); |
| 276 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 277 | RegisterSendCodec('A', kNameISAC, 32000); |
| 278 | |
| 279 | #if defined(SUPPORT_RED_SWB) && defined(SUPPORT_RED_WB) |
| 280 | // Switch codec, RED should remain. |
| 281 | EXPECT_TRUE(_acmA->REDStatus()); |
| 282 | #else |
| 283 | // Switch to a 32 kHz codec, RED should have been switched off. |
| 284 | EXPECT_FALSE(_acmA->REDStatus()); |
| 285 | #endif |
| 286 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 287 | OpenOutFile(_testCntr); |
| 288 | EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr)); |
| 289 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
| 290 | EXPECT_FALSE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 291 | #ifdef SUPPORT_RED_SWB |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 292 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 293 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 294 | #else |
| 295 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 296 | EXPECT_FALSE(_acmA->REDStatus()); |
| 297 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 298 | OpenOutFile(_testCntr); |
| 299 | Run(); |
| 300 | _outFileB.Close(); |
| 301 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 302 | RegisterSendCodec('A', kNameISAC, 32000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 303 | EXPECT_EQ(0, SetVAD(false, false, VADNormal)); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 304 | #if defined(SUPPORT_RED_SWB) && defined(SUPPORT_RED_WB) |
| 305 | OpenOutFile(_testCntr); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 306 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 307 | EXPECT_TRUE(_acmA->REDStatus()); |
| 308 | Run(); |
| 309 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 310 | RegisterSendCodec('A', kNameISAC, 16000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 311 | EXPECT_TRUE(_acmA->REDStatus()); |
| 312 | Run(); |
| 313 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 314 | RegisterSendCodec('A', kNameISAC, 32000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 315 | EXPECT_TRUE(_acmA->REDStatus()); |
| 316 | Run(); |
| 317 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 318 | RegisterSendCodec('A', kNameISAC, 16000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 319 | EXPECT_TRUE(_acmA->REDStatus()); |
| 320 | Run(); |
| 321 | _outFileB.Close(); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 322 | #else |
| 323 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 324 | EXPECT_FALSE(_acmA->REDStatus()); |
| 325 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 326 | |
| 327 | #ifndef WEBRTC_CODEC_OPUS |
| 328 | EXPECT_TRUE(false); |
| 329 | printf("Opus needs to be activated to run this test\n"); |
| 330 | return; |
| 331 | #endif |
| 332 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 333 | RegisterSendCodec('A', kNameOPUS, 48000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 334 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 335 | #if defined(SUPPORT_RED_FB) && defined(SUPPORT_RED_SWB) &&\ |
| 336 | defined(SUPPORT_RED_WB) |
| 337 | // Switch to codec, RED should remain switched on. |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 338 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 339 | #else |
| 340 | EXPECT_FALSE(_acmA->REDStatus()); |
| 341 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 342 | |
| 343 | // _channelA2B imposes 25% packet loss rate. |
| 344 | EXPECT_EQ(0, _acmA->SetPacketLossRate(25)); |
| 345 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 346 | #ifdef SUPPORT_RED_FB |
| 347 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 348 | EXPECT_TRUE(_acmA->REDStatus()); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 349 | // Codec FEC and RED are mutually exclusive. |
| 350 | EXPECT_EQ(-1, _acmA->SetCodecFEC(true)); |
| 351 | |
| 352 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
| 353 | EXPECT_EQ(0, _acmA->SetCodecFEC(true)); |
| 354 | |
| 355 | // Codec FEC and RED are mutually exclusive. |
| 356 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 357 | #else |
| 358 | EXPECT_EQ(-1, _acmA->SetREDStatus(true)); |
| 359 | EXPECT_FALSE(_acmA->REDStatus()); |
| 360 | EXPECT_EQ(0, _acmA->SetCodecFEC(true)); |
| 361 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 362 | |
| 363 | EXPECT_TRUE(_acmA->CodecFEC()); |
| 364 | OpenOutFile(_testCntr); |
| 365 | Run(); |
| 366 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 367 | // Switch to L16 with RED. |
| 368 | RegisterSendCodec('A', kNameL16, 8000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 369 | EXPECT_EQ(0, SetVAD(false, false, VADNormal)); |
| 370 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 371 | // L16 does not support FEC, so FEC should be turned off automatically. |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 372 | EXPECT_FALSE(_acmA->CodecFEC()); |
| 373 | |
| 374 | EXPECT_EQ(0, _acmA->SetREDStatus(true)); |
| 375 | EXPECT_TRUE(_acmA->REDStatus()); |
| 376 | Run(); |
| 377 | |
| 378 | // Switch to Opus again. |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 379 | RegisterSendCodec('A', kNameOPUS, 48000); |
| 380 | #ifdef SUPPORT_RED_FB |
| 381 | // Switch to codec, RED should remain switched on. |
| 382 | EXPECT_TRUE(_acmA->REDStatus()); |
| 383 | #else |
| 384 | EXPECT_FALSE(_acmA->REDStatus()); |
| 385 | #endif |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 386 | EXPECT_EQ(0, _acmA->SetREDStatus(false)); |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 387 | EXPECT_EQ(0, _acmA->SetCodecFEC(false)); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 388 | Run(); |
| 389 | |
| 390 | EXPECT_EQ(0, _acmA->SetCodecFEC(true)); |
| 391 | _outFileB.Close(); |
| 392 | |
minyue@webrtc.org | 60fbd65 | 2014-09-25 14:36:30 +0000 | [diff] [blame] | 393 | // Codecs does not support internal FEC, cannot enable FEC. |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 394 | RegisterSendCodec('A', kNameG722, 16000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 395 | EXPECT_FALSE(_acmA->REDStatus()); |
| 396 | EXPECT_EQ(-1, _acmA->SetCodecFEC(true)); |
| 397 | EXPECT_FALSE(_acmA->CodecFEC()); |
| 398 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 399 | RegisterSendCodec('A', kNameISAC, 16000); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 400 | EXPECT_FALSE(_acmA->REDStatus()); |
| 401 | EXPECT_EQ(-1, _acmA->SetCodecFEC(true)); |
| 402 | EXPECT_FALSE(_acmA->CodecFEC()); |
minyue@webrtc.org | 60fbd65 | 2014-09-25 14:36:30 +0000 | [diff] [blame] | 403 | |
| 404 | // Codecs does not support internal FEC, disable FEC does not trigger failure. |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 405 | RegisterSendCodec('A', kNameG722, 16000); |
minyue@webrtc.org | 60fbd65 | 2014-09-25 14:36:30 +0000 | [diff] [blame] | 406 | EXPECT_FALSE(_acmA->REDStatus()); |
| 407 | EXPECT_EQ(0, _acmA->SetCodecFEC(false)); |
| 408 | EXPECT_FALSE(_acmA->CodecFEC()); |
| 409 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 410 | RegisterSendCodec('A', kNameISAC, 16000); |
minyue@webrtc.org | 60fbd65 | 2014-09-25 14:36:30 +0000 | [diff] [blame] | 411 | EXPECT_FALSE(_acmA->REDStatus()); |
| 412 | EXPECT_EQ(0, _acmA->SetCodecFEC(false)); |
| 413 | EXPECT_FALSE(_acmA->CodecFEC()); |
kwiberg | 98ab3a4 | 2015-09-30 21:54:21 -0700 | [diff] [blame] | 414 | |
| 415 | #endif // defined(WEBRTC_CODEC_G722) |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | int32_t TestRedFec::SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode) { |
| 419 | return _acmA->SetVAD(enableDTX, enableVAD, vadMode); |
| 420 | } |
| 421 | |
minyue@webrtc.org | 41d2bef | 2015-03-23 12:57:45 +0000 | [diff] [blame] | 422 | int16_t TestRedFec::RegisterSendCodec(char side, const char* codecName, |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 423 | int32_t samplingFreqHz) { |
| 424 | std::cout << std::flush; |
| 425 | AudioCodingModule* myACM; |
| 426 | switch (side) { |
| 427 | case 'A': { |
| 428 | myACM = _acmA.get(); |
| 429 | break; |
| 430 | } |
| 431 | case 'B': { |
| 432 | myACM = _acmB.get(); |
| 433 | break; |
| 434 | } |
| 435 | default: |
| 436 | return -1; |
| 437 | } |
| 438 | |
| 439 | if (myACM == NULL) { |
| 440 | assert(false); |
| 441 | return -1; |
| 442 | } |
| 443 | CodecInst myCodecParam; |
| 444 | EXPECT_GT(AudioCodingModule::Codec(codecName, &myCodecParam, |
| 445 | samplingFreqHz, 1), -1); |
| 446 | EXPECT_GT(myACM->RegisterSendCodec(myCodecParam), -1); |
| 447 | |
| 448 | // Initialization was successful. |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | void TestRedFec::Run() { |
| 453 | AudioFrame audioFrame; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 454 | int32_t outFreqHzB = _outFileB.SamplingFrequency(); |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 455 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 456 | _inFileA.SetNum10MsBlocksToRead(50); |
| 457 | // Fast-forward 1 second (100 blocks) since the file starts with silence. |
| 458 | _inFileA.FastForward(100); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 459 | |
| 460 | while (!_inFileA.EndOfFile()) { |
| 461 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 462 | EXPECT_GE(_acmA->Add10MsData(audioFrame), 0); |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 463 | bool muted; |
| 464 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(outFreqHzB, &audioFrame, &muted)); |
| 465 | ASSERT_FALSE(muted); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 466 | _outFileB.Write10MsData(audioFrame.data_, audioFrame.samples_per_channel_); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 467 | } |
| 468 | _inFileA.Rewind(); |
| 469 | } |
| 470 | |
| 471 | void TestRedFec::OpenOutFile(int16_t test_number) { |
| 472 | std::string file_name; |
| 473 | std::stringstream file_stream; |
| 474 | file_stream << webrtc::test::OutputPath(); |
| 475 | file_stream << "TestRedFec_outFile_"; |
| 476 | file_stream << test_number << ".pcm"; |
| 477 | file_name = file_stream.str(); |
| 478 | _outFileB.Open(file_name, 16000, "wb"); |
| 479 | } |
| 480 | |
| 481 | } // namespace webrtc |