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" |
| 28 | #include "webrtc/system_wrappers/interface/event_wrapper.h" |
| 29 | #include "webrtc/system_wrappers/interface/tick_util.h" |
| 30 | #include "webrtc/system_wrappers/interface/trace.h" |
| 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; |
| 38 | isacConfig.maxRateBitPerSec = 0; |
| 39 | isacConfig.maxPayloadSizeByte = 0; |
| 40 | isacConfig.encodingMode = -1; |
| 41 | isacConfig.initRateBitPerSec = 0; |
| 42 | isacConfig.initFrameSizeInMsec = 0; |
| 43 | isacConfig.enforceFrameSize = false; |
| 44 | return; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 47 | int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm, |
| 48 | int testMode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 50 | if ((isacConfig.currentRateBitPerSec != 0) |
| 51 | || (isacConfig.currentFrameSizeMsec != 0)) { |
| 52 | CodecInst sendCodec; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 53 | EXPECT_EQ(0, acm->SendCodec(&sendCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 54 | if (isacConfig.currentRateBitPerSec < 0) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 55 | // Register iSAC in adaptive (channel-dependent) mode. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 56 | sendCodec.rate = -1; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 57 | EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 58 | } else { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 59 | if (isacConfig.currentRateBitPerSec != 0) { |
| 60 | sendCodec.rate = isacConfig.currentRateBitPerSec; |
| 61 | } |
| 62 | if (isacConfig.currentFrameSizeMsec != 0) { |
| 63 | sendCodec.pacsize = isacConfig.currentFrameSizeMsec |
| 64 | * (sendCodec.plfreq / 1000); |
| 65 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 66 | EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec)); |
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 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 70 | if (isacConfig.maxRateBitPerSec > 0) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 71 | // Set max rate. |
| 72 | EXPECT_EQ(0, acm->SetISACMaxRate(isacConfig.maxRateBitPerSec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 73 | } |
| 74 | if (isacConfig.maxPayloadSizeByte > 0) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 75 | // Set max payload size. |
| 76 | EXPECT_EQ(0, acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 77 | } |
| 78 | if ((isacConfig.initFrameSizeInMsec != 0) |
| 79 | || (isacConfig.initRateBitPerSec != 0)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 80 | EXPECT_EQ(0, acm->ConfigISACBandwidthEstimator( |
| 81 | static_cast<uint8_t>(isacConfig.initFrameSizeInMsec), |
| 82 | static_cast<uint16_t>(isacConfig.initRateBitPerSec), |
| 83 | isacConfig.enforceFrameSize)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 84 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 86 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | } |
| 88 | |
turaj@webrtc.org | 6ea3d1c | 2013-10-02 21:44:33 +0000 | [diff] [blame] | 89 | ISACTest::ISACTest(int testMode, const Config& config) |
| 90 | : _acmA(config.Get<AudioCodingModuleFactory>().Create(1)), |
| 91 | _acmB(config.Get<AudioCodingModuleFactory>().Create(2)), |
andrew@webrtc.org | 89df092 | 2013-09-12 01:27:43 +0000 | [diff] [blame] | 92 | _testMode(testMode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | } |
| 94 | |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 95 | ISACTest::~ISACTest() {} |
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 | void ISACTest::Setup() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 98 | int codecCntr; |
| 99 | CodecInst codecParam; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 101 | for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs(); |
| 102 | codecCntr++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 103 | EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 104 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") |
| 105 | && codecParam.plfreq == 16000) { |
| 106 | memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst)); |
| 107 | _idISAC16kHz = codecCntr; |
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 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") |
| 110 | && codecParam.plfreq == 32000) { |
| 111 | memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst)); |
| 112 | _idISAC32kHz = codecCntr; |
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 | } |
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 | // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. |
| 117 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz)); |
| 118 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz)); |
| 119 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz)); |
| 120 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 122 | //--- Set A-to-B channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 123 | _channel_A2B.reset(new Channel); |
| 124 | EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get())); |
| 125 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 127 | //--- Set B-to-A channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 128 | _channel_B2A.reset(new Channel); |
| 129 | EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get())); |
| 130 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 132 | file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz", |
| 133 | "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 135 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
| 136 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 137 | |
| 138 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 139 | std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm"; |
| 140 | std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm"; |
| 141 | _outFileA.Open(fileNameA, 32000, "wb"); |
| 142 | _outFileB.Open(fileNameB, 32000, "wb"); |
| 143 | |
| 144 | while (!_inFileA.EndOfFile()) { |
| 145 | Run10ms(); |
| 146 | } |
| 147 | CodecInst receiveCodec; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 148 | EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec)); |
| 149 | EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 150 | |
| 151 | _inFileA.Close(); |
| 152 | _outFileA.Close(); |
| 153 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | } |
| 155 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 156 | void ISACTest::Perform() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 157 | Setup(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 159 | int16_t testNr = 0; |
| 160 | ACMTestISACConfig wbISACConfig; |
| 161 | ACMTestISACConfig swbISACConfig; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 163 | SetISACConfigDefault(wbISACConfig); |
| 164 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 166 | wbISACConfig.currentRateBitPerSec = -1; |
| 167 | swbISACConfig.currentRateBitPerSec = -1; |
| 168 | testNr++; |
| 169 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 170 | |
| 171 | if (_testMode != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | SetISACConfigDefault(wbISACConfig); |
| 173 | SetISACConfigDefault(swbISACConfig); |
| 174 | |
| 175 | wbISACConfig.currentRateBitPerSec = -1; |
| 176 | swbISACConfig.currentRateBitPerSec = -1; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 177 | wbISACConfig.initRateBitPerSec = 13000; |
| 178 | wbISACConfig.initFrameSizeInMsec = 60; |
| 179 | swbISACConfig.initRateBitPerSec = 20000; |
| 180 | swbISACConfig.initFrameSizeInMsec = 30; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | testNr++; |
| 182 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 183 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | SetISACConfigDefault(wbISACConfig); |
| 185 | SetISACConfigDefault(swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 186 | |
| 187 | wbISACConfig.currentRateBitPerSec = 20000; |
| 188 | swbISACConfig.currentRateBitPerSec = 48000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 189 | testNr++; |
| 190 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 191 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 192 | wbISACConfig.currentRateBitPerSec = 16000; |
| 193 | swbISACConfig.currentRateBitPerSec = 30000; |
| 194 | wbISACConfig.currentFrameSizeMsec = 60; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 195 | testNr++; |
| 196 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 197 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 199 | SetISACConfigDefault(wbISACConfig); |
| 200 | SetISACConfigDefault(swbISACConfig); |
| 201 | testNr++; |
| 202 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 204 | int user_input; |
| 205 | if ((_testMode == 0) || (_testMode == 1)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 206 | swbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200); |
| 207 | wbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 208 | } else { |
| 209 | printf("Enter the max payload-size for side A: "); |
| 210 | CHECK_ERROR(scanf("%d", &user_input)); |
| 211 | swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input; |
| 212 | printf("Enter the max payload-size for side B: "); |
| 213 | CHECK_ERROR(scanf("%d", &user_input)); |
| 214 | wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input; |
| 215 | } |
| 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 | _acmA->ResetEncoder(); |
| 220 | _acmB->ResetEncoder(); |
| 221 | SetISACConfigDefault(wbISACConfig); |
| 222 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 223 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 224 | if ((_testMode == 0) || (_testMode == 1)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 225 | swbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000); |
| 226 | wbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 227 | } else { |
| 228 | printf("Enter the max rate for side A: "); |
| 229 | CHECK_ERROR(scanf("%d", &user_input)); |
| 230 | swbISACConfig.maxRateBitPerSec = (uint32_t) user_input; |
| 231 | printf("Enter the max rate for side B: "); |
| 232 | CHECK_ERROR(scanf("%d", &user_input)); |
| 233 | wbISACConfig.maxRateBitPerSec = (uint32_t) user_input; |
| 234 | } |
| 235 | |
| 236 | testNr++; |
| 237 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 238 | |
| 239 | testNr++; |
| 240 | if (_testMode == 0) { |
| 241 | SwitchingSamplingRate(testNr, 4); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 242 | } else { |
| 243 | SwitchingSamplingRate(testNr, 80); |
| 244 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 245 | } |
| 246 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame^] | 247 | void ISACTest::Run10ms() { |
| 248 | AudioFrame audioFrame; |
| 249 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
| 250 | EXPECT_EQ(0, _acmA->Add10MsData(audioFrame)); |
| 251 | EXPECT_EQ(0, _acmB->Add10MsData(audioFrame)); |
| 252 | EXPECT_GT(_acmA->Process(), -1); |
| 253 | EXPECT_GT(_acmB->Process(), -1); |
| 254 | EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame)); |
| 255 | _outFileA.Write10MsData(audioFrame); |
| 256 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame)); |
| 257 | _outFileB.Write10MsData(audioFrame); |
| 258 | } |
| 259 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 260 | void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig, |
| 261 | ACMTestISACConfig& swbISACConfig) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 262 | // Files in Side A and B |
| 263 | _inFileA.Open(file_name_swb_, 32000, "rb", true); |
| 264 | _inFileB.Open(file_name_swb_, 32000, "rb", true); |
| 265 | |
| 266 | std::string file_name_out; |
| 267 | std::stringstream file_stream_a; |
| 268 | std::stringstream file_stream_b; |
| 269 | file_stream_a << webrtc::test::OutputPath(); |
| 270 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 271 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 272 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 273 | file_name_out = file_stream_a.str(); |
| 274 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 275 | file_name_out = file_stream_b.str(); |
| 276 | _outFileB.Open(file_name_out, 32000, "wb"); |
| 277 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 278 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
| 279 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 280 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
| 281 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 282 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 283 | // 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] | 284 | SetISAConfig(swbISACConfig, _acmA.get(), _testMode); |
| 285 | SetISAConfig(wbISACConfig, _acmB.get(), _testMode); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 286 | |
| 287 | bool adaptiveMode = false; |
| 288 | if ((swbISACConfig.currentRateBitPerSec == -1) |
| 289 | || (wbISACConfig.currentRateBitPerSec == -1)) { |
| 290 | adaptiveMode = true; |
| 291 | } |
| 292 | _myTimer.Reset(); |
| 293 | _channel_A2B->ResetStats(); |
| 294 | _channel_B2A->ResetStats(); |
| 295 | |
| 296 | char currentTime[500]; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 297 | CodecInst sendCodec; |
| 298 | EventWrapper* myEvent = EventWrapper::Create(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 299 | EXPECT_TRUE(myEvent->StartTimer(true, 10)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 300 | while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { |
| 301 | Run10ms(); |
| 302 | _myTimer.Tick10ms(); |
| 303 | _myTimer.CurrentTimeHMS(currentTime); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 304 | |
| 305 | if ((adaptiveMode) && (_testMode != 0)) { |
| 306 | myEvent->Wait(5000); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 307 | EXPECT_EQ(0, _acmA->SendCodec(&sendCodec)); |
| 308 | EXPECT_EQ(0, _acmB->SendCodec(&sendCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 309 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 310 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 312 | if (_testMode != 0) { |
| 313 | printf("\n\nSide A statistics\n\n"); |
| 314 | _channel_A2B->PrintStats(_paramISAC32kHz); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 315 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 316 | printf("\n\nSide B statistics\n\n"); |
| 317 | _channel_B2A->PrintStats(_paramISAC16kHz); |
| 318 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 319 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame^] | 320 | _channel_A2B->ResetStats(); |
| 321 | _channel_B2A->ResetStats(); |
| 322 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 323 | _outFileA.Close(); |
| 324 | _outFileB.Close(); |
| 325 | _inFileA.Close(); |
| 326 | _inFileB.Close(); |
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 | void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) { |
| 330 | // Files in Side A |
| 331 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 332 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 333 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 334 | std::string file_name_out; |
| 335 | std::stringstream file_stream_a; |
| 336 | std::stringstream file_stream_b; |
| 337 | file_stream_a << webrtc::test::OutputPath(); |
| 338 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 339 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 340 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 341 | file_name_out = file_stream_a.str(); |
| 342 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 343 | file_name_out = file_stream_b.str(); |
| 344 | _outFileB.Open(file_name_out, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 345 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 346 | // Start with side A sending super-wideband and side B seding wideband. |
| 347 | // Toggle sending wideband/super-wideband in this test. |
| 348 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 349 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 350 | |
| 351 | int numSendCodecChanged = 0; |
| 352 | _myTimer.Reset(); |
| 353 | char currentTime[50]; |
| 354 | while (numSendCodecChanged < (maxSampRateChange << 1)) { |
| 355 | Run10ms(); |
| 356 | _myTimer.Tick10ms(); |
| 357 | _myTimer.CurrentTimeHMS(currentTime); |
| 358 | if (_testMode == 2) |
| 359 | printf("\r%s", currentTime); |
| 360 | if (_inFileA.EndOfFile()) { |
| 361 | if (_inFileA.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 362 | // Switch side A to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 363 | _inFileA.Close(); |
| 364 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 365 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 366 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 367 | // Switch side A to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 368 | _inFileA.Close(); |
| 369 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 370 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 371 | } |
| 372 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 373 | } |
| 374 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 375 | if (_inFileB.EndOfFile()) { |
| 376 | if (_inFileB.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 377 | // Switch side B to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 378 | _inFileB.Close(); |
| 379 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 380 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 381 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 382 | // Switch side B to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 383 | _inFileB.Close(); |
| 384 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 385 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 386 | } |
| 387 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 388 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 389 | } |
| 390 | _outFileA.Close(); |
| 391 | _outFileB.Close(); |
| 392 | _inFileA.Close(); |
| 393 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 394 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 395 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 396 | } // namespace webrtc |