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