blob: 90f88e3bf5f66699997dc80fa0c2d0543b60c8cb [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org63a50982012-05-02 23:56:37 +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/APITest.h"
12
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <ctype.h>
kjellander@webrtc.org543c3ea2011-11-23 12:20:35 +000014#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000017
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000018#include <iostream>
19#include <ostream>
20#include <string>
21
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000022#include "testing/gtest/include/gtest/gtest.h"
23#include "webrtc/common_types.h"
24#include "webrtc/engine_configurations.h"
25#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
26#include "webrtc/modules/audio_coding/main/test/utility.h"
27#include "webrtc/system_wrappers/interface/event_wrapper.h"
28#include "webrtc/system_wrappers/interface/thread_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 {
34
niklase@google.com470e71d2011-07-07 08:21:25 +000035#define TEST_DURATION_SEC 600
niklase@google.com470e71d2011-07-07 08:21:25 +000036#define NUMBER_OF_SENDER_TESTS 6
niklase@google.com470e71d2011-07-07 08:21:25 +000037#define MAX_FILE_NAME_LENGTH_BYTE 500
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000038#define CHECK_THREAD_NULLITY(myThread, S) \
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000039 if(myThread != NULL) { \
40 unsigned int i; \
41 (myThread)->Start(i); \
42 } else { \
43 ADD_FAILURE() << S; \
44 }
niklase@google.com470e71d2011-07-07 08:21:25 +000045
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000046void APITest::Wait(uint32_t waitLengthMs) {
47 if (_randomTest) {
48 return;
49 } else {
50 EventWrapper* myEvent = EventWrapper::Create();
51 myEvent->Wait(waitLengthMs);
52 delete myEvent;
53 return;
54 }
niklase@google.com470e71d2011-07-07 08:21:25 +000055}
56
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000057APITest::APITest()
58 : _acmA(NULL),
59 _acmB(NULL),
60 _channel_A2B(NULL),
61 _channel_B2A(NULL),
62 _writeToFile(true),
63 _pullEventA(NULL),
64 _pushEventA(NULL),
65 _processEventA(NULL),
66 _apiEventA(NULL),
67 _pullEventB(NULL),
68 _pushEventB(NULL),
69 _processEventB(NULL),
70 _apiEventB(NULL),
71 _codecCntrA(0),
72 _codecCntrB(0),
73 _thereIsEncoderA(false),
74 _thereIsEncoderB(false),
75 _thereIsDecoderA(false),
76 _thereIsDecoderB(false),
77 _sendVADA(false),
78 _sendDTXA(false),
79 _sendVADModeA(VADNormal),
80 _sendVADB(false),
81 _sendDTXB(false),
82 _sendVADModeB(VADNormal),
83 _minDelayA(0),
84 _minDelayB(0),
85 _dotPositionA(0),
86 _dotMoveDirectionA(1),
87 _dotPositionB(39),
88 _dotMoveDirectionB(-1),
89 _dtmfCallback(NULL),
90 _vadCallbackA(NULL),
91 _vadCallbackB(NULL),
92 _apiTestRWLock(*RWLockWrapper::CreateRWLock()),
93 _randomTest(false),
94 _testNumA(0),
95 _testNumB(1) {
96 int n;
97 for (n = 0; n < 32; n++) {
98 _payloadUsed[n] = false;
99 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000101 for (n = 0; n < 3; n++) {
102 _receiveVADActivityA[n] = 0;
103 _receiveVADActivityB[n] = 0;
104 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000106 _movingDot[40] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000108 for (int n = 0; n < 40; n++) {
109 _movingDot[n] = ' ';
110 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000111}
112
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000113APITest::~APITest() {
114 DESTROY_ACM(_acmA);
115 DESTROY_ACM(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000117 DELETE_POINTER(_channel_A2B);
118 DELETE_POINTER(_channel_B2A);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000120 DELETE_POINTER(_pushEventA);
121 DELETE_POINTER(_pullEventA);
122 DELETE_POINTER(_processEventA);
123 DELETE_POINTER(_apiEventA);
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000125 DELETE_POINTER(_pushEventB);
126 DELETE_POINTER(_pullEventB);
127 DELETE_POINTER(_processEventB);
128 DELETE_POINTER(_apiEventB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000130 _inFileA.Close();
131 _outFileA.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000133 _inFileB.Close();
134 _outFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000136 DELETE_POINTER(_dtmfCallback);
137 DELETE_POINTER(_vadCallbackA);
138 DELETE_POINTER(_vadCallbackB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000140 delete &_apiTestRWLock;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141}
142
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000143int16_t APITest::SetUp() {
144 _acmA = AudioCodingModule::Create(1);
145 _acmB = AudioCodingModule::Create(2);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000147 CodecInst dummyCodec;
148 int lastPayloadType = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000150 int16_t numCodecs = _acmA->NumberOfCodecs();
151 for (uint8_t n = 0; n < numCodecs; n++) {
152 AudioCodingModule::Codec(n, &dummyCodec);
153 if ((STR_CASE_CMP(dummyCodec.plname, "CN") == 0)
154 && (dummyCodec.plfreq == 32000)) {
155 continue;
niklase@google.com470e71d2011-07-07 08:21:25 +0000156 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000158 printf("Register Receive Codec %s ", dummyCodec.plname);
niklase@google.com470e71d2011-07-07 08:21:25 +0000159
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000160 if ((n != 0) && !FixedPayloadTypeCodec(dummyCodec.plname)) {
161 // Check registration with an already occupied payload type
162 int currentPayloadType = dummyCodec.pltype;
163 dummyCodec.pltype = 97; //lastPayloadType;
164 CHECK_ERROR(_acmB->RegisterReceiveCodec(dummyCodec));
165 dummyCodec.pltype = currentPayloadType;
166 }
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000167
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000168 if ((n < numCodecs - 1) && !FixedPayloadTypeCodec(dummyCodec.plname)) {
169 // test if re-registration works;
170 CodecInst nextCodec;
171 int currentPayloadType = dummyCodec.pltype;
172 AudioCodingModule::Codec(n + 1, &nextCodec);
173 dummyCodec.pltype = nextCodec.pltype;
174 if (!FixedPayloadTypeCodec(nextCodec.plname)) {
175 _acmB->RegisterReceiveCodec(dummyCodec);
176 }
177 dummyCodec.pltype = currentPayloadType;
178 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000180 if ((n < numCodecs - 1) && !FixedPayloadTypeCodec(dummyCodec.plname)) {
181 // test if un-registration works;
182 CodecInst nextCodec;
183 AudioCodingModule::Codec(n + 1, &nextCodec);
184 nextCodec.pltype = dummyCodec.pltype;
185 if (!FixedPayloadTypeCodec(nextCodec.plname)) {
186 CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(nextCodec));
187 CHECK_ERROR_MT(_acmA->UnregisterReceiveCodec(nextCodec.pltype));
188 }
189 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000190
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000191 CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(dummyCodec));
192 printf(" side A done!");
193 CHECK_ERROR_MT(_acmB->RegisterReceiveCodec(dummyCodec));
194 printf(" side B done!\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000196 if (!strcmp(dummyCodec.plname, "CN")) {
197 CHECK_ERROR_MT(_acmA->RegisterSendCodec(dummyCodec));
198 CHECK_ERROR_MT(_acmB->RegisterSendCodec(dummyCodec));
199 }
200 lastPayloadType = dummyCodec.pltype;
201 if ((lastPayloadType >= 96) && (lastPayloadType <= 127)) {
202 _payloadUsed[lastPayloadType - 96] = true;
203 }
204 }
205 _thereIsDecoderA = true;
206 _thereIsDecoderB = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000208 // Register Send Codec
209 AudioCodingModule::Codec((uint8_t) _codecCntrA, &dummyCodec);
210 CHECK_ERROR_MT(_acmA->RegisterSendCodec(dummyCodec));
211 _thereIsEncoderA = true;
212 //
213 AudioCodingModule::Codec((uint8_t) _codecCntrB, &dummyCodec);
214 CHECK_ERROR_MT(_acmB->RegisterSendCodec(dummyCodec));
215 _thereIsEncoderB = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000217 uint16_t frequencyHz;
niklase@google.com470e71d2011-07-07 08:21:25 +0000218
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000219 printf("\n\nAPI Test\n");
220 printf("========\n");
221 printf("Hit enter to accept the default values indicated in []\n\n");
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000222
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000223 //--- Input A
224 std::string file_name = webrtc::test::ResourcePath(
225 "audio_coding/testfile32kHz", "pcm");
226 frequencyHz = 32000;
227 printf("Enter input file at side A [%s]: ", file_name.c_str());
228 PCMFile::ChooseFile(&file_name, 499, &frequencyHz);
229 _inFileA.Open(file_name, frequencyHz, "rb", true);
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000231 //--- Output A
232 std::string out_file_a = webrtc::test::OutputPath() + "outA.pcm";
233 printf("Enter output file at side A [%s]: ", out_file_a.c_str());
234 PCMFile::ChooseFile(&out_file_a, 499, &frequencyHz);
235 _outFileA.Open(out_file_a, frequencyHz, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000236
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000237 //--- Input B
238 file_name = webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
239 printf("\n\nEnter input file at side B [%s]: ", file_name.c_str());
240 PCMFile::ChooseFile(&file_name, 499, &frequencyHz);
241 _inFileB.Open(file_name, frequencyHz, "rb", true);
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000243 //--- Output B
244 std::string out_file_b = webrtc::test::OutputPath() + "outB.pcm";
245 printf("Enter output file at side B [%s]: ", out_file_b.c_str());
246 PCMFile::ChooseFile(&out_file_b, 499, &frequencyHz);
247 _outFileB.Open(out_file_b, frequencyHz, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000249 //--- Set A-to-B channel
250 _channel_A2B = new Channel(2);
251 CHECK_ERROR_MT(_acmA->RegisterTransportCallback(_channel_A2B));
252 _channel_A2B->RegisterReceiverACM(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000254 //--- Set B-to-A channel
255 _channel_B2A = new Channel(1);
256 CHECK_ERROR_MT(_acmB->RegisterTransportCallback(_channel_B2A));
257 _channel_B2A->RegisterReceiverACM(_acmA);
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000258
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000259 //--- EVENT TIMERS
260 // A
261 _pullEventA = EventWrapper::Create();
262 _pushEventA = EventWrapper::Create();
263 _processEventA = EventWrapper::Create();
264 _apiEventA = EventWrapper::Create();
265 // B
266 _pullEventB = EventWrapper::Create();
267 _pushEventB = EventWrapper::Create();
268 _processEventB = EventWrapper::Create();
269 _apiEventB = EventWrapper::Create();
270
271 //--- I/O params
272 // A
273 _outFreqHzA = _outFileA.SamplingFrequency();
274 // B
275 _outFreqHzB = _outFileB.SamplingFrequency();
276
277 //Trace::SetEncryptedTraceFile("ACMAPITestEncrypted.txt");
278
279 char print[11];
280
281 // Create a trace file.
282 Trace::CreateTrace();
283 Trace::SetTraceFile(
284 (webrtc::test::OutputPath() + "acm_api_trace.txt").c_str());
285
286 printf("\nRandom Test (y/n)?");
287 EXPECT_TRUE(fgets(print, 10, stdin) != NULL);
288 print[10] = '\0';
289 if (strstr(print, "y") != NULL) {
290 _randomTest = true;
291 _verbose = false;
292 _writeToFile = false;
293 } else {
294 _randomTest = false;
295 printf("\nPrint Tests (y/n)? ");
kjellander@webrtc.org543c3ea2011-11-23 12:20:35 +0000296 EXPECT_TRUE(fgets(print, 10, stdin) != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000297 print[10] = '\0';
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000298 if (strstr(print, "y") == NULL) {
299 EXPECT_TRUE(freopen("APITest_log.txt", "w", stdout) != 0);
300 _verbose = false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000301 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000302 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000303
304#ifdef WEBRTC_DTMF_DETECTION
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000305 _dtmfCallback = new DTMFDetector;
niklase@google.com470e71d2011-07-07 08:21:25 +0000306#endif
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000307 _vadCallbackA = new VADCallback;
308 _vadCallbackB = new VADCallback;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000309
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000310 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000311}
312
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000313bool APITest::PushAudioThreadA(void* obj) {
314 return static_cast<APITest*>(obj)->PushAudioRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000315}
316
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000317bool APITest::PushAudioThreadB(void* obj) {
318 return static_cast<APITest*>(obj)->PushAudioRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000319}
320
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000321bool APITest::PullAudioThreadA(void* obj) {
322 return static_cast<APITest*>(obj)->PullAudioRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000323}
324
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000325bool APITest::PullAudioThreadB(void* obj) {
326 return static_cast<APITest*>(obj)->PullAudioRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000327}
328
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000329bool APITest::ProcessThreadA(void* obj) {
330 return static_cast<APITest*>(obj)->ProcessRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000331}
332
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000333bool APITest::ProcessThreadB(void* obj) {
334 return static_cast<APITest*>(obj)->ProcessRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000335}
336
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000337bool APITest::APIThreadA(void* obj) {
338 return static_cast<APITest*>(obj)->APIRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000339}
340
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000341bool APITest::APIThreadB(void* obj) {
342 return static_cast<APITest*>(obj)->APIRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000343}
344
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000345bool APITest::PullAudioRunA() {
346 _pullEventA->Wait(100);
347 AudioFrame audioFrame;
348 if (_acmA->PlayoutData10Ms(_outFreqHzA, &audioFrame) < 0) {
349 bool thereIsDecoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000350 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000351 ReadLockScoped rl(_apiTestRWLock);
352 thereIsDecoder = _thereIsDecoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000353 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000354 if (thereIsDecoder) {
355 fprintf(stderr, "\n>>>>>> cannot pull audio A <<<<<<<< \n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000356 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000357 } else {
358 if (_writeToFile) {
359 _outFileA.Write10MsData(audioFrame);
360 }
361 _receiveVADActivityA[(int) audioFrame.vad_activity_]++;
362 }
363 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000364}
365
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000366bool APITest::PullAudioRunB() {
367 _pullEventB->Wait(100);
368 AudioFrame audioFrame;
369 if (_acmB->PlayoutData10Ms(_outFreqHzB, &audioFrame) < 0) {
370 bool thereIsDecoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000371 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000372 ReadLockScoped rl(_apiTestRWLock);
373 thereIsDecoder = _thereIsDecoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000374 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000375 if (thereIsDecoder) {
376 fprintf(stderr, "\n>>>>>> cannot pull audio B <<<<<<<< \n");
377 fprintf(stderr, "%d %d\n", _testNumA, _testNumB);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000378 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000379 } else {
380 if (_writeToFile) {
381 _outFileB.Write10MsData(audioFrame);
382 }
383 _receiveVADActivityB[(int) audioFrame.vad_activity_]++;
384 }
385 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000386}
387
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000388bool APITest::PushAudioRunA() {
389 _pushEventA->Wait(100);
390 AudioFrame audioFrame;
391 _inFileA.Read10MsData(audioFrame);
392 if (_acmA->Add10MsData(audioFrame) < 0) {
393 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000394 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000395 ReadLockScoped rl(_apiTestRWLock);
396 thereIsEncoder = _thereIsEncoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000397 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000398 if (thereIsEncoder) {
399 fprintf(stderr, "\n>>>> add10MsData at A failed <<<<\n");
400 }
401 }
402 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403}
404
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000405bool APITest::PushAudioRunB() {
406 _pushEventB->Wait(100);
407 AudioFrame audioFrame;
408 _inFileB.Read10MsData(audioFrame);
409 if (_acmB->Add10MsData(audioFrame) < 0) {
410 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000411 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000412 ReadLockScoped rl(_apiTestRWLock);
413 thereIsEncoder = _thereIsEncoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000414 }
415
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000416 if (thereIsEncoder) {
417 fprintf(stderr, "\n>>>> cannot add audio to B <<<<");
418 }
419 }
420
421 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000422}
423
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000424bool APITest::ProcessRunA() {
425 _processEventA->Wait(100);
426 if (_acmA->Process() < 0) {
427 // do not print error message if there is no encoder
428 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000429 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000430 ReadLockScoped rl(_apiTestRWLock);
431 thereIsEncoder = _thereIsEncoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000432 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000433
434 if (thereIsEncoder) {
435 fprintf(stderr, "\n>>>>> Process Failed at A <<<<<\n");
436 }
437 }
438 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000439}
440
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000441bool APITest::ProcessRunB() {
442 _processEventB->Wait(100);
443 if (_acmB->Process() < 0) {
444 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000445 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000446 ReadLockScoped rl(_apiTestRWLock);
447 thereIsEncoder = _thereIsEncoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000448 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000449 if (thereIsEncoder) {
450 fprintf(stderr, "\n>>>>> Process Failed at B <<<<<\n");
451 }
452 }
453 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000454}
455
456/*/
457 *
458 * In side A we test the APIs which are related to sender Side.
459 *
460/*/
461
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000462void APITest::RunTest(char thread) {
463 int testNum;
464 {
465 WriteLockScoped cs(_apiTestRWLock);
466 if (thread == 'A') {
467 _testNumA = (_testNumB + 1 + (rand() % 6)) % 7;
468 testNum = _testNumA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000469
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000470 _movingDot[_dotPositionA] = ' ';
471 if (_dotPositionA == 0) {
472 _dotMoveDirectionA = 1;
473 }
474 if (_dotPositionA == 19) {
475 _dotMoveDirectionA = -1;
476 }
477 _dotPositionA += _dotMoveDirectionA;
478 _movingDot[_dotPositionA] = (_dotMoveDirectionA > 0) ? '>' : '<';
479 } else {
480 _testNumB = (_testNumA + 1 + (rand() % 6)) % 7;
481 testNum = _testNumB;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000482
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000483 _movingDot[_dotPositionB] = ' ';
484 if (_dotPositionB == 20) {
485 _dotMoveDirectionB = 1;
486 }
487 if (_dotPositionB == 39) {
488 _dotMoveDirectionB = -1;
489 }
490 _dotPositionB += _dotMoveDirectionB;
491 _movingDot[_dotPositionB] = (_dotMoveDirectionB > 0) ? '>' : '<';
niklase@google.com470e71d2011-07-07 08:21:25 +0000492 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000493 //fprintf(stderr, "%c: %d \n", thread, testNum);
494 //fflush(stderr);
495 }
496 switch (testNum) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000497 case 0:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000498 CurrentCodec('A');
499 ChangeCodec('A');
500 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000501 case 1:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000502 TestPlayout('B');
503 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000504 case 2:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000505 if (!_randomTest) {
506 fprintf(stdout, "\nTesting Delay ...\n");
507 }
508 TestDelay('A');
509 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000510 case 3:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000511 TestSendVAD('A');
512 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000513 case 4:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000514 TestRegisteration('A');
515 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000516 case 5:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000517 TestReceiverVAD('A');
518 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000519 case 6:
520#ifdef WEBRTC_DTMF_DETECTION
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000521 LookForDTMF('A');
niklase@google.com470e71d2011-07-07 08:21:25 +0000522#endif
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000523 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000524 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000525 fprintf(stderr, "Wrong Test Number\n");
526 getchar();
527 exit(1);
528 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000529}
530
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000531bool APITest::APIRunA() {
532 _apiEventA->Wait(50);
niklase@google.com470e71d2011-07-07 08:21:25 +0000533
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000534 bool randomTest;
535 {
536 ReadLockScoped rl(_apiTestRWLock);
537 randomTest = _randomTest;
538 }
539 if (randomTest) {
540 RunTest('A');
541 } else {
542 CurrentCodec('A');
543 ChangeCodec('A');
544 TestPlayout('B');
545 if (_codecCntrA == 0) {
546 fprintf(stdout, "\nTesting Delay ...\n");
547 TestDelay('A');
niklase@google.com470e71d2011-07-07 08:21:25 +0000548 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000549 // VAD TEST
550 TestSendVAD('A');
551 TestRegisteration('A');
552 TestReceiverVAD('A');
niklase@google.com470e71d2011-07-07 08:21:25 +0000553#ifdef WEBRTC_DTMF_DETECTION
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000554 LookForDTMF('A');
niklase@google.com470e71d2011-07-07 08:21:25 +0000555#endif
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000556 }
557 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000558}
559
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000560bool APITest::APIRunB() {
561 _apiEventB->Wait(50);
562 bool randomTest;
563 {
564 ReadLockScoped rl(_apiTestRWLock);
565 randomTest = _randomTest;
566 }
567 //_apiEventB->Wait(2000);
568 if (randomTest) {
569 RunTest('B');
570 }
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000571
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000572 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000573}
574
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000575void APITest::Perform() {
576 SetUp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000577
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000578 //--- THREADS
579 // A
580 // PUSH
581 ThreadWrapper* myPushAudioThreadA = ThreadWrapper::CreateThread(
582 PushAudioThreadA, this, kNormalPriority, "PushAudioThreadA");
583 CHECK_THREAD_NULLITY(myPushAudioThreadA, "Unable to start A::PUSH thread");
584 // PULL
585 ThreadWrapper* myPullAudioThreadA = ThreadWrapper::CreateThread(
586 PullAudioThreadA, this, kNormalPriority, "PullAudioThreadA");
587 CHECK_THREAD_NULLITY(myPullAudioThreadA, "Unable to start A::PULL thread");
588 // Process
589 ThreadWrapper* myProcessThreadA = ThreadWrapper::CreateThread(
590 ProcessThreadA, this, kNormalPriority, "ProcessThreadA");
591 CHECK_THREAD_NULLITY(myProcessThreadA, "Unable to start A::Process thread");
592 // API
593 ThreadWrapper* myAPIThreadA = ThreadWrapper::CreateThread(APIThreadA, this,
594 kNormalPriority,
595 "APIThreadA");
596 CHECK_THREAD_NULLITY(myAPIThreadA, "Unable to start A::API thread");
597 // B
598 // PUSH
599 ThreadWrapper* myPushAudioThreadB = ThreadWrapper::CreateThread(
600 PushAudioThreadB, this, kNormalPriority, "PushAudioThreadB");
601 CHECK_THREAD_NULLITY(myPushAudioThreadB, "Unable to start B::PUSH thread");
602 // PULL
603 ThreadWrapper* myPullAudioThreadB = ThreadWrapper::CreateThread(
604 PullAudioThreadB, this, kNormalPriority, "PullAudioThreadB");
605 CHECK_THREAD_NULLITY(myPullAudioThreadB, "Unable to start B::PULL thread");
606 // Process
607 ThreadWrapper* myProcessThreadB = ThreadWrapper::CreateThread(
608 ProcessThreadB, this, kNormalPriority, "ProcessThreadB");
609 CHECK_THREAD_NULLITY(myProcessThreadB, "Unable to start B::Process thread");
610 // API
611 ThreadWrapper* myAPIThreadB = ThreadWrapper::CreateThread(APIThreadB, this,
612 kNormalPriority,
613 "APIThreadB");
614 CHECK_THREAD_NULLITY(myAPIThreadB, "Unable to start B::API thread");
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000615
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000616 //_apiEventA->StartTimer(true, 5000);
617 //_apiEventB->StartTimer(true, 5000);
niklase@google.com470e71d2011-07-07 08:21:25 +0000618
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000619 _processEventA->StartTimer(true, 10);
620 _processEventB->StartTimer(true, 10);
niklase@google.com470e71d2011-07-07 08:21:25 +0000621
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000622 _pullEventA->StartTimer(true, 10);
623 _pullEventB->StartTimer(true, 10);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000624
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000625 _pushEventA->StartTimer(true, 10);
626 _pushEventB->StartTimer(true, 10);
niklase@google.com470e71d2011-07-07 08:21:25 +0000627
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000628 // Keep main thread waiting for sender/receiver
629 // threads to complete
630 EventWrapper* completeEvent = EventWrapper::Create();
631 uint64_t startTime = TickTime::MillisecondTimestamp();
632 uint64_t currentTime;
633 // Run test in 2 minutes (120000 ms).
634 do {
niklase@google.com470e71d2011-07-07 08:21:25 +0000635 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000636 //ReadLockScoped rl(_apiTestRWLock);
637 //fprintf(stderr, "\r%s", _movingDot);
638 }
639 //fflush(stderr);
640 completeEvent->Wait(50);
641 currentTime = TickTime::MillisecondTimestamp();
642 } while ((currentTime - startTime) < 120000);
niklase@google.com470e71d2011-07-07 08:21:25 +0000643
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000644 //completeEvent->Wait(0xFFFFFFFF);
645 //(unsigned long)((unsigned long)TEST_DURATION_SEC * (unsigned long)1000));
646 delete completeEvent;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000647
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000648 myPushAudioThreadA->Stop();
649 myPullAudioThreadA->Stop();
650 myProcessThreadA->Stop();
651 myAPIThreadA->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +0000652
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000653 delete myPushAudioThreadA;
654 delete myPullAudioThreadA;
655 delete myProcessThreadA;
656 delete myAPIThreadA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000657
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000658 myPushAudioThreadB->Stop();
659 myPullAudioThreadB->Stop();
660 myProcessThreadB->Stop();
661 myAPIThreadB->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +0000662
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000663 delete myPushAudioThreadB;
664 delete myPullAudioThreadB;
665 delete myProcessThreadB;
666 delete myAPIThreadB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000667}
668
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000669void APITest::CheckVADStatus(char side) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000670
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000671 bool dtxEnabled;
672 bool vadEnabled;
673 ACMVADMode vadMode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000674
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000675 if (side == 'A') {
676 _acmA->VAD(&dtxEnabled, &vadEnabled, &vadMode);
677 _acmA->RegisterVADCallback(NULL);
678 _vadCallbackA->Reset();
679 _acmA->RegisterVADCallback(_vadCallbackA);
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000680
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000681 if (!_randomTest) {
682 if (_verbose) {
683 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d", dtxEnabled ? "ON" : "OFF",
684 vadEnabled ? "ON" : "OFF", (int) vadMode);
685 Wait(5000);
686 fprintf(stdout, " => bit-rate %3.0f kbps\n", _channel_A2B->BitRate());
687 } else {
688 Wait(5000);
689 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d => bit-rate %3.0f kbps\n",
690 dtxEnabled ? "ON" : "OFF", vadEnabled ? "ON" : "OFF",
691 (int) vadMode, _channel_A2B->BitRate());
692 }
693 _vadCallbackA->PrintFrameTypes();
niklase@google.com470e71d2011-07-07 08:21:25 +0000694 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000695
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000696 if (dtxEnabled != _sendDTXA) {
697 fprintf(stderr, ">>> Error Enabling DTX <<<\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000698 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000699 if ((vadEnabled != _sendVADA) && (!dtxEnabled)) {
700 fprintf(stderr, ">>> Error Enabling VAD <<<\n");
701 }
702 if ((vadMode != _sendVADModeA) && vadEnabled) {
703 fprintf(stderr, ">>> Error setting VAD-mode <<<\n");
704 }
705 } else {
706 _acmB->VAD(&dtxEnabled, &vadEnabled, &vadMode);
707
708 _acmB->RegisterVADCallback(NULL);
709 _vadCallbackB->Reset();
710 _acmB->RegisterVADCallback(_vadCallbackB);
711
712 if (!_randomTest) {
713 if (_verbose) {
714 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d", dtxEnabled ? "ON" : "OFF",
715 vadEnabled ? "ON" : "OFF", (int) vadMode);
716 Wait(5000);
717 fprintf(stdout, " => bit-rate %3.0f kbps\n", _channel_B2A->BitRate());
718 } else {
719 Wait(5000);
720 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d => bit-rate %3.0f kbps\n",
721 dtxEnabled ? "ON" : "OFF", vadEnabled ? "ON" : "OFF",
722 (int) vadMode, _channel_B2A->BitRate());
723 }
724 _vadCallbackB->PrintFrameTypes();
725 }
726
727 if (dtxEnabled != _sendDTXB) {
728 fprintf(stderr, ">>> Error Enabling DTX <<<\n");
729 }
730 if ((vadEnabled != _sendVADB) && (!dtxEnabled)) {
731 fprintf(stderr, ">>> Error Enabling VAD <<<\n");
732 }
733 if ((vadMode != _sendVADModeB) && vadEnabled) {
734 fprintf(stderr, ">>> Error setting VAD-mode <<<\n");
735 }
736 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000737}
738
739// Set Min delay, get delay, playout timestamp
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000740void APITest::TestDelay(char side) {
741 AudioCodingModule* myACM;
742 Channel* myChannel;
743 int32_t* myMinDelay;
744 EventWrapper* myEvent = EventWrapper::Create();
niklase@google.com470e71d2011-07-07 08:21:25 +0000745
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000746 uint32_t inTimestamp = 0;
747 uint32_t outTimestamp = 0;
748 double estimDelay = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000749
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000750 double averageEstimDelay = 0;
751 double averageDelay = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000752
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000753 CircularBuffer estimDelayCB(100);
754 estimDelayCB.SetArithMean(true);
niklase@google.com470e71d2011-07-07 08:21:25 +0000755
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000756 if (side == 'A') {
757 myACM = _acmA;
758 myChannel = _channel_B2A;
759 myMinDelay = &_minDelayA;
760 } else {
761 myACM = _acmB;
762 myChannel = _channel_A2B;
763 myMinDelay = &_minDelayB;
764 }
765
766 CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay));
767
768 inTimestamp = myChannel->LastInTimestamp();
769 CHECK_ERROR_MT(myACM->PlayoutTimestamp(&outTimestamp));
770
771 if (!_randomTest) {
772 myEvent->StartTimer(true, 30);
773 int n = 0;
774 int settlePoint = 5000;
775 while (n < settlePoint + 400) {
776 myEvent->Wait(1000);
777
778 inTimestamp = myChannel->LastInTimestamp();
779 CHECK_ERROR_MT(myACM->PlayoutTimestamp(&outTimestamp));
780
781 //std::cout << outTimestamp << std::endl << std::flush;
782 estimDelay = (double) ((uint32_t)(inTimestamp - outTimestamp))
783 / ((double) myACM->ReceiveFrequency() / 1000.0);
784
785 estimDelayCB.Update(estimDelay);
786
787 estimDelayCB.ArithMean(averageEstimDelay);
788 //printf("\n %6.1f \n", estimDelay);
789 //std::cout << " " << std::flush;
790
791 if (_verbose) {
792 fprintf(stdout,
793 "\rExpected: %4d, retreived: %6.1f, measured: %6.1f",
794 *myMinDelay, averageDelay, averageEstimDelay);
795 std::cout << " " << std::flush;
796 }
797 if ((averageDelay > *myMinDelay) && (n < settlePoint)) {
798 settlePoint = n;
799 }
800 n++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000801 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000802 myEvent->StopTimer();
803 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000804
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000805 if ((!_verbose) && (!_randomTest)) {
806 fprintf(stdout, "\nExpected: %4d, retreived: %6.1f, measured: %6.1f",
niklase@google.com470e71d2011-07-07 08:21:25 +0000807 *myMinDelay, averageDelay, averageEstimDelay);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000808 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000809
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000810 *myMinDelay = (rand() % 1000) + 1;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000811
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000812 ACMNetworkStatistics networkStat;
813 CHECK_ERROR_MT(myACM->NetworkStatistics(&networkStat));
niklase@google.com470e71d2011-07-07 08:21:25 +0000814
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000815 if (!_randomTest) {
816 fprintf(stdout, "\n\nJitter Statistics at Side %c\n", side);
817 fprintf(stdout, "--------------------------------------\n");
818 fprintf(stdout, "buffer-size............. %d\n",
819 networkStat.currentBufferSize);
820 fprintf(stdout, "Preferred buffer-size... %d\n",
821 networkStat.preferredBufferSize);
822 fprintf(stdout, "Peaky jitter mode........%d\n",
823 networkStat.jitterPeaksFound);
824 fprintf(stdout, "packet-size rate........ %d\n",
825 networkStat.currentPacketLossRate);
826 fprintf(stdout, "discard rate............ %d\n",
827 networkStat.currentDiscardRate);
828 fprintf(stdout, "expand rate............. %d\n",
829 networkStat.currentExpandRate);
830 fprintf(stdout, "Preemptive rate......... %d\n",
831 networkStat.currentPreemptiveRate);
832 fprintf(stdout, "Accelerate rate......... %d\n",
833 networkStat.currentAccelerateRate);
834 fprintf(stdout, "Clock-drift............. %d\n", networkStat.clockDriftPPM);
835 fprintf(stdout, "Mean waiting time....... %d\n",
836 networkStat.meanWaitingTimeMs);
837 fprintf(stdout, "Median waiting time..... %d\n",
838 networkStat.medianWaitingTimeMs);
839 fprintf(stdout, "Min waiting time........ %d\n",
840 networkStat.minWaitingTimeMs);
841 fprintf(stdout, "Max waiting time........ %d\n",
842 networkStat.maxWaitingTimeMs);
843 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000844
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000845 CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay));
niklase@google.com470e71d2011-07-07 08:21:25 +0000846
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000847 if (!_randomTest) {
848 myEvent->Wait(500);
849 fprintf(stdout, "\n");
850 fprintf(stdout, "\n");
851 }
852 delete myEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000853}
854
855// Unregister a codec & register again.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000856void APITest::TestRegisteration(char sendSide) {
857 AudioCodingModule* sendACM;
858 AudioCodingModule* receiveACM;
859 bool* thereIsDecoder;
860 EventWrapper* myEvent = EventWrapper::Create();
niklase@google.com470e71d2011-07-07 08:21:25 +0000861
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000862 if (!_randomTest) {
863 fprintf(stdout, "\n\n");
864 fprintf(stdout,
865 "---------------------------------------------------------\n");
866 fprintf(stdout, " Unregister/register Receive Codec\n");
867 fprintf(stdout,
868 "---------------------------------------------------------\n");
869 }
870
871 switch (sendSide) {
872 case 'A': {
873 sendACM = _acmA;
874 receiveACM = _acmB;
875 thereIsDecoder = &_thereIsDecoderB;
876 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000877 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000878 case 'B': {
879 sendACM = _acmB;
880 receiveACM = _acmA;
881 thereIsDecoder = &_thereIsDecoderA;
882 break;
883 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000884 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000885 fprintf(stderr, "Invalid sender-side in TestRegistration(%c)\n",
886 sendSide);
887 exit(-1);
888 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000889
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000890 CodecInst myCodec;
891 if (sendACM->SendCodec(&myCodec) < 0) {
892 AudioCodingModule::Codec(_codecCntrA, &myCodec);
893 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000894
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000895 if (!_randomTest) {
896 fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n");
897 fflush (stdout);
898 }
899 {
900 WriteLockScoped wl(_apiTestRWLock);
901 *thereIsDecoder = false;
902 }
903 //myEvent->Wait(20);
904 CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
905 Wait(1000);
niklase@google.com470e71d2011-07-07 08:21:25 +0000906
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000907 int currentPayload = myCodec.pltype;
niklase@google.com470e71d2011-07-07 08:21:25 +0000908
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000909 if (!FixedPayloadTypeCodec(myCodec.plname)) {
910 int32_t i;
911 for (i = 0; i < 32; i++) {
912 if (!_payloadUsed[i]) {
913 if (!_randomTest) {
914 fprintf(stdout,
915 "Register receive codec with new Payload, AUDIO BACK.\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000916 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000917 //myCodec.pltype = i + 96;
918 //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
919 //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec));
920 //myEvent->Wait(20);
921 //{
922 // WriteLockScoped wl(_apiTestRWLock);
923 // *thereIsDecoder = true;
924 //}
925 Wait(1000);
926
927 if (!_randomTest) {
928 fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000929 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000930 //{
931 // WriteLockScoped wl(_apiTestRWLock);
932 // *thereIsDecoder = false;
933 //}
934 //myEvent->Wait(20);
935 //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
936 Wait(1000);
937
938 myCodec.pltype = currentPayload;
939 if (!_randomTest) {
940 fprintf(stdout,
941 "Register receive codec with default Payload, AUDIO BACK.\n");
942 fflush (stdout);
niklase@google.com470e71d2011-07-07 08:21:25 +0000943 }
944 CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000945 //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +0000946 myEvent->Wait(20);
947 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000948 WriteLockScoped wl(_apiTestRWLock);
949 *thereIsDecoder = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000950 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000951 Wait(1000);
952
953 break;
954 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000955 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000956 if (i == 32) {
957 CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
958 {
959 WriteLockScoped wl(_apiTestRWLock);
960 *thereIsDecoder = true;
961 }
962 }
963 } else {
964 if (!_randomTest) {
965 fprintf(stdout,
966 "Register receive codec with fixed Payload, AUDIO BACK.\n");
967 fflush (stdout);
968 }
969 CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
970 //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
971 //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
972 myEvent->Wait(20);
niklase@google.com470e71d2011-07-07 08:21:25 +0000973 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000974 WriteLockScoped wl(_apiTestRWLock);
975 *thereIsDecoder = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000976 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000977 }
978 delete myEvent;
979 if (!_randomTest) {
980 fprintf(stdout,
981 "---------------------------------------------------------\n");
982 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000983}
984
985// Playout Mode, background noise mode.
986// Receiver Frequency, playout frequency.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000987void APITest::TestPlayout(char receiveSide) {
988 AudioCodingModule* receiveACM;
989 AudioPlayoutMode* playoutMode = NULL;
990 ACMBackgroundNoiseMode* bgnMode = NULL;
991 switch (receiveSide) {
992 case 'A': {
993 receiveACM = _acmA;
994 playoutMode = &_playoutModeA;
995 bgnMode = &_bgnModeA;
996 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000997 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000998 case 'B': {
999 receiveACM = _acmB;
1000 playoutMode = &_playoutModeB;
1001 bgnMode = &_bgnModeB;
1002 break;
1003 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001004 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001005 receiveACM = _acmA;
1006 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001007
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001008 int32_t receiveFreqHz = receiveACM->ReceiveFrequency();
1009 int32_t playoutFreqHz = receiveACM->PlayoutFrequency();
1010
1011 CHECK_ERROR_MT(receiveFreqHz);
1012 CHECK_ERROR_MT(playoutFreqHz);
1013
1014 char bgnString[25];
1015 switch (*bgnMode) {
1016 case On: {
1017 *bgnMode = Fade;
1018 strncpy(bgnString, "Fade", 25);
1019 break;
1020 }
1021 case Fade: {
1022 *bgnMode = Off;
1023 strncpy(bgnString, "OFF", 25);
1024 break;
1025 }
1026 case Off: {
1027 *bgnMode = On;
1028 strncpy(bgnString, "ON", 25);
1029 break;
1030 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001031 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001032 *bgnMode = On;
1033 strncpy(bgnString, "ON", 25);
1034 }
1035 CHECK_ERROR_MT(receiveACM->SetBackgroundNoiseMode(*bgnMode));
1036 bgnString[24] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +00001037
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001038 char playoutString[25];
1039 switch (*playoutMode) {
1040 case voice: {
1041 *playoutMode = fax;
1042 strncpy(playoutString, "FAX", 25);
1043 break;
niklase@google.com470e71d2011-07-07 08:21:25 +00001044 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001045 case fax: {
1046 *playoutMode = streaming;
1047 strncpy(playoutString, "Streaming", 25);
1048 break;
1049 }
1050 case streaming: {
1051 *playoutMode = voice;
1052 strncpy(playoutString, "Voice", 25);
1053 break;
1054 }
1055 default:
1056 *playoutMode = voice;
1057 strncpy(playoutString, "Voice", 25);
1058 }
1059 CHECK_ERROR_MT(receiveACM->SetPlayoutMode(*playoutMode));
1060 playoutString[24] = '\0';
1061
1062 if (!_randomTest) {
1063 fprintf(stdout, "\n");
1064 fprintf(stdout, "In Side %c\n", receiveSide);
1065 fprintf(stdout, "---------------------------------\n");
1066 fprintf(stdout, "Receive Frequency....... %d Hz\n", receiveFreqHz);
1067 fprintf(stdout, "Playout Frequency....... %d Hz\n", playoutFreqHz);
1068 fprintf(stdout, "Audio Playout Mode...... %s\n", playoutString);
1069 fprintf(stdout, "Background Noise Mode... %s\n", bgnString);
1070 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001071}
1072
1073// set/get receiver VAD status & mode.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001074void APITest::TestReceiverVAD(char side) {
1075 AudioCodingModule* myACM;
1076 int* myReceiveVADActivity;
niklase@google.com470e71d2011-07-07 08:21:25 +00001077
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001078 if (side == 'A') {
1079 myACM = _acmA;
1080 myReceiveVADActivity = _receiveVADActivityA;
1081 } else {
1082 myACM = _acmB;
1083 myReceiveVADActivity = _receiveVADActivityB;
1084 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001085
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001086 ACMVADMode mode = myACM->ReceiveVADMode();
niklase@google.com470e71d2011-07-07 08:21:25 +00001087
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001088 CHECK_ERROR_MT(mode);
niklase@google.com470e71d2011-07-07 08:21:25 +00001089
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001090 if (!_randomTest) {
1091 fprintf(stdout, "\n\nCurrent Receive VAD at side %c\n", side);
1092 fprintf(stdout, "----------------------------------\n");
1093 fprintf(stdout, "mode.......... %d\n", (int) mode);
1094 fprintf(stdout, "VAD Active.... %d\n", myReceiveVADActivity[0]);
1095 fprintf(stdout, "VAD Passive... %d\n", myReceiveVADActivity[1]);
1096 fprintf(stdout, "VAD Unknown... %d\n", myReceiveVADActivity[2]);
1097 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001098
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001099 if (!_randomTest) {
1100 fprintf(stdout, "\nChange Receive VAD at side %c\n\n", side);
1101 }
henrike@webrtc.org26d36672011-11-07 23:24:40 +00001102
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001103 switch (mode) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001104 case VADNormal:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001105 mode = VADAggr;
1106 break;
niklase@google.com470e71d2011-07-07 08:21:25 +00001107 case VADLowBitrate:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001108 mode = VADVeryAggr;
1109 break;
niklase@google.com470e71d2011-07-07 08:21:25 +00001110 case VADAggr:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001111 mode = VADLowBitrate;
1112 break;
niklase@google.com470e71d2011-07-07 08:21:25 +00001113 case VADVeryAggr:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001114 mode = VADNormal;
1115 break;
niklase@google.com470e71d2011-07-07 08:21:25 +00001116 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001117 mode = VADNormal;
niklase@google.com470e71d2011-07-07 08:21:25 +00001118
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001119 CHECK_ERROR_MT(myACM->SetReceiveVADMode(mode));
1120 }
1121 for (int n = 0; n < 3; n++) {
1122 myReceiveVADActivity[n] = 0;
1123 }
1124}
niklase@google.com470e71d2011-07-07 08:21:25 +00001125
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001126void APITest::TestSendVAD(char side) {
1127 if (_randomTest) {
1128 return;
1129 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001130
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001131 bool* vad;
1132 bool* dtx;
1133 ACMVADMode* mode;
1134 Channel* myChannel;
1135 AudioCodingModule* myACM;
niklase@google.com470e71d2011-07-07 08:21:25 +00001136
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001137 CodecInst myCodec;
1138 if (!_randomTest) {
1139 fprintf(stdout, "\n\n");
1140 fprintf(stdout, "-----------------------------------------------\n");
1141 fprintf(stdout, " Test VAD API\n");
1142 fprintf(stdout, "-----------------------------------------------\n");
1143 }
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +00001144
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001145 if (side == 'A') {
1146 AudioCodingModule::Codec(_codecCntrA, &myCodec);
1147 vad = &_sendVADA;
1148 dtx = &_sendDTXA;
1149 mode = &_sendVADModeA;
1150 myChannel = _channel_A2B;
1151 myACM = _acmA;
1152 } else {
1153 AudioCodingModule::Codec(_codecCntrB, &myCodec);
1154 vad = &_sendVADB;
1155 dtx = &_sendDTXB;
1156 mode = &_sendVADModeB;
1157 myChannel = _channel_B2A;
1158 myACM = _acmB;
1159 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001160
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001161 CheckVADStatus(side);
1162 if (!_randomTest) {
1163 fprintf(stdout, "\n\n");
1164 }
1165
1166 switch (*mode) {
1167 case VADNormal:
1168 *vad = true;
1169 *dtx = true;
1170 *mode = VADAggr;
1171 break;
1172 case VADLowBitrate:
1173 *vad = true;
1174 *dtx = true;
1175 *mode = VADVeryAggr;
1176 break;
1177 case VADAggr:
1178 *vad = true;
1179 *dtx = true;
1180 *mode = VADLowBitrate;
1181 break;
1182 case VADVeryAggr:
1183 *vad = false;
1184 *dtx = false;
1185 *mode = VADNormal;
1186 break;
1187 default:
1188 *mode = VADNormal;
1189 }
1190
1191 *dtx = (myCodec.plfreq == 32000) ? false : *dtx;
1192
1193 CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode));
1194 myChannel->ResetStats();
1195
1196 CheckVADStatus(side);
1197 if (!_randomTest) {
1198 fprintf(stdout, "\n");
1199 fprintf(stdout, "-----------------------------------------------\n");
1200 }
1201
1202 // Fault Test
1203 CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) - 1));
1204 CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) 4));
niklase@google.com470e71d2011-07-07 08:21:25 +00001205
1206}
1207
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001208void APITest::CurrentCodec(char side) {
1209 CodecInst myCodec;
1210 if (side == 'A') {
1211 _acmA->SendCodec(&myCodec);
1212 } else {
1213 _acmB->SendCodec(&myCodec);
1214 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001215
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001216 if (!_randomTest) {
1217 fprintf(stdout, "\n\n");
1218 fprintf(stdout, "Send codec in Side A\n");
1219 fprintf(stdout, "----------------------------\n");
1220 fprintf(stdout, "Name................. %s\n", myCodec.plname);
1221 fprintf(stdout, "Sampling Frequency... %d\n", myCodec.plfreq);
1222 fprintf(stdout, "Rate................. %d\n", myCodec.rate);
1223 fprintf(stdout, "Payload-type......... %d\n", myCodec.pltype);
1224 fprintf(stdout, "Packet-size.......... %d\n", myCodec.pacsize);
1225 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001226
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001227 Wait(100);
niklase@google.com470e71d2011-07-07 08:21:25 +00001228}
1229
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001230void APITest::ChangeCodec(char side) {
1231 CodecInst myCodec;
1232 AudioCodingModule* myACM;
1233 uint8_t* codecCntr;
1234 bool* thereIsEncoder;
1235 bool* vad;
1236 bool* dtx;
1237 ACMVADMode* mode;
1238 Channel* myChannel;
1239 // Reset and Wait
1240 if (!_randomTest) {
1241 fprintf(stdout, "Reset Encoder Side A \n");
1242 }
1243 if (side == 'A') {
1244 myACM = _acmA;
1245 codecCntr = &_codecCntrA;
niklase@google.com470e71d2011-07-07 08:21:25 +00001246 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001247 WriteLockScoped wl(_apiTestRWLock);
1248 thereIsEncoder = &_thereIsEncoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +00001249 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001250 vad = &_sendVADA;
1251 dtx = &_sendDTXA;
1252 mode = &_sendVADModeA;
1253 myChannel = _channel_A2B;
1254 } else {
1255 myACM = _acmB;
1256 codecCntr = &_codecCntrB;
niklase@google.com470e71d2011-07-07 08:21:25 +00001257 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001258 WriteLockScoped wl(_apiTestRWLock);
1259 thereIsEncoder = &_thereIsEncoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +00001260 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001261 vad = &_sendVADB;
1262 dtx = &_sendDTXB;
1263 mode = &_sendVADModeB;
1264 myChannel = _channel_B2A;
1265 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001266
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001267 myACM->ResetEncoder();
1268 Wait(100);
niklase@google.com470e71d2011-07-07 08:21:25 +00001269
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001270 // Register the next codec
1271 do {
1272 *codecCntr =
1273 (*codecCntr < AudioCodingModule::NumberOfCodecs() - 1) ?
1274 (*codecCntr + 1) : 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001275
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001276 if (*codecCntr == 0) {
1277 //printf("Initialize Sender Side A \n");
1278 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001279 WriteLockScoped wl(_apiTestRWLock);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001280 *thereIsEncoder = false;
1281 }
1282 CHECK_ERROR_MT(myACM->InitializeSender());
1283 Wait(1000);
1284
1285 // After Initialization CN is lost, re-register them
1286 if (AudioCodingModule::Codec("CN", &myCodec, 8000, 1) >= 0) {
1287 CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec));
1288 }
1289 if (AudioCodingModule::Codec("CN", &myCodec, 16000, 1) >= 0) {
1290 CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec));
1291 }
1292 // VAD & DTX are disabled after initialization
1293 *vad = false;
1294 *dtx = false;
1295 _writeToFile = false;
niklase@google.com470e71d2011-07-07 08:21:25 +00001296 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001297
1298 AudioCodingModule::Codec(*codecCntr, &myCodec);
1299 } while (!STR_CASE_CMP(myCodec.plname, "CN")
1300 || !STR_CASE_CMP(myCodec.plname, "telephone-event")
1301 || !STR_CASE_CMP(myCodec.plname, "RED"));
1302
1303 if (!_randomTest) {
1304 fprintf(stdout,"\n=====================================================\n");
1305 fprintf(stdout, " Registering New Codec %s, %d kHz, %d kbps\n",
1306 myCodec.plname, myCodec.plfreq / 1000, myCodec.rate / 1000);
1307 }
1308 //std::cout<< std::flush;
1309
1310 // NO DTX for supe-wideband codec at this point
1311 if (myCodec.plfreq == 32000) {
1312 *dtx = false;
1313 CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode));
1314
1315 }
1316
1317 CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec));
1318 myChannel->ResetStats();
1319 {
1320 WriteLockScoped wl(_apiTestRWLock);
1321 *thereIsEncoder = true;
1322 }
1323 Wait(500);
niklase@google.com470e71d2011-07-07 08:21:25 +00001324}
1325
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001326void APITest::LookForDTMF(char side) {
1327 if (!_randomTest) {
1328 fprintf(stdout, "\n\nLooking for DTMF Signal in Side %c\n", side);
1329 fprintf(stdout, "----------------------------------------\n");
1330 }
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +00001331
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001332 if (side == 'A') {
1333 _acmB->RegisterIncomingMessagesCallback(NULL);
1334 _acmA->RegisterIncomingMessagesCallback(_dtmfCallback);
1335 Wait(1000);
1336 _acmA->RegisterIncomingMessagesCallback(NULL);
1337 } else {
1338 _acmA->RegisterIncomingMessagesCallback(NULL);
1339 _acmB->RegisterIncomingMessagesCallback(_dtmfCallback);
1340 Wait(1000);
1341 _acmB->RegisterIncomingMessagesCallback(NULL);
1342 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001343}
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +00001344
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001345} // namespace webrtc