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