niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 9dc45da | 2012-05-23 15:39:01 +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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/test/iSACTest.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 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 | |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 17 | #include "absl/strings/match.h" |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 18 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 19 | #include "api/audio_codecs/isac/audio_encoder_isac_float.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 20 | #include "rtc_base/strings/string_builder.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 21 | #include "rtc_base/time_utils.h" |
Niels Möller | fe3240a | 2018-09-06 16:47:42 +0200 | [diff] [blame] | 22 | #include "system_wrappers/include/sleep.h" |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 23 | #include "test/gmock.h" |
| 24 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 25 | #include "test/testsupport/file_utils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 27 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 29 | using ::testing::AnyOf; |
| 30 | using ::testing::Eq; |
| 31 | using ::testing::StrCaseEq; |
| 32 | |
| 33 | namespace { |
| 34 | |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 35 | constexpr int kISAC16kPayloadType = 103; |
| 36 | constexpr int kISAC32kPayloadType = 104; |
| 37 | const SdpAudioFormat kISAC16kFormat = { "ISAC", 16000, 1 }; |
| 38 | const SdpAudioFormat kISAC32kFormat = { "ISAC", 32000, 1 }; |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 39 | |
| 40 | AudioEncoderIsacFloat::Config TweakConfig( |
| 41 | AudioEncoderIsacFloat::Config config, |
| 42 | const ACMTestISACConfig& test_config) { |
| 43 | if (test_config.currentRateBitPerSec > 0) { |
| 44 | config.bit_rate = test_config.currentRateBitPerSec; |
| 45 | } |
| 46 | if (test_config.currentFrameSizeMsec != 0) { |
| 47 | config.frame_size_ms = test_config.currentFrameSizeMsec; |
| 48 | } |
| 49 | EXPECT_THAT(config.IsOk(), Eq(true)); |
| 50 | return config; |
| 51 | } |
| 52 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 53 | void SetISACConfigDefault(ACMTestISACConfig& isacConfig) { |
| 54 | isacConfig.currentRateBitPerSec = 0; |
| 55 | isacConfig.currentFrameSizeMsec = 0; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 56 | isacConfig.encodingMode = -1; |
| 57 | isacConfig.initRateBitPerSec = 0; |
| 58 | isacConfig.initFrameSizeInMsec = 0; |
| 59 | isacConfig.enforceFrameSize = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 62 | } // namespace |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 64 | ISACTest::ACMTestTimer::ACMTestTimer() : _msec(0), _sec(0), _min(0), _hour(0) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | ISACTest::ACMTestTimer::~ACMTestTimer() { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | void ISACTest::ACMTestTimer::Reset() { |
| 73 | _msec = 0; |
| 74 | _sec = 0; |
| 75 | _min = 0; |
| 76 | _hour = 0; |
| 77 | return; |
| 78 | } |
| 79 | void ISACTest::ACMTestTimer::Tick10ms() { |
| 80 | _msec += 10; |
| 81 | Adjust(); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | void ISACTest::ACMTestTimer::Tick1ms() { |
| 86 | _msec++; |
| 87 | Adjust(); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | void ISACTest::ACMTestTimer::Tick100ms() { |
| 92 | _msec += 100; |
| 93 | Adjust(); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | void ISACTest::ACMTestTimer::Tick1sec() { |
| 98 | _sec++; |
| 99 | Adjust(); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | void ISACTest::ACMTestTimer::CurrentTimeHMS(char* currTime) { |
| 104 | sprintf(currTime, "%4lu:%02u:%06.3f", _hour, _min, |
| 105 | (double)_sec + (double)_msec / 1000.); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | void ISACTest::ACMTestTimer::CurrentTime(unsigned long& h, |
| 110 | unsigned char& m, |
| 111 | unsigned char& s, |
| 112 | unsigned short& ms) { |
| 113 | h = _hour; |
| 114 | m = _min; |
| 115 | s = _sec; |
| 116 | ms = _msec; |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | void ISACTest::ACMTestTimer::Adjust() { |
| 121 | unsigned int n; |
| 122 | if (_msec >= 1000) { |
| 123 | n = _msec / 1000; |
| 124 | _msec -= (1000 * n); |
| 125 | _sec += n; |
| 126 | } |
| 127 | if (_sec >= 60) { |
| 128 | n = _sec / 60; |
| 129 | _sec -= (n * 60); |
| 130 | _min += n; |
| 131 | } |
| 132 | if (_min >= 60) { |
| 133 | n = _min / 60; |
| 134 | _min -= (n * 60); |
| 135 | _hour += n; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | ISACTest::ISACTest() |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 140 | : _acmA(AudioCodingModule::Create( |
| 141 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
| 142 | _acmB(AudioCodingModule::Create( |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 143 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 145 | ISACTest::~ISACTest() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 147 | void ISACTest::Setup() { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 148 | // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 149 | std::map<int, SdpAudioFormat> receive_codecs = |
| 150 | {{kISAC16kPayloadType, kISAC16kFormat}, |
| 151 | {kISAC32kPayloadType, kISAC32kFormat}}; |
| 152 | _acmA->SetReceiveCodecs(receive_codecs); |
| 153 | _acmB->SetReceiveCodecs(receive_codecs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 155 | //--- Set A-to-B channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 156 | _channel_A2B.reset(new Channel); |
| 157 | EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get())); |
| 158 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 160 | //--- Set B-to-A channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 161 | _channel_B2A.reset(new Channel); |
| 162 | EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get())); |
| 163 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 165 | file_name_swb_ = |
| 166 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 168 | _acmB->SetEncoder( |
| 169 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 170 | *AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat), |
| 171 | kISAC16kPayloadType)); |
| 172 | _acmA->SetEncoder( |
| 173 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 174 | *AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat), |
| 175 | kISAC32kPayloadType)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 176 | |
| 177 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 178 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 179 | _inFileA.SetNum10MsBlocksToRead(50); |
| 180 | // Fast-forward 1 second (100 blocks) since the files start with silence. |
| 181 | _inFileA.FastForward(100); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 182 | std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm"; |
| 183 | std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm"; |
| 184 | _outFileA.Open(fileNameA, 32000, "wb"); |
| 185 | _outFileB.Open(fileNameB, 32000, "wb"); |
| 186 | |
| 187 | while (!_inFileA.EndOfFile()) { |
| 188 | Run10ms(); |
| 189 | } |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 190 | |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 191 | EXPECT_TRUE(_acmA->ReceiveCodec()); |
| 192 | EXPECT_TRUE(_acmB->ReceiveCodec()); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 193 | |
| 194 | _inFileA.Close(); |
| 195 | _outFileA.Close(); |
| 196 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | } |
| 198 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 199 | void ISACTest::Perform() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 200 | Setup(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 202 | int16_t testNr = 0; |
| 203 | ACMTestISACConfig wbISACConfig; |
| 204 | ACMTestISACConfig swbISACConfig; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 206 | SetISACConfigDefault(wbISACConfig); |
| 207 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 208 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 209 | wbISACConfig.currentRateBitPerSec = -1; |
| 210 | swbISACConfig.currentRateBitPerSec = -1; |
| 211 | testNr++; |
| 212 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 213 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 214 | SetISACConfigDefault(wbISACConfig); |
| 215 | SetISACConfigDefault(swbISACConfig); |
| 216 | testNr++; |
| 217 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 218 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 219 | testNr++; |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 220 | SwitchingSamplingRate(testNr, 4); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | } |
| 222 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 223 | void ISACTest::Run10ms() { |
| 224 | AudioFrame audioFrame; |
| 225 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 226 | EXPECT_GE(_acmA->Add10MsData(audioFrame), 0); |
| 227 | EXPECT_GE(_acmB->Add10MsData(audioFrame), 0); |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 228 | bool muted; |
| 229 | EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame, &muted)); |
| 230 | ASSERT_FALSE(muted); |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 231 | _outFileA.Write10MsData(audioFrame); |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 232 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame, &muted)); |
| 233 | ASSERT_FALSE(muted); |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 234 | _outFileB.Write10MsData(audioFrame); |
| 235 | } |
| 236 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 237 | void ISACTest::EncodeDecode(int testNr, |
| 238 | ACMTestISACConfig& wbISACConfig, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 239 | ACMTestISACConfig& swbISACConfig) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 240 | // Files in Side A and B |
| 241 | _inFileA.Open(file_name_swb_, 32000, "rb", true); |
| 242 | _inFileB.Open(file_name_swb_, 32000, "rb", true); |
| 243 | |
| 244 | std::string file_name_out; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 245 | rtc::StringBuilder file_stream_a; |
| 246 | rtc::StringBuilder file_stream_b; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 247 | file_stream_a << webrtc::test::OutputPath(); |
| 248 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 249 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 250 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 251 | file_name_out = file_stream_a.str(); |
| 252 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 253 | file_name_out = file_stream_b.str(); |
| 254 | _outFileB.Open(file_name_out, 32000, "wb"); |
| 255 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 256 | // Side A is sending super-wideband, and side B is sending wideband. |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 257 | _acmA->SetEncoder( |
| 258 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 259 | TweakConfig(*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat), |
| 260 | swbISACConfig), |
| 261 | kISAC32kPayloadType)); |
| 262 | _acmB->SetEncoder( |
| 263 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 264 | TweakConfig(*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat), |
| 265 | wbISACConfig), |
| 266 | kISAC16kPayloadType)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 267 | |
| 268 | bool adaptiveMode = false; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 269 | if ((swbISACConfig.currentRateBitPerSec == -1) || |
| 270 | (wbISACConfig.currentRateBitPerSec == -1)) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 271 | adaptiveMode = true; |
| 272 | } |
| 273 | _myTimer.Reset(); |
| 274 | _channel_A2B->ResetStats(); |
| 275 | _channel_B2A->ResetStats(); |
| 276 | |
| 277 | char currentTime[500]; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 278 | while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { |
| 279 | Run10ms(); |
| 280 | _myTimer.Tick10ms(); |
| 281 | _myTimer.CurrentTimeHMS(currentTime); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 282 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 283 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 284 | _channel_A2B->ResetStats(); |
| 285 | _channel_B2A->ResetStats(); |
| 286 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 287 | _outFileA.Close(); |
| 288 | _outFileB.Close(); |
| 289 | _inFileA.Close(); |
| 290 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 291 | } |
| 292 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 293 | void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) { |
| 294 | // Files in Side A |
| 295 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 296 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 297 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 298 | std::string file_name_out; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 299 | rtc::StringBuilder file_stream_a; |
| 300 | rtc::StringBuilder file_stream_b; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 301 | file_stream_a << webrtc::test::OutputPath(); |
| 302 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 303 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 304 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 305 | file_name_out = file_stream_a.str(); |
| 306 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 307 | file_name_out = file_stream_b.str(); |
| 308 | _outFileB.Open(file_name_out, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 309 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 310 | // Start with side A sending super-wideband and side B seding wideband. |
| 311 | // Toggle sending wideband/super-wideband in this test. |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 312 | _acmA->SetEncoder( |
| 313 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 314 | *AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat), |
| 315 | kISAC32kPayloadType)); |
| 316 | _acmB->SetEncoder( |
| 317 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 318 | *AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat), |
| 319 | kISAC16kPayloadType)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 320 | |
| 321 | int numSendCodecChanged = 0; |
| 322 | _myTimer.Reset(); |
| 323 | char currentTime[50]; |
| 324 | while (numSendCodecChanged < (maxSampRateChange << 1)) { |
| 325 | Run10ms(); |
| 326 | _myTimer.Tick10ms(); |
| 327 | _myTimer.CurrentTimeHMS(currentTime); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 328 | if (_inFileA.EndOfFile()) { |
| 329 | if (_inFileA.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 330 | // Switch side A to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 331 | _inFileA.Close(); |
| 332 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 333 | _acmA->SetEncoder( |
| 334 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 335 | *AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat), |
| 336 | kISAC32kPayloadType)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 337 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 338 | // Switch side A to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 339 | _inFileA.Close(); |
| 340 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 341 | _acmA->SetEncoder( |
| 342 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 343 | *AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat), |
| 344 | kISAC16kPayloadType)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 345 | } |
| 346 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | } |
| 348 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 349 | if (_inFileB.EndOfFile()) { |
| 350 | if (_inFileB.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 351 | // Switch side B to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 352 | _inFileB.Close(); |
| 353 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 354 | _acmB->SetEncoder( |
| 355 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 356 | *AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat), |
| 357 | kISAC32kPayloadType)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 358 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 359 | // Switch side B to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 360 | _inFileB.Close(); |
| 361 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | 657b296 | 2018-12-05 10:30:25 +0100 | [diff] [blame] | 362 | _acmB->SetEncoder( |
| 363 | AudioEncoderIsacFloat::MakeAudioEncoder( |
| 364 | *AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat), |
| 365 | kISAC16kPayloadType)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 366 | } |
| 367 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 368 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 369 | } |
| 370 | _outFileA.Close(); |
| 371 | _outFileB.Close(); |
| 372 | _inFileA.Close(); |
| 373 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 374 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 375 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 376 | } // namespace webrtc |