niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/main/test/APITest.h" |
| 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame^] | 13 | #include <ctype.h> |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 17 | |
tina.legrand@webrtc.org | 5e7ca60 | 2012-06-12 07:16:24 +0000 | [diff] [blame] | 18 | #include <iostream> |
| 19 | #include <ostream> |
| 20 | #include <string> |
| 21 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 22 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 33 | namespace webrtc { |
| 34 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | #define TEST_DURATION_SEC 600 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | #define NUMBER_OF_SENDER_TESTS 6 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | #define MAX_FILE_NAME_LENGTH_BYTE 500 |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 38 | #define CHECK_THREAD_NULLITY(myThread, S) \ |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 39 | if(myThread != NULL) { \ |
| 40 | unsigned int i; \ |
| 41 | (myThread)->Start(i); \ |
| 42 | } else { \ |
| 43 | ADD_FAILURE() << S; \ |
| 44 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 46 | void 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | } |
| 56 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 57 | APITest::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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 101 | for (n = 0; n < 3; n++) { |
| 102 | _receiveVADActivityA[n] = 0; |
| 103 | _receiveVADActivityB[n] = 0; |
| 104 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 106 | _movingDot[40] = '\0'; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 108 | for (int n = 0; n < 40; n++) { |
| 109 | _movingDot[n] = ' '; |
| 110 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | } |
| 112 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 113 | APITest::~APITest() { |
| 114 | DESTROY_ACM(_acmA); |
| 115 | DESTROY_ACM(_acmB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 117 | DELETE_POINTER(_channel_A2B); |
| 118 | DELETE_POINTER(_channel_B2A); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 120 | DELETE_POINTER(_pushEventA); |
| 121 | DELETE_POINTER(_pullEventA); |
| 122 | DELETE_POINTER(_processEventA); |
| 123 | DELETE_POINTER(_apiEventA); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 125 | DELETE_POINTER(_pushEventB); |
| 126 | DELETE_POINTER(_pullEventB); |
| 127 | DELETE_POINTER(_processEventB); |
| 128 | DELETE_POINTER(_apiEventB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 130 | _inFileA.Close(); |
| 131 | _outFileA.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 133 | _inFileB.Close(); |
| 134 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 136 | DELETE_POINTER(_dtmfCallback); |
| 137 | DELETE_POINTER(_vadCallbackA); |
| 138 | DELETE_POINTER(_vadCallbackB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 139 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 140 | delete &_apiTestRWLock; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | } |
| 142 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 143 | int16_t APITest::SetUp() { |
| 144 | _acmA = AudioCodingModule::Create(1); |
| 145 | _acmB = AudioCodingModule::Create(2); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 147 | CodecInst dummyCodec; |
| 148 | int lastPayloadType = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 150 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 158 | printf("Register Receive Codec %s ", dummyCodec.plname); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 160 | 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.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 167 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 168 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 180 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 191 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 195 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 196 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 208 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 217 | uint16_t frequencyHz; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 218 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 219 | printf("\n\nAPI Test\n"); |
| 220 | printf("========\n"); |
| 221 | printf("Hit enter to accept the default values indicated in []\n\n"); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 222 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 223 | //--- 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 230 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 231 | //--- 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 237 | //--- 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 242 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 243 | //--- 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 248 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 249 | //--- 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 254 | //--- 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.org | 5e7ca60 | 2012-06-12 07:16:24 +0000 | [diff] [blame] | 258 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 259 | //--- 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.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 296 | EXPECT_TRUE(fgets(print, 10, stdin) != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | print[10] = '\0'; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 298 | if (strstr(print, "y") == NULL) { |
| 299 | EXPECT_TRUE(freopen("APITest_log.txt", "w", stdout) != 0); |
| 300 | _verbose = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 301 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 302 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | |
| 304 | #ifdef WEBRTC_DTMF_DETECTION |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 305 | _dtmfCallback = new DTMFDetector; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 306 | #endif |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 307 | _vadCallbackA = new VADCallback; |
| 308 | _vadCallbackB = new VADCallback; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 309 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 310 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | } |
| 312 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 313 | bool APITest::PushAudioThreadA(void* obj) { |
| 314 | return static_cast<APITest*>(obj)->PushAudioRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 315 | } |
| 316 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 317 | bool APITest::PushAudioThreadB(void* obj) { |
| 318 | return static_cast<APITest*>(obj)->PushAudioRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 319 | } |
| 320 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 321 | bool APITest::PullAudioThreadA(void* obj) { |
| 322 | return static_cast<APITest*>(obj)->PullAudioRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 323 | } |
| 324 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 325 | bool APITest::PullAudioThreadB(void* obj) { |
| 326 | return static_cast<APITest*>(obj)->PullAudioRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | } |
| 328 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 329 | bool APITest::ProcessThreadA(void* obj) { |
| 330 | return static_cast<APITest*>(obj)->ProcessRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 331 | } |
| 332 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 333 | bool APITest::ProcessThreadB(void* obj) { |
| 334 | return static_cast<APITest*>(obj)->ProcessRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 335 | } |
| 336 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 337 | bool APITest::APIThreadA(void* obj) { |
| 338 | return static_cast<APITest*>(obj)->APIRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 339 | } |
| 340 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 341 | bool APITest::APIThreadB(void* obj) { |
| 342 | return static_cast<APITest*>(obj)->APIRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 343 | } |
| 344 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 345 | bool APITest::PullAudioRunA() { |
| 346 | _pullEventA->Wait(100); |
| 347 | AudioFrame audioFrame; |
| 348 | if (_acmA->PlayoutData10Ms(_outFreqHzA, &audioFrame) < 0) { |
| 349 | bool thereIsDecoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 350 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 351 | ReadLockScoped rl(_apiTestRWLock); |
| 352 | thereIsDecoder = _thereIsDecoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 353 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 354 | if (thereIsDecoder) { |
| 355 | fprintf(stderr, "\n>>>>>> cannot pull audio A <<<<<<<< \n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 356 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 357 | } else { |
| 358 | if (_writeToFile) { |
| 359 | _outFileA.Write10MsData(audioFrame); |
| 360 | } |
| 361 | _receiveVADActivityA[(int) audioFrame.vad_activity_]++; |
| 362 | } |
| 363 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 364 | } |
| 365 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 366 | bool APITest::PullAudioRunB() { |
| 367 | _pullEventB->Wait(100); |
| 368 | AudioFrame audioFrame; |
| 369 | if (_acmB->PlayoutData10Ms(_outFreqHzB, &audioFrame) < 0) { |
| 370 | bool thereIsDecoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 372 | ReadLockScoped rl(_apiTestRWLock); |
| 373 | thereIsDecoder = _thereIsDecoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 374 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 375 | if (thereIsDecoder) { |
| 376 | fprintf(stderr, "\n>>>>>> cannot pull audio B <<<<<<<< \n"); |
| 377 | fprintf(stderr, "%d %d\n", _testNumA, _testNumB); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 378 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 379 | } else { |
| 380 | if (_writeToFile) { |
| 381 | _outFileB.Write10MsData(audioFrame); |
| 382 | } |
| 383 | _receiveVADActivityB[(int) audioFrame.vad_activity_]++; |
| 384 | } |
| 385 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 386 | } |
| 387 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 388 | bool APITest::PushAudioRunA() { |
| 389 | _pushEventA->Wait(100); |
| 390 | AudioFrame audioFrame; |
| 391 | _inFileA.Read10MsData(audioFrame); |
| 392 | if (_acmA->Add10MsData(audioFrame) < 0) { |
| 393 | bool thereIsEncoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 394 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 395 | ReadLockScoped rl(_apiTestRWLock); |
| 396 | thereIsEncoder = _thereIsEncoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 397 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 398 | if (thereIsEncoder) { |
| 399 | fprintf(stderr, "\n>>>> add10MsData at A failed <<<<\n"); |
| 400 | } |
| 401 | } |
| 402 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 403 | } |
| 404 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 405 | bool APITest::PushAudioRunB() { |
| 406 | _pushEventB->Wait(100); |
| 407 | AudioFrame audioFrame; |
| 408 | _inFileB.Read10MsData(audioFrame); |
| 409 | if (_acmB->Add10MsData(audioFrame) < 0) { |
| 410 | bool thereIsEncoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 411 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 412 | ReadLockScoped rl(_apiTestRWLock); |
| 413 | thereIsEncoder = _thereIsEncoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 414 | } |
| 415 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 416 | if (thereIsEncoder) { |
| 417 | fprintf(stderr, "\n>>>> cannot add audio to B <<<<"); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 422 | } |
| 423 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 424 | bool 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 429 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 430 | ReadLockScoped rl(_apiTestRWLock); |
| 431 | thereIsEncoder = _thereIsEncoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 432 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 433 | |
| 434 | if (thereIsEncoder) { |
| 435 | fprintf(stderr, "\n>>>>> Process Failed at A <<<<<\n"); |
| 436 | } |
| 437 | } |
| 438 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | } |
| 440 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 441 | bool APITest::ProcessRunB() { |
| 442 | _processEventB->Wait(100); |
| 443 | if (_acmB->Process() < 0) { |
| 444 | bool thereIsEncoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 445 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 446 | ReadLockScoped rl(_apiTestRWLock); |
| 447 | thereIsEncoder = _thereIsEncoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 448 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 449 | if (thereIsEncoder) { |
| 450 | fprintf(stderr, "\n>>>>> Process Failed at B <<<<<\n"); |
| 451 | } |
| 452 | } |
| 453 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /*/ |
| 457 | * |
| 458 | * In side A we test the APIs which are related to sender Side. |
| 459 | * |
| 460 | /*/ |
| 461 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 462 | void 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 469 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 470 | _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.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 482 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 483 | _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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 492 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 493 | //fprintf(stderr, "%c: %d \n", thread, testNum); |
| 494 | //fflush(stderr); |
| 495 | } |
| 496 | switch (testNum) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 497 | case 0: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 498 | CurrentCodec('A'); |
| 499 | ChangeCodec('A'); |
| 500 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 501 | case 1: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 502 | TestPlayout('B'); |
| 503 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 504 | case 2: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 505 | if (!_randomTest) { |
| 506 | fprintf(stdout, "\nTesting Delay ...\n"); |
| 507 | } |
| 508 | TestDelay('A'); |
| 509 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 510 | case 3: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 511 | TestSendVAD('A'); |
| 512 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 513 | case 4: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 514 | TestRegisteration('A'); |
| 515 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 516 | case 5: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 517 | TestReceiverVAD('A'); |
| 518 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 519 | case 6: |
| 520 | #ifdef WEBRTC_DTMF_DETECTION |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 521 | LookForDTMF('A'); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 522 | #endif |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 523 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 524 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 525 | fprintf(stderr, "Wrong Test Number\n"); |
| 526 | getchar(); |
| 527 | exit(1); |
| 528 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 529 | } |
| 530 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 531 | bool APITest::APIRunA() { |
| 532 | _apiEventA->Wait(50); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 533 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 534 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 548 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 549 | // VAD TEST |
| 550 | TestSendVAD('A'); |
| 551 | TestRegisteration('A'); |
| 552 | TestReceiverVAD('A'); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 553 | #ifdef WEBRTC_DTMF_DETECTION |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 554 | LookForDTMF('A'); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 555 | #endif |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 556 | } |
| 557 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 558 | } |
| 559 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 560 | bool 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.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 571 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 572 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 573 | } |
| 574 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 575 | void APITest::Perform() { |
| 576 | SetUp(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 577 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 578 | //--- 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.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 615 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 616 | //_apiEventA->StartTimer(true, 5000); |
| 617 | //_apiEventB->StartTimer(true, 5000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 618 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 619 | _processEventA->StartTimer(true, 10); |
| 620 | _processEventB->StartTimer(true, 10); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 621 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 622 | _pullEventA->StartTimer(true, 10); |
| 623 | _pullEventB->StartTimer(true, 10); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 624 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 625 | _pushEventA->StartTimer(true, 10); |
| 626 | _pushEventB->StartTimer(true, 10); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 627 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 628 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 635 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 636 | //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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 643 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 644 | //completeEvent->Wait(0xFFFFFFFF); |
| 645 | //(unsigned long)((unsigned long)TEST_DURATION_SEC * (unsigned long)1000)); |
| 646 | delete completeEvent; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 647 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 648 | myPushAudioThreadA->Stop(); |
| 649 | myPullAudioThreadA->Stop(); |
| 650 | myProcessThreadA->Stop(); |
| 651 | myAPIThreadA->Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 652 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 653 | delete myPushAudioThreadA; |
| 654 | delete myPullAudioThreadA; |
| 655 | delete myProcessThreadA; |
| 656 | delete myAPIThreadA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 657 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 658 | myPushAudioThreadB->Stop(); |
| 659 | myPullAudioThreadB->Stop(); |
| 660 | myProcessThreadB->Stop(); |
| 661 | myAPIThreadB->Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 662 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 663 | delete myPushAudioThreadB; |
| 664 | delete myPullAudioThreadB; |
| 665 | delete myProcessThreadB; |
| 666 | delete myAPIThreadB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 667 | } |
| 668 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 669 | void APITest::CheckVADStatus(char side) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 670 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 671 | bool dtxEnabled; |
| 672 | bool vadEnabled; |
| 673 | ACMVADMode vadMode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 674 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 675 | if (side == 'A') { |
| 676 | _acmA->VAD(&dtxEnabled, &vadEnabled, &vadMode); |
| 677 | _acmA->RegisterVADCallback(NULL); |
| 678 | _vadCallbackA->Reset(); |
| 679 | _acmA->RegisterVADCallback(_vadCallbackA); |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 680 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 681 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 694 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 695 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 696 | if (dtxEnabled != _sendDTXA) { |
| 697 | fprintf(stderr, ">>> Error Enabling DTX <<<\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 698 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 699 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | // Set Min delay, get delay, playout timestamp |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 740 | void APITest::TestDelay(char side) { |
| 741 | AudioCodingModule* myACM; |
| 742 | Channel* myChannel; |
| 743 | int32_t* myMinDelay; |
| 744 | EventWrapper* myEvent = EventWrapper::Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 745 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 746 | uint32_t inTimestamp = 0; |
| 747 | uint32_t outTimestamp = 0; |
| 748 | double estimDelay = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 749 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 750 | double averageEstimDelay = 0; |
| 751 | double averageDelay = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 752 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 753 | CircularBuffer estimDelayCB(100); |
| 754 | estimDelayCB.SetArithMean(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 755 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 756 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 801 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 802 | myEvent->StopTimer(); |
| 803 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 804 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 805 | if ((!_verbose) && (!_randomTest)) { |
| 806 | fprintf(stdout, "\nExpected: %4d, retreived: %6.1f, measured: %6.1f", |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 807 | *myMinDelay, averageDelay, averageEstimDelay); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 808 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 809 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 810 | *myMinDelay = (rand() % 1000) + 1; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 811 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 812 | ACMNetworkStatistics networkStat; |
| 813 | CHECK_ERROR_MT(myACM->NetworkStatistics(&networkStat)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 814 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 815 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 844 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 845 | CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 846 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 847 | if (!_randomTest) { |
| 848 | myEvent->Wait(500); |
| 849 | fprintf(stdout, "\n"); |
| 850 | fprintf(stdout, "\n"); |
| 851 | } |
| 852 | delete myEvent; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | // Unregister a codec & register again. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 856 | void APITest::TestRegisteration(char sendSide) { |
| 857 | AudioCodingModule* sendACM; |
| 858 | AudioCodingModule* receiveACM; |
| 859 | bool* thereIsDecoder; |
| 860 | EventWrapper* myEvent = EventWrapper::Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 861 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 862 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 877 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 878 | case 'B': { |
| 879 | sendACM = _acmB; |
| 880 | receiveACM = _acmA; |
| 881 | thereIsDecoder = &_thereIsDecoderA; |
| 882 | break; |
| 883 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 884 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 885 | fprintf(stderr, "Invalid sender-side in TestRegistration(%c)\n", |
| 886 | sendSide); |
| 887 | exit(-1); |
| 888 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 889 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 890 | CodecInst myCodec; |
| 891 | if (sendACM->SendCodec(&myCodec) < 0) { |
| 892 | AudioCodingModule::Codec(_codecCntrA, &myCodec); |
| 893 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 894 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 895 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 906 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 907 | int currentPayload = myCodec.pltype; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 908 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 909 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 916 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 917 | //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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 929 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 930 | //{ |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 943 | } |
| 944 | CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 945 | //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 946 | myEvent->Wait(20); |
| 947 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 948 | WriteLockScoped wl(_apiTestRWLock); |
| 949 | *thereIsDecoder = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 950 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 951 | Wait(1000); |
| 952 | |
| 953 | break; |
| 954 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 955 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 956 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 973 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 974 | WriteLockScoped wl(_apiTestRWLock); |
| 975 | *thereIsDecoder = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 976 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 977 | } |
| 978 | delete myEvent; |
| 979 | if (!_randomTest) { |
| 980 | fprintf(stdout, |
| 981 | "---------------------------------------------------------\n"); |
| 982 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | // Playout Mode, background noise mode. |
| 986 | // Receiver Frequency, playout frequency. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 987 | void 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 997 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 998 | case 'B': { |
| 999 | receiveACM = _acmB; |
| 1000 | playoutMode = &_playoutModeB; |
| 1001 | bgnMode = &_bgnModeB; |
| 1002 | break; |
| 1003 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1004 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1005 | receiveACM = _acmA; |
| 1006 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1007 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1008 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1031 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1032 | *bgnMode = On; |
| 1033 | strncpy(bgnString, "ON", 25); |
| 1034 | } |
| 1035 | CHECK_ERROR_MT(receiveACM->SetBackgroundNoiseMode(*bgnMode)); |
| 1036 | bgnString[24] = '\0'; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1037 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1038 | char playoutString[25]; |
| 1039 | switch (*playoutMode) { |
| 1040 | case voice: { |
| 1041 | *playoutMode = fax; |
| 1042 | strncpy(playoutString, "FAX", 25); |
| 1043 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1044 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1045 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | // set/get receiver VAD status & mode. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1074 | void APITest::TestReceiverVAD(char side) { |
| 1075 | AudioCodingModule* myACM; |
| 1076 | int* myReceiveVADActivity; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1077 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1078 | if (side == 'A') { |
| 1079 | myACM = _acmA; |
| 1080 | myReceiveVADActivity = _receiveVADActivityA; |
| 1081 | } else { |
| 1082 | myACM = _acmB; |
| 1083 | myReceiveVADActivity = _receiveVADActivityB; |
| 1084 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1085 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1086 | ACMVADMode mode = myACM->ReceiveVADMode(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1087 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1088 | CHECK_ERROR_MT(mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1089 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1090 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1098 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1099 | if (!_randomTest) { |
| 1100 | fprintf(stdout, "\nChange Receive VAD at side %c\n\n", side); |
| 1101 | } |
henrike@webrtc.org | 26d3667 | 2011-11-07 23:24:40 +0000 | [diff] [blame] | 1102 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1103 | switch (mode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1104 | case VADNormal: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1105 | mode = VADAggr; |
| 1106 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1107 | case VADLowBitrate: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1108 | mode = VADVeryAggr; |
| 1109 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1110 | case VADAggr: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1111 | mode = VADLowBitrate; |
| 1112 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1113 | case VADVeryAggr: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1114 | mode = VADNormal; |
| 1115 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1116 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1117 | mode = VADNormal; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1118 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1119 | CHECK_ERROR_MT(myACM->SetReceiveVADMode(mode)); |
| 1120 | } |
| 1121 | for (int n = 0; n < 3; n++) { |
| 1122 | myReceiveVADActivity[n] = 0; |
| 1123 | } |
| 1124 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1125 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1126 | void APITest::TestSendVAD(char side) { |
| 1127 | if (_randomTest) { |
| 1128 | return; |
| 1129 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1130 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1131 | bool* vad; |
| 1132 | bool* dtx; |
| 1133 | ACMVADMode* mode; |
| 1134 | Channel* myChannel; |
| 1135 | AudioCodingModule* myACM; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1136 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1137 | 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.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 1144 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1145 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1160 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1161 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1205 | |
| 1206 | } |
| 1207 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1208 | void APITest::CurrentCodec(char side) { |
| 1209 | CodecInst myCodec; |
| 1210 | if (side == 'A') { |
| 1211 | _acmA->SendCodec(&myCodec); |
| 1212 | } else { |
| 1213 | _acmB->SendCodec(&myCodec); |
| 1214 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1215 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1216 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1226 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1227 | Wait(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1230 | void 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1246 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1247 | WriteLockScoped wl(_apiTestRWLock); |
| 1248 | thereIsEncoder = &_thereIsEncoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1249 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1250 | vad = &_sendVADA; |
| 1251 | dtx = &_sendDTXA; |
| 1252 | mode = &_sendVADModeA; |
| 1253 | myChannel = _channel_A2B; |
| 1254 | } else { |
| 1255 | myACM = _acmB; |
| 1256 | codecCntr = &_codecCntrB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1257 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1258 | WriteLockScoped wl(_apiTestRWLock); |
| 1259 | thereIsEncoder = &_thereIsEncoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1260 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1261 | vad = &_sendVADB; |
| 1262 | dtx = &_sendDTXB; |
| 1263 | mode = &_sendVADModeB; |
| 1264 | myChannel = _channel_B2A; |
| 1265 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1266 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1267 | myACM->ResetEncoder(); |
| 1268 | Wait(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1269 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1270 | // Register the next codec |
| 1271 | do { |
| 1272 | *codecCntr = |
| 1273 | (*codecCntr < AudioCodingModule::NumberOfCodecs() - 1) ? |
| 1274 | (*codecCntr + 1) : 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1275 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1276 | if (*codecCntr == 0) { |
| 1277 | //printf("Initialize Sender Side A \n"); |
| 1278 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1279 | WriteLockScoped wl(_apiTestRWLock); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1280 | *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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1296 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1297 | |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1326 | void 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.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 1331 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1332 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1343 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 1344 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1345 | } // namespace webrtc |