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