blob: cb7115ecc2b760a9e51aad3fb01dd1fbea4dd3bc [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"
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +000025#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000026#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()
andrew@webrtc.org89df0922013-09-12 01:27:43 +000058 : _acmA(AudioCodingModule::Create(1)),
59 _acmB(AudioCodingModule::Create(2)),
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000060 _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
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000101 for (n = 0; n < 3; n++) {
102 _receiveVADActivityA[n] = 0;
103 _receiveVADActivityB[n] = 0;
104 }
105
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() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000114 DELETE_POINTER(_channel_A2B);
115 DELETE_POINTER(_channel_B2A);
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000117 DELETE_POINTER(_pushEventA);
118 DELETE_POINTER(_pullEventA);
119 DELETE_POINTER(_processEventA);
120 DELETE_POINTER(_apiEventA);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000122 DELETE_POINTER(_pushEventB);
123 DELETE_POINTER(_pullEventB);
124 DELETE_POINTER(_processEventB);
125 DELETE_POINTER(_apiEventB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000127 _inFileA.Close();
128 _outFileA.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000130 _inFileB.Close();
131 _outFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000133 DELETE_POINTER(_dtmfCallback);
134 DELETE_POINTER(_vadCallbackA);
135 DELETE_POINTER(_vadCallbackB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000137 delete &_apiTestRWLock;
niklase@google.com470e71d2011-07-07 08:21:25 +0000138}
139
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000140int16_t APITest::SetUp() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000141 CodecInst dummyCodec;
142 int lastPayloadType = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000144 int16_t numCodecs = _acmA->NumberOfCodecs();
145 for (uint8_t n = 0; n < numCodecs; n++) {
146 AudioCodingModule::Codec(n, &dummyCodec);
147 if ((STR_CASE_CMP(dummyCodec.plname, "CN") == 0)
148 && (dummyCodec.plfreq == 32000)) {
149 continue;
niklase@google.com470e71d2011-07-07 08:21:25 +0000150 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000151
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000152 printf("Register Receive Codec %s ", dummyCodec.plname);
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000154 if ((n != 0) && !FixedPayloadTypeCodec(dummyCodec.plname)) {
155 // Check registration with an already occupied payload type
156 int currentPayloadType = dummyCodec.pltype;
157 dummyCodec.pltype = 97; //lastPayloadType;
158 CHECK_ERROR(_acmB->RegisterReceiveCodec(dummyCodec));
159 dummyCodec.pltype = currentPayloadType;
160 }
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000161
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000162 if ((n < numCodecs - 1) && !FixedPayloadTypeCodec(dummyCodec.plname)) {
163 // test if re-registration works;
164 CodecInst nextCodec;
165 int currentPayloadType = dummyCodec.pltype;
166 AudioCodingModule::Codec(n + 1, &nextCodec);
167 dummyCodec.pltype = nextCodec.pltype;
168 if (!FixedPayloadTypeCodec(nextCodec.plname)) {
169 _acmB->RegisterReceiveCodec(dummyCodec);
170 }
171 dummyCodec.pltype = currentPayloadType;
172 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000174 if ((n < numCodecs - 1) && !FixedPayloadTypeCodec(dummyCodec.plname)) {
175 // test if un-registration works;
176 CodecInst nextCodec;
177 AudioCodingModule::Codec(n + 1, &nextCodec);
178 nextCodec.pltype = dummyCodec.pltype;
179 if (!FixedPayloadTypeCodec(nextCodec.plname)) {
180 CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(nextCodec));
181 CHECK_ERROR_MT(_acmA->UnregisterReceiveCodec(nextCodec.pltype));
182 }
183 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000184
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000185 CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(dummyCodec));
186 printf(" side A done!");
187 CHECK_ERROR_MT(_acmB->RegisterReceiveCodec(dummyCodec));
188 printf(" side B done!\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000190 if (!strcmp(dummyCodec.plname, "CN")) {
191 CHECK_ERROR_MT(_acmA->RegisterSendCodec(dummyCodec));
192 CHECK_ERROR_MT(_acmB->RegisterSendCodec(dummyCodec));
193 }
194 lastPayloadType = dummyCodec.pltype;
195 if ((lastPayloadType >= 96) && (lastPayloadType <= 127)) {
196 _payloadUsed[lastPayloadType - 96] = true;
197 }
198 }
199 _thereIsDecoderA = true;
200 _thereIsDecoderB = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000202 // Register Send Codec
203 AudioCodingModule::Codec((uint8_t) _codecCntrA, &dummyCodec);
204 CHECK_ERROR_MT(_acmA->RegisterSendCodec(dummyCodec));
205 _thereIsEncoderA = true;
206 //
207 AudioCodingModule::Codec((uint8_t) _codecCntrB, &dummyCodec);
208 CHECK_ERROR_MT(_acmB->RegisterSendCodec(dummyCodec));
209 _thereIsEncoderB = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000211 uint16_t frequencyHz;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000213 printf("\n\nAPI Test\n");
214 printf("========\n");
215 printf("Hit enter to accept the default values indicated in []\n\n");
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000216
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000217 //--- Input A
218 std::string file_name = webrtc::test::ResourcePath(
219 "audio_coding/testfile32kHz", "pcm");
220 frequencyHz = 32000;
221 printf("Enter input file at side A [%s]: ", file_name.c_str());
222 PCMFile::ChooseFile(&file_name, 499, &frequencyHz);
223 _inFileA.Open(file_name, frequencyHz, "rb", true);
niklase@google.com470e71d2011-07-07 08:21:25 +0000224
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000225 //--- Output A
226 std::string out_file_a = webrtc::test::OutputPath() + "outA.pcm";
227 printf("Enter output file at side A [%s]: ", out_file_a.c_str());
228 PCMFile::ChooseFile(&out_file_a, 499, &frequencyHz);
229 _outFileA.Open(out_file_a, frequencyHz, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000231 //--- Input B
232 file_name = webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
233 printf("\n\nEnter input file at side B [%s]: ", file_name.c_str());
234 PCMFile::ChooseFile(&file_name, 499, &frequencyHz);
235 _inFileB.Open(file_name, frequencyHz, "rb", true);
niklase@google.com470e71d2011-07-07 08:21:25 +0000236
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000237 //--- Output B
238 std::string out_file_b = webrtc::test::OutputPath() + "outB.pcm";
239 printf("Enter output file at side B [%s]: ", out_file_b.c_str());
240 PCMFile::ChooseFile(&out_file_b, 499, &frequencyHz);
241 _outFileB.Open(out_file_b, frequencyHz, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000243 //--- Set A-to-B channel
244 _channel_A2B = new Channel(2);
245 CHECK_ERROR_MT(_acmA->RegisterTransportCallback(_channel_A2B));
246 _channel_A2B->RegisterReceiverACM(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000247
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000248 //--- Set B-to-A channel
249 _channel_B2A = new Channel(1);
250 CHECK_ERROR_MT(_acmB->RegisterTransportCallback(_channel_B2A));
251 _channel_B2A->RegisterReceiverACM(_acmA);
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000252
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000253 //--- EVENT TIMERS
254 // A
255 _pullEventA = EventWrapper::Create();
256 _pushEventA = EventWrapper::Create();
257 _processEventA = EventWrapper::Create();
258 _apiEventA = EventWrapper::Create();
259 // B
260 _pullEventB = EventWrapper::Create();
261 _pushEventB = EventWrapper::Create();
262 _processEventB = EventWrapper::Create();
263 _apiEventB = EventWrapper::Create();
264
265 //--- I/O params
266 // A
267 _outFreqHzA = _outFileA.SamplingFrequency();
268 // B
269 _outFreqHzB = _outFileB.SamplingFrequency();
270
271 //Trace::SetEncryptedTraceFile("ACMAPITestEncrypted.txt");
272
273 char print[11];
274
275 // Create a trace file.
276 Trace::CreateTrace();
277 Trace::SetTraceFile(
278 (webrtc::test::OutputPath() + "acm_api_trace.txt").c_str());
279
280 printf("\nRandom Test (y/n)?");
281 EXPECT_TRUE(fgets(print, 10, stdin) != NULL);
282 print[10] = '\0';
283 if (strstr(print, "y") != NULL) {
284 _randomTest = true;
285 _verbose = false;
286 _writeToFile = false;
287 } else {
288 _randomTest = false;
289 printf("\nPrint Tests (y/n)? ");
kjellander@webrtc.org543c3ea2011-11-23 12:20:35 +0000290 EXPECT_TRUE(fgets(print, 10, stdin) != NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000291 print[10] = '\0';
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000292 if (strstr(print, "y") == NULL) {
293 EXPECT_TRUE(freopen("APITest_log.txt", "w", stdout) != 0);
294 _verbose = false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000295 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000296 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000297
298#ifdef WEBRTC_DTMF_DETECTION
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000299 _dtmfCallback = new DTMFDetector;
niklase@google.com470e71d2011-07-07 08:21:25 +0000300#endif
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000301 _vadCallbackA = new VADCallback;
302 _vadCallbackB = new VADCallback;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000303
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000304 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000305}
306
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000307bool APITest::PushAudioThreadA(void* obj) {
308 return static_cast<APITest*>(obj)->PushAudioRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000309}
310
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000311bool APITest::PushAudioThreadB(void* obj) {
312 return static_cast<APITest*>(obj)->PushAudioRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000313}
314
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000315bool APITest::PullAudioThreadA(void* obj) {
316 return static_cast<APITest*>(obj)->PullAudioRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000317}
318
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000319bool APITest::PullAudioThreadB(void* obj) {
320 return static_cast<APITest*>(obj)->PullAudioRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000321}
322
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000323bool APITest::ProcessThreadA(void* obj) {
324 return static_cast<APITest*>(obj)->ProcessRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000325}
326
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000327bool APITest::ProcessThreadB(void* obj) {
328 return static_cast<APITest*>(obj)->ProcessRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000329}
330
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000331bool APITest::APIThreadA(void* obj) {
332 return static_cast<APITest*>(obj)->APIRunA();
niklase@google.com470e71d2011-07-07 08:21:25 +0000333}
334
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000335bool APITest::APIThreadB(void* obj) {
336 return static_cast<APITest*>(obj)->APIRunB();
niklase@google.com470e71d2011-07-07 08:21:25 +0000337}
338
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000339bool APITest::PullAudioRunA() {
340 _pullEventA->Wait(100);
341 AudioFrame audioFrame;
342 if (_acmA->PlayoutData10Ms(_outFreqHzA, &audioFrame) < 0) {
343 bool thereIsDecoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000344 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000345 ReadLockScoped rl(_apiTestRWLock);
346 thereIsDecoder = _thereIsDecoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000347 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000348 if (thereIsDecoder) {
349 fprintf(stderr, "\n>>>>>> cannot pull audio A <<<<<<<< \n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000350 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000351 } else {
352 if (_writeToFile) {
353 _outFileA.Write10MsData(audioFrame);
354 }
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000355 _receiveVADActivityA[(int) audioFrame.vad_activity_]++;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000356 }
357 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000358}
359
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000360bool APITest::PullAudioRunB() {
361 _pullEventB->Wait(100);
362 AudioFrame audioFrame;
363 if (_acmB->PlayoutData10Ms(_outFreqHzB, &audioFrame) < 0) {
364 bool thereIsDecoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000365 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000366 ReadLockScoped rl(_apiTestRWLock);
367 thereIsDecoder = _thereIsDecoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000368 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000369 if (thereIsDecoder) {
370 fprintf(stderr, "\n>>>>>> cannot pull audio B <<<<<<<< \n");
371 fprintf(stderr, "%d %d\n", _testNumA, _testNumB);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000372 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000373 } else {
374 if (_writeToFile) {
375 _outFileB.Write10MsData(audioFrame);
376 }
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000377 _receiveVADActivityB[(int) audioFrame.vad_activity_]++;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000378 }
379 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000380}
381
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000382bool APITest::PushAudioRunA() {
383 _pushEventA->Wait(100);
384 AudioFrame audioFrame;
385 _inFileA.Read10MsData(audioFrame);
386 if (_acmA->Add10MsData(audioFrame) < 0) {
387 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000388 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000389 ReadLockScoped rl(_apiTestRWLock);
390 thereIsEncoder = _thereIsEncoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000391 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000392 if (thereIsEncoder) {
393 fprintf(stderr, "\n>>>> add10MsData at A failed <<<<\n");
394 }
395 }
396 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000397}
398
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000399bool APITest::PushAudioRunB() {
400 _pushEventB->Wait(100);
401 AudioFrame audioFrame;
402 _inFileB.Read10MsData(audioFrame);
403 if (_acmB->Add10MsData(audioFrame) < 0) {
404 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000405 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000406 ReadLockScoped rl(_apiTestRWLock);
407 thereIsEncoder = _thereIsEncoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000408 }
409
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000410 if (thereIsEncoder) {
411 fprintf(stderr, "\n>>>> cannot add audio to B <<<<");
412 }
413 }
414
415 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000416}
417
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000418bool APITest::ProcessRunA() {
419 _processEventA->Wait(100);
420 if (_acmA->Process() < 0) {
421 // do not print error message if there is no encoder
422 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000423 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000424 ReadLockScoped rl(_apiTestRWLock);
425 thereIsEncoder = _thereIsEncoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000426 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000427
428 if (thereIsEncoder) {
429 fprintf(stderr, "\n>>>>> Process Failed at A <<<<<\n");
430 }
431 }
432 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000433}
434
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000435bool APITest::ProcessRunB() {
436 _processEventB->Wait(100);
437 if (_acmB->Process() < 0) {
438 bool thereIsEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000439 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000440 ReadLockScoped rl(_apiTestRWLock);
441 thereIsEncoder = _thereIsEncoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000442 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000443 if (thereIsEncoder) {
444 fprintf(stderr, "\n>>>>> Process Failed at B <<<<<\n");
445 }
446 }
447 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000448}
449
450/*/
451 *
452 * In side A we test the APIs which are related to sender Side.
453 *
454/*/
455
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000456void APITest::RunTest(char thread) {
457 int testNum;
458 {
459 WriteLockScoped cs(_apiTestRWLock);
460 if (thread == 'A') {
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000461 _testNumA = (_testNumB + 1 + (rand() % 6)) % 7;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000462 testNum = _testNumA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000463
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000464 _movingDot[_dotPositionA] = ' ';
465 if (_dotPositionA == 0) {
466 _dotMoveDirectionA = 1;
467 }
468 if (_dotPositionA == 19) {
469 _dotMoveDirectionA = -1;
470 }
471 _dotPositionA += _dotMoveDirectionA;
472 _movingDot[_dotPositionA] = (_dotMoveDirectionA > 0) ? '>' : '<';
473 } else {
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000474 _testNumB = (_testNumA + 1 + (rand() % 6)) % 7;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000475 testNum = _testNumB;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000476
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000477 _movingDot[_dotPositionB] = ' ';
478 if (_dotPositionB == 20) {
479 _dotMoveDirectionB = 1;
480 }
481 if (_dotPositionB == 39) {
482 _dotMoveDirectionB = -1;
483 }
484 _dotPositionB += _dotMoveDirectionB;
485 _movingDot[_dotPositionB] = (_dotMoveDirectionB > 0) ? '>' : '<';
niklase@google.com470e71d2011-07-07 08:21:25 +0000486 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000487 //fprintf(stderr, "%c: %d \n", thread, testNum);
488 //fflush(stderr);
489 }
490 switch (testNum) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000491 case 0:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000492 CurrentCodec('A');
493 ChangeCodec('A');
494 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000495 case 1:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000496 TestPlayout('B');
497 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000498 case 2:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000499 if (!_randomTest) {
500 fprintf(stdout, "\nTesting Delay ...\n");
501 }
502 TestDelay('A');
503 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000504 case 3:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000505 TestSendVAD('A');
506 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000507 case 4:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000508 TestRegisteration('A');
509 break;
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000510 case 5:
511 TestReceiverVAD('A');
512 break;
513 case 6:
514#ifdef WEBRTC_DTMF_DETECTION
515 LookForDTMF('A');
516#endif
517 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000518 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000519 fprintf(stderr, "Wrong Test Number\n");
520 getchar();
521 exit(1);
522 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000523}
524
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000525bool APITest::APIRunA() {
526 _apiEventA->Wait(50);
niklase@google.com470e71d2011-07-07 08:21:25 +0000527
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000528 bool randomTest;
529 {
530 ReadLockScoped rl(_apiTestRWLock);
531 randomTest = _randomTest;
532 }
533 if (randomTest) {
534 RunTest('A');
535 } else {
536 CurrentCodec('A');
537 ChangeCodec('A');
538 TestPlayout('B');
539 if (_codecCntrA == 0) {
540 fprintf(stdout, "\nTesting Delay ...\n");
541 TestDelay('A');
niklase@google.com470e71d2011-07-07 08:21:25 +0000542 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000543 // VAD TEST
544 TestSendVAD('A');
545 TestRegisteration('A');
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000546 TestReceiverVAD('A');
547#ifdef WEBRTC_DTMF_DETECTION
548 LookForDTMF('A');
549#endif
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000550 }
551 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000552}
553
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000554bool APITest::APIRunB() {
555 _apiEventB->Wait(50);
556 bool randomTest;
557 {
558 ReadLockScoped rl(_apiTestRWLock);
559 randomTest = _randomTest;
560 }
561 //_apiEventB->Wait(2000);
562 if (randomTest) {
563 RunTest('B');
564 }
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000565
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000566 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000567}
568
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000569void APITest::Perform() {
570 SetUp();
niklase@google.com470e71d2011-07-07 08:21:25 +0000571
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000572 //--- THREADS
573 // A
574 // PUSH
575 ThreadWrapper* myPushAudioThreadA = ThreadWrapper::CreateThread(
576 PushAudioThreadA, this, kNormalPriority, "PushAudioThreadA");
577 CHECK_THREAD_NULLITY(myPushAudioThreadA, "Unable to start A::PUSH thread");
578 // PULL
579 ThreadWrapper* myPullAudioThreadA = ThreadWrapper::CreateThread(
580 PullAudioThreadA, this, kNormalPriority, "PullAudioThreadA");
581 CHECK_THREAD_NULLITY(myPullAudioThreadA, "Unable to start A::PULL thread");
582 // Process
583 ThreadWrapper* myProcessThreadA = ThreadWrapper::CreateThread(
584 ProcessThreadA, this, kNormalPriority, "ProcessThreadA");
585 CHECK_THREAD_NULLITY(myProcessThreadA, "Unable to start A::Process thread");
586 // API
587 ThreadWrapper* myAPIThreadA = ThreadWrapper::CreateThread(APIThreadA, this,
588 kNormalPriority,
589 "APIThreadA");
590 CHECK_THREAD_NULLITY(myAPIThreadA, "Unable to start A::API thread");
591 // B
592 // PUSH
593 ThreadWrapper* myPushAudioThreadB = ThreadWrapper::CreateThread(
594 PushAudioThreadB, this, kNormalPriority, "PushAudioThreadB");
595 CHECK_THREAD_NULLITY(myPushAudioThreadB, "Unable to start B::PUSH thread");
596 // PULL
597 ThreadWrapper* myPullAudioThreadB = ThreadWrapper::CreateThread(
598 PullAudioThreadB, this, kNormalPriority, "PullAudioThreadB");
599 CHECK_THREAD_NULLITY(myPullAudioThreadB, "Unable to start B::PULL thread");
600 // Process
601 ThreadWrapper* myProcessThreadB = ThreadWrapper::CreateThread(
602 ProcessThreadB, this, kNormalPriority, "ProcessThreadB");
603 CHECK_THREAD_NULLITY(myProcessThreadB, "Unable to start B::Process thread");
604 // API
605 ThreadWrapper* myAPIThreadB = ThreadWrapper::CreateThread(APIThreadB, this,
606 kNormalPriority,
607 "APIThreadB");
608 CHECK_THREAD_NULLITY(myAPIThreadB, "Unable to start B::API thread");
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000609
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000610 //_apiEventA->StartTimer(true, 5000);
611 //_apiEventB->StartTimer(true, 5000);
niklase@google.com470e71d2011-07-07 08:21:25 +0000612
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000613 _processEventA->StartTimer(true, 10);
614 _processEventB->StartTimer(true, 10);
niklase@google.com470e71d2011-07-07 08:21:25 +0000615
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000616 _pullEventA->StartTimer(true, 10);
617 _pullEventB->StartTimer(true, 10);
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000618
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000619 _pushEventA->StartTimer(true, 10);
620 _pushEventB->StartTimer(true, 10);
niklase@google.com470e71d2011-07-07 08:21:25 +0000621
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000622 // Keep main thread waiting for sender/receiver
623 // threads to complete
624 EventWrapper* completeEvent = EventWrapper::Create();
625 uint64_t startTime = TickTime::MillisecondTimestamp();
626 uint64_t currentTime;
627 // Run test in 2 minutes (120000 ms).
628 do {
niklase@google.com470e71d2011-07-07 08:21:25 +0000629 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000630 //ReadLockScoped rl(_apiTestRWLock);
631 //fprintf(stderr, "\r%s", _movingDot);
632 }
633 //fflush(stderr);
634 completeEvent->Wait(50);
635 currentTime = TickTime::MillisecondTimestamp();
636 } while ((currentTime - startTime) < 120000);
niklase@google.com470e71d2011-07-07 08:21:25 +0000637
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000638 //completeEvent->Wait(0xFFFFFFFF);
639 //(unsigned long)((unsigned long)TEST_DURATION_SEC * (unsigned long)1000));
640 delete completeEvent;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000641
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000642 myPushAudioThreadA->Stop();
643 myPullAudioThreadA->Stop();
644 myProcessThreadA->Stop();
645 myAPIThreadA->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +0000646
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000647 delete myPushAudioThreadA;
648 delete myPullAudioThreadA;
649 delete myProcessThreadA;
650 delete myAPIThreadA;
niklase@google.com470e71d2011-07-07 08:21:25 +0000651
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000652 myPushAudioThreadB->Stop();
653 myPullAudioThreadB->Stop();
654 myProcessThreadB->Stop();
655 myAPIThreadB->Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +0000656
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000657 delete myPushAudioThreadB;
658 delete myPullAudioThreadB;
659 delete myProcessThreadB;
660 delete myAPIThreadB;
niklase@google.com470e71d2011-07-07 08:21:25 +0000661}
662
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000663void APITest::CheckVADStatus(char side) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000664
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000665 bool dtxEnabled;
666 bool vadEnabled;
667 ACMVADMode vadMode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000668
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000669 if (side == 'A') {
670 _acmA->VAD(&dtxEnabled, &vadEnabled, &vadMode);
671 _acmA->RegisterVADCallback(NULL);
672 _vadCallbackA->Reset();
673 _acmA->RegisterVADCallback(_vadCallbackA);
tina.legrand@webrtc.org2e096922011-08-18 06:20:30 +0000674
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000675 if (!_randomTest) {
676 if (_verbose) {
677 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d", dtxEnabled ? "ON" : "OFF",
678 vadEnabled ? "ON" : "OFF", (int) vadMode);
679 Wait(5000);
680 fprintf(stdout, " => bit-rate %3.0f kbps\n", _channel_A2B->BitRate());
681 } else {
682 Wait(5000);
683 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d => bit-rate %3.0f kbps\n",
684 dtxEnabled ? "ON" : "OFF", vadEnabled ? "ON" : "OFF",
685 (int) vadMode, _channel_A2B->BitRate());
686 }
687 _vadCallbackA->PrintFrameTypes();
niklase@google.com470e71d2011-07-07 08:21:25 +0000688 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000689
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000690 if (dtxEnabled != _sendDTXA) {
691 fprintf(stderr, ">>> Error Enabling DTX <<<\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000692 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000693 if ((vadEnabled != _sendVADA) && (!dtxEnabled)) {
694 fprintf(stderr, ">>> Error Enabling VAD <<<\n");
695 }
696 if ((vadMode != _sendVADModeA) && vadEnabled) {
697 fprintf(stderr, ">>> Error setting VAD-mode <<<\n");
698 }
699 } else {
700 _acmB->VAD(&dtxEnabled, &vadEnabled, &vadMode);
701
702 _acmB->RegisterVADCallback(NULL);
703 _vadCallbackB->Reset();
704 _acmB->RegisterVADCallback(_vadCallbackB);
705
706 if (!_randomTest) {
707 if (_verbose) {
708 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d", dtxEnabled ? "ON" : "OFF",
709 vadEnabled ? "ON" : "OFF", (int) vadMode);
710 Wait(5000);
711 fprintf(stdout, " => bit-rate %3.0f kbps\n", _channel_B2A->BitRate());
712 } else {
713 Wait(5000);
714 fprintf(stdout, "DTX %3s, VAD %3s, Mode %d => bit-rate %3.0f kbps\n",
715 dtxEnabled ? "ON" : "OFF", vadEnabled ? "ON" : "OFF",
716 (int) vadMode, _channel_B2A->BitRate());
717 }
718 _vadCallbackB->PrintFrameTypes();
719 }
720
721 if (dtxEnabled != _sendDTXB) {
722 fprintf(stderr, ">>> Error Enabling DTX <<<\n");
723 }
724 if ((vadEnabled != _sendVADB) && (!dtxEnabled)) {
725 fprintf(stderr, ">>> Error Enabling VAD <<<\n");
726 }
727 if ((vadMode != _sendVADModeB) && vadEnabled) {
728 fprintf(stderr, ">>> Error setting VAD-mode <<<\n");
729 }
730 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000731}
732
733// Set Min delay, get delay, playout timestamp
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000734void APITest::TestDelay(char side) {
735 AudioCodingModule* myACM;
736 Channel* myChannel;
737 int32_t* myMinDelay;
738 EventWrapper* myEvent = EventWrapper::Create();
niklase@google.com470e71d2011-07-07 08:21:25 +0000739
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000740 uint32_t inTimestamp = 0;
741 uint32_t outTimestamp = 0;
742 double estimDelay = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000743
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000744 double averageEstimDelay = 0;
745 double averageDelay = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000746
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000747 CircularBuffer estimDelayCB(100);
748 estimDelayCB.SetArithMean(true);
niklase@google.com470e71d2011-07-07 08:21:25 +0000749
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000750 if (side == 'A') {
751 myACM = _acmA;
752 myChannel = _channel_B2A;
753 myMinDelay = &_minDelayA;
754 } else {
755 myACM = _acmB;
756 myChannel = _channel_A2B;
757 myMinDelay = &_minDelayB;
758 }
759
760 CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay));
761
762 inTimestamp = myChannel->LastInTimestamp();
763 CHECK_ERROR_MT(myACM->PlayoutTimestamp(&outTimestamp));
764
765 if (!_randomTest) {
766 myEvent->StartTimer(true, 30);
767 int n = 0;
768 int settlePoint = 5000;
769 while (n < settlePoint + 400) {
770 myEvent->Wait(1000);
771
772 inTimestamp = myChannel->LastInTimestamp();
773 CHECK_ERROR_MT(myACM->PlayoutTimestamp(&outTimestamp));
774
775 //std::cout << outTimestamp << std::endl << std::flush;
776 estimDelay = (double) ((uint32_t)(inTimestamp - outTimestamp))
777 / ((double) myACM->ReceiveFrequency() / 1000.0);
778
779 estimDelayCB.Update(estimDelay);
780
781 estimDelayCB.ArithMean(averageEstimDelay);
782 //printf("\n %6.1f \n", estimDelay);
783 //std::cout << " " << std::flush;
784
785 if (_verbose) {
786 fprintf(stdout,
787 "\rExpected: %4d, retreived: %6.1f, measured: %6.1f",
788 *myMinDelay, averageDelay, averageEstimDelay);
789 std::cout << " " << std::flush;
790 }
791 if ((averageDelay > *myMinDelay) && (n < settlePoint)) {
792 settlePoint = n;
793 }
794 n++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000795 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000796 myEvent->StopTimer();
797 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000798
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000799 if ((!_verbose) && (!_randomTest)) {
800 fprintf(stdout, "\nExpected: %4d, retreived: %6.1f, measured: %6.1f",
niklase@google.com470e71d2011-07-07 08:21:25 +0000801 *myMinDelay, averageDelay, averageEstimDelay);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000802 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000803
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000804 *myMinDelay = (rand() % 1000) + 1;
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +0000805
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000806 ACMNetworkStatistics networkStat;
807 CHECK_ERROR_MT(myACM->NetworkStatistics(&networkStat));
niklase@google.com470e71d2011-07-07 08:21:25 +0000808
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000809 if (!_randomTest) {
810 fprintf(stdout, "\n\nJitter Statistics at Side %c\n", side);
811 fprintf(stdout, "--------------------------------------\n");
812 fprintf(stdout, "buffer-size............. %d\n",
813 networkStat.currentBufferSize);
814 fprintf(stdout, "Preferred buffer-size... %d\n",
815 networkStat.preferredBufferSize);
816 fprintf(stdout, "Peaky jitter mode........%d\n",
817 networkStat.jitterPeaksFound);
818 fprintf(stdout, "packet-size rate........ %d\n",
819 networkStat.currentPacketLossRate);
820 fprintf(stdout, "discard rate............ %d\n",
821 networkStat.currentDiscardRate);
822 fprintf(stdout, "expand rate............. %d\n",
823 networkStat.currentExpandRate);
824 fprintf(stdout, "Preemptive rate......... %d\n",
825 networkStat.currentPreemptiveRate);
826 fprintf(stdout, "Accelerate rate......... %d\n",
827 networkStat.currentAccelerateRate);
828 fprintf(stdout, "Clock-drift............. %d\n", networkStat.clockDriftPPM);
829 fprintf(stdout, "Mean waiting time....... %d\n",
830 networkStat.meanWaitingTimeMs);
831 fprintf(stdout, "Median waiting time..... %d\n",
832 networkStat.medianWaitingTimeMs);
833 fprintf(stdout, "Min waiting time........ %d\n",
834 networkStat.minWaitingTimeMs);
835 fprintf(stdout, "Max waiting time........ %d\n",
836 networkStat.maxWaitingTimeMs);
837 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000838
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000839 CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay));
niklase@google.com470e71d2011-07-07 08:21:25 +0000840
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000841 if (!_randomTest) {
842 myEvent->Wait(500);
843 fprintf(stdout, "\n");
844 fprintf(stdout, "\n");
845 }
846 delete myEvent;
niklase@google.com470e71d2011-07-07 08:21:25 +0000847}
848
849// Unregister a codec & register again.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000850void APITest::TestRegisteration(char sendSide) {
851 AudioCodingModule* sendACM;
852 AudioCodingModule* receiveACM;
853 bool* thereIsDecoder;
854 EventWrapper* myEvent = EventWrapper::Create();
niklase@google.com470e71d2011-07-07 08:21:25 +0000855
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000856 if (!_randomTest) {
857 fprintf(stdout, "\n\n");
858 fprintf(stdout,
859 "---------------------------------------------------------\n");
860 fprintf(stdout, " Unregister/register Receive Codec\n");
861 fprintf(stdout,
862 "---------------------------------------------------------\n");
863 }
864
865 switch (sendSide) {
866 case 'A': {
867 sendACM = _acmA;
868 receiveACM = _acmB;
869 thereIsDecoder = &_thereIsDecoderB;
870 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000871 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000872 case 'B': {
873 sendACM = _acmB;
874 receiveACM = _acmA;
875 thereIsDecoder = &_thereIsDecoderA;
876 break;
877 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000878 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000879 fprintf(stderr, "Invalid sender-side in TestRegistration(%c)\n",
880 sendSide);
881 exit(-1);
882 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000883
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000884 CodecInst myCodec;
885 if (sendACM->SendCodec(&myCodec) < 0) {
886 AudioCodingModule::Codec(_codecCntrA, &myCodec);
887 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000888
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000889 if (!_randomTest) {
890 fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n");
891 fflush (stdout);
892 }
893 {
894 WriteLockScoped wl(_apiTestRWLock);
895 *thereIsDecoder = false;
896 }
897 //myEvent->Wait(20);
898 CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
899 Wait(1000);
niklase@google.com470e71d2011-07-07 08:21:25 +0000900
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000901 int currentPayload = myCodec.pltype;
niklase@google.com470e71d2011-07-07 08:21:25 +0000902
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000903 if (!FixedPayloadTypeCodec(myCodec.plname)) {
904 int32_t i;
905 for (i = 0; i < 32; i++) {
906 if (!_payloadUsed[i]) {
907 if (!_randomTest) {
908 fprintf(stdout,
909 "Register receive codec with new Payload, AUDIO BACK.\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000910 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000911 //myCodec.pltype = i + 96;
912 //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
913 //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec));
914 //myEvent->Wait(20);
915 //{
916 // WriteLockScoped wl(_apiTestRWLock);
917 // *thereIsDecoder = true;
918 //}
919 Wait(1000);
920
921 if (!_randomTest) {
922 fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000923 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000924 //{
925 // WriteLockScoped wl(_apiTestRWLock);
926 // *thereIsDecoder = false;
927 //}
928 //myEvent->Wait(20);
929 //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
930 Wait(1000);
931
932 myCodec.pltype = currentPayload;
933 if (!_randomTest) {
934 fprintf(stdout,
935 "Register receive codec with default Payload, AUDIO BACK.\n");
936 fflush (stdout);
niklase@google.com470e71d2011-07-07 08:21:25 +0000937 }
938 CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000939 //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +0000940 myEvent->Wait(20);
941 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000942 WriteLockScoped wl(_apiTestRWLock);
943 *thereIsDecoder = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000944 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000945 Wait(1000);
946
947 break;
948 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000949 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000950 if (i == 32) {
951 CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
952 {
953 WriteLockScoped wl(_apiTestRWLock);
954 *thereIsDecoder = true;
955 }
956 }
957 } else {
958 if (!_randomTest) {
959 fprintf(stdout,
960 "Register receive codec with fixed Payload, AUDIO BACK.\n");
961 fflush (stdout);
962 }
963 CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
964 //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
965 //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
966 myEvent->Wait(20);
niklase@google.com470e71d2011-07-07 08:21:25 +0000967 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000968 WriteLockScoped wl(_apiTestRWLock);
969 *thereIsDecoder = true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000970 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000971 }
972 delete myEvent;
973 if (!_randomTest) {
974 fprintf(stdout,
975 "---------------------------------------------------------\n");
976 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000977}
978
979// Playout Mode, background noise mode.
980// Receiver Frequency, playout frequency.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000981void APITest::TestPlayout(char receiveSide) {
982 AudioCodingModule* receiveACM;
983 AudioPlayoutMode* playoutMode = NULL;
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000984 ACMBackgroundNoiseMode* bgnMode = NULL;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000985 switch (receiveSide) {
986 case 'A': {
987 receiveACM = _acmA;
988 playoutMode = &_playoutModeA;
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000989 bgnMode = &_bgnModeA;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000990 break;
niklase@google.com470e71d2011-07-07 08:21:25 +0000991 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000992 case 'B': {
993 receiveACM = _acmB;
994 playoutMode = &_playoutModeB;
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +0000995 bgnMode = &_bgnModeB;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000996 break;
997 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000998 default:
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000999 receiveACM = _acmA;
1000 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001001
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001002 int32_t receiveFreqHz = receiveACM->ReceiveFrequency();
1003 int32_t playoutFreqHz = receiveACM->PlayoutFrequency();
1004
1005 CHECK_ERROR_MT(receiveFreqHz);
1006 CHECK_ERROR_MT(playoutFreqHz);
1007
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +00001008 char bgnString[25];
1009 switch (*bgnMode) {
1010 case On: {
1011 *bgnMode = Fade;
1012 strncpy(bgnString, "Fade", 25);
1013 break;
1014 }
1015 case Fade: {
1016 *bgnMode = Off;
1017 strncpy(bgnString, "OFF", 25);
1018 break;
1019 }
1020 case Off: {
1021 *bgnMode = On;
1022 strncpy(bgnString, "ON", 25);
1023 break;
1024 }
1025 default:
1026 *bgnMode = On;
1027 strncpy(bgnString, "ON", 25);
1028 }
1029 CHECK_ERROR_MT(receiveACM->SetBackgroundNoiseMode(*bgnMode));
1030 bgnString[24] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +00001031
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001032 char playoutString[25];
1033 switch (*playoutMode) {
1034 case voice: {
1035 *playoutMode = fax;
1036 strncpy(playoutString, "FAX", 25);
1037 break;
niklase@google.com470e71d2011-07-07 08:21:25 +00001038 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001039 case fax: {
1040 *playoutMode = streaming;
1041 strncpy(playoutString, "Streaming", 25);
1042 break;
1043 }
1044 case streaming: {
1045 *playoutMode = voice;
1046 strncpy(playoutString, "Voice", 25);
1047 break;
1048 }
1049 default:
1050 *playoutMode = voice;
1051 strncpy(playoutString, "Voice", 25);
1052 }
1053 CHECK_ERROR_MT(receiveACM->SetPlayoutMode(*playoutMode));
1054 playoutString[24] = '\0';
1055
1056 if (!_randomTest) {
1057 fprintf(stdout, "\n");
1058 fprintf(stdout, "In Side %c\n", receiveSide);
1059 fprintf(stdout, "---------------------------------\n");
1060 fprintf(stdout, "Receive Frequency....... %d Hz\n", receiveFreqHz);
1061 fprintf(stdout, "Playout Frequency....... %d Hz\n", playoutFreqHz);
1062 fprintf(stdout, "Audio Playout Mode...... %s\n", playoutString);
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +00001063 fprintf(stdout, "Background Noise Mode... %s\n", bgnString);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001064 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001065}
1066
1067// set/get receiver VAD status & mode.
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +00001068void APITest::TestReceiverVAD(char side) {
1069 AudioCodingModule* myACM;
1070 int* myReceiveVADActivity;
1071
1072 if (side == 'A') {
1073 myACM = _acmA;
1074 myReceiveVADActivity = _receiveVADActivityA;
1075 } else {
1076 myACM = _acmB;
1077 myReceiveVADActivity = _receiveVADActivityB;
1078 }
1079
1080 ACMVADMode mode = myACM->ReceiveVADMode();
1081
1082 CHECK_ERROR_MT(mode);
1083
1084 if (!_randomTest) {
1085 fprintf(stdout, "\n\nCurrent Receive VAD at side %c\n", side);
1086 fprintf(stdout, "----------------------------------\n");
1087 fprintf(stdout, "mode.......... %d\n", (int) mode);
1088 fprintf(stdout, "VAD Active.... %d\n", myReceiveVADActivity[0]);
1089 fprintf(stdout, "VAD Passive... %d\n", myReceiveVADActivity[1]);
1090 fprintf(stdout, "VAD Unknown... %d\n", myReceiveVADActivity[2]);
1091 }
1092
1093 if (!_randomTest) {
1094 fprintf(stdout, "\nChange Receive VAD at side %c\n\n", side);
1095 }
1096
1097 switch (mode) {
1098 case VADNormal:
1099 mode = VADAggr;
1100 break;
1101 case VADLowBitrate:
1102 mode = VADVeryAggr;
1103 break;
1104 case VADAggr:
1105 mode = VADLowBitrate;
1106 break;
1107 case VADVeryAggr:
1108 mode = VADNormal;
1109 break;
1110 default:
1111 mode = VADNormal;
1112
1113 CHECK_ERROR_MT(myACM->SetReceiveVADMode(mode));
1114 }
1115 for (int n = 0; n < 3; n++) {
1116 myReceiveVADActivity[n] = 0;
1117 }
1118}
1119
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001120void APITest::TestSendVAD(char side) {
1121 if (_randomTest) {
1122 return;
1123 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001124
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001125 bool* vad;
1126 bool* dtx;
1127 ACMVADMode* mode;
1128 Channel* myChannel;
1129 AudioCodingModule* myACM;
niklase@google.com470e71d2011-07-07 08:21:25 +00001130
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001131 CodecInst myCodec;
1132 if (!_randomTest) {
1133 fprintf(stdout, "\n\n");
1134 fprintf(stdout, "-----------------------------------------------\n");
1135 fprintf(stdout, " Test VAD API\n");
1136 fprintf(stdout, "-----------------------------------------------\n");
1137 }
andrew@webrtc.orgd7a71d02012-08-01 01:40:02 +00001138
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001139 if (side == 'A') {
1140 AudioCodingModule::Codec(_codecCntrA, &myCodec);
1141 vad = &_sendVADA;
1142 dtx = &_sendDTXA;
1143 mode = &_sendVADModeA;
1144 myChannel = _channel_A2B;
1145 myACM = _acmA;
1146 } else {
1147 AudioCodingModule::Codec(_codecCntrB, &myCodec);
1148 vad = &_sendVADB;
1149 dtx = &_sendDTXB;
1150 mode = &_sendVADModeB;
1151 myChannel = _channel_B2A;
1152 myACM = _acmB;
1153 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001154
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001155 CheckVADStatus(side);
1156 if (!_randomTest) {
1157 fprintf(stdout, "\n\n");
1158 }
1159
1160 switch (*mode) {
1161 case VADNormal:
1162 *vad = true;
1163 *dtx = true;
1164 *mode = VADAggr;
1165 break;
1166 case VADLowBitrate:
1167 *vad = true;
1168 *dtx = true;
1169 *mode = VADVeryAggr;
1170 break;
1171 case VADAggr:
1172 *vad = true;
1173 *dtx = true;
1174 *mode = VADLowBitrate;
1175 break;
1176 case VADVeryAggr:
1177 *vad = false;
1178 *dtx = false;
1179 *mode = VADNormal;
1180 break;
1181 default:
1182 *mode = VADNormal;
1183 }
1184
1185 *dtx = (myCodec.plfreq == 32000) ? false : *dtx;
1186
1187 CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode));
1188 myChannel->ResetStats();
1189
1190 CheckVADStatus(side);
1191 if (!_randomTest) {
1192 fprintf(stdout, "\n");
1193 fprintf(stdout, "-----------------------------------------------\n");
1194 }
1195
1196 // Fault Test
1197 CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) - 1));
1198 CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) 4));
niklase@google.com470e71d2011-07-07 08:21:25 +00001199
1200}
1201
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001202void APITest::CurrentCodec(char side) {
1203 CodecInst myCodec;
1204 if (side == 'A') {
1205 _acmA->SendCodec(&myCodec);
1206 } else {
1207 _acmB->SendCodec(&myCodec);
1208 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001209
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001210 if (!_randomTest) {
1211 fprintf(stdout, "\n\n");
1212 fprintf(stdout, "Send codec in Side A\n");
1213 fprintf(stdout, "----------------------------\n");
1214 fprintf(stdout, "Name................. %s\n", myCodec.plname);
1215 fprintf(stdout, "Sampling Frequency... %d\n", myCodec.plfreq);
1216 fprintf(stdout, "Rate................. %d\n", myCodec.rate);
1217 fprintf(stdout, "Payload-type......... %d\n", myCodec.pltype);
1218 fprintf(stdout, "Packet-size.......... %d\n", myCodec.pacsize);
1219 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001220
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001221 Wait(100);
niklase@google.com470e71d2011-07-07 08:21:25 +00001222}
1223
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001224void APITest::ChangeCodec(char side) {
1225 CodecInst myCodec;
1226 AudioCodingModule* myACM;
1227 uint8_t* codecCntr;
1228 bool* thereIsEncoder;
1229 bool* vad;
1230 bool* dtx;
1231 ACMVADMode* mode;
1232 Channel* myChannel;
1233 // Reset and Wait
1234 if (!_randomTest) {
1235 fprintf(stdout, "Reset Encoder Side A \n");
1236 }
1237 if (side == 'A') {
1238 myACM = _acmA;
1239 codecCntr = &_codecCntrA;
niklase@google.com470e71d2011-07-07 08:21:25 +00001240 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001241 WriteLockScoped wl(_apiTestRWLock);
1242 thereIsEncoder = &_thereIsEncoderA;
niklase@google.com470e71d2011-07-07 08:21:25 +00001243 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001244 vad = &_sendVADA;
1245 dtx = &_sendDTXA;
1246 mode = &_sendVADModeA;
1247 myChannel = _channel_A2B;
1248 } else {
1249 myACM = _acmB;
1250 codecCntr = &_codecCntrB;
niklase@google.com470e71d2011-07-07 08:21:25 +00001251 {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001252 WriteLockScoped wl(_apiTestRWLock);
1253 thereIsEncoder = &_thereIsEncoderB;
niklase@google.com470e71d2011-07-07 08:21:25 +00001254 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001255 vad = &_sendVADB;
1256 dtx = &_sendDTXB;
1257 mode = &_sendVADModeB;
1258 myChannel = _channel_B2A;
1259 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001260
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001261 myACM->ResetEncoder();
1262 Wait(100);
niklase@google.com470e71d2011-07-07 08:21:25 +00001263
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001264 // Register the next codec
1265 do {
1266 *codecCntr =
1267 (*codecCntr < AudioCodingModule::NumberOfCodecs() - 1) ?
1268 (*codecCntr + 1) : 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001269
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001270 if (*codecCntr == 0) {
1271 //printf("Initialize Sender Side A \n");
1272 {
niklase@google.com470e71d2011-07-07 08:21:25 +00001273 WriteLockScoped wl(_apiTestRWLock);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001274 *thereIsEncoder = false;
1275 }
1276 CHECK_ERROR_MT(myACM->InitializeSender());
1277 Wait(1000);
1278
1279 // After Initialization CN is lost, re-register them
1280 if (AudioCodingModule::Codec("CN", &myCodec, 8000, 1) >= 0) {
1281 CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec));
1282 }
1283 if (AudioCodingModule::Codec("CN", &myCodec, 16000, 1) >= 0) {
1284 CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec));
1285 }
1286 // VAD & DTX are disabled after initialization
1287 *vad = false;
1288 *dtx = false;
1289 _writeToFile = false;
niklase@google.com470e71d2011-07-07 08:21:25 +00001290 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001291
1292 AudioCodingModule::Codec(*codecCntr, &myCodec);
1293 } while (!STR_CASE_CMP(myCodec.plname, "CN")
1294 || !STR_CASE_CMP(myCodec.plname, "telephone-event")
1295 || !STR_CASE_CMP(myCodec.plname, "RED"));
1296
1297 if (!_randomTest) {
1298 fprintf(stdout,"\n=====================================================\n");
1299 fprintf(stdout, " Registering New Codec %s, %d kHz, %d kbps\n",
1300 myCodec.plname, myCodec.plfreq / 1000, myCodec.rate / 1000);
1301 }
1302 //std::cout<< std::flush;
1303
1304 // NO DTX for supe-wideband codec at this point
1305 if (myCodec.plfreq == 32000) {
1306 *dtx = false;
1307 CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode));
1308
1309 }
1310
1311 CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec));
1312 myChannel->ResetStats();
1313 {
1314 WriteLockScoped wl(_apiTestRWLock);
1315 *thereIsEncoder = true;
1316 }
1317 Wait(500);
niklase@google.com470e71d2011-07-07 08:21:25 +00001318}
1319
stefan@webrtc.org1c77dfd2013-09-18 12:34:05 +00001320void APITest::LookForDTMF(char side) {
1321 if (!_randomTest) {
1322 fprintf(stdout, "\n\nLooking for DTMF Signal in Side %c\n", side);
1323 fprintf(stdout, "----------------------------------------\n");
1324 }
1325
1326 if (side == 'A') {
1327 _acmB->RegisterIncomingMessagesCallback(NULL);
1328 _acmA->RegisterIncomingMessagesCallback(_dtmfCallback);
1329 Wait(1000);
1330 _acmA->RegisterIncomingMessagesCallback(NULL);
1331 } else {
1332 _acmA->RegisterIncomingMessagesCallback(NULL);
1333 _acmB->RegisterIncomingMessagesCallback(_dtmfCallback);
1334 Wait(1000);
1335 _acmB->RegisterIncomingMessagesCallback(NULL);
1336 }
1337}
1338
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +00001339} // namespace webrtc