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