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