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 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 70 | uint8_t |
| 71 | TwoWayCommunication::ChooseCodec(uint8_t* codecID_A, |
| 72 | uint8_t* codecID_B) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | { |
| 74 | AudioCodingModule* tmpACM = AudioCodingModule::Create(0); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 75 | uint8_t noCodec = tmpACM->NumberOfCodecs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | CodecInst codecInst; |
| 77 | printf("List of Supported Codecs\n"); |
| 78 | printf("========================\n"); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 79 | for(uint8_t codecCntr = 0; codecCntr < noCodec; codecCntr++) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | { |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 81 | tmpACM->Codec(codecCntr, &codecInst); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 87 | *codecID_A = (uint8_t)atoi(myStr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 91 | *codecID_B = (uint8_t)atoi(myStr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | |
| 93 | AudioCodingModule::Destroy(tmpACM); |
| 94 | printf("\n"); |
| 95 | return 0; |
| 96 | } |
| 97 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 98 | int16_t TwoWayCommunication::SetUp() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | { |
| 100 | _acmA = AudioCodingModule::Create(1); |
| 101 | _acmB = AudioCodingModule::Create(2); |
| 102 | |
| 103 | _acmRefA = AudioCodingModule::Create(3); |
| 104 | _acmRefB = AudioCodingModule::Create(4); |
| 105 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 106 | uint8_t codecID_A; |
| 107 | uint8_t codecID_B; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
| 109 | ChooseCodec(&codecID_A, &codecID_B); |
| 110 | CodecInst codecInst_A; |
| 111 | CodecInst codecInst_B; |
| 112 | CodecInst dummyCodec; |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 113 | _acmA->Codec(codecID_A, &codecInst_A); |
| 114 | _acmB->Codec(codecID_B, &codecInst_B); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 116 | _acmA->Codec(6, &dummyCodec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
| 118 | //--- Set A codecs |
| 119 | CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A)); |
| 120 | CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B)); |
| 121 | #ifdef WEBRTC_DTMF_DETECTION |
| 122 | _dtmfDetectorA = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 123 | CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA, |
| 124 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | #endif |
| 126 | //--- Set ref-A codecs |
| 127 | CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A)); |
| 128 | CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B)); |
| 129 | |
| 130 | //--- Set B codecs |
| 131 | CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B)); |
| 132 | CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A)); |
| 133 | #ifdef WEBRTC_DTMF_DETECTION |
| 134 | _dtmfDetectorB = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 135 | CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB, |
| 136 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | //--- Set ref-B codecs |
| 140 | CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B)); |
| 141 | CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A)); |
| 142 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 143 | uint16_t frequencyHz; |
| 144 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | //--- Input A |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 146 | std::string in_file_name = |
| 147 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | frequencyHz = 32000; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 149 | printf("Enter input file at side A [%s]: ", in_file_name.c_str()); |
| 150 | PCMFile::ChooseFile(&in_file_name, 499, &frequencyHz); |
| 151 | _inFileA.Open(in_file_name, frequencyHz, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | |
| 153 | //--- Output A |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 154 | std::string out_file_a = webrtc::test::OutputPath() + "outA.pcm"; |
| 155 | printf("Output file at side A: %s\n", out_file_a.c_str()); |
| 156 | printf("Sampling frequency (in Hz) of the above file: %u\n", |
| 157 | frequencyHz); |
| 158 | _outFileA.Open(out_file_a, frequencyHz, "wb"); |
| 159 | std::string ref_file_name = webrtc::test::OutputPath() + "ref_outA.pcm"; |
| 160 | _outFileRefA.Open(ref_file_name, frequencyHz, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | |
| 162 | //--- Input B |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 163 | in_file_name = |
| 164 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | frequencyHz = 32000; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 166 | printf("\n\nEnter input file at side B [%s]: ", in_file_name.c_str()); |
| 167 | PCMFile::ChooseFile(&in_file_name, 499, &frequencyHz); |
| 168 | _inFileB.Open(in_file_name, frequencyHz, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
| 170 | //--- Output B |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 171 | std::string out_file_b = webrtc::test::OutputPath() + "outB.pcm"; |
| 172 | printf("Output file at side B: %s\n", out_file_b.c_str()); |
| 173 | printf("Sampling frequency (in Hz) of the above file: %u\n", |
| 174 | frequencyHz); |
| 175 | _outFileB.Open(out_file_b, frequencyHz, "wb"); |
| 176 | ref_file_name = webrtc::test::OutputPath() + "ref_outB.pcm"; |
| 177 | _outFileRefB.Open(ref_file_name, frequencyHz, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 178 | |
| 179 | //--- Set A-to-B channel |
| 180 | _channel_A2B = new Channel; |
| 181 | _acmA->RegisterTransportCallback(_channel_A2B); |
| 182 | _channel_A2B->RegisterReceiverACM(_acmB); |
| 183 | //--- Do the same for the reference |
| 184 | _channelRef_A2B = new Channel; |
| 185 | _acmRefA->RegisterTransportCallback(_channelRef_A2B); |
| 186 | _channelRef_A2B->RegisterReceiverACM(_acmRefB); |
| 187 | |
| 188 | //--- Set B-to-A channel |
| 189 | _channel_B2A = new Channel; |
| 190 | _acmB->RegisterTransportCallback(_channel_B2A); |
| 191 | _channel_B2A->RegisterReceiverACM(_acmA); |
| 192 | //--- Do the same for reference |
| 193 | _channelRef_B2A = new Channel; |
| 194 | _acmRefB->RegisterTransportCallback(_channelRef_B2A); |
| 195 | _channelRef_B2A->RegisterReceiverACM(_acmRefA); |
| 196 | |
| 197 | // The clicks will be more obvious when we |
| 198 | // are in FAX mode. |
| 199 | _acmB->SetPlayoutMode(fax); |
| 200 | _acmRefB->SetPlayoutMode(fax); |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 205 | int16_t TwoWayCommunication::SetUpAutotest() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 206 | { |
| 207 | _acmA = AudioCodingModule::Create(1); |
| 208 | _acmB = AudioCodingModule::Create(2); |
| 209 | |
| 210 | _acmRefA = AudioCodingModule::Create(3); |
| 211 | _acmRefB = AudioCodingModule::Create(4); |
| 212 | |
| 213 | CodecInst codecInst_A; |
| 214 | CodecInst codecInst_B; |
| 215 | CodecInst dummyCodec; |
| 216 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 217 | _acmA->Codec("ISAC", &codecInst_A, 16000, 1); |
| 218 | _acmB->Codec("L16", &codecInst_B, 8000, 1); |
| 219 | _acmA->Codec(6, &dummyCodec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 220 | |
| 221 | //--- Set A codecs |
| 222 | CHECK_ERROR(_acmA->RegisterSendCodec(codecInst_A)); |
| 223 | CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B)); |
| 224 | #ifdef WEBRTC_DTMF_DETECTION |
| 225 | _dtmfDetectorA = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 226 | CHECK_ERROR(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA, |
| 227 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 228 | #endif |
| 229 | |
| 230 | //--- Set ref-A codecs |
| 231 | CHECK_ERROR(_acmRefA->RegisterSendCodec(codecInst_A)); |
| 232 | CHECK_ERROR(_acmRefA->RegisterReceiveCodec(codecInst_B)); |
| 233 | |
| 234 | //--- Set B codecs |
| 235 | CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B)); |
| 236 | CHECK_ERROR(_acmB->RegisterReceiveCodec(codecInst_A)); |
| 237 | #ifdef WEBRTC_DTMF_DETECTION |
| 238 | _dtmfDetectorB = new(DTMFDetector); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 239 | CHECK_ERROR(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB, |
| 240 | ACMUSA)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 241 | #endif |
| 242 | |
| 243 | //--- Set ref-B codecs |
| 244 | CHECK_ERROR(_acmRefB->RegisterSendCodec(codecInst_B)); |
| 245 | CHECK_ERROR(_acmRefB->RegisterReceiveCodec(codecInst_A)); |
| 246 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 247 | uint16_t frequencyHz; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 248 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 249 | //--- Input A and B |
| 250 | std::string in_file_name = |
| 251 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 252 | frequencyHz = 16000; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 253 | _inFileA.Open(in_file_name, frequencyHz, "rb"); |
| 254 | _inFileB.Open(in_file_name, frequencyHz, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 255 | |
| 256 | //--- Output A |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 257 | std::string output_file_a = webrtc::test::OutputPath() + "outAutotestA.pcm"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | frequencyHz = 16000; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 259 | _outFileA.Open(output_file_a, frequencyHz, "wb"); |
| 260 | std::string output_ref_file_a = webrtc::test::OutputPath() + |
| 261 | "ref_outAutotestA.pcm"; |
| 262 | _outFileRefA.Open(output_ref_file_a, frequencyHz, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 263 | |
| 264 | //--- Output B |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 265 | std::string output_file_b = webrtc::test::OutputPath() + "outAutotestB.pcm"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 266 | frequencyHz = 16000; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 267 | _outFileB.Open(output_file_b, frequencyHz, "wb"); |
| 268 | std::string output_ref_file_b = webrtc::test::OutputPath() + |
| 269 | "ref_outAutotestB.pcm"; |
| 270 | _outFileRefB.Open(output_ref_file_b, frequencyHz, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 271 | |
| 272 | //--- Set A-to-B channel |
| 273 | _channel_A2B = new Channel; |
| 274 | _acmA->RegisterTransportCallback(_channel_A2B); |
| 275 | _channel_A2B->RegisterReceiverACM(_acmB); |
| 276 | //--- Do the same for the reference |
| 277 | _channelRef_A2B = new Channel; |
| 278 | _acmRefA->RegisterTransportCallback(_channelRef_A2B); |
| 279 | _channelRef_A2B->RegisterReceiverACM(_acmRefB); |
| 280 | |
| 281 | //--- Set B-to-A channel |
| 282 | _channel_B2A = new Channel; |
| 283 | _acmB->RegisterTransportCallback(_channel_B2A); |
| 284 | _channel_B2A->RegisterReceiverACM(_acmA); |
| 285 | //--- Do the same for reference |
| 286 | _channelRef_B2A = new Channel; |
| 287 | _acmRefB->RegisterTransportCallback(_channelRef_B2A); |
| 288 | _channelRef_B2A->RegisterReceiverACM(_acmRefA); |
| 289 | |
| 290 | // The clicks will be more obvious when we |
| 291 | // are in FAX mode. |
| 292 | _acmB->SetPlayoutMode(fax); |
| 293 | _acmRefB->SetPlayoutMode(fax); |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | void |
| 299 | TwoWayCommunication::Perform() |
| 300 | { |
| 301 | if(_testMode == 0) |
| 302 | { |
| 303 | printf("Running TwoWayCommunication Test"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 304 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
| 305 | "---------- TwoWayCommunication ----------"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 306 | SetUpAutotest(); |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | SetUp(); |
| 311 | } |
| 312 | unsigned int msecPassed = 0; |
| 313 | unsigned int secPassed = 0; |
| 314 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 315 | int32_t outFreqHzA = _outFileA.SamplingFrequency(); |
| 316 | int32_t outFreqHzB = _outFileB.SamplingFrequency(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 317 | |
| 318 | AudioFrame audioFrame; |
| 319 | |
| 320 | CodecInst codecInst_B; |
| 321 | CodecInst dummy; |
| 322 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 323 | _acmB->SendCodec(&codecInst_B); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 324 | |
| 325 | if(_testMode != 0) |
| 326 | { |
| 327 | printf("\n"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 328 | printf("sec:msec A B\n"); |
| 329 | printf("-------- ----- -----\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | while(!_inFileA.EndOfFile() && !_inFileB.EndOfFile()) |
| 333 | { |
| 334 | _inFileA.Read10MsData(audioFrame); |
| 335 | _acmA->Add10MsData(audioFrame); |
| 336 | _acmRefA->Add10MsData(audioFrame); |
| 337 | |
| 338 | _inFileB.Read10MsData(audioFrame); |
| 339 | _acmB->Add10MsData(audioFrame); |
| 340 | _acmRefB->Add10MsData(audioFrame); |
| 341 | |
| 342 | |
| 343 | _acmA->Process(); |
| 344 | _acmB->Process(); |
| 345 | _acmRefA->Process(); |
| 346 | _acmRefB->Process(); |
| 347 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 348 | _acmA->PlayoutData10Ms(outFreqHzA, &audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 349 | _outFileA.Write10MsData(audioFrame); |
| 350 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 351 | _acmRefA->PlayoutData10Ms(outFreqHzA, &audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 352 | _outFileRefA.Write10MsData(audioFrame); |
| 353 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 354 | _acmB->PlayoutData10Ms(outFreqHzB, &audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 355 | _outFileB.Write10MsData(audioFrame); |
| 356 | |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 357 | _acmRefB->PlayoutData10Ms(outFreqHzB, &audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 358 | _outFileRefB.Write10MsData(audioFrame); |
| 359 | |
| 360 | msecPassed += 10; |
| 361 | if(msecPassed >= 1000) |
| 362 | { |
| 363 | msecPassed = 0; |
| 364 | secPassed++; |
| 365 | } |
| 366 | if(((secPassed%5) == 4) && (msecPassed == 0)) |
| 367 | { |
| 368 | if(_testMode != 0) |
| 369 | { |
| 370 | printf("%3u:%3u ", secPassed, msecPassed); |
| 371 | } |
| 372 | _acmA->ResetEncoder(); |
| 373 | if(_testMode == 0) |
| 374 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 375 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 376 | "---------- Errors expected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 377 | printf("."); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | printf("Reset Encoder (click in side B) "); |
| 382 | printf("Initialize Sender (no audio in side A)\n"); |
| 383 | } |
| 384 | CHECK_ERROR(_acmB->InitializeSender()); |
| 385 | } |
| 386 | if(((secPassed%5) == 4) && (msecPassed >= 990)) |
| 387 | { |
| 388 | if(_testMode == 0) |
| 389 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 390 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 391 | "----- END: Errors expected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 392 | printf("."); |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | printf("%3u:%3u ", secPassed, msecPassed); |
| 397 | printf(" "); |
| 398 | printf("Register Send Codec (audio back in side A)\n"); |
| 399 | } |
| 400 | CHECK_ERROR(_acmB->RegisterSendCodec(codecInst_B)); |
tina.legrand@webrtc.org | 7a7a008 | 2013-02-21 10:27:48 +0000 | [diff] [blame] | 401 | CHECK_ERROR(_acmB->SendCodec(&dummy)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 402 | } |
| 403 | if(((secPassed%7) == 6) && (msecPassed == 0)) |
| 404 | { |
| 405 | CHECK_ERROR(_acmB->ResetDecoder()); |
| 406 | if(_testMode == 0) |
| 407 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 408 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 409 | "---------- Errors expected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 410 | printf("."); |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | printf("%3u:%3u ", secPassed, msecPassed); |
| 415 | printf("Initialize Receiver (no audio in side A) "); |
| 416 | printf("Reset Decoder\n"); |
| 417 | } |
| 418 | CHECK_ERROR(_acmA->InitializeReceiver()); |
| 419 | } |
| 420 | if(((secPassed%7) == 6) && (msecPassed >= 990)) |
| 421 | { |
| 422 | if(_testMode == 0) |
| 423 | { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 424 | WEBRTC_TRACE(kTraceStateInfo, kTraceAudioCoding, -1, |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 425 | "----- END: Errors expected"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 426 | printf("."); |
| 427 | } |
| 428 | else |
| 429 | { |
| 430 | printf("%3u:%3u ", secPassed, msecPassed); |
| 431 | printf("Register Receive Coded (audio back in side A)\n"); |
| 432 | } |
| 433 | CHECK_ERROR(_acmA->RegisterReceiveCodec(codecInst_B)); |
| 434 | } |
| 435 | //Sleep(9); |
| 436 | } |
| 437 | if(_testMode == 0) |
| 438 | { |
| 439 | printf("Done!\n"); |
| 440 | } |
| 441 | |
| 442 | #ifdef WEBRTC_DTMF_DETECTION |
| 443 | printf("\nDTMF at Side A\n"); |
| 444 | _dtmfDetectorA->PrintDetectedDigits(); |
| 445 | |
| 446 | printf("\nDTMF at Side B\n"); |
| 447 | _dtmfDetectorB->PrintDetectedDigits(); |
| 448 | #endif |
| 449 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 450 | } |
| 451 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 452 | } // namespace webrtc |