Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: webrtc/modules/audio_coding/main/test/iSACTest.cc

Issue 1481493004: audio_coding: remove "main" directory (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
11 #include "webrtc/modules/audio_coding/main/test/iSACTest.h"
12
13 #include <ctype.h>
14 #include <stdio.h>
15 #include <string.h>
16
17 #if _WIN32
18 #include <windows.h>
19 #elif WEBRTC_LINUX
20 #include <time.h>
21 #else
22 #include <sys/time.h>
23 #include <time.h>
24 #endif
25
26 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
27 #include "webrtc/modules/audio_coding/main/test/utility.h"
28 #include "webrtc/system_wrappers/include/event_wrapper.h"
29 #include "webrtc/system_wrappers/include/tick_util.h"
30 #include "webrtc/system_wrappers/include/trace.h"
31 #include "webrtc/test/testsupport/fileutils.h"
32
33 namespace webrtc {
34
35 void SetISACConfigDefault(ACMTestISACConfig& isacConfig) {
36 isacConfig.currentRateBitPerSec = 0;
37 isacConfig.currentFrameSizeMsec = 0;
38 isacConfig.encodingMode = -1;
39 isacConfig.initRateBitPerSec = 0;
40 isacConfig.initFrameSizeInMsec = 0;
41 isacConfig.enforceFrameSize = false;
42 return;
43 }
44
45 int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm,
46 int testMode) {
47
48 if ((isacConfig.currentRateBitPerSec != 0)
49 || (isacConfig.currentFrameSizeMsec != 0)) {
50 auto sendCodec = acm->SendCodec();
51 EXPECT_TRUE(sendCodec);
52 if (isacConfig.currentRateBitPerSec < 0) {
53 // Register iSAC in adaptive (channel-dependent) mode.
54 sendCodec->rate = -1;
55 EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec));
56 } else {
57 if (isacConfig.currentRateBitPerSec != 0) {
58 sendCodec->rate = isacConfig.currentRateBitPerSec;
59 }
60 if (isacConfig.currentFrameSizeMsec != 0) {
61 sendCodec->pacsize = isacConfig.currentFrameSizeMsec
62 * (sendCodec->plfreq / 1000);
63 }
64 EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec));
65 }
66 }
67
68 return 0;
69 }
70
71 ISACTest::ISACTest(int testMode)
72 : _acmA(AudioCodingModule::Create(1)),
73 _acmB(AudioCodingModule::Create(2)),
74 _testMode(testMode) {}
75
76 ISACTest::~ISACTest() {}
77
78 void ISACTest::Setup() {
79 int codecCntr;
80 CodecInst codecParam;
81
82 for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
83 codecCntr++) {
84 EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam));
85 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
86 && codecParam.plfreq == 16000) {
87 memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
88 _idISAC16kHz = codecCntr;
89 }
90 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
91 && codecParam.plfreq == 32000) {
92 memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
93 _idISAC32kHz = codecCntr;
94 }
95 }
96
97 // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs.
98 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz));
99 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz));
100 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz));
101 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz));
102
103 //--- Set A-to-B channel
104 _channel_A2B.reset(new Channel);
105 EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get()));
106 _channel_A2B->RegisterReceiverACM(_acmB.get());
107
108 //--- Set B-to-A channel
109 _channel_B2A.reset(new Channel);
110 EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get()));
111 _channel_B2A->RegisterReceiverACM(_acmA.get());
112
113 file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
114 "pcm");
115
116 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
117 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
118
119 _inFileA.Open(file_name_swb_, 32000, "rb");
120 std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
121 std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
122 _outFileA.Open(fileNameA, 32000, "wb");
123 _outFileB.Open(fileNameB, 32000, "wb");
124
125 while (!_inFileA.EndOfFile()) {
126 Run10ms();
127 }
128 CodecInst receiveCodec;
129 EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec));
130 EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec));
131
132 _inFileA.Close();
133 _outFileA.Close();
134 _outFileB.Close();
135 }
136
137 void ISACTest::Perform() {
138 Setup();
139
140 int16_t testNr = 0;
141 ACMTestISACConfig wbISACConfig;
142 ACMTestISACConfig swbISACConfig;
143
144 SetISACConfigDefault(wbISACConfig);
145 SetISACConfigDefault(swbISACConfig);
146
147 wbISACConfig.currentRateBitPerSec = -1;
148 swbISACConfig.currentRateBitPerSec = -1;
149 testNr++;
150 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
151
152 if (_testMode != 0) {
153 SetISACConfigDefault(wbISACConfig);
154 SetISACConfigDefault(swbISACConfig);
155
156 wbISACConfig.currentRateBitPerSec = -1;
157 swbISACConfig.currentRateBitPerSec = -1;
158 wbISACConfig.initRateBitPerSec = 13000;
159 wbISACConfig.initFrameSizeInMsec = 60;
160 swbISACConfig.initRateBitPerSec = 20000;
161 swbISACConfig.initFrameSizeInMsec = 30;
162 testNr++;
163 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
164
165 SetISACConfigDefault(wbISACConfig);
166 SetISACConfigDefault(swbISACConfig);
167
168 wbISACConfig.currentRateBitPerSec = 20000;
169 swbISACConfig.currentRateBitPerSec = 48000;
170 testNr++;
171 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
172
173 wbISACConfig.currentRateBitPerSec = 16000;
174 swbISACConfig.currentRateBitPerSec = 30000;
175 wbISACConfig.currentFrameSizeMsec = 60;
176 testNr++;
177 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
178 }
179
180 SetISACConfigDefault(wbISACConfig);
181 SetISACConfigDefault(swbISACConfig);
182 testNr++;
183 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
184
185 testNr++;
186 if (_testMode == 0) {
187 SwitchingSamplingRate(testNr, 4);
188 } else {
189 SwitchingSamplingRate(testNr, 80);
190 }
191 }
192
193 void ISACTest::Run10ms() {
194 AudioFrame audioFrame;
195 EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
196 EXPECT_GE(_acmA->Add10MsData(audioFrame), 0);
197 EXPECT_GE(_acmB->Add10MsData(audioFrame), 0);
198 EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame));
199 _outFileA.Write10MsData(audioFrame);
200 EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame));
201 _outFileB.Write10MsData(audioFrame);
202 }
203
204 void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
205 ACMTestISACConfig& swbISACConfig) {
206 // Files in Side A and B
207 _inFileA.Open(file_name_swb_, 32000, "rb", true);
208 _inFileB.Open(file_name_swb_, 32000, "rb", true);
209
210 std::string file_name_out;
211 std::stringstream file_stream_a;
212 std::stringstream file_stream_b;
213 file_stream_a << webrtc::test::OutputPath();
214 file_stream_b << webrtc::test::OutputPath();
215 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
216 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
217 file_name_out = file_stream_a.str();
218 _outFileA.Open(file_name_out, 32000, "wb");
219 file_name_out = file_stream_b.str();
220 _outFileB.Open(file_name_out, 32000, "wb");
221
222 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
223 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
224 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
225 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
226
227 // Side A is sending super-wideband, and side B is sending wideband.
228 SetISAConfig(swbISACConfig, _acmA.get(), _testMode);
229 SetISAConfig(wbISACConfig, _acmB.get(), _testMode);
230
231 bool adaptiveMode = false;
232 if ((swbISACConfig.currentRateBitPerSec == -1)
233 || (wbISACConfig.currentRateBitPerSec == -1)) {
234 adaptiveMode = true;
235 }
236 _myTimer.Reset();
237 _channel_A2B->ResetStats();
238 _channel_B2A->ResetStats();
239
240 char currentTime[500];
241 EventTimerWrapper* myEvent = EventTimerWrapper::Create();
242 EXPECT_TRUE(myEvent->StartTimer(true, 10));
243 while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
244 Run10ms();
245 _myTimer.Tick10ms();
246 _myTimer.CurrentTimeHMS(currentTime);
247
248 if ((adaptiveMode) && (_testMode != 0)) {
249 myEvent->Wait(5000);
250 EXPECT_TRUE(_acmA->SendCodec());
251 EXPECT_TRUE(_acmB->SendCodec());
252 }
253 }
254
255 if (_testMode != 0) {
256 printf("\n\nSide A statistics\n\n");
257 _channel_A2B->PrintStats(_paramISAC32kHz);
258
259 printf("\n\nSide B statistics\n\n");
260 _channel_B2A->PrintStats(_paramISAC16kHz);
261 }
262
263 _channel_A2B->ResetStats();
264 _channel_B2A->ResetStats();
265
266 _outFileA.Close();
267 _outFileB.Close();
268 _inFileA.Close();
269 _inFileB.Close();
270 }
271
272 void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
273 // Files in Side A
274 _inFileA.Open(file_name_swb_, 32000, "rb");
275 _inFileB.Open(file_name_swb_, 32000, "rb");
276
277 std::string file_name_out;
278 std::stringstream file_stream_a;
279 std::stringstream file_stream_b;
280 file_stream_a << webrtc::test::OutputPath();
281 file_stream_b << webrtc::test::OutputPath();
282 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
283 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
284 file_name_out = file_stream_a.str();
285 _outFileA.Open(file_name_out, 32000, "wb");
286 file_name_out = file_stream_b.str();
287 _outFileB.Open(file_name_out, 32000, "wb");
288
289 // Start with side A sending super-wideband and side B seding wideband.
290 // Toggle sending wideband/super-wideband in this test.
291 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
292 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
293
294 int numSendCodecChanged = 0;
295 _myTimer.Reset();
296 char currentTime[50];
297 while (numSendCodecChanged < (maxSampRateChange << 1)) {
298 Run10ms();
299 _myTimer.Tick10ms();
300 _myTimer.CurrentTimeHMS(currentTime);
301 if (_testMode == 2)
302 printf("\r%s", currentTime);
303 if (_inFileA.EndOfFile()) {
304 if (_inFileA.SamplingFrequency() == 16000) {
305 // Switch side A to send super-wideband.
306 _inFileA.Close();
307 _inFileA.Open(file_name_swb_, 32000, "rb");
308 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
309 } else {
310 // Switch side A to send wideband.
311 _inFileA.Close();
312 _inFileA.Open(file_name_swb_, 32000, "rb");
313 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
314 }
315 numSendCodecChanged++;
316 }
317
318 if (_inFileB.EndOfFile()) {
319 if (_inFileB.SamplingFrequency() == 16000) {
320 // Switch side B to send super-wideband.
321 _inFileB.Close();
322 _inFileB.Open(file_name_swb_, 32000, "rb");
323 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
324 } else {
325 // Switch side B to send wideband.
326 _inFileB.Close();
327 _inFileB.Open(file_name_swb_, 32000, "rb");
328 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
329 }
330 numSendCodecChanged++;
331 }
332 }
333 _outFileA.Close();
334 _outFileB.Close();
335 _inFileA.Close();
336 _inFileB.Close();
337 }
338
339 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/main/test/iSACTest.h ('k') | webrtc/modules/audio_coding/main/test/insert_packet_with_timing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698