niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 91b359e | 2012-02-28 17:26:14 +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@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 11 | #include "TwoWayCommunication.h" |
| 12 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | #include <cctype> |
| 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | #ifdef WIN32 |
| 18 | #include <Windows.h> |
| 19 | #endif |
| 20 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | #include "common_types.h" |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 22 | #include "engine_configurations.h" |
| 23 | #include "gtest/gtest.h" |
| 24 | #include "PCMFile.h" |
| 25 | #include "trace.h" |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 26 | #include "testsupport/fileutils.h" |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 27 | #include "utility.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 29 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
| 31 | #define MAX_FILE_NAME_LENGTH_BYTE 500 |
| 32 | |
| 33 | TwoWayCommunication::TwoWayCommunication(int testMode) |
| 34 | { |
| 35 | _testMode = testMode; |
| 36 | } |
| 37 | |
| 38 | TwoWayCommunication::~TwoWayCommunication() |
| 39 | { |
| 40 | AudioCodingModule::Destroy(_acmA); |
| 41 | AudioCodingModule::Destroy(_acmB); |
| 42 | |
| 43 | AudioCodingModule::Destroy(_acmRefA); |
| 44 | AudioCodingModule::Destroy(_acmRefB); |
| 45 | |
| 46 | delete _channel_A2B; |
| 47 | delete _channel_B2A; |
| 48 | |
| 49 | delete _channelRef_A2B; |
| 50 | delete _channelRef_B2A; |
| 51 | #ifdef WEBRTC_DTMF_DETECTION |
| 52 | if(_dtmfDetectorA != NULL) |
| 53 | { |
| 54 | delete _dtmfDetectorA; |
| 55 | } |
| 56 | if(_dtmfDetectorB != NULL) |
| 57 | { |
| 58 | delete _dtmfDetectorB; |
| 59 | } |
| 60 | #endif |
| 61 | _inFileA.Close(); |
| 62 | _inFileB.Close(); |
| 63 | _outFileA.Close(); |
| 64 | _outFileB.Close(); |
| 65 | _outFileRefA.Close(); |
| 66 | _outFileRefB.Close(); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | WebRtc_UWord8 |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 71 | TwoWayCommunication::ChooseCodec(WebRtc_UWord8* codecID_A, |
| 72 | WebRtc_UWord8* codecID_B) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | { |
| 74 | AudioCodingModule* tmpACM = AudioCodingModule::Create(0); |
| 75 | WebRtc_UWord8 noCodec = tmpACM->NumberOfCodecs(); |
| 76 | CodecInst codecInst; |
| 77 | printf("List of Supported Codecs\n"); |
| 78 | printf("========================\n"); |
| 79 | for(WebRtc_UWord8 codecCntr = 0; codecCntr < noCodec; codecCntr++) |
| 80 | { |
| 81 | tmpACM->Codec(codecCntr, codecInst); |
| 82 | printf("%d- %s\n", codecCntr, codecInst.plname); |
| 83 | } |
| 84 | printf("\nChoose a send codec for side A [0]: "); |
| 85 | char myStr[15] = ""; |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 86 | EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | *codecID_A = (WebRtc_UWord8)atoi(myStr); |
| 88 | |
| 89 | printf("\nChoose a send codec for side B [0]: "); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 90 | EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | *codecID_B = (WebRtc_UWord8)atoi(myStr); |
| 92 | |
| 93 | AudioCodingModule::Destroy(tmpACM); |
| 94 | printf("\n"); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | WebRtc_Word16 |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 99 | TwoWayCommunication::ChooseFile(char* fileName, WebRtc_Word16 maxLen, |
| 100 | WebRtc_UWord16* frequencyHz) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | { |
leozwang@webrtc.org | 91b359e | 2012-02-28 17:26:14 +0000 | [diff] [blame^] | 102 | char tmpName[MAX_FILE_NAME_LENGTH_BYTE]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | //strcpy(_fileName, "in.pcm"); |
| 104 | //printf("\n\nPlease enter the input file: "); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 105 | EXPECT_TRUE(fgets(tmpName, MAX_FILE_NAME_LENGTH_BYTE, stdin) != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | tmpName[MAX_FILE_NAME_LENGTH_BYTE-1] = '\0'; |
| 107 | WebRtc_Word16 n = 0; |
| 108 | |
| 109 | // removing leading spaces |
| 110 | while((isspace(tmpName[n]) || iscntrl(tmpName[n])) && |
| 111 | (tmpName[n] != 0) && |
| 112 | (n < MAX_FILE_NAME_LENGTH_BYTE)) |
| 113 | { |
| 114 | n++; |
| 115 | } |
| 116 | if(n > 0) |
| 117 | { |
| 118 | memmove(tmpName, &tmpName[n], MAX_FILE_NAME_LENGTH_BYTE - n); |
| 119 | } |
| 120 | |
| 121 | //removing trailing spaces |
| 122 | n = (WebRtc_Word16)(strlen(tmpName) - 1); |
| 123 | if(n >= 0) |
| 124 | { |
| 125 | while((isspace(tmpName[n]) || iscntrl(tmpName[n])) && |
| 126 | (n >= 0)) |
| 127 | { |
| 128 | n--; |
| 129 | } |
| 130 | } |
| 131 | if(n >= 0) |
| 132 | { |
| 133 | tmpName[n + 1] = '\0'; |
| 134 | } |
| 135 | |
| 136 | WebRtc_Word16 len = (WebRtc_Word16)strlen(tmpName); |
| 137 | if(len > maxLen) |
| 138 | { |
| 139 | return -1; |
| 140 | } |
| 141 | if(len > 0) |
| 142 | { |
| 143 | strncpy(fileName, tmpName, len+1); |
| 144 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 145 | printf("Enter the sampling frequency (in Hz) of the above file [%u]: ", |
| 146 | *frequencyHz); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 147 | EXPECT_TRUE(fgets(tmpName, 6, stdin) != NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | WebRtc_UWord16 tmpFreq = (WebRtc_UWord16)atoi(tmpName); |
| 149 | if(tmpFreq > 0) |
| 150 | { |
| 151 | *frequencyHz = tmpFreq; |
| 152 | } |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | WebRtc_Word16 TwoWayCommunication::SetUp() |
| 157 | { |
| 158 | _acmA = AudioCodingModule::Create(1); |
| 159 | _acmB = AudioCodingModule::Create(2); |
| 160 | |
| 161 | _acmRefA = AudioCodingModule::Create(3); |
| 162 | _acmRefB = AudioCodingModule::Create(4); |
| 163 | |
| 164 | WebRtc_UWord8 codecID_A; |
| 165 | WebRtc_UWord8 codecID_B; |
| 166 | |
| 167 | ChooseCodec(&codecID_A, &codecID_B); |
| 168 | CodecInst codecInst_A; |
| 169 | CodecInst codecInst_B; |
| 170 | CodecInst dummyCodec; |
| 171 | _acmA->Codec(codecID_A, codecInst_A); |
| 172 | _acmB->Codec(codecID_B, codecInst_B); |
| 173 | |
| 174 | _acmA->Codec(6, dummyCodec); |
| 175 | |
| 176 | //--- Set A codecs |
| 177 | CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A)); |
| 178 | CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B)); |
| 179 | #ifdef WEBRTC_DTMF_DETECTION |
| 180 | _dtmfDetectorA = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 181 | CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA, |
| 182 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 183 | #endif |
| 184 | //--- Set ref-A codecs |
| 185 | CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A)); |
| 186 | CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B)); |
| 187 | |
| 188 | //--- Set B codecs |
| 189 | CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B)); |
| 190 | CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A)); |
| 191 | #ifdef WEBRTC_DTMF_DETECTION |
| 192 | _dtmfDetectorB = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 193 | CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB, |
| 194 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
| 197 | //--- Set ref-B codecs |
| 198 | CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B)); |
| 199 | CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A)); |
| 200 | |
| 201 | char fileName[500]; |
| 202 | char refFileName[500]; |
| 203 | WebRtc_UWord16 frequencyHz; |
| 204 | |
| 205 | //--- Input A |
tlegrand@google.com | 3675f9b | 2011-07-08 06:43:34 +0000 | [diff] [blame] | 206 | strcpy(fileName, "./test/data/audio_coding/testfile32kHz.pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | frequencyHz = 32000; |
| 208 | printf("Enter input file at side A [%s]: ", fileName); |
| 209 | ChooseFile(fileName, 499, &frequencyHz); |
| 210 | |
| 211 | |
| 212 | _inFileA.Open(fileName, frequencyHz, "rb"); |
| 213 | |
| 214 | //--- Output A |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 215 | std::string outputFileA = webrtc::test::OutputPath() + "outA.pcm"; |
| 216 | strcpy(fileName, outputFileA.c_str()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | frequencyHz = 16000; |
| 218 | printf("Enter output file at side A [%s]: ", fileName); |
| 219 | ChooseFile(fileName, 499, &frequencyHz); |
| 220 | _outFileA.Open(fileName, frequencyHz, "wb"); |
| 221 | strcpy(refFileName, "ref_"); |
| 222 | strcat(refFileName, fileName); |
| 223 | _outFileRefA.Open(refFileName, frequencyHz, "wb"); |
| 224 | |
| 225 | //--- Input B |
tlegrand@google.com | 3675f9b | 2011-07-08 06:43:34 +0000 | [diff] [blame] | 226 | strcpy(fileName, "./test/data/audio_coding/testfile32kHz.pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 227 | frequencyHz = 32000; |
| 228 | printf("\n\nEnter input file at side B [%s]: ", fileName); |
| 229 | ChooseFile(fileName, 499, &frequencyHz); |
| 230 | _inFileB.Open(fileName, frequencyHz, "rb"); |
| 231 | |
| 232 | //--- Output B |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 233 | std::string outputFileB = webrtc::test::OutputPath() + "outB.pcm"; |
| 234 | strcpy(fileName, outputFileB.c_str()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 235 | frequencyHz = 16000; |
| 236 | printf("Enter output file at side B [%s]: ", fileName); |
| 237 | ChooseFile(fileName, 499, &frequencyHz); |
| 238 | _outFileB.Open(fileName, frequencyHz, "wb"); |
| 239 | strcpy(refFileName, "ref_"); |
| 240 | strcat(refFileName, fileName); |
| 241 | _outFileRefB.Open(refFileName, frequencyHz, "wb"); |
| 242 | |
| 243 | //--- Set A-to-B channel |
| 244 | _channel_A2B = new Channel; |
| 245 | _acmA->RegisterTransportCallback(_channel_A2B); |
| 246 | _channel_A2B->RegisterReceiverACM(_acmB); |
| 247 | //--- Do the same for the reference |
| 248 | _channelRef_A2B = new Channel; |
| 249 | _acmRefA->RegisterTransportCallback(_channelRef_A2B); |
| 250 | _channelRef_A2B->RegisterReceiverACM(_acmRefB); |
| 251 | |
| 252 | //--- Set B-to-A channel |
| 253 | _channel_B2A = new Channel; |
| 254 | _acmB->RegisterTransportCallback(_channel_B2A); |
| 255 | _channel_B2A->RegisterReceiverACM(_acmA); |
| 256 | //--- Do the same for reference |
| 257 | _channelRef_B2A = new Channel; |
| 258 | _acmRefB->RegisterTransportCallback(_channelRef_B2A); |
| 259 | _channelRef_B2A->RegisterReceiverACM(_acmRefA); |
| 260 | |
| 261 | // The clicks will be more obvious when we |
| 262 | // are in FAX mode. |
| 263 | _acmB->SetPlayoutMode(fax); |
| 264 | _acmRefB->SetPlayoutMode(fax); |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | WebRtc_Word16 TwoWayCommunication::SetUpAutotest() |
| 270 | { |
| 271 | _acmA = AudioCodingModule::Create(1); |
| 272 | _acmB = AudioCodingModule::Create(2); |
| 273 | |
| 274 | _acmRefA = AudioCodingModule::Create(3); |
| 275 | _acmRefB = AudioCodingModule::Create(4); |
| 276 | |
| 277 | CodecInst codecInst_A; |
| 278 | CodecInst codecInst_B; |
| 279 | CodecInst dummyCodec; |
| 280 | |
| 281 | _acmA->Codec("ISAC", codecInst_A, 16000); |
| 282 | _acmB->Codec("L16", codecInst_B, 8000); |
| 283 | _acmA->Codec(6, dummyCodec); |
| 284 | |
| 285 | //--- Set A codecs |
| 286 | CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A)); |
| 287 | CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B)); |
| 288 | #ifdef WEBRTC_DTMF_DETECTION |
| 289 | _dtmfDetectorA = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 290 | CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA, |
| 291 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 292 | #endif |
| 293 | |
| 294 | //--- Set ref-A codecs |
| 295 | CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A)); |
| 296 | CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B)); |
| 297 | |
| 298 | //--- Set B codecs |
| 299 | CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B)); |
| 300 | CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A)); |
| 301 | #ifdef WEBRTC_DTMF_DETECTION |
| 302 | _dtmfDetectorB = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 303 | CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB, |
| 304 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 305 | #endif |
| 306 | |
| 307 | //--- Set ref-B codecs |
| 308 | CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B)); |
| 309 | CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A)); |
| 310 | |
| 311 | char fileName[500]; |
| 312 | char refFileName[500]; |
| 313 | WebRtc_UWord16 frequencyHz; |
| 314 | |
| 315 | |
| 316 | //--- Input A |
tlegrand@google.com | 3675f9b | 2011-07-08 06:43:34 +0000 | [diff] [blame] | 317 | strcpy(fileName, "./test/data/audio_coding/testfile32kHz.pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 318 | frequencyHz = 16000; |
| 319 | _inFileA.Open(fileName, frequencyHz, "rb"); |
| 320 | |
| 321 | //--- Output A |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 322 | std::string outputFileA = webrtc::test::OutputPath() + "outAutotestA.pcm"; |
| 323 | strcpy(fileName, outputFileA.c_str()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 324 | frequencyHz = 16000; |
| 325 | _outFileA.Open(fileName, frequencyHz, "wb"); |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 326 | std::string outputRefFileA = webrtc::test::OutputPath() + "ref_outAutotestA.pcm"; |
| 327 | strcpy(refFileName, outputRefFileA.c_str()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 328 | _outFileRefA.Open(refFileName, frequencyHz, "wb"); |
| 329 | |
| 330 | //--- Input B |
tlegrand@google.com | 3675f9b | 2011-07-08 06:43:34 +0000 | [diff] [blame] | 331 | strcpy(fileName, "./test/data/audio_coding/testfile32kHz.pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 332 | frequencyHz = 16000; |
| 333 | _inFileB.Open(fileName, frequencyHz, "rb"); |
| 334 | |
| 335 | //--- Output B |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 336 | std::string outputFileB = webrtc::test::OutputPath() + "outAutotestB.pcm"; |
| 337 | strcpy(fileName, outputFileB.c_str()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 338 | frequencyHz = 16000; |
| 339 | _outFileB.Open(fileName, frequencyHz, "wb"); |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 340 | std::string outputRefFileB = webrtc::test::OutputPath() + "ref_outAutotestB.pcm"; |
| 341 | strcpy(refFileName, outputRefFileB.c_str()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 342 | _outFileRefB.Open(refFileName, frequencyHz, "wb"); |
| 343 | |
| 344 | //--- Set A-to-B channel |
| 345 | _channel_A2B = new Channel; |
| 346 | _acmA->RegisterTransportCallback(_channel_A2B); |
| 347 | _channel_A2B->RegisterReceiverACM(_acmB); |
| 348 | //--- Do the same for the reference |
| 349 | _channelRef_A2B = new Channel; |
| 350 | _acmRefA->RegisterTransportCallback(_channelRef_A2B); |
| 351 | _channelRef_A2B->RegisterReceiverACM(_acmRefB); |
| 352 | |
| 353 | //--- Set B-to-A channel |
| 354 | _channel_B2A = new Channel; |
| 355 | _acmB->RegisterTransportCallback(_channel_B2A); |
| 356 | _channel_B2A->RegisterReceiverACM(_acmA); |
| 357 | //--- Do the same for reference |
| 358 | _channelRef_B2A = new Channel; |
| 359 | _acmRefB->RegisterTransportCallback(_channelRef_B2A); |
| 360 | _channelRef_B2A->RegisterReceiverACM(_acmRefA); |
| 361 | |
| 362 | // The clicks will be more obvious when we |
| 363 | // are in FAX mode. |
| 364 | _acmB->SetPlayoutMode(fax); |
| 365 | _acmRefB->SetPlayoutMode(fax); |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | void |
| 371 | TwoWayCommunication::Perform() |
| 372 | { |
| 373 | if(_testMode == 0) |
| 374 | { |
| 375 | printf("Running TwoWayCommunication Test"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 376 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
| 377 | "---------- TwoWayCommunication ----------"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 378 | SetUpAutotest(); |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | SetUp(); |
| 383 | } |
| 384 | unsigned int msecPassed = 0; |
| 385 | unsigned int secPassed = 0; |
| 386 | |
| 387 | WebRtc_Word32 outFreqHzA = _outFileA.SamplingFrequency(); |
| 388 | WebRtc_Word32 outFreqHzB = _outFileB.SamplingFrequency(); |
| 389 | |
| 390 | AudioFrame audioFrame; |
| 391 | |
| 392 | CodecInst codecInst_B; |
| 393 | CodecInst dummy; |
| 394 | |
| 395 | _acmB->SendCodec(codecInst_B); |
| 396 | |
| 397 | if(_testMode != 0) |
| 398 | { |
| 399 | printf("\n"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 400 | printf("sec:msec A B\n"); |
| 401 | printf("-------- ----- -----\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | while(!_inFileA.EndOfFile() && !_inFileB.EndOfFile()) |
| 405 | { |
| 406 | _inFileA.Read10MsData(audioFrame); |
| 407 | _acmA->Add10MsData(audioFrame); |
| 408 | _acmRefA->Add10MsData(audioFrame); |
| 409 | |
| 410 | _inFileB.Read10MsData(audioFrame); |
| 411 | _acmB->Add10MsData(audioFrame); |
| 412 | _acmRefB->Add10MsData(audioFrame); |
| 413 | |
| 414 | |
| 415 | _acmA->Process(); |
| 416 | _acmB->Process(); |
| 417 | _acmRefA->Process(); |
| 418 | _acmRefB->Process(); |
| 419 | |
| 420 | _acmA->PlayoutData10Ms(outFreqHzA, audioFrame); |
| 421 | _outFileA.Write10MsData(audioFrame); |
| 422 | |
| 423 | _acmRefA->PlayoutData10Ms(outFreqHzA, audioFrame); |
| 424 | _outFileRefA.Write10MsData(audioFrame); |
| 425 | |
| 426 | _acmB->PlayoutData10Ms(outFreqHzB, audioFrame); |
| 427 | _outFileB.Write10MsData(audioFrame); |
| 428 | |
| 429 | _acmRefB->PlayoutData10Ms(outFreqHzB, audioFrame); |
| 430 | _outFileRefB.Write10MsData(audioFrame); |
| 431 | |
| 432 | msecPassed += 10; |
| 433 | if(msecPassed >= 1000) |
| 434 | { |
| 435 | msecPassed = 0; |
| 436 | secPassed++; |
| 437 | } |
| 438 | if(((secPassed%5) == 4) && (msecPassed == 0)) |
| 439 | { |
| 440 | if(_testMode != 0) |
| 441 | { |
| 442 | printf("%3u:%3u ", secPassed, msecPassed); |
| 443 | } |
| 444 | _acmA->ResetEncoder(); |
| 445 | if(_testMode == 0) |
| 446 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 447 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
| 448 | "---------- Errors epected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 449 | printf("."); |
| 450 | } |
| 451 | else |
| 452 | { |
| 453 | printf("Reset Encoder (click in side B) "); |
| 454 | printf("Initialize Sender (no audio in side A)\n"); |
| 455 | } |
| 456 | CHECK_ERROR(_acmB->InitializeSender()); |
| 457 | } |
| 458 | if(((secPassed%5) == 4) && (msecPassed >= 990)) |
| 459 | { |
| 460 | if(_testMode == 0) |
| 461 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 462 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
| 463 | "----- END: Errors epected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 464 | printf("."); |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | printf("%3u:%3u ", secPassed, msecPassed); |
| 469 | printf(" "); |
| 470 | printf("Register Send Codec (audio back in side A)\n"); |
| 471 | } |
| 472 | CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B)); |
| 473 | CHECK_ERROR(_acmB->SendCodec(dummy)); |
| 474 | } |
| 475 | if(((secPassed%7) == 6) && (msecPassed == 0)) |
| 476 | { |
| 477 | CHECK_ERROR(_acmB->ResetDecoder()); |
| 478 | if(_testMode == 0) |
| 479 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 480 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
| 481 | "---------- Errors epected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 482 | printf("."); |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | printf("%3u:%3u ", secPassed, msecPassed); |
| 487 | printf("Initialize Receiver (no audio in side A) "); |
| 488 | printf("Reset Decoder\n"); |
| 489 | } |
| 490 | CHECK_ERROR(_acmA->InitializeReceiver()); |
| 491 | } |
| 492 | if(((secPassed%7) == 6) && (msecPassed >= 990)) |
| 493 | { |
| 494 | if(_testMode == 0) |
| 495 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 496 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
| 497 | "----- END: Errors epected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 498 | printf("."); |
| 499 | } |
| 500 | else |
| 501 | { |
| 502 | printf("%3u:%3u ", secPassed, msecPassed); |
| 503 | printf("Register Receive Coded (audio back in side A)\n"); |
| 504 | } |
| 505 | CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B)); |
| 506 | } |
| 507 | //Sleep(9); |
| 508 | } |
| 509 | if(_testMode == 0) |
| 510 | { |
| 511 | printf("Done!\n"); |
| 512 | } |
| 513 | |
| 514 | #ifdef WEBRTC_DTMF_DETECTION |
| 515 | printf("\nDTMF at Side A\n"); |
| 516 | _dtmfDetectorA->PrintDetectedDigits(); |
| 517 | |
| 518 | printf("\nDTMF at Side B\n"); |
| 519 | _dtmfDetectorB->PrintDetectedDigits(); |
| 520 | #endif |
| 521 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 522 | } |
| 523 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 524 | } // namespace webrtc |