blob: c5da92e1e523b08ae3758351e14bcd5eb830262b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org9dc45da2012-05-23 15:39:01 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000011#include "webrtc/modules/audio_coding/main/test/iSACTest.h"
12
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <ctype.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000014#include <stdio.h>
15#include <string.h>
16
17#if _WIN32
18#include <windows.h>
19#elif WEBRTC_LINUX
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000020#include <time.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000021#else
22#include <sys/time.h>
23#include <time.h>
andrew@webrtc.org89df0922013-09-12 01:27:43 +000024#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000025
turaj@webrtc.org532f3dc2013-09-19 00:12:23 +000026#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000027#include "webrtc/modules/audio_coding/main/test/utility.h"
28#include "webrtc/system_wrappers/interface/event_wrapper.h"
29#include "webrtc/system_wrappers/interface/tick_util.h"
30#include "webrtc/system_wrappers/interface/trace.h"
31#include "webrtc/test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000032
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000033namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000034
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000035void SetISACConfigDefault(ACMTestISACConfig& isacConfig) {
36 isacConfig.currentRateBitPerSec = 0;
37 isacConfig.currentFrameSizeMsec = 0;
38 isacConfig.maxRateBitPerSec = 0;
39 isacConfig.maxPayloadSizeByte = 0;
40 isacConfig.encodingMode = -1;
41 isacConfig.initRateBitPerSec = 0;
42 isacConfig.initFrameSizeInMsec = 0;
43 isacConfig.enforceFrameSize = false;
44 return;
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm,
48 int testMode) {
niklase@google.com470e71d2011-07-07 08:21:25 +000049
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050 if ((isacConfig.currentRateBitPerSec != 0)
51 || (isacConfig.currentFrameSizeMsec != 0)) {
52 CodecInst sendCodec;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000053 EXPECT_EQ(0, acm->SendCodec(&sendCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000054 if (isacConfig.currentRateBitPerSec < 0) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000055 // Register iSAC in adaptive (channel-dependent) mode.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000056 sendCodec.rate = -1;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000057 EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000058 } else {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000059 if (isacConfig.currentRateBitPerSec != 0) {
60 sendCodec.rate = isacConfig.currentRateBitPerSec;
61 }
62 if (isacConfig.currentFrameSizeMsec != 0) {
63 sendCodec.pacsize = isacConfig.currentFrameSizeMsec
64 * (sendCodec.plfreq / 1000);
65 }
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000066 EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +000067 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000068 }
niklase@google.com470e71d2011-07-07 08:21:25 +000069
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000070 if (isacConfig.maxRateBitPerSec > 0) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000071 // Set max rate.
72 EXPECT_EQ(0, acm->SetISACMaxRate(isacConfig.maxRateBitPerSec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000073 }
74 if (isacConfig.maxPayloadSizeByte > 0) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000075 // Set max payload size.
76 EXPECT_EQ(0, acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 }
78 if ((isacConfig.initFrameSizeInMsec != 0)
79 || (isacConfig.initRateBitPerSec != 0)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000080 EXPECT_EQ(0, acm->ConfigISACBandwidthEstimator(
81 static_cast<uint8_t>(isacConfig.initFrameSizeInMsec),
82 static_cast<uint16_t>(isacConfig.initRateBitPerSec),
83 isacConfig.enforceFrameSize));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000084 }
niklase@google.com470e71d2011-07-07 08:21:25 +000085
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000086 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000087}
88
henrik.lundin@webrtc.orgadaf8092014-04-17 08:29:10 +000089ISACTest::ISACTest(int testMode)
90 : _acmA(AudioCodingModule::Create(1)),
91 _acmB(AudioCodingModule::Create(2)),
92 _testMode(testMode) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000093
turaj@webrtc.org55e17232013-10-29 04:40:09 +000094ISACTest::~ISACTest() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000095
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000096void ISACTest::Setup() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000097 int codecCntr;
98 CodecInst codecParam;
niklase@google.com470e71d2011-07-07 08:21:25 +000099
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000100 for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
101 codecCntr++) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000102 EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000103 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
104 && codecParam.plfreq == 16000) {
105 memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
106 _idISAC16kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000108 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
109 && codecParam.plfreq == 32000) {
110 memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
111 _idISAC32kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000113 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000115 // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs.
116 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz));
117 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz));
118 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz));
119 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz));
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000121 //--- Set A-to-B channel
turaj@webrtc.org55e17232013-10-29 04:40:09 +0000122 _channel_A2B.reset(new Channel);
123 EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get()));
124 _channel_A2B->RegisterReceiverACM(_acmB.get());
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000126 //--- Set B-to-A channel
turaj@webrtc.org55e17232013-10-29 04:40:09 +0000127 _channel_B2A.reset(new Channel);
128 EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get()));
129 _channel_B2A->RegisterReceiverACM(_acmA.get());
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000131 file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
132 "pcm");
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000134 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
135 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000136
137 _inFileA.Open(file_name_swb_, 32000, "rb");
138 std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
139 std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
140 _outFileA.Open(fileNameA, 32000, "wb");
141 _outFileB.Open(fileNameB, 32000, "wb");
142
143 while (!_inFileA.EndOfFile()) {
144 Run10ms();
145 }
146 CodecInst receiveCodec;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000147 EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec));
148 EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000149
150 _inFileA.Close();
151 _outFileA.Close();
152 _outFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000153}
154
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000155void ISACTest::Perform() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000156 Setup();
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000158 int16_t testNr = 0;
159 ACMTestISACConfig wbISACConfig;
160 ACMTestISACConfig swbISACConfig;
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000162 SetISACConfigDefault(wbISACConfig);
163 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000164
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000165 wbISACConfig.currentRateBitPerSec = -1;
166 swbISACConfig.currentRateBitPerSec = -1;
167 testNr++;
168 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
169
170 if (_testMode != 0) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000171 SetISACConfigDefault(wbISACConfig);
172 SetISACConfigDefault(swbISACConfig);
173
174 wbISACConfig.currentRateBitPerSec = -1;
175 swbISACConfig.currentRateBitPerSec = -1;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000176 wbISACConfig.initRateBitPerSec = 13000;
177 wbISACConfig.initFrameSizeInMsec = 60;
178 swbISACConfig.initRateBitPerSec = 20000;
179 swbISACConfig.initFrameSizeInMsec = 30;
niklase@google.com470e71d2011-07-07 08:21:25 +0000180 testNr++;
181 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
182
niklase@google.com470e71d2011-07-07 08:21:25 +0000183 SetISACConfigDefault(wbISACConfig);
184 SetISACConfigDefault(swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000185
186 wbISACConfig.currentRateBitPerSec = 20000;
187 swbISACConfig.currentRateBitPerSec = 48000;
niklase@google.com470e71d2011-07-07 08:21:25 +0000188 testNr++;
189 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000190
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000191 wbISACConfig.currentRateBitPerSec = 16000;
192 swbISACConfig.currentRateBitPerSec = 30000;
193 wbISACConfig.currentFrameSizeMsec = 60;
niklase@google.com470e71d2011-07-07 08:21:25 +0000194 testNr++;
195 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000196 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000198 SetISACConfigDefault(wbISACConfig);
199 SetISACConfigDefault(swbISACConfig);
200 testNr++;
201 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000203 int user_input;
204 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000205 swbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
206 wbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000207 } else {
208 printf("Enter the max payload-size for side A: ");
209 CHECK_ERROR(scanf("%d", &user_input));
210 swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
211 printf("Enter the max payload-size for side B: ");
212 CHECK_ERROR(scanf("%d", &user_input));
213 wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
214 }
215 testNr++;
216 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000218 _acmA->ResetEncoder();
219 _acmB->ResetEncoder();
220 SetISACConfigDefault(wbISACConfig);
221 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000222
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000223 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000224 swbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
225 wbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000226 } else {
227 printf("Enter the max rate for side A: ");
228 CHECK_ERROR(scanf("%d", &user_input));
229 swbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
230 printf("Enter the max rate for side B: ");
231 CHECK_ERROR(scanf("%d", &user_input));
232 wbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
233 }
234
235 testNr++;
236 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
237
238 testNr++;
239 if (_testMode == 0) {
240 SwitchingSamplingRate(testNr, 4);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000241 } else {
242 SwitchingSamplingRate(testNr, 80);
243 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000244}
245
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000246void ISACTest::Run10ms() {
247 AudioFrame audioFrame;
248 EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
249 EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
250 EXPECT_EQ(0, _acmB->Add10MsData(audioFrame));
251 EXPECT_GT(_acmA->Process(), -1);
252 EXPECT_GT(_acmB->Process(), -1);
253 EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame));
254 _outFileA.Write10MsData(audioFrame);
255 EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame));
256 _outFileB.Write10MsData(audioFrame);
257}
258
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000259void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
260 ACMTestISACConfig& swbISACConfig) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000261 // Files in Side A and B
262 _inFileA.Open(file_name_swb_, 32000, "rb", true);
263 _inFileB.Open(file_name_swb_, 32000, "rb", true);
264
265 std::string file_name_out;
266 std::stringstream file_stream_a;
267 std::stringstream file_stream_b;
268 file_stream_a << webrtc::test::OutputPath();
269 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000270 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
271 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000272 file_name_out = file_stream_a.str();
273 _outFileA.Open(file_name_out, 32000, "wb");
274 file_name_out = file_stream_b.str();
275 _outFileB.Open(file_name_out, 32000, "wb");
276
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000277 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
278 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
279 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
280 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000281
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000282 // Side A is sending super-wideband, and side B is sending wideband.
turaj@webrtc.org55e17232013-10-29 04:40:09 +0000283 SetISAConfig(swbISACConfig, _acmA.get(), _testMode);
284 SetISAConfig(wbISACConfig, _acmB.get(), _testMode);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000285
286 bool adaptiveMode = false;
287 if ((swbISACConfig.currentRateBitPerSec == -1)
288 || (wbISACConfig.currentRateBitPerSec == -1)) {
289 adaptiveMode = true;
290 }
291 _myTimer.Reset();
292 _channel_A2B->ResetStats();
293 _channel_B2A->ResetStats();
294
295 char currentTime[500];
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000296 CodecInst sendCodec;
297 EventWrapper* myEvent = EventWrapper::Create();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000298 EXPECT_TRUE(myEvent->StartTimer(true, 10));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000299 while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
300 Run10ms();
301 _myTimer.Tick10ms();
302 _myTimer.CurrentTimeHMS(currentTime);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000303
304 if ((adaptiveMode) && (_testMode != 0)) {
305 myEvent->Wait(5000);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000306 EXPECT_EQ(0, _acmA->SendCodec(&sendCodec));
307 EXPECT_EQ(0, _acmB->SendCodec(&sendCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +0000308 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000309 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000311 if (_testMode != 0) {
312 printf("\n\nSide A statistics\n\n");
313 _channel_A2B->PrintStats(_paramISAC32kHz);
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000314
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000315 printf("\n\nSide B statistics\n\n");
316 _channel_B2A->PrintStats(_paramISAC16kHz);
317 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000318
andresp@webrtc.orgd0b436a2014-01-13 13:15:59 +0000319 _channel_A2B->ResetStats();
320 _channel_B2A->ResetStats();
321
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000322 _outFileA.Close();
323 _outFileB.Close();
324 _inFileA.Close();
325 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000326}
327
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000328void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
329 // Files in Side A
330 _inFileA.Open(file_name_swb_, 32000, "rb");
331 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000332
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000333 std::string file_name_out;
334 std::stringstream file_stream_a;
335 std::stringstream file_stream_b;
336 file_stream_a << webrtc::test::OutputPath();
337 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000338 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
339 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000340 file_name_out = file_stream_a.str();
341 _outFileA.Open(file_name_out, 32000, "wb");
342 file_name_out = file_stream_b.str();
343 _outFileB.Open(file_name_out, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000344
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000345 // Start with side A sending super-wideband and side B seding wideband.
346 // Toggle sending wideband/super-wideband in this test.
347 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
348 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000349
350 int numSendCodecChanged = 0;
351 _myTimer.Reset();
352 char currentTime[50];
353 while (numSendCodecChanged < (maxSampRateChange << 1)) {
354 Run10ms();
355 _myTimer.Tick10ms();
356 _myTimer.CurrentTimeHMS(currentTime);
357 if (_testMode == 2)
358 printf("\r%s", currentTime);
359 if (_inFileA.EndOfFile()) {
360 if (_inFileA.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000361 // Switch side A to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000362 _inFileA.Close();
363 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000364 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000365 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000366 // Switch side A to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000367 _inFileA.Close();
368 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000369 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000370 }
371 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000372 }
373
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000374 if (_inFileB.EndOfFile()) {
375 if (_inFileB.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000376 // Switch side B to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000377 _inFileB.Close();
378 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000379 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000380 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000381 // Switch side B to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000382 _inFileB.Close();
383 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000384 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000385 }
386 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000387 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000388 }
389 _outFileA.Close();
390 _outFileB.Close();
391 _inFileA.Close();
392 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000393}
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000394
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000395} // namespace webrtc