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; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 669 | double estimDelay = 0; |
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 | double averageEstimDelay = 0; |
| 672 | double averageDelay = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 673 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 674 | CircularBuffer estimDelayCB(100); |
| 675 | estimDelayCB.SetArithMean(true); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 676 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 677 | if (side == 'A') { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 678 | myACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 679 | myChannel = _channel_B2A; |
| 680 | myMinDelay = &_minDelayA; |
| 681 | } else { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 682 | myACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 683 | myChannel = _channel_A2B; |
| 684 | myMinDelay = &_minDelayB; |
| 685 | } |
| 686 | |
| 687 | CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay)); |
| 688 | |
| 689 | inTimestamp = myChannel->LastInTimestamp(); |
henrik.lundin | 9a410dd | 2016-04-06 01:39:22 -0700 | [diff] [blame] | 690 | rtc::Optional<uint32_t> outTimestamp = myACM->PlayoutTimestamp(); |
| 691 | CHECK_ERROR_MT(outTimestamp ? 0 : -1); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 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(); |
henrik.lundin | 9a410dd | 2016-04-06 01:39:22 -0700 | [diff] [blame] | 701 | outTimestamp = myACM->PlayoutTimestamp(); |
| 702 | CHECK_ERROR_MT(outTimestamp ? 0 : -1); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 703 | |
| 704 | //std::cout << outTimestamp << std::endl << std::flush; |
henrik.lundin | 9a410dd | 2016-04-06 01:39:22 -0700 | [diff] [blame] | 705 | estimDelay = (double)((uint32_t)(inTimestamp - *outTimestamp)) / |
| 706 | ((double)myACM->ReceiveFrequency() / 1000.0); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 707 | |
| 708 | estimDelayCB.Update(estimDelay); |
| 709 | |
| 710 | estimDelayCB.ArithMean(averageEstimDelay); |
| 711 | //printf("\n %6.1f \n", estimDelay); |
| 712 | //std::cout << " " << std::flush; |
| 713 | |
| 714 | if (_verbose) { |
| 715 | fprintf(stdout, |
| 716 | "\rExpected: %4d, retreived: %6.1f, measured: %6.1f", |
| 717 | *myMinDelay, averageDelay, averageEstimDelay); |
| 718 | std::cout << " " << std::flush; |
| 719 | } |
| 720 | if ((averageDelay > *myMinDelay) && (n < settlePoint)) { |
| 721 | settlePoint = n; |
| 722 | } |
| 723 | n++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 724 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 725 | myEvent->StopTimer(); |
| 726 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 727 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 728 | if ((!_verbose) && (!_randomTest)) { |
| 729 | fprintf(stdout, "\nExpected: %4d, retreived: %6.1f, measured: %6.1f", |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 730 | *myMinDelay, averageDelay, averageEstimDelay); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 731 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 732 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 733 | *myMinDelay = (rand() % 1000) + 1; |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 734 | |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 735 | NetworkStatistics networkStat; |
| 736 | CHECK_ERROR_MT(myACM->GetNetworkStatistics(&networkStat)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 737 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 738 | if (!_randomTest) { |
| 739 | fprintf(stdout, "\n\nJitter Statistics at Side %c\n", side); |
| 740 | fprintf(stdout, "--------------------------------------\n"); |
| 741 | fprintf(stdout, "buffer-size............. %d\n", |
| 742 | networkStat.currentBufferSize); |
| 743 | fprintf(stdout, "Preferred buffer-size... %d\n", |
| 744 | networkStat.preferredBufferSize); |
| 745 | fprintf(stdout, "Peaky jitter mode........%d\n", |
| 746 | networkStat.jitterPeaksFound); |
| 747 | fprintf(stdout, "packet-size rate........ %d\n", |
| 748 | networkStat.currentPacketLossRate); |
| 749 | fprintf(stdout, "discard rate............ %d\n", |
| 750 | networkStat.currentDiscardRate); |
| 751 | fprintf(stdout, "expand rate............. %d\n", |
| 752 | networkStat.currentExpandRate); |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 753 | fprintf(stdout, "speech expand rate...... %d\n", |
| 754 | networkStat.currentSpeechExpandRate); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 755 | fprintf(stdout, "Preemptive rate......... %d\n", |
| 756 | networkStat.currentPreemptiveRate); |
| 757 | fprintf(stdout, "Accelerate rate......... %d\n", |
| 758 | networkStat.currentAccelerateRate); |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 759 | fprintf(stdout, "Secondary decoded rate.. %d\n", |
| 760 | networkStat.currentSecondaryDecodedRate); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 761 | fprintf(stdout, "Clock-drift............. %d\n", networkStat.clockDriftPPM); |
| 762 | fprintf(stdout, "Mean waiting time....... %d\n", |
| 763 | networkStat.meanWaitingTimeMs); |
| 764 | fprintf(stdout, "Median waiting time..... %d\n", |
| 765 | networkStat.medianWaitingTimeMs); |
| 766 | fprintf(stdout, "Min waiting time........ %d\n", |
| 767 | networkStat.minWaitingTimeMs); |
| 768 | fprintf(stdout, "Max waiting time........ %d\n", |
| 769 | networkStat.maxWaitingTimeMs); |
| 770 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 771 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 772 | CHECK_ERROR_MT(myACM->SetMinimumPlayoutDelay(*myMinDelay)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 773 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 774 | if (!_randomTest) { |
| 775 | myEvent->Wait(500); |
| 776 | fprintf(stdout, "\n"); |
| 777 | fprintf(stdout, "\n"); |
| 778 | } |
| 779 | delete myEvent; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | // Unregister a codec & register again. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 783 | void APITest::TestRegisteration(char sendSide) { |
| 784 | AudioCodingModule* sendACM; |
| 785 | AudioCodingModule* receiveACM; |
| 786 | bool* thereIsDecoder; |
| 787 | EventWrapper* myEvent = EventWrapper::Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 788 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 789 | if (!_randomTest) { |
| 790 | fprintf(stdout, "\n\n"); |
| 791 | fprintf(stdout, |
| 792 | "---------------------------------------------------------\n"); |
| 793 | fprintf(stdout, " Unregister/register Receive Codec\n"); |
| 794 | fprintf(stdout, |
| 795 | "---------------------------------------------------------\n"); |
| 796 | } |
| 797 | |
| 798 | switch (sendSide) { |
| 799 | case 'A': { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 800 | sendACM = _acmA.get(); |
| 801 | receiveACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 802 | thereIsDecoder = &_thereIsDecoderB; |
| 803 | break; |
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 | case 'B': { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 806 | sendACM = _acmB.get(); |
| 807 | receiveACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 808 | thereIsDecoder = &_thereIsDecoderA; |
| 809 | break; |
| 810 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 811 | default: |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 812 | fprintf(stderr, "Invalid sender-side in TestRegistration(%c)\n", |
| 813 | sendSide); |
| 814 | exit(-1); |
| 815 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 816 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 817 | auto myCodec = sendACM->SendCodec(); |
| 818 | if (!myCodec) { |
| 819 | CodecInst ci; |
| 820 | AudioCodingModule::Codec(_codecCntrA, &ci); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 821 | myCodec = rtc::Optional<CodecInst>(ci); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 822 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 823 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 824 | if (!_randomTest) { |
| 825 | fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n"); |
| 826 | fflush (stdout); |
| 827 | } |
| 828 | { |
| 829 | WriteLockScoped wl(_apiTestRWLock); |
| 830 | *thereIsDecoder = false; |
| 831 | } |
| 832 | //myEvent->Wait(20); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 833 | CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 834 | Wait(1000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 835 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 836 | int currentPayload = myCodec->pltype; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 837 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 838 | if (!FixedPayloadTypeCodec(myCodec->plname)) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 839 | int32_t i; |
| 840 | for (i = 0; i < 32; i++) { |
| 841 | if (!_payloadUsed[i]) { |
| 842 | if (!_randomTest) { |
| 843 | fprintf(stdout, |
| 844 | "Register receive codec with new Payload, AUDIO BACK.\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 845 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 846 | //myCodec->pltype = i + 96; |
| 847 | //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
| 848 | //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 849 | //myEvent->Wait(20); |
| 850 | //{ |
| 851 | // WriteLockScoped wl(_apiTestRWLock); |
| 852 | // *thereIsDecoder = true; |
| 853 | //} |
| 854 | Wait(1000); |
| 855 | |
| 856 | if (!_randomTest) { |
| 857 | fprintf(stdout, "Unregistering reveive codec, NO AUDIO.\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 858 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 859 | //{ |
| 860 | // WriteLockScoped wl(_apiTestRWLock); |
| 861 | // *thereIsDecoder = false; |
| 862 | //} |
| 863 | //myEvent->Wait(20); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 864 | //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 865 | Wait(1000); |
| 866 | |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 867 | myCodec->pltype = currentPayload; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 868 | if (!_randomTest) { |
| 869 | fprintf(stdout, |
| 870 | "Register receive codec with default Payload, AUDIO BACK.\n"); |
| 871 | fflush (stdout); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 872 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 873 | CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
| 874 | //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 875 | myEvent->Wait(20); |
| 876 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 877 | WriteLockScoped wl(_apiTestRWLock); |
| 878 | *thereIsDecoder = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 879 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 880 | Wait(1000); |
| 881 | |
| 882 | break; |
| 883 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 884 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 885 | if (i == 32) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 886 | CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 887 | { |
| 888 | WriteLockScoped wl(_apiTestRWLock); |
| 889 | *thereIsDecoder = true; |
| 890 | } |
| 891 | } |
| 892 | } else { |
| 893 | if (!_randomTest) { |
| 894 | fprintf(stdout, |
| 895 | "Register receive codec with fixed Payload, AUDIO BACK.\n"); |
| 896 | fflush (stdout); |
| 897 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 898 | CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
| 899 | //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype)); |
| 900 | //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 901 | myEvent->Wait(20); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 902 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 903 | WriteLockScoped wl(_apiTestRWLock); |
| 904 | *thereIsDecoder = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 905 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 906 | } |
| 907 | delete myEvent; |
| 908 | if (!_randomTest) { |
| 909 | fprintf(stdout, |
| 910 | "---------------------------------------------------------\n"); |
| 911 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 912 | } |
| 913 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 914 | void APITest::TestSendVAD(char side) { |
| 915 | if (_randomTest) { |
| 916 | return; |
| 917 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 918 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 919 | bool* vad; |
| 920 | bool* dtx; |
| 921 | ACMVADMode* mode; |
| 922 | Channel* myChannel; |
| 923 | AudioCodingModule* myACM; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 924 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 925 | CodecInst myCodec; |
| 926 | if (!_randomTest) { |
| 927 | fprintf(stdout, "\n\n"); |
| 928 | fprintf(stdout, "-----------------------------------------------\n"); |
| 929 | fprintf(stdout, " Test VAD API\n"); |
| 930 | fprintf(stdout, "-----------------------------------------------\n"); |
| 931 | } |
andrew@webrtc.org | d7a71d0 | 2012-08-01 01:40:02 +0000 | [diff] [blame] | 932 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 933 | if (side == 'A') { |
| 934 | AudioCodingModule::Codec(_codecCntrA, &myCodec); |
| 935 | vad = &_sendVADA; |
| 936 | dtx = &_sendDTXA; |
| 937 | mode = &_sendVADModeA; |
| 938 | myChannel = _channel_A2B; |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 939 | myACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 940 | } else { |
| 941 | AudioCodingModule::Codec(_codecCntrB, &myCodec); |
| 942 | vad = &_sendVADB; |
| 943 | dtx = &_sendDTXB; |
| 944 | mode = &_sendVADModeB; |
| 945 | myChannel = _channel_B2A; |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 946 | myACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 947 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 948 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 949 | CheckVADStatus(side); |
| 950 | if (!_randomTest) { |
| 951 | fprintf(stdout, "\n\n"); |
| 952 | } |
| 953 | |
| 954 | switch (*mode) { |
| 955 | case VADNormal: |
| 956 | *vad = true; |
| 957 | *dtx = true; |
| 958 | *mode = VADAggr; |
| 959 | break; |
| 960 | case VADLowBitrate: |
| 961 | *vad = true; |
| 962 | *dtx = true; |
| 963 | *mode = VADVeryAggr; |
| 964 | break; |
| 965 | case VADAggr: |
| 966 | *vad = true; |
| 967 | *dtx = true; |
| 968 | *mode = VADLowBitrate; |
| 969 | break; |
| 970 | case VADVeryAggr: |
| 971 | *vad = false; |
| 972 | *dtx = false; |
| 973 | *mode = VADNormal; |
| 974 | break; |
| 975 | default: |
| 976 | *mode = VADNormal; |
| 977 | } |
| 978 | |
| 979 | *dtx = (myCodec.plfreq == 32000) ? false : *dtx; |
| 980 | |
| 981 | CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode)); |
| 982 | myChannel->ResetStats(); |
| 983 | |
| 984 | CheckVADStatus(side); |
| 985 | if (!_randomTest) { |
| 986 | fprintf(stdout, "\n"); |
| 987 | fprintf(stdout, "-----------------------------------------------\n"); |
| 988 | } |
| 989 | |
| 990 | // Fault Test |
| 991 | CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) - 1)); |
| 992 | CHECK_PROTECTED_MT(myACM->SetVAD(false, true, (ACMVADMode) 4)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 993 | |
| 994 | } |
| 995 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 996 | void APITest::CurrentCodec(char side) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 997 | auto myCodec = (side == 'A' ? _acmA : _acmB)->SendCodec(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 998 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 999 | if (!_randomTest) { |
| 1000 | fprintf(stdout, "\n\n"); |
| 1001 | fprintf(stdout, "Send codec in Side A\n"); |
| 1002 | fprintf(stdout, "----------------------------\n"); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 1003 | fprintf(stdout, "Name................. %s\n", myCodec->plname); |
| 1004 | fprintf(stdout, "Sampling Frequency... %d\n", myCodec->plfreq); |
| 1005 | fprintf(stdout, "Rate................. %d\n", myCodec->rate); |
| 1006 | fprintf(stdout, "Payload-type......... %d\n", myCodec->pltype); |
| 1007 | fprintf(stdout, "Packet-size.......... %d\n", myCodec->pacsize); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1008 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1009 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1010 | Wait(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1013 | void APITest::ChangeCodec(char side) { |
| 1014 | CodecInst myCodec; |
| 1015 | AudioCodingModule* myACM; |
| 1016 | uint8_t* codecCntr; |
| 1017 | bool* thereIsEncoder; |
| 1018 | bool* vad; |
| 1019 | bool* dtx; |
| 1020 | ACMVADMode* mode; |
| 1021 | Channel* myChannel; |
| 1022 | // Reset and Wait |
| 1023 | if (!_randomTest) { |
| 1024 | fprintf(stdout, "Reset Encoder Side A \n"); |
| 1025 | } |
| 1026 | if (side == 'A') { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 1027 | myACM = _acmA.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1028 | codecCntr = &_codecCntrA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1029 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1030 | WriteLockScoped wl(_apiTestRWLock); |
| 1031 | thereIsEncoder = &_thereIsEncoderA; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1032 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1033 | vad = &_sendVADA; |
| 1034 | dtx = &_sendDTXA; |
| 1035 | mode = &_sendVADModeA; |
| 1036 | myChannel = _channel_A2B; |
| 1037 | } else { |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 1038 | myACM = _acmB.get(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1039 | codecCntr = &_codecCntrB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1040 | { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1041 | WriteLockScoped wl(_apiTestRWLock); |
| 1042 | thereIsEncoder = &_thereIsEncoderB; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1043 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1044 | vad = &_sendVADB; |
| 1045 | dtx = &_sendDTXB; |
| 1046 | mode = &_sendVADModeB; |
| 1047 | myChannel = _channel_B2A; |
| 1048 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1049 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1050 | Wait(100); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1051 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1052 | // Register the next codec |
| 1053 | do { |
| 1054 | *codecCntr = |
| 1055 | (*codecCntr < AudioCodingModule::NumberOfCodecs() - 1) ? |
| 1056 | (*codecCntr + 1) : 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1057 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1058 | if (*codecCntr == 0) { |
| 1059 | //printf("Initialize Sender Side A \n"); |
| 1060 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1061 | WriteLockScoped wl(_apiTestRWLock); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1062 | *thereIsEncoder = false; |
| 1063 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1064 | // After Initialization CN is lost, re-register them |
| 1065 | if (AudioCodingModule::Codec("CN", &myCodec, 8000, 1) >= 0) { |
| 1066 | CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec)); |
| 1067 | } |
| 1068 | if (AudioCodingModule::Codec("CN", &myCodec, 16000, 1) >= 0) { |
| 1069 | CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec)); |
| 1070 | } |
| 1071 | // VAD & DTX are disabled after initialization |
| 1072 | *vad = false; |
| 1073 | *dtx = false; |
| 1074 | _writeToFile = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1075 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1076 | |
| 1077 | AudioCodingModule::Codec(*codecCntr, &myCodec); |
| 1078 | } while (!STR_CASE_CMP(myCodec.plname, "CN") |
| 1079 | || !STR_CASE_CMP(myCodec.plname, "telephone-event") |
| 1080 | || !STR_CASE_CMP(myCodec.plname, "RED")); |
| 1081 | |
| 1082 | if (!_randomTest) { |
| 1083 | fprintf(stdout,"\n=====================================================\n"); |
| 1084 | fprintf(stdout, " Registering New Codec %s, %d kHz, %d kbps\n", |
| 1085 | myCodec.plname, myCodec.plfreq / 1000, myCodec.rate / 1000); |
| 1086 | } |
| 1087 | //std::cout<< std::flush; |
| 1088 | |
| 1089 | // NO DTX for supe-wideband codec at this point |
| 1090 | if (myCodec.plfreq == 32000) { |
| 1091 | *dtx = false; |
| 1092 | CHECK_ERROR_MT(myACM->SetVAD(*dtx, *vad, *mode)); |
| 1093 | |
| 1094 | } |
| 1095 | |
| 1096 | CHECK_ERROR_MT(myACM->RegisterSendCodec(myCodec)); |
| 1097 | myChannel->ResetStats(); |
| 1098 | { |
| 1099 | WriteLockScoped wl(_apiTestRWLock); |
| 1100 | *thereIsEncoder = true; |
| 1101 | } |
| 1102 | Wait(500); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 1105 | } // namespace webrtc |