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 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/test/APITest.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 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" |
pbos | 12411ef | 2015-11-23 14:47:56 -0800 | [diff] [blame] | 23 | #include "webrtc/base/platform_thread.h" |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 24 | #include "webrtc/common.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 25 | #include "webrtc/common_types.h" |
| 26 | #include "webrtc/engine_configurations.h" |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 27 | #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" |
| 28 | #include "webrtc/modules/audio_coding/test/utility.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 29 | #include "webrtc/system_wrappers/include/event_wrapper.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 30 | #include "webrtc/system_wrappers/include/tick_util.h" |
| 31 | #include "webrtc/system_wrappers/include/trace.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 32 | #include "webrtc/test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 34 | namespace webrtc { |
| 35 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | #define TEST_DURATION_SEC 600 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | #define NUMBER_OF_SENDER_TESTS 6 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | #define MAX_FILE_NAME_LENGTH_BYTE 500 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 40 | void APITest::Wait(uint32_t waitLengthMs) { |
| 41 | if (_randomTest) { |
| 42 | return; |
| 43 | } else { |
| 44 | EventWrapper* myEvent = EventWrapper::Create(); |
| 45 | myEvent->Wait(waitLengthMs); |
| 46 | delete myEvent; |
| 47 | return; |
| 48 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | } |
| 50 | |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 51 | APITest::APITest(const Config& config) |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 52 | : _acmA(AudioCodingModule::Create(1)), |
| 53 | _acmB(AudioCodingModule::Create(2)), |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 54 | _channel_A2B(NULL), |
| 55 | _channel_B2A(NULL), |
| 56 | _writeToFile(true), |
| 57 | _pullEventA(NULL), |
| 58 | _pushEventA(NULL), |
| 59 | _processEventA(NULL), |
| 60 | _apiEventA(NULL), |
| 61 | _pullEventB(NULL), |
| 62 | _pushEventB(NULL), |
| 63 | _processEventB(NULL), |
| 64 | _apiEventB(NULL), |
| 65 | _codecCntrA(0), |
| 66 | _codecCntrB(0), |
| 67 | _thereIsEncoderA(false), |
| 68 | _thereIsEncoderB(false), |
| 69 | _thereIsDecoderA(false), |
| 70 | _thereIsDecoderB(false), |
| 71 | _sendVADA(false), |
| 72 | _sendDTXA(false), |
| 73 | _sendVADModeA(VADNormal), |
| 74 | _sendVADB(false), |
| 75 | _sendDTXB(false), |
| 76 | _sendVADModeB(VADNormal), |
| 77 | _minDelayA(0), |
| 78 | _minDelayB(0), |
| 79 | _dotPositionA(0), |
| 80 | _dotMoveDirectionA(1), |
| 81 | _dotPositionB(39), |
| 82 | _dotMoveDirectionB(-1), |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 83 | _vadCallbackA(NULL), |
| 84 | _vadCallbackB(NULL), |
| 85 | _apiTestRWLock(*RWLockWrapper::CreateRWLock()), |
| 86 | _randomTest(false), |
| 87 | _testNumA(0), |
| 88 | _testNumB(1) { |
| 89 | int n; |
| 90 | for (n = 0; n < 32; n++) { |
| 91 | _payloadUsed[n] = false; |
| 92 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 94 | _movingDot[40] = '\0'; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 96 | for (int n = 0; n < 40; n++) { |
| 97 | _movingDot[n] = ' '; |
| 98 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | } |
| 100 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 101 | APITest::~APITest() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 102 | DELETE_POINTER(_channel_A2B); |
| 103 | DELETE_POINTER(_channel_B2A); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 105 | DELETE_POINTER(_pushEventA); |
| 106 | DELETE_POINTER(_pullEventA); |
| 107 | DELETE_POINTER(_processEventA); |
| 108 | DELETE_POINTER(_apiEventA); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 110 | DELETE_POINTER(_pushEventB); |
| 111 | DELETE_POINTER(_pullEventB); |
| 112 | DELETE_POINTER(_processEventB); |
| 113 | DELETE_POINTER(_apiEventB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 115 | _inFileA.Close(); |
| 116 | _outFileA.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 118 | _inFileB.Close(); |
| 119 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 121 | DELETE_POINTER(_vadCallbackA); |
| 122 | DELETE_POINTER(_vadCallbackB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 124 | delete &_apiTestRWLock; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | } |
| 126 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 127 | int16_t APITest::SetUp() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 128 | CodecInst dummyCodec; |
| 129 | int lastPayloadType = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 131 | int16_t numCodecs = _acmA->NumberOfCodecs(); |
| 132 | for (uint8_t n = 0; n < numCodecs; n++) { |
| 133 | AudioCodingModule::Codec(n, &dummyCodec); |
| 134 | if ((STR_CASE_CMP(dummyCodec.plname, "CN") == 0) |
| 135 | && (dummyCodec.plfreq == 32000)) { |
| 136 | continue; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 139 | printf("Register Receive Codec %s ", dummyCodec.plname); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 141 | if ((n != 0) && !FixedPayloadTypeCodec(dummyCodec.plname)) { |
| 142 | // Check registration with an already occupied payload type |
| 143 | int currentPayloadType = dummyCodec.pltype; |
| 144 | dummyCodec.pltype = 97; //lastPayloadType; |
| 145 | CHECK_ERROR(_acmB->RegisterReceiveCodec(dummyCodec)); |
| 146 | dummyCodec.pltype = currentPayloadType; |
| 147 | } |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 148 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 149 | if ((n < numCodecs - 1) && !FixedPayloadTypeCodec(dummyCodec.plname)) { |
| 150 | // test if re-registration works; |
| 151 | CodecInst nextCodec; |
| 152 | int currentPayloadType = dummyCodec.pltype; |
| 153 | AudioCodingModule::Codec(n + 1, &nextCodec); |
| 154 | dummyCodec.pltype = nextCodec.pltype; |
| 155 | if (!FixedPayloadTypeCodec(nextCodec.plname)) { |
| 156 | _acmB->RegisterReceiveCodec(dummyCodec); |
| 157 | } |
| 158 | dummyCodec.pltype = currentPayloadType; |
| 159 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 161 | if ((n < numCodecs - 1) && !FixedPayloadTypeCodec(dummyCodec.plname)) { |
| 162 | // test if un-registration works; |
| 163 | CodecInst nextCodec; |
| 164 | AudioCodingModule::Codec(n + 1, &nextCodec); |
| 165 | nextCodec.pltype = dummyCodec.pltype; |
| 166 | if (!FixedPayloadTypeCodec(nextCodec.plname)) { |
| 167 | CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(nextCodec)); |
| 168 | CHECK_ERROR_MT(_acmA->UnregisterReceiveCodec(nextCodec.pltype)); |
| 169 | } |
| 170 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 171 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 172 | CHECK_ERROR_MT(_acmA->RegisterReceiveCodec(dummyCodec)); |
| 173 | printf(" side A done!"); |
| 174 | CHECK_ERROR_MT(_acmB->RegisterReceiveCodec(dummyCodec)); |
| 175 | printf(" side B done!\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 177 | if (!strcmp(dummyCodec.plname, "CN")) { |
| 178 | CHECK_ERROR_MT(_acmA->RegisterSendCodec(dummyCodec)); |
| 179 | CHECK_ERROR_MT(_acmB->RegisterSendCodec(dummyCodec)); |
| 180 | } |
| 181 | lastPayloadType = dummyCodec.pltype; |
| 182 | if ((lastPayloadType >= 96) && (lastPayloadType <= 127)) { |
| 183 | _payloadUsed[lastPayloadType - 96] = true; |
| 184 | } |
| 185 | } |
| 186 | _thereIsDecoderA = true; |
| 187 | _thereIsDecoderB = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 189 | // Register Send Codec |
| 190 | AudioCodingModule::Codec((uint8_t) _codecCntrA, &dummyCodec); |
| 191 | CHECK_ERROR_MT(_acmA->RegisterSendCodec(dummyCodec)); |
| 192 | _thereIsEncoderA = true; |
| 193 | // |
| 194 | AudioCodingModule::Codec((uint8_t) _codecCntrB, &dummyCodec); |
| 195 | CHECK_ERROR_MT(_acmB->RegisterSendCodec(dummyCodec)); |
| 196 | _thereIsEncoderB = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 198 | uint16_t frequencyHz; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 200 | printf("\n\nAPI Test\n"); |
| 201 | printf("========\n"); |
| 202 | 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] | 203 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 204 | //--- Input A |
| 205 | std::string file_name = webrtc::test::ResourcePath( |
| 206 | "audio_coding/testfile32kHz", "pcm"); |
| 207 | frequencyHz = 32000; |
| 208 | printf("Enter input file at side A [%s]: ", file_name.c_str()); |
| 209 | PCMFile::ChooseFile(&file_name, 499, &frequencyHz); |
| 210 | _inFileA.Open(file_name, frequencyHz, "rb", true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 211 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 212 | //--- Output A |
| 213 | std::string out_file_a = webrtc::test::OutputPath() + "outA.pcm"; |
| 214 | printf("Enter output file at side A [%s]: ", out_file_a.c_str()); |
| 215 | PCMFile::ChooseFile(&out_file_a, 499, &frequencyHz); |
| 216 | _outFileA.Open(out_file_a, frequencyHz, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 218 | //--- Input B |
| 219 | file_name = webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
| 220 | printf("\n\nEnter input file at side B [%s]: ", file_name.c_str()); |
| 221 | PCMFile::ChooseFile(&file_name, 499, &frequencyHz); |
| 222 | _inFileB.Open(file_name, frequencyHz, "rb", true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 223 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 224 | //--- Output B |
| 225 | std::string out_file_b = webrtc::test::OutputPath() + "outB.pcm"; |
| 226 | printf("Enter output file at side B [%s]: ", out_file_b.c_str()); |
| 227 | PCMFile::ChooseFile(&out_file_b, 499, &frequencyHz); |
| 228 | _outFileB.Open(out_file_b, frequencyHz, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 230 | //--- Set A-to-B channel |
| 231 | _channel_A2B = new Channel(2); |
| 232 | CHECK_ERROR_MT(_acmA->RegisterTransportCallback(_channel_A2B)); |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 233 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 234 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 235 | //--- Set B-to-A channel |
| 236 | _channel_B2A = new Channel(1); |
| 237 | CHECK_ERROR_MT(_acmB->RegisterTransportCallback(_channel_B2A)); |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 238 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
tina.legrand@webrtc.org | 5e7ca60 | 2012-06-12 07:16:24 +0000 | [diff] [blame] | 239 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 240 | //--- EVENT TIMERS |
| 241 | // A |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 242 | _pullEventA = EventTimerWrapper::Create(); |
| 243 | _pushEventA = EventTimerWrapper::Create(); |
| 244 | _processEventA = EventTimerWrapper::Create(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 245 | _apiEventA = EventWrapper::Create(); |
| 246 | // B |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 247 | _pullEventB = EventTimerWrapper::Create(); |
| 248 | _pushEventB = EventTimerWrapper::Create(); |
| 249 | _processEventB = EventTimerWrapper::Create(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 250 | _apiEventB = EventWrapper::Create(); |
| 251 | |
| 252 | //--- I/O params |
| 253 | // A |
| 254 | _outFreqHzA = _outFileA.SamplingFrequency(); |
| 255 | // B |
| 256 | _outFreqHzB = _outFileB.SamplingFrequency(); |
| 257 | |
| 258 | //Trace::SetEncryptedTraceFile("ACMAPITestEncrypted.txt"); |
| 259 | |
| 260 | char print[11]; |
| 261 | |
| 262 | // Create a trace file. |
| 263 | Trace::CreateTrace(); |
| 264 | Trace::SetTraceFile( |
| 265 | (webrtc::test::OutputPath() + "acm_api_trace.txt").c_str()); |
| 266 | |
| 267 | printf("\nRandom Test (y/n)?"); |
| 268 | EXPECT_TRUE(fgets(print, 10, stdin) != NULL); |
| 269 | print[10] = '\0'; |
| 270 | if (strstr(print, "y") != NULL) { |
| 271 | _randomTest = true; |
| 272 | _verbose = false; |
| 273 | _writeToFile = false; |
| 274 | } else { |
| 275 | _randomTest = false; |
| 276 | printf("\nPrint Tests (y/n)? "); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 277 | EXPECT_TRUE(fgets(print, 10, stdin) != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 278 | print[10] = '\0'; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 279 | if (strstr(print, "y") == NULL) { |
| 280 | EXPECT_TRUE(freopen("APITest_log.txt", "w", stdout) != 0); |
| 281 | _verbose = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 282 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 283 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 284 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 285 | _vadCallbackA = new VADCallback; |
| 286 | _vadCallbackB = new VADCallback; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 287 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 288 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 289 | } |
| 290 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 291 | bool APITest::PushAudioThreadA(void* obj) { |
| 292 | return static_cast<APITest*>(obj)->PushAudioRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 293 | } |
| 294 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 295 | bool APITest::PushAudioThreadB(void* obj) { |
| 296 | return static_cast<APITest*>(obj)->PushAudioRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | } |
| 298 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 299 | bool APITest::PullAudioThreadA(void* obj) { |
| 300 | return static_cast<APITest*>(obj)->PullAudioRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 301 | } |
| 302 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 303 | bool APITest::PullAudioThreadB(void* obj) { |
| 304 | return static_cast<APITest*>(obj)->PullAudioRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 305 | } |
| 306 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 307 | bool APITest::ProcessThreadA(void* obj) { |
| 308 | return static_cast<APITest*>(obj)->ProcessRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 309 | } |
| 310 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 311 | bool APITest::ProcessThreadB(void* obj) { |
| 312 | return static_cast<APITest*>(obj)->ProcessRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 313 | } |
| 314 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 315 | bool APITest::APIThreadA(void* obj) { |
| 316 | return static_cast<APITest*>(obj)->APIRunA(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 317 | } |
| 318 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 319 | bool APITest::APIThreadB(void* obj) { |
| 320 | return static_cast<APITest*>(obj)->APIRunB(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 321 | } |
| 322 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 323 | bool APITest::PullAudioRunA() { |
| 324 | _pullEventA->Wait(100); |
| 325 | AudioFrame audioFrame; |
| 326 | if (_acmA->PlayoutData10Ms(_outFreqHzA, &audioFrame) < 0) { |
| 327 | bool thereIsDecoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 328 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 329 | ReadLockScoped rl(_apiTestRWLock); |
| 330 | thereIsDecoder = _thereIsDecoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 331 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 332 | if (thereIsDecoder) { |
| 333 | fprintf(stderr, "\n>>>>>> cannot pull audio A <<<<<<<< \n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 334 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 335 | } else { |
| 336 | if (_writeToFile) { |
| 337 | _outFileA.Write10MsData(audioFrame); |
| 338 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 339 | } |
| 340 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 341 | } |
| 342 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 343 | bool APITest::PullAudioRunB() { |
| 344 | _pullEventB->Wait(100); |
| 345 | AudioFrame audioFrame; |
| 346 | if (_acmB->PlayoutData10Ms(_outFreqHzB, &audioFrame) < 0) { |
| 347 | bool thereIsDecoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 349 | ReadLockScoped rl(_apiTestRWLock); |
| 350 | thereIsDecoder = _thereIsDecoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 352 | if (thereIsDecoder) { |
| 353 | fprintf(stderr, "\n>>>>>> cannot pull audio B <<<<<<<< \n"); |
| 354 | fprintf(stderr, "%d %d\n", _testNumA, _testNumB); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 355 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 356 | } else { |
| 357 | if (_writeToFile) { |
| 358 | _outFileB.Write10MsData(audioFrame); |
| 359 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 360 | } |
| 361 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 362 | } |
| 363 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 364 | bool APITest::PushAudioRunA() { |
| 365 | _pushEventA->Wait(100); |
| 366 | AudioFrame audioFrame; |
| 367 | _inFileA.Read10MsData(audioFrame); |
| 368 | if (_acmA->Add10MsData(audioFrame) < 0) { |
| 369 | bool thereIsEncoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 370 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 371 | ReadLockScoped rl(_apiTestRWLock); |
| 372 | thereIsEncoder = _thereIsEncoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 373 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 374 | if (thereIsEncoder) { |
| 375 | fprintf(stderr, "\n>>>> add10MsData at A failed <<<<\n"); |
| 376 | } |
| 377 | } |
| 378 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 379 | } |
| 380 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 381 | bool APITest::PushAudioRunB() { |
| 382 | _pushEventB->Wait(100); |
| 383 | AudioFrame audioFrame; |
| 384 | _inFileB.Read10MsData(audioFrame); |
| 385 | if (_acmB->Add10MsData(audioFrame) < 0) { |
| 386 | bool thereIsEncoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 387 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 388 | ReadLockScoped rl(_apiTestRWLock); |
| 389 | thereIsEncoder = _thereIsEncoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 390 | } |
| 391 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 392 | if (thereIsEncoder) { |
| 393 | fprintf(stderr, "\n>>>> cannot add audio to B <<<<"); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 398 | } |
| 399 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 400 | bool APITest::ProcessRunA() { |
| 401 | _processEventA->Wait(100); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 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::ProcessRunB() { |
| 406 | _processEventB->Wait(100); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 407 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /*/ |
| 411 | * |
| 412 | * In side A we test the APIs which are related to sender Side. |
| 413 | * |
| 414 | /*/ |
| 415 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 416 | void APITest::RunTest(char thread) { |
| 417 | int testNum; |
| 418 | { |
| 419 | WriteLockScoped cs(_apiTestRWLock); |
| 420 | if (thread == 'A') { |
henrik.lundin | 1bd0e03 | 2015-09-28 06:12:17 -0700 | [diff] [blame] | 421 | _testNumA = (_testNumB + 1 + (rand() % 3)) % 4; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 422 | testNum = _testNumA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 423 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 424 | _movingDot[_dotPositionA] = ' '; |
| 425 | if (_dotPositionA == 0) { |
| 426 | _dotMoveDirectionA = 1; |
| 427 | } |
| 428 | if (_dotPositionA == 19) { |
| 429 | _dotMoveDirectionA = -1; |
| 430 | } |
| 431 | _dotPositionA += _dotMoveDirectionA; |
| 432 | _movingDot[_dotPositionA] = (_dotMoveDirectionA > 0) ? '>' : '<'; |
| 433 | } else { |
henrik.lundin | 1bd0e03 | 2015-09-28 06:12:17 -0700 | [diff] [blame] | 434 | _testNumB = (_testNumA + 1 + (rand() % 3)) % 4; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 435 | testNum = _testNumB; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 436 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 437 | _movingDot[_dotPositionB] = ' '; |
| 438 | if (_dotPositionB == 20) { |
| 439 | _dotMoveDirectionB = 1; |
| 440 | } |
| 441 | if (_dotPositionB == 39) { |
| 442 | _dotMoveDirectionB = -1; |
| 443 | } |
| 444 | _dotPositionB += _dotMoveDirectionB; |
| 445 | _movingDot[_dotPositionB] = (_dotMoveDirectionB > 0) ? '>' : '<'; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 446 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 447 | //fprintf(stderr, "%c: %d \n", thread, testNum); |
| 448 | //fflush(stderr); |
| 449 | } |
| 450 | switch (testNum) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 451 | case 0: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 452 | CurrentCodec('A'); |
| 453 | ChangeCodec('A'); |
| 454 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 455 | case 1: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 456 | if (!_randomTest) { |
| 457 | fprintf(stdout, "\nTesting Delay ...\n"); |
| 458 | } |
| 459 | TestDelay('A'); |
| 460 | break; |
henrik.lundin | 1bd0e03 | 2015-09-28 06:12:17 -0700 | [diff] [blame] | 461 | case 2: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 462 | TestSendVAD('A'); |
| 463 | break; |
henrik.lundin | 1bd0e03 | 2015-09-28 06:12:17 -0700 | [diff] [blame] | 464 | case 3: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 465 | TestRegisteration('A'); |
| 466 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 467 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 468 | fprintf(stderr, "Wrong Test Number\n"); |
marpan@webrtc.org | 4765ca5 | 2014-11-03 20:10:26 +0000 | [diff] [blame] | 469 | getc(stdin); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 470 | exit(1); |
| 471 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 472 | } |
| 473 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 474 | bool APITest::APIRunA() { |
| 475 | _apiEventA->Wait(50); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 476 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 477 | bool randomTest; |
| 478 | { |
| 479 | ReadLockScoped rl(_apiTestRWLock); |
| 480 | randomTest = _randomTest; |
| 481 | } |
| 482 | if (randomTest) { |
| 483 | RunTest('A'); |
| 484 | } else { |
| 485 | CurrentCodec('A'); |
| 486 | ChangeCodec('A'); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 487 | if (_codecCntrA == 0) { |
| 488 | fprintf(stdout, "\nTesting Delay ...\n"); |
| 489 | TestDelay('A'); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 490 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 491 | // VAD TEST |
| 492 | TestSendVAD('A'); |
| 493 | TestRegisteration('A'); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 494 | } |
| 495 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 496 | } |
| 497 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 498 | bool APITest::APIRunB() { |
| 499 | _apiEventB->Wait(50); |
| 500 | bool randomTest; |
| 501 | { |
| 502 | ReadLockScoped rl(_apiTestRWLock); |
| 503 | randomTest = _randomTest; |
| 504 | } |
| 505 | //_apiEventB->Wait(2000); |
| 506 | if (randomTest) { |
| 507 | RunTest('B'); |
| 508 | } |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 509 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 510 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 511 | } |
| 512 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 513 | void APITest::Perform() { |
| 514 | SetUp(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 515 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 516 | //--- THREADS |
| 517 | // A |
| 518 | // PUSH |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 519 | rtc::PlatformThread myPushAudioThreadA(PushAudioThreadA, this, |
| 520 | "PushAudioThreadA"); |
| 521 | myPushAudioThreadA.Start(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 522 | // PULL |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 523 | rtc::PlatformThread myPullAudioThreadA(PullAudioThreadA, this, |
| 524 | "PullAudioThreadA"); |
| 525 | myPullAudioThreadA.Start(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 526 | // Process |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 527 | rtc::PlatformThread myProcessThreadA(ProcessThreadA, this, "ProcessThreadA"); |
| 528 | myProcessThreadA.Start(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 529 | // API |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 530 | rtc::PlatformThread myAPIThreadA(APIThreadA, this, "APIThreadA"); |
| 531 | myAPIThreadA.Start(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 532 | // B |
| 533 | // PUSH |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 534 | rtc::PlatformThread myPushAudioThreadB(PushAudioThreadB, this, |
| 535 | "PushAudioThreadB"); |
| 536 | myPushAudioThreadB.Start(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 537 | // PULL |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 538 | rtc::PlatformThread myPullAudioThreadB(PullAudioThreadB, this, |
| 539 | "PullAudioThreadB"); |
| 540 | myPullAudioThreadB.Start(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 541 | // Process |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 542 | rtc::PlatformThread myProcessThreadB(ProcessThreadB, this, "ProcessThreadB"); |
| 543 | myProcessThreadB.Start(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 544 | // API |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 545 | rtc::PlatformThread myAPIThreadB(APIThreadB, this, "APIThreadB"); |
| 546 | myAPIThreadB.Start(); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 547 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 548 | //_apiEventA->StartTimer(true, 5000); |
| 549 | //_apiEventB->StartTimer(true, 5000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 550 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 551 | _processEventA->StartTimer(true, 10); |
| 552 | _processEventB->StartTimer(true, 10); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 553 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 554 | _pullEventA->StartTimer(true, 10); |
| 555 | _pullEventB->StartTimer(true, 10); |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 556 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 557 | _pushEventA->StartTimer(true, 10); |
| 558 | _pushEventB->StartTimer(true, 10); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 559 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 560 | // Keep main thread waiting for sender/receiver |
| 561 | // threads to complete |
| 562 | EventWrapper* completeEvent = EventWrapper::Create(); |
| 563 | uint64_t startTime = TickTime::MillisecondTimestamp(); |
| 564 | uint64_t currentTime; |
| 565 | // Run test in 2 minutes (120000 ms). |
| 566 | do { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 567 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 568 | //ReadLockScoped rl(_apiTestRWLock); |
| 569 | //fprintf(stderr, "\r%s", _movingDot); |
| 570 | } |
| 571 | //fflush(stderr); |
| 572 | completeEvent->Wait(50); |
| 573 | currentTime = TickTime::MillisecondTimestamp(); |
| 574 | } while ((currentTime - startTime) < 120000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 575 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 576 | //completeEvent->Wait(0xFFFFFFFF); |
| 577 | //(unsigned long)((unsigned long)TEST_DURATION_SEC * (unsigned long)1000)); |
| 578 | delete completeEvent; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 579 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 580 | myPushAudioThreadA.Stop(); |
| 581 | myPullAudioThreadA.Stop(); |
| 582 | myProcessThreadA.Stop(); |
| 583 | myAPIThreadA.Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 584 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 585 | myPushAudioThreadB.Stop(); |
| 586 | myPullAudioThreadB.Stop(); |
| 587 | myProcessThreadB.Stop(); |
| 588 | myAPIThreadB.Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 589 | } |
| 590 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 591 | void APITest::CheckVADStatus(char side) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 592 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 593 | bool dtxEnabled; |
| 594 | bool vadEnabled; |
| 595 | ACMVADMode vadMode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 596 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 597 | if (side == 'A') { |
| 598 | _acmA->VAD(&dtxEnabled, &vadEnabled, &vadMode); |
| 599 | _acmA->RegisterVADCallback(NULL); |
| 600 | _vadCallbackA->Reset(); |
| 601 | _acmA->RegisterVADCallback(_vadCallbackA); |
tina.legrand@webrtc.org | 2e09692 | 2011-08-18 06:20:30 +0000 | [diff] [blame] | 602 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 603 | if (!_randomTest) { |
| 604 | if (_verbose) { |
| 605 | fprintf(stdout, "DTX %3s, VAD %3s, Mode %d", dtxEnabled ? "ON" : "OFF", |
| 606 | vadEnabled ? "ON" : "OFF", (int) vadMode); |
| 607 | Wait(5000); |
| 608 | fprintf(stdout, " => bit-rate %3.0f kbps\n", _channel_A2B->BitRate()); |
| 609 | } else { |
| 610 | Wait(5000); |
| 611 | fprintf(stdout, "DTX %3s, VAD %3s, Mode %d => bit-rate %3.0f kbps\n", |
| 612 | dtxEnabled ? "ON" : "OFF", vadEnabled ? "ON" : "OFF", |
| 613 | (int) vadMode, _channel_A2B->BitRate()); |
| 614 | } |
| 615 | _vadCallbackA->PrintFrameTypes(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 616 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 617 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 618 | if (dtxEnabled != _sendDTXA) { |
| 619 | fprintf(stderr, ">>> Error Enabling DTX <<<\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 620 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 621 | if ((vadEnabled != _sendVADA) && (!dtxEnabled)) { |
| 622 | fprintf(stderr, ">>> Error Enabling VAD <<<\n"); |
| 623 | } |
| 624 | if ((vadMode != _sendVADModeA) && vadEnabled) { |
| 625 | fprintf(stderr, ">>> Error setting VAD-mode <<<\n"); |
| 626 | } |
| 627 | } else { |
| 628 | _acmB->VAD(&dtxEnabled, &vadEnabled, &vadMode); |
| 629 | |
| 630 | _acmB->RegisterVADCallback(NULL); |
| 631 | _vadCallbackB->Reset(); |
| 632 | _acmB->RegisterVADCallback(_vadCallbackB); |
| 633 | |
| 634 | if (!_randomTest) { |
| 635 | if (_verbose) { |
| 636 | fprintf(stdout, "DTX %3s, VAD %3s, Mode %d", dtxEnabled ? "ON" : "OFF", |
| 637 | vadEnabled ? "ON" : "OFF", (int) vadMode); |
| 638 | Wait(5000); |
| 639 | fprintf(stdout, " => bit-rate %3.0f kbps\n", _channel_B2A->BitRate()); |
| 640 | } else { |
| 641 | Wait(5000); |
| 642 | fprintf(stdout, "DTX %3s, VAD %3s, Mode %d => bit-rate %3.0f kbps\n", |
| 643 | dtxEnabled ? "ON" : "OFF", vadEnabled ? "ON" : "OFF", |
| 644 | (int) vadMode, _channel_B2A->BitRate()); |
| 645 | } |
| 646 | _vadCallbackB->PrintFrameTypes(); |
| 647 | } |
| 648 | |
| 649 | if (dtxEnabled != _sendDTXB) { |
| 650 | fprintf(stderr, ">>> Error Enabling DTX <<<\n"); |
| 651 | } |
| 652 | if ((vadEnabled != _sendVADB) && (!dtxEnabled)) { |
| 653 | fprintf(stderr, ">>> Error Enabling VAD <<<\n"); |
| 654 | } |
| 655 | if ((vadMode != _sendVADModeB) && vadEnabled) { |
| 656 | fprintf(stderr, ">>> Error setting VAD-mode <<<\n"); |
| 657 | } |
| 658 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | // Set Min delay, get delay, playout timestamp |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 662 | void APITest::TestDelay(char side) { |
| 663 | AudioCodingModule* myACM; |
| 664 | Channel* myChannel; |
| 665 | int32_t* myMinDelay; |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 666 | EventTimerWrapper* myEvent = EventTimerWrapper::Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 667 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 668 | uint32_t inTimestamp = 0; |
| 669 | uint32_t outTimestamp = 0; |
| 670 | double estimDelay = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 671 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 672 | double averageEstimDelay = 0; |
| 673 | double averageDelay = 0; |
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 | CircularBuffer estimDelayCB(100); |
| 676 | estimDelayCB.SetArithMean(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 677 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 678 | if (side == 'A') { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 679 | myACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 680 | myChannel = _channel_B2A; |
| 681 | myMinDelay = &_minDelayA; |
| 682 | } else { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 683 | myACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 684 | myChannel = _channel_A2B; |
| 685 | myMinDelay = &_minDelayB; |
| 686 | } |
| 687 | |
| 688 | CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay)); |
| 689 | |
| 690 | inTimestamp = myChannel->LastInTimestamp(); |
| 691 | CHECK_ERROR_MT(myACM->PlayoutTimestamp(&outTimestamp)); |
| 692 | |
| 693 | if (!_randomTest) { |
| 694 | myEvent->StartTimer(true, 30); |
| 695 | int n = 0; |
| 696 | int settlePoint = 5000; |
| 697 | while (n < settlePoint + 400) { |
| 698 | myEvent->Wait(1000); |
| 699 | |
| 700 | inTimestamp = myChannel->LastInTimestamp(); |
| 701 | CHECK_ERROR_MT(myACM->PlayoutTimestamp(&outTimestamp)); |
| 702 | |
| 703 | //std::cout << outTimestamp << std::endl << std::flush; |
| 704 | estimDelay = (double) ((uint32_t)(inTimestamp - outTimestamp)) |
| 705 | / ((double) myACM->ReceiveFrequency() / 1000.0); |
| 706 | |
| 707 | estimDelayCB.Update(estimDelay); |
| 708 | |
| 709 | estimDelayCB.ArithMean(averageEstimDelay); |
| 710 | //printf("\n %6.1f \n", estimDelay); |
| 711 | //std::cout << " " << std::flush; |
| 712 | |
| 713 | if (_verbose) { |
| 714 | fprintf(stdout, |
| 715 | "\rExpected: %4d, retreived: %6.1f, measured: %6.1f", |
| 716 | *myMinDelay, averageDelay, averageEstimDelay); |
| 717 | std::cout << " " << std::flush; |
| 718 | } |
| 719 | if ((averageDelay > *myMinDelay) && (n < settlePoint)) { |
| 720 | settlePoint = n; |
| 721 | } |
| 722 | n++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 723 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 724 | myEvent->StopTimer(); |
| 725 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 726 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 727 | if ((!_verbose) && (!_randomTest)) { |
| 728 | fprintf(stdout, "\nExpected: %4d, retreived: %6.1f, measured: %6.1f", |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 729 | *myMinDelay, averageDelay, averageEstimDelay); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 730 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 731 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 732 | *myMinDelay = (rand() % 1000) + 1; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 733 | |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 734 | NetworkStatistics networkStat; |
| 735 | CHECK_ERROR_MT(myACM->GetNetworkStatistics(&networkStat)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 736 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 737 | if (!_randomTest) { |
| 738 | fprintf(stdout, "\n\nJitter Statistics at Side %c\n", side); |
| 739 | fprintf(stdout, "--------------------------------------\n"); |
| 740 | fprintf(stdout, "buffer-size............. %d\n", |
| 741 | networkStat.currentBufferSize); |
| 742 | fprintf(stdout, "Preferred buffer-size... %d\n", |
| 743 | networkStat.preferredBufferSize); |
| 744 | fprintf(stdout, "Peaky jitter mode........%d\n", |
| 745 | networkStat.jitterPeaksFound); |
| 746 | fprintf(stdout, "packet-size rate........ %d\n", |
| 747 | networkStat.currentPacketLossRate); |
| 748 | fprintf(stdout, "discard rate............ %d\n", |
| 749 | networkStat.currentDiscardRate); |
| 750 | fprintf(stdout, "expand rate............. %d\n", |
| 751 | networkStat.currentExpandRate); |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 752 | fprintf(stdout, "speech expand rate...... %d\n", |
| 753 | networkStat.currentSpeechExpandRate); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 754 | fprintf(stdout, "Preemptive rate......... %d\n", |
| 755 | networkStat.currentPreemptiveRate); |
| 756 | fprintf(stdout, "Accelerate rate......... %d\n", |
| 757 | networkStat.currentAccelerateRate); |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 758 | fprintf(stdout, "Secondary decoded rate.. %d\n", |
| 759 | networkStat.currentSecondaryDecodedRate); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 760 | fprintf(stdout, "Clock-drift............. %d\n", networkStat.clockDriftPPM); |
| 761 | fprintf(stdout, "Mean waiting time....... %d\n", |
| 762 | networkStat.meanWaitingTimeMs); |
| 763 | fprintf(stdout, "Median waiting time..... %d\n", |
| 764 | networkStat.medianWaitingTimeMs); |
| 765 | fprintf(stdout, "Min waiting time........ %d\n", |
| 766 | networkStat.minWaitingTimeMs); |
| 767 | fprintf(stdout, "Max waiting time........ %d\n", |
| 768 | networkStat.maxWaitingTimeMs); |
| 769 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 770 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 771 | CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 772 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 773 | if (!_randomTest) { |
| 774 | myEvent->Wait(500); |
| 775 | fprintf(stdout, "\n"); |
| 776 | fprintf(stdout, "\n"); |
| 777 | } |
| 778 | delete myEvent; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | // Unregister a codec & register again. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 782 | void APITest::TestRegisteration(char sendSide) { |
| 783 | AudioCodingModule* sendACM; |
| 784 | AudioCodingModule* receiveACM; |
| 785 | bool* thereIsDecoder; |
| 786 | EventWrapper* myEvent = EventWrapper::Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 787 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 788 | if (!_randomTest) { |
| 789 | fprintf(stdout, "\n\n"); |
| 790 | fprintf(stdout, |
| 791 | "---------------------------------------------------------\n"); |
| 792 | fprintf(stdout, " Unregister/register Receive Codec\n"); |
| 793 | fprintf(stdout, |
| 794 | "---------------------------------------------------------\n"); |
| 795 | } |
| 796 | |
| 797 | switch (sendSide) { |
| 798 | case 'A': { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 799 | sendACM = _acmA.get(); |
| 800 | receiveACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 801 | thereIsDecoder = &_thereIsDecoderB; |
| 802 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 803 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 804 | case 'B': { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 805 | sendACM = _acmB.get(); |
| 806 | receiveACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 807 | thereIsDecoder = &_thereIsDecoderA; |
| 808 | break; |
| 809 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 810 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 811 | fprintf(stderr, "Invalid sender-side in TestRegistration(%c)\n", |
| 812 | sendSide); |
| 813 | exit(-1); |
| 814 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 815 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 816 | auto myCodec = sendACM->SendCodec(); |
| 817 | if (!myCodec) { |
| 818 | CodecInst ci; |
| 819 | AudioCodingModule::Codec(_codecCntrA, &ci); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 820 | myCodec = rtc::Optional<CodecInst>(ci); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 821 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 822 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 823 | if (!_randomTest) { |
| 824 | fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n"); |
| 825 | fflush (stdout); |
| 826 | } |
| 827 | { |
| 828 | WriteLockScoped wl(_apiTestRWLock); |
| 829 | *thereIsDecoder = false; |
| 830 | } |
| 831 | //myEvent->Wait(20); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 832 | CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 833 | Wait(1000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 834 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 835 | int currentPayload = myCodec->pltype; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 836 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 837 | if (!FixedPayloadTypeCodec(myCodec->plname)) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 838 | int32_t i; |
| 839 | for (i = 0; i < 32; i++) { |
| 840 | if (!_payloadUsed[i]) { |
| 841 | if (!_randomTest) { |
| 842 | fprintf(stdout, |
| 843 | "Register receive codec with new Payload, AUDIO BACK.\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 844 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 845 | //myCodec->pltype = i + 96; |
| 846 | //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
| 847 | //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 848 | //myEvent->Wait(20); |
| 849 | //{ |
| 850 | // WriteLockScoped wl(_apiTestRWLock); |
| 851 | // *thereIsDecoder = true; |
| 852 | //} |
| 853 | Wait(1000); |
| 854 | |
| 855 | if (!_randomTest) { |
| 856 | fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 857 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 858 | //{ |
| 859 | // WriteLockScoped wl(_apiTestRWLock); |
| 860 | // *thereIsDecoder = false; |
| 861 | //} |
| 862 | //myEvent->Wait(20); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 863 | //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 864 | Wait(1000); |
| 865 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 866 | myCodec->pltype = currentPayload; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 867 | if (!_randomTest) { |
| 868 | fprintf(stdout, |
| 869 | "Register receive codec with default Payload, AUDIO BACK.\n"); |
| 870 | fflush (stdout); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 871 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 872 | CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
| 873 | //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 874 | myEvent->Wait(20); |
| 875 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 876 | WriteLockScoped wl(_apiTestRWLock); |
| 877 | *thereIsDecoder = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 878 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 879 | Wait(1000); |
| 880 | |
| 881 | break; |
| 882 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 883 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 884 | if (i == 32) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 885 | CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 886 | { |
| 887 | WriteLockScoped wl(_apiTestRWLock); |
| 888 | *thereIsDecoder = true; |
| 889 | } |
| 890 | } |
| 891 | } else { |
| 892 | if (!_randomTest) { |
| 893 | fprintf(stdout, |
| 894 | "Register receive codec with fixed Payload, AUDIO BACK.\n"); |
| 895 | fflush (stdout); |
| 896 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 897 | CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
| 898 | //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); |
| 899 | //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 900 | myEvent->Wait(20); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 901 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 902 | WriteLockScoped wl(_apiTestRWLock); |
| 903 | *thereIsDecoder = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 904 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 905 | } |
| 906 | delete myEvent; |
| 907 | if (!_randomTest) { |
| 908 | fprintf(stdout, |
| 909 | "---------------------------------------------------------\n"); |
| 910 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 911 | } |
| 912 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 913 | void APITest::TestSendVAD(char side) { |
| 914 | if (_randomTest) { |
| 915 | return; |
| 916 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 917 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 918 | bool* vad; |
| 919 | bool* dtx; |
| 920 | ACMVADMode* mode; |
| 921 | Channel* myChannel; |
| 922 | AudioCodingModule* myACM; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 923 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 924 | CodecInst myCodec; |
| 925 | if (!_randomTest) { |
| 926 | fprintf(stdout, "\n\n"); |
| 927 | fprintf(stdout, "-----------------------------------------------\n"); |
| 928 | fprintf(stdout, " Test VAD API\n"); |
| 929 | fprintf(stdout, "-----------------------------------------------\n"); |
| 930 | } |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 931 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 932 | if (side == 'A') { |
| 933 | AudioCodingModule::Codec(_codecCntrA, &myCodec); |
| 934 | vad = &_sendVADA; |
| 935 | dtx = &_sendDTXA; |
| 936 | mode = &_sendVADModeA; |
| 937 | myChannel = _channel_A2B; |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 938 | myACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 939 | } else { |
| 940 | AudioCodingModule::Codec(_codecCntrB, &myCodec); |
| 941 | vad = &_sendVADB; |
| 942 | dtx = &_sendDTXB; |
| 943 | mode = &_sendVADModeB; |
| 944 | myChannel = _channel_B2A; |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 945 | myACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 946 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 947 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 948 | CheckVADStatus(side); |
| 949 | if (!_randomTest) { |
| 950 | fprintf(stdout, "\n\n"); |
| 951 | } |
| 952 | |
| 953 | switch (*mode) { |
| 954 | case VADNormal: |
| 955 | *vad = true; |
| 956 | *dtx = true; |
| 957 | *mode = VADAggr; |
| 958 | break; |
| 959 | case VADLowBitrate: |
| 960 | *vad = true; |
| 961 | *dtx = true; |
| 962 | *mode = VADVeryAggr; |
| 963 | break; |
| 964 | case VADAggr: |
| 965 | *vad = true; |
| 966 | *dtx = true; |
| 967 | *mode = VADLowBitrate; |
| 968 | break; |
| 969 | case VADVeryAggr: |
| 970 | *vad = false; |
| 971 | *dtx = false; |
| 972 | *mode = VADNormal; |
| 973 | break; |
| 974 | default: |
| 975 | *mode = VADNormal; |
| 976 | } |
| 977 | |
| 978 | *dtx = (myCodec.plfreq == 32000) ? false : *dtx; |
| 979 | |
| 980 | CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode)); |
| 981 | myChannel->ResetStats(); |
| 982 | |
| 983 | CheckVADStatus(side); |
| 984 | if (!_randomTest) { |
| 985 | fprintf(stdout, "\n"); |
| 986 | fprintf(stdout, "-----------------------------------------------\n"); |
| 987 | } |
| 988 | |
| 989 | // Fault Test |
| 990 | CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) - 1)); |
| 991 | CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) 4)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 992 | |
| 993 | } |
| 994 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 995 | void APITest::CurrentCodec(char side) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 996 | auto myCodec = (side == 'A' ? _acmA : _acmB)->SendCodec(); |
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 | if (!_randomTest) { |
| 999 | fprintf(stdout, "\n\n"); |
| 1000 | fprintf(stdout, "Send codec in Side A\n"); |
| 1001 | fprintf(stdout, "----------------------------\n"); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 1002 | fprintf(stdout, "Name................. %s\n", myCodec->plname); |
| 1003 | fprintf(stdout, "Sampling Frequency... %d\n", myCodec->plfreq); |
| 1004 | fprintf(stdout, "Rate................. %d\n", myCodec->rate); |
| 1005 | fprintf(stdout, "Payload-type......... %d\n", myCodec->pltype); |
| 1006 | fprintf(stdout, "Packet-size.......... %d\n", myCodec->pacsize); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1007 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1008 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1009 | Wait(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1012 | void APITest::ChangeCodec(char side) { |
| 1013 | CodecInst myCodec; |
| 1014 | AudioCodingModule* myACM; |
| 1015 | uint8_t* codecCntr; |
| 1016 | bool* thereIsEncoder; |
| 1017 | bool* vad; |
| 1018 | bool* dtx; |
| 1019 | ACMVADMode* mode; |
| 1020 | Channel* myChannel; |
| 1021 | // Reset and Wait |
| 1022 | if (!_randomTest) { |
| 1023 | fprintf(stdout, "Reset Encoder Side A \n"); |
| 1024 | } |
| 1025 | if (side == 'A') { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 1026 | myACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1027 | codecCntr = &_codecCntrA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1028 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1029 | WriteLockScoped wl(_apiTestRWLock); |
| 1030 | thereIsEncoder = &_thereIsEncoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1031 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1032 | vad = &_sendVADA; |
| 1033 | dtx = &_sendDTXA; |
| 1034 | mode = &_sendVADModeA; |
| 1035 | myChannel = _channel_A2B; |
| 1036 | } else { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 1037 | myACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1038 | codecCntr = &_codecCntrB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1039 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1040 | WriteLockScoped wl(_apiTestRWLock); |
| 1041 | thereIsEncoder = &_thereIsEncoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1042 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1043 | vad = &_sendVADB; |
| 1044 | dtx = &_sendDTXB; |
| 1045 | mode = &_sendVADModeB; |
| 1046 | myChannel = _channel_B2A; |
| 1047 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1048 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1049 | Wait(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1050 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1051 | // Register the next codec |
| 1052 | do { |
| 1053 | *codecCntr = |
| 1054 | (*codecCntr < AudioCodingModule::NumberOfCodecs() - 1) ? |
| 1055 | (*codecCntr + 1) : 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1056 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1057 | if (*codecCntr == 0) { |
| 1058 | //printf("Initialize Sender Side A \n"); |
| 1059 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1060 | WriteLockScoped wl(_apiTestRWLock); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1061 | *thereIsEncoder = false; |
| 1062 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1063 | // After Initialization CN is lost, re-register them |
| 1064 | if (AudioCodingModule::Codec("CN", &myCodec, 8000, 1) >= 0) { |
| 1065 | CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec)); |
| 1066 | } |
| 1067 | if (AudioCodingModule::Codec("CN", &myCodec, 16000, 1) >= 0) { |
| 1068 | CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec)); |
| 1069 | } |
| 1070 | // VAD & DTX are disabled after initialization |
| 1071 | *vad = false; |
| 1072 | *dtx = false; |
| 1073 | _writeToFile = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1074 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1075 | |
| 1076 | AudioCodingModule::Codec(*codecCntr, &myCodec); |
| 1077 | } while (!STR_CASE_CMP(myCodec.plname, "CN") |
| 1078 | || !STR_CASE_CMP(myCodec.plname, "telephone-event") |
| 1079 | || !STR_CASE_CMP(myCodec.plname, "RED")); |
| 1080 | |
| 1081 | if (!_randomTest) { |
| 1082 | fprintf(stdout,"\n=====================================================\n"); |
| 1083 | fprintf(stdout, " Registering New Codec %s, %d kHz, %d kbps\n", |
| 1084 | myCodec.plname, myCodec.plfreq / 1000, myCodec.rate / 1000); |
| 1085 | } |
| 1086 | //std::cout<< std::flush; |
| 1087 | |
| 1088 | // NO DTX for supe-wideband codec at this point |
| 1089 | if (myCodec.plfreq == 32000) { |
| 1090 | *dtx = false; |
| 1091 | CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode)); |
| 1092 | |
| 1093 | } |
| 1094 | |
| 1095 | CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec)); |
| 1096 | myChannel->ResetStats(); |
| 1097 | { |
| 1098 | WriteLockScoped wl(_apiTestRWLock); |
| 1099 | *thereIsEncoder = true; |
| 1100 | } |
| 1101 | Wait(500); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1104 | } // namespace webrtc |