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