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