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 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <ctype.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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" |
| 26 | #include "utility.h" |
pbos@webrtc.org | 2ab209e | 2013-08-09 08:49:48 +0000 | [diff] [blame] | 27 | #include "webrtc/test/testsupport/fileutils.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 | |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 33 | TwoWayCommunication::TwoWayCommunication(int testMode) |
| 34 | : _acmA(AudioCodingModule::Create(1)), |
| 35 | _acmB(AudioCodingModule::Create(2)), |
| 36 | _acmRefA(AudioCodingModule::Create(3)), |
| 37 | _acmRefB(AudioCodingModule::Create(4)), |
| 38 | _testMode(testMode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | } |
| 40 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 41 | TwoWayCommunication::~TwoWayCommunication() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 42 | delete _channel_A2B; |
| 43 | delete _channel_B2A; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 44 | delete _channelRef_A2B; |
| 45 | delete _channelRef_B2A; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | #ifdef WEBRTC_DTMF_DETECTION |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 47 | if (_dtmfDetectorA != NULL) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 48 | delete _dtmfDetectorA; |
| 49 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 50 | if (_dtmfDetectorB != NULL) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 51 | delete _dtmfDetectorB; |
| 52 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | #endif |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 54 | _inFileA.Close(); |
| 55 | _inFileB.Close(); |
| 56 | _outFileA.Close(); |
| 57 | _outFileB.Close(); |
| 58 | _outFileRefA.Close(); |
| 59 | _outFileRefB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | } |
| 61 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 62 | void TwoWayCommunication::ChooseCodec(uint8_t* codecID_A, |
| 63 | uint8_t* codecID_B) { |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 64 | scoped_ptr<AudioCodingModule> tmpACM(AudioCodingModule::Create(0)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 65 | uint8_t noCodec = tmpACM->NumberOfCodecs(); |
| 66 | CodecInst codecInst; |
| 67 | printf("List of Supported Codecs\n"); |
| 68 | printf("========================\n"); |
| 69 | for (uint8_t codecCntr = 0; codecCntr < noCodec; codecCntr++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 70 | EXPECT_EQ(tmpACM->Codec(codecCntr, &codecInst), 0); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 71 | printf("%d- %s\n", codecCntr, codecInst.plname); |
| 72 | } |
| 73 | printf("\nChoose a send codec for side A [0]: "); |
| 74 | char myStr[15] = ""; |
| 75 | EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL); |
| 76 | *codecID_A = (uint8_t) atoi(myStr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 78 | printf("\nChoose a send codec for side B [0]: "); |
| 79 | EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL); |
| 80 | *codecID_B = (uint8_t) atoi(myStr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 82 | printf("\n"); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 83 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 85 | void TwoWayCommunication::SetUp() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 86 | uint8_t codecID_A; |
| 87 | uint8_t codecID_B; |
| 88 | |
| 89 | ChooseCodec(&codecID_A, &codecID_B); |
| 90 | CodecInst codecInst_A; |
| 91 | CodecInst codecInst_B; |
| 92 | CodecInst dummyCodec; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 93 | EXPECT_EQ(0, _acmA->Codec(codecID_A, &codecInst_A)); |
| 94 | EXPECT_EQ(0, _acmB->Codec(codecID_B, &codecInst_B)); |
| 95 | EXPECT_EQ(0, _acmA->Codec(6, &dummyCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 96 | |
| 97 | //--- Set A codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 98 | EXPECT_EQ(0, _acmA->RegisterSendCodec(codecInst_A)); |
| 99 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(codecInst_B)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 100 | #ifdef WEBRTC_DTMF_DETECTION |
| 101 | _dtmfDetectorA = new(DTMFDetector); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 102 | EXPECT_GT(_acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA, ACMUSA), |
| 103 | -1); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 104 | #endif |
| 105 | //--- Set ref-A codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 106 | EXPECT_EQ(0, _acmRefA->RegisterSendCodec(codecInst_A)); |
| 107 | EXPECT_EQ(0, _acmRefA->RegisterReceiveCodec(codecInst_B)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 108 | |
| 109 | //--- Set B codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 110 | EXPECT_EQ(0, _acmB->RegisterSendCodec(codecInst_B)); |
| 111 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(codecInst_A)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 112 | #ifdef WEBRTC_DTMF_DETECTION |
| 113 | _dtmfDetectorB = new(DTMFDetector); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 114 | EXPECT_GT(_acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB, ACMUSA), |
| 115 | -1); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 116 | #endif |
| 117 | |
| 118 | //--- Set ref-B codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 119 | EXPECT_EQ(0, _acmRefB->RegisterSendCodec(codecInst_B)); |
| 120 | EXPECT_EQ(0, _acmRefB->RegisterReceiveCodec(codecInst_A)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 121 | |
| 122 | uint16_t frequencyHz; |
| 123 | |
| 124 | //--- Input A |
| 125 | std::string in_file_name = webrtc::test::ResourcePath( |
| 126 | "audio_coding/testfile32kHz", "pcm"); |
| 127 | frequencyHz = 32000; |
| 128 | printf("Enter input file at side A [%s]: ", in_file_name.c_str()); |
| 129 | PCMFile::ChooseFile(&in_file_name, 499, &frequencyHz); |
| 130 | _inFileA.Open(in_file_name, frequencyHz, "rb"); |
| 131 | |
| 132 | //--- Output A |
| 133 | std::string out_file_a = webrtc::test::OutputPath() + "outA.pcm"; |
| 134 | printf("Output file at side A: %s\n", out_file_a.c_str()); |
| 135 | printf("Sampling frequency (in Hz) of the above file: %u\n", frequencyHz); |
| 136 | _outFileA.Open(out_file_a, frequencyHz, "wb"); |
| 137 | std::string ref_file_name = webrtc::test::OutputPath() + "ref_outA.pcm"; |
| 138 | _outFileRefA.Open(ref_file_name, frequencyHz, "wb"); |
| 139 | |
| 140 | //--- Input B |
| 141 | in_file_name = webrtc::test::ResourcePath("audio_coding/testfile32kHz", |
| 142 | "pcm"); |
| 143 | frequencyHz = 32000; |
| 144 | printf("\n\nEnter input file at side B [%s]: ", in_file_name.c_str()); |
| 145 | PCMFile::ChooseFile(&in_file_name, 499, &frequencyHz); |
| 146 | _inFileB.Open(in_file_name, frequencyHz, "rb"); |
| 147 | |
| 148 | //--- Output B |
| 149 | std::string out_file_b = webrtc::test::OutputPath() + "outB.pcm"; |
| 150 | printf("Output file at side B: %s\n", out_file_b.c_str()); |
| 151 | printf("Sampling frequency (in Hz) of the above file: %u\n", frequencyHz); |
| 152 | _outFileB.Open(out_file_b, frequencyHz, "wb"); |
| 153 | ref_file_name = webrtc::test::OutputPath() + "ref_outB.pcm"; |
| 154 | _outFileRefB.Open(ref_file_name, frequencyHz, "wb"); |
| 155 | |
| 156 | //--- Set A-to-B channel |
| 157 | _channel_A2B = new Channel; |
| 158 | _acmA->RegisterTransportCallback(_channel_A2B); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 159 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 160 | //--- Do the same for the reference |
| 161 | _channelRef_A2B = new Channel; |
| 162 | _acmRefA->RegisterTransportCallback(_channelRef_A2B); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 163 | _channelRef_A2B->RegisterReceiverACM(_acmRefB.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 164 | |
| 165 | //--- Set B-to-A channel |
| 166 | _channel_B2A = new Channel; |
| 167 | _acmB->RegisterTransportCallback(_channel_B2A); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 168 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 169 | //--- Do the same for reference |
| 170 | _channelRef_B2A = new Channel; |
| 171 | _acmRefB->RegisterTransportCallback(_channelRef_B2A); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 172 | _channelRef_B2A->RegisterReceiverACM(_acmRefA.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 173 | |
| 174 | // The clicks will be more obvious when we |
| 175 | // are in FAX mode. |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 176 | EXPECT_EQ(_acmB->SetPlayoutMode(fax), 0); |
| 177 | EXPECT_EQ(_acmRefB->SetPlayoutMode(fax), 0); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 178 | } |
| 179 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 180 | void TwoWayCommunication::SetUpAutotest() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 181 | CodecInst codecInst_A; |
| 182 | CodecInst codecInst_B; |
| 183 | CodecInst dummyCodec; |
| 184 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 185 | EXPECT_EQ(0, _acmA->Codec("ISAC", &codecInst_A, 16000, 1)); |
| 186 | EXPECT_EQ(0, _acmB->Codec("L16", &codecInst_B, 8000, 1)); |
| 187 | EXPECT_EQ(0, _acmA->Codec(6, &dummyCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 188 | |
| 189 | //--- Set A codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 190 | EXPECT_EQ(0, _acmA->RegisterSendCodec(codecInst_A)); |
| 191 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(codecInst_B)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 192 | #ifdef WEBRTC_DTMF_DETECTION |
| 193 | _dtmfDetectorA = new(DTMFDetector); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 194 | EXPECT_EQ(0, _acmA->RegisterIncomingMessagesCallback(_dtmfDetectorA, ACMUSA)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
| 197 | //--- Set ref-A codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 198 | EXPECT_GT(_acmRefA->RegisterSendCodec(codecInst_A), -1); |
| 199 | EXPECT_GT(_acmRefA->RegisterReceiveCodec(codecInst_B), -1); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 200 | |
| 201 | //--- Set B codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 202 | EXPECT_GT(_acmB->RegisterSendCodec(codecInst_B), -1); |
| 203 | EXPECT_GT(_acmB->RegisterReceiveCodec(codecInst_A), -1); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 204 | #ifdef WEBRTC_DTMF_DETECTION |
| 205 | _dtmfDetectorB = new(DTMFDetector); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 206 | EXPECT_EQ(0, _acmB->RegisterIncomingMessagesCallback(_dtmfDetectorB, ACMUSA)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 207 | #endif |
| 208 | |
| 209 | //--- Set ref-B codecs |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 210 | EXPECT_EQ(0, _acmRefB->RegisterSendCodec(codecInst_B)); |
| 211 | EXPECT_EQ(0, _acmRefB->RegisterReceiveCodec(codecInst_A)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 212 | |
| 213 | uint16_t frequencyHz; |
| 214 | |
| 215 | //--- Input A and B |
| 216 | std::string in_file_name = webrtc::test::ResourcePath( |
| 217 | "audio_coding/testfile32kHz", "pcm"); |
| 218 | frequencyHz = 16000; |
| 219 | _inFileA.Open(in_file_name, frequencyHz, "rb"); |
| 220 | _inFileB.Open(in_file_name, frequencyHz, "rb"); |
| 221 | |
| 222 | //--- Output A |
| 223 | std::string output_file_a = webrtc::test::OutputPath() + "outAutotestA.pcm"; |
| 224 | frequencyHz = 16000; |
| 225 | _outFileA.Open(output_file_a, frequencyHz, "wb"); |
| 226 | std::string output_ref_file_a = webrtc::test::OutputPath() |
| 227 | + "ref_outAutotestA.pcm"; |
| 228 | _outFileRefA.Open(output_ref_file_a, frequencyHz, "wb"); |
| 229 | |
| 230 | //--- Output B |
| 231 | std::string output_file_b = webrtc::test::OutputPath() + "outAutotestB.pcm"; |
| 232 | frequencyHz = 16000; |
| 233 | _outFileB.Open(output_file_b, frequencyHz, "wb"); |
| 234 | std::string output_ref_file_b = webrtc::test::OutputPath() |
| 235 | + "ref_outAutotestB.pcm"; |
| 236 | _outFileRefB.Open(output_ref_file_b, frequencyHz, "wb"); |
| 237 | |
| 238 | //--- Set A-to-B channel |
| 239 | _channel_A2B = new Channel; |
| 240 | _acmA->RegisterTransportCallback(_channel_A2B); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 241 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 242 | //--- Do the same for the reference |
| 243 | _channelRef_A2B = new Channel; |
| 244 | _acmRefA->RegisterTransportCallback(_channelRef_A2B); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 245 | _channelRef_A2B->RegisterReceiverACM(_acmRefB.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 246 | |
| 247 | //--- Set B-to-A channel |
| 248 | _channel_B2A = new Channel; |
| 249 | _acmB->RegisterTransportCallback(_channel_B2A); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 250 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 251 | //--- Do the same for reference |
| 252 | _channelRef_B2A = new Channel; |
| 253 | _acmRefB->RegisterTransportCallback(_channelRef_B2A); |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 254 | _channelRef_B2A->RegisterReceiverACM(_acmRefA.get()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 255 | |
| 256 | // The clicks will be more obvious when we |
| 257 | // are in FAX mode. |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 258 | EXPECT_EQ(0, _acmB->SetPlayoutMode(fax)); |
| 259 | EXPECT_EQ(0, _acmRefB->SetPlayoutMode(fax)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void TwoWayCommunication::Perform() { |
| 263 | if (_testMode == 0) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 264 | SetUpAutotest(); |
| 265 | } else { |
| 266 | SetUp(); |
| 267 | } |
| 268 | unsigned int msecPassed = 0; |
| 269 | unsigned int secPassed = 0; |
| 270 | |
| 271 | int32_t outFreqHzA = _outFileA.SamplingFrequency(); |
| 272 | int32_t outFreqHzB = _outFileB.SamplingFrequency(); |
| 273 | |
| 274 | AudioFrame audioFrame; |
| 275 | |
| 276 | CodecInst codecInst_B; |
| 277 | CodecInst dummy; |
| 278 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 279 | EXPECT_EQ(0, _acmB->SendCodec(&codecInst_B)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 280 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 281 | // In the following loop we tests that the code can handle misuse of the APIs. |
| 282 | // In the middle of a session with data flowing between two sides, called A |
| 283 | // and B, APIs will be called, like ResetEncoder(), and the code should |
| 284 | // continue to run, and be able to recover. |
| 285 | bool expect_error_add = false; |
| 286 | bool expect_error_process = false; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 287 | while (!_inFileA.EndOfFile() && !_inFileB.EndOfFile()) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 288 | msecPassed += 10; |
| 289 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
| 290 | EXPECT_EQ(0, _acmA->Add10MsData(audioFrame)); |
| 291 | EXPECT_EQ(0, _acmRefA->Add10MsData(audioFrame)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 292 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 293 | EXPECT_GT(_inFileB.Read10MsData(audioFrame), 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 294 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 295 | // Expect call to pass except for the time when no send codec is registered. |
| 296 | if (!expect_error_add) { |
| 297 | EXPECT_EQ(0, _acmB->Add10MsData(audioFrame)); |
| 298 | } else { |
| 299 | EXPECT_EQ(-1, _acmB->Add10MsData(audioFrame)); |
| 300 | } |
| 301 | // Expect to pass except for the time when there either is no send codec |
| 302 | // registered, or no receive codec. |
| 303 | if (!expect_error_process) { |
| 304 | EXPECT_GT(_acmB->Process(), -1); |
| 305 | } else { |
| 306 | EXPECT_EQ(_acmB->Process(), -1); |
| 307 | } |
| 308 | EXPECT_EQ(0, _acmRefB->Add10MsData(audioFrame)); |
| 309 | EXPECT_GT(_acmA->Process(), -1); |
| 310 | EXPECT_GT(_acmRefA->Process(), -1); |
| 311 | EXPECT_GT(_acmRefB->Process(), -1); |
| 312 | EXPECT_EQ(0, _acmA->PlayoutData10Ms(outFreqHzA, &audioFrame)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 313 | _outFileA.Write10MsData(audioFrame); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 314 | EXPECT_EQ(0, _acmRefA->PlayoutData10Ms(outFreqHzA, &audioFrame)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 315 | _outFileRefA.Write10MsData(audioFrame); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 316 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(outFreqHzB, &audioFrame)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 317 | _outFileB.Write10MsData(audioFrame); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 318 | EXPECT_EQ(0, _acmRefB->PlayoutData10Ms(outFreqHzB, &audioFrame)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 319 | _outFileRefB.Write10MsData(audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 320 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 321 | // Update time counters each time a second of data has passed. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 322 | if (msecPassed >= 1000) { |
| 323 | msecPassed = 0; |
| 324 | secPassed++; |
| 325 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 326 | // Call RestEncoder for ACM on side A, and InitializeSender for ACM on |
| 327 | // side B. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 328 | if (((secPassed % 5) == 4) && (msecPassed == 0)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 329 | EXPECT_EQ(0, _acmA->ResetEncoder()); |
| 330 | EXPECT_EQ(0, _acmB->InitializeSender()); |
| 331 | expect_error_add = true; |
| 332 | expect_error_process = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 333 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 334 | // Re-register send codec on side B. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 335 | if (((secPassed % 5) == 4) && (msecPassed >= 990)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 336 | EXPECT_EQ(0, _acmB->RegisterSendCodec(codecInst_B)); |
| 337 | EXPECT_EQ(0, _acmB->SendCodec(&dummy)); |
| 338 | expect_error_add = false; |
| 339 | expect_error_process = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 340 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 341 | // Reset decoder on side B, and initialize receiver on side A. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 342 | if (((secPassed % 7) == 6) && (msecPassed == 0)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 343 | EXPECT_EQ(0, _acmB->ResetDecoder()); |
| 344 | EXPECT_EQ(0, _acmA->InitializeReceiver()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 345 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 346 | // Re-register codec on side A. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 347 | if (((secPassed % 7) == 6) && (msecPassed >= 990)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 348 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(codecInst_B)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 349 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 350 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | } |
| 352 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 353 | } // namespace webrtc |