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 | |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 17 | #ifdef _WIN32 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | #include <windows.h> |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 19 | #elif defined(WEBRTC_LINUX) |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 20 | #include <time.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | #else |
| 22 | #include <sys/time.h> |
| 23 | #include <time.h> |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 24 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 26 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "modules/audio_coding/codecs/audio_format_conversion.h" |
| 28 | #include "modules/audio_coding/test/utility.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 29 | #include "rtc_base/strings/string_builder.h" |
Niels Moller | 85e6e82 | 2018-09-04 11:49:57 +0000 | [diff] [blame] | 30 | #include "system_wrappers/include/event_wrapper.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 33 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 35 | void SetISACConfigDefault(ACMTestISACConfig& isacConfig) { |
| 36 | isacConfig.currentRateBitPerSec = 0; |
| 37 | isacConfig.currentFrameSizeMsec = 0; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 38 | isacConfig.encodingMode = -1; |
| 39 | isacConfig.initRateBitPerSec = 0; |
| 40 | isacConfig.initFrameSizeInMsec = 0; |
| 41 | isacConfig.enforceFrameSize = false; |
| 42 | return; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 45 | int16_t SetISAConfig(ACMTestISACConfig& isacConfig, |
| 46 | AudioCodingModule* acm, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 47 | int testMode) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 48 | if ((isacConfig.currentRateBitPerSec != 0) || |
| 49 | (isacConfig.currentFrameSizeMsec != 0)) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 50 | auto sendCodec = acm->SendCodec(); |
| 51 | EXPECT_TRUE(sendCodec); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 52 | if (isacConfig.currentRateBitPerSec < 0) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 53 | // Register iSAC in adaptive (channel-dependent) mode. |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 54 | sendCodec->rate = -1; |
| 55 | EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 56 | } else { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 57 | if (isacConfig.currentRateBitPerSec != 0) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 58 | sendCodec->rate = isacConfig.currentRateBitPerSec; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 59 | } |
| 60 | if (isacConfig.currentFrameSizeMsec != 0) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 61 | sendCodec->pacsize = |
| 62 | isacConfig.currentFrameSizeMsec * (sendCodec->plfreq / 1000); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 63 | } |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 64 | EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 66 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 68 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | } |
| 70 | |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 71 | ISACTest::ISACTest(int testMode) |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 72 | : _acmA(AudioCodingModule::Create( |
| 73 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
| 74 | _acmB(AudioCodingModule::Create( |
| 75 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 76 | _testMode(testMode) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 78 | ISACTest::~ISACTest() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 80 | void ISACTest::Setup() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 81 | int codecCntr; |
| 82 | CodecInst codecParam; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 84 | for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 85 | codecCntr++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 86 | EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 87 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") && |
| 88 | codecParam.plfreq == 16000) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 89 | memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst)); |
| 90 | _idISAC16kHz = codecCntr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 92 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") && |
| 93 | codecParam.plfreq == 32000) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 94 | memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst)); |
| 95 | _idISAC32kHz = codecCntr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 97 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 99 | // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 100 | EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC16kHz.pltype, |
| 101 | CodecInstToSdp(_paramISAC16kHz))); |
| 102 | EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC32kHz.pltype, |
| 103 | CodecInstToSdp(_paramISAC32kHz))); |
| 104 | EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC16kHz.pltype, |
| 105 | CodecInstToSdp(_paramISAC16kHz))); |
| 106 | EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC32kHz.pltype, |
| 107 | CodecInstToSdp(_paramISAC32kHz))); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 109 | //--- Set A-to-B channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 110 | _channel_A2B.reset(new Channel); |
| 111 | EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get())); |
| 112 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 114 | //--- Set B-to-A channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 115 | _channel_B2A.reset(new Channel); |
| 116 | EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get())); |
| 117 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 119 | file_name_swb_ = |
| 120 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 122 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
| 123 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 124 | |
| 125 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 126 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 127 | _inFileA.SetNum10MsBlocksToRead(50); |
| 128 | // Fast-forward 1 second (100 blocks) since the files start with silence. |
| 129 | _inFileA.FastForward(100); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 130 | std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm"; |
| 131 | std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm"; |
| 132 | _outFileA.Open(fileNameA, 32000, "wb"); |
| 133 | _outFileB.Open(fileNameB, 32000, "wb"); |
| 134 | |
| 135 | while (!_inFileA.EndOfFile()) { |
| 136 | Run10ms(); |
| 137 | } |
| 138 | CodecInst receiveCodec; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 139 | EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec)); |
| 140 | EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 141 | |
| 142 | _inFileA.Close(); |
| 143 | _outFileA.Close(); |
| 144 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | } |
| 146 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 147 | void ISACTest::Perform() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 148 | Setup(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 150 | int16_t testNr = 0; |
| 151 | ACMTestISACConfig wbISACConfig; |
| 152 | ACMTestISACConfig swbISACConfig; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 154 | SetISACConfigDefault(wbISACConfig); |
| 155 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 157 | wbISACConfig.currentRateBitPerSec = -1; |
| 158 | swbISACConfig.currentRateBitPerSec = -1; |
| 159 | testNr++; |
| 160 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 161 | |
| 162 | if (_testMode != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 163 | SetISACConfigDefault(wbISACConfig); |
| 164 | SetISACConfigDefault(swbISACConfig); |
| 165 | |
| 166 | wbISACConfig.currentRateBitPerSec = -1; |
| 167 | swbISACConfig.currentRateBitPerSec = -1; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 168 | wbISACConfig.initRateBitPerSec = 13000; |
| 169 | wbISACConfig.initFrameSizeInMsec = 60; |
| 170 | swbISACConfig.initRateBitPerSec = 20000; |
| 171 | swbISACConfig.initFrameSizeInMsec = 30; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | testNr++; |
| 173 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 174 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | SetISACConfigDefault(wbISACConfig); |
| 176 | SetISACConfigDefault(swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 177 | |
| 178 | wbISACConfig.currentRateBitPerSec = 20000; |
| 179 | swbISACConfig.currentRateBitPerSec = 48000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 180 | testNr++; |
| 181 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 182 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 183 | wbISACConfig.currentRateBitPerSec = 16000; |
| 184 | swbISACConfig.currentRateBitPerSec = 30000; |
| 185 | wbISACConfig.currentFrameSizeMsec = 60; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | testNr++; |
| 187 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 188 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 189 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 190 | SetISACConfigDefault(wbISACConfig); |
| 191 | SetISACConfigDefault(swbISACConfig); |
| 192 | testNr++; |
| 193 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 194 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 195 | testNr++; |
| 196 | if (_testMode == 0) { |
| 197 | SwitchingSamplingRate(testNr, 4); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 198 | } else { |
| 199 | SwitchingSamplingRate(testNr, 80); |
| 200 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | } |
| 202 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 203 | void ISACTest::Run10ms() { |
| 204 | AudioFrame audioFrame; |
| 205 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 206 | EXPECT_GE(_acmA->Add10MsData(audioFrame), 0); |
| 207 | EXPECT_GE(_acmB->Add10MsData(audioFrame), 0); |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 208 | bool muted; |
| 209 | EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame, &muted)); |
| 210 | ASSERT_FALSE(muted); |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 211 | _outFileA.Write10MsData(audioFrame); |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 212 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame, &muted)); |
| 213 | ASSERT_FALSE(muted); |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 214 | _outFileB.Write10MsData(audioFrame); |
| 215 | } |
| 216 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 217 | void ISACTest::EncodeDecode(int testNr, |
| 218 | ACMTestISACConfig& wbISACConfig, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 219 | ACMTestISACConfig& swbISACConfig) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 220 | // Files in Side A and B |
| 221 | _inFileA.Open(file_name_swb_, 32000, "rb", true); |
| 222 | _inFileB.Open(file_name_swb_, 32000, "rb", true); |
| 223 | |
| 224 | std::string file_name_out; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 225 | rtc::StringBuilder file_stream_a; |
| 226 | rtc::StringBuilder file_stream_b; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 227 | file_stream_a << webrtc::test::OutputPath(); |
| 228 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 229 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 230 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 231 | file_name_out = file_stream_a.str(); |
| 232 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 233 | file_name_out = file_stream_b.str(); |
| 234 | _outFileB.Open(file_name_out, 32000, "wb"); |
| 235 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 236 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
| 237 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 238 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
| 239 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 240 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 241 | // Side A is sending super-wideband, and side B is sending wideband. |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 242 | SetISAConfig(swbISACConfig, _acmA.get(), _testMode); |
| 243 | SetISAConfig(wbISACConfig, _acmB.get(), _testMode); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 244 | |
| 245 | bool adaptiveMode = false; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 246 | if ((swbISACConfig.currentRateBitPerSec == -1) || |
| 247 | (wbISACConfig.currentRateBitPerSec == -1)) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 248 | adaptiveMode = true; |
| 249 | } |
| 250 | _myTimer.Reset(); |
| 251 | _channel_A2B->ResetStats(); |
| 252 | _channel_B2A->ResetStats(); |
| 253 | |
| 254 | char currentTime[500]; |
Niels Moller | 85e6e82 | 2018-09-04 11:49:57 +0000 | [diff] [blame] | 255 | EventTimerWrapper* myEvent = EventTimerWrapper::Create(); |
| 256 | EXPECT_TRUE(myEvent->StartTimer(true, 10)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 257 | while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { |
| 258 | Run10ms(); |
| 259 | _myTimer.Tick10ms(); |
| 260 | _myTimer.CurrentTimeHMS(currentTime); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 261 | |
| 262 | if ((adaptiveMode) && (_testMode != 0)) { |
Niels Moller | 85e6e82 | 2018-09-04 11:49:57 +0000 | [diff] [blame] | 263 | myEvent->Wait(5000); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 264 | EXPECT_TRUE(_acmA->SendCodec()); |
| 265 | EXPECT_TRUE(_acmB->SendCodec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 266 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 267 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 268 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 269 | if (_testMode != 0) { |
| 270 | printf("\n\nSide A statistics\n\n"); |
| 271 | _channel_A2B->PrintStats(_paramISAC32kHz); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 272 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 273 | printf("\n\nSide B statistics\n\n"); |
| 274 | _channel_B2A->PrintStats(_paramISAC16kHz); |
| 275 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 276 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 277 | _channel_A2B->ResetStats(); |
| 278 | _channel_B2A->ResetStats(); |
| 279 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 280 | _outFileA.Close(); |
| 281 | _outFileB.Close(); |
| 282 | _inFileA.Close(); |
| 283 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 284 | } |
| 285 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 286 | void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) { |
| 287 | // Files in Side A |
| 288 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 289 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 290 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 291 | std::string file_name_out; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 292 | rtc::StringBuilder file_stream_a; |
| 293 | rtc::StringBuilder file_stream_b; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 294 | file_stream_a << webrtc::test::OutputPath(); |
| 295 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 296 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 297 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 298 | file_name_out = file_stream_a.str(); |
| 299 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 300 | file_name_out = file_stream_b.str(); |
| 301 | _outFileB.Open(file_name_out, 32000, "wb"); |
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 | // Start with side A sending super-wideband and side B seding wideband. |
| 304 | // Toggle sending wideband/super-wideband in this test. |
| 305 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 306 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 307 | |
| 308 | int numSendCodecChanged = 0; |
| 309 | _myTimer.Reset(); |
| 310 | char currentTime[50]; |
| 311 | while (numSendCodecChanged < (maxSampRateChange << 1)) { |
| 312 | Run10ms(); |
| 313 | _myTimer.Tick10ms(); |
| 314 | _myTimer.CurrentTimeHMS(currentTime); |
| 315 | if (_testMode == 2) |
| 316 | printf("\r%s", currentTime); |
| 317 | if (_inFileA.EndOfFile()) { |
| 318 | if (_inFileA.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 319 | // Switch side A to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 320 | _inFileA.Close(); |
| 321 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 322 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 323 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 324 | // Switch side A to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 325 | _inFileA.Close(); |
| 326 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 327 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 328 | } |
| 329 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | } |
| 331 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 332 | if (_inFileB.EndOfFile()) { |
| 333 | if (_inFileB.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 334 | // Switch side B to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 335 | _inFileB.Close(); |
| 336 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 337 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 338 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 339 | // Switch side B to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 340 | _inFileB.Close(); |
| 341 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 342 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 343 | } |
| 344 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 345 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 346 | } |
| 347 | _outFileA.Close(); |
| 348 | _outFileB.Close(); |
| 349 | _inFileA.Close(); |
| 350 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 352 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 353 | } // namespace webrtc |