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 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/main/test/iSACTest.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 | #if _WIN32 |
| 18 | #include <windows.h> |
| 19 | #elif 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 | |
turaj@webrtc.org | 532f3dc | 2013-09-19 00:12:23 +0000 | [diff] [blame] | 26 | #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 27 | #include "webrtc/modules/audio_coding/main/test/utility.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 28 | #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 29 | #include "webrtc/system_wrappers/include/tick_util.h" |
| 30 | #include "webrtc/system_wrappers/include/trace.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 31 | #include "webrtc/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 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 45 | int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm, |
| 46 | int testMode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [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) { |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame^] | 61 | sendCodec->pacsize = isacConfig.currentFrameSizeMsec |
| 62 | * (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) |
| 72 | : _acmA(AudioCodingModule::Create(1)), |
| 73 | _acmB(AudioCodingModule::Create(2)), |
| 74 | _testMode(testMode) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 76 | ISACTest::~ISACTest() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 78 | void ISACTest::Setup() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 79 | int codecCntr; |
| 80 | CodecInst codecParam; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 82 | for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs(); |
| 83 | codecCntr++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 84 | EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 85 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") |
| 86 | && codecParam.plfreq == 16000) { |
| 87 | memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst)); |
| 88 | _idISAC16kHz = codecCntr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 90 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") |
| 91 | && codecParam.plfreq == 32000) { |
| 92 | memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst)); |
| 93 | _idISAC32kHz = codecCntr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 95 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 97 | // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. |
| 98 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz)); |
| 99 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz)); |
| 100 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz)); |
| 101 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 103 | //--- Set A-to-B channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 104 | _channel_A2B.reset(new Channel); |
| 105 | EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get())); |
| 106 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 108 | //--- Set B-to-A channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 109 | _channel_B2A.reset(new Channel); |
| 110 | EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get())); |
| 111 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 113 | file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz", |
| 114 | "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 116 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
| 117 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 118 | |
| 119 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 120 | std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm"; |
| 121 | std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm"; |
| 122 | _outFileA.Open(fileNameA, 32000, "wb"); |
| 123 | _outFileB.Open(fileNameB, 32000, "wb"); |
| 124 | |
| 125 | while (!_inFileA.EndOfFile()) { |
| 126 | Run10ms(); |
| 127 | } |
| 128 | CodecInst receiveCodec; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 129 | EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec)); |
| 130 | EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 131 | |
| 132 | _inFileA.Close(); |
| 133 | _outFileA.Close(); |
| 134 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | } |
| 136 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 137 | void ISACTest::Perform() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 138 | Setup(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 139 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 140 | int16_t testNr = 0; |
| 141 | ACMTestISACConfig wbISACConfig; |
| 142 | ACMTestISACConfig swbISACConfig; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 144 | SetISACConfigDefault(wbISACConfig); |
| 145 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 147 | wbISACConfig.currentRateBitPerSec = -1; |
| 148 | swbISACConfig.currentRateBitPerSec = -1; |
| 149 | testNr++; |
| 150 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 151 | |
| 152 | if (_testMode != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | SetISACConfigDefault(wbISACConfig); |
| 154 | SetISACConfigDefault(swbISACConfig); |
| 155 | |
| 156 | wbISACConfig.currentRateBitPerSec = -1; |
| 157 | swbISACConfig.currentRateBitPerSec = -1; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 158 | wbISACConfig.initRateBitPerSec = 13000; |
| 159 | wbISACConfig.initFrameSizeInMsec = 60; |
| 160 | swbISACConfig.initRateBitPerSec = 20000; |
| 161 | swbISACConfig.initFrameSizeInMsec = 30; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | testNr++; |
| 163 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 164 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | SetISACConfigDefault(wbISACConfig); |
| 166 | SetISACConfigDefault(swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 167 | |
| 168 | wbISACConfig.currentRateBitPerSec = 20000; |
| 169 | swbISACConfig.currentRateBitPerSec = 48000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 170 | testNr++; |
| 171 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 172 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 173 | wbISACConfig.currentRateBitPerSec = 16000; |
| 174 | swbISACConfig.currentRateBitPerSec = 30000; |
| 175 | wbISACConfig.currentFrameSizeMsec = 60; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | testNr++; |
| 177 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 178 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 180 | SetISACConfigDefault(wbISACConfig); |
| 181 | SetISACConfigDefault(swbISACConfig); |
| 182 | testNr++; |
| 183 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 185 | testNr++; |
| 186 | if (_testMode == 0) { |
| 187 | SwitchingSamplingRate(testNr, 4); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 188 | } else { |
| 189 | SwitchingSamplingRate(testNr, 80); |
| 190 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | } |
| 192 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 193 | void ISACTest::Run10ms() { |
| 194 | AudioFrame audioFrame; |
| 195 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 196 | EXPECT_GE(_acmA->Add10MsData(audioFrame), 0); |
| 197 | EXPECT_GE(_acmB->Add10MsData(audioFrame), 0); |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 198 | EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame)); |
| 199 | _outFileA.Write10MsData(audioFrame); |
| 200 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame)); |
| 201 | _outFileB.Write10MsData(audioFrame); |
| 202 | } |
| 203 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 204 | void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig, |
| 205 | ACMTestISACConfig& swbISACConfig) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 206 | // Files in Side A and B |
| 207 | _inFileA.Open(file_name_swb_, 32000, "rb", true); |
| 208 | _inFileB.Open(file_name_swb_, 32000, "rb", true); |
| 209 | |
| 210 | std::string file_name_out; |
| 211 | std::stringstream file_stream_a; |
| 212 | std::stringstream file_stream_b; |
| 213 | file_stream_a << webrtc::test::OutputPath(); |
| 214 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 215 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 216 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 217 | file_name_out = file_stream_a.str(); |
| 218 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 219 | file_name_out = file_stream_b.str(); |
| 220 | _outFileB.Open(file_name_out, 32000, "wb"); |
| 221 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 222 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
| 223 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 224 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
| 225 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 226 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 227 | // 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] | 228 | SetISAConfig(swbISACConfig, _acmA.get(), _testMode); |
| 229 | SetISAConfig(wbISACConfig, _acmB.get(), _testMode); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 230 | |
| 231 | bool adaptiveMode = false; |
| 232 | if ((swbISACConfig.currentRateBitPerSec == -1) |
| 233 | || (wbISACConfig.currentRateBitPerSec == -1)) { |
| 234 | adaptiveMode = true; |
| 235 | } |
| 236 | _myTimer.Reset(); |
| 237 | _channel_A2B->ResetStats(); |
| 238 | _channel_B2A->ResetStats(); |
| 239 | |
| 240 | char currentTime[500]; |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 241 | EventTimerWrapper* myEvent = EventTimerWrapper::Create(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 242 | EXPECT_TRUE(myEvent->StartTimer(true, 10)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 243 | while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { |
| 244 | Run10ms(); |
| 245 | _myTimer.Tick10ms(); |
| 246 | _myTimer.CurrentTimeHMS(currentTime); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 247 | |
| 248 | if ((adaptiveMode) && (_testMode != 0)) { |
| 249 | myEvent->Wait(5000); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame^] | 250 | EXPECT_TRUE(_acmA->SendCodec()); |
| 251 | EXPECT_TRUE(_acmB->SendCodec()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 252 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 253 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 254 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 255 | if (_testMode != 0) { |
| 256 | printf("\n\nSide A statistics\n\n"); |
| 257 | _channel_A2B->PrintStats(_paramISAC32kHz); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 258 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 259 | printf("\n\nSide B statistics\n\n"); |
| 260 | _channel_B2A->PrintStats(_paramISAC16kHz); |
| 261 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 262 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 263 | _channel_A2B->ResetStats(); |
| 264 | _channel_B2A->ResetStats(); |
| 265 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 266 | _outFileA.Close(); |
| 267 | _outFileB.Close(); |
| 268 | _inFileA.Close(); |
| 269 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 270 | } |
| 271 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 272 | void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) { |
| 273 | // Files in Side A |
| 274 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 275 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 276 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 277 | std::string file_name_out; |
| 278 | std::stringstream file_stream_a; |
| 279 | std::stringstream file_stream_b; |
| 280 | file_stream_a << webrtc::test::OutputPath(); |
| 281 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 282 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 283 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 284 | file_name_out = file_stream_a.str(); |
| 285 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 286 | file_name_out = file_stream_b.str(); |
| 287 | _outFileB.Open(file_name_out, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 288 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 289 | // Start with side A sending super-wideband and side B seding wideband. |
| 290 | // Toggle sending wideband/super-wideband in this test. |
| 291 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 292 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 293 | |
| 294 | int numSendCodecChanged = 0; |
| 295 | _myTimer.Reset(); |
| 296 | char currentTime[50]; |
| 297 | while (numSendCodecChanged < (maxSampRateChange << 1)) { |
| 298 | Run10ms(); |
| 299 | _myTimer.Tick10ms(); |
| 300 | _myTimer.CurrentTimeHMS(currentTime); |
| 301 | if (_testMode == 2) |
| 302 | printf("\r%s", currentTime); |
| 303 | if (_inFileA.EndOfFile()) { |
| 304 | if (_inFileA.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 305 | // Switch side A to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 306 | _inFileA.Close(); |
| 307 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 308 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 309 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 310 | // Switch side A to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 311 | _inFileA.Close(); |
| 312 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 313 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 314 | } |
| 315 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | } |
| 317 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 318 | if (_inFileB.EndOfFile()) { |
| 319 | if (_inFileB.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 320 | // Switch side B to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 321 | _inFileB.Close(); |
| 322 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 323 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 324 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 325 | // Switch side B to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 326 | _inFileB.Close(); |
| 327 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 328 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 329 | } |
| 330 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 331 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 332 | } |
| 333 | _outFileA.Close(); |
| 334 | _outFileB.Close(); |
| 335 | _inFileA.Close(); |
| 336 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 337 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 338 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 339 | } // namespace webrtc |