blob: ef0e92b2ea506c597e8c26944557f1e007a188b6 [file] [log] [blame]
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_coding/test/TestRedFec.h"
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000012
13#include <assert.h>
14
Karl Wiberg5817d3d2018-04-06 10:06:42 +020015#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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 Bonadei71207422017-09-15 13:58:09 +020021#include "typedefs.h" // NOLINT(build/include)
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000022
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +000023#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.orgaa5ea1c2014-05-23 15:16:51 +000035namespace webrtc {
36
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +000037namespace {
Karl Wiberg5817d3d2018-04-06 10:06:42 +020038
39const char kNameL16[] = "L16";
40const char kNamePCMU[] = "PCMU";
41const char kNameCN[] = "CN";
42const char kNameRED[] = "RED";
43const char kNameISAC[] = "ISAC";
44const char kNameG722[] = "G722";
45const char kNameOPUS[] = "opus";
46
47} // namespace
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +000048
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000049TestRedFec::TestRedFec()
Karl Wiberg5817d3d2018-04-06 10:06:42 +020050 : _acmA(AudioCodingModule::Create(
51 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
52 _acmB(AudioCodingModule::Create(
53 AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000054 _channelA2B(NULL),
Karl Wiberg5817d3d2018-04-06 10:06:42 +020055 _testCntr(0) {}
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000056
57TestRedFec::~TestRedFec() {
58 if (_channelA2B != NULL) {
59 delete _channelA2B;
60 _channelA2B = NULL;
61 }
62}
63
64void 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 }
kwibergda2bf4e2016-10-24 13:47:09 -070080 EXPECT_EQ(true, _acmB->RegisterReceiveCodec(myCodecParam.pltype,
81 CodecInstToSdp(myCodecParam)));
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +000082 }
83
84 // Create and connect the channel
85 _channelA2B = new Channel;
86 _acmA->RegisterTransportCallback(_channelA2B);
87 _channelA2B->RegisterReceiverACM(_acmB.get());
88
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +000089 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.org41d2bef2015-03-23 12:57:45 +0000107 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.orgaa5ea1c2014-05-23 15:16:51 +0000118 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.org41d2bef2015-03-23 12:57:45 +0000123#ifdef SUPPORT_RED_WB
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000124 EXPECT_EQ(0, _acmA->SetREDStatus(true));
125 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000126#else
127 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
128 EXPECT_FALSE(_acmA->REDStatus());
129#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000130 Run();
131 _outFileB.Close();
132
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000133 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.orgaa5ea1c2014-05-23 15:16:51 +0000142 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.org41d2bef2015-03-23 12:57:45 +0000149#ifdef SUPPORT_RED_WB
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000150 EXPECT_EQ(0, _acmA->SetREDStatus(true));
151 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000152#else
153 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
154 EXPECT_FALSE(_acmA->REDStatus());
155#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000156 OpenOutFile(_testCntr);
157 Run();
158 _outFileB.Close();
159
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000160 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.orgaa5ea1c2014-05-23 15:16:51 +0000170 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.org41d2bef2015-03-23 12:57:45 +0000177#ifdef SUPPORT_RED_SWB
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000178 EXPECT_EQ(0, _acmA->SetREDStatus(true));
179 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000180#else
181 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
182 EXPECT_FALSE(_acmA->REDStatus());
183#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000184 OpenOutFile(_testCntr);
185 Run();
186 _outFileB.Close();
187
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000188 RegisterSendCodec('A', kNameISAC, 32000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000189 EXPECT_EQ(0, SetVAD(false, false, VADNormal));
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000190
191#if defined(SUPPORT_RED_SWB) && defined(SUPPORT_RED_WB)
192 OpenOutFile(_testCntr);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000193 EXPECT_EQ(0, _acmA->SetREDStatus(true));
194 EXPECT_TRUE(_acmA->REDStatus());
195 Run();
196
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000197 RegisterSendCodec('A', kNameISAC, 16000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000198 EXPECT_TRUE(_acmA->REDStatus());
199 Run();
200
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000201 RegisterSendCodec('A', kNameISAC, 32000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000202 EXPECT_TRUE(_acmA->REDStatus());
203 Run();
204
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000205 RegisterSendCodec('A', kNameISAC, 16000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000206 EXPECT_TRUE(_acmA->REDStatus());
207 Run();
208 _outFileB.Close();
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000209#else
210 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
211 EXPECT_FALSE(_acmA->REDStatus());
212#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000213
214 _channelA2B->SetFECTestWithPacketLoss(true);
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000215 // Following tests are under packet losses.
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000216
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000217 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.orgaa5ea1c2014-05-23 15:16:51 +0000228 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.org41d2bef2015-03-23 12:57:45 +0000235#ifdef SUPPORT_RED_WB
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000236 EXPECT_EQ(0, _acmA->SetREDStatus(true));
237 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000238#else
239 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
240 EXPECT_FALSE(_acmA->REDStatus());
241#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000242 OpenOutFile(_testCntr);
243 Run();
244 _outFileB.Close();
245
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000246 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.orgaa5ea1c2014-05-23 15:16:51 +0000256 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.org41d2bef2015-03-23 12:57:45 +0000262#ifdef SUPPORT_RED_WB
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000263 EXPECT_EQ(0, _acmA->SetREDStatus(true));
264 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000265#else
266 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
267 EXPECT_FALSE(_acmA->REDStatus());
268#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000269 OpenOutFile(_testCntr);
270 Run();
271 _outFileB.Close();
272
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000273 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.orgaa5ea1c2014-05-23 15:16:51 +0000283 OpenOutFile(_testCntr);
284 EXPECT_EQ(0, SetVAD(true, true, VADVeryAggr));
285 EXPECT_EQ(0, _acmA->SetREDStatus(false));
286 EXPECT_FALSE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000287#ifdef SUPPORT_RED_SWB
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000288 EXPECT_EQ(0, _acmA->SetREDStatus(true));
289 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000290#else
291 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
292 EXPECT_FALSE(_acmA->REDStatus());
293#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000294 OpenOutFile(_testCntr);
295 Run();
296 _outFileB.Close();
297
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000298 RegisterSendCodec('A', kNameISAC, 32000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000299 EXPECT_EQ(0, SetVAD(false, false, VADNormal));
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000300#if defined(SUPPORT_RED_SWB) && defined(SUPPORT_RED_WB)
301 OpenOutFile(_testCntr);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000302 EXPECT_EQ(0, _acmA->SetREDStatus(true));
303 EXPECT_TRUE(_acmA->REDStatus());
304 Run();
305
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000306 RegisterSendCodec('A', kNameISAC, 16000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000307 EXPECT_TRUE(_acmA->REDStatus());
308 Run();
309
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000310 RegisterSendCodec('A', kNameISAC, 32000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000311 EXPECT_TRUE(_acmA->REDStatus());
312 Run();
313
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000314 RegisterSendCodec('A', kNameISAC, 16000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000315 EXPECT_TRUE(_acmA->REDStatus());
316 Run();
317 _outFileB.Close();
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000318#else
319 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
320 EXPECT_FALSE(_acmA->REDStatus());
321#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000322
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.org41d2bef2015-03-23 12:57:45 +0000329 RegisterSendCodec('A', kNameOPUS, 48000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000330
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000331#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.orgaa5ea1c2014-05-23 15:16:51 +0000334 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000335#else
336 EXPECT_FALSE(_acmA->REDStatus());
337#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000338
339 // _channelA2B imposes 25% packet loss rate.
340 EXPECT_EQ(0, _acmA->SetPacketLossRate(25));
341
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000342#ifdef SUPPORT_RED_FB
343 EXPECT_EQ(0, _acmA->SetREDStatus(true));
344 EXPECT_TRUE(_acmA->REDStatus());
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000345 // 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.org41d2bef2015-03-23 12:57:45 +0000353#else
354 EXPECT_EQ(-1, _acmA->SetREDStatus(true));
355 EXPECT_FALSE(_acmA->REDStatus());
356 EXPECT_EQ(0, _acmA->SetCodecFEC(true));
357#endif
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000358
359 EXPECT_TRUE(_acmA->CodecFEC());
360 OpenOutFile(_testCntr);
361 Run();
362
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000363 // Switch to L16 with RED.
364 RegisterSendCodec('A', kNameL16, 8000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000365 EXPECT_EQ(0, SetVAD(false, false, VADNormal));
366
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000367 // L16 does not support FEC, so FEC should be turned off automatically.
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000368 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.org41d2bef2015-03-23 12:57:45 +0000375 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.orgaa5ea1c2014-05-23 15:16:51 +0000382 EXPECT_EQ(0, _acmA->SetREDStatus(false));
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000383 EXPECT_EQ(0, _acmA->SetCodecFEC(false));
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000384 Run();
385
386 EXPECT_EQ(0, _acmA->SetCodecFEC(true));
387 _outFileB.Close();
388
minyue@webrtc.org60fbd652014-09-25 14:36:30 +0000389 // Codecs does not support internal FEC, cannot enable FEC.
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000390 RegisterSendCodec('A', kNameG722, 16000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000391 EXPECT_FALSE(_acmA->REDStatus());
392 EXPECT_EQ(-1, _acmA->SetCodecFEC(true));
393 EXPECT_FALSE(_acmA->CodecFEC());
394
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000395 RegisterSendCodec('A', kNameISAC, 16000);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000396 EXPECT_FALSE(_acmA->REDStatus());
397 EXPECT_EQ(-1, _acmA->SetCodecFEC(true));
398 EXPECT_FALSE(_acmA->CodecFEC());
minyue@webrtc.org60fbd652014-09-25 14:36:30 +0000399
400 // Codecs does not support internal FEC, disable FEC does not trigger failure.
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000401 RegisterSendCodec('A', kNameG722, 16000);
minyue@webrtc.org60fbd652014-09-25 14:36:30 +0000402 EXPECT_FALSE(_acmA->REDStatus());
403 EXPECT_EQ(0, _acmA->SetCodecFEC(false));
404 EXPECT_FALSE(_acmA->CodecFEC());
405
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000406 RegisterSendCodec('A', kNameISAC, 16000);
minyue@webrtc.org60fbd652014-09-25 14:36:30 +0000407 EXPECT_FALSE(_acmA->REDStatus());
408 EXPECT_EQ(0, _acmA->SetCodecFEC(false));
409 EXPECT_FALSE(_acmA->CodecFEC());
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000410}
411
412int32_t TestRedFec::SetVAD(bool enableDTX, bool enableVAD, ACMVADMode vadMode) {
413 return _acmA->SetVAD(enableDTX, enableVAD, vadMode);
414}
415
minyue@webrtc.org41d2bef2015-03-23 12:57:45 +0000416int16_t TestRedFec::RegisterSendCodec(char side, const char* codecName,
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000417 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
446void TestRedFec::Run() {
447 AudioFrame audioFrame;
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000448 int32_t outFreqHzB = _outFileB.SamplingFrequency();
Henrik Lundin4d682082015-12-10 16:24:39 +0100449 // 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.orgaa5ea1c2014-05-23 15:16:51 +0000453
454 while (!_inFileA.EndOfFile()) {
455 EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
henrik.lundin@webrtc.orgf56c1622015-03-02 12:29:30 +0000456 EXPECT_GE(_acmA->Add10MsData(audioFrame), 0);
henrik.lundind4ccb002016-05-17 12:21:55 -0700457 bool muted;
458 EXPECT_EQ(0, _acmB->PlayoutData10Ms(outFreqHzB, &audioFrame, &muted));
459 ASSERT_FALSE(muted);
yujo36b1a5f2017-06-12 12:45:32 -0700460 _outFileB.Write10MsData(audioFrame.data(), audioFrame.samples_per_channel_);
minyue@webrtc.orgaa5ea1c2014-05-23 15:16:51 +0000461 }
462 _inFileA.Rewind();
463}
464
465void 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